/* Belfort main interface: layout and components. Tokens live in tokens.css. */

*, *::before, *::after { box-sizing: border-box; }

html { height: 100%; -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  font-size: var(--fs-md);
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  background-image:
    radial-gradient(900px 600px at 100% -10%, var(--bg-glow), transparent 60%),
    radial-gradient(700px 500px at -10% 110%, var(--bg-glow), transparent 60%);
  background-attachment: fixed;
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

.bg-grid {
  position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background-image:
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: radial-gradient(ellipse at 70% 0%, rgba(0,0,0,.9), transparent 75%);
  -webkit-mask-image: radial-gradient(ellipse at 70% 0%, rgba(0,0,0,.9), transparent 75%);
}

[hidden] { display: none !important; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }

h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
p { margin: 0; }
ul { list-style: none; margin: 0; padding: 0; }
button { font: inherit; color: inherit; }
input, textarea, select { font: inherit; color: inherit; }
svg { display: block; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

bdi, [dir="ltr"], [dir="auto"] { unicode-bidi: isolate; }

.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--text-2); }
.faint { color: var(--text-3); }
.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* ---------- App frame ---------- */

.app {
  position: relative; z-index: 1;
  display: grid;
  grid-template-columns: var(--rail-w) minmax(0, 1fr);
  min-height: 100dvh;
}

.main-wrap {
  min-width: 0;
  display: flex; flex-direction: column;
}

.screen {
  width: 100%;
  max-width: var(--content-max);
  margin: 0 auto;
  padding: var(--s-6) var(--s-6) calc(var(--s-8) + env(safe-area-inset-bottom));
  outline: none;
}

/* ---------- Side rail ---------- */

.rail {
  position: sticky; top: 0;
  height: 100dvh;
  display: flex; flex-direction: column;
  padding: var(--s-4) var(--s-2) calc(var(--s-3) + env(safe-area-inset-bottom));
  border-inline-start: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 70%, transparent);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

.rail-brand {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: var(--s-2) 0 var(--s-5);
  color: var(--text);
}
.rail-brand:hover { text-decoration: none; }
.brand-dot {
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--accent);
  box-shadow: var(--accent-glow);
}
.brand-name { font-size: var(--fs-xs); font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-2); }

.rail-list { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.rail-foot { display: flex; flex-direction: column; gap: 2px; padding-top: var(--s-3); border-top: 1px solid var(--line); }

.rail-btn {
  position: relative;
  width: 100%;
  min-height: 56px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  padding: 8px 4px;
  border: 0; border-radius: var(--r-md);
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.rail-btn:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.rail-btn.is-active { color: var(--accent); background: var(--accent-soft); }
.rail-btn.is-active::before {
  content: ""; position: absolute; inset-inline-end: -8px; top: 14px; bottom: 14px; width: 3px;
  border-radius: 3px; background: var(--accent); box-shadow: var(--accent-glow);
}
.rail-icon { width: 22px; height: 22px; display: inline-flex; }
.rail-icon svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.rail-label { font-size: var(--fs-xs); line-height: 1.2; }

.badge {
  position: absolute; top: 6px; inset-inline-start: calc(50% + 6px);
  min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 9px;
  font-size: 11px; font-weight: 600; line-height: 18px; text-align: center;
  background: var(--accent); color: var(--on-accent);
  box-shadow: 0 0 0 2px var(--surface);
}
.badge:empty { display: none; }
.unread-dot {
  position: absolute; top: 10px; inset-inline-start: calc(50% + 8px);
  width: 8px; height: 8px; border-radius: 50%; background: var(--accent); box-shadow: var(--accent-glow);
}

/* ---------- Bottom tab bar (phone) ---------- */

.tabbar {
  display: none;
  position: fixed; inset-inline: 0; bottom: 0; z-index: 30;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  border-top: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 82%, transparent);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}
.tab-item {
  position: relative;
  flex: 1; min-width: 44px; min-height: 44px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  border: 0; background: transparent; color: var(--text-2);
  font-size: 11px; cursor: pointer;
}
.tab-item.is-active { color: var(--accent); }
.tab-item:hover { text-decoration: none; }
.tab-item .badge { top: 4px; inset-inline-start: calc(50% + 4px); }

.fab {
  display: none;
  position: fixed; inset-inline-start: 16px; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
  z-index: 29;
  width: 52px; height: 52px; border-radius: 50%;
  border: 0; background: var(--accent); color: var(--on-accent);
  box-shadow: var(--shadow-2), var(--accent-glow);
  align-items: center; justify-content: center; cursor: pointer;
}
.fab .rail-icon svg { stroke: currentColor; }

/* ---------- Banner, toasts ---------- */

.banner {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: var(--s-2);
  padding: 8px var(--s-5);
  font-size: var(--fs-sm);
  color: var(--warn);
  background: var(--warn-soft);
  border-bottom: 1px solid var(--line);
}
.banner-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); animation: pulse 1.4s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }

