:root {
  --bg: #f6f8fb;
  --surface: #ffffff;
  --surface-strong: #f0f4f7;
  --ink: #14212f;
  --muted: #607080;
  --line: #dce3ea;
  --navy: #17324d;
  --teal: #007c78;
  --blue: #2563eb;
  --amber: #ad6a00;
  --red: #b42318;
  --green: #0f7a46;
  --shadow: 0 18px 45px rgba(20, 33, 47, 0.08);
  --radius: 8px;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  --sans: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  color: var(--ink);
  background: var(--bg);
  font-family: var(--sans);
}

button,
textarea,
select,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
  background: #102132;
  color: #f8fbfd;
  padding: 20px 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
}

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: var(--radius);
  background: #f4c95d;
  color: #102132;
  font-weight: 800;
}

.brand strong,
.brand span {
  display: block;
}

.brand span {
  color: #b9c7d4;
  font-size: 13px;
  margin-top: 2px;
}

.nav-list {
  display: grid;
  gap: 10px;
}

.nav-group {
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.04);
}

.nav-group-summary {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto 16px;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding: 9px 10px;
  color: #ffffff;
  font-weight: 800;
  list-style: none;
  cursor: pointer;
}

.nav-group-summary::-webkit-details-marker {
  display: none;
}

.nav-group-summary::after {
  content: ">";
  color: #99acbc;
  transform: rotate(0deg);
  transition: transform 160ms ease;
}

.nav-group[open] .nav-group-summary::after {
  transform: rotate(90deg);
}

.nav-group-summary small {
  display: grid;
  min-width: 24px;
  height: 22px;
  place-items: center;
  border-radius: 999px;
  background: rgba(244, 201, 93, 0.16);
  color: #f4c95d;
  font-size: 12px;
}

.nav-group-panel {
  display: grid;
  gap: 4px;
  padding: 0 6px 8px;
}

.nav-button {
  width: 100%;
  min-height: 42px;
  display: grid;
  grid-template-columns: 26px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  border: 0;
  border-radius: var(--radius);
  padding: 8px 10px;
  background: transparent;
  color: #d6e0e8;
  text-align: left;
}

.nav-button:hover,
.nav-button.is-active {
  background: rgba(255, 255, 255, 0.1);
  color: #ffffff;
}

.nav-index {
  display: grid;
  width: 24px;
  height: 24px;
  place-items: center;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.12);
  font-size: 12px;
  font-family: var(--mono);
}

.nav-tag {
  color: #99acbc;
  font-size: 12px;
}

.security-panel {
  margin-top: 22px;
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.06);
}

.panel-title {
  margin-bottom: 12px;
  color: #ffffff;
  font-weight: 700;
  font-size: 14px;
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 10px 0;
  color: #d6e0e8;
  font-size: 13px;
}

.workspace {
  min-width: 0;
  padding: 26px;
}

.topbar,
.command-center,
.status-grid,
.module-layout {
  width: min(1460px, 100%);
  margin: 0 auto;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--teal);
  font-size: 13px;
  font-weight: 700;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(28px, 4vw, 40px);
  line-height: 1.12;
  letter-spacing: 0;
}

h2 {
  font-size: 18px;
}

h3 {
  font-size: 16px;
}

.topbar-controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

