:root {
  --bg: #f6f6f8;
  --surface: #ffffff;
  --surface-2: #fafafb;
  --text: #24182b;
  --muted: #7a7383;
  --border: #e7e5ea;
  --primary: #2b1a33;
  --primary-text: #ffffff;
  --accent: #e4572e;
  --accent-soft: #fde9e2;
  --best: 228 87 46;            /* rgb triplet for best-time shading */
  --ig: #d62976;
  --fb: #1877f2;
  --ok: #1f9d55;
  --warn: #c98a00;
  --err: #d64545;
  --radius: 10px;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141217; --surface: #1d1a21; --surface-2: #221f27; --text: #ece9f0; --muted: #9c95a5; --border: #2f2b35;
    --primary: #ece9f0; --primary-text: #1d1a21; --accent-soft: #3a231c;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); }
.hidden { display: none !important; }
h1, h2, h3 { margin: 0 0 12px; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 22px; } h2 { font-size: 16px; } h3 { font-size: 14px; }
a { color: inherit; }
input, textarea, select, button { font: inherit; color: inherit; }
input[type=text], input[type=password], input[type=number], input[type=datetime-local], input[type=search], textarea, select {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface);
}
textarea { resize: vertical; min-height: 90px; }
label { display: block; color: var(--muted); font-size: 12px; margin-bottom: 10px; }
label > input, label > textarea, label > select { margin-top: 4px; color: var(--text); font-size: 14px; }
svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

