/* ============================================================
   Broadcaster — a subtle, premium design system
   ============================================================ */
:root {
  --paper:      #FBFAF7;
  --surface:    #FFFFFF;
  --surface-2:  #F4F2EC;
  --ink:        #1C1B19;
  --ink-soft:   #55524C;
  --muted:      #8B877E;
  --line:       #E7E3DA;
  --line-soft:  #F0EDE5;
  --gold:       #B0894F;   /* antique champagne gold */
  --gold-deep:  #97723B;
  --gold-tint:  #F6EFE1;
  --green:      #1E6B54;   /* deep emerald for "live"/success */
  --green-tint: #E7F1EC;
  --red:        #B4463C;
  --red-tint:   #F7E9E7;
  --amber:      #B5842B;
  --amber-tint: #F8EFD9;

  --shadow-sm: 0 1px 2px rgba(28,27,25,.05), 0 1px 3px rgba(28,27,25,.04);
  --shadow-md: 0 4px 14px rgba(28,27,25,.07), 0 1px 3px rgba(28,27,25,.05);
  --shadow-lg: 0 18px 50px rgba(28,27,25,.16), 0 4px 12px rgba(28,27,25,.08);
  --radius: 14px;
  --radius-sm: 10px;
  --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
  --font-serif: 'Fraunces', Georgia, serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper:      #16150F;
    --surface:    #201E17;
    --surface-2:  #272419;
    --ink:        #F1EEE6;
    --ink-soft:   #C4BEB0;
    --muted:      #928C7C;
    --line:       #34301F;
    --line-soft:  #2A2718;
    --gold:       #D6B678;
    --gold-deep:  #C9A863;
    --gold-tint:  #2C2718;
    --green:      #57B891;
    --green-tint: #1B2B23;
    --red:        #E28B82;
    --red-tint:   #2E211F;
    --amber:      #E0BA6A;
    --amber-tint: #2B2515;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.3);
    --shadow-md: 0 4px 16px rgba(0,0,0,.4);
    --shadow-lg: 0 20px 55px rgba(0,0,0,.6);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-sans);
  background: var(--paper);
  color: var(--ink);
  font-size: 14.5px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
.serif { font-family: var(--font-serif); font-weight: 500; letter-spacing: -.01em; }
.muted { color: var(--muted); }
.tiny  { font-size: 12.5px; }
.small { font-size: 13px; }
.right { text-align: right; }
.spacer { flex: 1; }
code {
  font-family: ui-monospace, monospace; font-size: .85em;
  background: var(--surface-2); padding: 1px 6px; border-radius: 6px; color: var(--gold-deep);
}
h1,h2,h3 { margin: 0; }

/* ---------- brand marks ---------- */
.mark { color: var(--gold); font-size: 20px; }
.mark.sm { font-size: 16px; }
.mark.lg { font-size: 40px; }

/* ---------- login ---------- */
.login-wrap {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background:
    radial-gradient(1200px 600px at 50% -10%, var(--gold-tint), transparent 60%),
    var(--paper);
}
.login-card {
  width: 100%; max-width: 360px; background: var(--surface);
  border: 1px solid var(--line); border-radius: 20px; padding: 40px 32px;
  box-shadow: var(--shadow-lg); text-align: center;
}
.login-card .mark { font-size: 34px; }
.login-card h1 { font-size: 30px; margin: 10px 0 2px; }
.login-card form { margin-top: 22px; display: grid; gap: 12px; }
.err { color: var(--red); font-size: 13px; margin: 12px 0 0; min-height: 18px; }

/* ---------- inputs ---------- */
input, select, textarea {
  font-family: inherit; font-size: 14px; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 10px 13px; width: 100%;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--gold);
  box-shadow: 0 0 0 3px var(--gold-tint);
}
textarea { resize: vertical; min-height: 90px; line-height: 1.55; }
label.field { display: block; text-align: left; margin-bottom: 14px; }
label.field > span { display: block; font-size: 12.5px; color: var(--ink-soft); margin-bottom: 6px; font-weight: 500; }

