:root {
  --blue: #1d4ed8;
  --blue-dark: #1e3a8a;
  --bg: #f1f5f9;
  --card: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --minor: #eab308;
  --serious: #f97316;
  --major: #dc2626;
  --fatal: #111827;
  --ok: #16a34a;
  --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 1px 2px rgba(15, 23, 42, .06);
  --radius: 14px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ---------- top bar ---------- */
.topbar {
  background: linear-gradient(135deg, var(--blue-dark), var(--blue));
  color: #fff;
  padding: 12px 18px;
  display: flex;
  align-items: center;
  gap: 14px;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: var(--shadow);
}
.topbar .brand { display: flex; align-items: center; gap: 10px; text-decoration: none; }
.brand-mark { width: 32px; height: 32px; flex: none; filter: drop-shadow(0 1px 2px rgba(0, 0, 0, .28)); }
.brand-name { display: flex; align-items: baseline; gap: 5px; color: #fff; line-height: 1; }
.brand-name b { font-weight: 900; font-size: 19px; letter-spacing: .4px; }
.brand-sub { font-weight: 400; font-size: 18px; letter-spacing: .3px; color: #dbe6ff; }
.brand-tag { color: #bfdbfe; font-size: 13px; font-weight: 600; padding-left: 10px; margin-left: 8px; border-left: 1px solid rgba(255,255,255,.3); }
.topbar nav { margin-left: auto; display: flex; gap: 4px; flex-wrap: wrap; }
.topbar nav a {
  color: #dbeafe; text-decoration: none; padding: 7px 12px; border-radius: 8px;
  font-size: 14px; font-weight: 600;
}
.topbar nav a:hover, .topbar nav a.active { background: rgba(255, 255, 255, .18); color: #fff; }
.topbar nav .user-chip { color: #bfdbfe; font-size: 13px; font-weight: 700; padding: 7px 10px; opacity: .95; }
#logout { color: #fecaca !important; }

.wrap { max-width: 1120px; margin: 0 auto; padding: 20px 16px 60px; }
.page-title { font-size: 22px; font-weight: 800; margin: 6px 0 2px; }
.page-sub { color: var(--muted); margin: 0 0 20px; font-size: 14px; }

/* ---------- cards ---------- */
.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px;
}
.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 820px) { .grid.cols-3, .grid.cols-4 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 560px) { .grid.cols-2, .grid.cols-3, .grid.cols-4 { grid-template-columns: 1fr; } }

/* ---------- KPI stat tiles ---------- */
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; }
.stat .n { font-size: 30px; font-weight: 800; line-height: 1; }
.stat .l { color: var(--muted); font-size: 13px; margin-top: 6px; font-weight: 600; text-transform: uppercase; letter-spacing: .4px; }
.stat.accent-red .n { color: var(--major); }
.stat.accent-orange .n { color: var(--serious); }
.stat.accent-green .n { color: var(--ok); }
.stat.accent-blue .n { color: var(--blue); }

/* ---------- forms ---------- */
label.field { display: block; margin-bottom: 16px; }
label.field > span { display: block; font-weight: 600; font-size: 14px; margin-bottom: 6px; }
label.field .req { color: var(--major); }
input, select, textarea {
  width: 100%; padding: 12px 14px; font-size: 15px; font-family: inherit;
  border: 1px solid #cbd5e1; border-radius: 10px; background: #fff; color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px rgba(29, 78, 216, .15); }
textarea { min-height: 90px; resize: vertical; }
.hint { color: var(--muted); font-size: 12.5px; margin-top: 4px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--blue); color: #fff; border: none; border-radius: 10px;
  padding: 13px 22px; font-size: 15px; font-weight: 700; cursor: pointer; text-decoration: none;
}
.btn:hover { background: var(--blue-dark); }
.btn:disabled { opacity: .6; cursor: not-allowed; }
.btn.ghost { background: #fff; color: var(--blue); border: 1px solid var(--line); }
.btn.ghost:hover { background: #f8fafc; }
.btn.big { width: 100%; padding: 16px; font-size: 17px; }
.btn.sm { padding: 8px 14px; font-size: 13px; }
.btn.danger { background: var(--major); }

/* ---------- severity chips ---------- */
.chip { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.sev-Minor { background: #fef9c3; color: #854d0e; }
.sev-Serious { background: #ffedd5; color: #9a3412; }
.sev-Major { background: #fee2e2; color: #991b1b; }
.sev-Fatal { background: #e5e7eb; color: #111827; }
.st-Open { background: #dbeafe; color: #1e40af; }
.st-Under.Investigation, .st-Under { background: #fef3c7; color: #92400e; }
.status-badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; background: #e2e8f0; color: #334155; }

/* severity selector buttons (report form) */
.sev-select { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.sev-select button {
  border: 2px solid var(--line); background: #fff; border-radius: 10px; padding: 12px 6px;
  font-weight: 700; cursor: pointer; font-size: 14px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
}

/* ---------- pictorial type picker (low-literacy friendly) ---------- */
.type-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.type-tile {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 5px;
  border: 2px solid var(--line); background: #fff; border-radius: 12px; padding: 12px 6px;
  cursor: pointer; font-weight: 700; color: var(--ink); text-align: center; min-height: 80px;
}
.type-tile:hover { border-color: #cbd5e1; background: #f8fafc; }
.type-tile[aria-pressed="true"] {
  border-color: var(--blue); background: #eff6ff; color: var(--blue);
  box-shadow: 0 0 0 3px rgba(29, 78, 216, .12);
}
.ti-ico { font-size: 26px; line-height: 1; }
.ti-lbl { font-size: 12.5px; line-height: 1.2; }
@media (max-width: 430px) { .type-grid { grid-template-columns: repeat(2, 1fr); } }
.sev-select button[aria-pressed="true"] { color: #fff; border-color: transparent; }
.sev-select button.Minor[aria-pressed="true"] { background: var(--minor); }
.sev-select button.Serious[aria-pressed="true"] { background: var(--serious); }
.sev-select button.Major[aria-pressed="true"] { background: var(--major); }
.sev-select button.Fatal[aria-pressed="true"] { background: var(--fatal); }

/* ---------- table ---------- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th, table.data td { text-align: left; padding: 11px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.data th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .4px; }
table.data tr:hover td { background: #f8fafc; cursor: pointer; }

.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; margin-bottom: 16px; }
.filters label.field { margin-bottom: 0; min-width: 140px; }

.section-title { font-weight: 800; font-size: 15px; margin: 0 0 12px; display: flex; align-items: center; gap: 8px; }
.muted { color: var(--muted); }
.right { text-align: right; }

/* toast / banner */
.banner { padding: 14px 16px; border-radius: 12px; margin-bottom: 16px; font-weight: 600; }
.banner.ok { background: #dcfce7; color: #166534; border: 1px solid #86efac; }
.banner.err { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }
.banner.warn { background: #fef3c7; color: #92400e; border: 1px solid #fcd34d; }

canvas { max-width: 100%; }
/* Chart.js with maintainAspectRatio:false needs a definite-height parent, or it
   grows unbounded on each resize. A relative box with a fixed height is the
   standard responsive container — Chart.js fills it (no absolute positioning). */
.chart-box { position: relative; height: 240px; width: 100%; }

/* ---------- dashboard head + range filter ---------- */
.dash-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.range-filter { display: inline-flex; background: #eef2f7; border: 1px solid var(--line); border-radius: 10px; padding: 3px; gap: 2px; }
.range-filter button { border: none; background: transparent; color: var(--muted); font-weight: 700; font-size: 13px; padding: 7px 14px; border-radius: 8px; cursor: pointer; }
.range-filter button:hover { color: var(--ink); }
.range-filter button.active { background: #fff; color: var(--blue); box-shadow: var(--shadow); }

/* ---------- info tooltip (hover/focus) ---------- */
.info { display: inline-flex; align-items: center; justify-content: center; width: 15px; height: 15px; border-radius: 50%; background: #cbd5e1; color: #fff; font-size: 10px; font-weight: 800; font-style: normal; cursor: help; margin-left: 4px; position: relative; vertical-align: middle; }
.info:hover, .info:focus { background: var(--blue); outline: none; }
.info::after { content: attr(data-tip); position: absolute; bottom: 160%; left: 50%; transform: translateX(-50%); background: #0f172a; color: #fff; padding: 8px 11px; border-radius: 8px; font-size: 12px; font-weight: 500; line-height: 1.45; width: max-content; max-width: 260px; white-space: normal; text-align: left; opacity: 0; pointer-events: none; transition: opacity .12s; z-index: 70; box-shadow: 0 6px 18px rgba(15, 23, 42, .22); }
.info::before { content: ''; position: absolute; bottom: 160%; left: 50%; width: 9px; height: 9px; background: #0f172a; transform: translate(-50%, 55%) rotate(45deg); opacity: 0; transition: opacity .12s; z-index: 70; }
.info:hover::after, .info:focus::after, .info:hover::before, .info:focus::before { opacity: 1; }

/* ---------- KPI delta ---------- */
.kpi-delta { display: block; font-size: 12.5px; font-weight: 700; margin-top: 8px; }

/* ---------- follow-through funnel ---------- */
.fu-insight { font-size: 13.5px; font-weight: 600; padding: 8px 12px; border-radius: 8px; margin-bottom: 14px; }
.fu-insight.warn { background: #fef3c7; color: #92400e; }
.fu-insight.ok { background: #dcfce7; color: #166534; }
.fu-grid { display: flex; flex-direction: column; gap: 10px; }
.fu-row { display: grid; grid-template-columns: 120px 1fr 92px; align-items: center; gap: 12px; }
.fu-label { font-size: 13px; font-weight: 600; color: var(--ink); }
.fu-bar { background: #eef2f7; border-radius: 999px; height: 12px; overflow: hidden; }
.fu-fill { height: 100%; border-radius: 999px; transition: width .5s ease; }
.fu-val { font-size: 13px; text-align: right; }
@media (max-width: 560px) { .fu-row { grid-template-columns: 96px 1fr 70px; gap: 8px; } }

/* severity strip */
.sev-strip { display: flex; height: 12px; border-radius: 999px; overflow: hidden; margin-top: 18px; gap: 2px; background: #eef2f7; }
.sev-strip span { display: block; }
.sev-legend { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 10px; font-size: 12.5px; color: var(--muted); }
.sev-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: middle; }
.sev-legend b { color: var(--ink); }

/* ---------- action list rows ---------- */
.row-item { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 11px 4px; border-bottom: 1px solid var(--line); text-decoration: none; color: var(--ink); }
.row-item:last-child { border-bottom: none; }
.row-item:hover { background: #f8fafc; }
.ri-main { font-size: 14px; display: flex; align-items: center; gap: 7px; min-width: 0; }
.ri-main b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ri-reason { font-size: 12.5px; text-align: right; white-space: nowrap; display: flex; align-items: center; gap: 8px; }

/* ---------- progress chips (recent incidents) ---------- */
.prog-done { background: #dcfce7; color: #166534; }
.prog-ok { background: #dbeafe; color: #1e40af; }
.prog-todo { background: #fee2e2; color: #991b1b; }

/* success screen (report submitted) */
.success { text-align: center; padding: 40px 20px; }
.success .tick { width: 84px; height: 84px; border-radius: 50%; background: #dcfce7; color: var(--ok); display: flex; align-items: center; justify-content: center; font-size: 46px; margin: 0 auto 18px; }
.success .ref { font-size: 22px; font-weight: 800; color: var(--blue); margin: 8px 0; }
