/* Glowa — design system
   Light and dark are both first-class; every colour is a token. */

:root {
  --brand:        #0f7b5f;
  --brand-600:    #0c6a51;
  --brand-100:    #e3f3ed;
  --brand-fg:     #ffffff;

  --bg:           #f4f6f5;
  --surface:      #ffffff;
  --surface-2:    #fafbfa;
  --sidebar:      #10231d;
  --sidebar-fg:   #cfe0d8;
  --sidebar-active:#1c3b31;

  --text:         #16211d;
  --text-2:       #5b6b65;
  --text-3:       #8b9a94;
  --border:       #e2e8e5;
  --border-2:     #cfd8d4;

  --ok:           #17915f;
  --ok-bg:        #e6f5ee;
  --warn:         #b7791f;
  --warn-bg:      #fdf4e3;
  --danger:       #c0392b;
  --danger-bg:    #fdecea;
  --info:         #2b6cb0;
  --info-bg:      #e8f1fa;

  --radius:       10px;
  --radius-sm:    7px;
  --shadow:       0 1px 2px rgba(16,35,29,.06), 0 4px 14px rgba(16,35,29,.05);
  --shadow-lg:    0 10px 40px rgba(16,35,29,.16);
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:        #0f1512;
    --surface:   #161e1a;
    --surface-2: #1b241f;
    --sidebar:   #0b120f;
    --sidebar-fg:#a9bfb6;
    --sidebar-active:#18271f;
    --text:      #e6ece9;
    --text-2:    #9db0a8;
    --text-3:    #6f8078;
    --border:    #253029;
    --border-2:  #33413a;
    --brand:     #35a97f;
    --brand-600: #2b8c69;
    --brand-100: #163026;
    --ok-bg:     #122b20;
    --warn-bg:   #2c2312;
    --danger-bg: #2e1815;
    --info-bg:   #14202e;
    --shadow:    0 1px 2px rgba(0,0,0,.4), 0 4px 14px rgba(0,0,0,.3);
    --shadow-lg: 0 10px 40px rgba(0,0,0,.55);
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: var(--sans); font-size: 14px; line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1,h2,h3,h4 { margin: 0; font-weight: 640; letter-spacing: -.01em; }
h1 { font-size: 21px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
p { margin: 0 0 10px; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }

/* ---------- Layout ---------- */
.layout { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }

.sidebar {
  background: var(--sidebar); color: var(--sidebar-fg);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 18px 18px 16px; font-weight: 680; font-size: 17px; color: #fff;
  letter-spacing: -.02em;
}
.brand .dot {
  width: 26px; height: 26px; border-radius: 8px; display: grid; place-items: center;
  background: var(--brand); color: #fff; font-size: 14px; flex: none;
}
.nav { padding: 6px 10px; flex: 1; overflow-y: auto; }
.nav-label {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .09em;
  color: #6b8378; padding: 14px 10px 6px; font-weight: 640;
}
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; margin-bottom: 1px;
  border-radius: var(--radius-sm); color: var(--sidebar-fg); font-weight: 500;
  text-decoration: none; transition: background .12s, color .12s;
}
.nav a:hover { background: rgba(255,255,255,.05); color: #fff; text-decoration: none; }
.nav a.active { background: var(--sidebar-active); color: #fff; font-weight: 600; }
.nav a .ico { width: 17px; text-align: center; opacity: .85; flex: none; }
.nav a .count {
  margin-left: auto; background: var(--brand); color: #fff; font-size: 11px;
  padding: 1px 7px; border-radius: 999px; font-weight: 640;
}
.sidebar-foot { padding: 12px; border-top: 1px solid rgba(255,255,255,.07); }
.who { display: flex; align-items: center; gap: 9px; padding: 6px 4px; }
.who .avatar {
  width: 30px; height: 30px; border-radius: 50%; background: var(--brand); color: #fff;
  display: grid; place-items: center; font-weight: 640; font-size: 12px; flex: none;
}
.who .meta { min-width: 0; }
.who .n { color: #fff; font-weight: 600; font-size: 13px; }
.who .o { color: #7f978c; font-size: 11.5px; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 14px; padding: 16px 26px;
  border-bottom: 1px solid var(--border); background: var(--surface); position: sticky; top: 0; z-index: 20;
}
.topbar .sub { color: var(--text-2); font-size: 13px; margin-top: 1px; }
.topbar .spacer { flex: 1; }
.content { padding: 22px 26px 60px; flex: 1; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 8px 14px; border-radius: var(--radius-sm); border: 1px solid var(--border-2);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 560;
  cursor: pointer; white-space: nowrap; transition: background .12s, border-color .12s, opacity .12s;
}
.btn:hover { background: var(--surface-2); border-color: var(--text-3); }
.btn:active { transform: translateY(.5px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--brand-fg); }
.btn-primary:hover { background: var(--brand-600); border-color: var(--brand-600); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { opacity: .9; background: var(--danger); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-2); border-color: var(--border); }
.btn-sm { padding: 5px 10px; font-size: 12.5px; }
.btn-block { width: 100%; }

/* ---------- Forms ---------- */
.field { margin-bottom: 14px; }
.field > label {
  display: block; font-weight: 580; font-size: 12.5px; margin-bottom: 5px; color: var(--text);
}
.field .hint { font-size: 12px; color: var(--text-2); margin-top: 5px; }
input[type=text], input[type=email], input[type=password], input[type=number],
input[type=datetime-local], input[type=search], select, textarea {
  width: 100%; padding: 8px 11px; border: 1px solid var(--border-2);
  border-radius: var(--radius-sm); background: var(--surface); color: var(--text);
  font: inherit; transition: border-color .12s, box-shadow .12s;
}
textarea { resize: vertical; min-height: 88px; line-height: 1.55; }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-100);
}
input::placeholder, textarea::placeholder { color: var(--text-3); }
.row { display: flex; gap: 12px; }
.row > * { flex: 1; min-width: 0; }
.check { display: flex; align-items: flex-start; gap: 9px; font-size: 13px; cursor: pointer; }
.check input { margin-top: 2px; width: auto; accent-color: var(--brand); }

/* ---------- Cards & grid ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.card-head {
  padding: 14px 18px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px;
}
.card-head .spacer { flex: 1; }
.card-body { padding: 18px; }
.grid { display: grid; gap: 16px; }
.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)); }

/* ---------- KPI ---------- */
.kpi { padding: 15px 17px; }
.kpi .k { font-size: 11.5px; color: var(--text-2); font-weight: 580;
  text-transform: uppercase; letter-spacing: .05em; }
.kpi .v { font-size: 27px; font-weight: 680; letter-spacing: -.03em; margin-top: 4px; line-height: 1.1; }
.kpi .d { font-size: 12px; color: var(--text-3); margin-top: 3px; }
.kpi .v.small { font-size: 20px; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.tbl th {
  text-align: left; padding: 9px 14px; font-size: 11.5px; font-weight: 640;
  text-transform: uppercase; letter-spacing: .05em; color: var(--text-2);
  border-bottom: 1px solid var(--border); background: var(--surface-2); white-space: nowrap;
}
table.tbl td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.tbl tbody tr:hover { background: var(--surface-2); }
table.tbl tbody tr:last-child td { border-bottom: none; }
table.tbl td.num, table.tbl th.num { text-align: right; font-variant-numeric: tabular-nums; }
.clickable { cursor: pointer; }

/* ---------- Chips / badges ---------- */
.chip {
  display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px;
  border-radius: 999px; font-size: 11.5px; font-weight: 600; white-space: nowrap;
  background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border);
}
.chip.ok      { background: var(--ok-bg);     color: var(--ok);     border-color: transparent; }
.chip.warn    { background: var(--warn-bg);   color: var(--warn);   border-color: transparent; }
.chip.danger  { background: var(--danger-bg); color: var(--danger); border-color: transparent; }
.chip.info    { background: var(--info-bg);   color: var(--info);   border-color: transparent; }
.chip.brand   { background: var(--brand-100); color: var(--brand);  border-color: transparent; }
.chip .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.tag-chip { display:inline-flex; align-items:center; gap:5px; padding:2px 8px; border-radius:999px;
  font-size:11.5px; font-weight:600; margin: 1px 3px 1px 0; }

/* ---------- Progress ---------- */
.bar { height: 6px; border-radius: 999px; background: var(--border); overflow: hidden; display: flex; }
.bar > span { display: block; height: 100%; }
.bar .s-sent { background: var(--info); }
.bar .s-delivered { background: var(--brand); }
.bar .s-read { background: #7bc9a4; }
.bar .s-failed { background: var(--danger); }
.bar .s-queued { background: var(--border-2); }

/* ---------- Empty / loading ---------- */
.empty { text-align: center; padding: 52px 20px; color: var(--text-2); }
.empty .big { font-size: 34px; margin-bottom: 10px; opacity: .5; }
.empty h3 { margin-bottom: 6px; color: var(--text); }
.empty p { max-width: 420px; margin: 0 auto 16px; }
.skeleton {
  background: linear-gradient(90deg, var(--border) 25%, var(--surface-2) 50%, var(--border) 75%);
  background-size: 200% 100%; animation: sk 1.2s infinite; border-radius: 6px; height: 14px;
}
@keyframes sk { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
.spinner {
  width: 15px; height: 15px; border: 2px solid var(--border-2); border-top-color: var(--brand);
  border-radius: 50%; animation: spin .7s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Toast ---------- */
#toasts { position: fixed; bottom: 22px; right: 22px; z-index: 300; display: flex;
  flex-direction: column; gap: 9px; max-width: 380px; }
.toast {
  background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--brand);
  border-radius: var(--radius-sm); box-shadow: var(--shadow-lg); padding: 11px 14px;
  font-size: 13px; animation: slidein .2s ease; display: flex; gap: 9px; align-items: flex-start;
}
.toast.err { border-left-color: var(--danger); }
.toast.warn { border-left-color: var(--warn); }
@keyframes slidein { from { opacity: 0; transform: translateX(16px); } }

/* ---------- Modal ---------- */
.modal-bg {
  position: fixed; inset: 0; background: rgba(10,20,16,.5); backdrop-filter: blur(2px);
  z-index: 200; display: grid; place-items: center; padding: 20px; overflow-y: auto;
}
.modal {
  background: var(--surface); border-radius: 12px; box-shadow: var(--shadow-lg);
  width: 100%; max-width: 560px; max-height: 90vh; display: flex; flex-direction: column;
  animation: pop .16s ease;
}
.modal.wide { max-width: 860px; }
@keyframes pop { from { opacity: 0; transform: scale(.97) translateY(6px); } }
.modal-head { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; }
.modal-head h2 { flex: 1; }
.modal-body { padding: 20px; overflow-y: auto; }
.modal-foot {
  padding: 14px 20px; border-top: 1px solid var(--border); display: flex; gap: 9px;
  justify-content: flex-end; background: var(--surface-2); border-radius: 0 0 12px 12px;
}

/* ---------- Banner ---------- */
.banner {
  display: flex; gap: 11px; align-items: flex-start; padding: 12px 15px;
  border-radius: var(--radius-sm); font-size: 13px; margin-bottom: 16px; border: 1px solid transparent;
}
.banner .b-ico { font-size: 15px; line-height: 1.3; flex: none; }
.banner.warn   { background: var(--warn-bg);   color: var(--warn); }
.banner.danger { background: var(--danger-bg); color: var(--danger); }
.banner.info   { background: var(--info-bg);   color: var(--info); }
.banner.ok     { background: var(--ok-bg);     color: var(--ok); }
.banner b { font-weight: 660; }
.banner a { color: inherit; text-decoration: underline; }

/* ---------- Toolbar ---------- */
.toolbar { display: flex; gap: 9px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar .grow { flex: 1; min-width: 180px; }
.toolbar input[type=search] { max-width: 320px; }

/* ---------- Steps ---------- */
.steps { display: flex; gap: 6px; margin-bottom: 22px; }
.step {
  flex: 1; padding: 9px 12px; border-radius: var(--radius-sm); background: var(--surface-2);
  border: 1px solid var(--border); font-size: 12.5px; color: var(--text-2); font-weight: 560;
  display: flex; align-items: center; gap: 8px;
}
.step .n {
  width: 20px; height: 20px; border-radius: 50%; background: var(--border-2); color: var(--text-2);
  display: grid; place-items: center; font-size: 11px; font-weight: 700; flex: none;
}
.step.active { background: var(--brand-100); border-color: var(--brand); color: var(--brand); }
.step.active .n { background: var(--brand); color: #fff; }
.step.done .n { background: var(--ok); color: #fff; }
.step.done { color: var(--text); }

/* ---------- WhatsApp preview ---------- */
.wa-preview {
  background: #e5ded8; border-radius: var(--radius); padding: 16px; min-height: 200px;
  background-image: radial-gradient(rgba(0,0,0,.035) 1px, transparent 1px); background-size: 14px 14px;
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .wa-preview { background: #0d1a14; } }
.wa-bubble {
  background: #fff; border-radius: 8px 8px 8px 2px; padding: 8px 10px; max-width: 320px;
  box-shadow: 0 1px 1px rgba(0,0,0,.13); font-size: 13.5px; color: #111b21; line-height: 1.45;
  white-space: pre-wrap; word-break: break-word;
}
.wa-bubble.out { background: #d9fdd3; border-radius: 8px 8px 2px 8px; margin-left: auto; }
.wa-bubble .wa-h { font-weight: 680; margin-bottom: 4px; }
.wa-bubble .wa-f { font-size: 11.5px; color: #667781; margin-top: 5px; }
.wa-bubble .wa-t { font-size: 10.5px; color: #667781; text-align: right; margin-top: 2px; }
.wa-btns { margin-top: 6px; border-top: 1px solid #e9edef; padding-top: 4px; }
.wa-btn {
  display: block; text-align: center; color: #027eb5; font-size: 13.5px;
  padding: 6px; border-top: 1px solid #e9edef; font-weight: 500;
}
.wa-btn:first-child { border-top: none; }
.wa-var { background: #ffe9a8; border-radius: 3px; padding: 0 3px; color: #6b4f00; font-weight: 600; }

/* ---------- Inbox ---------- */
.inbox { display: grid; grid-template-columns: 310px 1fr 260px; height: calc(100vh - 69px); }
.inbox > div { min-width: 0; }
.conv-list { border-right: 1px solid var(--border); overflow-y: auto; background: var(--surface); }
.conv-filters { padding: 11px 13px; border-bottom: 1px solid var(--border); position: sticky; top: 0;
  background: var(--surface); z-index: 2; display: flex; gap: 6px; }
.conv {
  padding: 12px 14px; border-bottom: 1px solid var(--border); cursor: pointer; display: flex; gap: 10px;
}
.conv:hover { background: var(--surface-2); }
.conv.active { background: var(--brand-100); box-shadow: inset 3px 0 0 var(--brand); }
.conv .avatar {
  width: 36px; height: 36px; border-radius: 50%; background: var(--border);
  display: grid; place-items: center; font-weight: 640; font-size: 13px; color: var(--text-2); flex: none;
}
.conv .cbody { flex: 1; min-width: 0; }
.conv .cname { font-weight: 620; font-size: 13.5px; display: flex; gap: 6px; align-items: center; }
.conv .csnip { color: var(--text-2); font-size: 12.5px; margin-top: 1px; }
.conv .cmeta { font-size: 11px; color: var(--text-3); margin-top: 3px; display: flex; gap: 7px; align-items: center; }
.unread-dot { background: var(--brand); color: #fff; border-radius: 999px; font-size: 10.5px;
  padding: 0 6px; font-weight: 700; margin-left: auto; }

.thread { display: flex; flex-direction: column; background: var(--bg); }
.thread-head { padding: 12px 18px; border-bottom: 1px solid var(--border); background: var(--surface);
  display: flex; align-items: center; gap: 11px; }
.thread-msgs { flex: 1; overflow-y: auto; padding: 20px;
  background-image: radial-gradient(rgba(0,0,0,.03) 1px, transparent 1px); background-size: 16px 16px; }
.msg-row { display: flex; margin-bottom: 9px; }
.msg-row.out { justify-content: flex-end; }
.composer { border-top: 1px solid var(--border); padding: 12px 16px; background: var(--surface); }
.composer textarea { min-height: 44px; max-height: 130px; }
.composer-locked {
  background: var(--warn-bg); color: var(--warn); padding: 13px 15px; border-radius: var(--radius-sm);
  font-size: 13px; display: flex; gap: 10px; align-items: center;
}
.ctx-panel { border-left: 1px solid var(--border); background: var(--surface); overflow-y: auto; padding: 18px; }
.ctx-panel .kv { font-size: 12.5px; margin-bottom: 11px; }
.ctx-panel .kv .k { color: var(--text-2); font-size: 11px; text-transform: uppercase;
  letter-spacing: .05em; font-weight: 620; }
.ctx-panel .kv .v { margin-top: 1px; word-break: break-word; }

/* ---------- Auth ---------- */
.auth-wrap { min-height: 100vh; display: grid; grid-template-columns: 1fr 1fr; }
.auth-side { background: var(--sidebar); color: #fff; padding: 48px; display: flex;
  flex-direction: column; justify-content: center; }
.auth-side h1 { font-size: 32px; line-height: 1.2; margin-bottom: 14px; }
.auth-side p { color: #9db5aa; font-size: 15px; max-width: 400px; }
.auth-side ul { list-style: none; padding: 0; margin: 28px 0 0; }
.auth-side li { color: #cfe0d8; padding: 7px 0 7px 26px; position: relative; font-size: 14px; }
.auth-side li::before { content: "✓"; position: absolute; left: 0; color: var(--brand); font-weight: 700; }
.auth-main { display: grid; place-items: center; padding: 40px 24px; }
.auth-card { width: 100%; max-width: 380px; }
.auth-card h2 { margin-bottom: 5px; font-size: 22px; }
.auth-card .lede { color: var(--text-2); margin-bottom: 22px; }
.auth-switch { text-align: center; margin-top: 18px; font-size: 13px; color: var(--text-2); }

/* ---------- Misc ---------- */
.muted { color: var(--text-2); }
.small { font-size: 12.5px; }
.right { text-align: right; }
.center { text-align: center; }
.mt { margin-top: 16px; } .mb { margin-bottom: 16px; }
.flex { display: flex; gap: 10px; align-items: center; }
.flex-between { display: flex; gap: 10px; align-items: center; justify-content: space-between; }
.wrap-gap { display: flex; flex-wrap: wrap; gap: 7px; }
.divider { height: 1px; background: var(--border); margin: 18px 0; }
.sparkline { display: flex; align-items: flex-end; gap: 2px; height: 90px; }
.sparkline .sb { flex: 1; background: var(--brand); border-radius: 2px 2px 0 0; min-height: 2px;
  opacity: .85; transition: opacity .12s; }
.sparkline .sb:hover { opacity: 1; }
.copyable { display: flex; gap: 6px; align-items: center; }
.copyable input { font-family: var(--mono); font-size: 12px; }

@media (max-width: 1100px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .inbox { grid-template-columns: 280px 1fr; }
  .ctx-panel { display: none; }
}
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .nav { display: flex; overflow-x: auto; padding: 8px; }
  .nav-label, .sidebar-foot .who .meta { display: none; }
  .nav a { white-space: nowrap; }
  .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; }
  .auth-wrap { grid-template-columns: 1fr; }
  .auth-side { display: none; }
  .inbox { grid-template-columns: 1fr; height: auto; }
  .content { padding: 16px; }
  .topbar { padding: 14px 16px; }
}
