/* Self-hosted so the panel needs no third-party origin and works offline.
   Sources: @fontsource/{space-grotesk,ibm-plex-sans,jetbrains-mono} (OFL-1.1). */
@font-face { font-family: "Space Grotesk"; src: url("/static/fonts/space-grotesk-latin-500-normal.woff2") format("woff2");
             font-weight: 500; font-style: normal; font-display: swap; }
@font-face { font-family: "Space Grotesk"; src: url("/static/fonts/space-grotesk-latin-600-normal.woff2") format("woff2");
             font-weight: 600; font-style: normal; font-display: swap; }
@font-face { font-family: "IBM Plex Sans"; src: url("/static/fonts/ibm-plex-sans-latin-400-normal.woff2") format("woff2");
             font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: "IBM Plex Sans"; src: url("/static/fonts/ibm-plex-sans-latin-600-normal.woff2") format("woff2");
             font-weight: 600; font-style: normal; font-display: swap; }
@font-face { font-family: "JetBrains Mono"; src: url("/static/fonts/jetbrains-mono-latin-400-normal.woff2") format("woff2");
             font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: "JetBrains Mono"; src: url("/static/fonts/jetbrains-mono-latin-700-normal.woff2") format("woff2");
             font-weight: 700; font-style: normal; font-display: swap; }

/* Support desk console
   ---------------------
   The structural device is the *thread bar*: Telegram's own blockquote rule,
   reused as a status carrier. It marks every ticket row, grows into the rail of
   the conversation view, and is the only place colour is spent. Everything else
   stays quiet: cool paper, one ink, generous mono for the IDs this job is made of.
*/

:root {
  --paper: #eef1f6;
  --surface: #ffffff;
  --surface-2: #f7f9fc;
  --ink: #10131a;
  --muted: #5c6577;
  --line: #dde3ec;

  --thread: #6e5ae6;
  --open: #e0a21b;
  --closed: #2e9e6b;
  --locked: #c2453d;

  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 19, 26, .06), 0 8px 24px -12px rgba(16, 19, 26, .18);
  --sans: "IBM Plex Sans", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --display: "Space Grotesk", var(--sans);
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #0e1016;
    --surface: #161a23;
    --surface-2: #1b202b;
    --ink: #e9edf5;
    --muted: #98a2b8;
    --line: #29303e;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px -12px rgba(0, 0, 0, .6);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; }
h1, h2, h3 { font-family: var(--display); letter-spacing: -.02em; margin: 0; }
h1 { font-size: 1.5rem; font-weight: 600; }
h2 { font-size: 1.05rem; font-weight: 600; }
code, .mono, kbd { font-family: var(--mono); font-size: .86em; }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 22px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand { display: flex; align-items: center; gap: 10px; padding: 0 6px; }
.brand .bar { width: 4px; height: 30px; border-radius: 2px; background: var(--thread); }
.brand b { font-family: var(--display); font-size: 1rem; letter-spacing: -.02em; display: block; }
.brand span { color: var(--muted); font-size: .72rem; letter-spacing: .08em; text-transform: uppercase; }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px 10px; border-radius: 8px; text-decoration: none; color: var(--muted);
  font-size: .9rem; border-left: 3px solid transparent;
}
.nav a:hover { background: var(--surface-2); color: var(--ink); }
.nav a[aria-current="page"] {
  background: var(--surface-2); color: var(--ink); font-weight: 600;
  border-left-color: var(--thread);
}
.nav .count {
  font-family: var(--mono); font-size: .7rem; background: var(--open);
  color: #201802; border-radius: 999px; padding: 1px 7px;
}

.sidebar footer { margin-top: auto; font-size: .8rem; color: var(--muted); }
.sidebar footer .who { display: block; color: var(--ink); font-weight: 600; }

.main { padding: 26px 30px 60px; min-width: 0; }
.head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.head p { margin: 4px 0 0; color: var(--muted); font-size: .88rem; }

/* ---------- messages ---------- */
.note { border-radius: var(--radius); padding: 10px 14px; margin-bottom: 16px; font-size: .9rem; border-left: 3px solid; background: var(--surface); }
.note.ok { border-color: var(--closed); }
.note.bad { border-color: var(--locked); }

