:root {
  --page: #eef3f8;
  --page-soft: #f7faff;
  --panel: #ffffff;
  --panel-soft: #f6f9fc;
  --ink: #172033;
  --muted: #667386;
  --line: #dbe5ef;
  --line-strong: #b8cada;
  --shell: #101923;
  --shell-2: #172333;
  --shell-muted: #9fb0c2;
  --accent: #2fc6f6;
  --accent-deep: #159fd0;
  --accent-soft: #e6f8ff;
  --steel: #60758b;
  --steel-soft: #edf3f8;
  --green: #31a866;
  --green-soft: #e8f7ee;
  --amber: #f2aa35;
  --amber-soft: #fff4df;
  --red: #df5547;
  --red-soft: #fff0ee;
  --violet: #806de6;
  --violet-soft: #f2efff;
  --shadow: 0 18px 45px rgba(25, 43, 63, 0.1);
  --shadow-soft: 0 10px 28px rgba(25, 43, 63, 0.07);
  --radius: 8px;
  --ui-font: "Segoe UI", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background:
    linear-gradient(180deg, var(--page-soft) 0, var(--page) 320px, #e9eff6 100%);
  color: var(--ink);
  font-family: var(--ui-font);
  font-size: 15px;
  line-height: 1.45;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.svg-sprite {
  display: none;
}

svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 72px 1fr;
}

.side-rail {
  position: sticky;
  top: 0;
  height: 100vh;
  background: var(--shell);
  border-right: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 18px 12px;
}

.brand-mark {
  width: 44px;
  height: 44px;
  border: 1px solid rgba(47, 198, 246, 0.55);
  background: rgba(47, 198, 246, 0.13);
  color: #ffffff;
  display: grid;
  place-items: center;
  font-weight: 800;
  margin-bottom: 14px;
  border-radius: var(--radius);
}

.rail-button {
  width: 44px;
  height: 44px;
  border: 1px solid rgba(255, 255, 255, 0.13);
  background: transparent;
  color: var(--shell-muted);
  border-radius: var(--radius);
  display: grid;
  place-items: center;
}

.rail-button.active,
.rail-button:hover,
.rail-button:focus-visible {
  background: var(--accent);
  color: #08202b;
  border-color: var(--accent);
  outline: none;
}

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

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 16px;
  padding: 18px;
  border-radius: var(--radius);
  color: #ffffff;
  background: linear-gradient(135deg, var(--shell) 0%, var(--shell-2) 68%, #0e2a34 100%);
  border: 1px solid rgba(47, 198, 246, 0.2);
  box-shadow: var(--shadow);
}

.eyebrow {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  font-weight: 700;
  margin: 0 0 4px;
}

.topbar .eyebrow {
  color: #8ee1ff;
}

h1,
h2,
h3 {
  margin: 0;
  line-height: 1.1;
  font-weight: 800;
  letter-spacing: 0;
}

h1 {
  font-size: 36px;
}

h2 {
  font-size: 22px;
}

h3 {
  font-size: 17px;
}

.topbar-status {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.status-chip,
.stamp,
.zone-badge,
.reason-code,
.data-pill,
.rec-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.status-chip.dry {
  background: var(--amber-soft);
  border-color: #f3ce82;
  color: #7a510d;
}

.status-chip.locked {
  background: var(--red-soft);
  border-color: #e9b4ad;
  color: #9a3026;
}

.status-chip.ok {
  background: var(--green-soft);
  border-color: #b8dec8;
  color: #1f7248;
}

.filter-strip {
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-soft);
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr)) minmax(240px, 1.2fr);
  gap: 10px;
  padding: 12px;
  margin-bottom: 16px;
}

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

select,
.search-field,
input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel-soft);
  color: var(--ink);
  min-height: 40px;
}

select:focus-visible,
input:focus-visible,
button:focus-visible {
  outline: 2px solid rgba(47, 198, 246, 0.35);
  outline-offset: 2px;
}

select {
  padding: 0 10px;
}

.search-field {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  align-self: end;
}

.search-field input {
  border: 0;
  background: transparent;
  min-height: 38px;
  outline: none;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 390px;
  gap: 16px;
  align-items: start;
}

.view {
  display: none;
}

.view.view-active {
  display: grid;
}

.main-column {
  display: grid;
  gap: 16px;
  min-width: 0;
}

.main-column.wide {
  grid-column: 1 / -1;
}

.main-column > * {
  min-width: 0;
  max-width: 100%;
}

.summary-grid,
.plan-panel,
.intervention-panel,
.deal-panel {
  width: 100%;
}

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

.metric-card,
.plan-panel,
.intervention-panel,
.deal-panel,
.detail-panel,
.flag-card,
.intervention-card,
.review-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-soft);
}

