/*
 * One stylesheet for the dashboard. Dark and light from the same tokens,
 * switched on the viewer's own setting.
 */

:root {
  color-scheme: light dark;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --panel-2: #f8f9fb;
  --ink: #16191d;
  --muted: #61696f;
  --line: #dfe3e8;
  --accent: #335c81;
  --accent-ink: #ffffff;
  --ok-bg: #e4f3e8;
  --ok-ink: #1d6b33;
  --warn-bg: #fff4e0;
  --warn-ink: #8a5a00;
  --error: #b3261e;
  --error-bg: #fdecea;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(0,0,0,0.05), 0 4px 16px rgba(0,0,0,0.04);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171a; --panel: #1c2024; --panel-2: #22272c; --ink: #e8eaed; --muted: #9aa2a9; --line: #2e343a;
    --accent: #6f9dc7; --accent-ink: #10151a; --ok-bg: #1c3a25; --ok-ink: #7fc894; --warn-bg: #3a2e12; --warn-ink: #f5c86a; --error: #f2b8b5; --error-bg: #3a1f1d;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 14.5px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif; }
::selection { background: color-mix(in srgb, var(--accent) 28%, transparent); }
input, textarea, select, button { font: inherit; color: inherit; }
input, textarea, select { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 10px; width: 100%; }
input:focus, textarea:focus, select:focus { outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent); border-color: var(--accent); }
textarea { resize: vertical; min-height: 80px; }
label { display: block; font-size: 13px; color: var(--muted); margin: 10px 0 4px; }
label.inline { display: inline-flex; align-items: center; gap: 6px; margin: 6px 12px 6px 0; color: var(--ink); }
label.inline input { width: auto; }
a { color: var(--accent); }
h1, h2, h3 { margin: 0 0 8px; line-height: 1.25; }
h1 { font-size: 22px; } h2 { font-size: 17px; } h3 { font-size: 15px; }
p { margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.error { color: var(--error); }
code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }
pre { background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; overflow-x: auto; white-space: pre-wrap; word-break: break-all; }

