/* ── Reverso OS — SABER Tracker ──
 * Warm-neutral dark palette. Inter for UI, DM Mono for numbers / codes.
 */

:root {
  --bg: #0f1114;
  --panel: #171a1f;
  --panel-2: #1d2027;
  --border: #2a2e37;
  --border-soft: #22252d;
  --text: #e6e7ea;
  --muted: #8e9199;
  --accent: #d4a373;
  --accent-soft: #a98160;

  --ok: #6cbf7a;
  --warn: #e6b86a;
  --bad: #d77b7b;
  --info: #7aa6d6;
  --neutral: #7a7f88;

  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 4px 20px rgba(0,0,0,0.3);
  --mono: 'DM Mono', ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; background: var(--bg); color: var(--text);
  font-family: 'Inter', -apple-system, system-ui, sans-serif; font-size: 14px; line-height: 1.5; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font-family: inherit; }
input, select, textarea { font-family: inherit; font-size: 14px; }
h1, h2, h3, h4 { margin: 0 0 12px; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 22px; } h2 { font-size: 18px; } h3 { font-size: 15px; }
p { margin: 0 0 12px; } .muted { color: var(--muted); }

.screen { display: none; }
.screen[hidden] { display: none !important; }
.screen[hidden="false"], .screen:not([hidden]) { display: block; }
.screen-app:not([hidden]) { display: grid !important; }
.screen-auth:not([hidden]) { display: flex !important; }

/* ── Auth screens ── */
.screen-auth { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: 24px; }
.auth-card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 32px; width: 100%; max-width: 380px; box-shadow: var(--shadow); }
.auth-card h1 { margin: 16px 0 8px; }
.auth-card form { display: flex; flex-direction: column; gap: 14px; margin-top: 20px; }
.auth-card label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.auth-card input { background: var(--panel-2); border: 1px solid var(--border); border-radius: var(--radius-sm);
  color: var(--text); padding: 10px 12px; outline: none; transition: border .15s; }
.auth-card input:focus { border-color: var(--accent); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 14px; color: var(--muted); }
.brand-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }
.form-error { color: var(--bad); font-size: 13px; min-height: 18px; }

/* ── Buttons ── */
.btn-primary { background: var(--accent); color: #1a1208; border: 0; padding: 10px 14px;
  border-radius: var(--radius-sm); font-weight: 600; cursor: pointer; transition: background .15s; }
.btn-primary:hover { background: var(--accent-soft); color: #110a03; }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-ghost { background: transparent; color: var(--muted); border: 1px solid var(--border);
  padding: 7px 11px; border-radius: var(--radius-sm); cursor: pointer; transition: border .15s, color .15s; }
.btn-ghost:hover { color: var(--text); border-color: var(--accent); }
.btn-sm { padding: 5px 9px; font-size: 12px; }

/* ── App shell ── */
.screen-app { display: grid; grid-template-columns: 240px 1fr; height: 100vh; }
.sidebar { background: var(--panel); border-right: 1px solid var(--border);
  padding: 20px 16px; display: flex; flex-direction: column; gap: 10px; }
.sidebar .brand { margin-bottom: 20px; }
#sidebar-nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 9px 11px;
  color: var(--muted); border-radius: var(--radius-sm); cursor: pointer;
  text-decoration: none; transition: background .12s, color .12s; font-size: 13px; }
.nav-item:hover { background: var(--panel-2); color: var(--text); }
.nav-item.active { background: var(--panel-2); color: var(--accent); }
.nav-section { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em;
  padding: 14px 11px 6px; opacity: 0.6; }

.sidebar-foot { border-top: 1px solid var(--border-soft); padding-top: 14px; display: flex;
  align-items: center; gap: 12px; }