.toasts {
  position: fixed; inset-inline-start: 50%; bottom: calc(var(--s-5) + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 100;
  display: flex; flex-direction: column; gap: var(--s-2);
  pointer-events: none;
  width: min(92vw, 420px);
}
.toast {
  pointer-events: auto;
  padding: 12px 16px;
  border-radius: var(--r-md);
  background: var(--text); color: var(--text-inverse);
  box-shadow: var(--shadow-2);
  font-size: var(--fs-sm);
  animation: rise var(--t-med) var(--ease) both;
}
.toast-error { background: var(--danger); color: #fff; }
.toast-ok { background: var(--ok); color: #fff; }

/* ---------- Screen header ---------- */

.screen-head {
  display: flex; align-items: flex-end; justify-content: space-between; gap: var(--s-4); flex-wrap: wrap;
  margin-bottom: var(--s-6);
}
.screen-title { font-size: var(--fs-2xl); font-weight: 600; letter-spacing: -0.02em; }
.screen-sub { margin-top: 4px; color: var(--text-2); font-size: var(--fs-md); display: flex; gap: var(--s-3); flex-wrap: wrap; align-items: center; }
.screen-actions { display: flex; gap: var(--s-2); align-items: center; flex-wrap: wrap; }

/* ---------- Cards ---------- */

.card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-1);
  padding: var(--s-5);
  min-width: 0;
  animation: rise 420ms var(--ease) both;
  animation-delay: calc(var(--i, 0) * 45ms);
}
.card-label {
  display: flex; align-items: center; justify-content: space-between; gap: var(--s-2);
  font-size: var(--fs-sm); color: var(--text-2); margin-bottom: var(--s-4);
}
.card-label strong { color: var(--text); font-weight: 600; font-size: var(--fs-md); }
.card-foot { margin-top: var(--s-4); padding-top: var(--s-3); border-top: 1px solid var(--line); font-size: var(--fs-sm); color: var(--text-2); display: flex; justify-content: space-between; gap: var(--s-2); }

.grid-hero {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: var(--s-4);
  margin-bottom: var(--s-4);
}
.grid-hero > .card { grid-column: span 6; }
.grid-hero > .card.span-4 { grid-column: span 4; }
.grid-hero > .card.span-12 { grid-column: span 12; }
.card.hero { padding: var(--s-6); }
.card.hero .card-label strong { font-size: var(--fs-lg); }

.initiative {
  grid-column: span 12;
  display: flex; align-items: center; gap: var(--s-4);
  padding: var(--s-5) var(--s-6);
  border-color: var(--accent-line);
  background: linear-gradient(90deg, var(--accent-soft), transparent 60%), var(--surface);
  box-shadow: var(--shadow-1), var(--accent-glow);
}
.initiative-mark { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); box-shadow: var(--accent-glow); flex: none; }
.initiative-text { font-size: var(--fs-lg); }
.initiative-text.faint { font-size: var(--fs-md); }

.grid-small {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--s-4);
}
.grid-small .card { padding: var(--s-4) var(--s-5); }
.mini {
  display: flex; align-items: center; justify-content: space-between; gap: var(--s-3);
  color: inherit;
}
.mini:hover { text-decoration: none; }
.mini-value { font-size: var(--fs-2xl); font-weight: 600; letter-spacing: -0.02em; line-height: 1; }
.mini-label { color: var(--text-2); font-size: var(--fs-sm); }

/* ---------- Lists and items ---------- */