button, .btn { cursor: pointer; border: 1px solid var(--line); background: var(--panel); color: var(--ink); border-radius: var(--radius); padding: 7px 12px; }
button:hover, .btn:hover { background: var(--panel-2); }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.primary:hover { filter: brightness(1.08); background: var(--accent); }
button.danger { color: var(--error); border-color: color-mix(in srgb, var(--error) 40%, var(--line)); }
button.link { border: 0; background: none; padding: 0; color: var(--accent); }
button:disabled { opacity: 0.5; cursor: default; }
button.sm { padding: 4px 8px; font-size: 13px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grid { display: grid; gap: 12px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.grid.three { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 16px; box-shadow: var(--shadow); }
.card.flat { box-shadow: none; }
.pill { display: inline-block; padding: 2px 8px; border-radius: 12px; font-size: 12px; background: var(--panel-2); border: 1px solid var(--line); }
.pill.ok { background: var(--ok-bg); color: var(--ok-ink); border-color: transparent; }
.pill.warn { background: var(--warn-bg); color: var(--warn-ink); border-color: transparent; }
.pill.err { background: var(--error-bg); color: var(--error); border-color: transparent; }
.pill.accent { background: color-mix(in srgb, var(--accent) 15%, var(--panel)); color: var(--accent); border-color: transparent; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12.5px; color: var(--muted); font-weight: 600; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--panel-2); }
.empty { padding: 32px; text-align: center; color: var(--muted); }
.stack > * + * { margin-top: 12px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; flex-wrap: wrap; }
.tabs button { border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: none; padding: 8px 12px; color: var(--muted); }
.tabs button.on { color: var(--ink); border-bottom-color: var(--accent); }
.field-help { font-size: 12.5px; color: var(--muted); margin-top: 2px; }

/* sign-in */
.signin { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.signin .card { width: min(420px, 100%); }
.signin h1 { margin-bottom: 4px; }
.signin button { width: 100%; margin-top: 14px; background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.forgot { display: inline-block; margin: 12px 12px 0 0; font-size: 13px; }

/* shell */
.shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: 14px 12px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; }
.brand-mark { width: 26px; height: 26px; border-radius: 7px; background: var(--accent); flex: 0 0 auto; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a { display: flex; align-items: center; justify-content: space-between; padding: 8px 10px; border-radius: var(--radius); color: var(--ink); text-decoration: none; }
.nav a:hover { background: var(--panel-2); }
.nav a.on { background: color-mix(in srgb, var(--accent) 14%, var(--panel)); color: var(--accent); font-weight: 600; }
.nav .count { font-size: 12px; background: var(--accent); color: var(--accent-ink); border-radius: 10px; padding: 0 7px; }
.sidebar-foot { margin-top: auto; font-size: 13px; }
.away-toggle { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; }
.away-toggle input { width: auto; }
.me { display: flex; justify-content: space-between; gap: 8px; color: var(--muted); }
.view { padding: 22px 26px; min-width: 0; }
.view > header { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 8px; }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .sidebar-foot { margin-top: 0; margin-left: auto; }
  .view { padding: 14px; }
}

/* toasts */
.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 50; }
.toast { background: var(--ink); color: var(--bg); padding: 10px 14px; border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,0.25); max-width: 360px; cursor: pointer; }
.toast.error { background: var(--error); color: #fff; }

/* modal */
.modal-back { position: fixed; inset: 0; background: rgba(0,0,0,0.45); display: grid; place-items: center; z-index: 40; padding: 16px; }
.modal { background: var(--panel); border-radius: 14px; padding: 20px; width: min(560px, 100%); max-height: 90vh; overflow: auto; box-shadow: 0 20px 60px rgba(0,0,0,0.35); }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

/* inbox */
.inbox { display: grid; grid-template-columns: 320px 1fr 280px; gap: 0; height: calc(100vh - 44px); margin: -22px -26px; border-top: 1px solid var(--line); }
.inbox > * { min-width: 0; min-height: 0; }
.inbox-list { border-right: 1px solid var(--line); display: flex; flex-direction: column; background: var(--panel); }
.inbox-filters { padding: 10px; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 6px; }
.inbox-filters .row { gap: 4px; }
.inbox-filters button { padding: 4px 8px; font-size: 12.5px; }
.inbox-filters button.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.inbox-items { overflow-y: auto; flex: 1; }
.conv-item { display: block; width: 100%; text-align: left; border: 0; border-bottom: 1px solid var(--line); border-radius: 0; background: none; padding: 10px 12px; }
.conv-item:hover { background: var(--panel-2); }
.conv-item.on { background: color-mix(in srgb, var(--accent) 12%, var(--panel)); }
.conv-item .top { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; }
.conv-item .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-item .time { color: var(--muted); font-size: 12px; flex: 0 0 auto; }
.conv-item .preview { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 2px; }
.conv-item .tags { display: flex; gap: 4px; margin-top: 4px; flex-wrap: wrap; }
.conv-item.unread .name { color: var(--accent); }
.conv-item.unread .preview { color: var(--ink); font-weight: 600; }
.badge-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); margin-right: 6px; vertical-align: middle; }
.badge-dot.on { background: #22c55e; }
.badge-dot.bot { background: var(--accent); }

.conv-pane { display: flex; flex-direction: column; background: var(--bg); }
.conv-head { padding: 10px 14px; border-bottom: 1px solid var(--line); background: var(--panel); display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.conv-head .title { font-weight: 600; flex: 1; min-width: 120px; }
.conv-log { flex: 1; overflow-y: auto; padding: 14px 16px; display: flex; flex-direction: column; }
.m { max-width: 76%; margin: 3px 0; display: flex; flex-direction: column; }
.m.visitor { align-self: flex-start; }
.m.operator, .m.bot { align-self: flex-end; align-items: flex-end; }
.m .who { font-size: 11.5px; color: var(--muted); margin: 4px 4px 2px; }
.m .b { padding: 8px 12px; border-radius: 14px; background: var(--panel); border: 1px solid var(--line); white-space: pre-wrap; overflow-wrap: anywhere; }
.m.visitor .b { border-bottom-left-radius: 4px; }
.m.operator .b { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); border-bottom-right-radius: 4px; }
.m.bot .b { background: color-mix(in srgb, var(--accent) 12%, var(--panel)); border-bottom-right-radius: 4px; }
/* A bot reply still being written: a blinking caret after the text so far. */
.m.streaming .b::after { content: "▍"; margin-left: 1px; color: var(--accent); animation: caret-blink 1s infinite; }
@keyframes caret-blink { 50% { opacity: 0; } }
.m.private .b { background: var(--warn-bg); color: var(--warn-ink); border-color: transparent; }
.m .t { font-size: 11px; color: var(--muted); margin: 2px 4px 0; }
.m .extras { font-size: 12px; color: var(--muted); margin: 3px 4px 0; }
.ev { align-self: center; color: var(--muted); font-size: 12.5px; margin: 6px 0; text-align: center; }
.composer { border-top: 1px solid var(--line); background: var(--panel); padding: 10px 12px; }
.composer textarea { min-height: 64px; }
.composer .row { margin-top: 6px; }
.composer.note textarea { background: var(--warn-bg); }
.canned-pop { position: absolute; bottom: 100%; left: 0; right: 0; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); max-height: 220px; overflow: auto; z-index: 5; }
.canned-pop button { display: block; width: 100%; text-align: left; border: 0; border-radius: 0; padding: 8px 10px; }
.canned-pop button:hover, .canned-pop button.on { background: var(--panel-2); }
.side { border-left: 1px solid var(--line); background: var(--panel); overflow-y: auto; padding: 14px; font-size: 13.5px; }
.side h3 { font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; margin: 14px 0 6px; }
.side h3:first-child { margin-top: 0; }
.side dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 3px 10px; }
.side dt { color: var(--muted); }
.side dd { margin: 0; overflow-wrap: anywhere; }
.typing-dots { color: var(--muted); font-size: 12.5px; padding: 4px 0; }
@media (max-width: 1100px) { .inbox { grid-template-columns: 280px 1fr; } .side { display: none; } }
@media (max-width: 860px) { .inbox { grid-template-columns: 1fr; height: auto; margin: -14px; } .inbox-list { max-height: 40vh; } .inbox.showing-conv .inbox-list { display: none; } .conv-pane { min-height: 70vh; } }

