:root {
  --bg: #0b0c0e; --panel: #121316; --panel-2: #181a1e; --line: #24272d; --line-2: #2f333b;
  --text: #e9eaec; --text-2: #a6a9b0; --muted: #70747d;
  --accent: #7cc4a4; --accent-ink: #06150e; --good: #45cf9a; --bad: #f2617f; --warn: #efc24f; --info: #6fb3e0;
  --r: 9px;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif;
  font-size: 14px; color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font-variant-numeric: tabular-nums; }
a { color: var(--info); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
h1 { font-size: 20px; font-weight: 600; margin: 0 0 4px; }
h2 { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .09em; color: var(--text-2); margin: 26px 0 10px; }
.sub { color: var(--muted); margin: 0 0 18px; font-size: 13px; }
.muted { color: var(--muted); } .small { font-size: 12px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.right { margin-left: auto; }

input, select, textarea { background: var(--panel); border: 1px solid var(--line-2); border-radius: 7px; padding: 7px 9px; font-size: 13px; }
textarea { width: 100%; resize: vertical; line-height: 1.5; }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.btn { background: var(--panel-2); border: 1px solid var(--line-2); border-radius: 7px; padding: 7px 12px; cursor: pointer; font-size: 13px; white-space: nowrap; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 45%, var(--line-2)); }
.btn.sm { padding: 4px 9px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: default; }
.seg { display: inline-flex; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 2px; }
.seg button { background: none; border: 0; padding: 5px 10px; border-radius: 6px; color: var(--text-2); cursor: pointer; font-size: 13px; }
.seg button.on { background: var(--line-2); color: var(--text); }

/* shell */
.app { display: grid; grid-template-columns: 188px 1fr; grid-template-rows: 52px 1fr; height: 100vh; }
.top { grid-column: 1 / -1; display: flex; align-items: center; gap: 14px; padding: 0 16px; border-bottom: 1px solid var(--line); background: var(--panel); }
.brand { font-weight: 700; font-size: 15px; width: 172px; letter-spacing: .01em; }
.brand span { color: var(--accent); }
.clock { display: flex; align-items: center; gap: 8px; padding: 5px 10px; border: 1px solid var(--line-2); border-radius: 8px; font-size: 13px; }
.clock .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--good); box-shadow: 0 0 0 3px color-mix(in srgb, var(--good) 22%, transparent); }
.clock b { font-weight: 600; }
.quota { font-size: 12px; color: var(--text-2); display: flex; gap: 14px; }
.quota b { color: var(--text); font-weight: 600; }
.quota .hot b { color: var(--warn); }
nav.side { border-right: 1px solid var(--line); padding: 12px 8px; display: flex; flex-direction: column; gap: 2px; overflow: auto; }
nav.side a { color: var(--text-2); padding: 8px 10px; border-radius: 7px; display: flex; justify-content: space-between; }
nav.side a:hover { background: var(--panel-2); color: var(--text); text-decoration: none; }
nav.side a.on { background: var(--panel-2); color: var(--text); box-shadow: inset 2px 0 0 var(--accent); }
nav.side .sep { margin: 10px 10px 4px; font-size: 11px; letter-spacing: .09em; text-transform: uppercase; color: var(--muted); }
nav.side .foot { margin-top: auto; padding: 10px; font-size: 12px; color: var(--muted); line-height: 1.6; }
.count { background: var(--line-2); border-radius: 20px; padding: 0 7px; font-size: 11px; line-height: 18px; color: var(--text); }
main { overflow: auto; min-width: 0; min-height: 0; }
.page { padding: 22px 26px 60px; max-width: 1180px; }