.list { display: flex; flex-direction: column; }
.item {
  display: flex; align-items: flex-start; gap: var(--s-3);
  padding: 10px 0;
  border-top: 1px solid var(--line);
}
.item:first-child { border-top: 0; padding-top: 0; }
.list.boxed .item { padding: 12px var(--s-2); }
.item-main { flex: 1; min-width: 0; }
.item-title { font-weight: 500; overflow-wrap: anywhere; }
.item.is-done .item-title { color: var(--text-3); text-decoration: line-through; }
.item-meta { display: flex; flex-wrap: wrap; gap: 6px 10px; margin-top: 3px; font-size: var(--fs-sm); color: var(--text-2); align-items: center; }
.item-actions { display: flex; gap: 4px; align-items: center; flex: none; }
.item-time { flex: none; min-width: 3.2em; color: var(--accent); font-weight: 500; font-size: var(--fs-sm); padding-top: 2px; }
.item-text { color: var(--text-2); font-size: var(--fs-sm); margin-top: 3px; overflow-wrap: anywhere; }

.check {
  flex: none;
  width: 24px; height: 24px; margin-top: 1px;
  border-radius: 50%;
  border: 1.5px solid var(--line-strong);
  background: transparent;
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  color: transparent;
  transition: all var(--t-fast) var(--ease);
}
.check svg { width: 14px; height: 14px; stroke: currentColor; fill: none; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.check:hover { border-color: var(--accent); color: var(--accent); }
.check.is-done { background: var(--accent); border-color: var(--accent); color: var(--on-accent); box-shadow: var(--accent-glow); }
.check:disabled { opacity: .5; cursor: default; }

.pill {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: var(--fs-xs);
  font-weight: 500;
  background: var(--surface-2); color: var(--text-2);
  white-space: nowrap;
}
.pill-accent { background: var(--accent-soft); color: var(--accent); }
.pill-ok { background: var(--ok-soft); color: var(--ok); }
.pill-warn { background: var(--warn-soft); color: var(--warn); }
.pill-danger { background: var(--danger-soft); color: var(--danger); }

.group-title {
  display: flex; align-items: center; gap: var(--s-2);
  font-size: var(--fs-sm); color: var(--text-2); font-weight: 500;
  margin: var(--s-5) 0 var(--s-2);
}
.group-title:first-child { margin-top: 0; }
.group-title .count { color: var(--text-3); }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 36px; padding: 6px 14px;
  border-radius: var(--r-md);
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-size: var(--fs-sm); font-weight: 500;
  transition: background var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease), transform var(--t-fast) var(--ease);
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: default; }
.btn-primary { background: var(--accent); border-color: transparent; color: var(--on-accent); box-shadow: var(--accent-glow); }
.btn-primary:hover { background: var(--accent-strong); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-danger { color: var(--danger); border-color: transparent; background: transparent; }
.btn-danger:hover { background: var(--danger-soft); }
.btn-lg { min-height: 48px; padding: 10px 22px; font-size: var(--fs-md); border-radius: var(--r-lg); }
.btn-sm { min-height: 30px; padding: 3px 10px; font-size: var(--fs-xs); }
.btn .rail-icon, .btn .rail-icon svg { width: 16px; height: 16px; }

.icon-btn {
  width: 40px; height: 40px;
  display: inline-flex; align-items: center; justify-content: center;
  border: 0; border-radius: var(--r-md); background: transparent; color: var(--text-2); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn .rail-icon, .icon-btn .rail-icon svg { width: 18px; height: 18px; }

.btn-row { display: flex; gap: var(--s-2); flex-wrap: wrap; margin-top: var(--s-4); }

/* ---------- Tabs, inputs, forms ---------- */

.tabs { display: inline-flex; gap: 2px; padding: 3px; border-radius: var(--r-md); background: var(--surface-2); }
.tab {
  min-height: 34px; padding: 4px 14px;
  border: 0; border-radius: 9px; background: transparent; color: var(--text-2);
  font-size: var(--fs-sm); font-weight: 500; cursor: pointer;
}
.tab:hover { color: var(--text); text-decoration: none; }
.tab[aria-selected="true"], .tab.is-active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-1); }

