:root {
  color-scheme: dark;
  --bg: #11131d;
  --surface: #1d1f2a;
  --surface-high: #282934;
  --text: #e1e1f0;
  --muted: #c4c6cc;
  --primary: #82cfff;
  --success: #4de082;
  --warning: #f6c85f;
  --error: #ffb4ab;
  --border: #44474c;
  --radius: 8px;
  --radius-lg: 16px;
  --space: 16px;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
  padding-bottom: 72px;
}
a { color: var(--primary); }
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid var(--primary);
  outline-offset: 2px;
}
.skip-link { position: absolute; left: -9999px; top: 8px; z-index: 100; }
.skip-link:focus { left: 8px; background: var(--primary); color: #001d2b; padding: 8px 12px; }

.appbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 56px;
  padding: 8px var(--space);
  background: rgb(17 19 29 / 94%);
  border-bottom: 1px solid var(--border);
}
.appbar-brand { color: var(--text); font-weight: 700; text-decoration: none; }
.appbar-title { flex: 1; margin: 0; }
.appbar-user {
  display: grid;
  width: 40px;
  height: 40px;
  place-items: center;
  border-radius: 50%;
  background: var(--surface-high);
  font-weight: 700;
}
.net-status { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); }
.net-status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--success); }
.net-status.offline .dot { background: var(--error); }
.net-pending { padding: 2px 8px; border-radius: 999px; background: var(--surface-high); }
.net-toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  z-index: 20;
  transform: translateX(-50%);
  padding: 10px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-high);
}

