/* ============================================================
   VISIT BOOK CRM — Theme
   Palette: warm paper background, deep indigo-navy structure,
   marigold/saffron accent (textile-trade, Surat), WhatsApp green
   reserved exclusively for WhatsApp actions so it stays meaningful.
   ============================================================ */

:root {
  /* ── Core palette ── */
  --ink-900: #1a2744;        /* deep indigo navy — sidebar, headers */
  --ink-800: #233158;
  --ink-700: #2d3d6b;
  --paper: #faf8f5;          /* warm paper background */
  --paper-card: #ffffff;
  --paper-sunken: #f3efe8;   /* table head, input bg */
  --border: #e6dfd2;
  --border-strong: #d8cdb8;
  --text: #211c14;
  --text-soft: #5c5648;
  --muted: #8a8270;

  /* ── Accent: marigold/saffron ── */
  --accent: #e08a2c;
  --accent-dark: #c4731c;
  --accent-tint: #fdf0de;

  /* ── Functional colors ── */
  --green: #1a8754;
  --green-tint: #e3f5ec;
  --red: #c4392b;
  --red-tint: #fbe9e7;
  --yellow: #b8860b;
  --yellow-tint: #fbf2dc;
  --blue: #2563a8;
  --blue-tint: #e7f0fa;

  /* ── WhatsApp (reserved for WA actions only) ── */
  --wa-green: #25d366;
  --wa-green-dark: #1da851;
  --wa-tint: #e7f9ee;

  --radius: 10px;
  --radius-sm: 6px;
  --shadow-card: 0 1px 2px rgba(26,39,68,0.06), 0 1px 1px rgba(26,39,68,0.04);
  --shadow-pop: 0 12px 32px rgba(26,39,68,0.18);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  background: var(--paper);
  color: var(--text);
  font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, 'Inter', system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.45;
}

button, input, select, textarea { font-family: inherit; }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--muted); }

a { color: var(--blue); }

