/* Codeworks Support Desk — design system
   Tokens → base → layout → components. No framework. */

:root {
  --navy: #192841; --navy-2: #233857; --yellow: #FCCF00; --yellow-2: #ffe15a;
  --bg: #f6f7f9; --surface: #ffffff; --surface-2: #f1f3f6; --line: #e5e8ee; --line-2: #d6dbe4;
  --ink: #192841; --ink-2: #4b5567; --ink-3: #8a93a5; --ink-inv: #ffffff;
  --accent: var(--yellow); --accent-ink: #192841;
  --good: #1f8f5a; --good-bg: #e6f6ee; --warn: #b7791f; --warn-bg: #fff6df; --bad: #c43d3d; --bad-bg: #fdeaea;
  --info: #2f6fd6; --info-bg: #e9f0fc; --note-bg: #fff8d6; --note-line: #f2dd6e;
  --r: 12px; --r-s: 8px; --r-pill: 999px;
  --font: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --shadow: 0 1px 2px rgba(25,40,65,.06), 0 8px 24px -12px rgba(25,40,65,.18);
  --rail-w: 232px; --list-w: 400px; --t: 150ms ease;
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) {
  --bg: #0f1420; --surface: #161c2a; --surface-2: #1d2434; --line: #273040; --line-2: #33405a;
  --ink: #e8ecf3; --ink-2: #aab3c3; --ink-3: #6f7a90; --accent-ink: #192841;
  --good-bg: #12301f; --warn-bg: #3a2c10; --bad-bg: #3b1818; --info-bg: #15264a; --note-bg: #332b0f; --note-line: #5a4c1a;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px -12px rgba(0,0,0,.6);
}}
:root[data-theme="dark"] {
  --bg: #0f1420; --surface: #161c2a; --surface-2: #1d2434; --line: #273040; --line-2: #33405a;
  --ink: #e8ecf3; --ink-2: #aab3c3; --ink-3: #6f7a90;
  --good-bg: #12301f; --warn-bg: #3a2c10; --bad-bg: #3b1818; --info-bg: #15264a; --note-bg: #332b0f; --note-line: #5a4c1a;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 14px/1.5 var(--font); color: var(--ink); background: var(--bg); -webkit-font-smoothing: antialiased; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
img { max-width: 100%; }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -.01em; }
h1 { font-size: 20px; } h2 { font-size: 16px; } h3 { font-size: 14px; }
.muted { color: var(--ink-2); } .faint { color: var(--ink-3); } .small { font-size: 12.5px; } .mono { font-family: var(--mono); font-size: 12.5px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
:focus-visible { outline: 2px solid var(--info); outline-offset: 2px; border-radius: 4px; }

/* ---------- App shell ---------- */
.app { display: grid; grid-template-columns: var(--rail-w) 1fr; min-height: 100dvh; }
.rail { background: var(--surface); border-right: 1px solid var(--line); padding: 16px 12px; display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100dvh; overflow: auto; }
.brand { display: flex; align-items: center; gap: 10px; padding: 6px 8px 14px; }
.brand .logo { width: 30px; height: 30px; border-radius: 8px; background: var(--yellow); color: var(--navy); display: grid; place-items: center; font-weight: 800; font-size: 12px; letter-spacing: -.02em; }
.brand b { font-size: 14px; }
.rail .sec { font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-3); padding: 14px 8px 4px; }
.nav { display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: var(--r-s); color: var(--ink-2); transition: background var(--t), color var(--t); }
.nav:hover { background: var(--surface-2); color: var(--ink); }
.nav.active { background: var(--navy); color: #fff; }
.nav .count { margin-left: auto; font-size: 11.5px; padding: 1px 7px; border-radius: var(--r-pill); background: var(--surface-2); color: var(--ink-2); font-weight: 600; }
.nav.active .count { background: rgba(255,255,255,.18); color: #fff; }
.nav .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--line-2); }
.rail .spacer { flex: 1; }
.rail .me { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-top: 1px solid var(--line); margin-top: 8px; }
.main { min-width: 0; }

