/* Dashboard look. Tokens first; dark mode only changes tokens. */
:root {
  --bg: #f3f5f8; --card: #fff; --ink: #18212d; --muted: #667085; --line: #e4e8ee; --line-2: #eef1f5;
  --brand: #1b3a5c; --brand-2: #2b5a8a; --brand-soft: #e8eff7; --on-brand: #fff;
  --ok: #157347; --ok-soft: #e6f4ec; --warn: #a15c00; --warn-soft: #fdf1df; --bad: #b42318; --bad-soft: #fdecea;
  --soft: #f0f3f7; --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06); --shadow-lg: 0 8px 24px rgba(16, 24, 40, .14);
  --r: 12px; --r-sm: 8px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141a; --card: #171d25; --ink: #e7ebf0; --muted: #98a2b3; --line: #273140; --line-2: #1f2833;
    --brand: #6ea8e0; --brand-2: #8cbbe8; --brand-soft: #1c2a3a; --on-brand: #0f141a;
    --ok: #4cc287; --ok-soft: #15291f; --warn: #f0a94b; --warn-soft: #2d2213; --bad: #f07a6e; --bad-soft: #321a18;
    --soft: #1d2530; --shadow: none; --shadow-lg: 0 8px 24px rgba(0, 0, 0, .5);
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif; background: var(--bg); color: var(--ink); -webkit-font-smoothing: antialiased; font-variant-numeric: tabular-nums; }
h2 { margin: 0 0 4px; font-size: 20px; }
a { color: var(--brand); }
.muted { color: var(--muted); }
small { font-size: 12.5px; }

/* ---- header */
header { position: sticky; top: 0; z-index: 5; display: flex; gap: 16px; align-items: center; padding: 10px 20px; background: color-mix(in srgb, var(--card) 92%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
header > strong { display: flex; align-items: center; gap: 9px; color: var(--ink); font-size: 15.5px; white-space: nowrap; }
header > strong::before { content: "Rx"; display: grid; place-items: center; width: 30px; height: 30px; border-radius: 9px; background: var(--brand); color: var(--on-brand); font-size: 12.5px; font-weight: 800; letter-spacing: .3px; }
nav { display: flex; gap: 2px; padding: 3px; background: var(--soft); border-radius: 11px; overflow-x: auto; scrollbar-width: none; }
nav:empty { display: none; }
nav button { border: 0; background: none; color: var(--muted); border-radius: 8px; padding: 6px 14px; font: inherit; font-weight: 600; font-size: 14px; cursor: pointer; white-space: nowrap; }
nav button:hover { color: var(--ink); }
nav button.on { background: var(--card); color: var(--brand); box-shadow: var(--shadow); }
#me { margin-left: auto; display: flex; align-items: center; gap: 10px; font-size: 13.5px; white-space: nowrap; }

/* ---- buttons and fields */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--card); color: var(--ink); border-radius: var(--r-sm); padding: 7px 13px; font: inherit; font-size: 14px; font-weight: 500; cursor: pointer; transition: background .12s, border-color .12s; }
.btn:hover { background: var(--soft); }
.btn.primary { background: var(--brand); color: var(--on-brand); border-color: var(--brand); }
.btn.primary:hover { background: var(--brand-2); border-color: var(--brand-2); }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 45%, var(--line)); }
.btn.danger:hover { background: var(--bad-soft); }
.btn:disabled { opacity: .5; cursor: default; }
.btn:focus-visible, nav button:focus-visible, input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--brand) 55%, transparent); outline-offset: 1px; }
textarea, input, select { font: inherit; font-size: 14.5px; padding: 8px 10px; border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--card); color: var(--ink); }
input[type="checkbox"] { width: 17px; height: 17px; accent-color: var(--brand); vertical-align: -3px; }
textarea { width: 100%; min-height: 64px; resize: vertical; }
.field { display: grid; gap: 4px; } .field span { font-size: 12.5px; color: var(--muted); font-weight: 600; }