.input, .select, .textarea {
  width: 100%;
  min-height: 42px;
  padding: 8px 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-md);
  background: var(--surface);
  color: var(--text);
  transition: border-color var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease);
}
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--accent); box-shadow: var(--accent-glow); }
.input::placeholder { color: var(--text-3); }
.select { appearance: none; -webkit-appearance: none; padding-inline-end: 34px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%237f8a98' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 6l4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: left 12px center; }
.search { position: relative; max-width: 520px; }
.search .input { padding-inline-start: 40px; }
.search .rail-icon { position: absolute; inset-inline-start: 12px; top: 50%; transform: translateY(-50%); color: var(--text-3); width: 18px; height: 18px; }
.search .rail-icon svg { width: 18px; height: 18px; }

.form { display: flex; flex-direction: column; gap: var(--s-4); }
.field { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr); gap: var(--s-3); align-items: center; padding: 10px 0; border-top: 1px solid var(--line); }
.field:first-child { border-top: 0; }
.field-label { font-size: var(--fs-sm); color: var(--text-2); }
.field-hint { font-size: var(--fs-xs); color: var(--text-3); margin-top: 2px; }
.field.saved .field-label::after { content: " ✓"; color: var(--ok); }

.switch {
  position: relative; width: 46px; height: 28px; flex: none;
  border-radius: 14px; border: 0; background: var(--surface-3); cursor: pointer;
  transition: background var(--t-fast) var(--ease);
}
.switch::after {
  content: ""; position: absolute; top: 3px; inset-inline-start: 3px;
  width: 22px; height: 22px; border-radius: 50%; background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,.3);
  transition: transform var(--t-fast) var(--ease);
}
.switch[aria-checked="true"] { background: var(--accent); box-shadow: var(--accent-glow); }
.switch[aria-checked="true"]::after { transform: translateX(-18px); }

.kv { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 8px 16px; font-size: var(--fs-sm); }
.kv dt { color: var(--text-2); }
.kv dd { margin: 0; overflow-wrap: anywhere; }

/* ---------- Table ---------- */

.table-wrap {
  overflow: auto;
  max-height: min(70vh, 720px);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--surface);
  box-shadow: var(--shadow-1);
  overscroll-behavior-x: contain;
}
.table { border-collapse: separate; border-spacing: 0; min-width: 100%; font-size: var(--fs-sm); }
.table th, .table td { padding: 10px 12px; text-align: start; white-space: nowrap; border-bottom: 1px solid var(--line); max-width: 320px; overflow: hidden; text-overflow: ellipsis; }
.table th {
  position: sticky; top: 0; z-index: 2;
  background: var(--surface-2); color: var(--text-2); font-weight: 500;
  border-bottom: 1px solid var(--line-strong);
}
.table th:first-child, .table td:first-child { position: sticky; inset-inline-start: 0; z-index: 1; background: var(--surface); box-shadow: -1px 0 0 var(--line) inset; }
.table th:first-child { z-index: 3; background: var(--surface-2); }
.table tbody tr { cursor: pointer; }
.table tbody tr:hover td { background: var(--accent-soft); }
.table tbody tr:hover td:first-child { background: color-mix(in srgb, var(--accent-soft), var(--surface)); }
.table td:empty::after { content: "–"; color: var(--text-3); }

.diff-table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); margin-top: var(--s-3); }
.diff-table th, .diff-table td { padding: 8px 10px; text-align: start; border-bottom: 1px solid var(--line); vertical-align: top; overflow-wrap: anywhere; }
.diff-table th { color: var(--text-2); font-weight: 500; }
.diff-before { color: var(--text-3); text-decoration: line-through; }
.diff-after { color: var(--accent); font-weight: 500; }

/* ---------- Timeline ---------- */

.timeline { position: relative; padding-inline-start: 22px; }
.timeline::before { content: ""; position: absolute; inset-inline-start: 6px; top: 8px; bottom: 8px; width: 1px; background: var(--line-strong); }
.tl-day { margin: var(--s-5) 0 var(--s-2); font-size: var(--fs-sm); color: var(--text-2); font-weight: 500; }
.tl-day:first-child { margin-top: 0; }
.tl-item { position: relative; padding: 8px 0 8px; display: flex; gap: var(--s-3); align-items: flex-start; }
.tl-dot { position: absolute; inset-inline-start: -20px; top: 15px; width: 9px; height: 9px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 3px var(--bg); }
.tl-time { flex: none; width: 3.2em; color: var(--text-3); font-size: var(--fs-sm); padding-top: 2px; }
.tl-prev { font-size: var(--fs-xs); color: var(--text-3); margin-top: 2px; }

