/* ==========================================================================
   OpsMind design system
   Palette, type scale and spacing per the implementation guide:
     primary #2F4E3E · accent #A4B494 · background #F7F7F3 · surface #FFFFFF
   ========================================================================== */
:root {
  --primary: #2f4e3e;
  --primary-light: #4e6b5b;
  --accent: #a4b494;
  --accent-soft: #eef1ea;
  --background: #f7f7f3;
  --surface: #ffffff;
  --border: #e8e8e0;
  --neutral: #6b7280;
  --text: #23281f;
  --text-muted: #8a8f85;

  --critical: #b05c34;
  --critical-soft: #fbeae2;
  --warning: #d9aa44;
  --warning-soft: #fbf4e0;
  --info: #7a87a8;
  --info-soft: #e9edf5;
  --success: #3f7d58;
  --success-soft: #e6f0e9;

  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(35, 40, 31, 0.05), 0 8px 24px -12px rgba(35, 40, 31, 0.12);
  --sidebar-w: 244px;
  --font-display: "Playfair Display", Georgia, serif;
  --font-body: "Inter", system-ui, sans-serif;

  /* 8px spacing base */
  --s1: 8px; --s2: 16px; --s3: 24px; --s4: 32px; --s5: 48px;
}

html[data-theme="dark"] {
  --background: #14171a;
  --surface: #1c2023;
  --border: #2a2f33;
  --text: #eceee8;
  --text-muted: #9aa096;
  --accent-soft: #25302a;
  --critical-soft: #3a2620;
  --warning-soft: #38301c;
  --info-soft: #232a3a;
  --success-soft: #20342a;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 10px 30px -12px rgba(0, 0, 0, 0.5);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; }
body {
  font-family: var(--font-body);
  background: var(--background);
  color: var(--text);
  line-height: 1.5;
  transition: background 0.25s ease, color 0.25s ease;
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
svg.lucide { width: 18px; height: 18px; }

/* ------------------------------------------------------------- layout --- */
#app { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: var(--s3) var(--s2);
  display: flex;
  flex-direction: column;
  gap: var(--s3);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 0 var(--s1); }
.brand-logo {
  width: 38px; height: 38px; border-radius: 12px;
  background: var(--primary); color: #fff;
  display: grid; place-items: center;
}
.brand-name { font-family: var(--font-display); font-weight: 700; font-size: 20px; display: block; }
.brand-tag { font-size: 11px; color: var(--text-muted); letter-spacing: 0.02em; }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-label {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--text-muted); padding: 0 var(--s2); margin-bottom: 6px;
}
.nav a {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 12px; border-radius: var(--radius-sm);
  color: var(--neutral); font-size: 13.5px; font-weight: 500;
  transition: all 0.15s ease;
}
.nav a:hover { background: var(--accent-soft); color: var(--primary); }
.nav a.active { background: var(--primary); color: #fff; box-shadow: var(--shadow); }
.nav-secondary { margin-top: auto; }
.sidebar-quote {
  border-top: 1px solid var(--border);
  padding: var(--s2) var(--s1) 0;
  font-size: 12.5px; color: var(--text-muted); font-style: italic;
}
.quote-icon {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--accent-soft); color: var(--primary-light);
  display: grid; place-items: center; margin-bottom: 8px;
}
.sidebar-version { text-align: center; font-size: 11px; color: var(--text-muted); opacity: 0.7; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.view { padding: var(--s3); max-width: 1440px; width: 100%; margin: 0 auto; }

/* ------------------------------------------------------------- topbar --- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--s2) var(--s3); gap: var(--s2);
  position: sticky; top: 0; z-index: 50;
  background: color-mix(in srgb, var(--background) 82%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.search {
  flex: 1; max-width: 520px;
  display: flex; align-items: center; gap: 9px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 999px; padding: 8px 14px;
  color: var(--text-muted);
}
.search input {
  border: none; outline: none; background: transparent;
  font: inherit; color: var(--text); flex: 1; min-width: 0;
}
.search kbd {
  font-family: var(--font-body); font-size: 11px;
  border: 1px solid var(--border); border-radius: 6px;
  padding: 1px 6px; color: var(--text-muted); background: var(--background);
}
.topbar-right { display: flex; align-items: center; gap: 10px; }
.icon-btn {
  width: 38px; height: 38px; border-radius: 50%;
  border: 1px solid var(--border); background: var(--surface);
  display: grid; place-items: center; color: var(--neutral);
  transition: all 0.15s ease; position: relative;
}
.icon-btn:hover { border-color: var(--accent); color: var(--primary); }
.badge-wrap .badge {
  position: absolute; top: -4px; right: -4px;
  min-width: 17px; height: 17px; border-radius: 999px;
  background: var(--critical); color: #fff;
  font-size: 10.5px; font-weight: 600;
  display: grid; place-items: center; padding: 0 4px;
}
.user-chip {
  display: flex; align-items: center; gap: 9px;
  border: 1px solid var(--border); border-radius: 999px;
  padding: 4px 12px 4px 4px; background: var(--surface); cursor: pointer;
}
.user-chip img { width: 30px; height: 30px; border-radius: 50%; background: var(--accent-soft); }
.user-meta strong { display: block; font-size: 12.5px; }
.user-meta span { display: block; font-size: 10.5px; color: var(--text-muted); }
.sidebar-toggle { display: none; }

/* ------------------------------------------------------------ headings --- */
.page-head { margin-bottom: var(--s3); }
.page-head h1 {
  font-family: var(--font-display); font-weight: 600;
  font-size: clamp(22px, 3vw, 30px); letter-spacing: 0.01em;
}
.page-head .sub { color: var(--text-muted); font-size: 13.5px; margin-top: 2px; }
.date-pill {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 12px; color: var(--text-muted);
  border: 1px solid var(--border); background: var(--surface);
  border-radius: 999px; padding: 4px 12px; margin-top: 10px;
}
.quote-note {
  max-width: 260px; text-align: right; font-style: italic;
  color: var(--text-muted); font-size: 12.5px; line-height: 1.45;
}
.head-row { display: flex; justify-content: space-between; align-items: flex-end; gap: var(--s2); flex-wrap: wrap; }

/* --------------------------------------------------------------- cards --- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: var(--s2);
}
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: var(--s2); gap: 8px;
}
.card-head h2 {
  font-family: var(--font-display); font-size: 17px; font-weight: 600;
}
.card-head .link {
  font-size: 12px; color: var(--primary-light); font-weight: 500;
  display: inline-flex; align-items: center; gap: 4px;
}
.link:hover { text-decoration: underline; }

.kpi-grid {
  display: grid; gap: var(--s2);
  grid-template-columns: repeat(auto-fit, minmax(215px, 1fr));
}
.kpi { display: flex; flex-direction: column; gap: 6px; }
.kpi-top { display: flex; align-items: center; gap: 9px; }
.kpi-icon {
  width: 34px; height: 34px; border-radius: 10px;
  display: grid; place-items: center;
  background: var(--accent-soft); color: var(--primary);
}
.kpi-label { font-size: 12px; color: var(--text-muted); }
.kpi-value { font-family: var(--font-display); font-size: 25px; font-weight: 600; letter-spacing: 0.01em; }
.kpi-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.delta { font-size: 12px; font-weight: 600; }
.delta.up { color: var(--success); }
.delta.down { color: var(--critical); }
.delta small { color: var(--text-muted); font-weight: 400; margin-left: 4px; }
.spark { width: 92px; height: 34px; }

.overview-grid {
  display: grid; gap: var(--s2);
  grid-template-columns: repeat(12, 1fr);
}
.span-3 { grid-column: span 3; } .span-4 { grid-column: span 4; }
.span-5 { grid-column: span 5; } .span-6 { grid-column: span 6; }
.span-7 { grid-column: span 7; } .span-8 { grid-column: span 8; }
.span-12 { grid-column: span 12; }
@media (max-width: 1100px) {
  .span-3, .span-4, .span-5, .span-6, .span-7, .span-8 { grid-column: span 12; }
}

/* ---------------------------------------------------------- action list --- */
.action-item {
  display: flex; gap: 12px; align-items: flex-start;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 12px; margin-bottom: 10px; transition: transform 0.12s ease;
}
.action-item:hover { transform: translateX(3px); }
.action-item:last-child { margin-bottom: 0; }
.sev-dot { width: 10px; height: 10px; border-radius: 50%; margin-top: 5px; flex-shrink: 0; }
.sev-critical .sev-dot { background: var(--critical); }
.sev-warning .sev-dot { background: var(--warning); }
.sev-info .sev-dot { background: var(--info); }
.sev-chip {
  font-size: 10px; font-weight: 700; letter-spacing: 0.06em;
  padding: 2px 8px; border-radius: 999px;
}
.sev-critical .sev-chip { background: var(--critical-soft); color: var(--critical); }
.sev-warning .sev-chip { background: var(--warning-soft); color: #a07a17; }
.sev-info .sev-chip { background: var(--info-soft); color: var(--info); }
.action-body { flex: 1; min-width: 0; }
.action-title { font-weight: 600; font-size: 13.5px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.action-detail { font-size: 12.5px; color: var(--text-muted); margin-top: 1px; }
.action-rec { font-size: 12.5px; margin-top: 7px; }
.action-rec b { font-weight: 600; }
.action-impact { font-size: 12px; color: var(--success); font-weight: 500; }
.btn-review {
  align-self: center; white-space: nowrap;
  border: 1px solid var(--primary); color: #fff;
  background: var(--primary); border-radius: 999px;
  font-size: 12px; font-weight: 600; padding: 7px 15px;
  transition: filter 0.15s ease;
}
.btn-review:hover { filter: brightness(1.12); }
.btn-ghost {
  border: 1px solid var(--border); background: transparent;
  color: var(--neutral); border-radius: 999px;
  font-size: 12px; font-weight: 600; padding: 7px 15px;
}

/* ---------------------------------------------------------------- table --- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  text-align: left; font-size: 11px; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--text-muted);
  padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
td { padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--accent-soft); }
.rank-badge {
  width: 22px; height: 22px; border-radius: 7px;
  background: var(--accent-soft); color: var(--primary);
  display: inline-grid; place-items: center; font-weight: 600; font-size: 11.5px;
}
.chg-up { color: var(--success); font-weight: 600; font-size: 12px; }
.chg-down { color: var(--critical); font-weight: 600; font-size: 12px; }

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11.5px; font-weight: 600;
  border-radius: 999px; padding: 3px 10px; white-space: nowrap;
}
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill-Healthy { background: var(--success-soft); color: var(--success); }
.pill-Monitor { background: var(--info-soft); color: var(--info); }
.pill-AtRisk { background: var(--warning-soft); color: #a07a17; }
.pill-Critical { background: var(--critical-soft); color: var(--critical); }

.progress-track {
  height: 6px; border-radius: 999px; background: var(--accent-soft);
  overflow: hidden; min-width: 90px;
}
.progress-fill { height: 100%; border-radius: 999px; background: var(--primary); }

.donut-center { position: relative; }
.donut-meta { text-align: center; margin-top: 10px; }
.donut-meta .big { font-family: var(--font-display); font-size: 24px; font-weight: 600; }
.legend { display: flex; flex-direction: column; gap: 9px; margin-top: 6px; }
.legend-item { display: flex; align-items: center; gap: 8px; font-size: 12.5px; }
.legend-swatch { width: 10px; height: 10px; border-radius: 3px; }
.legend-value { margin-left: auto; color: var(--text-muted); }

.chart-box { position: relative; height: 260px; }
.chart-box.tall { height: 320px; }
.chart-box.short { height: 190px; }

.stat-strip { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--s2); margin-top: var(--s2); }
.stat-cell { text-align: left; }
.stat-cell .num { font-family: var(--font-display); font-size: 21px; font-weight: 600; }
.stat-cell .lbl { font-size: 11.5px; color: var(--text-muted); }

/* ----------------------------------------------------------- simulator --- */
.form-grid { display: grid; gap: var(--s2); grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.field label { font-size: 12px; font-weight: 600; color: var(--neutral); display: block; margin-bottom: 6px; }
.field input, .field select {
  width: 100%; border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 10px 12px; font: inherit; color: var(--text);
  background: var(--background); outline: none; transition: border 0.15s ease;
}
.field input:focus, .field select:focus { border-color: var(--primary-light); }
.range-row { display: flex; align-items: center; gap: 12px; }
input[type="range"] { accent-color: var(--primary); flex: 1; }
.range-val { min-width: 64px; font-weight: 600; font-size: 13px; text-align: right; }
.btn-primary {
  background: var(--primary); color: #fff; border: none;
  border-radius: 999px; padding: 11px 22px; font-weight: 600; font-size: 13.5px;
  display: inline-flex; align-items: center; gap: 8px; transition: filter 0.15s ease;
}
.btn-primary:hover { filter: brightness(1.12); }
.btn-primary:disabled { opacity: 0.55; cursor: wait; }

.compare-grid { display: grid; grid-template-columns: 1fr auto 1fr; gap: var(--s2); align-items: stretch; }
.compare-col { border: 1px dashed var(--border); border-radius: var(--radius-sm); padding: var(--s2); }
.compare-col.projected { border-style: solid; border-color: var(--accent); background: var(--accent-soft); }
.compare-arrow { align-self: center; color: var(--text-muted); }
.compare-metric .lbl { font-size: 11.5px; color: var(--text-muted); }
.compare-metric .val { font-family: var(--font-display); font-size: 19px; font-weight: 600; }

/* -------------------------------------------------------------- copilot --- */
.chat-window {
  display: flex; flex-direction: column; gap: var(--s2);
  height: calc(100vh - 240px); min-height: 420px;
}
.chat-scroll { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; padding-right: 4px; }
.msg { max-width: 78%; padding: 11px 14px; border-radius: 16px; font-size: 13.5px; white-space: pre-wrap; }
.msg.user { align-self: flex-end; background: var(--primary); color: #fff; border-bottom-right-radius: 4px; }
.msg.bot {
  align-self: flex-start; background: var(--surface);
  border: 1px solid var(--border); border-bottom-left-radius: 4px;
}
.msg.typing { color: var(--text-muted); font-style: italic; }
.suggest-row { display: flex; flex-wrap: wrap; gap: 8px; }
.suggest-chip {
  border: 1px solid var(--border); border-radius: 999px;
  padding: 6px 13px; font-size: 12px; background: var(--surface);
  color: var(--primary-light); font-weight: 500; transition: all 0.15s ease;
}
.suggest-chip:hover { border-color: var(--primary); background: var(--accent-soft); }
.chat-input { display: flex; gap: 10px; }
.chat-input input {
  flex: 1; border: 1px solid var(--border); background: var(--surface);
  border-radius: 999px; padding: 12px 18px; font: inherit;
  color: var(--text); outline: none;
}
.chat-send {
  width: 46px; height: 46px; border-radius: 50%; border: none;
  background: var(--primary); color: #fff; display: grid; place-items: center;
}

/* ------------------------------------------------------------- misc UI --- */
.empty {
  text-align: center; padding: var(--s4); color: var(--text-muted); font-size: 13.5px;
}
.filters { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: var(--s2); }
.filters input, .filters select {
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: 999px; padding: 8px 14px; font: inherit; font-size: 13px; outline: none;
}
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--primary); color: #fff; padding: 11px 22px;
  border-radius: 999px; font-size: 13px; box-shadow: var(--shadow); z-index: 200;
  animation: rise 0.25s ease;
}
.hidden { display: none !important; }
@keyframes rise { from { opacity: 0; transform: translate(-50%, 8px); } }
.fade-in { animation: fadein 0.35s ease; }
@keyframes fadein { from { opacity: 0; transform: translateY(6px); } }

.loading-skeleton { min-height: 60vh; display: grid; place-items: center; color: var(--text-muted); }
.spinner {
  width: 28px; height: 28px; border: 3px solid var(--border);
  border-top-color: var(--primary); border-radius: 50%;
  animation: spin 0.8s linear infinite; margin: 0 auto 12px;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 900px) {
  .sidebar {
    position: fixed; z-index: 100; transform: translateX(-105%);
    transition: transform 0.25s ease; box-shadow: var(--shadow);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-toggle { display: grid; }
  .user-meta, .search kbd { display: none; }
  .quote-note { display: none; }
}

/* ------------------------------------------------------ overview compact ---
   Keep the dashboard information-dense like the reference design.
   Grid rows must size to their content instead of stretching cards to a
   tall sibling/loading placeholder. */
.kpi-grid {
  align-items: start;
  grid-auto-rows: max-content;
}

.kpi-grid .kpi {
  height: 148px;
  min-height: 148px;
  align-self: start;
  overflow: hidden;
}

.kpi-grid .loading-skeleton {
  min-height: 148px;
}

.overview-grid {
  align-items: start;
  grid-auto-rows: max-content;
}

.overview-grid > .card {
  min-height: 0;
  align-self: start;
  overflow: hidden;
}

/* The primary two-column row stays compact while still leaving enough room
   for the chart and three action items. */
.overview-grid > .card:nth-child(1),
.overview-grid > .card:nth-child(2) {
  min-height: 350px;
  max-height: 350px;
}

#actionList {
  max-height: 276px;
  overflow-y: auto;
  padding-right: 2px;
  scrollbar-width: thin;
}

#actionList .action-item {
  margin-bottom: 8px;
  padding: 10px;
}

#actionList .action-rec {
  margin-top: 5px;
}

#actionList .action-impact {
  margin-top: 2px;
}

/* Keep the three supporting cards visually close to the reference layout. */
.overview-grid > .span-4,
.overview-grid > .span-3 {
  min-height: 250px;
  max-height: 300px;
}

.overview-grid > .span-4 table td {
  padding-top: 6px;
  padding-bottom: 6px;
}

.overview-grid .donut-center .chart-box.short {
  height: 135px;
}

.overview-grid #forecastSummary .chart-box.short {
  height: 125px;
}

.overview-grid .donut-meta {
  margin-top: 4px;
}

.overview-grid .legend {
  gap: 5px;
  margin-top: 3px;
}

.overview-grid .stat-strip {
  margin-top: 8px;
}

@media (max-width: 1100px) {
  .kpi-grid .kpi {
    height: auto;
    min-height: 148px;
  }

  .overview-grid > .card:nth-child(1),
  .overview-grid > .card:nth-child(2),
  .overview-grid > .span-4,
  .overview-grid > .span-3 {
    min-height: 0;
    max-height: none;
  }

  #actionList {
    max-height: none;
    overflow: visible;
  }
}