@import url("https://fonts.googleapis.com/css2?family=Source+Serif+4:wght@500;600&family=Public+Sans:wght@400;500;600;700&display=swap");

/* Institutional Calm - shared by every Dash app. Keep in sync with ui/shell.py. */
:root {
  color-scheme: light;
  --bg: #f6f4f0;
  --panel: #ffffff;
  --line: #e6e2da;
  --line-strong: #d5d0c4;
  --text: #20242c;
  --muted: #767b85;
  --tile: #faf9f6;
  --mute-bg: #eeece7;
  --accent: #0f6b5c;
  --accent-hover: #0c5748;
  --accent-bg: rgba(15, 107, 92, 0.09);
  --accent-ring: rgba(15, 107, 92, 0.25);
  --ok: #0f6b5c;
  --ok-bg: rgba(15, 107, 92, 0.09);
  --up: #1b7f4e;
  --up-bg: rgba(27, 127, 78, 0.1);
  --down: #b91c1c;
  --down-bg: rgba(185, 28, 28, 0.09);
  --warn: #9a5b12;
  --warn-bg: rgba(180, 83, 9, 0.1);
  --bad: #b91c1c;
  --bad-bg: rgba(185, 28, 28, 0.09);
  --info: #2c5aa0;
  --info-bg: rgba(44, 90, 160, 0.08);
  --violet: #5f56b3;
  --violet-bg: rgba(95, 86, 179, 0.1);
  --sidebar-bg: #132036;
  --sidebar-muted: #8b93a8;
  --sidebar-line: rgba(255, 255, 255, 0.08);
  --sidebar-active-bg: rgba(255, 255, 255, 0.1);
  --shadow: 0 1px 2px rgba(20, 20, 20, 0.04);
  --shadow-pop: 0 12px 28px rgba(20, 20, 20, 0.12);
  --radius: 12px;
  --radius-sm: 8px;
  --font: "Public Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-display: "Source Serif 4", Georgia, serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, monospace;

  /* Dash 4's own component tokens (dcc dropdown/tabs/checklist) mapped onto ours. */
  --Dash-Fill-Interactive-Strong: #0f6b5c;
  --Dash-Fill-Interactive-Weak: rgba(15, 107, 92, 0.09);
  --Dash-Fill-Inverse-Strong: #ffffff;
  --Dash-Stroke-Strong: #d5d0c4;
  --Dash-Stroke-Weak: #e6e2da;
  --Dash-Text-Primary: #20242c;
  --Dash-Text-Strong: #20242c;
  --Dash-Text-Weak: #767b85;
  --Dash-Text-Disabled: #a6a297;
  --Dash-Fill-Primary-Hover: #faf9f6;
  --Dash-Fill-Primary-Active: rgba(15, 107, 92, 0.09);
  --Dash-Fill-Disabled: #eeece7;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.55 var(--font);
}

h1, h2, h3, h4 { font-family: var(--font-display); font-weight: 600; margin: 0; }
h1 { font-size: 24px; }
h2 { font-size: 20px; }
h3 { font-size: 17px; }
h4 { font-size: 15px; }

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); text-decoration: underline; }

code, .mono { font-family: var(--font-mono); font-size: 12px; }

/* -------------------------------------------------------------- app shell */

.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 236px; flex-shrink: 0; background: var(--sidebar-bg);
  display: flex; flex-direction: column; padding: 26px 18px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.sidebar .brand {
  display: flex; align-items: center; gap: 10px; padding: 0 6px 26px;
  font-family: var(--font-display); font-weight: 600; font-size: 18px; color: #fff;
}
.sidebar .brand .mark { width: 24px; height: 24px; border-radius: 6px; background: #fff; flex-shrink: 0; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar nav a {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: var(--radius-sm);
  color: var(--sidebar-muted); font-size: 13.5px; text-decoration: none;
}
.sidebar nav a:hover { color: #fff; text-decoration: none; }
.sidebar nav a.active { background: var(--sidebar-active-bg); color: #fff; font-weight: 600; }

.content-col { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.topbar {
  min-height: 72px; flex-shrink: 0; display: flex; align-items: center; justify-content: space-between;
  gap: 20px; padding: 12px 34px; border-bottom: 1px solid var(--line); background: var(--panel);
  position: sticky; top: 0; z-index: 30;
}
.topbar-left { display: flex; align-items: center; gap: 22px; flex-wrap: wrap; min-width: 0; }
.topbar-right { display: flex; align-items: center; gap: 16px; flex-shrink: 0; }
.page-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.whoami { font-size: 12px; color: var(--muted); text-align: right; line-height: 1.35; }
.whoami b { color: var(--text); display: block; font-size: 13px; }

.wrap { flex: 1; padding: 30px 34px 48px; display: flex; flex-direction: column; gap: 20px; }

/* ------------------------------------------------------------ primitives */

.panel, .card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 26px 28px; box-shadow: var(--shadow);
}
.panel h3, .card h3 { margin: 0 0 6px; }
.panel .hint, .card .hint, .hint { margin: 0 0 16px; color: var(--muted); font-size: 12.5px; }

.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap; }
.toolbar-left, .toolbar-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 5px; }

