:root {
  --ink: #172331;
  --muted: #647083;
  --line: #dbe4ec;
  --surface: #ffffff;
  --surface-soft: #f5f8fb;
  --nav: #083a63;
  --nav-soft: #0d4f86;
  --nav-accent: #79b829;
  --teal: #008b9a;
  --blue: #0869a9;
  --amber: #c87912;
  --red: #c73a38;
  --green: #69a82f;
  --green-deep: #357c2b;
  --shadow: 0 16px 36px rgba(8, 58, 99, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(8, 105, 169, 0.06), rgba(105, 168, 47, 0.05) 42%, #f6f9fb),
    #f6f9fb;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

button,
select,
textarea {
  font: inherit;
}

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

.sidebar {
  background:
    linear-gradient(180deg, #083a63 0%, #0a4f86 58%, #0d3d65 100%);
  color: #f7fbf9;
  padding: 24px 18px;
}

.brand-block {
  display: grid;
  gap: 14px;
  padding-bottom: 24px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.18);
}

.brand-logo {
  display: block;
  width: min(210px, 100%);
  height: auto;
}

.brand-block h1 {
  margin: 0;
  font-size: 18px;
  line-height: 1.1;
}

.brand-block p {
  margin: 4px 0 0;
  color: #c7dcec;
  font-size: 13px;
}

.nav-list {
  display: grid;
  gap: 8px;
  margin-top: 26px;
}

.nav-item {
  width: 100%;
  min-height: 42px;
  padding: 10px 12px;
  color: #eef7ff;
  text-align: left;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  cursor: pointer;
}

.nav-item:hover,
.nav-item.active {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.18);
  box-shadow: inset 4px 0 0 var(--nav-accent);
}

.capture-link {
  border-color: rgba(255, 255, 255, 0.16);
  background: rgba(121, 184, 41, 0.12);
}

.demo-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 18px;
}

.demo-link span {
  padding: 3px 7px;
  border-radius: 999px;
  background: var(--nav-accent);
  color: #07345a;
  font-size: 10px;
  font-weight: 900;
  text-transform: uppercase;
}

.workspace {
  min-width: 0;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  justify-content: space-between;
  gap: 18px;
  padding: 18px 28px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
}

.context-fields {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

select,
textarea,
input {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}

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

textarea {
  width: 100%;
  resize: vertical;
  padding: 12px;
  line-height: 1.45;
}

.submission-status {
  display: flex;
  align-items: end;
  gap: 10px;
}

.badge,
.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.badge {
  background: #eaf5fb;
  color: var(--blue);
}

.primary-action,
.ghost-action {
  min-height: 38px;
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
}

.primary-action {
  border: 1px solid var(--blue);
  background: var(--blue);
  color: #fff;
  font-weight: 800;
}

.primary-action:hover {
  background: #075d96;
}

.ghost-action {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--blue);
  font-weight: 800;
}

.story-section {
  display: none;
  padding: 28px;
}

.active-section {
  display: block;
}

.section-heading {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--green-deep);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

h2,
h3 {
  margin: 0;
}

h2 {
  font-size: 30px;
  line-height: 1.1;
}

h3 {
  font-size: 17px;
}

.risk-score {
  min-width: 150px;
  padding: 14px;
  border-radius: 8px;
  color: #fff;
  text-align: right;
  box-shadow: var(--shadow);
}