.who { flex: 1; min-width: 0; }
.who-name { font-size: 13px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who-sub { font-size: 11px; color: var(--muted); }

#main { overflow: auto; padding: 28px 32px; }

/* ── KPI strip ── */
.kpi-strip { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px; margin-bottom: 24px; }
.kpi { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; }
.kpi-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.kpi-value { font-family: var(--mono); font-size: 24px; font-weight: 500; margin-top: 6px; }
.kpi-sub { font-size: 12px; color: var(--muted); margin-top: 4px; }
.kpi .kpi-value.ok { color: var(--ok); } .kpi .kpi-value.warn { color: var(--warn); }
.kpi .kpi-value.bad { color: var(--bad); } .kpi .kpi-value.info { color: var(--info); }

/* ── Status chips ── */
.chip { display: inline-flex; align-items: center; gap: 5px; padding: 3px 8px; border-radius: 12px;
  font-size: 11px; font-weight: 500; letter-spacing: 0.02em; }
.chip-yes { background: rgba(108,191,122,0.15); color: var(--ok); }
.chip-pending { background: rgba(230,184,106,0.15); color: var(--warn); }
.chip-no { background: rgba(215,123,123,0.15); color: var(--bad); }
.chip-not_set { background: rgba(122,127,136,0.15); color: var(--neutral); }
.chip-tier_1 { background: rgba(122,166,214,0.15); color: var(--info); }
.chip-tier_2 { background: rgba(169,129,96,0.18); color: var(--accent-soft); }

/* ── Progress bar ── */
.progress { background: var(--panel-2); border-radius: 4px; height: 6px; overflow: hidden; position: relative; }
.progress-fill { background: var(--accent); height: 100%; transition: width .3s; }

/* ── Category cards ── */
.cat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; margin-bottom: 24px; }
.cat-card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; cursor: pointer; transition: border .15s; }
.cat-card:hover { border-color: var(--accent); }
.cat-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.cat-name { font-weight: 600; }
.cat-pct { font-family: var(--mono); color: var(--accent); }
.cat-counts { display: flex; gap: 10px; font-size: 11px; color: var(--muted); margin-top: 8px; }

/* ── Tables ── */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th { text-align: left; padding: 10px 12px; font-weight: 500; color: var(--muted);
  border-bottom: 1px solid var(--border); font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; }
tbody td { padding: 10px 12px; border-bottom: 1px solid var(--border-soft); vertical-align: top; }
tbody tr:hover { background: var(--panel-2); }
td .sn { font-family: var(--mono); color: var(--muted); font-size: 12px; }
td .deadline { font-family: var(--mono); font-size: 12px; color: var(--muted); }
td .deadline.soon { color: var(--warn); }
td .deadline.overdue { color: var(--bad); }

/* ── Filter bar ── */
.filter-bar { display: flex; gap: 8px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.filter-bar input, .filter-bar select { background: var(--panel-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text); padding: 7px 10px; outline: none; }
.filter-bar input[type=search] { min-width: 240px; }
.filter-bar input:focus, .filter-bar select:focus { border-color: var(--accent); }

/* ── Panels ── */
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; margin-bottom: 20px; }
.panel h2 { margin-top: 0; }
.panel-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 16px; }

/* ── Toast ── */
#toast { position: fixed; bottom: 20px; right: 20px; background: var(--panel-2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 16px; max-width: 360px; box-shadow: var(--shadow); z-index: 100; }
#toast.ok { border-color: var(--ok); }
#toast.err { border-color: var(--bad); }

/* ── Deadlines list ── */
.deadline-list { display: flex; flex-direction: column; gap: 8px; }
.deadline-row { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px;
  background: var(--panel-2); border-radius: var(--radius-sm); }
.deadline-row .meta { display: flex; gap: 10px; align-items: center; }

/* ── Login header bar within app header ── */
.page-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 20px; }
.page-head .meta { color: var(--muted); font-size: 13px; }
.page-head .meta .pill { background: var(--panel-2); padding: 3px 9px; border-radius: 10px;
  font-family: var(--mono); font-size: 12px; margin-left: 8px; }

/* ── Dialog modal (lightweight) ── */
dialog { background: var(--panel); color: var(--text); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 24px; min-width: 380px; box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(0,0,0,0.6); }
dialog h2 { margin-top: 0; }
dialog form { display: flex; flex-direction: column; gap: 12px; }
dialog label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); }
dialog input, dialog select { background: var(--panel-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text); padding: 8px 10px; outline: none; }
dialog .dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }

/* Hierarchy (categories -> subjects) */
.hierarchy { display: flex; flex-direction: column; gap: 18px; margin-bottom: 24px; }
.hier-group { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.hier-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; cursor: pointer; padding: 4px 6px 12px; border-bottom: 1px solid var(--border-soft); margin-bottom: 14px; }
.hier-head:hover { background: var(--panel-2); border-radius: var(--radius-sm); }
.hier-title { font-size: 16px; font-weight: 600; color: var(--accent); }
.hier-meta { display: flex; align-items: center; gap: 12px; }
.hier-pct { font-family: var(--mono); font-size: 13px; min-width: 42px; text-align: right; color: var(--muted); }

.subj-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px; }
.subj-card { background: var(--panel-2); border: 1px solid var(--border-soft); border-radius: var(--radius-sm); padding: 12px; cursor: pointer; transition: border-color .15s, transform .1s; display: flex; flex-direction: column; gap: 8px; }
.subj-card:hover { border-color: var(--accent-soft); transform: translateY(-1px); }
.subj-name { font-weight: 500; font-size: 13px; line-height: 1.35; }
.subj-progress { display: flex; align-items: center; gap: 8px; }
.subj-progress .progress { flex: 1; }
.subj-pct { font-family: var(--mono); font-size: 12px; color: var(--muted); min-width: 36px; text-align: right; }
.subj-counts { display: flex; align-items: center; gap: 4px; font-size: 11px; }
.subj-counts .chip { padding: 2px 6px; font-size: 11px; }