/* ---------- Stats, chart ---------- */

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: var(--s-4); margin-bottom: var(--s-4); }
.stat { padding: var(--s-4) var(--s-5); }
.stat-value { font-size: var(--fs-2xl); font-weight: 600; letter-spacing: -0.02em; line-height: 1.1; }
.stat-label { color: var(--text-2); font-size: var(--fs-sm); margin-top: 6px; }
.stat-state-normal .stat-value { color: var(--ok); }
.stat-state-degraded .stat-value { color: var(--warn); }
.stat-state-stopped .stat-value { color: var(--danger); }

.meter { height: 6px; border-radius: 3px; background: var(--surface-3); overflow: hidden; margin-top: var(--s-3); }
.meter > span { display: block; height: 100%; background: var(--accent); border-radius: 3px; box-shadow: var(--accent-glow); transition: width var(--t-med) var(--ease); }

.chart { width: 100%; height: auto; display: block; }
.chart .bar { fill: var(--accent); opacity: .85; }
.chart .bar:hover { opacity: 1; }
.chart .axis { stroke: var(--line-strong); }
.chart text { fill: var(--text-3); font-size: 10px; font-family: var(--font); }
.chart .grid { stroke: var(--line); }

.two-col { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: var(--s-4); }
.simple-table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.simple-table th, .simple-table td { padding: 8px 4px; text-align: start; border-bottom: 1px solid var(--line); }
.simple-table th { color: var(--text-2); font-weight: 500; }
.simple-table td.num, .simple-table th.num { text-align: end; }

/* ---------- Empty, skeleton ---------- */

.empty { padding: var(--s-4) 0; color: var(--text-3); font-size: var(--fs-sm); }
.empty-big { padding: var(--s-7) var(--s-4); text-align: center; color: var(--text-3); }

.sk { position: relative; overflow: hidden; background: var(--surface-2); border-radius: var(--r-sm); }
.sk::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--surface) 60%, transparent), transparent);
  transform: translateX(-100%);
  animation: shimmer 1.4s infinite;
}
@keyframes shimmer { to { transform: translateX(100%); } }
.sk-line { height: 14px; margin: 10px 0; width: 70%; }
.sk-line.w-40 { width: 40%; } .sk-line.w-90 { width: 90%; } .sk-line.w-55 { width: 55%; }
.sk-card { height: 160px; border-radius: var(--r-lg); }
.sk-title { height: 30px; width: 30%; margin-bottom: var(--s-5); }

/* ---------- Drawers, sheet ---------- */

.drawer { position: fixed; inset: 0; z-index: 60; }
.drawer-backdrop, .sheet-backdrop { position: absolute; inset: 0; background: rgba(6, 10, 16, .45); backdrop-filter: blur(2px); -webkit-backdrop-filter: blur(2px); animation: fade var(--t-med) var(--ease) both; }
.drawer-panel {
  position: absolute; top: 0; bottom: 0; inset-inline-end: auto; inset-inline-start: 0;
  width: min(var(--drawer-w), 100vw);
  display: flex; flex-direction: column;
  background: var(--surface);
  border-inline-end: 1px solid var(--line);
  box-shadow: var(--shadow-2);
  animation: slide-in var(--t-med) var(--ease) both;
  padding-bottom: env(safe-area-inset-bottom);
}
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: var(--s-4) var(--s-4) var(--s-3) var(--s-5); border-bottom: 1px solid var(--line); }
.drawer-title { font-size: var(--fs-lg); }
.panel-body { overflow: auto; padding: var(--s-4) var(--s-5); }

.chat-log { flex: 1; overflow: auto; padding: var(--s-4) var(--s-5); display: flex; flex-direction: column; gap: var(--s-3); }
.chat-msg { max-width: 88%; padding: 10px 14px; border-radius: var(--r-lg); font-size: var(--fs-md); line-height: 1.5; overflow-wrap: anywhere; animation: rise var(--t-med) var(--ease) both; }
.chat-msg.avi { align-self: flex-start; background: var(--accent); color: var(--on-accent); border-start-start-radius: 6px; }
.chat-msg.belfort { align-self: flex-end; background: var(--surface-2); border-start-end-radius: 6px; }
.chat-msg.belfort a { color: var(--accent); }
.chat-msg .chat-time { display: block; margin-top: 4px; font-size: var(--fs-xs); opacity: .7; }
.chat-msg.pending { opacity: .6; }
.chat-form { display: flex; gap: var(--s-2); align-items: flex-end; padding: var(--s-3) var(--s-4); border-top: 1px solid var(--line); }
.chat-input { flex: 1; resize: none; max-height: 160px; min-height: 44px; padding: 10px 14px; border: 1px solid var(--line-strong); border-radius: var(--r-lg); background: var(--surface-2); }
.chat-input:focus { outline: none; border-color: var(--accent); box-shadow: var(--accent-glow); }
.chat-send { width: 44px; height: 44px; padding: 0; border-radius: 50%; flex: none; }
.chat-send .rail-icon svg { transform: scaleX(-1); }