.metric-card {
  position: relative;
  overflow: hidden;
  min-height: 130px;
  padding: 16px;
  display: grid;
  align-content: space-between;
}

.metric-card::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 5px;
  background: var(--steel);
}

.metric-card.red::before { background: var(--red); }
.metric-card.amber::before { background: var(--amber); }
.metric-card.green::before { background: var(--green); }
.metric-card.steel::before { background: var(--accent); }

.metric-card p,
.metric-card span {
  margin: 0;
  color: var(--muted);
  font-weight: 700;
}

.metric-card strong {
  font-size: 44px;
  line-height: 1;
}

.plan-panel,
.intervention-panel,
.deal-panel {
  padding: 16px;
}

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

.stamp {
  background: var(--steel-soft);
  color: var(--muted);
}

.plan-body {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 16px;
  align-items: center;
}

.plan-number span,
.signal-board span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.plan-number strong {
  display: block;
  font-size: 28px;
  margin-top: 4px;
}

.risk-bar {
  height: 30px;
  border: 1px solid var(--line-strong);
  display: flex;
  overflow: hidden;
  border-radius: 7px;
}

.risk-bar span {
  display: block;
}

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

.bar-legend {
  grid-column: 2;
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  margin-right: 6px;
}

.green-dot { background: var(--green); }
.amber-dot { background: var(--amber); }
.red-dot { background: var(--red); }

.icon-button {
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  background: var(--panel-soft);
  color: var(--ink);
  display: grid;
  place-items: center;
  border-radius: 7px;
}

.icon-button:hover,
.icon-button:focus-visible {
  border-color: var(--accent-deep);
  color: var(--accent-deep);
}