/* ---- layout */
main { padding: 20px; max-width: 1280px; margin: 0 auto; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.row > .row { margin-bottom: 0; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 16px 18px; box-shadow: var(--shadow); min-width: 0; }
.card h3 { margin: 0 0 12px; font-size: 13px; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: .4px; }
.card > p:last-child { margin-bottom: 0; }
.two { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 14px; margin-bottom: 14px; align-items: start; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar .title { margin-right: auto; }
.title h2 { font-size: 21px; } .title p { margin: 0; color: var(--muted); font-size: 13.5px; }

/* ---- numbers */
.grid { display: grid; gap: 12px; margin-bottom: 14px; }
.grid.hero { grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.grid.small { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.kpi { position: relative; overflow: hidden; }
.kpi .v { font-size: 24px; font-weight: 750; letter-spacing: -.3px; line-height: 1.2; }
.kpi .l { color: var(--muted); font-size: 13px; margin-top: 2px; }
.hero .kpi { padding: 18px 20px 16px 22px; }
.hero .kpi .v { font-size: 32px; }
.hero .kpi::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--brand); }
.hero .kpi.ok::before { background: var(--ok); } .hero .kpi.warn::before { background: var(--warn); } .hero .kpi.bad::before { background: var(--bad); }
.small .kpi { padding: 12px 14px; box-shadow: none; }
.small .kpi.alert { border-color: color-mix(in srgb, var(--warn) 40%, var(--line)); background: var(--warn-soft); }

/* ---- tables */
table { width: 100%; border-collapse: collapse; font-size: 14.5px; }
td, th { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
tr:last-child > td { border-bottom: 0; }
th { color: var(--muted); font-weight: 700; font-size: 12px; text-transform: uppercase; letter-spacing: .35px; border-bottom: 1px solid var(--line); }
td.num, th.num { text-align: right; white-space: nowrap; }
tr.item { cursor: pointer; } tr.item:hover > td { background: var(--soft); }
td .btn + .btn { margin-left: 6px; }
.scroll-x { overflow-x: auto; margin: 0 -4px; padding: 0 4px; }
td .actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }

/* ---- small charts */
.track { height: 10px; background: var(--soft); border-radius: 6px; overflow: hidden; }
.bar { height: 100%; background: var(--brand); border-radius: 6px; min-width: 3px; }
.chart { display: flex; align-items: flex-end; gap: 8px; height: 150px; padding-top: 6px; }
.chart > div { flex: 1; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 2px; font-size: 11.5px; color: var(--muted); }
.chart span.b { width: 100%; max-width: 34px; background: var(--brand); border-radius: 5px 5px 2px 2px; }
.chart span.b.c { background: color-mix(in srgb, var(--brand) 28%, transparent); }
.legend { display: flex; gap: 14px; font-size: 12.5px; color: var(--muted); margin-top: 10px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; background: var(--brand); margin-right: 5px; vertical-align: -1px; }
.legend i.c { background: color-mix(in srgb, var(--brand) 28%, transparent); }

/* ---- labels */
.tag { flex-shrink: 0; display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--soft); color: var(--muted); white-space: nowrap; line-height: 1.6; }
.tag.bad { color: var(--bad); background: var(--bad-soft); } .tag.warn { color: var(--warn); background: var(--warn-soft); } .tag.ok { color: var(--ok); background: var(--ok-soft); }
.tag.info { color: var(--brand); background: var(--brand-soft); }
span.bad { color: var(--bad); font-weight: 600; }
.note { padding: 10px 14px; border-radius: var(--r-sm); background: var(--brand-soft); margin: 0 0 14px; font-size: 14px; }
.note.bad { color: var(--bad); background: var(--bad-soft); }
.toast { position: fixed; right: 20px; bottom: 20px; left: auto; z-index: 20; max-width: min(440px, calc(100vw - 32px)); margin: 0; padding: 12px 16px; border-radius: 10px; background: var(--ink); color: var(--card); box-shadow: var(--shadow-lg); font-size: 14px; animation: rise .18s ease-out; }
.toast.bad { background: var(--bad); color: #fff; }
@keyframes rise { from { transform: translateY(8px); opacity: 0; } }

/* ---- avatars */
.av { flex-shrink: 0; display: grid; place-items: center; width: 38px; height: 38px; border-radius: 50%; font-size: 14px; font-weight: 700; color: #fff; background: var(--av, #5b7083); }
.av.lg { width: 42px; height: 42px; font-size: 15px; }

/* ---- inbox */
.inbox { display: grid; grid-template-columns: minmax(280px, 370px) 1fr; grid-template-rows: minmax(0, 1fr); gap: 14px; height: calc(100vh - 175px); min-height: 460px; }
.inbox > .card { padding: 0; overflow: hidden; }
.inbox > .list { overflow-y: auto; overflow-x: hidden; overscroll-behavior: contain; } /* must beat ".inbox > .card { overflow: hidden }" */
.list .item { display: flex; gap: 11px; padding: 12px 14px; border-bottom: 1px solid var(--line-2); cursor: pointer; border-left: 3px solid transparent; }
.list .item:hover { background: var(--soft); }
.list .item.sel { background: var(--brand-soft); border-left-color: var(--brand); }
.list .item .body { flex: 1; min-width: 0; }
.list .item .t { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.list .item .t strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14.5px; }
.list .item .t time { font-size: 12px; color: var(--muted); flex-shrink: 0; }
.list .item .last { color: var(--muted); font-size: 13.5px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; margin: 2px 0 6px; word-break: break-word; }
.list .item .foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.list .item .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--bad); margin-right: 6px; vertical-align: 1px; }
.list > p { padding: 16px; }

.chat { display: flex; flex-direction: column; min-height: 0; }
.chat > p.muted { margin: auto; }
.chat-head { padding: 12px 16px; border-bottom: 1px solid var(--line); display: grid; gap: 10px; }
.chat-head .who { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.chat-head .who strong { font-size: 16px; }
.chat-head .who .back { display: none; }
.chat-head .row { margin: 0; }
.msgs { flex: 1; overflow-y: auto; padding: 14px 16px; background: var(--bg); display: flex; flex-direction: column; gap: 6px; }
.m { max-width: min(78%, 620px); padding: 8px 12px; border-radius: 14px; white-space: pre-wrap; word-wrap: break-word; font-size: 14.5px; line-height: 1.45; }
.m.K { align-self: flex-start; background: var(--card); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.m.S, .m.N { align-self: flex-end; background: var(--brand); color: var(--on-brand); border-bottom-right-radius: 4px; }
.m.N { background: var(--ok); color: #fff; }
.m.A { align-self: center; max-width: 90%; background: var(--warn-soft); color: var(--warn); font-size: 12.5px; text-align: center; border-radius: 999px; padding: 4px 14px; }
.m .meta { display: block; font-size: 11px; opacity: .72; margin-top: 3px; }
.m.old { opacity: .78; } .m.S.old, .m.N.old { background: #64748b; color: #fff; }
.pic { display: block; max-width: 240px; max-height: 320px; border-radius: 10px; margin-bottom: 4px; cursor: zoom-in; }
audio { display: block; max-width: 260px; margin-bottom: 4px; }
.composer { border-top: 1px solid var(--line); padding: 12px 16px; display: grid; gap: 8px; background: var(--card); }
.composer textarea { min-height: 52px; max-height: 180px; }
.composer .row { margin: 0; }
.composer small { margin-left: auto; }

/* ---- settings and login */
.subnav { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 16px; }
.subnav .btn { border-radius: 999px; padding: 6px 14px; }
.script-card .row { margin: 6px 0 0; }
.script-card textarea { margin-top: 4px; }
.login { max-width: 380px; margin: 9vh auto; display: grid; gap: 12px; padding: 28px; }
.login::before { content: "Rx"; display: grid; place-items: center; width: 44px; height: 44px; border-radius: 12px; background: var(--brand); color: var(--on-brand); font-weight: 800; }
.login h2 { margin: 4px 0 2px; }
.login .btn { justify-content: center; padding: 10px; }
.qr { width: 260px; background: #fff; padding: 10px; border-radius: 12px; border: 1px solid var(--line); }

/* ---- phones */
@media (max-width: 760px) {
  header { gap: 10px; padding: 8px 12px; flex-wrap: wrap; }
  nav { order: 3; flex-basis: 100%; }
  #me .muted { display: none; }
  main { padding: 12px; }
  .inbox { grid-template-columns: 1fr; height: calc(100vh - 215px); height: calc(100dvh - 215px); min-height: 380px; }
  .title p { display: none; }
  .inbox.open .list { display: none; } .inbox:not(.open) .chat { display: none; }
  .chat-head .who .back { display: inline-flex; }
  .hero .kpi .v { font-size: 26px; }
  .grid.hero, .grid.small { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .m { max-width: 88%; }
  .composer small { display: none; }
}

/* ---- remarks on the bot's lines */
.m { position: relative; }
.fb-btn { display: inline; margin-left: 10px; border: 0; background: none; color: inherit; opacity: .8; font: inherit; font-size: 11.5px; font-weight: 600; cursor: pointer; padding: 0; }
.fb-btn:hover { opacity: 1; text-decoration: underline; }
@media (hover: hover) { .m .fb-btn { visibility: hidden; } .m:hover .fb-btn { visibility: visible; } }
.fb-wrap { display: flex; flex-direction: column; max-width: min(78%, 620px); width: 100%; }
.fb-wrap.S, .fb-wrap.N { align-self: flex-end; } .fb-wrap.A { align-self: center; } .fb-wrap.K { align-self: flex-start; }
.fb-note { background: var(--warn-soft); color: var(--warn); border-radius: 10px; padding: 6px 10px; font-size: 13px; white-space: pre-wrap; }
.fb-form { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px; display: grid; gap: 8px; box-shadow: var(--shadow); }
.fb-form .row { margin: 0; }
.m.pending { opacity: .8; border-style: dashed; }
.fb-card .row:first-child { margin-bottom: 10px; }
.fb-line { border-left: 3px solid var(--brand); padding: 4px 0 4px 12px; margin-bottom: 10px; white-space: pre-wrap; }
.fb-comment { background: var(--warn-soft); border-radius: var(--r-sm); padding: 10px 12px; white-space: pre-wrap; }
details { margin-top: 10px; } summary { cursor: pointer; color: var(--muted); font-size: 13.5px; }
.msgs.ctx { max-height: 360px; border-radius: var(--r-sm); margin-top: 8px; }

/* ---- customers */
.search { min-width: 240px; flex: 0 1 320px; }
.list .item .last.hit { color: var(--ink); }
.stats .stat { text-align: left; cursor: pointer; font: inherit; color: inherit; }
.stats .stat:hover { border-color: var(--brand); }
.stats .stat.on { border-color: var(--brand); box-shadow: 0 0 0 2px color-mix(in srgb, var(--brand) 30%, transparent); }
.stats .stat.warn .v { color: var(--warn); } .stats .stat.ok .v { color: var(--ok); } .stats .stat.bad .v { color: var(--bad); } .stats .stat.info .v { color: var(--brand); }
.selbar { position: sticky; top: 62px; z-index: 3; background: var(--bg); padding: 8px 0; margin: 0; }
table.cust td { vertical-align: top; }
.who-cell { display: flex; align-items: center; gap: 10px; min-width: 180px; }
.small { font-size: 13.5px; } .muted.small { font-size: 12.5px; }
.clip { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.clip2 { max-width: 420px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.profile .facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px 18px; margin: 14px 0; }
.profile .confirm { background: var(--soft); padding: 10px 12px; border-radius: var(--r-sm); }
.profile textarea { margin-top: 4px; }
@media (max-width: 760px) { .search { min-width: 0; flex: 1 1 100%; } .selbar { top: 100px; } }
.grid.small.stats { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
