:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #dde1e7;
  --text: #1c2129;
  --muted: #5f6b7a;
  --accent: #b42318;
  --accent-hover: #912018;
  --accent-soft: #fdecea;
  --nav-bg: #1d232c;
  --nav-text: #c9d1db;
  --nav-active: #ffffff;
  --green: #127a3e; --green-bg: #e3f5ea;
  --amber: #8a5a00; --amber-bg: #fff3d6;
  --red: #b42318; --red-bg: #fdecea;
  --blue: #1f5fae; --blue-bg: #e6effb;
  --gray: #4b5563; --gray-bg: #eceff3;
  --shadow: 0 8px 30px rgba(15, 23, 42, .18);
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161c; --surface: #1a2028; --surface-2: #222a34; --border: #2f3946; --text: #e6eaf0; --muted: #96a2b2;
    --accent: #e5483b; --accent-hover: #f0675b; --accent-soft: #3a1d1b; --nav-bg: #0d1116;
    --green: #5fd393; --green-bg: #173325; --amber: #f2c25b; --amber-bg: #3a2e12; --red: #ff8a80; --red-bg: #3d1c1a;
    --blue: #8ab8ff; --blue-bg: #1b2a40; --gray: #b8c1cc; --gray-bg: #2a323d; --shadow: 0 8px 30px rgba(0, 0, 0, .5);
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 17px; margin: 0; }
h3 { font-size: 14px; margin: 18px 0 8px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.muted { color: var(--muted); }
.boot { display: grid; place-items: center; height: 100vh; color: var(--muted); }

/* Layout */
.shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar { background: var(--nav-bg); color: var(--nav-text); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px 14px; color: #fff; font-weight: 700; }
.brand img { width: 30px; height: 30px; }
.brand small { display: block; font-weight: 400; color: var(--nav-text); font-size: 12px; }
.nav-group { padding: 6px 10px; }
.nav-group-label { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: #7d8896; padding: 10px 10px 4px; }
.nav a { display: flex; justify-content: space-between; align-items: center; padding: 7px 10px; border-radius: 7px; color: var(--nav-text); text-decoration: none; }
.nav a:hover { background: rgba(255,255,255,.07); color: #fff; }
.nav a.active { background: var(--accent); color: var(--nav-active); }
.nav .count { background: rgba(255,255,255,.18); border-radius: 99px; padding: 0 7px; font-size: 12px; }
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 24px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5; }
.topbar .who { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.menu-btn { display: none; }
.content { padding: 22px 24px 60px; max-width: 1400px; width: 100%; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* Controls */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border); background: var(--surface); padding: 7px 13px; border-radius: 8px; cursor: pointer; text-decoration: none; color: var(--text); white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.danger { color: var(--red); border-color: var(--red); background: transparent; }
.btn.success { background: var(--green); border-color: var(--green); color: #fff; }
.btn.small { padding: 4px 9px; font-size: 13px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.icon-btn { border: 0; background: transparent; font-size: 22px; line-height: 1; cursor: pointer; color: var(--muted); padding: 4px 8px; }
input[type=text], input[type=search], input[type=password], input[type=email], input[type=tel], input[type=number], input[type=date], input[type=url], select, textarea {
  width: 100%; padding: 7px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); min-height: 36px;
}
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus, .btn:focus-visible, .nav a:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
input:disabled, select:disabled, textarea:disabled { background: var(--surface-2); color: var(--text); opacity: 1; }
.toolbar input[type=search] { width: 240px; }
.toolbar select { width: auto; min-width: 160px; }
.check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }

/* Cards / stats */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.card + .card { margin-top: 16px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 10px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; text-decoration: none; color: var(--text); display: block; }
a.stat:hover { border-color: var(--accent); }
.stat .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .05em; }
.stat .value { font-size: 26px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat .sub { color: var(--muted); font-size: 12px; }
.stat.attention { border-color: var(--accent); background: var(--accent-soft); }
.grid-2 { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; }
.alerts { list-style: none; margin: 0; padding: 0; }
.alerts li { display: flex; gap: 10px; align-items: center; padding: 8px 4px; border-bottom: 1px solid var(--border); }
.alerts li:last-child { border-bottom: 0; }
.alerts a { color: var(--text); text-decoration: none; flex: 1; }
.alerts a:hover { text-decoration: underline; }
.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.dot.high { background: var(--red); }
.dot.medium { background: #e0a100; }
.quick { display: grid; gap: 8px; }

/* Tables */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: var(--surface-2); position: sticky; top: 0; white-space: nowrap; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: 0; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
.empty { padding: 30px; text-align: center; color: var(--muted); }
.overdue { color: var(--red); font-weight: 600; }
.due-soon { color: var(--amber); font-weight: 600; }
.low { color: var(--red); font-weight: 700; }

/* Badges */
.badge { display: inline-block; padding: 1px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; background: var(--gray-bg); color: var(--gray); white-space: nowrap; }
.b-in-service, .b-active, .b-pass, .b-completed, .b-approved, .b-low { background: var(--green-bg); color: var(--green); }
.b-out-of-service, .b-fail, .b-emergency, .b-rejected, .b-lost, .b-urgent, .b-closed { background: var(--red-bg); color: var(--red); }
.b-in-shop, .b-in-repair, .b-needs-repair, .b-high, .b-pending, .b-on-leave, .b-waiting-on-vendor, .b-light-duty, .b-under-renovation { background: var(--amber-bg); color: var(--amber); }
.b-in-progress, .b-open, .b-reserve, .b-normal { background: var(--blue-bg); color: var(--blue); }
.role-badge { background: var(--accent-soft); color: var(--accent); }

/* Modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(10, 14, 20, .55); display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow-y: auto; z-index: 50; }
.modal { background: var(--surface); border-radius: 12px; width: 100%; max-width: 720px; box-shadow: var(--shadow); }
.modal.wide { max-width: 980px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.modal-body { padding: 18px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--border); flex-wrap: wrap; }
.modal-foot .spacer { flex: 1; }

/* Forms */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; }
.field label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
.field.span2 { grid-column: 1 / -1; }
.req { color: var(--red); }
.hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
.error-box { background: var(--red-bg); color: var(--red); padding: 9px 12px; border-radius: 8px; margin-bottom: 12px; }
.info-box { background: var(--blue-bg); color: var(--blue); padding: 9px 12px; border-radius: 8px; margin-bottom: 12px; }
.secret { font-family: ui-monospace, Consolas, monospace; font-size: 16px; background: var(--surface-2); padding: 10px; border-radius: 8px; user-select: all; text-align: center; }
.inline-form { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; }
.inline-form .field { flex: 1; min-width: 120px; }

/* Auth */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: linear-gradient(160deg, var(--nav-bg) 0%, #3a1512 100%); }
.auth .card { width: 100%; max-width: 400px; padding: 28px; }
.auth .brand { color: var(--text); padding: 0 0 18px; }
.auth .brand small { color: var(--muted); }
.auth form > * + * { margin-top: 12px; }
.auth .btn { width: 100%; justify-content: center; padding: 10px; }

/* Tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 14px; flex-wrap: wrap; }
.tabs button { border: 0; background: transparent; padding: 9px 14px; cursor: pointer; border-bottom: 2px solid transparent; color: var(--muted); font-weight: 600; }
.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); }

/* Workflow */
.steps { display: flex; gap: 0; margin: 4px 0 16px; flex-wrap: wrap; }
.step { flex: 1; min-width: 140px; padding: 10px 12px; border: 1px solid var(--border); background: var(--surface-2); position: relative; }
.step:first-child { border-radius: 8px 0 0 8px; }
.step:last-child { border-radius: 0 8px 8px 0; }
.step .n { font-size: 11px; color: var(--muted); text-transform: uppercase; }
.step.done { background: var(--green-bg); border-color: var(--green); }
.step.current { background: var(--amber-bg); border-color: #e0a100; }
.step.stopped { background: var(--red-bg); border-color: var(--red); }
.kv { display: grid; grid-template-columns: 180px 1fr; gap: 6px 14px; margin: 0; }
.kv dt { color: var(--muted); font-weight: 600; }
.kv dd { margin: 0; white-space: pre-wrap; }
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { padding: 8px 0 8px 14px; border-left: 2px solid var(--border); margin-left: 4px; }
.timeline .when { color: var(--muted); font-size: 12px; }
.tpl-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }
.tpl-card { text-align: left; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); padding: 12px; cursor: pointer; }
.tpl-card:hover { border-color: var(--accent); }
.tpl-card .cat { font-size: 11px; text-transform: uppercase; color: var(--accent); font-weight: 700; }
.editor-row { display: grid; gap: 8px; align-items: center; padding: 8px; border: 1px solid var(--border); border-radius: 8px; margin-bottom: 8px; background: var(--surface-2); }
.editor-row.field-row { grid-template-columns: 2fr 1fr 2fr auto auto; }
.editor-row.step-row { grid-template-columns: 1.4fr 3fr auto auto; }
.roles-pick { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 13px; }

/* Settings */
.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: 16px; }
.settings-grid .card + .card { margin-top: 0; }
.settings-grid .card > * + * { margin-top: 10px; }
.status-pill { font-size: 12px; }
details.help { background: var(--surface-2); border-radius: 8px; padding: 8px 12px; font-size: 13px; }
details.help summary { cursor: pointer; font-weight: 600; }
details.help ol { padding-left: 18px; margin: 8px 0 0; }

/* Toast */
#toast { position: fixed; bottom: 20px; right: 20px; display: grid; gap: 8px; z-index: 100; }
.toast { background: var(--nav-bg); color: #fff; padding: 10px 16px; border-radius: 8px; box-shadow: var(--shadow); max-width: 420px; }
.toast.err { background: var(--red); }

@media (max-width: 960px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: 260px; transform: translateX(-100%); transition: transform .2s; z-index: 40; }
  .shell.nav-open .sidebar { transform: none; box-shadow: var(--shadow); }
  .menu-btn { display: inline-flex; }
  .grid-2 { grid-template-columns: 1fr; }
  .content { padding: 16px; }
  .topbar { padding: 10px 16px; }
  .form-grid { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 1fr; }
  .kv dd { margin-bottom: 8px; }
  .toolbar input[type=search] { width: 100%; }
  .settings-grid { grid-template-columns: 1fr; }
  .editor-row.field-row, .editor-row.step-row { grid-template-columns: 1fr; }
  .topbar .who .badge, .topbar .who .muted { display: none; }
}