/* ---------- cards & grid ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card .card-head { padding: 14px 16px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.card .card-body { padding: 16px; }
.grid { display: grid; gap: 16px; }
.grid.stats { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.grid.two { grid-template-columns: 1.6fr 1fr; align-items: start; }

.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; border-left: 3px solid var(--line); }
.stat .k { font-size: .7rem; letter-spacing: .09em; text-transform: uppercase; color: var(--muted); }
.stat .v { font-family: var(--display); font-size: 1.7rem; font-weight: 600; letter-spacing: -.03em; }
.stat.open { border-left-color: var(--open); }
.stat.closed { border-left-color: var(--closed); }
.stat.locked { border-left-color: var(--locked); }
.stat.thread { border-left-color: var(--thread); }

/* ---------- the thread bar ---------- */
.rows { display: flex; flex-direction: column; }
.row {
  display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: center;
  padding: 11px 16px 11px 13px; border-bottom: 1px solid var(--line);
  border-left: 3px solid var(--line); text-decoration: none; color: inherit;
  transition: border-left-width .12s ease, background .12s ease, padding-left .12s ease;
}
.row:last-child { border-bottom: 0; }
.row:hover { background: var(--surface-2); border-left-width: 7px; padding-left: 9px; }
.row:focus-visible { outline: 2px solid var(--thread); outline-offset: -2px; }
.row.open { border-left-color: var(--open); }
.row.closed { border-left-color: var(--closed); }
.row.locked { border-left-color: var(--locked); }
.row.live { border-left-color: var(--closed); }   /* button is enabled + visible */
.row.paused { border-left-color: var(--muted); }  /* button exists but users can't see it */
.row .title { font-weight: 600; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row .meta { color: var(--muted); font-size: .8rem; margin-top: 2px; }
.row .right { text-align: right; color: var(--muted); font-size: .8rem; white-space: nowrap; }

.tag {
  font-family: var(--mono); font-size: .7rem; padding: 1px 6px; border-radius: 5px;
  border: 1px solid var(--line); color: var(--muted);
}
.tag.unread { background: var(--open); border-color: var(--open); color: #201802; font-weight: 700; }
.tag.role { border-color: var(--thread); color: var(--thread); }

/* ---------- conversation rail ---------- */
.thread { position: relative; padding-left: 22px; }
.thread::before { content: ""; position: absolute; left: 6px; top: 6px; bottom: 6px; width: 2px; background: var(--line); }
.msg { position: relative; margin-bottom: 14px; }
.msg::before {
  content: ""; position: absolute; left: -20px; top: 7px; width: 10px; height: 10px;
  border-radius: 50%; background: var(--surface); border: 2px solid var(--muted);
}
.msg.user::before { border-color: var(--thread); }
.msg.admin::before { border-color: var(--closed); }
.msg.system::before { border-color: var(--line); }
.msg .who { font-size: .75rem; color: var(--muted); display: flex; gap: 8px; align-items: baseline; }
.msg .who b { color: var(--ink); font-size: .82rem; }
.msg .bubble {
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 0 var(--radius) var(--radius) var(--radius);
  padding: 9px 12px; margin-top: 4px; overflow-wrap: anywhere;
}
.msg.admin .bubble { background: color-mix(in srgb, var(--closed) 7%, var(--surface)); }
.msg.system .bubble { font-style: italic; color: var(--muted); }
.msg .attach { display: inline-block; margin-top: 6px; font-family: var(--mono); font-size: .72rem; color: var(--muted); border: 1px dashed var(--line); border-radius: 6px; padding: 2px 6px; }

/* Telegram formatting, rebuilt from stored entities */
.bubble blockquote.quote { margin: 4px 0; padding: 2px 0 2px 10px; border-left: 3px solid var(--thread); color: inherit; }
.bubble blockquote.expandable { border-left-style: double; }
.bubble pre { background: var(--paper); padding: 8px; border-radius: 6px; overflow-x: auto; margin: 4px 0; }
.bubble .spoiler { background: var(--muted); color: transparent; border-radius: 3px; cursor: pointer; }
.bubble .spoiler:hover, .bubble .spoiler:focus { background: transparent; color: inherit; }
.bubble a { color: var(--thread); }

/* ---------- live ---------- */
.live { display: inline-flex; align-items: center; gap: 6px; font-size: .72rem; color: var(--muted);
        letter-spacing: .06em; text-transform: uppercase; }
.live i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.live[data-state="on"] i { background: var(--closed); animation: pulse 2.4s ease-in-out infinite; }
.live[data-state="on"] { color: var(--closed); }
.live[data-state="off"] i { background: var(--open); }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }

/* A message that arrived while you were reading announces itself once, quietly. */
.msg.arriving .bubble { animation: land .5s ease-out; }
.msg.arriving::before { box-shadow: 0 0 0 4px color-mix(in srgb, var(--thread) 22%, transparent); }
@keyframes land {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

/* ---------- forms ---------- */
label { display: block; font-size: .78rem; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); margin-bottom: 5px; }
input[type=text], input[type=password], input[type=number], input[type=search], select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface); color: var(--ink); font: inherit;
}
textarea { font-family: var(--mono); font-size: .85rem; line-height: 1.55; resize: vertical; min-height: 90px; }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--thread); outline-offset: 1px;
}
.field { margin-bottom: 14px; }
.field .hint { font-size: .78rem; color: var(--muted); margin-top: 5px; text-transform: none; letter-spacing: 0; }
.inline { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.btn {
  font: inherit; font-weight: 600; font-size: .85rem; padding: 8px 14px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink); cursor: pointer;
  text-decoration: none; display: inline-flex; align-items: center; gap: 6px;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--thread); border-color: var(--thread); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--locked); border-color: color-mix(in srgb, var(--locked) 40%, var(--line)); }