/* inbox */
.inbox { display: grid; grid-template-columns: 330px minmax(0, 1fr) 360px; height: 100%; }
.inbox > * { min-height: 0; overflow: auto; }
.list { border-right: 1px solid var(--line); display: flex; flex-direction: column; }
.list .bar { padding: 10px; border-bottom: 1px solid var(--line); display: grid; gap: 8px; position: sticky; top: 0; background: var(--bg); z-index: 1; }
.list .bar select, .list .bar input { width: 100%; }
.conv { display: block; padding: 11px 12px; border-bottom: 1px solid var(--line); cursor: pointer; color: inherit; background: none; border-left: 2px solid transparent; width: 100%; text-align: left; border-top: 0; border-right: 0; }
.conv:hover { background: var(--panel); }
.conv.on { background: var(--panel-2); border-left-color: var(--accent); }
.conv .who { display: flex; justify-content: space-between; gap: 8px; }
.conv .who span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv.unread .who span:first-child, .conv.unread .subj { font-weight: 650; color: var(--text); }
.conv .subj { color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.conv .prev { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.conv .meta { display: flex; gap: 6px; margin-top: 6px; flex-wrap: wrap; }
.tag { font-size: 11px; padding: 1px 7px; border-radius: 20px; border: 1px solid var(--line-2); color: var(--text-2); white-space: nowrap; }
.tag.good { color: var(--good); border-color: color-mix(in srgb, var(--good) 40%, var(--line-2)); }
.tag.bad { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, var(--line-2)); }
.tag.warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 40%, var(--line-2)); }
.tag.info { color: var(--info); border-color: color-mix(in srgb, var(--info) 40%, var(--line-2)); }
.thread { display: flex; flex-direction: column; }
.thread .hd { padding: 14px 18px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--bg); z-index: 1; }
.thread .hd h1 { font-size: 16px; overflow-wrap: anywhere; }
.msgs { padding: 16px 18px; display: grid; gap: 12px; flex: 1; align-content: start; }
.msg { border: 1px solid var(--line); border-radius: var(--r); background: var(--panel); padding: 11px 13px; max-width: 760px; }
.msg.out { background: #13201b; border-color: #22382f; margin-left: 40px; }
.msg.note { background: #211d10; border-color: #3d3415; margin-left: 40px; }
.msg .mh { display: flex; justify-content: space-between; gap: 10px; font-size: 12px; color: var(--text-2); margin-bottom: 6px; }
.msg .mb { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.55; }
.msg iframe { width: 100%; height: 420px; border: 0; background: #fff; border-radius: 6px; }
.reply { border-top: 1px solid var(--line); padding: 12px 18px 16px; background: var(--bg); position: sticky; bottom: 0; }
.empty { color: var(--muted); padding: 40px 20px; text-align: center; }
.cust { border-left: 1px solid var(--line); padding: 14px; background: var(--panel); }
.cust h2:first-child { margin-top: 0; }

/* cards */
.card { border: 1px solid var(--line); border-radius: var(--r); background: var(--panel-2); padding: 11px 12px; margin-bottom: 10px; }
.card .ch { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.card .ch b { font-weight: 600; }
.card .items { margin: 8px 0; color: var(--text-2); font-size: 13px; display: grid; gap: 2px; }
.card .kv { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; font-size: 12px; color: var(--text-2); margin-top: 6px; }
.card .kv span:nth-child(odd) { color: var(--muted); }
.card .act { margin-top: 10px; display: flex; gap: 8px; flex-wrap: wrap; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 12px; }
.cards .card { margin: 0; }
.err { color: var(--bad); font-size: 12px; margin: 6px 0; overflow-wrap: anywhere; }

/* tables + tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; margin-bottom: 16px; }
.tile { border: 1px solid var(--line); border-radius: var(--r); background: var(--panel); padding: 12px 14px; }
.tile .l { color: var(--text-2); font-size: 12px; } .tile .v { font-size: 22px; font-weight: 600; margin-top: 4px; } .tile .s { color: var(--muted); font-size: 12px; margin-top: 2px; }
.tw { border: 1px solid var(--line); border-radius: var(--r); overflow: auto; background: var(--panel); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; font-weight: 500; color: var(--text-2); font-size: 12px; padding: 9px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; position: sticky; top: 0; background: var(--panel); }
td { padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
td.n, th.n { text-align: right; }
td.wrap { max-width: 320px; overflow-wrap: anywhere; }

/* forms + modal */
.form { display: grid; gap: 10px; }
.form label { display: grid; gap: 4px; font-size: 12px; color: var(--text-2); }
.form label input, .form label select { width: 100%; }
.form .two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form .three { display: grid; grid-template-columns: 2fr 1fr; gap: 10px; }
.check { display: flex !important; align-items: center; gap: 8px; grid-auto-flow: column; justify-content: start; }
.check input { width: auto !important; }
#modal:empty { display: none; }
#modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: grid; place-items: center; z-index: 10; padding: 20px; }
.dialog { background: var(--panel); border: 1px solid var(--line-2); border-radius: 12px; padding: 20px; width: min(520px, 100%); max-height: 90vh; overflow: auto; }
.dialog.wide { width: min(720px, 100%); }
.dialog h1 { margin-bottom: 14px; }
.dialog .foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.banner { border: 1px solid color-mix(in srgb, var(--warn) 40%, var(--line-2)); background: #211d10; border-radius: var(--r); padding: 10px 12px; font-size: 13px; margin-bottom: 14px; }
#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 20; display: grid; gap: 8px; }
#toast div { background: var(--panel-2); border: 1px solid var(--line-2); border-radius: 8px; padding: 9px 14px; box-shadow: 0 8px 30px rgba(0,0,0,.5); max-width: 560px; }
#toast div.bad { border-color: var(--bad); }
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login .dialog { width: min(380px, 100%); }
pre.code { background: var(--bg); border: 1px solid var(--line); border-radius: 7px; padding: 10px; font-size: 12px; overflow: auto; margin: 0; }

@media (max-width: 1150px) { .inbox { grid-template-columns: 280px minmax(0, 1fr); } .cust { grid-column: 1 / -1; border-left: 0; border-top: 1px solid var(--line); } }
[hidden]{display:none !important}

/* subscription card */
.card .ch b { overflow-wrap: anywhere; }
.card .kv { grid-template-columns: max-content minmax(0, 1fr); gap: 5px 14px; margin-top: 10px; }
.card .kv span:nth-child(odd) { white-space: nowrap; }
.card .kv span:nth-child(even) { overflow-wrap: anywhere; color: var(--text); }
.card .kv span span { color: var(--muted); }
.card.sub { padding: 14px 16px; }
.card.sub .price { font-size: 20px; font-weight: 600; margin-top: 8px; }
.card.sub .price span { font-size: 13px; font-weight: 400; color: var(--text-2); }
.card.sub .act { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); }

/* log table */
.page.wide { max-width: 1400px; }
td.nw { white-space: nowrap; }
td .clip { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
td { line-height: 1.45; }
td.wrap { overflow-wrap: break-word; min-width: 140px; }

/* customer sidebar cards: readable at a glance */
.inbox { grid-template-columns: 330px minmax(0, 1fr) 400px; }
.cust { padding: 16px; }
.cust h2 { margin: 22px 0 10px; }
.card.ord, .card.sub { padding: 14px 16px; margin-bottom: 12px; }
.card .ch b { color: var(--text); font-size: 15px; font-weight: 650; }
.card.sub .price { color: var(--text); }
.card.ord .when { color: var(--text-2); font-size: 12px; margin-top: 2px; }
.card.ord .pills { margin-top: 10px; gap: 6px; }
.card .tag { font-size: 12px; padding: 2px 9px; }
.card.ord .items { margin: 12px 0 0; padding: 10px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); color: var(--text); font-size: 13px; gap: 6px; }
.card.ord .items div { display: flex; justify-content: space-between; gap: 12px; }
.card.ord .items div span:last-child { color: var(--text-2); white-space: nowrap; }
.card .kv { font-size: 13px; gap: 8px 14px; line-height: 1.45; }
.card .kv span:nth-child(odd) { color: var(--text-2); }
.card.ord .act { margin-top: 14px; }
@media (max-width: 1150px) { .inbox { grid-template-columns: 280px minmax(0, 1fr); } }

/* AI agent */
.count.hot { background: var(--warn); color: #1c1503; font-weight: 600; }
#aibox:empty { display: none; }
#aibox { padding: 0 18px 12px; }
.aibox { border: 1px solid color-mix(in srgb, var(--accent) 45%, var(--line-2)); background: #101b17; border-radius: var(--r); padding: 12px 14px; max-width: 800px; }
.aibox.esc { border-color: color-mix(in srgb, var(--warn) 50%, var(--line-2)); background: #211d10; }
.aibox .lbl { font-size: 11px; letter-spacing: .09em; text-transform: uppercase; color: var(--text-2); margin-bottom: 6px; }
.aibox .acts { margin: 10px 0; display: grid; gap: 6px; }
.aibox textarea { margin-top: 8px; }
.form .check, .aibox .check { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text); }
.aibox .check input, .form .check input { width: auto; }

/* conversation as a chat: customer on the left, us on the right */
.msgs { gap: 14px; padding: 18px 22px; }
.msg { max-width: min(680px, 82%); border-radius: 14px; padding: 10px 14px 12px; justify-self: start; border-bottom-left-radius: 4px; }
.msg.out { justify-self: end; margin-left: 0; background: #14261f; border-color: #25423a; border-radius: 14px; border-bottom-right-radius: 4px; }
.msg.note { justify-self: center; margin-left: 0; max-width: min(620px, 90%); border-radius: 10px; padding: 7px 12px; font-size: 13px; background: #1d1a10; border-color: #3a3216; }
.msg .mh { font-size: 12px; color: var(--muted); margin-bottom: 5px; gap: 18px; }
.msg .mh span:first-child { font-weight: 600; color: var(--text-2); }
.msg.out .mh span:first-child { color: var(--accent); }
.msg .mb { font-size: 14px; line-height: 1.6; }
.msg .via { margin-top: 8px; font-size: 12px; color: var(--muted); }
.msg .qt { margin-top: 8px; background: none; border: 0; padding: 0; color: var(--muted); font-size: 12px; cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
.msg .qt:hover { color: var(--text-2); }
.msg .quoted { margin-top: 8px; padding-left: 10px; border-left: 2px solid var(--line-2); color: var(--muted); font-size: 12.5px; }

/* ------------------------------------------------------------------ polish pass: alignment, motion, loading states */
:root { --ease: cubic-bezier(.2, .7, .2, 1); }
body { -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; line-height: 1.45; }
* { scrollbar-width: thin; scrollbar-color: var(--line-2) transparent; }
::selection { background: color-mix(in srgb, var(--accent) 35%, transparent); }
::placeholder { color: var(--muted); }

/* controls share one height and centre their labels */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-height: 32px; padding: 0 12px; line-height: 1; color: var(--text); text-decoration: none !important; transition: background .15s, border-color .15s, color .15s, opacity .15s, transform .08s; }
.btn.sm { min-height: 26px; padding: 0 9px; }
.btn:hover:not(:disabled) { background: #1f2227; }
.btn.primary { color: var(--accent-ink); }
.btn.primary:hover:not(:disabled) { background: color-mix(in srgb, var(--accent) 86%, #fff); border-color: color-mix(in srgb, var(--accent) 86%, #fff); }
.btn.danger { color: var(--bad); }
.btn.danger:hover:not(:disabled) { background: color-mix(in srgb, var(--bad) 10%, var(--panel-2)); border-color: var(--bad); }
.btn:active:not(:disabled) { transform: translateY(1px); }
input:not([type=checkbox]):not([type=radio]), select { height: 34px; padding: 0 10px; }
textarea { padding: 9px 11px; display: block; }
input, select, textarea { transition: border-color .15s; }
input:hover, select:hover, textarea:hover { border-color: #3b4049; }
select { appearance: none; -webkit-appearance: none; padding-right: 30px; text-overflow: ellipsis; background-repeat: no-repeat; background-position: right 11px center; background-size: 10px 6px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%23a6a9b0' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E"); }
input[type=checkbox] { accent-color: var(--accent); width: 15px; height: 15px; margin: 0; flex: none; }
.seg { align-items: center; }
.seg button { display: inline-flex; align-items: center; min-height: 28px; padding: 0 11px; line-height: 1; transition: background .15s, color .15s; }
.seg button:hover:not(.on) { color: var(--text); }
.tag { display: inline-flex; align-items: center; min-height: 20px; padding: 0 8px; line-height: 1; flex: none; }
.card .tag { min-height: 22px; padding: 0 9px; }
.count { display: inline-flex; align-items: center; justify-content: center; min-width: 20px; height: 18px; line-height: 1; flex: none; }

/* top bar and navigation never overlap */
.top { min-width: 0; }
.brand, .clock, #clock { flex: none; }
.clock { min-height: 30px; padding: 0 10px; white-space: nowrap; }
.quota { min-width: 0; flex: 0 1 auto; overflow: hidden; white-space: nowrap; }
.top .right { flex: none; flex-wrap: nowrap; }
.top .right .muted { max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 1180px) { .quota { display: none; } }
nav.side a { align-items: center; gap: 8px; min-height: 34px; padding: 0 10px; white-space: nowrap; transition: background .15s, color .15s; }

/* inbox */
.conv { transition: background .12s; }
.conv .who { align-items: baseline; }
.conv .who span:last-child { flex: none; }
.thread .hd .row > .muted { flex: 1 1 240px; min-width: 0; overflow-wrap: anywhere; }
.thread .hd .right { flex: none; }
.msg .mh { align-items: baseline; }
.msg .mh span:first-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg .mh span:last-child { flex: none; white-space: nowrap; }
.empty { display: grid; place-items: center; min-height: 120px; }
.thread > .empty { flex: 1; }
.card .ch { align-items: flex-start; }
.card .ch > :first-child { min-width: 0; }
.card .ch > :last-child { flex: none; }
.aibox .row > b { flex: 1 1 260px; min-width: 0; overflow-wrap: anywhere; }
.aibox .row > .right { flex: none; }
.aibox > div { overflow-wrap: anywhere; }

/* pages, tables, forms */
.page > .row:first-child { align-items: flex-start; flex-wrap: nowrap; gap: 16px; }
.page > .row:first-child > div { min-width: 0; }
tbody tr { transition: background .12s; }
tbody tr:hover td { background: rgba(255, 255, 255, .018); }
td.empty { display: table-cell; text-align: center; padding: 34px 12px; }
.form .two, .form .three, .form .cols3 { align-items: end; }
.form .cols3 { display: grid; grid-template-columns: 1.5fr 1fr 1fr; gap: 10px; }
@media (max-width: 760px) { .form .two, .form .three, .form .cols3 { grid-template-columns: 1fr; } }
.tile .v { line-height: 1.2; }

/* motion */
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: 0 0; } }
@keyframes slide { from { transform: translateX(-100%); } to { transform: translateX(260%); } }
.enter { animation: rise .22s var(--ease); }
#modal { animation: fade .16s ease-out; backdrop-filter: blur(2px); }
.dialog { animation: pop .2s var(--ease); box-shadow: 0 24px 80px rgba(0, 0, 0, .55); }
.login .dialog { animation: rise .3s var(--ease); }
#toast { justify-items: center; pointer-events: none; width: max-content; max-width: calc(100vw - 32px); }
#toast div { animation: rise .2s var(--ease); text-align: center; overflow-wrap: anywhere; transition: opacity .2s, transform .2s; }
#toast div.out { opacity: 0; transform: translateY(6px); }

/* loading: thin bar at the top, spinners in buttons, grey placeholders where content is coming */
#bar { position: fixed; top: 0; left: 0; right: 0; height: 2px; z-index: 30; overflow: hidden; opacity: 0; pointer-events: none; transition: opacity .2s; }
#bar.on { opacity: 1; }
#bar::after { content: ""; position: absolute; inset: 0; width: 40%; border-radius: 2px; background: var(--accent); animation: slide 1s ease-in-out infinite; }
.btn.busy { pointer-events: none; opacity: .85; }
.btn.busy::before { content: ""; width: 12px; height: 12px; flex: none; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: spin .6s linear infinite; }
.sk { display: block; border-radius: 6px; margin: 0 0 9px; background: linear-gradient(90deg, var(--panel-2) 25%, #24272e 37%, var(--panel-2) 63%); background-size: 400% 100%; animation: shimmer 1.3s ease infinite; }
.sk:last-child { margin-bottom: 0; }
.skrow { pointer-events: none; cursor: default; }
.msg.skm { width: min(520px, 70%); }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .001s !important; animation-iteration-count: 1 !important; transition-duration: .001s !important; } }
/* inbox filter row stays on one line */
.list .bar .row { flex-wrap: nowrap; gap: 6px; }
.list .bar .seg { flex: 1 1 auto; min-width: 0; }
.list .bar .seg button { flex: 1 1 auto; justify-content: center; padding: 0 7px; }
.list .bar .btn { flex: none; }
.cust:empty { background: var(--bg); }
td.wrap { min-width: 220px; }