/* Chart row */
.chart-row { display: grid; grid-template-columns: 1fr 1.4fr 1fr; gap: 14px; margin-bottom: 24px; }
.chart-row > .panel { min-width: 0; }
.chart-wrap { position: relative; height: 260px; width: 100%; }
.chart-wrap canvas { position: absolute; inset: 0; width: 100% !important; height: 100% !important; }
.chart-card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; min-height: 220px; display: flex; flex-direction: column; }
.chart-title { font-size: 13px; color: var(--muted); margin-bottom: 8px; font-weight: 500; }

/* Deadline heatmap */
.heatmap { display: flex; flex-wrap: wrap; gap: 3px; flex: 1; align-content: flex-start; }
.heat-cell { width: 14px; height: 14px; border-radius: 3px; background: var(--neutral); cursor: default; }
.heat-ok { background: var(--ok); }
.heat-warn { background: var(--warn); }
.heat-bad { background: var(--bad); }
.heat-info { background: var(--info); opacity: 0.55; }

/* DLI cards */
.dli-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px; margin-bottom: 18px; }
.dli-card.active { border-color: var(--accent); background: var(--panel-2); }
.dli-detail-panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 24px; }
.dli-detail-panel h3 { margin: 0 0 12px; font-size: 15px; color: var(--accent); }
.admin-tables { display: flex; flex-direction: column; gap: 24px; margin-top: 24px; }
.admin-tables .panel h3 { margin: 0 0 12px; font-size: 15px; color: var(--accent); }
.deliverable-row { cursor: pointer; }
.deliverable-row:hover { background: var(--panel-2); }
.deliverable-row.open { background: var(--panel-2); }
.deliverable-items { background: var(--panel-2); padding: 10px 12px; border-radius: var(--radius-sm); margin: 6px 0 10px; display: flex; flex-direction: column; gap: 6px; }
.deliverable-items .d-item { display: grid; grid-template-columns: 70px 1fr auto auto auto; gap: 10px; align-items: center; font-size: 12px; padding: 6px 0; border-bottom: 1px solid var(--border-soft); }
.deliverable-items .d-item:last-child { border-bottom: 0; }
.deliverable-items .d-item .sn { color: var(--muted); font-family: var(--mono); }
.deliverable-items .d-item .d-evidence { color: var(--text); }
.deliverable-items .d-item .d-deadline { color: var(--muted); font-family: var(--mono); }
.dli-card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; cursor: pointer; transition: border-color .15s, background .15s; }
.dli-card:hover { border-color: var(--accent-soft); }
.dli-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.dli-title { font-size: 15px; font-weight: 600; color: var(--accent); }
.dli-meta { display: flex; align-items: center; gap: 10px; font-size: 12px; }
.dli-pct { font-family: var(--mono); font-weight: 600; }
.dli-pct-ok { color: var(--ok); }
.dli-pct-warn { color: var(--warn); }
.dli-pct-bad { color: var(--bad); }
.progress-ok { background: var(--ok); }
.progress-warn { background: var(--warn); }
.progress-bad { background: var(--bad); }
.dli-body { max-height: 0; overflow: hidden; transition: max-height .25s ease; margin-top: 0; }
.dli-card.expanded .dli-body { max-height: 1200px; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border-soft); }

/* Deliverable rows */
.deliverable-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--border-soft); font-size: 13px; }
.deliverable-row:last-child { border-bottom: 0; }
.deliverable-label { flex: 1; line-height: 1.4; }
.deliverable-meta { display: flex; align-items: center; gap: 8px; }
.deliverable-meta .deadline { font-family: var(--mono); font-size: 11px; color: var(--muted); }

