/* Tetra Console design system: tokens first (light, then dark), then layout, then components. Every page is built from
   these classes; a page never carries its own colours or spacing. */
:root {
  --bg: #f7f7f8; --surface: #ffffff; --surface-2: #f2f2f4; --line: #e4e4e8; --line-strong: #d2d2d8;
  --text: #17171c; --text-2: #55555f; --text-3: #8a8a96;
  --accent: #4f46e5; --accent-ink: #ffffff; --accent-soft: #eef0ff;
  --ok: #16884a; --ok-soft: #e7f6ee; --warn: #b26b00; --warn-soft: #fff4e0; --bad: #d1343a; --bad-soft: #fdecec; --info: #2563eb; --info-soft: #e8f0fe;
  --radius: 10px; --radius-sm: 6px; --shadow: 0 1px 2px rgba(16, 16, 24, .06), 0 1px 1px rgba(16, 16, 24, .04);
  --font: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --sidebar: 232px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e0f13; --surface: #16171d; --surface-2: #1c1d24; --line: #262832; --line-strong: #333644;
    --text: #ececf1; --text-2: #a9abb8; --text-3: #737686;
    --accent: #818cf8; --accent-ink: #0e0f13; --accent-soft: #23254a;
    --ok: #3ccf7f; --ok-soft: #13291e; --warn: #f0b252; --warn-soft: #2e2412; --bad: #f2676c; --bad-soft: #321718; --info: #6aa1ff; --info-soft: #172338;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e0f13; --surface: #16171d; --surface-2: #1c1d24; --line: #262832; --line-strong: #333644;
  --text: #ececf1; --text-2: #a9abb8; --text-3: #737686;
  --accent: #818cf8; --accent-ink: #0e0f13; --accent-soft: #23254a;
  --ok: #3ccf7f; --ok-soft: #13291e; --warn: #f0b252; --warn-soft: #2e2412; --bad: #f2676c; --bad-soft: #321718; --info: #6aa1ff; --info-soft: #172338;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .mono { font: 12.5px/1.4 var(--mono); }
h1 { font-size: 20px; font-weight: 650; letter-spacing: -.01em; margin: 0; }
h2 { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--text-3); margin: 28px 0 10px; }
h3 { font-size: 15px; font-weight: 600; margin: 0 0 8px; }
p { margin: 0 0 10px; }

/* Layout: a fixed sidebar beside the page; on a phone the sidebar becomes a drawer behind the menu button. */
.app { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; overflow-y: auto; background: var(--surface); border-right: 1px solid var(--line); padding: 14px 10px; display: flex; flex-direction: column; gap: 2px; }
.brand { display: flex; align-items: center; gap: 10px; padding: 6px 10px 14px; font-weight: 650; color: var(--text); }
.brand svg { width: 22px; height: 22px; }
.nav-section { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--text-3); padding: 14px 10px 4px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: var(--radius-sm); color: var(--text-2); font-weight: 500; }
.nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }
.nav a .count { margin-left: auto; font-size: 11px; font-weight: 600; background: var(--bad); color: #fff; border-radius: 999px; padding: 0 7px; line-height: 18px; }
.nav svg { width: 16px; height: 16px; flex: none; }
.sidebar .me { margin-top: auto; padding: 12px 10px 4px; border-top: 1px solid var(--line); font-size: 12px; color: var(--text-3); }
.sidebar .me b { display: block; color: var(--text-2); font-weight: 500; overflow: hidden; text-overflow: ellipsis; }
.main { min-width: 0; }
.topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 12px; padding: 12px 28px; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.topbar .crumbs { color: var(--text-3); font-size: 13px; }
.topbar .crumbs a { color: var(--text-3); }
.topbar .spacer { flex: 1; }
.page { padding: 24px 28px 48px; max-width: 1240px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head .sub { color: var(--text-3); margin-top: 4px; }
.menu-toggle, .menu-button, .scrim { display: none; }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 20; left: 0; top: 0; width: 82vw; max-width: 300px; transform: translateX(-100%); transition: transform .18s ease; box-shadow: 0 0 40px rgba(0, 0, 0, .25); }
  .menu-toggle:checked ~ .sidebar { transform: none; }
  .menu-toggle:checked ~ .scrim { display: block; }
  .scrim { display: none; position: fixed; inset: 0; z-index: 15; background: rgba(0, 0, 0, .35); }
  .menu-button { display: inline-flex; cursor: pointer; padding: 6px; margin-left: -6px; color: var(--text-2); }
  .topbar { padding: 10px 16px; }
  .page { padding: 18px 16px 40px; }
  .hide-phone { display: none !important; }
}

/* Components */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; }
.card + .card { margin-top: 12px; }
.grid { display: grid; gap: 12px; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 1100px) { .grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 860px) { .grid.cols-2, .grid.cols-3 { grid-template-columns: 1fr; } }
@media (max-width: 520px) { .grid.cols-4 { grid-template-columns: 1fr; } }

