/* PaxChat uses local system fonts and inherits its palette from the document. */
:root {
  color-scheme: dark;
  --page: #0b1218;
  --surface: #111c24;
  --raised: #192630;
  --inset: #0b151c;
  --hover: #20313a;
  --line: #2c404a;
  --line-soft: #20313a;
  --text: #ecf2f1;
  --muted: #a8b8bd;
  --quiet: #84969e;
  --brand: rgb(216 230 56);
  --brand-rpm: 7;
  --accent: var(--brand);
  --on-accent: #20230a;
  --accent-wash: color-mix(in srgb, var(--brand) 13%, var(--surface));
  --link: #8ecaec;
  --error: #ffaaa1;
  --error-wash: #3b2325;
  --warn: #f1c982;
  --shadow: 0 18px 44px rgb(0 0 0 / 17%);
  --mix-base: #fff;
  --mix-pct: 69%;
  --radius: .75rem;
  --row-height: 2.25rem;
  --sans: "DM Sans", Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

:root[data-theme="light"] {
  color-scheme: light;
  --page: #eff3f2;
  --surface: #fff;
  --raised: #f3f7f6;
  --inset: #f5f8f7;
  --hover: #e6efec;
  --line: #c3d1cc;
  --line-soft: #dbe5e0;
  --text: #162827;
  --muted: #4e625e;
  --quiet: #5b716b;
  --accent: color-mix(in srgb, var(--brand) 38%, #172000);
  --on-accent: #fff;
  --accent-wash: color-mix(in srgb, var(--brand) 25%, var(--surface));
  --link: #075f90;
  --error: #9d322b;
  --error-wash: #fbece9;
  --warn: #825500;
  --shadow: 0 15px 32px rgb(28 59 46 / 7%);
  --mix-base: #102823;
  --mix-pct: 46%;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { min-height: 100%; background: var(--page); -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--page);
  color: var(--text);
  font: 1rem/1.45 var(--sans);
  -webkit-font-smoothing: antialiased;
  accent-color: var(--accent);
}
button, input, select, textarea { font: inherit; color: inherit; }
button, a, input, select, textarea, summary { -webkit-tap-highlight-color: transparent; }
button, a { touch-action: manipulation; }
button, .button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .43rem;
  min-height: 2.55rem;
  padding: .43rem .85rem;
  border: 1px solid var(--line);
  border-radius: .52rem;
  background: var(--raised);
  color: var(--text);
  font: 600 .9rem/1.2 var(--sans);
  text-decoration: none;
  cursor: pointer;
  transition: background-color 120ms, border-color 120ms, color 120ms;
}
button:not(:disabled):hover, .button:hover { background: var(--hover); border-color: var(--quiet); }
button:not(:disabled):active, .button:active { transform: translateY(1px); }
button:disabled, .button[aria-disabled="true"] { opacity: .46; cursor: default; }
.primary, .send {
  color: var(--on-accent);
  background: var(--accent);
  border-color: transparent;
  font-weight: 700;
}
.primary:not(:disabled):hover, .send:not(:disabled):hover {
  background: color-mix(in srgb, var(--accent) 87%, var(--mix-base));
  border-color: transparent;
}
.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.secondary { background: var(--raised); }
.danger { color: var(--error); }
.icon-button, .menu-handle {
  flex: none;
  width: 2.65rem;
  min-height: 2.65rem;
  padding: 0;
  border-color: transparent;
  background: transparent;
  color: var(--muted);
}
.menu-handle:empty::before {
  content: "";
  width: 1rem;
  height: .68rem;
  border-block: 2px solid currentColor;
  background: linear-gradient(currentColor, currentColor) center / 100% 2px no-repeat;
}
button svg, .button svg { width: 1.1em; height: 1.1em; flex: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
input:not([type="checkbox"], [type="radio"], [type="color"], [type="range"]),
textarea, select {
  min-width: 0;
  min-height: 2.65rem;
  max-width: 100%;
  padding: .55rem .72rem;
  border: 1px solid var(--line);
  border-radius: .5rem;
  outline-offset: 1px;
  background: var(--inset);
  color: var(--text);
  font-size: 1rem;
  line-height: 1.35;
}
input::placeholder, textarea::placeholder { opacity: 1; color: var(--quiet); }
textarea { resize: vertical; }
input[type="checkbox"], input[type="radio"] { width: 1.1rem; height: 1.1rem; margin: 0; }
input[type="color"] { min-height: 2.55rem; width: 3.25rem; border: 1px solid var(--line); border-radius: .45rem; background: var(--inset); }
input[type="range"] { max-width: 100%; }
select {
  appearance: none;
  padding-right: 2rem;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 1rem) 52%, calc(100% - .75rem) 52%;
  background-size: .26rem .26rem;
  background-repeat: no-repeat;
}
label { color: var(--muted); font-size: .9rem; font-weight: 575; }
fieldset { min-width: 0; margin: 0; padding: 1rem; border: 1px solid var(--line); border-radius: .55rem; }
legend { padding-inline: .35rem; color: var(--muted); font-size: .9rem; }
a { color: var(--link); text-underline-offset: .16em; }
a:hover { text-decoration-thickness: 2px; }
h1, h2, h3, p { margin-block: 0; }
h1, h2, h3 { line-height: 1.16; text-wrap: balance; }
h1 { font-size: clamp(1.75rem, 3.4vw, 2.75rem); letter-spacing: -.05em; font-weight: 660; }
h2 { font-size: clamp(1.08rem, 2vw, 1.34rem); letter-spacing: -.027em; font-weight: 640; }
h3 { font-size: 1.025rem; letter-spacing: -.014em; }
code, kbd, samp, pre, .mono, .version { font-family: var(--mono); }
.muted, small { color: var(--muted); }
.spacer { flex: 1 1 auto; }
.empty-state { padding: 1.25rem; color: var(--muted); font-size: .92rem; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden;
  clip-path: inset(50%); border: 0; white-space: nowrap;
}

.brand, .auth-brand { display: inline-flex; align-items: center; gap: .65rem; min-width: 0; color: var(--accent); text-decoration: none; }
.brand { font-size: 1.12rem; font-weight: 720; letter-spacing: -.038em; }
.version, .badge, .status-pill {
  display: inline-flex; align-items: center; gap: .4rem; width: max-content;
  max-width: 100%; border-radius: .32rem; font: 500 .77rem/1.35 var(--mono);
  letter-spacing: 0; white-space: nowrap;
}
.version { color: var(--quiet); }
.badge, .status-pill { padding: .22rem .44rem; border: 1px solid var(--line); color: var(--muted); background: var(--inset); }
.status-pill { border-radius: 99rem; }
.status-pill::before { content: ""; width: .46rem; height: .46rem; flex: none; border-radius: 50%; background: currentColor; }
.status-pill.online, .status-pill[data-state="online"], .status-pill.good { color: var(--accent); background: var(--accent-wash); border-color: transparent; }
.status-pill.idle { color: var(--warn); }
.topbar { background: var(--surface); border-bottom: 1px solid var(--line-soft); }
.topbar-inner, .toolbar, .panel-actions, .composer-actions, .call-controls {
  display: flex; align-items: center; gap: .55rem; min-width: 0;
}
.topbar-inner { width: min(100%, 84rem); min-height: 4.15rem; padding: .65rem clamp(1rem, 3.3vw, 2.75rem); margin-inline: auto; gap: .85rem; }
.toolbar, .panel-actions { flex-wrap: wrap; }

/* Sign-in */
.auth-shell {
  position: relative; isolation: isolate; display: grid; place-items: center;
  min-height: 100vh; min-height: 100svh; padding: 1.25rem;
  padding-top: max(1.25rem, env(safe-area-inset-top)); padding-bottom: max(1.25rem, env(safe-area-inset-bottom));
  background: radial-gradient(ellipse at 21% 12%, color-mix(in srgb, var(--accent-wash) 67%, transparent), transparent 58%), var(--page);
}
.auth-shell::before {
  content: ""; position: absolute; inset: 0; z-index: -1; pointer-events: none;
  background-image: linear-gradient(to right, var(--line-soft) 1px, transparent 1px), linear-gradient(to bottom, var(--line-soft) 1px, transparent 1px);
  background-size: 3.25rem 3.25rem;
  mask-image: linear-gradient(135deg, rgb(0 0 0 / 65%), transparent 66%);
}
.auth-card, dialog { color: var(--text); border: 1px solid var(--line); background: var(--surface); box-shadow: var(--shadow); }
.auth-card {
  position: relative; width: min(100%, 26.75rem); padding: clamp(1.45rem, 5vw, 2.35rem); border-radius: 1rem;
}
.auth-card::before {
  content: ""; position: absolute; top: -1px; inset-inline: 1.75rem;
  height: 2px; border-radius: 99rem; background: linear-gradient(90deg, var(--accent), transparent 80%);
}
.auth-brand { margin-bottom: 2.3rem; font-weight: 690; font-size: 1.1rem; letter-spacing: -.035em; }
#login-screen .auth-brand {
  align-items: baseline; flex-wrap: wrap; gap: .15em .32em; margin-bottom: 1.55rem;
  font-size: clamp(1.875rem, 5vw, 2.35rem); line-height: 1.14;
}
#login-screen .auth-brand .version { font-size: .75em; }
#login-screen::before { background-size: 1.5rem 1.5rem; }
#login-screen .auth-card {
  isolation: isolate;
  border-width: 2px;
}
#login-screen .auth-card::before { content: none; }
.login-border {
  position: absolute; inset: -2px; width: calc(100% + 4px); height: calc(100% + 4px);
  pointer-events: none; border-radius: inherit; color: var(--accent);
}
#login-screen .wordmark {
  color: var(--accent);
  background-image: repeating-radial-gradient(ellipse .92em .72em at 32% 104%,
    var(--accent) 0 25%, #28a44f 51%, var(--accent) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
#login-form > .primary { justify-self: center; width: min(100%, 10rem); }
.auth-heading { margin-bottom: 1.55rem; }
.auth-heading h1, .auth-card > h1 { font-size: clamp(1.85rem, 4vw, 2.3rem); }
.auth-heading p, .page-heading p { margin-top: .42rem; color: var(--muted); font-size: .95rem; }
.form-stack, .drawer-body { display: grid; align-content: start; gap: 1rem; }
.field { display: grid; align-content: start; gap: .37rem; min-width: 0; }
.field > :is(input:not([type="color"], [type="checkbox"], [type="radio"]), select, textarea), .form-stack > :is(input, select, textarea) { width: 100%; }
.form-stack > .primary { margin-top: .35rem; min-height: 2.8rem; }
.notice { padding: .65rem .8rem; border: 1px solid var(--line); border-left: 3px solid var(--accent); border-radius: .42rem; color: var(--muted); background: var(--inset); font-size: .89rem; }
.notice:empty { display: none; }
.notice.error, .notice[role="alert"] { color: var(--error); border-left-color: var(--error); background: var(--error-wash); }

/* Operator dashboard */
.dashboard { width: min(100%, 84rem); margin-inline: auto; padding: clamp(1.2rem, 3vw, 2.2rem) clamp(1rem, 3.3vw, 2.75rem) 2.5rem; }
.dashboard > * + * { margin-top: 1.2rem; }
.page-heading, .panel-head, .drawer-head {
  display: flex; align-items: center; justify-content: space-between; gap: .8rem; min-width: 0;
}
.page-heading { flex-wrap: wrap; align-items: flex-end; }
.metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 10.7rem), 1fr)); gap: .72rem; }
.metric, .panel, .player, .call-tile { min-width: 0; border: 1px solid var(--line-soft); border-radius: var(--radius); background: var(--surface); }
.metric { display: grid; align-content: start; gap: .25rem; padding: .92rem 1rem; }
.metric-label, .metric-note { overflow-wrap: anywhere; color: var(--muted); font-size: .87rem; }
.metric-value { font-size: clamp(1.4rem, 2.3vw, 1.9rem); font-weight: 620; line-height: 1.23; letter-spacing: -.045em; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.metric-note { color: var(--quiet); font-size: .8rem; }
.panels, .settings-grid, .form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; align-items: start; }
.panel { overflow: hidden; }
.panel-head, .panel-actions, .panel-body { padding: .85rem 1rem; }
.panel-head { min-height: 3.65rem; border-bottom: 1px solid var(--line-soft); }
.panel-head h2, .panel-head h3 { margin: 0; }
.panel-actions { min-height: 3.45rem; border-top: 1px solid var(--line-soft); }
.panel-actions button { min-height: 2.18rem; padding: .36rem .64rem; font-size: .84rem; }
.list-viewport {
  height: calc(8 * var(--row-height)); overflow: auto; overscroll-behavior: contain; scrollbar-width: thin; scrollbar-color: var(--line) transparent;
}
.list-viewport:has(thead) { height: calc(9 * var(--row-height)); }
.list-viewport ul, ul.list-viewport { margin: 0; padding: 0; list-style: none; }
.list-viewport li, .list-row { display: flex; align-items: center; gap: .55rem; padding-inline: 1rem; }
table { width: 100%; border-collapse: separate; border-spacing: 0; text-align: start; font-size: .88rem; font-variant-numeric: tabular-nums; }
th, td { padding: .43rem .68rem; vertical-align: middle; text-align: start; }
th { color: var(--muted); background: var(--raised); font-size: .81rem; font-weight: 575; }
td, .list-viewport li, .list-row { border-bottom: 1px solid var(--line-soft); }
.list-viewport :is(th, td, li), .list-row { height: var(--row-height); white-space: nowrap; }
.list-viewport thead th { position: sticky; top: 0; z-index: 1; }
.list-viewport :is(th, td):first-child { padding-left: 1rem; }
.list-viewport [tabindex], .list-viewport [role="option"], .list-viewport tr[aria-selected] { cursor: pointer; }
.list-viewport [tabindex]:hover, .list-viewport [role="option"]:hover { background: var(--hover); }
.list-viewport [aria-selected="true"], .list-viewport .selected { background: var(--accent-wash); box-shadow: inset 3px 0 var(--accent); }
.list-viewport [aria-selected="true"]:focus-visible { outline-offset: -2px; }
.console {
  height: clamp(9rem, 21vh, 16rem); margin: 0; padding: .75rem 1rem; overflow: auto; background: var(--inset);
  color: var(--muted); font: .83rem/1.55 var(--mono); white-space: pre; tab-size: 4; scrollbar-width: thin; scrollbar-color: var(--line) transparent;
}
.log-line { display: block; min-height: 1.55em; white-space: pre; }
.log-line.info, .log-line .level { color: var(--accent); }
.log-line.warn, .log-line.warning { color: var(--warn); }
.log-line.error { color: var(--error); }
.tabbar { display: flex; flex-wrap: nowrap; gap: .35rem; overflow-x: auto; padding: .25rem .05rem; }
.tabbar > * { flex: none; }
.tabbar [aria-selected="true"], .tabbar [aria-current="page"], .tabbar .active { color: var(--accent); background: var(--accent-wash); border-color: transparent; }

