:root {
  --bg: #f5f6f8; --panel: #fff; --ink: #18202c; --muted: #647084; --line: #e3e6ec; --hover: #f0f2f5;
  --accent: #0f766e; --accent-ink: #fff; --accent-soft: #e3f3f1; --mine: #eaf5f3; --note: #fff7db; --note-line: #ecd98f;
  --danger: #b42318; --danger-soft: #fdecea; --ok: #116149; --ok-soft: #e4f5ec; --urgent: #c2410c;
  --radius: 12px; --shadow: 0 1px 2px rgba(16, 24, 40, .06);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216; --panel: #171b21; --ink: #e6e9ef; --muted: #98a2b3; --line: #29303a; --hover: #1e242c;
    --accent: #2bb8a6; --accent-ink: #05211e; --accent-soft: #14302c; --mine: #142b28; --note: #2a2410; --note-line: #5a4c16;
    --danger: #f97066; --danger-soft: #3a1714; --ok: #6ce9a6; --ok-soft: #0f2a1e; --urgent: #fb923c;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; line-height: 1.25; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 16px; margin: 0 0 4px; }
p { margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.nowrap { white-space: nowrap; }
svg.i { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------- layout */
.shell { display: grid; grid-template-columns: 252px minmax(0, 1fr); min-height: 100vh; }
.side { background: var(--panel); border-right: 1px solid var(--line); padding: 16px 12px; display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; padding: 4px 8px 12px; color: var(--ink); }
.brand .logo { width: 30px; height: 30px; border-radius: 8px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; }
.side .btn { margin: 0 4px 12px; }
.side a.nav { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: var(--ink); font-weight: 500; }
.side a.nav:hover { background: var(--hover); text-decoration: none; }
.side a.nav[aria-current] { background: var(--accent-soft); color: var(--accent); }
.side a.nav .n { margin-left: auto; font-size: 12px; font-weight: 600; color: var(--muted); }
.side a.nav .n.hot { background: var(--accent); color: var(--accent-ink); border-radius: 10px; padding: 0 7px; }
.side .label { font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); padding: 16px 10px 4px; }
.side .spacer { flex: 1; min-height: 12px; }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; background: var(--c, var(--muted)); }
.side a.nav .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
main { padding: 24px 28px 60px; max-width: 1180px; width: 100%; }
.topbar { display: none; }
.scrim { display: none; }
@media (max-width: 860px) {
  .shell { display: block; }
  .topbar { display: flex; align-items: center; gap: 10px; position: sticky; top: 0; z-index: 20; background: var(--panel); border-bottom: 1px solid var(--line); padding: 8px 12px; padding-top: max(8px, env(safe-area-inset-top)); }
  .topbar .title { font-weight: 700; flex: 1; }
  .side { position: fixed; z-index: 40; left: 0; top: 0; width: 280px; max-width: 86vw; transform: translateX(-100%); transition: transform .18s ease; padding-top: max(16px, env(safe-area-inset-top)); }
  body.menu .side { transform: none; box-shadow: 0 0 40px rgba(0, 0, 0, .3); }
  body.menu .scrim { display: block; position: fixed; inset: 0; z-index: 30; background: rgba(0, 0, 0, .35); }
  main { padding: 16px 14px 80px; }
  h1 { font-size: 20px; }
}

/* ---------- controls */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid var(--line); background: var(--panel); color: var(--ink); font: inherit; font-weight: 600; padding: 8px 14px; border-radius: 9px; cursor: pointer; min-height: 40px; white-space: nowrap; }
.btn:hover { background: var(--hover); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); background: var(--accent); }
.btn.danger { color: var(--danger); }
.btn.quiet { border-color: transparent; background: none; font-weight: 500; }
.btn.quiet:hover { background: var(--hover); }
.btn.sm { min-height: 32px; padding: 4px 10px; font-size: 13px; border-radius: 8px; }
.btn.icon { padding: 8px; min-width: 40px; }
input[type=text], input[type=email], input[type=tel], input[type=password], input[type=search], input[type=number], select, textarea {
  width: 100%; font: inherit; color: var(--ink); background: var(--panel); border: 1px solid var(--line); border-radius: 9px; padding: 9px 11px; min-height: 40px; }