/* Inbox: list + thread */
.inbox { display: grid; grid-template-columns: var(--list-w) 1fr; height: 100dvh; }
.list { border-right: 1px solid var(--line); background: var(--surface); display: flex; flex-direction: column; min-height: 0; }
.list-head { padding: 14px 16px 10px; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 10px; }
.list-head .row { display: flex; align-items: center; gap: 8px; }
.list-body { overflow: auto; flex: 1; }
.pane { min-width: 0; min-height: 0; display: flex; flex-direction: column; height: 100dvh; }
.pane-empty { flex: 1; display: grid; place-items: center; color: var(--ink-3); text-align: center; padding: 40px; }
.pane-empty .ico { font-size: 40px; margin-bottom: 8px; opacity: .5; }

/* Ticket rows */
.trow { display: grid; grid-template-columns: 36px 1fr auto; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); cursor: pointer; transition: background var(--t); position: relative; }
.trow:hover { background: var(--surface-2); }
.trow.active { background: var(--surface-2); box-shadow: inset 3px 0 0 var(--yellow); }
.trow .t1 { display: flex; align-items: center; gap: 8px; min-width: 0; }
.trow .subj { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.trow.unread .subj { font-weight: 700; }
.trow .prev { color: var(--ink-3); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.trow .meta { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; font-size: 11.5px; color: var(--ink-3); white-space: nowrap; }
.trow .num { color: var(--ink-3); font-size: 12px; font-variant-numeric: tabular-nums; }
.trow .company { font-size: 12px; color: var(--ink-2); }

.avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--surface-2); border: 1px solid var(--line); display: grid; place-items: center; font-size: 12px; font-weight: 600; color: var(--ink-2); flex: none; }
.avatar.s { width: 24px; height: 24px; font-size: 10px; }
.avatar.staff { background: var(--navy); color: #fff; border-color: var(--navy); }
.avatar.sys { background: var(--yellow); color: var(--navy); border-color: var(--yellow); }

.pri { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.pri.urgent { background: var(--bad); box-shadow: 0 0 0 3px var(--bad-bg); } .pri.low { background: var(--line-2); } .pri.normal { display: none; }

/* Chips */
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: var(--r-pill); font-size: 11.5px; font-weight: 600; border: 1px solid transparent; white-space: nowrap; }
.chip.open { background: var(--info-bg); color: var(--info); }
.chip.in_progress { background: var(--yellow); color: var(--navy); }
.chip.waiting { background: var(--warn-bg); color: var(--warn); }
.chip.closed { background: var(--surface-2); color: var(--ink-3); }
.chip.review { background: var(--bad-bg); color: var(--bad); }
.chip.ghost { background: transparent; border-color: var(--line-2); color: var(--ink-2); font-weight: 500; }
.chip.channel { background: var(--surface-2); color: var(--ink-2); text-transform: capitalize; font-weight: 500; }

/* Filter chips row */
.filters { display: flex; gap: 6px; flex-wrap: wrap; }
.filters a { padding: 4px 10px; border-radius: var(--r-pill); border: 1px solid var(--line-2); color: var(--ink-2); font-size: 12.5px; transition: all var(--t); }
.filters a:hover { border-color: var(--ink-3); color: var(--ink); }
.filters a.on { background: var(--navy); border-color: var(--navy); color: #fff; }

/* Thread */
.thread-head { padding: 14px 24px; border-bottom: 1px solid var(--line); background: var(--surface); display: flex; flex-direction: column; gap: 10px; }
.thread-head .top { display: flex; align-items: flex-start; gap: 12px; }
.thread-head h1 { font-size: 17px; line-height: 1.3; flex: 1; min-width: 0; }
.thread-head .sub { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; font-size: 12.5px; color: var(--ink-2); }
.controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.thread { flex: 1; overflow: auto; padding: 20px 24px; display: flex; flex-direction: column; gap: 14px; background: var(--bg); }
.msg { max-width: 760px; display: grid; grid-template-columns: 32px 1fr; gap: 12px; }
.msg.staff { margin-left: auto; width: 100%; grid-template-columns: 1fr 32px; }
.msg.staff .avatar { order: 2; }
.msg .card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 12px 16px; box-shadow: 0 1px 2px rgba(0,0,0,.03); }
.msg.staff .card { border-color: var(--line-2); background: var(--surface); }
.msg.note .card { background: var(--note-bg); border-color: var(--note-line); }
.msg.system { grid-template-columns: 1fr; max-width: none; text-align: center; }
.msg.system .card { display: inline-block; margin: 0 auto; background: transparent; border: 0; color: var(--ink-3); font-size: 12px; padding: 0; box-shadow: none; }
.msg .who { display: flex; justify-content: space-between; gap: 10px; font-size: 12.5px; color: var(--ink-2); margin-bottom: 6px; }
.msg .who b { color: var(--ink); }
.msg .body { font-size: 14.5px; line-height: 1.6; word-wrap: break-word; overflow-wrap: anywhere; }
.msg .body p { margin: 0 0 .7em; } .msg .body p:last-child { margin: 0; }
.msg .body blockquote { border-left: 3px solid var(--line-2); margin: .5em 0; padding: 0 0 0 12px; color: var(--ink-2); }
.msg .body pre { background: var(--surface-2); padding: 10px 12px; border-radius: var(--r-s); overflow: auto; font-size: 12.5px; }
.msg .body a { color: var(--info); text-decoration: underline; }
.msg .body table { border-collapse: collapse; } .msg .body td, .msg .body th { border: 1px solid var(--line); padding: 4px 8px; }
.atts { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.att { display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px; border: 1px solid var(--line-2); border-radius: var(--r-s); font-size: 12.5px; background: var(--surface-2); }
.att:hover { border-color: var(--ink-3); }

/* Composer */
.composer { border-top: 1px solid var(--line); background: var(--surface); padding: 12px 24px 14px; }
.composer .tabs { display: flex; gap: 2px; margin-bottom: 8px; }
.composer .tabs button { background: none; border: 0; padding: 6px 12px; border-radius: var(--r-s); color: var(--ink-3); font-weight: 500; cursor: pointer; }
.composer .tabs button.on { background: var(--surface-2); color: var(--ink); }
.composer .tabs button.on.note { background: var(--note-bg); color: var(--navy); }
.composer textarea { width: 100%; min-height: 96px; max-height: 320px; resize: vertical; border: 1px solid var(--line-2); border-radius: var(--r-s); padding: 10px 12px; background: var(--surface); transition: border var(--t); }
.composer textarea:focus { border-color: var(--navy); outline: none; }
.composer.is-note textarea { background: var(--note-bg); border-color: var(--note-line); }
.composer .foot { display: flex; gap: 8px; align-items: center; margin-top: 8px; flex-wrap: wrap; }
.composer .foot .right { margin-left: auto; display: flex; gap: 8px; align-items: center; }

/* Forms & buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 7px 14px; border-radius: var(--r-s); border: 1px solid var(--line-2); background: var(--surface); color: var(--ink); font-weight: 500; cursor: pointer; transition: all var(--t); white-space: nowrap; line-height: 1.3; }
.btn:hover { background: var(--surface-2); border-color: var(--ink-3); }
.btn.primary { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn.primary:hover { background: var(--navy-2); }
.btn.accent { background: var(--yellow); border-color: var(--yellow); color: var(--navy); font-weight: 600; }
.btn.accent:hover { background: var(--yellow-2); }
.btn.danger { color: var(--bad); } .btn.danger:hover { background: var(--bad-bg); border-color: var(--bad); }
.btn.sm { padding: 4px 10px; font-size: 12.5px; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn[disabled] { opacity: .5; cursor: default; }
.btn.htmx-request { opacity: .6; pointer-events: none; }
.input, select.input, textarea.input { width: 100%; padding: 8px 11px; border: 1px solid var(--line-2); border-radius: var(--r-s); background: var(--surface); transition: border var(--t); }
.input:focus { border-color: var(--navy); outline: none; }
select.input { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238a93a5' stroke-width='2.5'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 30px; }
select.input.sm { padding: 4px 26px 4px 9px; font-size: 12.5px; width: auto; }
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.field label { font-size: 12.5px; font-weight: 600; color: var(--ink-2); }
.field .hint { font-size: 12px; color: var(--ink-3); }
.search { position: relative; flex: 1; }
.search input { padding-left: 32px; }
.search svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--ink-3); }
.kbd { display: inline-block; padding: 0 5px; border: 1px solid var(--line-2); border-bottom-width: 2px; border-radius: 4px; font-size: 11px; font-family: var(--mono); color: var(--ink-3); background: var(--surface); }

/* Pages (clients, staff, settings) */
.page { padding: 24px 28px; max-width: 1040px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 18px 20px; }
.card + .card { margin-top: 14px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tbl th { text-align: left; font-size: 11.5px; letter-spacing: .05em; text-transform: uppercase; color: var(--ink-3); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.tbl td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tr:hover td { background: var(--surface-2); }
.empty { padding: 36px 20px; text-align: center; color: var(--ink-3); }
.empty b { display: block; color: var(--ink-2); margin-bottom: 4px; }

/* Toasts & flashes */
.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 50; }
.toast { background: var(--navy); color: #fff; padding: 10px 14px; border-radius: var(--r-s); box-shadow: var(--shadow); font-size: 13px; display: flex; gap: 12px; align-items: center; animation: up .2s ease; }
.toast.error { background: var(--bad); } .toast.success { background: var(--good); }
.toast button { background: none; border: 0; color: #fff; opacity: .8; cursor: pointer; }
@keyframes up { from { transform: translateY(8px); opacity: 0; } }
.banner { padding: 10px 14px; border-radius: var(--r-s); font-size: 13px; margin-bottom: 12px; }
.banner.info { background: var(--info-bg); color: var(--info); } .banner.warn { background: var(--warn-bg); color: var(--warn); } .banner.error { background: var(--bad-bg); color: var(--bad); } .banner.success { background: var(--good-bg); color: var(--good); }

/* Command palette */
.palette { position: fixed; inset: 0; background: rgba(15,20,32,.45); display: none; align-items: flex-start; justify-content: center; padding-top: 12vh; z-index: 60; }
.palette.open { display: flex; }
.palette .box { width: min(560px, 92vw); background: var(--surface); border-radius: 14px; box-shadow: var(--shadow); overflow: hidden; border: 1px solid var(--line); }
.palette input { width: 100%; border: 0; padding: 14px 16px; font-size: 15px; background: transparent; outline: none; border-bottom: 1px solid var(--line); }
.palette ul { list-style: none; margin: 0; padding: 6px; max-height: 50vh; overflow: auto; }
.palette li a { display: flex; gap: 10px; align-items: center; padding: 8px 10px; border-radius: var(--r-s); }
.palette li a:hover, .palette li.sel a { background: var(--surface-2); }
.palette li .k { margin-left: auto; color: var(--ink-3); font-size: 12px; }

/* Skeletons */
.skel { background: linear-gradient(90deg, var(--surface-2) 25%, var(--line) 50%, var(--surface-2) 75%); background-size: 200% 100%; animation: sh 1.2s infinite; border-radius: 6px; height: 12px; }
@keyframes sh { from { background-position: 200% 0; } to { background-position: -200% 0; } }
.htmx-indicator { display: none; } .htmx-request .htmx-indicator, .htmx-request.htmx-indicator { display: inline-flex; }

/* Login */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.login .box { width: min(400px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 28px; box-shadow: var(--shadow); }
.login .brand { padding: 0 0 18px; }

/* Topbar for mobile */
.topbar { display: none; align-items: center; gap: 10px; padding: 10px 14px; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.iconbtn { width: 36px; height: 36px; display: grid; place-items: center; border-radius: var(--r-s); border: 1px solid transparent; background: transparent; cursor: pointer; color: var(--ink-2); }
.iconbtn:hover { background: var(--surface-2); }
.back { display: none; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) { :root { --list-w: 340px; } .thread, .thread-head, .composer { padding-left: 16px; padding-right: 16px; } }
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .rail { position: fixed; left: 0; top: 0; width: 280px; transform: translateX(-100%); transition: transform .2s ease; z-index: 40; box-shadow: var(--shadow); }
  .rail.open { transform: none; }
  .scrim { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 30; display: none; } .scrim.on { display: block; }
  .topbar { display: flex; }
  .inbox { grid-template-columns: 1fr; height: auto; min-height: calc(100dvh - 57px); }
  .pane { height: auto; min-height: calc(100dvh - 57px); }
  .inbox.has-ticket .list { display: none; }
  .inbox:not(.has-ticket) .pane { display: none; }
  .back { display: inline-flex; }
  .thread { padding: 14px 12px; }
  .msg { grid-template-columns: 1fr; } .msg .avatar { display: none; }
  .msg.staff { grid-template-columns: 1fr; }
  .composer { padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); position: sticky; bottom: 0; }
  .page { padding: 16px; } .grid2 { grid-template-columns: 1fr; }
  .tbl { display: block; overflow-x: auto; }
  .list-body .trow { grid-template-columns: 1fr auto; } .list-body .trow .avatar { display: none; }
}