.sheet { position: fixed; inset: 0; z-index: 60; }
.sheet-panel {
  position: absolute; inset-inline: 0; bottom: 0;
  padding: var(--s-2) var(--s-3) calc(var(--s-4) + env(safe-area-inset-bottom));
  background: var(--surface);
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  box-shadow: var(--shadow-2);
  animation: slide-up var(--t-med) var(--ease) both;
}
.sheet-handle { width: 36px; height: 4px; border-radius: 2px; background: var(--line-strong); margin: 4px auto 12px; }
.sheet-list { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--s-2); }
.sheet-list .rail-btn { min-height: 72px; background: var(--surface-2); }
.sheet-list .rail-btn.is-active { background: var(--accent-soft); }

/* ---------- Login ---------- */

.login {
  position: relative; z-index: 1;
  min-height: 100dvh; display: grid; place-items: center; padding: var(--s-5);
}
.login-card {
  width: min(100%, 420px);
  padding: var(--s-7) var(--s-6);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-xl);
  box-shadow: var(--shadow-2);
  text-align: center;
  animation: rise 500ms var(--ease) both;
}
.login-mark { width: 44px; height: 44px; margin: 0 auto var(--s-4); border-radius: 50%; border: 2px solid var(--accent); position: relative; box-shadow: var(--accent-glow); }
.login-mark::after { content: ""; position: absolute; inset: 13px; border-radius: 50%; background: var(--accent); }
.login-title { font-size: var(--fs-xl); letter-spacing: 0.06em; }
.login-sub { color: var(--text-2); margin: var(--s-2) 0 var(--s-6); }
.login-step { display: flex; flex-direction: column; gap: var(--s-3); align-items: stretch; }
.login-actions { display: flex; flex-direction: column; gap: var(--s-2); }
.code-input {
  width: 100%; text-align: center;
  font-size: 32px; letter-spacing: 0.4em; font-variant-numeric: tabular-nums;
  padding: 10px; border: 1px solid var(--line-strong); border-radius: var(--r-lg); background: var(--surface-2);
}
.code-input:focus { outline: none; border-color: var(--accent); box-shadow: var(--accent-glow); }
.login-msg { min-height: 1.5em; margin-top: var(--s-4); color: var(--text-2); font-size: var(--fs-sm); }
.login-msg.error { color: var(--danger); }

/* ---------- Motion ---------- */

@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes slide-in { from { transform: translateX(-24px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes slide-up { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
.is-leaving { transition: opacity var(--t-med) var(--ease), transform var(--t-med) var(--ease); opacity: 0; transform: scale(.98); }

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

/* ---------- Responsive ---------- */

@media (max-width: 1100px) {
  .grid-hero > .card, .grid-hero > .card.span-4 { grid-column: span 6; }
}

@media (max-width: 899px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .rail { display: none; }
  .tabbar { display: flex; }
  .fab { display: inline-flex; }
  .screen { padding: var(--s-4) var(--s-4) calc(var(--tabbar-h) + env(safe-area-inset-bottom) + var(--s-7)); }
  .screen-title { font-size: var(--fs-xl); }
  .grid-hero > .card, .grid-hero > .card.span-4 { grid-column: span 12; }
  .card.hero { padding: var(--s-5); }
  .field { grid-template-columns: 1fr; gap: 6px; }
  .btn, .tab { min-height: 44px; }
  .btn-sm { min-height: 36px; }
  .check { width: 28px; height: 28px; }
  .drawer-panel { width: 100vw; border: 0; }
  .toasts { bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + var(--s-3)); }
}

@media (min-width: 1400px) {
  :root { --rail-w: 104px; }
}
