:root {
  --navy: #1b3a5b;
  --blue: #2f6db0;
  --bg: #f4f6f9;
  --ink: #1f2a37;
  --muted: #6b7684;
  --line: #e2e7ee;
  --red: #c0392b;
  --amber: #d98a00;
  --green: #2e7d32;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif; color: var(--ink); background: var(--bg); }
.hidden { display: none !important; }
button { cursor: pointer; font: inherit; }
a { color: var(--blue); }

/* Login */
.login-wrap { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; background: linear-gradient(160deg, #1b3a5b, #2f6db0); }
.login-card { background: #fff; padding: 32px; border-radius: 12px; width: 340px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.login-card h1 { font-size: 20px; margin: 0 0 4px; color: var(--navy); }
.login-card .sub { margin: 0 0 20px; color: var(--muted); font-size: 14px; }
.login-card label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 14px; }
.login-card input { display: block; width: 100%; margin-top: 5px; padding: 10px; border: 1px solid var(--line); border-radius: 7px; font-size: 15px; }
.login-card button { width: 100%; background: var(--blue); color: #fff; border: 0; padding: 11px; border-radius: 7px; font-size: 15px; font-weight: 600; }
.login-card button:hover { background: var(--navy); }
.brandline { color: #dce7f3; margin-top: 18px; font-size: 12px; letter-spacing: .3px; }
.error { color: #ffd7d0; font-size: 13px; margin-top: 10px; min-height: 16px; }
.login-card .error { color: var(--red); }

/* Topbar */
.topbar { display: flex; justify-content: space-between; align-items: center; background: var(--navy); color: #fff; padding: 12px 20px; }
.crumbs { font-size: 15px; }
.crumbs a { color: #cfe0f2; text-decoration: none; }
.crumbs a:hover { text-decoration: underline; }
.crumbs .sep { color: #7fa3c9; margin: 0 8px; }
.userbox { font-size: 13px; color: #cfe0f2; display: flex; gap: 12px; align-items: center; }
.linkbtn { background: none; border: 1px solid #40628a; color: #cfe0f2; border-radius: 6px; padding: 5px 10px; }
.linkbtn:hover { background: #24466a; }

/* Controls */
.controls { display: flex; align-items: center; gap: 20px; padding: 14px 20px; background: #fff; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.windowctl { font-size: 14px; display: flex; align-items: center; gap: 10px; }
.windowctl input[type=range] { width: 220px; }
.hint { color: var(--muted); font-size: 13px; }

main { padding: 22px; max-width: 1100px; margin: 0 auto; }

/* Tables & cards */
table { width: 100%; border-collapse: collapse; background: #fff; border-radius: 10px; overflow: hidden; box-shadow: 0 1px 3px rgba(0,0,0,.06); }
th, td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--line); font-size: 14px; }
th { background: #eef2f7; color: var(--navy); font-weight: 600; }
tr.click { cursor: pointer; }
tr.click:hover td { background: #f0f6ff; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.pill { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.pill.red { background: #fdecea; color: var(--red); }
.pill.amber { background: #fdf3e0; color: var(--amber); }
.pill.green { background: #e8f5e9; color: var(--green); }
.pill.gray { background: #eef1f5; color: var(--muted); }

.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat { background: #fff; border-radius: 10px; padding: 16px; box-shadow: 0 1px 3px rgba(0,0,0,.06); }
.stat .n { font-size: 30px; font-weight: 700; color: var(--navy); }
.stat .l { font-size: 13px; color: var(--muted); margin-top: 3px; }
.stat.alert .n { color: var(--red); }

h2 { color: var(--navy); font-size: 18px; margin: 6px 0 14px; }
.section { margin-bottom: 26px; }
.rowbtn { background: var(--blue); color: #fff; border: 0; padding: 10px 16px; border-radius: 8px; font-weight: 600; }
.rowbtn:hover { background: var(--navy); }
.ghostbtn { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 8px 14px; }
.muted { color: var(--muted); }
.spinner { color: var(--muted); padding: 30px; text-align: center; }
.backbtn { background: none; border: 0; color: var(--blue); padding: 0 0 10px; font-size: 14px; }

/* Write-up */
.warnwrap { background: #fff; padding: 26px; border-radius: 10px; box-shadow: 0 1px 3px rgba(0,0,0,.06); }
.warntop { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 16px; }
.nsdd { position: relative; }
.nsdd > summary { list-style: none; cursor: pointer; padding: 8px 14px; border: 1px solid var(--border, #cbd5e1); border-radius: 6px; background: #fff; font-weight: 600; font-size: 13px; user-select: none; white-space: nowrap; }
.nsdd > summary::-webkit-details-marker { display: none; }
.nsdd[open] > summary { border-color: #2563eb; }
.nsdd .nsmenu { position: absolute; z-index: 20; top: calc(100% + 4px); left: 0; min-width: 200px; background: #fff; border: 1px solid var(--border, #cbd5e1); border-radius: 6px; box-shadow: 0 6px 20px rgba(0,0,0,.12); padding: 6px; }
.nsdd .nsmenu label { display: flex; align-items: center; gap: 8px; padding: 7px 8px; border-radius: 4px; cursor: pointer; font-size: 13px; white-space: nowrap; }
.nsdd .nsmenu label:hover { background: #f1f5f9; }
.nsdd .nsmenu input { width: 15px; height: 15px; }
.warn { border: 2px solid #000; max-width: 780px; margin: 0 auto; font-size: 13px; color: #000; background: #fff; }
.warn .letterhead { text-align: center; font-weight: 800; font-size: 20px; letter-spacing: 2px; padding: 10px 8px 2px; }
.warn .title { text-align: center; font-weight: 700; font-size: 16px; padding: 8px; border-bottom: 2px solid #000; }
.warn .band { background: #d9d9d9; font-weight: 700; padding: 5px 8px; border-top: 1px solid #000; border-bottom: 1px solid #000; }
.warn .row { display: flex; border-bottom: 1px solid #000; }
.warn .cell { padding: 6px 8px; border-right: 1px solid #000; flex: 1; }
.warn .cell:last-child { border-right: 0; }
.warn .lbl { font-weight: 600; }
.warn .chk { width: 26px; text-align: center; border-right: 1px solid #000; font-weight: 700; }
.warn [contenteditable] { outline: none; min-height: 16px; }
.warn [contenteditable]:focus { background: #fffce0; }
.warn .desc { white-space: pre-wrap; padding: 8px; min-height: 90px; border-bottom: 1px solid #000; }
.warn .sig { display: flex; justify-content: space-between; padding: 22px 8px 6px; border-bottom: 1px solid #000; }
.warn .foot { text-align: center; font-weight: 700; letter-spacing: 1px; padding: 8px; }
.editnote { text-align: center; color: var(--muted); font-size: 12px; margin: 10px 0; }

/* ---------- Admin panel ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--line); margin: 4px 0 18px; }
.tab { padding: 9px 18px; color: var(--muted); text-decoration: none; border-bottom: 2px solid transparent; margin-bottom: -2px; font-weight: 600; }
.tab.on { color: var(--navy); border-bottom-color: var(--blue); }
.tab:hover { color: var(--navy); }
.formcard { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 18px 20px; box-shadow: 0 1px 3px rgba(0,0,0,.06); }
.formcard h2, .formcard h3, .detectbox h3 { margin: 6px 0 12px; color: var(--navy); }
.formcard h3, .detectbox h3 { font-size: 14px; margin-top: 16px; }
.frow { display: flex; gap: 14px; align-items: flex-end; margin-bottom: 12px; flex-wrap: wrap; }
.frow label { display: flex; flex-direction: column; font-size: 12px; color: var(--muted); font-weight: 600; gap: 4px; flex: 1; min-width: 160px; }
.frow input, .frow select { border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; font-size: 14px; color: var(--ink); background: #fff; }
.frow input:focus, .frow select:focus { outline: none; border-color: var(--blue); }
.formmsg { margin-top: 10px; font-size: 13px; color: var(--muted); }
.formmsg.err { color: var(--red); }
.rowactions { white-space: nowrap; }
.rowactions .linkbtn { color: var(--blue); border-color: transparent; background: none; padding: 4px 6px; font-size: 13px; }
.rowactions .linkbtn:hover { text-decoration: underline; background: none; }
.rowactions .linkbtn.danger { color: var(--red); }
.grid2 { display: grid; grid-template-columns: 1fr 1.3fr; gap: 18px; align-items: start; }
.detectbox { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 16px 20px; box-shadow: 0 1px 3px rgba(0,0,0,.06); }
ul.tight { margin: 4px 0; padding-left: 18px; }
ul.tight li { font-size: 13px; margin: 3px 0; }
.warnrow { background: #fff7e6; border: 1px solid #f0d69a; color: #7a5a00; border-radius: 8px; padding: 9px 12px; font-size: 13px; margin-top: 12px; }
@media (max-width: 720px) { .grid2 { grid-template-columns: 1fr; } }

/* Accident file — detail grid, report, photo gallery, lightbox */
.dgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; }
.dcell { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
.dcell .dk { font-size: 12px; color: var(--muted); }
.dcell .dv { font-size: 14px; color: var(--ink); margin-top: 2px; font-weight: 600; }
.reportbody { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 14px 16px; font-size: 14px; line-height: 1.5; white-space: normal; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.thumb { display: block; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: #000; aspect-ratio: 4 / 3; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .15s; }
.thumb:hover img { transform: scale(1.04); }
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.9); z-index: 1000; display: flex; align-items: center; justify-content: center; flex-direction: column; }
.lightbox img { max-width: 92vw; max-height: 82vh; object-fit: contain; border-radius: 4px; }
.lb-bar { position: fixed; top: 0; left: 0; right: 0; display: flex; align-items: center; gap: 16px; padding: 12px 18px; color: #fff; font-size: 14px; background: rgba(0,0,0,.4); }
.lb-bar span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-open { color: #9ecbff; text-decoration: none; }
.lb-close { background: none; border: 0; color: #fff; font-size: 22px; cursor: pointer; line-height: 1; }
.lb-nav { position: fixed; top: 50%; transform: translateY(-50%); background: rgba(255,255,255,.15); border: 0; color: #fff; font-size: 40px; width: 54px; height: 72px; cursor: pointer; border-radius: 8px; }
.lb-prev { left: 16px; } .lb-next { right: 16px; }

@media print {
  .topbar, .controls, .warntop, .editnote, .backbtn, .brandline { display: none !important; }
  body { background: #fff; }
  main { padding: 0; }
  .warnwrap { box-shadow: none; padding: 0; }
  .warn { border: 2px solid #000; }
}