.badge, .pill {
  display: inline-block; padding: 2px 9px; border-radius: 999px;
  font-size: 11px; font-weight: 600; letter-spacing: 0.3px; white-space: nowrap;
}
.pill.ok, .badge.ok { background: #fff; color: var(--ok); border: 1px solid var(--accent-ring); }
.pill.warn, .badge.warn { background: #fff; color: var(--warn); border: 1px solid rgba(180, 83, 9, 0.3); }
.pill.bad, .badge.bad { background: #fff; color: var(--bad); border: 1px solid rgba(185, 28, 28, 0.3); }
.pill.info, .badge.info { background: #fff; color: var(--info); border: 1px solid rgba(44, 90, 160, 0.3); }
.pill.mute, .badge.mute, .badge { background: var(--mute-bg); color: var(--muted); }

.stat, .kpi {
  background: var(--tile); border: 1px solid var(--line); border-radius: 10px; padding: 13px 15px;
  display: flex; flex-direction: column; gap: 3px;
}
.stat .k, .kpi .k { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }
.stat .v, .kpi .v { font-size: 19px; font-weight: 700; margin-top: 3px; letter-spacing: -0.2px; }
.stat .s, .kpi .s { font-size: 11.5px; color: var(--muted); }

.up, .positive, .text-green { color: var(--up) !important; }
.down, .negative, .text-red { color: var(--down) !important; }
.text-accent, .text-blue { color: var(--accent) !important; }
.text-muted { color: var(--muted) !important; }

.msg { padding: 10px 12px; border-radius: var(--radius-sm); font-size: 13px; margin-top: 12px; }
.msg.ok { background: var(--ok-bg); border: 1px solid var(--accent-ring); color: var(--accent); }
.msg.err { background: var(--bad-bg); border: 1px solid rgba(185, 28, 28, 0.28); color: var(--bad); }
.msg.info { background: var(--info-bg); border: 1px solid rgba(44, 90, 160, 0.25); color: var(--info); }
.msg code { word-break: break-all; font-size: 12px; }

.empty { padding: 28px; text-align: center; color: var(--muted); font-size: 13px; }
.empty-state {
  padding: 48px 24px; text-align: center; color: var(--muted);
  border: 1px dashed var(--line-strong); border-radius: var(--radius); background: var(--tile);
}

.chart { border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--panel); }

/* --------------------------------------------------------------- controls */

button, .btn {
  padding: 9px 15px; border: 0; border-radius: var(--radius-sm); cursor: pointer;
  background: var(--accent); color: #fff; font: inherit; font-size: 13px; font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none;
}
button:hover, .btn:hover { background: var(--accent-hover); color: #fff; text-decoration: none; }
button.ghost, .btn.ghost { background: #fff; border: 1px solid var(--line); color: var(--text); }
button.ghost:hover, .btn.ghost:hover { background: var(--tile); border-color: var(--line-strong); color: var(--text); }
button.danger, .btn.danger { background: var(--bad); }
button.danger:hover { background: #991717; }
button.sm, .btn.sm { padding: 6px 11px; font-size: 12px; }
button:disabled { opacity: 0.45; cursor: not-allowed; }

.chip {
  display: inline-flex; align-items: center; padding: 5px 11px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--tile); color: var(--muted);
  font-size: 12px; font-weight: 600; cursor: pointer; user-select: none;
}
.chip:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-bg); }
.chip.active, .chip--selected { background: var(--accent); border-color: var(--accent); color: #fff; }

/* Dash 3 ships a .dash-input-element class, which outranks a bare element selector. */
input,
select,
textarea,
input.dash-input-element {
  width: 100%; padding: 9px 11px; border-radius: var(--radius-sm); font: inherit; font-size: 13.5px;
  border: 1px solid var(--line); background: var(--tile); color: var(--text); outline: none;
}
input:focus, textarea:focus, input.dash-input-element:focus {
  border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-bg);
}
input::placeholder, textarea::placeholder { color: #a6a297; }
input[type="checkbox"], input[type="radio"] { width: auto; accent-color: var(--accent); cursor: pointer; }

.dash-checklist label, .dash-radioitems label {
  display: inline-flex; align-items: center; gap: 7px; color: var(--text); font-size: 13px; margin: 0 14px 6px 0;
}

/* dcc.Dropdown internals. Dash 3 renamed these from the old react-select classes,
   and renders the open menu in a portal outside the component's own wrapper - hence
   the unscoped selectors below. */
.dash-dropdown { font: inherit; }
.dash-dropdown-trigger {
  background: var(--tile); border: 1px solid var(--line); border-radius: var(--radius-sm);
  color: var(--text); min-height: 38px; font-size: 13.5px;
}
.dash-dropdown-trigger:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-bg); }
.dash-dropdown-value, .dash-dropdown-value-item { color: var(--text); }
.dash-dropdown-placeholder { color: #a6a297; }
.dash-dropdown-trigger-icon, .dash-dropdown-clear { color: var(--muted); }
.dash-dropdown-content,
.dash-dropdown-options,
.dash-options-list {
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius-sm);
  color: var(--text); box-shadow: var(--shadow-pop);
}
.dash-dropdown-search, .dash-dropdown-search-container { background: #fff; }
.dash-dropdown-search input { background: #fff; color: var(--text); border: 0; box-shadow: none; }
.dash-options-list-option, .dash-dropdown-option { background: transparent; color: var(--text); font-size: 13px; }
.dash-options-list-option:hover, .dash-dropdown-option:hover { background: var(--tile); }
.dash-options-list-option.selected, .dash-dropdown-option.selected { background: var(--accent-bg); color: var(--accent); }
.dash-options-list-option-text { color: inherit; }

/* dcc.Tabs */
.tab-container, .tabs {
  display: flex !important; gap: 4px; margin-bottom: 18px; border-bottom: 1px solid var(--line) !important;
  background: transparent !important;
}
.tab {
  flex: 0 0 auto !important; border: 0 !important; border-bottom: 2px solid transparent !important;
  padding: 10px 18px !important; background: transparent !important; color: var(--muted) !important;
  font-size: 13px !important; font-weight: 600 !important; cursor: pointer; text-align: center;
  width: auto !important;
}
.tab:hover { color: var(--text) !important; }
.tab--selected, .tab--active {
  color: var(--accent) !important; border-bottom-color: var(--accent) !important; background: transparent !important;
}

details > summary {
  cursor: pointer; color: var(--accent); font-size: 13px; font-weight: 600;
  padding: 8px 0; list-style: none;
}
details > summary::-webkit-details-marker { display: none; }
details > summary::before { content: "+ "; }
details[open] > summary::before { content: "− "; }

/* ---------------------------------------------------------------- tables */

.dash-table-container { border-radius: var(--radius-sm); overflow: hidden; }
.dash-table-container .dash-spreadsheet-container .dash-spreadsheet-inner td,
.dash-table-container .dash-spreadsheet-container .dash-spreadsheet-inner th {
  background: var(--panel) !important; color: var(--text) !important;
  border-color: var(--line) !important; font-size: 13px; font-family: var(--font);
}
.dash-table-container .dash-spreadsheet-container .dash-spreadsheet-inner th {
  background: var(--tile) !important; color: var(--muted) !important; font-weight: 600;
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em;
}
.dash-table-container .dash-spreadsheet-container .dash-spreadsheet-inner tr:hover td {
  background: var(--tile) !important;
}

/* Row-select radio (row_selectable="single") - default render is a tiny native
   radio easy to miss, so size it up and highlight the row it belongs to. */
.dash-select-cell { text-align: center !important; }
.dash-select-cell input[type="radio"],
.dash-select-cell input[type="checkbox"] {
  width: 19px; height: 19px; cursor: pointer; accent-color: var(--accent);
}
.dash-spreadsheet-inner tr:has(.dash-select-cell input:checked) td {
  background: var(--accent-bg) !important;
}

table.plain { width: 100%; border-collapse: collapse; font-size: 13px; }
table.plain th, table.plain td { padding: 8px 10px; border: 1px solid var(--line); text-align: center; }
table.plain th { background: var(--tile); color: var(--muted); font-weight: 600; font-size: 11px; text-transform: uppercase; }

/* ---------------------------------------------------------------- modals */

.modal-overlay {
  position: fixed; inset: 0; background: rgba(19, 32, 54, 0.45); backdrop-filter: blur(3px);
  display: flex; justify-content: center; align-items: center; z-index: 1000;
}
.modal {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  width: 90%; max-width: 900px; max-height: 90vh; overflow-y: auto; padding: 26px 28px; box-shadow: var(--shadow-pop);
}

@media (max-width: 900px) {
  .sidebar { display: none; }
  .topbar, .wrap { padding-left: 18px; padding-right: 18px; }
}
