/* driver-training.css — GPSFMS brand tokens (Roboto, navy #25477B, blue #0084C2,
 * dark #1C2B39), layout mirrors the Camera Health add-in. */

:root {
  --gpsfms-navy: #25477B;
  --gpsfms-blue: #0084C2;
  --gpsfms-dark: #1C2B39;
  --bg: #f4f6f9;
  --card: #ffffff;
  --line: #e2e8f0;
  --text: #1C2B39;
  --muted: #64748b;
  --green: #16a34a;
  --amber: #d97706;
  --red: #dc2626;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
/* The hidden attribute must beat explicit display values (.dt-modal is
 * display:flex, .dt-badge inline-block) — without this, modals render on load. */
[hidden] { display: none !important; }
.dt-body { font-family: 'Roboto', Arial, sans-serif; background: var(--bg); color: var(--text); font-size: 14px; }

/* ---- header ---- */
.dt-header { background: var(--gpsfms-navy); color: #fff; }
.dt-header-inner { display: flex; align-items: center; gap: 14px; padding: 12px 20px; max-width: 1280px; margin: 0 auto; }
.dt-logo { display: block; }
.dt-title { font-size: 19px; font-weight: 700; margin: 0; }
.dt-subtitle { font-size: 12px; opacity: .85; }
.dt-header-right { margin-left: auto; font-size: 12px; }
.dt-updated { opacity: .9; }

/* ---- tabs ---- */
.dt-tabs { display: flex; gap: 2px; background: var(--gpsfms-dark); padding: 0 20px; }
.dt-tab { appearance: none; border: 0; background: transparent; color: #cbd5e1; font: inherit; font-weight: 500; padding: 11px 18px; cursor: pointer; border-bottom: 3px solid transparent; }
.dt-tab:hover { color: #fff; }
.dt-tab-active { color: #fff; border-bottom-color: var(--gpsfms-blue); }
.dt-badge { display: inline-block; min-width: 18px; padding: 1px 6px; border-radius: 9px; background: var(--gpsfms-blue); color: #fff; font-size: 11px; font-weight: 700; margin-left: 6px; }

/* ---- layout ---- */
.dt-main { max-width: 1280px; margin: 0 auto; padding: 18px 20px 60px; }
.dt-card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 16px 18px; margin-bottom: 18px; }
.dt-card-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.dt-card-head h2 { font-size: 15px; margin: 0; }
.dt-card-actions { margin-left: auto; }
.dt-hint { font-size: 12px; color: var(--muted); }
.dt-none { color: var(--muted); padding: 14px 4px; }
.dt-warn { color: var(--red); font-size: 13px; }
.dt-success { color: var(--green); font-size: 13px; }

/* ---- KPI tiles ---- */
.dt-kpi-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 18px; }
.dt-kpi { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; }
.dt-kpi .v { font-size: 24px; font-weight: 700; color: var(--gpsfms-navy); }
.dt-kpi .l { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* ---- tables ---- */
.dt-table-wrap { overflow-x: auto; }
.dt-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.dt-table th { text-align: left; font-weight: 500; color: var(--muted); border-bottom: 2px solid var(--line); padding: 7px 10px; white-space: nowrap; }
.dt-table td { border-bottom: 1px solid var(--line); padding: 7px 10px; white-space: nowrap; }
.dt-table tr:hover td { background: #f8fafc; }

.dt-pill { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 500; }
.dt-pill-egregious { background: #fee2e2; color: var(--red); }
.dt-pill-coaching { background: #fef3c7; color: var(--amber); }
.dt-pill-open { background: #e0f2fe; color: var(--gpsfms-blue); }
.dt-pill-overdue { background: #fee2e2; color: var(--red); }
.dt-pill-completed { background: #dcfce7; color: var(--green); }
.dt-pill-cancelled { background: #f1f5f9; color: var(--muted); }
.dt-pill-assigned { background: #ede9fe; color: #6d28d9; }
.dt-pill-streak { background: #dcfce7; color: var(--green); font-weight: 700; }

.dt-btn { appearance: none; font: inherit; border: 1px solid var(--line); background: #fff; border-radius: 7px; padding: 7px 14px; cursor: pointer; color: var(--text); }
.dt-btn:hover { border-color: var(--gpsfms-blue); color: var(--gpsfms-blue); }
.dt-btn-primary { background: var(--gpsfms-blue); border-color: var(--gpsfms-blue); color: #fff; font-weight: 500; }
.dt-btn-primary:hover { background: #0a6ea0; color: #fff; }
.dt-btn-sm { padding: 3px 10px; font-size: 12px; }

.dt-filter-row { display: flex; gap: 16px; align-items: center; font-size: 13px; color: var(--muted); padding: 4px 0 10px; flex-wrap: wrap; }
.dt-filter-row select { font: inherit; padding: 3px 6px; }

/* ---- states ---- */
.dt-loading, .dt-empty, .dt-error { text-align: center; padding: 70px 20px; color: var(--muted); }
.dt-empty h2, .dt-error h2 { color: var(--text); }
.dt-spinner { display: inline-block; width: 18px; height: 18px; border: 3px solid var(--line); border-top-color: var(--gpsfms-blue); border-radius: 50%; animation: dtspin .8s linear infinite; vertical-align: -4px; margin-right: 8px; }
@keyframes dtspin { to { transform: rotate(360deg); } }

/* ---- trend bars (pure divs; no chart lib) ---- */
.dt-trend { display: flex; align-items: flex-end; gap: 6px; height: 110px; padding: 6px 0 0; }
.dt-trend-sm { height: 56px; gap: 4px; }
.dt-bar { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; height: 100%; position: relative; }
.dt-bar .seg-eg { background: #dc2626; border-radius: 3px 3px 0 0; }
.dt-bar .seg-ev { background: #b9d7ea; border-radius: 3px 3px 0 0; }
.dt-bar .seg-eg + .seg-ev { border-radius: 0; }
.dt-bar .lbl { position: absolute; bottom: -16px; left: 0; right: 0; text-align: center; font-size: 10.5px; color: var(--muted); white-space: nowrap; }
.dt-bar .val { position: absolute; top: -16px; left: 0; right: 0; text-align: center; font-size: 10.5px; color: var(--muted); }
.dt-trend-pad { padding-bottom: 18px; }

/* ---- recognition two-column layout ---- */
.dt-rec-layout { display: grid; grid-template-columns: minmax(280px, 340px) minmax(0, 1fr); gap: 14px; align-items: start; }
@media (max-width: 980px) { .dt-rec-layout { grid-template-columns: 1fr; } }
.dt-search { font: inherit; padding: 6px 10px; border: 1px solid var(--line); border-radius: 7px; width: 100%; margin: 8px 0; color: var(--text); }
.dt-filter-row .dt-search { width: 170px; margin: 0 0 0 auto; }

/* ---- district list (compact, internally scrollable) ---- */
.dt-district-list { max-height: 600px; overflow-y: auto; margin-top: 4px; }
.dt-dcard { border: 1px solid var(--line); border-radius: 9px; padding: 8px 10px; cursor: pointer; background: #fff; margin-bottom: 7px; }
.dt-dcard:hover { border-color: var(--gpsfms-blue); }
.dt-dcard.sel { border-color: var(--gpsfms-blue); background: #f0f9ff; }
.dt-dcard .row1 { display: flex; align-items: baseline; gap: 8px; }
.dt-dcard .code { font-weight: 700; color: var(--gpsfms-navy); font-size: 13px; }
.dt-dcard .dname { font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; }
.dt-dcard .score { font-size: 16px; font-weight: 700; margin-left: auto; }
.dt-trend-up { color: var(--red); font-size: 12px; }
.dt-trend-down { color: var(--green); font-size: 12px; }
.dt-trend-flat { color: var(--muted); font-size: 12px; }
.dt-dcard .som { font-size: 11px; color: var(--muted); margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dt-dcard .som b { color: var(--gpsfms-navy); font-weight: 500; }

/* ---- safety score badge (0-100, higher safer; GPSFMS-branded bands) ---- */
.dt-score { display: inline-block; min-width: 34px; text-align: center; font-weight: 700; padding: 3px 9px; border-radius: 7px; font-size: 13px; }
.dt-score.exc  { background: #dcfce7; color: #15803d; }   /* Excellent — green */
.dt-score.good { background: #e0f2fe; color: #0084C2; }   /* Good — GPSFMS blue */
.dt-score.fair { background: #fef3c7; color: #b45309; }   /* Fair — amber */
.dt-score.risk { background: #fee2e2; color: #b91c1c; }   /* Needs attention — red */
.dt-score.na   { background: #f1f5f9; color: var(--muted); }
/* colored KPI values reuse the same band palette */
.dt-v-exc { color: #15803d; }
.dt-v-good { color: #0084C2; }
.dt-v-fair { color: #b45309; }
.dt-v-risk { color: #b91c1c; }

/* ---- scoring legend ---- */
.dt-legend { background: #f8fafc; border: 1px solid var(--line); border-radius: 9px; padding: 12px 14px; font-size: 13px; margin-bottom: 10px; }
.dt-legend-scale { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 10px; }
.dt-legend p { margin: 0 0 8px; }
.dt-legend ul { margin: 0 0 10px; padding-left: 18px; }
.dt-legend li { margin-bottom: 3px; }
.dt-legend-weights { display: flex; flex-wrap: wrap; gap: 5px; }
.dt-wchip { font-size: 11.5px; border: 1px solid var(--line); border-radius: 999px; padding: 2px 9px; background: #fff; color: var(--muted); }
.dt-wchip b { color: var(--gpsfms-navy); }
.dt-wchip.eg { border-color: #fecaca; background: #fef2f2; }

/* ---- most improved ---- */
.dt-improved-row { display: grid; grid-template-columns: repeat(auto-fill, minmax(195px, 1fr)); gap: 10px; }
.dt-icard { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.dt-icard .who { font-weight: 500; cursor: pointer; }
.dt-icard .who:hover { color: var(--gpsfms-blue); }
.dt-icard .delta { color: var(--green); font-weight: 700; font-size: 15px; }
.dt-icard .ctx { font-size: 11.5px; color: var(--muted); }

/* ---- leaderboard polish ---- */
.dt-rank-1 .dt-rank, .dt-rank-2 .dt-rank, .dt-rank-3 .dt-rank { font-weight: 700; }
.dt-rank-1 .dt-rank { color: #b45309; }
.dt-rank-2 .dt-rank { color: #64748b; }
.dt-rank-3 .dt-rank { color: #92400e; }
.dt-driver-link { cursor: pointer; font-weight: 500; }
.dt-driver-link:hover { color: var(--gpsfms-blue); text-decoration: underline; }

/* ---- driver profile modal ---- */
.dt-modal-wide { width: min(660px, 94vw); }
.dt-profile-head { display: flex; gap: 12px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.dt-avatar { width: 44px; height: 44px; border-radius: 50%; background: var(--gpsfms-blue); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; }
.dt-profile-id h2 { margin: 0; }
.dt-profile-badges { margin-left: auto; display: flex; gap: 6px; flex-wrap: wrap; }
.dt-kpi-row-tight { grid-template-columns: repeat(auto-fit, minmax(108px, 1fr)); margin-bottom: 12px; }
.dt-kpi-row-tight .dt-kpi { padding: 8px 10px; }
.dt-kpi-row-tight .dt-kpi .v { font-size: 18px; }
.dt-prof-breakdown { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 14px; }
.dt-prof-history { max-height: 200px; overflow-y: auto; font-size: 13px; }
.dt-hist-item { display: flex; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--line); align-items: baseline; }
.dt-hist-item .when { color: var(--muted); font-size: 12px; white-space: nowrap; }
.dt-textarea { display: block; width: 100%; font: inherit; color: var(--text); padding: 8px 10px; margin-top: 4px; border: 1px solid var(--line); border-radius: 7px; min-height: 84px; resize: vertical; }

/* ---- modals ---- */
.dt-modal { position: fixed; inset: 0; background: rgba(28,43,57,.55); display: flex; align-items: center; justify-content: center; z-index: 50; }
.dt-modal-box { background: #fff; border-radius: 12px; padding: 20px 22px; width: min(480px, 92vw); max-height: 90vh; overflow-y: auto; }
.dt-modal-box h2 { margin: 0 0 10px; font-size: 16px; color: var(--gpsfms-navy); }
.dt-field { display: block; font-size: 13px; color: var(--muted); margin: 10px 0; }
.dt-field input, .dt-field select { display: block; width: 100%; font: inherit; color: var(--text); padding: 8px 10px; margin-top: 4px; border: 1px solid var(--line); border-radius: 7px; }
.dt-modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }
.dt-assign-context { background: #f1f5f9; border-radius: 8px; padding: 10px 12px; font-size: 13px; margin-bottom: 6px; }
.dt-link-box { width: 100%; font: 12px/1.5 monospace; padding: 8px; border: 1px solid var(--line); border-radius: 7px; height: 74px; resize: none; margin: 6px 0; }