.intervention-list {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.intervention-card {
  padding: 14px;
  display: grid;
  gap: 10px;
  border-left: 5px solid var(--red);
}

.intervention-card.yellow {
  border-left-color: var(--amber);
}

.intervention-card p {
  margin: 0;
  color: var(--muted);
}

.action-button {
  border: 1px solid var(--accent-deep);
  background: var(--accent);
  color: #062230;
  border-radius: 7px;
  min-height: 38px;
  padding: 0 12px;
  font-weight: 800;
  justify-self: start;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.action-button:hover,
.action-button:focus-visible {
  background: #65d7fb;
}

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

.action-button.secondary:hover,
.action-button.secondary:focus-visible {
  border-color: var(--accent-deep);
  color: var(--accent-deep);
}

.action-button:disabled {
  cursor: not-allowed;
  background: #eef3f7;
  border-color: var(--line);
  color: var(--muted);
}

.zone-tabs,
.detail-tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.zone-tab,
.detail-tab {
  min-height: 34px;
  border: 1px solid var(--line);
  background: var(--panel-soft);
  border-radius: 7px;
  padding: 0 10px;
  font-size: 13px;
  font-weight: 800;
}

.zone-tab.active,
.detail-tab.active {
  background: var(--shell-2);
  color: #ffffff;
  border-color: var(--shell-2);
}

.zone-tab.red:not(.active) { color: var(--red); }
.zone-tab.amber:not(.active) { color: #9a620b; }
.zone-tab.green:not(.active) { color: var(--green); }

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

.deal-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 960px;
}

.deal-table th {
  position: sticky;
  top: 0;
  background: #f2f6fa;
  color: var(--muted);
  font-size: 12px;
  text-align: left;
  padding: 10px;
  text-transform: uppercase;
}

.deal-table td {
  border-top: 1px solid var(--line);
  padding: 10px;
  vertical-align: middle;
}

.deal-row {
  cursor: pointer;
}

.deal-row:hover,
.deal-row.active {
  background: var(--accent-soft);
}

.deal-name {
  font-weight: 800;
}

.deal-sub {
  color: var(--muted);
  font-size: 13px;
}

.signal-rail {
  display: grid;
  grid-template-columns: 8px 1fr;
  gap: 8px;
  align-items: center;
  min-width: 86px;
}

.rail-color {
  width: 8px;
  height: 46px;
  border-radius: 5px;
  background: var(--steel);
}

.rail-color.red { background: var(--red); }
.rail-color.yellow { background: var(--amber); }
.rail-color.green { background: var(--green); }

.zone-label {
  font-weight: 800;
}

.zone-badge.red { background: var(--red-soft); border-color: #e9b4ad; color: #9a3026; }
.zone-badge.yellow { background: var(--amber-soft); border-color: #f3ce82; color: #83540e; }
.zone-badge.green { background: var(--green-soft); border-color: #b8dec8; color: #1f7248; }

.data-pill {
  border-radius: 6px;
  background: var(--steel-soft);
  color: var(--muted);
}

.data-pill.complete {
  background: var(--green-soft);
  color: #1f7248;
}

.rec-status.open { background: var(--amber-soft); border-color: #f3ce82; color: #83540e; }
.rec-status.done { background: var(--green-soft); border-color: #b8dec8; color: #1f7248; }
.rec-status.ignored { background: var(--red-soft); border-color: #e9b4ad; color: #9a3026; }
.rec-status.review { background: var(--violet-soft); border-color: #cec4f5; color: #5440bd; }

.detail-panel {
  position: sticky;
  top: 16px;
  padding: 16px;
  min-height: 720px;
  min-width: 0;
}

.detail-top {
  border-bottom: 1px solid var(--line);
  padding-bottom: 14px;
  margin-bottom: 14px;
}

.detail-top h2 {
  margin: 8px 0 10px;
}

.detail-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.signal-board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}

.signal-board div {
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 10px;
  background: var(--panel-soft);
}

.signal-board strong {
  display: block;
  font-size: 22px;
  margin-top: 2px;
}

.detail-tabs {
  margin-bottom: 12px;
}

.detail-tabpanel {
  display: none;
}

.detail-tabpanel.active {
  display: grid;
  gap: 10px;
}

.reason-list,
.evidence-list,
.timeline-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.reason-item,
.evidence-item,
.timeline-item,
.recommendation-box,
.safety-box {
  border: 1px solid var(--line);
  background: var(--panel-soft);
  border-radius: 7px;
  padding: 10px;
}

.reason-item {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px;
}

.reason-code {
  align-self: start;
  border-radius: 6px;
  background: var(--accent-soft);
  color: #0b7195;
  padding: 4px 8px;
}

.evidence-item strong,
.timeline-item strong {
  display: block;
  margin-bottom: 2px;
}

.evidence-item span,
.timeline-item span,
.recommendation-box p,
.safety-box p {
  color: var(--muted);
  margin: 0;
}

.review-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

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

.review-card {
  padding: 14px;
  display: grid;
  gap: 10px;
  border-top: 5px solid var(--red);
}

.review-card.yellow {
  border-top-color: var(--amber);
}

.review-card p {
  margin: 0;
  color: var(--muted);
}

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

.flag-card {
  padding: 14px;
  display: grid;
  gap: 8px;
  border-left: 5px solid var(--line-strong);
}

.flag-card.on {
  border-left-color: var(--green);
}

.flag-card.off {
  border-left-color: var(--red);
}

.flag-card span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.flag-card strong {
  font-size: 26px;
  line-height: 1.1;
}

@media (max-width: 1180px) {
  .content-grid,
  .view.view-active {
    grid-template-columns: 1fr;
  }

  .detail-panel {
    position: static;
    min-height: 0;
  }

  .summary-grid,
  .intervention-list,
  .review-grid,
  .settings-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 1320px) and (min-width: 1181px) {
  .summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

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

  .side-rail {
    position: sticky;
    top: 0;
    z-index: 20;
    height: 62px;
    flex-direction: row;
    justify-content: center;
    padding: 8px;
  }

  .brand-mark {
    display: none;
  }

  .workspace {
    padding: 14px;
  }

  .topbar {
    display: grid;
  }

  .topbar-status {
    justify-content: flex-start;
  }

  .filter-strip {
    grid-template-columns: 1fr 1fr;
  }

  .search-field {
    grid-column: 1 / -1;
  }

  .summary-grid,
  .intervention-list,
  .review-grid,
  .settings-grid {
    grid-template-columns: 1fr;
  }

  .plan-body {
    grid-template-columns: 1fr;
  }

  .bar-legend {
    grid-column: auto;
  }
}

@media (max-width: 620px) {
  h1 {
    font-size: 30px;
  }

  h2 {
    font-size: 20px;
  }

  .filter-strip {
    grid-template-columns: 1fr;
  }

  .panel-head {
    display: grid;
  }

  .deal-table,
  .deal-table thead,
  .deal-table tbody,
  .deal-table tr,
  .deal-table th,
  .deal-table td {
    display: block;
    min-width: 0;
  }

  .deal-table thead {
    display: none;
  }

  .deal-table tr {
    border-top: 1px solid var(--line);
    padding: 10px;
  }

  .deal-table tr:first-child {
    border-top: 0;
  }

  .deal-table td {
    border-top: 0;
    padding: 6px 0;
  }

  .deal-table td::before {
    content: attr(data-label);
    display: block;
    color: var(--muted);
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
  }

  .signal-rail {
    grid-template-columns: 8px 1fr;
  }
}

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