textarea { resize: vertical; min-height: 110px; line-height: 1.5; }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent); }
label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 4px; }
label.check { display: flex; align-items: center; gap: 8px; font-weight: 500; font-size: 15px; cursor: pointer; }
label.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.field { margin-bottom: 14px; }
.hint { font-size: 13px; color: var(--muted); margin-top: 4px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > * { flex: 1 1 200px; min-width: 0; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.grow { flex: 1; }
form.inline { display: inline; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 16px; }
.card > h2 { margin-bottom: 12px; }
.flash { padding: 10px 14px; border-radius: 10px; margin-bottom: 14px; font-weight: 500; background: var(--ok-soft); color: var(--ok); }
.flash.error { background: var(--danger-soft); color: var(--danger); }
.chip { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 20px; background: var(--hover); color: var(--muted); white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.chip.client { background: color-mix(in srgb, var(--c) 14%, transparent); color: color-mix(in srgb, var(--c) 80%, var(--ink)); }
.chip.urgent { background: color-mix(in srgb, var(--urgent) 16%, transparent); color: var(--urgent); }
.chip.warn { background: var(--danger-soft); color: var(--danger); }
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.head h1 { flex: 1; min-width: 0; }
.empty { text-align: center; padding: 48px 20px; color: var(--muted); }
.empty h2 { color: var(--ink); font-size: 18px; margin-bottom: 6px; }
.steps { text-align: left; max-width: 460px; margin: 18px auto 0; padding: 0; list-style: none; counter-reset: s; }
.steps li { counter-increment: s; display: flex; gap: 12px; padding: 10px 0; color: var(--ink); }
.steps li::before { content: counter(s); flex: none; width: 26px; height: 26px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-weight: 700; display: grid; place-items: center; font-size: 13px; }

/* ---------- inbox */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 12px; overflow-x: auto; }
.tabs a { padding: 9px 12px; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; white-space: nowrap; margin-bottom: -1px; }
.tabs a:hover { color: var(--ink); text-decoration: none; }
.tabs a[aria-current] { color: var(--accent); border-color: var(--accent); }
.tabs .n { font-weight: 600; opacity: .7; margin-left: 4px; }
.search { position: relative; flex: 0 1 300px; }
.search input { padding-left: 34px; }
.search svg { position: absolute; left: 10px; top: 11px; color: var(--muted); }
.list { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
a.t { display: grid; grid-template-columns: 10px 40px minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); color: var(--ink); }
a.t:last-child { border-bottom: 0; }
a.t:hover { background: var(--hover); text-decoration: none; }
a.t .unread { width: 9px; height: 9px; border-radius: 50%; background: var(--accent); visibility: hidden; }
a.t.new .unread { visibility: visible; }
.avatar { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 14px; background: color-mix(in srgb, var(--c, var(--muted)) 16%, transparent); color: color-mix(in srgb, var(--c, var(--muted)) 80%, var(--ink)); flex: none; }
a.t .who { font-weight: 500; display: flex; gap: 8px; align-items: center; min-width: 0; }
a.t .who span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
a.t.new .who, a.t.new .subject b { font-weight: 700; }
a.t .subject { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }
a.t .subject b { color: var(--ink); font-weight: 500; }
a.t .meta { text-align: right; font-size: 13px; color: var(--muted); display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
@media (max-width: 600px) {
  a.t { grid-template-columns: 8px 36px minmax(0, 1fr); padding: 12px; gap: 10px; }
  a.t .meta { grid-column: 3; flex-direction: row; justify-content: space-between; align-items: center; width: 100%; }
  .avatar { width: 36px; height: 36px; font-size: 13px; }
  .search { flex-basis: 100%; }
}

/* ---------- ticket */
.ticket { display: grid; grid-template-columns: minmax(0, 1fr) 290px; gap: 20px; align-items: start; }
@media (max-width: 1000px) { .ticket { grid-template-columns: minmax(0, 1fr); } .ticket aside { order: -1; } }
.back { display: inline-flex; align-items: center; gap: 4px; font-weight: 600; margin-bottom: 10px; }
.thead { margin-bottom: 14px; }
.thead .sub { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 8px; color: var(--muted); font-size: 14px; }
.msg { display: flex; gap: 10px; margin-bottom: 14px; }
.msg .bubble { background: var(--panel); border: 1px solid var(--line); border-radius: 4px 14px 14px 14px; padding: 12px 14px; min-width: 0; flex: 0 1 auto; max-width: min(100%, 760px); box-shadow: var(--shadow); }
.msg.out { flex-direction: row-reverse; }
.msg.out .bubble { background: var(--mine); border-color: color-mix(in srgb, var(--accent) 22%, var(--line)); border-radius: 14px 4px 14px 14px; }
.msg.note .bubble { background: var(--note); border-color: var(--note-line); border-radius: 10px; }
.msg .by { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.msg .by b { color: var(--ink); font-size: 14px; }
.msg .text { white-space: pre-wrap; overflow-wrap: anywhere; }
.msg details { margin-top: 8px; font-size: 13px; color: var(--muted); }
.msg details summary { cursor: pointer; }
.msg details .text { margin-top: 6px; padding-left: 10px; border-left: 3px solid var(--line); }
.files { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.file { display: inline-flex; gap: 6px; align-items: center; border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 5px 10px; font-size: 13px; font-weight: 500; color: var(--ink); max-width: 100%; }
.file span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg .foot { margin-top: 8px; font-size: 13px; display: flex; gap: 14px; flex-wrap: wrap; }
.composer { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; margin-top: 20px; }
.seg { display: inline-flex; background: var(--hover); border-radius: 10px; padding: 3px; margin-bottom: 12px; max-width: 100%; }
.seg label { margin: 0; cursor: pointer; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: flex; align-items: center; gap: 6px; padding: 6px 14px; border-radius: 8px; font-weight: 600; font-size: 14px; color: var(--muted); }
.seg input:checked + span { background: var(--panel); color: var(--ink); box-shadow: 0 1px 2px rgba(0, 0, 0, .12); }
.seg input:focus-visible + span { outline: 2px solid var(--accent); }
.composer [data-for] { display: none; }
.composer[data-via=email] [data-for~=email], .composer[data-via=text] [data-for~=text], .composer[data-via=note] [data-for~=note] { display: block; }
.composer[data-via=email] .actions [data-for~=email], .composer[data-via=text] .actions [data-for~=text], .composer[data-via=note] .actions [data-for~=note] { display: inline-flex; }
.composer[data-via=note]:not([data-new]) textarea { background: var(--note); }
.line { display: flex; align-items: center; gap: 8px; border-bottom: 1px solid var(--line); padding: 2px 0; }
.line label { margin: 0; color: var(--muted); font-weight: 500; width: 46px; flex: none; }
.line input { border: 0; padding-left: 0; min-height: 36px; background: none; }
.line input:focus { outline: 0; }
.composer textarea { border: 0; padding: 12px 0; min-height: 130px; border-radius: 0; background: none; }
.composer textarea:focus { outline: 0; }
.composer[data-via=note]:not([data-new]) textarea { padding: 12px; border-radius: 9px; border: 1px solid var(--note-line); }
.composer .actions { border-top: 1px solid var(--line); padding-top: 12px; }
aside .card { padding: 14px; }
aside .card h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 10px; }
.kv { display: flex; gap: 8px; align-items: center; margin-bottom: 6px; min-width: 0; }
.kv a, .kv span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
aside details summary { cursor: pointer; color: var(--accent); font-weight: 600; font-size: 14px; margin-top: 8px; }
aside details[open] summary { margin-bottom: 10px; }
.stack > * + * { margin-top: 8px; }
.stack .btn { width: 100%; }

/* ---------- clients + settings */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 14px; }
a.client { display: block; color: var(--ink); background: var(--panel); border: 1px solid var(--line); border-left: 5px solid var(--c); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
a.client:hover { text-decoration: none; background: var(--hover); }
a.client h2 { margin-bottom: 8px; }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatches label { margin: 0; cursor: pointer; }
.swatches input { position: absolute; opacity: 0; }
.swatches span { display: block; width: 28px; height: 28px; border-radius: 50%; background: var(--c); border: 3px solid var(--panel); box-shadow: 0 0 0 1px var(--line); }
.swatches input:checked + span { box-shadow: 0 0 0 2px var(--ink); }
.copy { display: flex; gap: 8px; }
.copy input { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding: 6px 8px; border-bottom: 1px solid var(--line); }
td { padding: 9px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; overflow-wrap: anywhere; }
tr:last-child td { border-bottom: 0; }
.scroll { overflow-x: auto; }
.inbox-row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; padding: 12px 0; border-bottom: 1px solid var(--line); }
.inbox-row:first-of-type { padding-top: 0; }
.inbox-row .who { flex: 1 1 220px; min-width: 0; }
.inbox-row .who b { display: block; overflow: hidden; text-overflow: ellipsis; }
details.add { margin-top: 14px; }
details.add > summary { cursor: pointer; font-weight: 600; color: var(--accent); list-style: none; display: inline-flex; align-items: center; gap: 6px; }
details.add > summary::-webkit-details-marker { display: none; }
details.add[open] > summary { margin-bottom: 14px; }
ol.how { padding-left: 20px; margin: 0 0 14px; }
ol.how li { margin-bottom: 6px; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; background: var(--hover); padding: 1px 5px; border-radius: 5px; overflow-wrap: anywhere; }
.keybox { background: var(--ok-soft); color: var(--ok); border-radius: 10px; padding: 12px 14px; margin-bottom: 14px; }
.keybox code { background: none; font-size: 15px; font-weight: 700; color: inherit; }

/* ---------- sign in + public form */
.center { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.center .card { width: 100%; max-width: 380px; padding: 26px; }
.public { max-width: 620px; margin: 0 auto; padding: 28px 16px 60px; }
.public.embed { padding: 4px; }
.public .card { border-top: 5px solid var(--c); padding: 24px; }
.public h1 { margin-bottom: 6px; }
.public .btn.primary { background: var(--c); border-color: var(--c); color: #fff; width: 100%; min-height: 46px; font-size: 16px; }
.public .seg span { padding: 8px 16px; }
.hp { position: absolute; left: -5000px; height: 0; overflow: hidden; }
.tick { width: 56px; height: 56px; border-radius: 50%; background: var(--ok-soft); color: var(--ok); display: grid; place-items: center; margin: 0 auto 14px; }
.tick svg { width: 28px; height: 28px; stroke-width: 2.5; }
