:root {
  --bg: #0b0f14; --panel: #131a22; --panel2: #1a232e; --line: #26323f; --text: #e8edf2; --muted: #8b9aab;
  --accent: #f59e0b; --red: #ef4444; --redbg: #3b1212; --green: #22c55e; --amber: #f59e0b; --blue: #3b82f6;
  --chip: #212c38; --shadow: 0 6px 24px rgba(0,0,0,.45); --radius: 10px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}
body.day {
  --bg: #eef1f5; --panel: #ffffff; --panel2: #f5f7fa; --line: #d3dae3; --text: #0f172a; --muted: #5b6b7d;
  --chip: #e9eef4; --redbg: #fde2e2; --shadow: 0 6px 24px rgba(15,23,42,.15);
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { min-height: 100vh; display: flex; flex-direction: column; font-size: 15px; }
main { flex: 1; padding: 14px; width: 100%; }
a { color: var(--accent); }
h1, h2, h3 { margin: 0 0 10px; letter-spacing: .02em; }
h2 { font-size: 20px; } h3 { font-size: 16px; }
.muted { color: var(--muted); } .small { font-size: 12px; }
.foot { text-align: center; color: var(--muted); font-size: 12px; padding: 10px; }

/* top bar */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 14px;
  background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.brand { display: flex; align-items: center; gap: 8px; color: var(--text); text-decoration: none; font-size: 15px; }
.brand img { width: 30px; height: 30px; }
.brand b { margin-left: 4px; color: var(--accent); }
nav { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
nav a, nav button { color: var(--text); text-decoration: none; background: none; border: 1px solid transparent; padding: 6px 10px; border-radius: 8px; font: inherit; cursor: pointer; }
nav a:hover, nav button:hover { border-color: var(--line); }
.who { color: var(--muted); font-size: 13px; padding: 0 6px; }

/* controls */
button, .btn { font: inherit; font-weight: 600; border-radius: 8px; border: 1px solid var(--line); background: var(--panel2);
  color: var(--text); padding: 8px 14px; cursor: pointer; min-height: 38px; }
button:hover { filter: brightness(1.15); }
button:disabled { opacity: .45; cursor: not-allowed; }
.primary { background: var(--accent); border-color: var(--accent); color: #111; }
.danger { background: var(--red); border-color: var(--red); color: #fff; }
.ghost { background: transparent; }
.sm { padding: 4px 9px; min-height: 30px; font-size: 13px; }
input, select, textarea { font: inherit; color: var(--text); background: var(--panel2); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 10px; min-height: 38px; width: 100%; }
textarea { min-height: 120px; }
label { display: block; font-size: 13px; color: var(--muted); margin: 8px 0 4px; }
.row { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 120px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.stack > * + * { margin-top: 12px; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
tr.inactive td { opacity: .5; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.tabs a { padding: 7px 12px; border-radius: 8px; background: var(--panel); border: 1px solid var(--line); color: var(--text); text-decoration: none; }
.tabs a.on { background: var(--accent); color: #111; border-color: var(--accent); }
.pill { display: inline-block; white-space: nowrap; font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 99px; background: var(--chip); color: var(--muted); letter-spacing: .03em; }
.pill.red { background: var(--red); color: #fff; } .pill.green { background: var(--green); color: #052e12; } .pill.amber { background: var(--amber); color: #111; }

/* login */
.login { max-width: 380px; margin: 8vh auto; }
.login .logo { text-align: center; margin-bottom: 14px; } .login .logo img { width: 64px; }

/* incidents list */
.inc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.inc { cursor: pointer; border-left: 5px solid var(--red); }
.inc .big { font-size: 26px; font-weight: 800; }

/* board */
.bhead { display: flex; flex-wrap: wrap; gap: 10px 18px; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.bhead .title { font-size: 20px; font-weight: 800; }
.stats { display: flex; gap: 8px; flex-wrap: wrap; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 4px 10px; text-align: center; min-width: 74px; }
.stat b { display: block; font-size: 20px; line-height: 1.1; }
.stat span { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.stat.hot b { color: var(--red); }
.icbadge { padding: 4px 10px; border-radius: 8px; background: var(--panel); border: 1px solid var(--line); font-size: 13px; }
.icbadge.me { background: var(--accent); color: #111; border-color: var(--accent); font-weight: 800; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.banner { border-radius: 8px; padding: 10px 14px; font-weight: 800; margin-bottom: 10px; }
.banner.emerg { background: var(--red); color: #fff; animation: flash 1s steps(2) infinite; font-size: 18px; }
.banner.par { background: var(--amber); color: #111; }
@keyframes flash { 50% { filter: brightness(1.5); } }
.netbanner { background: var(--red); color: #fff; text-align: center; padding: 6px; font-weight: 700; position: sticky; top: 47px; z-index: 19; }

.layout { display: grid; grid-template-columns: 1fr 300px; gap: 12px; align-items: start; }
.layout.nolog { grid-template-columns: 1fr; }
.board { display: grid; grid-template-columns: 300px 1fr; gap: 10px; align-items: start; }
.board .side { display: flex; flex-direction: column; gap: 10px; position: sticky; top: 60px; max-height: calc(100vh - 70px); overflow: auto; }
.board .work { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 10px; align-items: start; }
.thead .tname { flex: 1; }
.thead .tm { min-height: 26px; padding: 0 6px; }
@media (max-width: 700px) { .board { grid-template-columns: 1fr; } .board .side { position: static; max-height: none; } }
.task { background: var(--panel); border: 1px solid var(--line); border-top: 5px solid var(--tc, #64748b); border-radius: var(--radius); min-height: 90px; display: flex; flex-direction: column; }
.task.k-rehab { background: color-mix(in srgb, var(--green) 9%, var(--panel)); }
.task.k-released { opacity: .8; }
.task.empty { min-height: 70px; }
.task.drop-ok { outline: 3px dashed var(--accent); outline-offset: 2px; }
.thead { display: flex; justify-content: space-between; align-items: center; gap: 6px; padding: 8px 10px 4px; }
.thead .tname { font-weight: 800; text-transform: uppercase; letter-spacing: .04em; font-size: 14px; }
.thead .tcount { font-size: 12px; color: var(--muted); white-space: nowrap; }
.tloc { padding: 0 10px; font-size: 12px; color: var(--muted); }
.crews { padding: 6px 8px 8px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.droptip { color: var(--muted); font-size: 12px; text-align: center; padding: 8px; border: 1px dashed var(--line); border-radius: 8px; }

.crew { background: var(--panel2); border: 1px solid var(--line); border-radius: 9px; box-shadow: 0 1px 0 rgba(0,0,0,.2); }
.crew.drop-ok { outline: 3px dashed var(--accent); }
.crew.alert-par { border-color: var(--red); box-shadow: 0 0 0 2px var(--red) inset; }
.crew.alert-work { border-color: var(--amber); box-shadow: 0 0 0 2px var(--amber) inset; }
.crew.emergency { background: var(--redbg); border-color: var(--red); animation: flash 1s steps(2) infinite; box-shadow: 0 0 0 3px var(--red) inset; }
.chead { display: flex; align-items: center; gap: 6px; padding: 7px 8px 3px; }
.chead .grip { cursor: grab; touch-action: none; color: var(--muted); font-size: 18px; line-height: 1; padding: 2px 4px; user-select: none; }
.chead .cname { font-weight: 800; font-size: 15px; flex: 1; cursor: pointer; }
.chead[data-drag] { touch-action: none; cursor: grab; }
.ctimes { display: flex; gap: 8px; flex-wrap: wrap; padding: 0 8px; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.ctimes b { color: var(--text); }
.ctimes .warn b { color: var(--amber); } .ctimes .bad b { color: var(--red); }
.cloc { padding: 2px 8px; font-size: 12px; }
.members { display: flex; flex-wrap: wrap; gap: 5px; padding: 6px 8px; }
.mchip { display: inline-flex; align-items: center; gap: 5px; background: var(--chip); border: 1px solid var(--line); border-radius: 99px;
  padding: 3px 9px 3px 6px; font-size: 13px; cursor: pointer; touch-action: none; user-select: none; }
.mchip .dot { width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--muted); flex: none; }
.mchip.in { border-color: var(--red); background: color-mix(in srgb, var(--red) 18%, var(--chip)); }
.mchip.in .dot { background: var(--red); border-color: var(--red); }
.mchip .dept { font-size: 10px; color: var(--muted); font-weight: 700; }
.mchip .ht { font-size: 11px; color: var(--red); font-variant-numeric: tabular-nums; font-weight: 700; }
.cbtns { display: flex; gap: 5px; padding: 0 8px 8px; flex-wrap: wrap; }
.cbtns button { padding: 3px 8px; min-height: 30px; font-size: 12px; }
.cbtns .in { background: var(--red); border-color: var(--red); color: #fff; }
.cbtns .out { background: var(--green); border-color: var(--green); color: #052e12; }
.cbtns .clear { background: var(--green); border-color: var(--green); color: #052e12; }
.empty-crew { font-size: 12px; color: var(--muted); padding: 4px 8px 8px; }

.logpanel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; position: sticky; top: 60px; max-height: calc(100vh - 80px); overflow: auto; }
.logpanel .ev { font-size: 12px; padding: 5px 0; border-bottom: 1px solid var(--line); }
.logpanel .ev time { color: var(--muted); font-variant-numeric: tabular-nums; margin-right: 5px; }
.ev.e-EMERGENCY { color: var(--red); font-weight: 800; }

/* dragging */
body.is-dragging, body.is-dragging * { user-select: none !important; cursor: grabbing !important; }
.drag-ghost { position: fixed; z-index: 1000; pointer-events: none; opacity: .92; box-shadow: var(--shadow); transform: rotate(1.5deg); }
.dragging { opacity: .35; }
.tap-selected { outline: 3px solid var(--accent); }

/* menus, dialogs */
.menu { position: fixed; z-index: 900; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); min-width: 210px; max-height: 70vh; overflow: auto; padding: 5px; }
.menu button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 9px 10px; border-radius: 6px; font-weight: 500; }
.menu button:hover { background: var(--panel2); }
.menu .mh { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; padding: 6px 10px 2px; }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; }
dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 12px; padding: 0; width: min(640px, 96vw); box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(0,0,0,.55); }
dialog .dh { padding: 12px 16px; border-bottom: 1px solid var(--line); font-weight: 800; font-size: 17px; }
dialog .db { padding: 12px 16px; max-height: 68vh; overflow: auto; }
dialog .df { padding: 10px 16px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }
.plist { max-height: 300px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; margin-top: 6px; }
.plist label { display: flex; gap: 8px; align-items: center; margin: 0; padding: 7px 10px; color: var(--text); font-size: 14px; border-bottom: 1px solid var(--line); cursor: pointer; }
.plist label input { width: auto; min-height: 0; }
.plist label.busy { opacity: .5; }
.plist .grp { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding: 6px 10px; background: var(--panel2); }
#toasts { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); z-index: 2000; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { background: var(--panel); border: 1px solid var(--line); border-left: 5px solid var(--accent); padding: 10px 14px; border-radius: 8px; box-shadow: var(--shadow); max-width: 90vw; font-weight: 600; }
.toast.err { border-left-color: var(--red); } .toast.ok { border-left-color: var(--green); }

/* log report */
.report h1 { font-size: 22px; }
.report table { font-size: 13px; }
@media print {
  .topbar, .foot, .noprint, #toasts, .netbanner { display: none !important; }
  body, .card { background: #fff !important; color: #000 !important; }
  .card { border: 0; padding: 0; }
  th, td { border-color: #bbb; color: #000; }
}
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .logpanel { position: static; max-height: 300px; }
}