/* ── DLI detail: Excel-style grouping, roomier layout ── */
.dli-detail-panel { padding: 22px 26px !important; margin-top: 8px; }
.dli-detail-panel h3 { font-size: 17px; margin: 0 0 18px; }
.dlr-head { font-family: var(--mono); font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--accent); margin: 22px 0 8px; padding-bottom: 6px; border-bottom: 1px solid var(--border-soft); }
.dlr-head:first-of-type { margin-top: 4px; }
.sub-row { display: grid; grid-template-columns: 1fr 160px 64px 20px; align-items: center; gap: 18px; padding: 16px 14px; border-radius: var(--radius-sm); cursor: pointer; border-bottom: 1px solid var(--border-soft); }
.sub-row:hover, .sub-row.open { background: var(--panel-2); }
.sub-title { font-weight: 500; font-size: 14px; line-height: 1.4; }
.sub-desc { color: var(--muted); font-size: 12px; line-height: 1.5; margin-top: 4px; }
.sub-row .dli-pct { text-align: right; }
.sub-caret { color: var(--muted); font-size: 18px; transition: transform .15s; text-align: center; }
.sub-row.open .sub-caret { transform: rotate(90deg); }
.ev-list { margin: 4px 0 14px 14px; border-left: 2px solid var(--border); }
.ev-row { display: grid; grid-template-columns: 52px 1fr 100px 90px; align-items: start; gap: 18px; padding: 14px 16px; border-bottom: 1px solid var(--border-soft); }
.ev-row:last-child { border-bottom: none; }
.ev-sn { font-family: var(--mono); color: var(--muted); font-size: 12px; padding-top: 2px; }
.ev-text { font-size: 13.5px; line-height: 1.55; }
.ev-link { display: inline-block; margin-top: 6px; font-size: 12px; }
.ev-deadline { font-family: var(--mono); font-size: 12px; color: var(--muted); text-align: right; padding-top: 2px; }
.ev-status { text-align: right; }
@media (max-width: 760px) {
  .sub-row { grid-template-columns: 1fr 56px 16px; }
  .sub-bar { display: none; }
  .ev-row { grid-template-columns: 40px 1fr 76px; }
  .ev-deadline { display: none; }
}

/* ── Year 4 refresh ── */
:root { --bad: #e53935; }
.chip-no { background: rgba(229,57,53,0.18) !important; color: #ff5a52 !important; }
.kpi .kpi-value.bad, .dli-pct-bad { color: #ff5a52 !important; }
.status-key { display: flex; flex-wrap: wrap; gap: 22px; margin: 4px 0 20px; font-size: 13px; color: var(--muted); }
.status-key > span { display: inline-flex; align-items: center; gap: 8px; }
.dli-card { padding: 16px 18px; }
.dli-title { font-weight: 600; color: var(--accent); }
.dli-out { font-family: var(--mono); font-size: 26px; font-weight: 600; margin-top: 8px; line-height: 1; }
.dli-out-label { font-size: 11px; margin-top: 4px; }
.sub-row { grid-template-columns: 1fr 150px 20px !important; }
.race { display: flex; flex-direction: column; height: 260px; }
.race-head { display: flex; justify-content: space-between; align-items: flex-end; padding-bottom: 10px; border-bottom: 1px solid var(--border-soft); margin-bottom: 6px; }
.race-days { font-family: var(--mono); font-size: 34px; font-weight: 700; color: #ff5a52; line-height: 1; }
.race-count { font-family: var(--mono); font-size: 22px; font-weight: 600; color: var(--warn); line-height: 1; }
.race-sub { font-size: 11px; margin-top: 4px; }
.race-list { overflow-y: auto; flex: 1; }
.race-row { display: grid; grid-template-columns: 70px 1fr auto; gap: 10px; align-items: center; padding: 8px 2px; border-bottom: 1px solid var(--border-soft); font-size: 12px; }
.race-pk { font-family: var(--mono); color: var(--muted); font-size: 11px; }
.site-foot { position: fixed; right: 18px; bottom: 10px; display: flex; align-items: center; gap: 10px; font-size: 11px; color: var(--muted); z-index: 5; }
.foot-logo { height: 16px; width: auto; }
.screen-auth ~ .site-foot, body .site-foot { pointer-events: none; }

/* logo top-left + race list */
.brand.brand-logo { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; }
.brand-img { height: 26px; width: auto; display: block; }
.brand-title { font-size: 12px; font-weight: 600; color: var(--muted); letter-spacing: .02em; }
.race-row { grid-template-columns: 1fr auto !important; padding: 10px 2px !important; font-size: 13px !important; }
.race-row .race-pk { font-size: 12px; color: var(--accent); }

/* deadlines page */
.dl-race { display: flex; gap: 22px; align-items: center; padding: 18px 22px; margin-bottom: 22px; }
.dl-list { padding: 6px 18px; margin-bottom: 22px; }
.dl-row { display: grid; grid-template-columns: 130px 1fr 120px; gap: 18px; align-items: center; padding: 14px 0; border-bottom: 1px solid var(--border-soft); }
.dl-row:last-child { border-bottom: none; }
.dl-date { font-family: var(--mono); font-size: 13px; }
.dl-left { text-align: right; font-size: 13px; }
.dl-urgent { color: #ff5a52; font-weight: 600; }