.btn { border: 1px solid var(--border); background: var(--surface); padding: 7px 14px; border-radius: 8px; cursor: pointer; white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn.danger { color: var(--err); }
.btn.ghost { border-color: transparent; background: none; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.small { padding: 4px 10px; font-size: 12px; }
.btn.icon { padding: 7px 9px; }

.brand { font-size: 18px; letter-spacing: -0.02em; white-space: nowrap; }
.brand b { color: var(--accent); }
.brand span { color: var(--muted); font-size: 13px; margin-left: 2px; }

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 340px; display: grid; gap: 12px; }
.error { color: var(--err); min-height: 1em; margin: 0; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }

/* top bar */
.topbar { position: sticky; top: 0; z-index: 10; background: var(--surface); border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 28px; padding: 0 24px; height: 58px; }
.tabs { display: flex; gap: 4px; height: 100%; }
.tabs a { display: flex; align-items: center; gap: 7px; padding: 0 12px; text-decoration: none; color: var(--muted); border-bottom: 2px solid transparent; font-weight: 500; }
.tabs a:hover { color: var(--text); }
.tabs a.active { color: var(--text); border-bottom-color: var(--primary); }
.badge { background: var(--accent); color: #fff; border-radius: 10px; padding: 0 7px; font-size: 11px; line-height: 18px; }
.accounts { margin-left: auto; display: flex; gap: 10px; align-items: center; }
.avatar { position: relative; width: 32px; height: 32px; border-radius: 50%; background: var(--surface-2); border: 1px solid var(--border); display: grid; place-items: center; font-weight: 600; font-size: 12px; flex: none; }
.avatar img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; }
.avatar .net { position: absolute; right: -3px; bottom: -3px; }
.net { width: 15px; height: 15px; border-radius: 50%; display: grid; place-items: center; color: #fff; border: 2px solid var(--surface); box-sizing: content-box; }
.net svg { width: 9px; height: 9px; stroke-width: 2.4; }
.net.instagram { background: var(--ig); } .net.facebook { background: var(--fb); }
.acc-error { color: var(--err); font-size: 12px; max-width: 280px; }

main { padding: 20px 24px; min-width: 0; max-width: 1500px; margin: 0 auto; }

.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar .spacer { flex: 1; }
.range { min-width: 150px; text-align: center; font-weight: 500; }
.subtabs { display: flex; gap: 18px; border-bottom: 1px solid var(--border); margin-bottom: 14px; }
.subtabs button { border: 0; background: none; padding: 10px 0; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; font-weight: 500; }
.subtabs button.active { color: var(--text); border-bottom-color: var(--primary); }
.chip { border: 1px solid var(--border); border-radius: 999px; padding: 5px 10px 5px 6px; display: inline-flex; gap: 6px; align-items: center; cursor: pointer; background: var(--surface); font-size: 13px; }
.chip.off { opacity: .45; }
.chip .net { border: 0; }
.toggle { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 13px; color: var(--muted); }
.toggle input { display: none; }
.toggle i { width: 30px; height: 18px; border-radius: 9px; background: var(--border); position: relative; transition: background .15s; }
.toggle i::after { content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: #fff; transition: left .15s; }
.toggle input:checked + i { background: var(--accent); }
.toggle input:checked + i::after { left: 14px; }

/* calendar */
.calendar { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: auto; max-height: calc(100vh - 210px); }
.cal-grid { display: grid; grid-template-columns: 58px repeat(7, minmax(120px, 1fr)); min-width: 900px; }
.cal-head { position: sticky; top: 0; z-index: 2; background: var(--surface); border-bottom: 1px solid var(--border); padding: 8px 6px; text-align: center; }
.cal-head .wd { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.cal-head .dn { font-size: 18px; font-weight: 600; margin-top: 2px; }
.cal-head.today .dn { color: var(--accent); }
.cal-corner { position: sticky; top: 0; left: 0; z-index: 3; background: var(--surface); border-bottom: 1px solid var(--border); }
.cal-time { position: sticky; left: 0; z-index: 1; background: var(--surface); font-size: 11px; color: var(--muted); text-align: right; padding: 4px 8px 0 0; border-right: 1px solid var(--border); }
.cal-cell { min-height: 64px; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); padding: 3px; display: flex; flex-direction: column; gap: 3px; cursor: pointer; position: relative; }
.cal-cell:hover { background: var(--surface-2); }
.cal-cell.past { background: repeating-linear-gradient(135deg, transparent 0 6px, var(--surface-2) 6px 7px); cursor: default; }
.cal-cell.drop { outline: 2px dashed var(--accent); outline-offset: -3px; }
.cal-cell .add { position: absolute; right: 4px; top: 3px; font-size: 16px; color: var(--muted); opacity: 0; }
.cal-cell:hover .add { opacity: 1; }
.cal-cell.past .add { display: none; }
.now-line { position: absolute; left: 0; right: 0; height: 2px; background: var(--accent); z-index: 1; pointer-events: none; }

.pcard { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 5px 6px; display: grid; grid-template-columns: 1fr auto; gap: 6px; font-size: 11px; cursor: pointer; box-shadow: 0 1px 2px rgb(0 0 0 / .04); }
.pcard:hover { border-color: var(--muted); }
.pcard[draggable=true] { cursor: grab; }
.pcard .top { display: flex; gap: 4px; align-items: center; font-weight: 600; }
.pcard .top .net { border: 0; width: 13px; height: 13px; }
.pcard .txt { color: var(--muted); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; line-height: 1.3; }
.pcard img, .pcard video { width: 34px; height: 34px; object-fit: cover; border-radius: 5px; grid-row: span 2; background: var(--surface-2); }
.dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; flex: none; }
.dot.draft { background: var(--muted); } .dot.scheduled { background: var(--fb); } .dot.published { background: var(--ok); }
.dot.failed, .dot.partial { background: var(--err); } .dot.publishing { background: var(--warn); }
.legend-row { display: flex; gap: 14px; font-size: 12px; color: var(--muted); margin-top: 10px; flex-wrap: wrap; align-items: center; }
.legend-row span { display: inline-flex; gap: 5px; align-items: center; }
.best-swatch { width: 26px; height: 10px; border-radius: 3px; background: linear-gradient(90deg, rgb(var(--best) / .05), rgb(var(--best) / .32)); }
.drafts { margin-top: 18px; }
.drafts .list { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 8px; }

/* list view */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--muted); font-weight: 500; font-size: 12px; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td img.thumb, td video.thumb { width: 44px; height: 44px; object-fit: cover; border-radius: 6px; display: block; }
tr.click { cursor: pointer; } tr.click:hover td { background: var(--surface-2); }
.nets { display: inline-flex; gap: 3px; }
.nets .net { border: 0; }
.status-pill { display: inline-flex; gap: 6px; align-items: center; font-size: 12px; }

/* composer */
.composer { border: 1px solid var(--border); border-radius: 14px; padding: 0; width: min(960px, calc(100vw - 32px)); background: var(--surface); color: var(--text); }
.composer::backdrop { background: rgb(20 10 25 / .45); }
.composer form { display: grid; grid-template-columns: 1fr 320px; }
.composer .edit { padding: 22px; border-right: 1px solid var(--border); }
.composer .preview { padding: 22px; background: var(--surface-2); }
.composer .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 12px; flex-wrap: wrap; }
.net-pick { display: flex; gap: 8px; margin-bottom: 12px; }
.net-pick label { display: flex; gap: 8px; align-items: center; color: var(--text); font-size: 14px; margin: 0; border: 1px solid var(--border); border-radius: 999px; padding: 5px 12px 5px 6px; cursor: pointer; }
.net-pick input { display: none; }
.net-pick label:has(input:not(:checked)) { opacity: .4; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; margin-bottom: 12px; }
.seg label { margin: 0; padding: 6px 14px; color: var(--text); font-size: 13px; cursor: pointer; border-right: 1px solid var(--border); }
.seg label:last-child { border-right: 0; }
.seg input { display: none; }
.seg label:has(input:checked) { background: var(--primary); color: var(--primary-text); }
.drop { border: 1px dashed var(--border); border-radius: 8px; padding: 16px; text-align: center; color: var(--muted); cursor: pointer; margin-bottom: 10px; }
.drop.over { border-color: var(--accent); background: var(--accent-soft); }
.media-list { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.media-item { position: relative; width: 72px; height: 72px; }
.media-item img, .media-item video { width: 100%; height: 100%; object-fit: cover; border-radius: 6px; }
.media-item button { position: absolute; top: 2px; right: 2px; border: 0; border-radius: 50%; width: 20px; height: 20px; background: rgb(0 0 0 / .6); color: #fff; cursor: pointer; }
.counter { text-align: right; font-size: 11px; color: var(--muted); margin-top: -6px; margin-bottom: 10px; }
.ai-row { display: flex; gap: 6px; margin-bottom: 10px; }
.phone { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.phone .ph-head { padding: 9px 10px; font-weight: 600; font-size: 13px; display: flex; gap: 8px; align-items: center; }
.phone .ph-head .avatar { width: 26px; height: 26px; }
.phone img, .phone video { width: 100%; display: block; aspect-ratio: 1; object-fit: cover; background: var(--bg); }
.phone .ph-cap { padding: 8px 10px 12px; font-size: 12px; white-space: pre-wrap; max-height: 220px; overflow: auto; }
.results { margin-top: 12px; font-size: 12px; display: grid; gap: 4px; }
.results .failed { color: var(--err); }
.hint { font-size: 12px; color: var(--muted); margin: -4px 0 10px; }

/* inbox */
.inbox { display: grid; grid-template-columns: 360px 1fr; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); height: calc(100vh - 150px); overflow: hidden; }
.inbox .side { border-right: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; }
.inbox .side .filters { padding: 12px; border-bottom: 1px solid var(--border); display: grid; gap: 10px; }
.inbox .side .subtabs { margin: 0; border: 0; }
.inbox .list { overflow: auto; flex: 1; }
.msg-item { padding: 12px; border-bottom: 1px solid var(--border); cursor: pointer; display: grid; grid-template-columns: auto 1fr; gap: 10px; }
.msg-item:hover { background: var(--surface-2); }
.msg-item.active { background: var(--accent-soft); }
.msg-item .who { display: flex; justify-content: space-between; gap: 6px; font-weight: 600; font-size: 13px; }
.msg-item .when { color: var(--muted); font-weight: 400; font-size: 11px; white-space: nowrap; }
.msg-item .txt { color: var(--muted); font-size: 12px; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; margin-top: 2px; }
.msg-item .meta { display: flex; gap: 6px; align-items: center; margin-top: 4px; font-size: 11px; color: var(--muted); }
.status { font-size: 11px; font-weight: 500; }
.status.replied, .status.done { color: var(--ok); } .status.escalated, .status.failed { color: var(--err); } .status.new { color: var(--warn); } .status.ignored { color: var(--muted); }
.thread { display: flex; flex-direction: column; min-height: 0; }
.thread-head { padding: 12px 16px; border-bottom: 1px solid var(--border); display: flex; gap: 10px; align-items: center; }
.thread-head .ctx { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread .msgs { flex: 1; overflow: auto; padding: 16px; display: flex; flex-direction: column; gap: 8px; background: var(--surface-2); }
.bubble { max-width: 70%; padding: 9px 13px; border-radius: 14px; background: var(--surface); border: 1px solid var(--border); white-space: pre-wrap; }
.bubble.us { align-self: flex-end; background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.bubble small { display: block; font-size: 10px; opacity: .65; margin-top: 3px; }
.note { font-size: 12px; color: var(--muted); padding: 8px 16px; border-top: 1px solid var(--border); }
.reply { border-top: 1px solid var(--border); padding: 12px; display: flex; gap: 8px; align-items: flex-end; }
.reply textarea { min-height: 44px; }

/* analytics */
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px; margin-bottom: 14px; }
.kpi .label { font-size: 12px; color: var(--muted); display: flex; gap: 6px; align-items: center; }
.kpi .label .net { border: 0; }
.kpi .value { font-size: 26px; font-weight: 600; margin-top: 6px; font-variant-numeric: tabular-nums; }
.charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: 12px; margin-bottom: 14px; }
.chart svg { width: 100%; height: 190px; display: block; stroke-width: initial; }
.chart .legend { display: flex; gap: 12px; font-size: 12px; color: var(--muted); margin-top: 6px; }
.chart .legend i { display: inline-block; width: 10px; height: 3px; margin-right: 4px; vertical-align: middle; }

.settings { max-width: 760px; display: grid; gap: 14px; }
.settings textarea { min-height: 280px; font-family: ui-monospace, Menlo, monospace; font-size: 13px; }
.log { font-family: ui-monospace, Menlo, monospace; font-size: 12px; }
.log .error td { color: var(--err); }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--primary); color: var(--primary-text); padding: 10px 16px; border-radius: 8px; z-index: 50; max-width: calc(100vw - 32px); }
.empty { color: var(--muted); padding: 28px; text-align: center; }

@media (max-width: 900px) {
  .topbar { height: auto; flex-wrap: wrap; padding: 10px 16px 0; gap: 8px; }
  .tabs { order: 3; width: 100%; overflow-x: auto; height: 44px; }
  .tabs a { padding: 0 8px; }
  main { padding: 16px; }
  .composer form { grid-template-columns: 1fr; }
  .composer .edit { border-right: 0; }
  .inbox { grid-template-columns: 1fr; height: auto; }
  .inbox .list { max-height: 50vh; }
  .charts { grid-template-columns: 1fr; }
}