.btn.danger:hover { background: color-mix(in srgb, var(--locked) 10%, var(--surface)); }
.btn.small { padding: 5px 9px; font-size: .78rem; }
.btn[disabled] { opacity: .45; cursor: not-allowed; }

/* ---------- auth ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth .card { width: 100%; max-width: 420px; }
.auth .card-head { display: block; }
.auth .brand { padding: 0; margin-bottom: 10px; }
.auth .steps { display: flex; gap: 6px; margin-bottom: 14px; }
.auth .steps i { flex: 1; height: 3px; border-radius: 2px; background: var(--line); }
.auth .steps i.on { background: var(--thread); }
.auth .foot { text-align: center; padding: 12px; border-top: 1px solid var(--line); font-size: .85rem; color: var(--muted); }
.code-input { font-family: var(--mono); font-size: 1.6rem; letter-spacing: .5em; text-align: center; }

/* ---------- misc ---------- */
.pager { display: flex; gap: 8px; align-items: center; justify-content: space-between; margin-top: 14px; font-size: .85rem; color: var(--muted); }
.empty { padding: 40px 16px; text-align: center; color: var(--muted); }
.empty b { display: block; color: var(--ink); font-family: var(--display); margin-bottom: 4px; }
.spark { display: flex; align-items: flex-end; gap: 6px; height: 76px; margin-bottom: 4px; }
.spark div { flex: 1; background: linear-gradient(var(--thread), color-mix(in srgb, var(--thread) 55%, transparent));
              border-radius: 3px 3px 0 0; min-height: 3px; }
.spark span { display: block; text-align: center; font-size: .68rem; color: var(--muted); margin-top: 4px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: .86rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-family: var(--mono); font-size: .82rem; overflow-wrap: anywhere; }
.depth { display: inline-block; color: var(--line); font-family: var(--mono); }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; align-items: center; gap: 12px; overflow-x: auto; padding: 12px; }
  .sidebar .brand span, .sidebar footer { display: none; }
  .nav { flex-direction: row; }
  .nav a { white-space: nowrap; border-left: 0; border-bottom: 3px solid transparent; border-radius: 8px 8px 0 0; }
  .nav a[aria-current="page"] { border-left: 0; border-bottom-color: var(--thread); }
  .main { padding: 18px 14px 50px; }
  .grid.two { grid-template-columns: 1fr; }
  .row { grid-template-columns: 1fr; }
  .row .right { text-align: left; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}