main { width: min(100%, 960px); margin: 0 auto; padding: var(--space); }
h1, h2, p { overflow-wrap: anywhere; }
h1 { margin: 0; font-size: 1.6rem; }
h2 { margin: 0 0 8px; font-size: 1.1rem; }
.panel, .stack { display: flex; flex-direction: column; gap: var(--space); }
.panel.narrow { width: min(100%, 480px); margin: 0 auto; }
.lede, .muted, .breadcrumb, .empty { color: var(--muted); }
.card, .form-card {
  padding: var(--space);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
.workspace-grid { display: grid; gap: var(--space); grid-template-columns: 1fr; }
@media (min-width: 720px) { .workspace-grid { grid-template-columns: 1fr 1fr; } }

input, select, textarea, button, .button {
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}
button, .button { cursor: pointer; background: var(--surface-high); text-decoration: none; }
.primary { border-color: transparent; background: var(--primary); color: #001d2b; font-weight: 700; }
.small { min-height: 44px; padding: 6px 10px; }
.button-link { border: 0; background: transparent; color: var(--muted); }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.list { margin: 0; padding: 0; list-style: none; }
.list li { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.list-link { display: flex; width: 100%; min-height: 44px; flex-direction: column; justify-content: center; text-decoration: none; }
.badge { padding: 2px 8px; border-radius: 999px; background: var(--surface-high); color: var(--muted); font-size: .75rem; }
.task.done > span:first-child { color: var(--muted); text-decoration: line-through; }
.action-list { display: grid; gap: 12px; margin: 0; padding: 0; list-style: none; }
.action-card {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
}
.action-card.stale { border-color: var(--error); }
.action-card.applied { border-color: var(--success); }
.action-heading, .action-change, .action-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}
.action-heading { justify-content: space-between; }
.action-change, .action-meta, .action-detail { margin: 0; }
.action-status.applied { color: var(--success); }
.action-status.stale { color: var(--error); }
.action-controls form { margin: 0; }
.callout { padding: 12px; border: 1px solid var(--border); border-radius: var(--radius); }
.callout.ok { border-color: var(--success); }
.callout.error { border-color: var(--error); }

.document-search { gap: 12px; }
.document-query-row {
  display: grid;
  gap: 8px;
  grid-template-columns: minmax(0, 1fr);
}
.document-scopes {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  margin: 0;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.document-scopes legend { padding: 0 4px; color: var(--muted); }
.document-scopes label { display: inline-flex; align-items: center; gap: 6px; }
.document-scopes input { min-height: auto; }
.document-results-summary, .document-result-heading {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.document-results { display: grid; gap: 10px; margin: 12px 0 0; padding-left: 24px; }
.document-result {
  display: grid;
  gap: 6px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
}
.document-result cite { color: var(--primary); font-style: normal; font-size: .88rem; }
.document-result p, .document-search-notice { margin: 0; white-space: pre-wrap; }

.page-heading, .section-heading, .inline-form, .gantt-legend, .zoom-nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
}
.page-actions { display: flex; flex-wrap: wrap; gap: 12px; }
.chat-panel { min-height: calc(100vh - 120px); }
.chat-transcript {
  display: flex;
  min-height: 240px;
  max-height: 56vh;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
}
.chat-message { max-width: min(88%, 720px); padding: 10px 12px; border-radius: var(--radius); }
.chat-message strong { display: block; margin-bottom: 4px; font-size: .8rem; color: var(--muted); }
.chat-message p { margin: 0; white-space: pre-wrap; }
.chat-message.user { align-self: flex-end; background: var(--primary); color: #001d2b; }
.chat-message.user strong { color: #14313e; }
.chat-message.assistant { align-self: flex-start; background: var(--surface-high); }
.chat-message.error { align-self: stretch; border: 1px solid var(--error); background: var(--surface); }

.voice-panel { max-width: 920px; margin-inline: auto; }
.voice-console {
  display: grid;
  justify-items: center;
  gap: 12px;
  padding: 24px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: radial-gradient(circle at 50% 0%, rgba(74, 200, 255, .12), transparent 58%), var(--surface);
}
.voice-orb { display: flex; align-items: center; gap: 5px; min-height: 72px; }
.voice-orb span { width: 7px; height: 24px; border-radius: 999px; background: var(--muted); transition: height .18s ease, background .18s ease; }
.voice-orb[data-state="connecting"] span,
.voice-orb[data-state="thinking"] span,
.voice-orb[data-state="working"] span { background: var(--warning); animation: voice-pulse 1s ease-in-out infinite alternate; }
.voice-orb[data-state="listening"] span { background: var(--success); height: 36px; }
.voice-orb[data-state="speaking"] span { background: var(--primary); animation: voice-speak .55s ease-in-out infinite alternate; }
.voice-orb[data-state="speaking"] span:nth-child(2) { animation-delay: .15s; }
.voice-orb[data-state="speaking"] span:nth-child(3) { animation-delay: .3s; }
.voice-orb[data-state="error"] span { background: var(--error); }
.voice-status { margin: 0; font-size: 1.2rem; font-weight: 700; }
.voice-privacy, .voice-fallback { text-align: center; }
.voice-controls { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }
.voice-transcript-card { margin-top: 18px; }
.voice-transcript { display: flex; flex-direction: column; gap: 10px; min-height: 150px; max-height: 46vh; overflow-y: auto; }
.voice-message { max-width: min(90%, 680px); padding: 10px 12px; border-radius: var(--radius); }
.voice-message strong { display: block; margin-bottom: 4px; color: var(--muted); font-size: .8rem; }
.voice-message p { margin: 0; white-space: pre-wrap; }
.voice-message.user { align-self: flex-end; background: var(--surface-high); }
.voice-message.assistant { align-self: flex-start; border: 1px solid var(--border); background: var(--surface); }
@keyframes voice-pulse { from { transform: scaleY(.65); } to { transform: scaleY(1.2); } }
@keyframes voice-speak { from { height: 18px; } to { height: 48px; } }
@media (prefers-reduced-motion: reduce) {
  .voice-orb span { animation: none !important; transition: none; }
}
.page-heading, .section-heading { justify-content: space-between; }
.page-heading p, .section-heading p { margin: 0; }
.inline-form label { width: 100%; font-weight: 700; }
.inline-form input { flex: 1 1 280px; }
.summary-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.metric { padding: 12px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.metric span { display: block; color: var(--muted); font-size: .8rem; }
.metric strong { font-size: 1.4rem; }
.gantt-legend { margin: 12px 0; color: var(--muted); font-size: .85rem; }
.gantt-legend > span { display: inline-flex; align-items: center; gap: 6px; }
.legend-swatch { display: inline-block; width: 18px; height: 8px; border-radius: 999px; }
.legend-swatch.baseline { background: var(--muted); }
.legend-swatch.projected { background: var(--primary); }
.legend-swatch.critical { background: var(--error); }
.gantt-scroll, .table-scroll { max-width: 100%; overflow-x: auto; }
.gantt-chart { position: relative; padding-top: 36px; }
.gantt-track { position: absolute; inset: 0 0 auto 180px; height: 28px; border-bottom: 1px solid var(--border); }
.gantt-tick, .today-marker { position: absolute; top: 0; bottom: -1000px; border-left: 1px solid var(--border); }
.gantt-tick span, .today-marker span { position: absolute; top: 0; left: 4px; white-space: nowrap; color: var(--muted); font-size: .72rem; }
.today-marker { z-index: 2; border-left: 2px solid var(--success); }
.today-marker span { color: var(--success); font-weight: 700; }
.gantt-row { display: grid; grid-template-columns: 180px minmax(360px, 1fr); min-height: 52px; align-items: center; border-bottom: 1px solid var(--border); }
.gantt-label { display: flex; min-width: 0; flex-direction: column; padding-right: 10px; }
.gantt-label span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gantt-label small { color: var(--muted); }
.gantt-row.level-1 .gantt-label { padding-left: 14px; }
.gantt-row.level-2 .gantt-label { padding-left: 28px; }
.gantt-row-track { position: relative; height: 38px; background: repeating-linear-gradient(90deg, transparent, transparent 49px, rgb(68 71 76 / 35%) 50px); }
.gantt-bar { position: absolute; min-width: 4px; border-radius: 999px; }
.gantt-bar.baseline { top: 7px; height: 9px; background: var(--muted); }
.gantt-bar.baseline.critical { background: var(--error); }
.gantt-bar.projected { top: 22px; height: 9px; background: var(--primary); }
.gantt-bar.projected.slipped { box-shadow: 0 0 0 2px rgb(255 180 171 / 35%); }
.data-table { width: 100%; border-collapse: collapse; font-size: .85rem; }
.data-table th, .data-table td { padding: 10px 8px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
.data-table .hierarchy { white-space: normal; min-width: 180px; }
.data-table .level-1 { padding-left: 20px; }
.data-table .level-2 { padding-left: 36px; }
.badge.critical { color: var(--error); }
.badge.slipped { color: var(--primary); }

@media (min-width: 720px) {
  .summary-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .document-query-row { grid-template-columns: minmax(0, 1fr) auto; }
}

.shell-tabs {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  display: flex;
  min-height: 56px;
  align-items: center;
  justify-content: space-around;
  border-top: 1px solid var(--border);
  background: rgb(17 19 29 / 96%);
}
.shell-tabs form { margin: 0; }
.shell-tab { display: inline-flex; min-height: 44px; align-items: center; padding: 8px 12px; color: var(--muted); }
.shell-tab.active { color: var(--primary); font-weight: 700; }