/* ============== LAYOUT SHELL ============== */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 230px;
  flex-shrink: 0;
  background: var(--ink-900);
  color: #e8e6f0;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; bottom: 0; left: 0;
  z-index: 100;
  border-right: 1px solid var(--ink-700);
}
.sidebar-brand {
  padding: 18px 18px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  display: flex; align-items: center; gap: 10px;
}
.sidebar-brand .mark {
  width: 34px; height: 34px; border-radius: 8px;
  background: linear-gradient(155deg, var(--accent), var(--accent-dark));
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; flex-shrink: 0;
}
.sidebar-brand .name { font-size: 14px; font-weight: 700; letter-spacing: 0.2px; color: #fff; }
.sidebar-brand .sub { font-size: 10.5px; color: #9aa3c2; margin-top: 1px; letter-spacing: 0.3px; text-transform: uppercase; }

.sidebar-nav { flex: 1; padding: 10px 8px; overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: 8px; cursor: pointer;
  color: #b7bdd6; font-size: 13px; font-weight: 500;
  margin-bottom: 2px; transition: background 0.12s, color 0.12s;
  white-space: nowrap; position: relative;
}
.nav-item .icon { font-size: 15px; width: 18px; text-align: center; flex-shrink: 0; }
.nav-item:hover { background: rgba(255,255,255,0.06); color: #fff; }
.nav-item.active { background: var(--accent); color: #fff; font-weight: 700; }
.nav-item .nbadge {
  margin-left: auto; background: var(--red); color: #fff; font-size: 10px;
  font-weight: 700; padding: 1px 6px; border-radius: 99px; min-width: 16px; text-align: center;
}
.nav-item.active .nbadge { background: rgba(255,255,255,0.28); }

.sidebar-foot {
  padding: 12px; border-top: 1px solid rgba(255,255,255,0.08);
  font-size: 11px; color: #7d84a3;
}
.sidebar-foot .wa-dot { display: inline-flex; align-items: center; gap: 6px; }
.sidebar-foot .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.sidebar-foot .dot.ok { background: var(--wa-green); box-shadow: 0 0 0 3px rgba(37,211,102,0.18); }
.sidebar-foot .dot.bad { background: var(--red); box-shadow: 0 0 0 3px rgba(196,57,43,0.18); }

.main { margin-left: 230px; flex: 1; min-width: 0; min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
  height: 58px; flex-shrink: 0;
  background: var(--paper-card); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 14px; padding: 0 22px;
  position: sticky; top: 0; z-index: 50;
}
.topbar h1 { font-size: 16px; font-weight: 700; }
.topbar .crumb { font-size: 12px; color: var(--muted); }
.topbar-spacer { flex: 1; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.user-chip {
  display: flex; align-items: center; gap: 8px; padding: 5px 10px 5px 6px;
  background: var(--paper-sunken); border-radius: 99px; cursor: pointer; font-size: 12.5px; font-weight: 600;
}
.user-chip .av {
  width: 24px; height: 24px; border-radius: 50%; background: var(--ink-900); color: #fff;
  display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700;
}

.content { padding: 22px 26px 60px; flex: 1; }
.page { display: none; }
.page.active { display: block; animation: fadein 0.15s ease; }
@keyframes fadein { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: none; } }

.page-head {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 12px;
  margin-bottom: 18px; flex-wrap: wrap;
}
.page-head h2 { font-size: 19px; font-weight: 700; }
.page-head .desc { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ============== KPI CARDS ============== */
.kpi-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 20px; }
.kpi {
  background: var(--paper-card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow-card);
}
.kpi .label { font-size: 10.5px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; font-weight: 700; margin-bottom: 6px; }
.kpi .value { font-size: 22px; font-weight: 800; color: var(--ink-900); }
.kpi .value.accent { color: var(--accent-dark); }
.kpi .value.green { color: var(--green); }
.kpi .value.red { color: var(--red); }
.kpi .sub { font-size: 11.5px; color: var(--muted); margin-top: 3px; }

/* ============== BUTTONS ============== */
.btn {
  display: inline-flex; align-items: center; gap: 6px; justify-content: center;
  padding: 8px 15px; border-radius: 8px; font-size: 13px; font-weight: 600;
  cursor: pointer; border: 1px solid transparent; transition: filter 0.12s, background 0.12s;
  white-space: nowrap;
}
.btn:hover { filter: brightness(0.96); }
.btn:active { filter: brightness(0.9); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); }
.btn-secondary { background: var(--paper-card); color: var(--text); border-color: var(--border-strong); }
.btn-secondary:hover { background: var(--paper-sunken); }
.btn-ghost { background: transparent; color: var(--text-soft); border-color: var(--border); }
.btn-danger { background: var(--red-tint); color: var(--red); border-color: rgba(196,57,43,0.25); }
.btn-wa { background: var(--wa-green); color: #fff; }
.btn-wa:hover { background: var(--wa-green-dark); }
.btn-sm { padding: 5px 10px; font-size: 12px; border-radius: 6px; }
.btn-icon { padding: 6px 8px; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }

/* ============== TABLE ============== */
.panel { background: var(--paper-card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-card); margin-bottom: 20px; overflow: hidden; }
.panel-head { padding: 13px 18px; display: flex; align-items: center; justify-content: space-between; gap: 10px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.panel-head h3 { font-size: 14px; font-weight: 700; }
.filters-row { display: flex; gap: 8px; padding: 12px 18px; flex-wrap: wrap; border-bottom: 1px solid var(--border); background: var(--paper-sunken); }
.table-scroll { overflow: auto; max-height: 64vh; }
table { width: 100%; border-collapse: collapse; font-size: 12.5px; min-width: max-content; }
thead th {
  position: sticky; top: 0; z-index: 5;
  background: var(--paper-sunken); color: var(--muted);
  text-align: left; padding: 9px 13px; font-size: 10.5px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.4px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
tbody td { padding: 9px 13px; border-bottom: 1px solid var(--border); white-space: nowrap; vertical-align: middle; }
tbody tr:hover { background: var(--accent-tint); }
tbody tr:last-child td { border-bottom: none; }
.cell-muted { color: var(--muted); font-size: 12px; }
.cell-name { font-weight: 700; color: var(--text); }
.cell-phone { font-weight: 700; color: var(--ink-900); letter-spacing: 0.2px; }
.row-actions { display: flex; gap: 5px; }
.empty-row td { text-align: center; padding: 32px; color: var(--muted); }

/* tag/pill/status */
.tag { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 10.5px; font-weight: 700; white-space: nowrap; }
.tag.area { background: var(--blue-tint); color: var(--blue); }
.tag.active, .tag.delivered, .tag.read, .tag.done { background: var(--green-tint); color: var(--green); }
.tag.inactive, .tag.failed, .tag.cancelled { background: var(--red-tint); color: var(--red); }
.tag.prospect, .tag.pending, .tag.scheduled { background: var(--yellow-tint); color: var(--yellow); }
.tag.sent { background: var(--blue-tint); color: var(--blue); }
.tag.vip { background: var(--accent-tint); color: var(--accent-dark); }
.tag.hot { background: var(--red-tint); color: var(--red); }
.tag.cold { background: var(--blue-tint); color: var(--blue); }
.tag.grade-a { background: var(--green-tint); color: var(--green); }
.tag.grade-b { background: var(--yellow-tint); color: var(--yellow); }
.tag.grade-c { background: var(--red-tint); color: var(--red); }

/* ============== ROW ACTION DROPDOWN (⋮ menu) ============== */
.action-menu-wrap { position: relative; display: inline-block; }
.action-dots-btn {
  background: none; border: none; cursor: pointer; font-size: 16px; font-weight: 900;
  color: var(--muted); padding: 4px 8px; border-radius: 6px; line-height: 1;
}
.action-dots-btn:hover { background: var(--paper-sunken); color: var(--text); }
.action-dropdown {
  display: none; position: absolute; right: 0; top: 100%; margin-top: 4px;
  background: var(--paper-card); border: 1px solid var(--border-strong); border-radius: 10px;
  box-shadow: var(--shadow-pop); min-width: 190px; z-index: 80; overflow: hidden; padding: 5px;
}
.action-dropdown.open { display: block; }
.action-dropdown button {
  display: flex; align-items: center; gap: 9px; width: 100%; text-align: left;
  padding: 8px 10px; background: none; border: none; cursor: pointer; font-size: 12.5px;
  color: var(--text); border-radius: 6px; white-space: nowrap;
}
.action-dropdown button:hover { background: var(--accent-tint); }
.action-dropdown button.danger { color: var(--red); }
.action-dropdown button.danger:hover { background: var(--red-tint); }
.action-dropdown .sep { height: 1px; background: var(--border); margin: 4px 2px; }
.clickable-row { cursor: pointer; }

/* ============== DETAIL POPUP ============== */
.detail-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.detail-head h2 { font-size: 19px; font-weight: 800; }
.detail-head .meta { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.detail-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 14px; margin-bottom: 18px; }
.detail-field .k { font-size: 10px; text-transform: uppercase; letter-spacing: 0.4px; color: var(--muted); font-weight: 700; margin-bottom: 3px; }
.detail-field .v { font-size: 13.5px; font-weight: 600; }
.detail-section-title { font-size: 13px; font-weight: 800; margin: 18px 0 10px; display: flex; align-items: center; justify-content: space-between; }
.timeline { display: flex; flex-direction: column; gap: 10px; }
.timeline-item { border-left: 3px solid var(--accent); padding: 8px 0 8px 14px; position: relative; }
.timeline-item .tdate { font-size: 11.5px; font-weight: 800; color: var(--ink-900); display: flex; gap: 8px; align-items: center; }
.timeline-item .tremarks { font-size: 13px; margin-top: 4px; line-height: 1.5; }
.timeline-item .tnext { font-size: 11px; color: var(--muted); margin-top: 4px; }
.order-card { border: 1px solid var(--border); border-radius: 9px; padding: 12px 14px; margin-bottom: 10px; }
.order-card .ohead { display: flex; justify-content: space-between; font-size: 12.5px; font-weight: 700; margin-bottom: 8px; }
.order-card table { font-size: 12px; }
.order-card .ototal { text-align: right; font-weight: 800; color: var(--accent-dark); margin-top: 6px; font-size: 13px; }

/* ============== AI UI ============== */
.ai-btn {
  display: inline-flex; align-items: center; gap: 5px; background: linear-gradient(135deg, #6d5bd0, #8e6ff7);
  color: #fff; border: none; padding: 5px 11px; border-radius: 7px; font-size: 11.5px; font-weight: 700; cursor: pointer;
}
.ai-btn:hover { filter: brightness(1.08); }
.ai-btn[disabled] { opacity: 0.5; cursor: not-allowed; }
.ai-suggestion-box {
  background: #f4f1fc; border: 1px solid #ddd4f7; border-radius: 8px; padding: 10px 12px;
  font-size: 12.5px; color: #4a3d8f; margin-top: 8px; display: none;
}
.ai-suggestion-box.show { display: block; }
.ai-suggestion-box .apply-link { color: #6d5bd0; font-weight: 700; cursor: pointer; text-decoration: underline; margin-left: 6px; }
.mic-btn {
  width: 34px; height: 34px; border-radius: 50%; border: none; cursor: pointer;
  background: var(--paper-sunken); display: inline-flex; align-items: center; justify-content: center; font-size: 15px;
}
.mic-btn.recording { background: var(--red); color: #fff; animation: pulse 1.2s infinite; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(196,57,43,0.4); } 50% { box-shadow: 0 0 0 8px rgba(196,57,43,0); } }

/* ============== FORM ============== */
input[type="text"], input[type="date"], input[type="time"], input[type="number"], input[type="search"],
input[type="tel"], input[type="password"], select, textarea {
  background: var(--paper-card); border: 1px solid var(--border-strong); border-radius: 8px;
  padding: 8px 11px; color: var(--text); font-size: 13px; outline: none; width: 100%;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-tint); }
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 11px; font-weight: 700; color: var(--text-soft); text-transform: uppercase; letter-spacing: 0.3px; }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field-grid .full { grid-column: 1 / -1; }
.search-input { min-width: 200px; flex: 1; }

/* ============== MODAL ============== */
.modal-overlay {
  display: none; position: fixed; inset: 0; background: rgba(26,20,12,0.5); backdrop-filter: blur(2px);
  z-index: 300; align-items: center; justify-content: center; padding: 20px;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--paper-card); border-radius: 14px; padding: 22px; width: 100%; max-width: 600px;
  max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow-pop);
}
.modal.wide { max-width: 820px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.modal-head h3 { font-size: 16px; font-weight: 800; }
.modal-close { cursor: pointer; color: var(--muted); font-size: 20px; line-height: 1; background: none; border: none; }
.modal-close:hover { color: var(--text); }
.modal-actions { display: flex; gap: 9px; justify-content: flex-end; margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--border); }

/* ============== WHATSAPP-SPECIFIC UI ============== */
.wa-launch-btn {
  display: inline-flex; align-items: center; gap: 5px; background: var(--wa-tint); color: var(--wa-green-dark);
  border: 1px solid rgba(37,211,102,0.3); padding: 5px 10px; border-radius: 7px; font-size: 12px; font-weight: 700; cursor: pointer;
}
.wa-launch-btn:hover { background: var(--wa-green); color: #fff; }
.wa-preview {
  background: var(--wa-tint); border: 1px solid rgba(37,211,102,0.25); border-radius: 10px; padding: 14px;
  font-size: 13px; white-space: pre-wrap; line-height: 1.55; color: #14532d;
}
.wa-status-bar {
  display: flex; align-items: center; gap: 8px; padding: 10px 14px; border-radius: 8px; font-size: 12.5px; margin-bottom: 14px;
}
.wa-status-bar.ok { background: var(--green-tint); color: var(--green); }
.wa-status-bar.bad { background: var(--red-tint); color: var(--red); }
.wa-status-bar.pending { background: var(--yellow-tint); color: var(--yellow); }

/* ============== TABS ============== */
.tabs { display: flex; gap: 2px; border-bottom: 2px solid var(--border); margin-bottom: 18px; }
.tab-btn {
  padding: 9px 18px; cursor: pointer; font-size: 13px; font-weight: 700; color: var(--muted);
  background: none; border: none; border-bottom: 2px solid transparent; margin-bottom: -2px;
}
.tab-btn.active { color: var(--accent-dark); border-bottom-color: var(--accent); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ============== TOAST ============== */
.toast {
  position: fixed; bottom: 22px; right: 22px; background: var(--ink-900); color: #fff;
  border-radius: 10px; padding: 12px 18px; font-size: 13px; z-index: 500; opacity: 0;
  transform: translateY(8px); transition: all 0.2s; pointer-events: none; max-width: 340px;
  box-shadow: var(--shadow-pop);
}
.toast.show { opacity: 1; transform: none; }
.toast.success { background: var(--ink-900); border-left: 4px solid var(--green); }
.toast.error { background: var(--ink-900); border-left: 4px solid var(--red); }

/* ============== MISC ============== */
.divider { height: 1px; background: var(--border); margin: 16px 0; }
.text-muted { color: var(--muted); }
.flex-row { display: flex; align-items: center; gap: 8px; }
.gap-wrap { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.chk { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; }
.login-screen {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: var(--ink-900); padding: 20px;
}
.login-card {
  background: var(--paper-card); border-radius: 16px; padding: 36px 32px; width: 100%; max-width: 380px;
  box-shadow: var(--shadow-pop);
}
.login-card .mark {
  width: 52px; height: 52px; border-radius: 12px; background: linear-gradient(155deg, var(--accent), var(--accent-dark));
  display: flex; align-items: center; justify-content: center; font-size: 24px; margin: 0 auto 14px;
}
.login-card h1 { text-align: center; font-size: 18px; font-weight: 800; margin-bottom: 2px; }
.login-card .sub { text-align: center; font-size: 12px; color: var(--muted); margin-bottom: 22px; }
.login-error { background: var(--red-tint); color: var(--red); padding: 9px 12px; border-radius: 8px; font-size: 12.5px; margin-bottom: 12px; display: none; }
.login-error.show { display: block; }

.bar-chart-wrap { background: var(--paper-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; margin-bottom: 20px; box-shadow: var(--shadow-card); }
.bar-chart-wrap h3 { font-size: 13.5px; font-weight: 700; margin-bottom: 14px; }
.bars { display: flex; align-items: flex-end; gap: 10px; height: 140px; overflow-x: auto; padding-bottom: 4px; }
.bar-col { flex: 1; min-width: 36px; display: flex; flex-direction: column; align-items: center; gap: 5px; height: 100%; justify-content: flex-end; }
.bar { width: 100%; border-radius: 5px 5px 0 0; background: var(--accent); min-height: 3px; }
.bar-label { font-size: 10px; color: var(--muted); text-align: center; }
.bar-val { font-size: 10.5px; font-weight: 700; }

@media (max-width: 880px) {
  .sidebar { width: 64px; }
  .sidebar-brand .name, .sidebar-brand .sub, .nav-item span:not(.icon), .nav-item .nbadge { display: none; }
  .sidebar-brand { justify-content: center; padding: 16px 8px; }
  .nav-item { justify-content: center; padding: 11px; }
  .main { margin-left: 64px; }
  .field-grid { grid-template-columns: 1fr; }
  .content { padding: 16px; }
}

/* ============== ROLE-BASED VISIBILITY ============== */
/* These hide admin-only Settings tabs and WhatsApp send buttons for roles that
   don't have the corresponding backend permission — purely cosmetic (the backend
   still enforces every check independently), but keeps the UI from inviting a
   click that would just get rejected with a 403 anyway. */
body.role-no-settings #tab_wa, body.role-no-settings #tab_defaults,
body.role-no-settings #tab_templates, body.role-no-settings #tab_webhookhealth,
body.role-no-settings #tab_ai, body.role-no-settings #tab_team,
body.role-no-settings #tab_backup, body.role-no-settings #tab_users {
  display: none;
}
body.role-no-wa .wa-launch-btn, body.role-no-wa .btn-wa { display: none; }