.risk-score strong {
  display: block;
  font-size: 28px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.metric-grid.compact {
  grid-template-columns: repeat(4, minmax(160px, 1fr));
}

.metric-card,
.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.metric-card {
  border-top: 4px solid rgba(8, 105, 169, 0.18);
}

.metric-card {
  min-height: 116px;
  padding: 14px;
}

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

.metric-card strong {
  display: block;
  margin-top: 8px;
  font-size: 24px;
  color: var(--blue);
}

.metric-card small {
  display: block;
  margin-top: 8px;
  color: var(--muted);
}

.two-column {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(320px, 0.85fr);
  gap: 18px;
}

.capture-layout {
  display: grid;
  grid-template-columns: 310px minmax(0, 1fr);
  gap: 18px;
}

.capture-steps {
  display: grid;
  gap: 10px;
  align-content: start;
}

.capture-step {
  display: grid;
  grid-template-columns: 34px 1fr;
  gap: 10px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
  box-shadow: 0 10px 22px rgba(8, 58, 99, 0.06);
}

.capture-step.active {
  border-color: rgba(8, 105, 169, 0.45);
  box-shadow: inset 4px 0 0 var(--green), 0 14px 26px rgba(8, 58, 99, 0.12);
}

.capture-step.complete .step-number {
  background: var(--green);
}

.step-number {
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  border-radius: 999px;
  background: var(--blue);
  color: #fff;
  font-size: 12px;
  font-weight: 900;
}

.capture-step strong {
  display: block;
  font-size: 13px;
}

.capture-step span:last-child {
  color: var(--muted);
  font-size: 12px;
}

.capture-panel {
  min-height: 570px;
}

.capture-help {
  margin: 0 0 16px;
  color: var(--muted);
  line-height: 1.45;
}

.capture-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.capture-field {
  display: grid;
  gap: 7px;
}

.capture-field.full {
  grid-column: 1 / -1;
}

.capture-field input,
.capture-field select,
.capture-field textarea {
  width: 100%;
  min-height: 40px;
  padding: 9px 10px;
}

.capture-field textarea {
  min-height: 106px;
}

.capture-actions {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.kai-widget {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 40;
}

.kai-bubble {
  display: grid;
  width: 82px;
  height: 82px;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.6);
  border-radius: 999px;
  background: linear-gradient(135deg, var(--blue), #0a83b6 58%, var(--green));
  color: #fff;
  box-shadow: 0 18px 38px rgba(8, 58, 99, 0.28);
  cursor: pointer;
}

.kai-bubble span {
  max-width: 54px;
  font-size: 13px;
  font-weight: 900;
  line-height: 1.1;
}

.kai-popover {
  position: absolute;
  right: 0;
  bottom: 96px;
  display: none;
  width: min(390px, calc(100vw - 32px));
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 24px 60px rgba(8, 58, 99, 0.22);
}

.kai-widget.open .kai-popover {
  display: block;
}

.kai-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  background: var(--blue);
  color: #fff;
}

.kai-header strong,
.kai-header span {
  display: block;
}

.kai-header span {
  margin-top: 2px;
  color: #d9edf8;
  font-size: 12px;
}

.kai-close {
  display: grid;
  width: 32px;
  height: 32px;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 999px;
  background: transparent;
  color: #fff;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

.kai-thread {
  display: grid;
  align-content: start;
  gap: 12px;
  padding: 18px;
  height: 320px;
  overflow: auto;
  background: linear-gradient(180deg, #f8fbfd, #ffffff);
}

.kai-message {
  max-width: 78%;
  padding: 12px 14px;
  border-radius: 8px;
  line-height: 1.45;
}

.kai-message strong {
  display: block;
  margin-bottom: 4px;
  font-size: 12px;
  text-transform: uppercase;
}

.kai-message.bot {
  justify-self: start;
  border: 1px solid var(--line);
  background: #fff;
}

.kai-message.user {
  justify-self: end;
  background: var(--blue);
  color: #fff;
}

.kai-input-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  padding: 14px;
  border-top: 1px solid var(--line);
  background: #fff;
}

.kai-input-row input {
  min-height: 40px;
  padding: 9px 10px;
}

.kai-suggestions {
  display: grid;
  align-content: start;
  gap: 10px;
}

.compact-suggestions {
  grid-template-columns: repeat(3, 1fr);
  padding: 12px 14px 0;
}

.quick-question {
  min-height: 38px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--blue);
  text-align: left;
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
}

.quick-question:hover {
  border-color: rgba(8, 105, 169, 0.45);
  background: #f1f7fb;
}

.panel {
  padding: 18px;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

.risk-bars {
  display: grid;
  gap: 14px;
}

.risk-row {
  display: grid;
  gap: 7px;
}

.risk-row header {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.bar-track {
  height: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-soft);
}

.bar-fill {
  height: 100%;
  border-radius: inherit;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

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

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

th {
  background: #eaf2f8;
  color: #255373;
  font-size: 12px;
  text-transform: uppercase;
}

td.number {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.commentary-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-top: 18px;
}

.comment-card {
  min-height: 190px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.comment-card p {
  margin: 10px 0 0;
  color: var(--muted);
  line-height: 1.45;
}

.form-grid,
.driver-list,
.debtor-list,
.controls-list,
.exception-list,
.decision-list,
.action-list {
  display: grid;
  gap: 12px;
}

.field-row,
.driver-row,
.debtor-row,
.control-row,
.exception-row,
.decision-row,
.action-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.field-row p,
.driver-row p,
.debtor-row p,
.control-row p,
.exception-row p,
.decision-row p,
.action-row p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.cfo-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(320px, 0.75fr);
  gap: 18px;
  margin-top: 18px;
}

.compact-table {
  margin-top: 14px;
  box-shadow: none;
}

.compact-table table {
  min-width: 680px;
}

.exception-row {
  border-left: 4px solid var(--red);
}

.decision-row {
  border-left: 4px solid var(--amber);
}

.action-row {
  border-left: 4px solid var(--blue);
}

.status-green {
  background: #edf7e7;
  color: var(--green-deep);
}

.status-amber {
  background: #fff3dd;
  color: var(--amber);
}

.status-red {
  background: #fde9e9;
  color: var(--red);
}

.risk-low {
  background: var(--green);
}

.risk-medium {
  background: var(--amber);
}

.risk-high,
.risk-critical {
  background: var(--red);
}

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

  .sidebar {
    position: static;
  }

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

  .metric-grid,
  .metric-grid.compact,
  .two-column,
  .cfo-grid,
  .capture-layout,
  .commentary-grid {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 720px) {
  .topbar,
  .section-heading,
  .submission-status {
    align-items: stretch;
    flex-direction: column;
  }

  .story-section {
    padding: 18px;
  }

  .nav-list,
  .metric-grid,
  .metric-grid.compact,
  .two-column,
  .cfo-grid,
  .capture-layout,
  .capture-fields,
  .commentary-grid {
    grid-template-columns: 1fr;
  }

  .kai-widget {
    right: 16px;
    bottom: 16px;
  }

  .kai-bubble {
    width: 72px;
    height: 72px;
  }

  .compact-suggestions {
    grid-template-columns: 1fr;
  }

  h2 {
    font-size: 24px;
  }

  select {
    width: 100%;
  }
}