/* ---------- buttons ---------- */
.btn {
  font-family: inherit; font-size: 13.5px; font-weight: 500; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  padding: 9px 16px; border-radius: var(--radius-sm);
  transition: all .15s ease; white-space: nowrap; display: inline-flex; align-items: center; gap: 7px;
}
.btn:hover { border-color: var(--gold); color: var(--gold-deep); }
.btn.primary {
  background: linear-gradient(180deg, var(--ink) 0%, #000 140%); color: var(--paper);
  border-color: var(--ink);
}
.btn.primary:hover { filter: brightness(1.12); color: var(--paper); }
.btn.ghost { background: transparent; }
.btn.block { width: 100%; justify-content: center; padding: 11px; }
.btn.sm { padding: 6px 12px; font-size: 12.5px; }
.btn.danger { color: var(--red); border-color: var(--red-tint); }
.btn.danger:hover { background: var(--red-tint); border-color: var(--red); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.icon-btn {
  border: 1px solid var(--line); background: var(--surface); color: var(--ink-soft);
  width: 34px; height: 34px; border-radius: 9px; cursor: pointer; font-size: 15px;
  transition: all .15s;
}
.icon-btn:hover { border-color: var(--gold); color: var(--gold); }

/* ---------- topbar ---------- */
.topbar {
  display: flex; align-items: center; gap: 18px;
  padding: 14px 24px; background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 9px; font-size: 17px; }
.acct-switch { display: flex; align-items: center; gap: 8px; }
.acct-switch label { margin-right: 2px; }
.select-wrap { position: relative; }
.select-wrap::after {
  content: '▾'; position: absolute; right: 12px; top: 50%; transform: translateY(-50%);
  pointer-events: none; color: var(--muted); font-size: 11px;
}
#accountSelect { padding: 8px 32px 8px 13px; min-width: 190px; appearance: none; font-weight: 500; }
.mode-pill { font-size: 12px; font-weight: 500; padding: 5px 12px; border-radius: 999px; }
.mode-pill.test { background: var(--amber-tint); color: var(--amber); }
.mode-pill.live { background: var(--green-tint); color: var(--green); }

/* ---------- workspace ---------- */
#workspace { max-width: 1080px; margin: 0 auto; padding: 30px 24px 80px; }
.tabs {
  display: inline-flex; gap: 3px; background: var(--surface-2);
  padding: 4px; border-radius: 12px; margin-bottom: 26px;
}
.tab {
  border: none; background: transparent; color: var(--ink-soft); cursor: pointer;
  font-family: inherit; font-size: 13.5px; font-weight: 500; padding: 8px 18px; border-radius: 9px;
  transition: all .15s;
}
.tab:hover { color: var(--ink); }
.tab.active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm); }
.req-count { background: var(--red); color: #fff; font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 999px; margin-left: 4px; }

.panel-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.panel-head h2 { font-size: 24px; }
.actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.search input { min-width: 220px; }

/* ---------- cards & tables ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.table-card { overflow: hidden; }
table.data { width: 100%; border-collapse: collapse; }
table.data th {
  text-align: left; font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); padding: 13px 18px; border-bottom: 1px solid var(--line); background: var(--surface-2);
}
table.data td { padding: 13px 18px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
table.data tr:last-child td { border-bottom: none; }
table.data tbody tr { transition: background .12s; }
table.data tbody tr:hover { background: var(--surface-2); }
.phone-cell { font-variant-numeric: tabular-nums; color: var(--ink-soft); }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.link-btn { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 13px; padding: 4px 6px; border-radius: 6px; }
.link-btn:hover { color: var(--gold-deep); background: var(--gold-tint); }
.link-btn.danger:hover { color: var(--red); background: var(--red-tint); }
.empty-row { padding: 40px; text-align: center; color: var(--muted); }

/* ---------- badges ---------- */
.badge { font-size: 11.5px; font-weight: 500; padding: 3px 9px; border-radius: 999px; display: inline-block; }
.badge.ok    { background: var(--green-tint); color: var(--green); }
.badge.out   { background: var(--red-tint); color: var(--red); }
.badge.pending { background: var(--surface-2); color: var(--muted); }
.badge.sent  { background: var(--gold-tint); color: var(--gold-deep); }
.badge.delivered { background: var(--green-tint); color: var(--green); }
.badge.read  { background: var(--green-tint); color: var(--green); }
.badge.failed { background: var(--red-tint); color: var(--red); }
.badge.approved { background: var(--green-tint); color: var(--green); }
.badge.rejected { background: var(--red-tint); color: var(--red); }

/* ---------- generic cards grid ---------- */
.cards { display: grid; gap: 14px; }
.item-card { padding: 18px 20px; }
.item-card .row { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.item-card h3 { font-size: 16px; font-family: var(--font-serif); }
.tmpl-body { margin: 10px 0 0; color: var(--ink-soft); font-size: 13.5px; background: var(--surface-2); padding: 12px 14px; border-radius: var(--radius-sm); white-space: pre-wrap; }

/* ---------- broadcast progress ---------- */
.progress { height: 7px; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin: 12px 0 10px; display: flex; }
.progress > i { display: block; height: 100%; }
.progress .p-read { background: var(--green); }
.progress .p-delivered { background: #7FBFA5; }
.progress .p-sent { background: var(--gold); }
.progress .p-failed { background: var(--red); }
.stat-row { display: flex; gap: 20px; flex-wrap: wrap; font-size: 12.5px; color: var(--ink-soft); }
.stat-row b { color: var(--ink); font-variant-numeric: tabular-nums; }

/* ---------- KPI cards (portal dashboard) ---------- */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; margin-bottom: 8px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow-sm); }
.kpi .num { font-family: var(--font-serif); font-size: 30px; font-weight: 500; letter-spacing: -.02em; line-height: 1.1; }
.kpi .lbl { color: var(--muted); font-size: 12.5px; margin-top: 4px; }
.kpi .num.accent { color: var(--gold-deep); }

/* ---------- empty hero ---------- */
.empty-hero { max-width: 460px; margin: 90px auto; text-align: center; }
.empty-hero h2 { font-size: 28px; margin: 14px 0 6px; }
.empty-hero .btn { margin-top: 20px; }

/* ---------- notice ---------- */
.notice { padding: 12px 16px; border-radius: var(--radius-sm); margin-bottom: 16px; font-size: 13.5px; border: 1px solid var(--line); background: var(--surface); }
.notice.ok { background: var(--green-tint); border-color: transparent; color: var(--green); }
.notice.warn { background: var(--amber-tint); border-color: transparent; color: var(--amber); }

/* ---------- modal ---------- */
.modal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 24px;
  background: rgba(20,18,14,.42); backdrop-filter: blur(4px); }
.modal-card {
  width: 100%; max-width: 520px; max-height: 88vh; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 18px; padding: 26px 26px 24px; box-shadow: var(--shadow-lg);
}
.modal-card h3 { font-family: var(--font-serif); font-size: 21px; margin-bottom: 4px; }
.modal-card .sub { color: var(--muted); font-size: 13px; margin-bottom: 20px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }

/* ---------- toast ---------- */
.toast {
  position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%) translateY(10px);
  background: var(--ink); color: var(--paper); padding: 12px 20px; border-radius: 999px;
  font-size: 13.5px; box-shadow: var(--shadow-lg); opacity: 0; transition: all .25s; z-index: 60;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: var(--red); }

@media (max-width: 620px) {
  .topbar { flex-wrap: wrap; gap: 10px; }
  .acct-switch { order: 3; width: 100%; }
  #accountSelect { flex: 1; }
  .two-col { grid-template-columns: 1fr; }
  .panel-head { flex-direction: column; align-items: stretch; }
  .search input { min-width: 0; width: 100%; }
}
