:root {
  --bg: #eef3f7;
  --panel: #ffffff;
  --ink: #172230;
  --muted: #66788a;
  --line: #d7e0e8;
  --brand: #174e7a;
  --brand-2: #0f3a5d;
  --soft: #f6f9fb;
  --shadow: 0 18px 50px rgba(20, 44, 66, .18);
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; font-family: Arial, Helvetica, sans-serif; color: var(--ink); background: var(--bg); }
body.modal-open { overflow: hidden; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.muted, .helper, small { color: var(--muted); }
.secondary-line { display: block; margin-top: 5px; font-size: 12px; color: var(--muted); }
.eyebrow { margin: 0 0 4px; color: #668096; letter-spacing: .09em; font-size: 11px; font-weight: 800; }
h1,h2,h3,p { margin-top: 0; }

.auth-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-card { width: min(430px, 100%); background: white; padding: 34px; border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow); }
.brand-mark { width: 48px; height: 48px; display: grid; place-items: center; border-radius: 14px; background: var(--brand); color: #fff; font-weight: 800; margin-bottom: 18px; }
.stack { display: grid; gap: 14px; }

.app-shell { padding: 16px; }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 18px; background: #fff; border: 1px solid var(--line); padding: 14px 18px; border-radius: 14px; box-shadow: 0 6px 22px rgba(25,55,80,.07); }
.topbar h1 { font-size: 24px; margin: 0; }
.user-controls { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.user-chip { background: #edf4f9; color: var(--brand-2); padding: 8px 11px; border-radius: 999px; font-size: 13px; font-weight: 700; }

.button { border: 1px solid #bdcbd6; background: #fff; color: var(--ink); border-radius: 8px; padding: 10px 14px; font-weight: 700; }
.button:hover { filter: brightness(.98); }
.button.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.button.secondary { background: #fff; }
.button.danger { background:#9f2e2a; border-color:#9f2e2a; color:#fff; }
.button.compact { padding: 8px 11px; font-size: 13px; }
.button.tiny { padding: 5px 8px; font-size: 11px; white-space: nowrap; }

.metrics { display: grid; grid-template-columns: repeat(5, minmax(140px, 1fr)); gap: 10px; margin: 12px 0; }
.metric-card { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 12px 15px; }
.metric-card span { display:block; color: var(--muted); font-size: 12px; margin-bottom: 5px; }
.metric-card strong { font-size: 25px; }

.view-tabs { display:flex; gap: 7px; margin-bottom: 10px; }
.view-tab { border: 1px solid var(--line); background: #fff; padding: 9px 16px; border-radius: 9px; font-weight: 800; color: #4b6174; }
.view-tab.active { background: var(--brand); color:#fff; border-color:var(--brand); }
.panel { background:#fff; border:1px solid var(--line); border-radius:14px; box-shadow: 0 6px 22px rgba(25,55,80,.06); }
.main-panel, .map-panel { padding: 14px; }
.section-heading { display:flex; justify-content:space-between; align-items:flex-start; gap:16px; }
.section-heading h2, .section-heading h3 { margin:0; }
.list-heading { align-items:center; margin-bottom:12px; }
.list-heading .helper { margin:0; max-width:680px; text-align:right; }

.filters { display:grid; gap:10px; margin-bottom:12px; }
.case-filters { grid-template-columns: minmax(260px,2fr) repeat(3,minmax(150px,1fr)); }
label { display:grid; gap:5px; font-size:12px; font-weight:700; color:#31485d; }
input, select, textarea { width:100%; border:1px solid #c8d4de; border-radius:8px; padding:9px 10px; background:#fff; color:var(--ink); }
textarea { resize:vertical; }
input:focus, select:focus, textarea:focus { outline:2px solid rgba(23,78,122,.15); border-color:#6390b3; }

.table-wrap { overflow:auto; border:1px solid var(--line); border-radius:10px; max-height: calc(100vh - 300px); }
.cases-top-scroll { overflow-x:auto; overflow-y:hidden; height:18px; margin:0 0 5px; border:1px solid var(--line); border-radius:7px; background:#f8fafc; }
.cases-top-scroll-inner { height:1px; min-width:1px; }
.cases-table-wrap { overflow-x:hidden; overflow-y:auto; scrollbar-gutter:stable; }
.cases-table { border-collapse:separate; border-spacing:0; width:100%; min-width:1750px; font-size:12px; }
.cases-table th { position:sticky; top:0; z-index:2; background:#123f64; color:#fff; text-align:left; padding:9px 8px; border-right:1px solid rgba(255,255,255,.18); white-space:nowrap; }
.cases-table td { vertical-align:top; padding:9px 8px; border-right:1px solid #e2e8ee; border-bottom:1px solid #dce5ec; background:#fff; line-height:1.3; }
.cases-table tr.case-row:hover td { background:#edf5fb; }
.cases-table tr.case-row { cursor:pointer; }
.cases-table th:nth-child(1) { min-width:110px; }
.cases-table th:nth-child(2) { min-width:190px; }
.cases-table th:nth-child(5) { min-width:260px; }
.cases-table th:nth-child(6) { min-width:220px; }
.cases-table th:nth-child(7) { min-width:300px; }
.cases-table th:nth-child(8) { min-width:210px; }
.cases-table th:nth-child(9) { min-width:230px; }
.recent-update-cell { max-width:320px; }
.multi-status-cell { min-width:280px; }
.row-actions { display:flex; gap:5px; flex-wrap:wrap; }
.empty-state, .empty-inline { color:var(--muted); padding:18px; text-align:center; }
.workstream-line { display:grid; grid-template-columns:minmax(110px,1fr) auto auto; gap:6px; align-items:center; padding:3px 0; border-bottom:1px dashed #e4eaef; }
.workstream-line:last-child { border-bottom:0; }
.status-badge { display:inline-flex; align-items:center; border-radius:999px; padding:3px 7px; font-size:10px; font-weight:800; white-space:nowrap; background:#edf1f4; color:#435262; }
.status-badge.pending, .status-badge.requested { background:#fff0d5; color:#915f05; }
.status-badge.scheduled, .status-badge.drafting { background:#dfeeff; color:#1456a0; }
.status-badge.completed, .status-badge.sent { background:#daf5df; color:#17652d; }
.status-badge.cancelled { background:#eceff2; color:#5d6670; }
.status-badge.on-hold, .status-badge.ready-for-review, .status-badge.supplemental { background:#f0e6ff; color:#65369a; }
.status-badge.active { background:#def4e7; color:#176238; }
.status-badge.closed { background:#e5ebef; color:#45515c; }
.mini-pill { display:inline-flex; border-radius:999px; padding:2px 6px; font-size:10px; background:#e6f0f7; color:#315d7d; white-space:nowrap; }
.mini-pill.neutral { background:#eef1f3; color:#69737c; }
.overdue-text { color:#b42318 !important; font-weight:800; }
.due-soon-text { color:#a15c00 !important; font-weight:800; }

.map-heading { align-items:center; }
.map-actions { display:flex; align-items:center; gap:10px; }
.map-toggle { display:flex; grid-auto-flow:column; width:auto; align-items:center; gap:6px; font-size:12px; }
.map-toggle input { width:auto; }
#map { height: min(72vh, 760px); min-height:520px; border:1px solid var(--line); border-radius:10px; margin-top:12px; }
.map-legend { display:flex; flex-wrap:wrap; gap:14px; align-items:center; padding:10px 3px 0; font-size:12px; }
.legend-marker { width:26px; height:26px; display:inline-grid; place-items:center; margin-right:5px; font-weight:900; color:#fff; vertical-align:middle; }
.legend-marker.vi { border-radius:50%; background:#2563eb; }
.legend-marker.crash { clip-path:polygon(50% 0,61% 29%,85% 15%,71% 39%,100% 50%,71% 61%,85% 85%,61% 71%,50% 100%,39% 71%,15% 85%,29% 61%,0 50%,29% 39%,15% 15%,39% 29%); background:#d97706; }
.legend-status { border-left:7px solid; padding-left:5px; }
.legend-status.pending { border-color:#d97706; }.legend-status.scheduled{border-color:#2563eb}.legend-status.completed{border-color:#16a34a}.legend-status.cancelled{border-color:#6b7280}
.casehub-div-icon { background:transparent; border:0; }
.vi-map-marker, .crash-map-marker { width:34px; height:34px; display:grid; place-items:center; color:#fff; background:var(--marker-color); border:3px solid #fff; box-shadow:0 2px 9px rgba(0,0,0,.35); font-weight:900; font-size:12px; }
.vi-map-marker { border-radius:50%; }
.crash-map-marker { font-size:20px; clip-path:polygon(50% 0,61% 26%,82% 10%,74% 36%,100% 50%,74% 64%,82% 90%,61% 74%,50% 100%,39% 74%,18% 90%,26% 64%,0 50%,26% 36%,18% 10%,39% 26%); }
.map-tooltip { display:grid; gap:3px; min-width:230px; }
.map-tooltip span { font-size:11px; }

.modal { position:fixed; inset:0; z-index:5000; background:rgba(9,23,35,.56); backdrop-filter:blur(2px); display:grid; place-items:center; padding:18px; overflow:auto; }
.modal-surface { width:min(100%, 920px); max-height:calc(100vh - 36px); overflow:auto; background:#fff; border-radius:16px; box-shadow:var(--shadow); border:1px solid #c9d5df; padding:18px; }
.modal-surface.small { width:min(100%,680px); }
.modal-surface.medium { width:min(100%,980px); }
.modal-surface.xlarge { width:min(96vw,1500px); }
.modal-heading { padding-bottom:12px; border-bottom:1px solid var(--line); margin-bottom:14px; }
.modal-close { border:0; background:transparent; color:#4f6170; font-size:30px; line-height:1; padding:2px 8px; }
.workspace-heading-actions { display:flex; align-items:center; gap:7px; }
.sticky-heading { position:sticky; top:-18px; z-index:10; background:#fff; padding-top:18px; }
.form-grid { display:grid; gap:13px; }
.two-column { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:11px; }
.three-column { display:grid; grid-template-columns:repeat(3,minmax(0,1fr)); gap:11px; }
.location-row { display:grid; grid-template-columns:minmax(0,1fr) auto; gap:9px; align-items:end; }
.subpanel { padding:12px; border:1px solid var(--line); border-radius:10px; background:#f8fafc; display:grid; gap:10px; }
.compact-heading { margin-bottom:2px; }
.assignment-fieldset { border:1px solid var(--line); border-radius:10px; padding:10px 12px 12px; }
.assignment-fieldset legend { color:#31485d; font-size:12px; font-weight:800; padding:0 5px; }
.assignment-options { display:flex; gap:8px; flex-wrap:wrap; }
.assignment-option { display:flex; grid-auto-flow:column; width:auto; align-items:center; gap:6px; padding:7px 10px; border:1px solid #d5dee6; border-radius:8px; background:#fff; }
.assignment-option input, .inline-check input { width:auto; }
.checkbox-row.inline-check { display:flex; grid-auto-flow:column; justify-content:start; align-items:center; gap:7px; padding-top:23px; }
.form-actions { display:flex; justify-content:flex-end; gap:8px; padding-top:5px; }

.workspace-content { display:grid; gap:14px; }
.workspace-section-editing { border-color:#86aeca; box-shadow:0 0 0 2px rgba(53,112,151,.08); }
.workspace-inline-edit { background:#f8fbfd; border-radius:10px; padding:2px; }
.workspace-inline-edit .section-heading { margin-bottom:0; }
.workspace-inline-edit textarea { resize:vertical; }
.workspace-summary-grid { display:grid; grid-template-columns:repeat(6,minmax(0,1fr)); gap:8px; }
.workspace-summary-grid article { border:1px solid var(--line); background:#f8fafc; padding:10px; border-radius:10px; display:grid; gap:5px; }
.workspace-summary-grid span:first-child { font-size:10px; color:var(--muted); text-transform:uppercase; letter-spacing:.05em; }
.workspace-summary-grid strong { font-size:12px; }
.workspace-section { border:1px solid var(--line); border-radius:12px; padding:13px; background:#fff; }
.overview-grid { display:grid; grid-template-columns:repeat(4,minmax(0,1fr)); gap:8px; margin-top:11px; }
.detail-card { border:1px solid #e0e7ed; background:#f8fafb; padding:9px; border-radius:8px; display:grid; gap:4px; }
.detail-card span { font-size:10px; color:var(--muted); text-transform:uppercase; }
.detail-card.wide { grid-column:span 2; }
.setup-checks { display:grid; grid-template-columns:repeat(6,minmax(0,1fr)); gap:7px; margin-top:10px; }
.setup-check { display:flex; grid-auto-flow:column; align-items:center; gap:6px; background:#f7fafc; border:1px solid var(--line); border-radius:8px; padding:8px; }
.setup-check input { width:auto; }
.case-notes { margin-top:10px; padding:10px; background:#fffbea; border:1px solid #eee3ac; border-radius:8px; }
.case-notes p { margin:4px 0 0; white-space:pre-wrap; }
.materials-grid { display:grid; gap:6px; margin-top:10px; }
.material-row { display:grid; grid-template-columns:minmax(260px,2fr) minmax(150px,1fr) 150px; gap:8px; align-items:center; padding:6px; border-bottom:1px solid #edf1f4; }
.vehicle-grid { display:grid; grid-template-columns:repeat(auto-fit,minmax(360px,1fr)); gap:9px; margin-top:10px; }
.vehicle-card, .report-card, .inspection-row-card { border:1px solid #dce5eb; border-radius:9px; background:#f9fbfc; padding:10px; }
.card-heading, .report-card, .inspection-row-card { display:flex; justify-content:space-between; gap:12px; align-items:flex-start; }
.card-heading > div:first-child, .report-card > div:first-child, .inspection-row-card > div:first-child { display:grid; gap:4px; }
.report-card > div:last-child, .inspection-row-card > div:last-child { display:flex; gap:6px; align-items:center; flex-wrap:wrap; justify-content:flex-end; }
.mini-list, .inspection-list, .report-list { display:grid; gap:7px; margin-top:9px; }
.inspection-chip { width:100%; text-align:left; border:1px solid #d9e2e9; background:#fff; border-radius:7px; padding:7px; }
.unlinked-block { margin-top:10px; padding:10px; border:1px dashed #c7d3dd; display:grid; gap:6px; }
.scene-location-card { margin-top:9px; display:flex; flex-direction:column; gap:4px; background:#f6fafc; border:1px solid #dce6ee; padding:9px; border-radius:8px; }
.activity-list { display:grid; margin-top:8px; }
.activity-item { display:grid; grid-template-columns:150px minmax(0,1fr); gap:12px; padding:9px 3px; border-bottom:1px solid #edf1f4; }
.activity-item time { color:var(--muted); font-size:11px; }
.activity-item p { margin:3px 0; white-space:pre-wrap; }

.toast { position:fixed; z-index:9999; right:18px; bottom:18px; max-width:420px; padding:12px 15px; background:#183b55; color:#fff; border-radius:9px; box-shadow:0 10px 30px rgba(0,0,0,.25); opacity:0; transform:translateY(12px); pointer-events:none; transition:.18s ease; }
.toast.show { opacity:1; transform:translateY(0); }
.toast.error { background:#8b2824; }

@media (max-width: 1100px) {
  .metrics { grid-template-columns:repeat(3,1fr); }
  .case-filters { grid-template-columns:repeat(2,1fr); }
  .workspace-summary-grid { grid-template-columns:repeat(3,1fr); }
  .setup-checks { grid-template-columns:repeat(3,1fr); }
  .overview-grid { grid-template-columns:repeat(2,1fr); }
}
@media (max-width: 720px) {
  .app-shell { padding:8px; }
  .topbar { align-items:flex-start; flex-direction:column; }
  .user-controls { justify-content:flex-start; }
  .metrics, .case-filters, .two-column, .three-column, .workspace-summary-grid, .overview-grid, .setup-checks { grid-template-columns:1fr; }
  .detail-card.wide { grid-column:auto; }
  .location-row { grid-template-columns:1fr; }
  .material-row { grid-template-columns:1fr; }
  .vehicle-grid { grid-template-columns:1fr; }
  .modal { padding:5px; }
  .modal-surface { max-height:calc(100vh - 10px); border-radius:10px; padding:12px; }
  .activity-item { grid-template-columns:1fr; gap:4px; }
  #map { min-height:460px; }
}

/* Optimized Case Hub V2 additions */
.metrics { grid-template-columns: repeat(6, minmax(130px, 1fr)); }
.four-column { display:grid; grid-template-columns:repeat(4,minmax(0,1fr)); gap:11px; }
.next-action-cell { min-width:240px; }
.cases-table th:nth-child(6) { min-width:250px; }
.cases-table th:nth-child(7) { min-width:220px; }
.cases-table th:nth-child(8) { min-width:300px; }
.cases-table th:nth-child(9) { min-width:240px; }
.cases-table th:nth-child(10) { min-width:230px; }
.status-badge.final { background:#d9f1f4; color:#145c64; }
.status-badge.in-progress, .status-badge.authorized { background:#dfeeff; color:#1456a0; }
.status-badge.waiting, .status-badge.authorization-needed { background:#fff0d5; color:#915f05; }
.status-badge.archived { background:#e5e7eb; color:#4b5563; }
.status-badge.unavailable { background:#eceff2; color:#5d6670; }
.status-badge.not-requested { background:#f1f5f9; color:#64748b; }
.mini-pill.priority-high { background:#ffe7c2; color:#9a5100; }
.mini-pill.priority-critical { background:#fbe0de; color:#a0251c; }
.split-actions { align-items:center; }
.action-spacer { flex:1; }
.setup-checks-dated { grid-template-columns:repeat(3,minmax(0,1fr)); }
.setup-check.dated { display:grid; grid-template-columns:minmax(0,1fr) 132px; align-items:center; }
.setup-check.dated label { display:flex; align-items:center; gap:6px; }
.setup-check.dated input[type="date"] { padding:6px 7px; font-size:11px; }
.admin-date-grid { display:grid; grid-template-columns:repeat(5,minmax(150px,1fr)); gap:9px; margin-top:10px; }
.task-list { display:grid; gap:7px; margin-top:9px; }
.task-card { border:1px solid #dce5eb; border-radius:9px; background:#f9fbfc; padding:10px; display:flex; justify-content:space-between; gap:12px; align-items:flex-start; }
.task-card > div:first-child { display:grid; gap:4px; }
.task-card > div:last-child { display:flex; gap:6px; align-items:center; flex-wrap:wrap; justify-content:flex-end; }
.mini-section-label { color:var(--muted); font-size:10px; text-transform:uppercase; letter-spacing:.06em; font-weight:800; }
.vehicle-card .mini-list + .mini-list { border-top:1px dashed #d9e2e9; padding-top:8px; }

@media (max-width: 1250px) {
  .metrics { grid-template-columns:repeat(3,1fr); }
  .admin-date-grid { grid-template-columns:repeat(3,1fr); }
}
@media (max-width: 720px) {
  .four-column, .admin-date-grid, .setup-checks-dated { grid-template-columns:1fr; }
  .setup-check.dated { grid-template-columns:1fr; }
  .task-card { flex-direction:column; }
}

/* Downloads live inside vehicle inspections */
.subpanel-heading { display:flex; align-items:flex-start; justify-content:space-between; gap:12px; }
.subpanel-heading .helper { margin:3px 0 0; }
.nested-record-list { display:grid; gap:7px; }
.nested-record { width:100%; text-align:left; border:1px solid #d9e2e9; background:#fff; border-radius:7px; padding:7px 9px; cursor:pointer; }
.nested-record:hover { border-color:#9fb4c2; background:#f7fafc; }
.inspection-group { display:grid; gap:5px; padding:6px 0; }
.inspection-group + .inspection-group { border-top:1px dashed #d9e2e9; }
.inspection-download-summary { display:grid; gap:4px; padding-left:14px; }
.inspection-download-summary .nested-record { font-size:.88rem; padding:5px 7px; }
