:root {
  --bg: #f4f3ef;
  --surface: rgba(255, 255, 255, 0.72);
  --surface-solid: #fff;
  --surface-muted: #ebeae5;
  --text: #141518;
  --muted: #6d6e72;
  --border: rgba(20, 21, 24, 0.12);
  --border-strong: rgba(20, 21, 24, 0.2);
  --accent: #df1731;
  --accent-hover: #c90f27;
  --danger-bg: rgba(223, 23, 49, 0.08);
  --shadow: 0 24px 80px rgba(15, 18, 25, 0.1);
  --radius-lg: 24px;
  --radius-md: 15px;
  --radius-sm: 10px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0c0f;
    --surface: rgba(25, 27, 32, 0.78);
    --surface-solid: #16181d;
    --surface-muted: #202229;
    --text: #f4f2ed;
    --muted: #9b9ca1;
    --border: rgba(255, 255, 255, 0.1);
    --border-strong: rgba(255, 255, 255, 0.18);
    --danger-bg: rgba(255, 71, 94, 0.12);
    --shadow: 0 28px 90px rgba(0, 0, 0, 0.42);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

button, input, textarea { font: inherit; }
button { color: inherit; }
[hidden] { display: none !important; }

.noise {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  opacity: 0.32;
  background:
    radial-gradient(circle at 15% 10%, rgba(223, 23, 49, 0.12), transparent 30%),
    radial-gradient(circle at 85% 90%, rgba(70, 92, 255, 0.08), transparent 32%);
}

.eyebrow {
  margin: 0;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.16em;
}

.muted { color: var(--muted); }

.login-shell {
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: max(24px, var(--safe-top)) 24px max(24px, var(--safe-bottom));
}

.login-card {
  width: min(100%, 460px);
  padding: clamp(28px, 7vw, 52px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  backdrop-filter: blur(24px);
}

.login-card h1 {
  margin: 14px 0 10px;
  font-size: clamp(2.2rem, 9vw, 4rem);
  line-height: 0.98;
  letter-spacing: -0.06em;
}

.lede {
  margin: 0 0 36px;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.7;
}

.stack-lg { display: grid; gap: 14px; }
.field-label { font-size: 0.8rem; font-weight: 650; }

input, textarea {
  width: 100%;
  border: 1px solid var(--border-strong);
  background: var(--surface-solid);
  color: var(--text);
  outline: none;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}

input { height: 48px; padding: 0 14px; border-radius: var(--radius-sm); }
input:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(223, 23, 49, 0.12); }

.button {
  min-height: 44px;
  border: 0;
  border-radius: var(--radius-sm);
  padding: 0 17px;
  font-weight: 680;
  cursor: pointer;
  transition: transform 120ms ease, background 120ms ease, opacity 120ms ease;
}
.button:active { transform: scale(0.98); }
.button:disabled { cursor: wait; opacity: 0.5; }
.button.primary { background: var(--accent); color: #fff; }
.button.primary:hover { background: var(--accent-hover); }
.button.secondary { background: var(--surface-muted); }
.button.danger { background: var(--danger-bg); color: var(--accent); }
.button.compact { min-height: 36px; padding: 0 13px; font-size: 0.82rem; }

.form-error { min-height: 1.2em; margin: 0; color: var(--accent); font-size: 0.8rem; }

.app-shell { height: 100svh; overflow: hidden; }

.topbar {
  height: calc(76px + var(--safe-top));
  padding: calc(16px + var(--safe-top)) 22px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(18px);
}

.topbar-title { margin: 3px 0 0; font-size: 1.15rem; letter-spacing: -0.02em; }
.topbar-actions { display: flex; align-items: center; gap: 9px; }

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 32px;
  padding: 0 11px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.75rem;
}
.status-pill i { width: 7px; height: 7px; border-radius: 50%; background: #d09a28; }
.status-pill.online i { background: #30a46c; box-shadow: 0 0 0 4px rgba(48, 164, 108, 0.12); }

.icon-button, .text-button {
  border: 0;
  background: transparent;
  cursor: pointer;
}
.icon-button { width: 36px; height: 36px; border-radius: 50%; font-size: 1.2rem; }
.icon-button:hover { background: var(--surface-muted); }
.text-button { color: var(--muted); font-size: 0.76rem; }

.workspace {
  height: calc(100svh - 76px - var(--safe-top));
  display: grid;
  grid-template-columns: minmax(250px, 320px) 1fr;
}

.rail {
  min-width: 0;
  overflow: auto;
  border-right: 1px solid var(--border);
  padding: 18px 12px calc(18px + var(--safe-bottom));
}

.rail-section + .rail-section { margin-top: 24px; }
.section-heading { display: flex; justify-content: space-between; align-items: center; padding: 0 9px 9px; font-size: 0.73rem; font-weight: 720; color: var(--muted); }
.device-list, .session-list { display: grid; gap: 4px; }

.device-row, .session-row {
  width: 100%;
  border: 0;
  border-radius: 12px;
  background: transparent;
  padding: 11px;
  text-align: left;
  cursor: pointer;
}
.device-row:hover, .session-row:hover { background: var(--surface-muted); }
.device-row.active, .session-row.active { background: var(--surface-solid); box-shadow: inset 0 0 0 1px var(--border); }
.row-title { display: flex; align-items: center; gap: 8px; font-size: 0.88rem; font-weight: 650; }
.row-subtitle { margin: 5px 0 0 17px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: 0.72rem; }
.dot { width: 8px; height: 8px; flex: 0 0 auto; border-radius: 50%; background: #8d8d91; }
.dot.ready { background: #30a46c; }
.dot.disabled { background: #d09a28; }

.content-pane { min-width: 0; min-height: 0; position: relative; }
.empty-state { height: 100%; display: grid; place-content: center; justify-items: center; padding: 30px; text-align: center; }
.empty-mark { width: 54px; height: 54px; display: grid; place-items: center; border: 1px solid var(--border-strong); border-radius: 18px; color: var(--accent); font-size: 1.4rem; font-weight: 800; }
.empty-state h2 { margin: 20px 0 7px; letter-spacing: -0.03em; }
.empty-state p { max-width: 340px; margin: 0; color: var(--muted); line-height: 1.6; }

.session-view { height: 100%; display: grid; grid-template-rows: auto 1fr auto; }
.session-header { padding: 20px clamp(18px, 4vw, 42px) 16px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--border); }
.session-header h2 { max-width: 60vw; margin: 5px 0 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 1.18rem; letter-spacing: -0.025em; }

.message-list { overflow: auto; padding: 24px clamp(18px, 6vw, 90px); scroll-behavior: smooth; }
.message { max-width: 780px; margin: 0 auto 22px; }
.message-role { margin-bottom: 7px; color: var(--muted); font-size: 0.68rem; font-weight: 720; letter-spacing: 0.09em; text-transform: uppercase; }
.message-body { white-space: pre-wrap; word-break: break-word; line-height: 1.65; font-size: 0.94rem; }
.message.user .message-body { width: fit-content; max-width: min(90%, 680px); margin-left: auto; padding: 11px 14px; background: var(--surface-muted); border-radius: 16px 16px 4px 16px; }
.message.user .message-role { text-align: right; }
.message.error .message-body { color: var(--accent); }

.composer {
  margin: 0 clamp(14px, 5vw, 72px) calc(14px + var(--safe-bottom));
  padding: 8px 8px 8px 14px;
  display: flex;
  align-items: flex-end;
  gap: 9px;
  border: 1px solid var(--border-strong);
  border-radius: 18px;
  background: var(--surface-solid);
  box-shadow: 0 15px 45px rgba(0, 0, 0, 0.08);
}
.composer textarea { min-height: 36px; max-height: 144px; resize: none; border: 0; padding: 8px 0 5px; background: transparent; box-shadow: none; line-height: 1.45; }
.composer textarea:focus { box-shadow: none; }
.send-button { width: 38px; height: 38px; flex: 0 0 auto; border: 0; border-radius: 12px; background: var(--accent); color: #fff; font-size: 1.25rem; font-weight: 760; cursor: pointer; }

.pair-dialog { width: min(calc(100% - 28px), 430px); padding: 0; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface-solid); color: var(--text); box-shadow: var(--shadow); }
.pair-dialog::backdrop { background: rgba(0, 0, 0, 0.48); backdrop-filter: blur(5px); }
.pair-card { position: relative; padding: 30px; }
.pair-card h2 { margin: 9px 0 8px; letter-spacing: -0.035em; }
.pair-card p { line-height: 1.55; }
.dialog-close { position: absolute; top: 13px; right: 13px; width: 34px; height: 34px; border: 0; border-radius: 50%; background: var(--surface-muted); cursor: pointer; }
.pair-code { margin: 25px 0 18px; padding: 18px; border: 1px dashed var(--border-strong); border-radius: 14px; text-align: center; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: clamp(1.25rem, 7vw, 2rem); font-weight: 760; letter-spacing: 0.12em; }
.pair-card .button { width: 100%; }
.pair-expiry { min-height: 1em; margin: 11px 0 0; text-align: center; color: var(--muted); font-size: 0.75rem; }

.toast { position: fixed; z-index: 20; left: 50%; bottom: calc(24px + var(--safe-bottom)); transform: translateX(-50%); max-width: min(420px, calc(100% - 32px)); padding: 11px 15px; border: 1px solid var(--border); border-radius: 999px; background: var(--surface-solid); box-shadow: var(--shadow); font-size: 0.82rem; }

@media (max-width: 720px) {
  .status-pill { display: none; }
  .topbar { padding-left: 16px; padding-right: 12px; }
  .workspace { display: block; overflow: hidden; }
  .rail { height: 100%; border-right: 0; }
  .content-pane { position: absolute; inset: calc(76px + var(--safe-top)) 0 0; background: var(--bg); transform: translateX(100%); transition: transform 220ms cubic-bezier(.2,.8,.2,1); }
  .app-shell.show-session .content-pane { transform: translateX(0); }
  .session-header::before { content: "‹"; margin-right: 12px; font-size: 1.8rem; cursor: pointer; }
  .session-header { justify-content: flex-start; padding-left: 16px; }
  .session-header > div { min-width: 0; flex: 1; }
  .session-header h2 { max-width: 58vw; }
  .message-list { padding-left: 18px; padding-right: 18px; }
  .composer { margin-left: 10px; margin-right: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}
