/* ====================================================================
   WhatsApp CRM — Custom Stylesheet
   Palette: warm off-white surface + deep forest primary + amber accent
   Fonts:   Bricolage Grotesque (headings) · Instrument Sans (body)
   ==================================================================== */

:root {
  --bg:            #F6F3EC;
  --surface:       #FFFFFF;
  --surface-2:     #FBF9F4;
  --border:        #E5E1D6;
  --border-strong: #CFC9B8;
  --text:          #14181C;
  --text-soft:     #4B5560;
  --text-mute:     #8A94A0;

  --primary:       #0F4C3A;
  --primary-2:     #146B52;
  --primary-soft:  #DDEAE3;
  --accent:        #C2410C;
  --accent-soft:   #FDE8D6;
  --info:          #1E4E8C;
  --warn:          #B45309;
  --warn-soft:     #FEF3C7;
  --danger:        #B91C1C;
  --danger-soft:   #FEE2E2;
  --ok:            #15803D;
  --ok-soft:       #DCFCE7;

  --radius:        14px;
  --radius-sm:     10px;
  --shadow:        0 1px 2px rgba(20,24,28,.04), 0 6px 24px rgba(20,24,28,.06);
  --shadow-lg:     0 8px 40px rgba(20,24,28,.12);

  --font-head: 'Bricolage Grotesque', ui-sans-serif, system-ui, sans-serif;
  --font-body: 'Instrument Sans', ui-sans-serif, system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body { margin:0; padding:0; }
body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { font-family: var(--font-head); font-weight: 700; letter-spacing: -.01em; margin: 0; }
a { color: var(--primary-2); text-decoration: none; }
a:hover { color: var(--primary); }
button { font-family: inherit; }

/* ---------- Layout ---------- */
.app-shell { display: grid; grid-template-columns: 260px 1fr; min-height: 100vh; }
.main { min-width: 0; display: flex; flex-direction: column; }

/* ---------- Sidebar ---------- */
.sidebar {
  background: #111815;
  color: #D8DDD7;
  padding: 22px 16px 24px;
  position: sticky; top: 0;
  height: 100vh;
  display: flex; flex-direction: column;
  border-right: 1px solid #1e2622;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 6px 8px 22px; border-bottom: 1px solid #1e2622; margin-bottom: 12px; }
.brand-mark {
  width: 42px; height: 42px; border-radius: 12px;
  background: linear-gradient(135deg, #22C55E, #0F4C3A);
  display: grid; place-items: center; color: white; font-size: 20px;
}
.brand-name { font-family: var(--font-head); font-weight: 700; font-size: 18px; color: #F4F1E8; }
.brand-sub  { font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: #7F8B84; }

.nav { flex: 1; overflow-y: auto; }
.nav-section { font-size: 11px; letter-spacing: .16em; text-transform: uppercase; color: #6B7770; padding: 14px 10px 6px; }
.nav-link {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border-radius: 10px;
  color: #C6CCC5; font-weight: 500;
  transition: background .18s, color .18s, transform .18s;
}
.nav-link i { width: 18px; text-align: center; opacity: .85; }
.nav-link:hover { background: #1a2320; color: #F4F1E8; }
.nav-link.active {
  background: linear-gradient(90deg, rgba(34,197,94,.14), rgba(34,197,94,0));
  color: #E8F3E0;
  box-shadow: inset 3px 0 0 #22C55E;
}
.sidebar-footer { padding-top: 12px; }
.foot-card { padding: 12px; border: 1px dashed #2a3430; border-radius: 12px; }
.foot-title { font-family: var(--font-head); color: #E4E9E1; font-size: 13px; }
.foot-sub { color: #7F8B84; font-size: 12px; margin-top: 4px; }

/* ---------- Topbar ---------- */
.topbar {
  background: transparent;
  padding: 22px 32px;
  display: flex; justify-content: space-between; align-items: center;
  gap: 20px;
  border-bottom: 1px solid var(--border);
}
.topbar-left { display: flex; align-items: center; gap: 14px; }
.crumb { font-size: 12px; text-transform: uppercase; letter-spacing: .14em; color: var(--text-mute); }
.page-title { font-size: 26px; margin-top: 2px; }
.menu-toggle { display: none; background: none; border: 0; font-size: 20px; }

.topbar-right { display: flex; align-items: center; gap: 14px; }
.user-chip { display: flex; align-items: center; gap: 10px; padding: 6px 10px 6px 6px; background: var(--surface); border: 1px solid var(--border); border-radius: 999px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--primary); color: white; display: grid; place-items: center; font-weight: 700; font-family: var(--font-head); }
.who-name { font-weight: 600; font-size: 13px; line-height: 1; }
.who-sub { font-size: 11px; color: var(--text-mute); }

/* ---------- Content ---------- */
.content { padding: 28px 32px 60px; }

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
}
.card + .card { margin-top: 20px; }
.card-title { font-size: 17px; margin-bottom: 4px; }
.card-sub { color: var(--text-mute); font-size: 13px; margin-bottom: 18px; }
.card-header { display: flex; justify-content: space-between; align-items: end; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }

/* ---------- Grid utilities ---------- */
.grid { display: grid; gap: 20px; }
.grid-4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.grid-2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
@media (max-width: 1100px) { .grid-4 { grid-template-columns: repeat(2, 1fr); } .grid-3 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 720px)  { .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; } }

/* ---------- Stat cards ---------- */
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  position: relative;
  overflow: hidden;
}
.stat::after {
  content:''; position:absolute; right:-30px; top:-30px; width:120px; height:120px;
  background: radial-gradient(closest-side, var(--primary-soft), transparent);
  opacity:.7;
}
.stat-label { color: var(--text-mute); font-size: 12px; text-transform: uppercase; letter-spacing: .12em; }
.stat-value { font-family: var(--font-head); font-size: 34px; font-weight: 800; margin-top: 6px; }
.stat-hint  { color: var(--text-soft); font-size: 12px; margin-top: 4px; }
.stat-icon  { position: absolute; right: 18px; bottom: 18px; font-size: 22px; color: var(--primary); opacity: .55; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 16px; border-radius: 999px;
  font-weight: 600; font-size: 14px;
  border: 1px solid transparent; cursor: pointer;
  transition: transform .12s ease, box-shadow .18s, background-color .18s, color .18s, border-color .18s;
}
.btn:hover { transform: translateY(-1px); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-2); box-shadow: 0 8px 24px rgba(15,76,58,.24); }
.btn-accent { background: var(--accent); color: #fff; }
.btn-accent:hover { background: #9C3308; }
.btn-outline { background: var(--surface); border-color: var(--border-strong); color: var(--text); }
.btn-outline:hover { border-color: var(--text); }
.btn-ghost { background: transparent; color: var(--text-soft); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-danger { background: var(--danger-soft); color: var(--danger); }
.btn-danger:hover { background: #FCC7C7; }
.btn-sm { padding: 6px 12px; font-size: 12.5px; }
.btn-block { width: 100%; justify-content: center; }

/* ---------- Forms ---------- */
.form-row { display: grid; gap: 6px; margin-bottom: 14px; }
.form-row.two { grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 640px) { .form-row.two { grid-template-columns: 1fr; } }
.label { font-size: 12.5px; font-weight: 600; color: var(--text-soft); text-transform: uppercase; letter-spacing: .06em; }
.input, .select, .textarea {
  width: 100%; padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  background: var(--surface);
  font-size: 14px; color: var(--text);
  font-family: inherit;
  transition: border-color .15s, box-shadow .15s;
}
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(15,76,58,.14);
}
.textarea { min-height: 110px; resize: vertical; font-family: inherit; }
.hint { font-size: 12px; color: var(--text-mute); }

/* ---------- Table ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th, table.data td { padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--border); }
table.data th { background: var(--surface-2); font-family: var(--font-head); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--text-soft); }
table.data tbody tr:hover { background: #FAF7EF; }
table.data td small { color: var(--text-mute); }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 600;
  background: var(--surface-2); color: var(--text-soft); border: 1px solid var(--border);
}
.badge-ok    { background: var(--ok-soft); color: var(--ok); border-color: #BBF0CB; }
.badge-warn  { background: var(--warn-soft); color: var(--warn); border-color: #FDE68A; }
.badge-info  { background: #DBEAFE; color: var(--info); border-color: #BFDBFE; }
.badge-danger{ background: var(--danger-soft); color: var(--danger); border-color: #FCA5A5; }
.badge-muted { background: #EEEAE0; color: var(--text-soft); }

/* ---------- Flash ---------- */
.flash {
  margin: 16px 32px 0; padding: 12px 16px;
  border-radius: 12px; display: flex; align-items: center; gap: 10px;
  font-weight: 500;
}
.flash-success { background: var(--ok-soft); color: var(--ok); border: 1px solid #BBF0CB; }
.flash-error   { background: var(--danger-soft); color: var(--danger); border: 1px solid #FCA5A5; }
.flash-info    { background: #DBEAFE; color: var(--info); border: 1px solid #BFDBFE; }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(20,24,28,.42);
  display: none; align-items: center; justify-content: center;
  z-index: 60; padding: 24px;
  backdrop-filter: blur(4px);
}
.modal-backdrop.open { display: flex; }
.modal {
  background: var(--surface); border-radius: 18px; width: 100%; max-width: 640px;
  padding: 26px; box-shadow: var(--shadow-lg);
  animation: pop .18s ease;
}
.modal.lg { max-width: 820px; }
.modal-head { display: flex; justify-content: space-between; align-items: start; margin-bottom: 16px; }
.modal-head h3 { font-size: 20px; }
.modal-close { background: none; border: 0; font-size: 20px; color: var(--text-mute); cursor: pointer; }
@keyframes pop { from { transform: scale(.96); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* ---------- Filters row ---------- */
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; margin-bottom: 16px; }
.filters .form-row { margin: 0; min-width: 160px; }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 20px; }
.tab {
  padding: 10px 16px; background: transparent; border: 0; cursor: pointer;
  font-weight: 600; color: var(--text-soft); border-bottom: 2px solid transparent;
  font-family: inherit;
}
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ---------- Chat preview (template preview card) ---------- */
.wa-preview {
  background: #EBE4D5;
  border-radius: 14px;
  padding: 18px;
  min-height: 200px;
  background-image:
    radial-gradient(circle at 12% 18%, rgba(15,76,58,.06) 0 2px, transparent 2px),
    radial-gradient(circle at 82% 60%, rgba(194,65,12,.05) 0 2px, transparent 2px);
}
.wa-bubble {
  background: #FFFFFF; border-radius: 10px 10px 10px 2px;
  padding: 12px 14px; max-width: 320px;
  box-shadow: 0 1px 1px rgba(0,0,0,.08);
  font-size: 14px; white-space: pre-wrap;
}
.wa-bubble .wa-header-text { font-weight: 700; margin-bottom: 6px; }
.wa-bubble .wa-footer { color: var(--text-mute); font-size: 12px; margin-top: 8px; }
.wa-bubble .wa-time { color: var(--text-mute); font-size: 10px; text-align: right; }
.wa-buttons { margin-top: 8px; display: flex; flex-direction: column; gap: 4px; }
.wa-btn { background: #FFFFFF; border-top: 1px solid #EDE7D8; text-align: center; padding: 8px; color: #007BFC; font-weight: 600; border-radius: 8px; font-size: 13px; }

/* ---------- Empty state ---------- */
.empty { text-align: center; padding: 46px 20px; color: var(--text-mute); }
.empty i { font-size: 32px; margin-bottom: 10px; color: var(--border-strong); }

/* ---------- Toast ---------- */
.toast-container { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 10px; z-index: 100; }
.toast { background: #111815; color: white; padding: 12px 16px; border-radius: 10px; box-shadow: var(--shadow-lg); animation: pop .18s ease; }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 50; transform: translateX(-100%); transition: transform .25s; }
  .sidebar.open { transform: none; }
  .menu-toggle { display: inline-flex; }
  .content, .topbar, .flash { padding-left: 18px; padding-right: 18px; }
  .flash { margin-left: 18px; margin-right: 18px; }
}

/* utility */
.row { display: flex; gap: 10px; }
.row-wrap { flex-wrap: wrap; }
.between { justify-content: space-between; }
.center { align-items: center; }
.gap-6 { gap: 6px; } .gap-10 { gap: 10px; } .gap-14 { gap: 14px; }
.mt-6 { margin-top: 6px; } .mt-10 { margin-top: 10px; } .mt-14 { margin-top: 14px; } .mt-20 { margin-top: 20px; }
.mb-0 { margin-bottom: 0; }
.text-mute { color: var(--text-mute); }
.text-soft { color: var(--text-soft); }
.mono { font-family: var(--font-mono); font-size: 13px; }

/* ==============================================================
   Inbox — WhatsApp-style two-panel chat UI
   ============================================================== */
.inbox {
  display: grid;
  grid-template-columns: 360px 1fr;
  height: calc(100vh - 100px);
  background: #FFF;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
  border: 1px solid #E8E4D8;
}

/* LEFT PANEL — conversation list */
.inbox-list {
  border-right: 1px solid #E8E4D8;
  display: flex;
  flex-direction: column;
  background: #F8F7F1;
  min-width: 0;
}
.inbox-list-head {
  padding: 14px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid #EDE9DE;
  background: #F0EDE0;
}
.inbox-search {
  padding: 10px 12px;
  border-bottom: 1px solid #EDE9DE;
  position: relative;
}
.inbox-search i { position: absolute; left: 22px; top: 50%; transform: translateY(-50%); color: #9AA3A5; font-size: 13px; }
.inbox-search input {
  width: 100%;
  padding: 8px 12px 8px 32px;
  border: 1px solid transparent;
  background: #FFF;
  border-radius: 8px;
  font-size: 14px;
  outline: none;
}
.inbox-search input:focus { border-color: #10462F; }

#inbox-conversations, #inbox-picker { overflow-y: auto; flex: 1; }

.inbox-row, .inbox-pick-row {
  display: flex;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid #F1EEE2;
  cursor: pointer;
  transition: background .08s;
  color: inherit;
  text-decoration: none;
  align-items: center;
}
.inbox-row:hover, .inbox-pick-row:hover { background: #F1EEE0; }
.inbox-row.active { background: #E6F0EA; }
.avatar {
  width: 42px; height: 42px; border-radius: 50%;
  background: #10462F; color: #FFF;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 16px;
  flex-shrink: 0;
}
.avatar.lg { width: 40px; height: 40px; font-size: 14px; }
.row-body { flex: 1; min-width: 0; }
.row-top { display: flex; justify-content: space-between; align-items: center; }
.row-name { font-weight: 600; font-size: 14px; color: #111827; }
.row-time { font-size: 11px; color: #9AA3A5; }
.row-bottom { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 2px; }
.row-preview { font-size: 13px; color: #6B7280; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.inbox-picker-head { padding: 10px 14px; font-size: 12px; font-weight: 600; text-transform: uppercase; color: #6B7280; background: #F0EDE0; border-bottom: 1px solid #EDE9DE; }

/* RIGHT PANEL — thread */
.inbox-thread {
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: #ECE5DD; /* WhatsApp chat backdrop */
  background-image: radial-gradient(circle at 20% 20%, rgba(255,255,255,.4) 0, transparent 40%),
                    radial-gradient(circle at 80% 80%, rgba(255,255,255,.3) 0, transparent 40%);
}
.thread-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #6B7280;
  text-align: center;
  padding: 40px;
}
.thread-empty i.fa-whatsapp { font-size: 90px; color: #10462F; opacity: .3; margin-bottom: 20px; }
.thread-empty.small { font-size: 13px; padding: 20px; color: #9AA3A5; }
.thread-empty.small i { font-size: 24px; margin-bottom: 6px; }
.thread-head {
  padding: 12px 16px;
  background: #F0EDE0;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid #E8E4D8;
}
.thread-head-right { margin-left: auto; }

.thread-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.thread-loading { text-align: center; color: #9AA3A5; padding: 40px; }
.day-sep {
  align-self: center;
  background: rgba(255,255,255,.85);
  padding: 4px 12px;
  border-radius: 8px;
  font-size: 11px;
  color: #6B7280;
  margin: 12px 0;
  font-weight: 500;
  box-shadow: 0 1px 2px rgba(0,0,0,.06);
}

.msg {
  max-width: 65%;
  padding: 8px 10px 6px;
  border-radius: 8px;
  position: relative;
  box-shadow: 0 1px 1px rgba(0,0,0,.08);
  font-size: 14px;
  line-height: 1.35;
  word-break: break-word;
}
.msg.in {
  align-self: flex-start;
  background: #FFF;
  border-top-left-radius: 2px;
}
.msg.out {
  align-self: flex-end;
  background: #D9FDD3; /* WhatsApp light green */
  border-top-right-radius: 2px;
}
.msg-text { white-space: pre-wrap; }
.msg-media { color: #10462F; font-size: 13px; font-weight: 600; margin-bottom: 4px; }
.msg-foot {
  font-size: 10px;
  color: #6B7280;
  text-align: right;
  margin-top: 2px;
  display: flex;
  gap: 4px;
  justify-content: flex-end;
  align-items: center;
}
.ticks { font-size: 11px; }

/* Compose */
.thread-compose {
  padding: 12px 16px;
  background: #F0EDE0;
  border-top: 1px solid #E8E4D8;
}
#freeform-form { display: flex; gap: 8px; }
#freeform-form textarea {
  flex: 1;
  border: 1px solid #E8E4D8;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 14px;
  outline: none;
  resize: none;
  background: #FFF;
}
#freeform-form textarea:focus { border-color: #10462F; }

.thread-locked {
  background: #FEF3C7;
  padding: 10px 14px;
  border-radius: 8px;
  display: flex;
  gap: 10px;
  align-items: flex-start;
  color: #78350F;
  font-size: 13px;
  margin-bottom: 10px;
  line-height: 1.4;
}
#template-form { display: flex; flex-direction: column; gap: 8px; }
#template-form button { align-self: flex-end; }

@media (max-width: 900px) {
  .inbox { grid-template-columns: 1fr; }
  .inbox-list { display: none; }
}