/* Channel viewport */
.chat-app {
  display: flex; flex-direction: column; width: min(100%, 82rem); height: 100vh; height: 100dvh;
  min-height: 0; margin-inline: auto; background: var(--page); overflow: hidden;
}
.chat-header, .presence-pane, .composer { flex: none; background: var(--surface); }
.chat-header {
  display: flex; align-items: center; flex-wrap: wrap; gap: .45rem .7rem; padding: .65rem 1rem;
  padding-top: max(.65rem, env(safe-area-inset-top)); border-bottom: 1px solid var(--line-soft);
}
.presence-pane { min-width: 0; padding: .5rem 1rem; border-bottom: 1px solid var(--line); }
.presence-list {
  display: grid; grid-template-columns: minmax(0, 1fr); gap: .2rem;
  max-height: min(22dvh, 9rem); overflow-y: auto; margin: 0; padding: 0; list-style: none;
}
.presence-user { font: .88rem/1.45 var(--mono); overflow-wrap: anywhere; }
.message, .message-author, .presence-user, .receipt {
  --strong-user-color: color-mix(in srgb, var(--user-accent, var(--accent)) var(--mix-pct), var(--mix-base));
}
.presence-user.here strong, .presence-user.here .username { color: var(--strong-user-color); font-weight: 700; }
.presence-user.idle, .presence-user.idle :is(strong, .username) { color: var(--text); font-weight: 400; }
.presence-user.offline, .presence-user.offline :is(strong, .username) { color: var(--quiet); font-style: italic; font-weight: 400; }
.conversation {
  flex: 1 1 0; min-height: 0; display: flex; flex-direction: column; align-items: flex-start; gap: .3rem;
  overflow: auto; overscroll-behavior: contain; padding: .85rem 1rem 1rem; scroll-padding-block: .65rem; scrollbar-width: thin; scrollbar-color: var(--line) transparent;
}
.conversation > * { flex: none; min-width: 0; }
.conversation .empty-state { margin: auto; max-width: 28rem; text-align: center; }
.message {
  width: fit-content; max-width: min(100%, 70rem); padding: .34rem .65rem;
  border: 1px solid color-mix(in srgb, var(--user-accent, var(--accent)) 22%, var(--line-soft));
  border-radius: .16rem .52rem .52rem .52rem;
  background: color-mix(in srgb, var(--user-accent, var(--accent)) 8%, var(--surface));
  line-height: 1.38; overflow-wrap: anywhere;
}
:root[data-theme="light"] .message {
  --mix-pct: 27%;
  --muted: #2a3b36;
  --quiet: var(--muted);
  --link: #043c5c;
  background-color: color-mix(in srgb, var(--user-accent, var(--accent)) 26%, #d0ddd7);
}
.message-time { color: var(--muted); font: .77rem/1.4 var(--mono); font-variant-numeric: tabular-nums; white-space: nowrap; }
.message-author { color: var(--strong-user-color); font-weight: 715; }
.message-body { color: var(--user-font, var(--text)); white-space: pre-wrap; overflow-wrap: anywhere; }
.message button { min-height: 1.65rem; padding: .2rem .4rem; font-size: .8rem; }
.quote { min-width: 0; padding: .35rem .55rem; border-inline-start: 2px solid var(--user-accent, var(--accent)); border-radius: .2rem; background: var(--inset); color: var(--muted); font-size: .87rem; overflow-wrap: anywhere; }
.receipt {
  display: inline-flex; align-items: center; justify-content: center; vertical-align: middle;
  flex: none; width: 1.28rem; height: 1.28rem; border: 1px solid var(--strong-user-color); border-radius: 50%;
  background: color-mix(in srgb, var(--user-accent, var(--accent)) 13%, var(--surface));
  color: var(--strong-user-color); font: 700 .75rem/1 var(--sans);
}
.typing { flex: none; min-height: 1.55rem; padding: .12rem 1rem; color: var(--muted); font-size: .84rem; }
.composer { display: grid; gap: .45rem; padding: .55rem 1rem .7rem; padding-bottom: max(.7rem, env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
.composer textarea { display: block; width: 100%; min-height: 3.1rem; max-height: min(10rem, 20dvh); resize: vertical; }
.composer-actions { flex-wrap: wrap; }
.composer-actions .send, .composer-actions .primary { margin-inline-start: auto; }

/* Settings, media and calls */
dialog {
  width: min(28rem, calc(100% - 2rem)); max-width: 100%; max-height: min(90vh, 90dvh);
  padding: 1.25rem; border-radius: .85rem; overflow: auto;
}
dialog::backdrop { background: rgb(4 11 13 / 63%); }
dialog[open]:not(.drawer) > * + * { margin-top: .85rem; }
.drawer {
  position: fixed; z-index: 3; inset: 0 0 0 auto; width: min(24rem, 92vw); max-width: 100%; height: 100%; max-height: 100%;
  margin: 0; padding: max(1rem, env(safe-area-inset-top)) 1rem max(1rem, env(safe-area-inset-bottom));
  overflow: auto; overscroll-behavior: contain; border: 0; border-inline-start: 1px solid var(--line); border-radius: 0; background: var(--surface); box-shadow: var(--shadow);
}
.drawer[aria-hidden="true"] { display: none; }
.drawer-head { min-height: 2.75rem; margin-bottom: 1.25rem; border-bottom: 1px solid var(--line-soft); padding-bottom: .65rem; }
.player { width: min(100% - 2rem, 56rem); margin: 1rem auto; padding: 1rem; }
.player :is(img, video, audio) { display: block; max-width: 100%; margin-inline: auto; }
.player :is(img, video) { width: auto; max-height: 74vh; object-fit: contain; }
.player :is(video, audio) { width: 100%; }
.call-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 17rem), 1fr)); gap: .7rem; padding: .8rem; align-content: start; }
.call-tile { position: relative; isolation: isolate; display: grid; place-items: center; aspect-ratio: 16 / 10; overflow: hidden; background: #0a1418; }
.call-tile video { width: 100%; height: 100%; object-fit: contain; }
.call-tile figcaption, .call-tile .tile-label { position: absolute; inset: auto auto .55rem .55rem; padding: .2rem .45rem; border-radius: .28rem; background: rgb(4 14 19 / 80%); color: white; font-size: .83rem; }
.call-controls { justify-content: center; flex-wrap: wrap; padding: .7rem 1rem max(.7rem, env(safe-area-inset-bottom)); }

@media (min-width: 82rem) {
  .chat-app { border-inline: 1px solid var(--line-soft); }
}
@media (max-width: 48rem) {
  .panels, .settings-grid { grid-template-columns: minmax(0, 1fr); }
  .topbar-inner { min-height: 3.65rem; }
  .chat-header, .presence-pane, .conversation, .typing, .composer { padding-inline: max(.65rem, env(safe-area-inset-left)) max(.65rem, env(safe-area-inset-right)); }
  .chat-header { gap: .3rem .5rem; }
  .presence-list { max-height: 5.8rem; overflow-y: auto; }
  .list-viewport { scrollbar-width: auto; }
}
@media (max-width: 34rem) {
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .5rem; }
  .metric { padding: .76rem; }
  .panel-head, .panel-body, .panel-actions { padding-inline: .75rem; }
  .composer-actions { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: .27rem; }
  .composer-actions button { width: 100%; padding-inline: .2rem; font-size: .84rem; }
  .composer-actions :is(.send, .primary) { margin: 0; }
  .message { max-width: 100%; padding: .28rem .48rem; }
}
@media (pointer: coarse) {
  button, .button, .panel-actions button, .menu-handle, .icon-button, .composer-actions button { min-height: 2.75rem; }
  .menu-handle, .icon-button { min-width: 2.75rem; }
}
@media (max-height: 28rem) and (orientation: landscape) {
  .auth-shell { place-items: start center; }
  .chat-header, .presence-pane, .composer { padding-block: .25rem; }
  .presence-list { max-height: 2rem; }
  .composer textarea { min-height: 2.35rem; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}
@media (forced-colors: active) {
  #login-screen .auth-card { border-color: CanvasText; }
  .login-border { display: none; }
  #login-screen .wordmark { -webkit-text-fill-color: CanvasText; }
  .message, .receipt, .panel, .metric { border-color: CanvasText; }
  .list-viewport [aria-selected="true"] { outline: 2px solid Highlight; outline-offset: -2px; }
}