/* widgets */
.preview-wrap { position: relative; background: repeating-linear-gradient(45deg, var(--panel-2), var(--panel-2) 10px, var(--panel) 10px, var(--panel) 20px); border: 1px solid var(--line); border-radius: 12px; min-height: 620px; overflow: hidden; }
.preview-wrap iframe { position: absolute; right: 16px; bottom: 16px; width: 380px; height: 580px; border: 0; border-radius: 16px; box-shadow: 0 16px 48px rgba(0,0,0,0.28); background: transparent; }
.swatch { display: inline-block; width: 18px; height: 18px; border-radius: 4px; vertical-align: middle; border: 1px solid var(--line); }
input[type="color"] { width: 48px; padding: 2px; height: 34px; }
.hours-row { display: grid; grid-template-columns: 1fr auto auto auto; gap: 6px; align-items: center; margin-bottom: 6px; }
.days button { padding: 3px 7px; font-size: 12px; }
.days button.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

/* stats */
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px; }
.stat .n { font-size: 26px; font-weight: 700; line-height: 1.1; }
.stat .l { color: var(--muted); font-size: 12.5px; }
.bars { display: flex; align-items: flex-end; gap: 3px; height: 120px; }
.bars div { flex: 1; background: var(--accent); border-radius: 3px 3px 0 0; min-height: 2px; position: relative; }
.bars div:hover::after { content: attr(data-label); position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg); font-size: 11px; padding: 2px 6px; border-radius: 4px; white-space: nowrap; }
.playground { display: flex; flex-direction: column; gap: 8px; max-height: 480px; overflow-y: auto; padding: 8px; background: var(--panel-2); border-radius: 10px; border: 1px solid var(--line); }
.stars-sm { color: #f5a623; letter-spacing: 1px; }
.kbd { font-family: ui-monospace, monospace; font-size: 11.5px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; }
