:root {
  --blue: #1a56a0; --blue-light: #e8f0fb; --green: #166534; --calc: #d1fae5;
  --grey: #374151; --grey-light: #f9fafb; --border: #d1d5db; --red: #991b1b;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; font-size: 14px; color: var(--grey); background: #f3f4f6; }

/* ── Login ── */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: linear-gradient(135deg, #1a56a0, #0f3a72); }
.login-card { background: white; border-radius: 14px; padding: 36px 40px; width: 360px; box-shadow: 0 12px 40px rgba(0,0,0,0.25); text-align: center; }
.login-logo { font-size: 40px; }
.login-card h1 { font-size: 20px; color: var(--blue); margin-top: 6px; }
.login-sub { font-size: 12px; color: #6b7280; margin-bottom: 22px; }
.login-card form { text-align: left; }
.login-error { color: var(--red); font-size: 12px; min-height: 16px; margin: 4px 0; }
.login-hint { font-size: 11px; color: #9ca3af; margin-top: 16px; }
.btn-block { width: 100%; justify-content: center; margin-top: 8px; }

/* ── Header ── */
header { background: var(--blue); color: white; padding: 14px 24px; display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; z-index: 100; box-shadow: 0 2px 8px rgba(0,0,0,0.2); }
header h1 { font-size: 17px; font-weight: 600; }
header p { font-size: 12px; opacity: 0.8; margin-top: 2px; }
.header-actions { display: flex; gap: 12px; align-items: center; }
.whoami { font-size: 12px; opacity: 0.9; }

.tab-bar { background: white; border-bottom: 2px solid var(--border); display: flex; padding: 0 24px; position: sticky; top: 64px; z-index: 99; }
.tab { padding: 12px 20px; cursor: pointer; font-weight: 500; color: #6b7280; border-bottom: 3px solid transparent; margin-bottom: -2px; font-size: 13px; }
.tab:hover { color: var(--blue); }
.tab.active { color: var(--blue); border-bottom-color: var(--blue); }
.tab-content { display: none; }
.tab-content.active { display: block; }

.container { max-width: 980px; margin: 0 auto; padding: 24px 16px; }
.container-wide { max-width: 1180px; }

.card { background: white; border-radius: 10px; border: 1px solid var(--border); margin-bottom: 20px; overflow: hidden; }
.card-header { padding: 12px 20px; font-weight: 700; font-size: 13px; letter-spacing: 0.03em; text-transform: uppercase; color: white; }
.card-header.admin { background: #1e3a5f; }
.card-header.section-a { background: #1e40af; }
.card-header.section-b { background: #065f46; }
.card-header.section-c { background: #6d28d9; }
.card-header.section-d { background: #92400e; }
.card-header.section-e { background: #991b1b; }
.card-body { padding: 16px 20px; }

.field-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px 16px; }
.field-grid-4 { grid-template-columns: repeat(4, 1fr); }
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 11px; font-weight: 600; color: #6b7280; text-transform: uppercase; letter-spacing: 0.03em; }
.field .req { color: #dc2626; }
.field .muted { color: #9ca3af; font-weight: 400; text-transform: none; }
.field input, .field select, .field textarea { border: 1px solid var(--border); border-radius: 6px; padding: 7px 10px; font-size: 14px; color: var(--grey); background: white; width: 100%; }
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px rgba(26,86,160,0.1); }
.field input.auto-calc { background: var(--calc); color: var(--green); font-weight: 600; }
.field-full { grid-column: 1 / -1; }
textarea { resize: vertical; }

/* ── Manual (left) vs AI (right) paired layout ── */
.field-total { max-width: 260px; margin-bottom: 14px; }
.compare-head { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin: 2px 0 10px; }
.compare-head span { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; padding: 6px 10px; border-radius: 6px; text-align: center; }
.compare-head .col-manual { background: #eef2ff; color: #3730a3; border: 1px solid #c7d2fe; }
.compare-head .col-ai { background: #dcfce7; color: #065f46; border: 1px solid #a7f3d0; }
.pair-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; }
.pair-grid .field.m input { border-left: 3px solid #6366f1; }
.pair-grid .field.ai input { border-left: 3px solid #16a34a; }
.pair-note { display: flex; align-items: flex-end; padding-bottom: 8px; }
.pair-note span { font-size: 11px; color: #9ca3af; font-style: italic; }

.divider { border: none; border-top: 1px solid var(--border); margin: 14px 0; }
.sub-label { font-size: 11px; color: #9ca3af; font-style: italic; margin-bottom: 8px; }

.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 16px; border-radius: 6px; font-size: 13px; font-weight: 600; cursor: pointer; border: none; text-decoration: none; }
.btn-primary { background: var(--blue); color: white; }
.btn-success { background: #16a34a; color: white; }
.btn-outline { background: white; color: var(--grey); border: 1px solid var(--border); }
.btn-outline:hover { background: var(--grey-light); }
.btn-danger { background: #fee2e2; color: var(--red); border: 1px solid #fca5a5; }
.btn-ghost { background: rgba(255,255,255,0.12); color: white; border: 1px solid rgba(255,255,255,0.35); }
.btn-sm { padding: 5px 10px; font-size: 12px; }

.action-bar { padding: 16px 20px; background: var(--grey-light); border-top: 1px solid var(--border); display: flex; gap: 10px; justify-content: flex-end; align-items: center; }
.validation-msg { flex: 1; font-size: 12px; color: var(--red); font-weight: 500; }

.records-header { display: flex; justify-content: space-between; align-items: center; padding: 14px 20px; border-bottom: 1px solid var(--border); gap: 12px; flex-wrap: wrap; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; }
.filters select, .filters input { border: 1px solid var(--border); border-radius: 6px; padding: 6px 10px; font-size: 12px; }
.badge { display: inline-flex; align-items: center; justify-content: center; background: var(--blue); color: white; border-radius: 12px; padding: 2px 8px; font-size: 11px; font-weight: 700; min-width: 22px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 12px; }
thead tr { background: #f1f5f9; }
th { padding: 8px 10px; text-align: left; font-weight: 700; color: #475569; border-bottom: 2px solid var(--border); white-space: nowrap; }
td { padding: 8px 10px; border-bottom: 1px solid #f1f5f9; white-space: nowrap; }
tr:hover td { background: var(--blue-light); }
td.phase-Baseline { color: #1e40af; font-weight: 600; }
td.phase-Intervention { color: #065f46; font-weight: 600; }
.row-actions { display: flex; gap: 6px; }

.empty-state { text-align: center; padding: 48px 24px; color: #9ca3af; }
.empty-state .icon { font-size: 40px; margin-bottom: 12px; }

/* ── Dashboard ── */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; margin-bottom: 20px; }
.kpi { background: white; border: 1px solid var(--border); border-radius: 10px; padding: 16px 18px; border-left: 4px solid var(--blue); }
.kpi .kpi-value { font-size: 26px; font-weight: 700; color: #111827; }
.kpi .kpi-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; color: #6b7280; margin-top: 4px; }
.kpi .kpi-sub { font-size: 11px; color: #9ca3af; margin-top: 2px; }
.kpi.green { border-left-color: #16a34a; }
.kpi.purple { border-left-color: #6d28d9; }
.kpi.amber { border-left-color: #d97706; }
.chart-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 20px; }
.chart-grid canvas { max-height: 260px; }
table.compare th, table.compare td { font-size: 13px; padding: 10px 14px; }
table.compare td.metric { font-weight: 600; color: #374151; }
.delta-good { color: #16a34a; font-weight: 700; }
.delta-bad { color: #dc2626; font-weight: 700; }

.toast { position: fixed; bottom: 24px; right: 24px; background: #1f2937; color: white; padding: 12px 20px; border-radius: 8px; font-size: 13px; font-weight: 500; transform: translateY(80px); opacity: 0; transition: all 0.3s; z-index: 999; box-shadow: 0 4px 16px rgba(0,0,0,0.3); }
.toast.show { transform: translateY(0); opacity: 1; }
.toast.success { background: #166534; }
.toast.error { background: #991b1b; }

@media (max-width: 720px) {
  .field-grid-4 { grid-template-columns: repeat(2, 1fr); }
  .chart-grid { grid-template-columns: 1fr; }
  header { flex-direction: column; align-items: flex-start; gap: 8px; }
  .tab-bar { top: 88px; }
}