.tile .label { font-size: 12px; color: var(--text-3); font-weight: 500; }
.tile .value { font-size: 24px; font-weight: 650; letter-spacing: -.02em; margin-top: 4px; font-variant-numeric: tabular-nums; }
.tile .foot { font-size: 12px; color: var(--text-3); margin-top: 4px; }

.table-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; font-weight: 500; color: var(--text-3); background: var(--surface-2); white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:hover td { background: color-mix(in srgb, var(--surface-2) 60%, transparent); }
td .sub { display: block; color: var(--text-3); font-size: 12px; }
.empty { padding: 28px; text-align: center; color: var(--text-3); }

.badge { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 500; padding: 1px 8px; border-radius: 999px; background: var(--surface-2); color: var(--text-2); white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .9; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.info { background: var(--info-soft); color: var(--info); }
.badge.plain::before { display: none; }
.muted { color: var(--text-3); }
.nowrap { white-space: nowrap; }
.ok { color: var(--ok); } .bad { color: var(--bad); } .warn { color: var(--warn); }

.alert { border-radius: var(--radius-sm); padding: 10px 14px; margin-bottom: 14px; border: 1px solid; }
.alert.bad { background: var(--bad-soft); color: var(--bad); border-color: color-mix(in srgb, var(--bad) 30%, transparent); }
.alert.info { background: var(--info-soft); color: var(--info); border-color: color-mix(in srgb, var(--info) 30%, transparent); }

form.inline { display: inline; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 860px) { .form-grid { grid-template-columns: 1fr; } }
label.field { display: grid; gap: 4px; font-size: 12px; color: var(--text-2); font-weight: 500; }
input, select, textarea { font: 14px var(--font); color: var(--text); background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius-sm); padding: 7px 10px; width: 100%; }
textarea { font-family: var(--mono); font-size: 12.5px; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 40%, transparent); outline-offset: 0; border-color: var(--accent); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row > .grow { flex: 1; min-width: 180px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: 500 13px var(--font); padding: 7px 14px; border-radius: var(--radius-sm); border: 1px solid var(--line-strong); background: var(--surface); color: var(--text); cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--bad); }
.btn.small { padding: 3px 10px; font-size: 12px; }
.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); overflow: hidden; }
.seg a { padding: 5px 12px; font-size: 13px; color: var(--text-2); border-right: 1px solid var(--line-strong); }
.seg a:last-child { border-right: 0; }
.seg a[aria-current="true"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.seg a:hover { text-decoration: none; background: var(--surface-2); }

/* The Inbox */
.inbox { display: grid; gap: 8px; }
.item { display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: start; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); }
.item .sev { width: 8px; height: 8px; border-radius: 50%; margin-top: 7px; background: var(--text-3); }
.item .sev.critical { background: var(--bad); box-shadow: 0 0 0 3px var(--bad-soft); }
.item .sev.warning { background: var(--warn); box-shadow: 0 0 0 3px var(--warn-soft); }
.item .sev.info { background: var(--info); }
.item .title { font-weight: 600; }
.item .meta { color: var(--text-3); font-size: 12px; margin-top: 2px; }
.item .actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
@media (max-width: 860px) { .item { grid-template-columns: auto 1fr; } .item .actions { grid-column: 2; justify-content: flex-start; } }

/* Sign-in */
.signin { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.signin .card { width: 100%; max-width: 380px; text-align: center; padding: 32px 28px; }
.signin .brand { justify-content: center; font-size: 18px; padding: 0 0 6px; }
.signin p { color: var(--text-3); }
.signin .gsi { display: flex; justify-content: center; margin-top: 18px; min-height: 44px; }

/* Support: a conversation beside its player and state */
.desk { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 16px; align-items: start; }
@media (max-width: 1000px) { .desk { grid-template-columns: 1fr; } }
.side { display: grid; gap: 12px; position: sticky; top: 72px; }
.side .card + .card { margin-top: 0; }
.side .field { margin-bottom: 10px; }
.thread { display: flex; flex-direction: column; gap: 10px; margin-bottom: 12px; }
.msg { max-width: 78%; padding: 10px 14px; border-radius: 14px; white-space: pre-wrap; overflow-wrap: anywhere; box-shadow: var(--shadow); }
.msg .who { font-size: 11px; color: var(--text-3); margin-bottom: 4px; white-space: normal; }
.msg.user { align-self: flex-start; background: var(--surface); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg.staff { align-self: flex-end; background: var(--accent-soft); border: 1px solid color-mix(in srgb, var(--accent) 25%, transparent); border-bottom-right-radius: 4px; }
.msg.staff .who { color: var(--accent); }
.msg.note { align-self: center; max-width: 90%; background: var(--warn-soft); border: 1px dashed color-mix(in srgb, var(--warn) 45%, transparent); font-size: 13px; }
.composer .field { margin-bottom: 10px; }
.composer textarea { font-family: var(--font); font-size: 14px; }
@media (max-width: 860px) { .msg { max-width: 92%; } .side { position: static; } }