.select-label {
  display: grid;
  gap: 4px;
  min-width: 132px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

select,
textarea,
input[type="text"],
input[type="number"] {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
  color: var(--ink);
}

select {
  min-height: 38px;
  padding: 0 34px 0 10px;
}

textarea,
input[type="text"],
input[type="number"] {
  padding: 11px 12px;
}

textarea {
  resize: vertical;
}

.command-center {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  margin-top: 24px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.command-input-wrap label,
.field label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.command-actions {
  display: grid;
  align-content: end;
  gap: 8px;
  min-width: 150px;
}

.primary-button,
.secondary-button,
.ghost-button,
.danger-button,
.text-button {
  min-height: 38px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  padding: 0 14px;
  font-weight: 700;
}

.primary-button {
  background: var(--navy);
  color: #ffffff;
}

.secondary-button {
  border-color: var(--line);
  background: var(--surface-strong);
  color: var(--ink);
}

.ghost-button {
  border-color: var(--line);
  background: var(--surface);
  color: var(--navy);
}

.ai-status {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #ffffff;
  color: var(--muted);
  padding: 0 12px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.ai-status::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 999px;
  margin-right: 7px;
  background: var(--amber);
}

.ai-status[data-state="connected"]::before {
  background: var(--green);
}

.ai-status[data-state="fallback"]::before,
.ai-status[data-state="error"]::before {
  background: var(--red);
}

.danger-button {
  border-color: #ffd6d1;
  background: #fff4f2;
  color: var(--red);
}

.text-button {
  min-height: 32px;
  border: 0;
  background: transparent;
  color: var(--blue);
  padding: 0 4px;
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-top: 16px;
}

.status-grid article {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 14px;
}

.metric-label,
.status-grid small {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.status-grid strong {
  display: block;
  margin: 6px 0 2px;
  color: var(--navy);
  font-size: 28px;
  line-height: 1;
}

.module-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 16px;
  margin-top: 16px;
  align-items: start;
}

.module-main,
.rail-section {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.module-main {
  min-height: 600px;
  padding: 18px;
}

.module-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 14px;
  margin-bottom: 16px;
}

.module-header p {
  max-width: 760px;
  color: var(--muted);
  margin-bottom: 0;
}

.module-badge {
  align-self: flex-start;
  border-radius: 999px;
  background: #e8f5f4;
  color: var(--teal);
  padding: 5px 9px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.control-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.field.span-2 {
  grid-column: span 2;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0 0;
}

.results-grid,
.two-column,
.firm-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.firm-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.result-panel,
.risk-item,
.timeline-item,
.knowledge-row,
.report-block,
.draft-output,
.version-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
  padding: 14px;
}

.result-panel h3,
.risk-item h3,
.timeline-item h3,
.knowledge-row h3,
.report-block h3,
.version-card h3 {
  margin-bottom: 8px;
}

.result-panel p,
.risk-item p,
.timeline-item p,
.knowledge-row p,
.report-block p,
.version-card p,
.small-note {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.55;
}

.result-panel ul {
  margin: 8px 0 0;
  padding-left: 20px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.55;
}

.ai-panel {
  grid-column: 1 / -1;
  border-color: #b7d6d2;
  background: #f8fdfc;
}

.small-note {
  margin: 8px 0 0;
}

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.tag {
  border-radius: 999px;
  background: var(--surface-strong);
  color: var(--navy);
  padding: 4px 8px;
  font-size: 12px;
  font-weight: 700;
}

.tag.high {
  background: #fff0ee;
  color: var(--red);
}

.tag.medium {
  background: #fff6df;
  color: var(--amber);
}

.tag.low {
  background: #eaf7ef;
  color: var(--green);
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 680px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 10px;
  text-align: left;
  vertical-align: top;
  font-size: 14px;
}

th {
  background: var(--surface-strong);
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

tr:last-child td {
  border-bottom: 0;
}

.draft-output {
  white-space: pre-wrap;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.6;
}

.redline-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin: 16px 0 10px;
}

.redline-toolbar h3 {
  margin: 0;
}

.redline-doc {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
  padding: 16px;
}

.redline-doc pre {
  max-height: 560px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0;
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.7;
}

.redline-highlight {
  background: #ffe8e5;
  color: var(--red);
  font-weight: 800;
}

.redline-note {
  color: var(--red);
  font-weight: 800;
}

.redline-insertions {
  margin-top: 14px;
  border: 1px solid #ffd6d1;
  border-radius: var(--radius);
  background: #fff7f5;
  padding: 12px;
}

.redline-insertions h4 {
  margin: 0 0 8px;
  color: var(--red);
}

.redline-insertions ins {
  display: block;
  margin: 8px 0;
  color: var(--red);
  font-weight: 800;
  text-decoration: none;
}

.insight-rail {
  display: grid;
  gap: 16px;
}

.rail-section {
  padding: 14px;
}

.section-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}

.section-heading h2 {
  margin: 0;
}

.source-list {
  display: grid;
  gap: 8px;
}

.citation-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
  background: #fbfcfd;
}

.citation-card strong,
.citation-card span,
.citation-card a {
  display: block;
}

.citation-card strong {
  margin-bottom: 4px;
  font-size: 13px;
}

.citation-card span {
  color: var(--muted);
  font-size: 12px;
}

.citation-card a {
  margin-top: 8px;
  color: var(--blue);
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
}

.audit-log {
  display: grid;
  gap: 8px;
  max-height: 370px;
  overflow: auto;
  margin: 0;
  padding-left: 18px;
}

.audit-log li {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.audit-log strong {
  display: block;
  color: var(--ink);
}

.notice {
  border-left: 4px solid var(--amber);
  background: #fffaf0;
  padding: 12px 14px;
  border-radius: var(--radius);
  color: #5a3b00;
  font-size: 14px;
}

.file-drop {
  border: 1px dashed #9fb1c1;
  border-radius: var(--radius);
  background: #f9fbfc;
  padding: 16px;
}

.file-drop input {
  width: 100%;
}

.graph-box {
  min-height: 320px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background:
    linear-gradient(90deg, rgba(220, 227, 234, 0.55) 1px, transparent 1px),
    linear-gradient(rgba(220, 227, 234, 0.55) 1px, transparent 1px),
    #fbfcfd;
  background-size: 28px 28px;
  position: relative;
  overflow: hidden;
}

.node {
  position: absolute;
  min-width: 96px;
  max-width: 160px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
  padding: 9px;
  box-shadow: 0 8px 20px rgba(20, 33, 47, 0.12);
  font-size: 13px;
}

.node strong {
  display: block;
  margin-bottom: 4px;
}

.edge {
  position: absolute;
  height: 2px;
  background: #7d92a5;
  transform-origin: left center;
}

.report-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.empty-state {
  display: grid;
  min-height: 240px;
  place-items: center;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  text-align: center;
  padding: 24px;
}

@media (max-width: 1180px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
  }

  .nav-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .module-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  .workspace {
    padding: 16px;
  }

  .topbar,
  .command-center,
  .module-header {
    display: grid;
  }

  .topbar-controls,
  .command-actions {
    justify-content: stretch;
  }

  .status-grid,
  .control-grid,
  .results-grid,
  .two-column,
  .firm-grid,
  .nav-list {
    grid-template-columns: 1fr;
  }

  .field.span-2 {
    grid-column: auto;
  }
}
