:root {
  --bg: #ffffff;
  --bg-soft: #f7f8f9;
  --border: #e3e5e8;
  --text: #1f2328;
  --text-muted: #6b7280;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --success: #16a34a;
  --warning: #d97706;
  --danger: #dc2626;
  --radius: 8px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 220px;
  background: var(--bg-soft);
  border-right: 1px solid var(--border);
  padding: 20px 0;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.sidebar .brand {
  font-weight: 700;
  font-size: 16px;
  padding: 0 20px 16px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
}
.sidebar .brand small { display: block; font-weight: 400; color: var(--text-muted); font-size: 12px; }
.sidebar nav a {
  display: block;
  padding: 10px 20px;
  color: var(--text);
  font-size: 14px;
}
.sidebar nav a:hover { background: #eef1f4; text-decoration: none; }
.sidebar nav a.active { background: #e7edfd; color: var(--primary-dark); font-weight: 600; }
/* 2026-08-10 — collapsible sidebar sections (native <details>/<summary>,
   same no-JS pattern as Equipment Categories / Roles & Permissions).
   Keeps a long combined nav from forcing the whole sidebar to scroll. */
.sidebar nav details.nav-group summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  padding: 14px 20px 4px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  list-style: none;
  user-select: none;
}
.sidebar nav details.nav-group summary::-webkit-details-marker { display: none; }
.sidebar nav details.nav-group summary::after {
  content: "\25BE";
  font-size: 10px;
  transition: transform 0.15s ease;
}
.sidebar nav details.nav-group:not([open]) summary::after { transform: rotate(-90deg); }
.sidebar nav details.nav-group .nav-group-links { padding-bottom: 4px; }
.sidebar .user-box {
  margin-top: 20px;
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  font-size: 13px;
  color: var(--text-muted);
}
.sidebar .user-box strong { display: block; color: var(--text); font-size: 14px; }

.main { flex: 1; padding: 28px 36px; max-width: 1200px; }

.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.page-header h1 { font-size: 22px; margin: 0; }

.card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 18px;
}

.grid { display: grid; gap: 16px; }
.grid-4 { grid-template-columns: repeat(4, 1fr); }

/* 2026-08-09 audit fix #20 — breadcrumbs on deep (detail/edit) pages */
.breadcrumbs {
  font-size: 13px;
  color: var(--text-muted, #6b7785);
  margin-bottom: 14px;
}
.breadcrumbs a { color: var(--text-muted, #6b7785); text-decoration: none; }
.breadcrumbs a:hover { text-decoration: underline; }
.breadcrumbs .sep { margin: 0 6px; }
.breadcrumbs .current { color: inherit; font-weight: 600; }

/* 2026-08-09 audit fix #18 — Equipment Categories accordion */
.accordion-card summary {
  cursor: pointer;
  font-weight: 600;
  display: flex;
  justify-content: space-between;
  align-items: center;
  list-style-position: outside;
}
.accordion-card summary::-webkit-details-marker { margin-right: 8px; }
.accordion-card[open] summary { margin-bottom: 4px; }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 900px) { .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr 1fr; } }

.stat { text-align: left; }
.stat .num { font-size: 28px; font-weight: 700; }
.stat .label { color: var(--text-muted); font-size: 13px; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); }
th { color: var(--text-muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.03em; }
tr:hover td { background: var(--bg-soft); }

.btn {
  display: inline-block;
  padding: 8px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  font-size: 14px;
}
.btn:hover { background: var(--bg-soft); text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-sm { padding: 5px 10px; font-size: 13px; }

.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 5px; }
.form-group .hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
input, select, textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
  color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); }
.form-row { display: flex; gap: 14px; }
.form-row > * { flex: 1; }

.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}
.badge-open { background: #eef1f4; color: #4b5563; }
.badge-assigned { background: #e0edff; color: #1d4ed8; }
.badge-in_progress { background: #fef3c7; color: #92400e; }
.badge-parts_awaited { background: #fee2e2; color: #b91c1c; }
.badge-completed { background: #dcfce7; color: #15803d; }
.badge-hod_verified { background: #dbeafe; color: #1e40af; }
.badge-urgent { background: #fee2e2; color: #b91c1c; }
.badge-high { background: #ffedd5; color: #c2410c; }
.badge-normal { background: #eef1f4; color: #4b5563; }
.badge-low { background: #f3f4f6; color: #6b7280; }
.badge-low_stock { background: #fee2e2; color: #b91c1c; }
.badge-ok { background: #dcfce7; color: #15803d; }

.flash { padding: 10px 14px; border-radius: 6px; margin-bottom: 14px; font-size: 14px; }
.flash-success { background: #dcfce7; color: #15803d; }
.flash-error { background: #fee2e2; color: #b91c1c; }

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-soft);
}
.login-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 36px 40px;
  width: 340px;
  text-align: center;
}
.login-card h1 { font-size: 18px; margin-bottom: 4px; }
.login-card p { color: var(--text-muted); font-size: 13px; margin-top: 0; margin-bottom: 20px; }
.pin-input {
  font-size: 24px;
  letter-spacing: 8px;
  text-align: center;
  padding: 12px;
}

.filters { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; align-items: center; }
.filters select, .filters input { width: auto; }

.text-muted { color: var(--text-muted); }
.small { font-size: 12px; }
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); margin: 24px 0 10px; }

.tab { padding: 8px 14px; color: var(--text-muted); text-decoration: none; border-bottom: 2px solid transparent; margin-bottom: -1px; font-size: 14px; }
.tab:hover { color: var(--text); text-decoration: none; }
.tab-active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }
.empty-state { color: var(--text-muted); padding: 24px 0; text-align: center; }

.table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* ---------- Mobile ---------- */

.mobile-topbar { display: none; }
.sidebar-overlay { display: none; }

@media (max-width: 860px) {
  .layout { flex-direction: column; }

  .mobile-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--bg-soft);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 30;
  }
  .mobile-topbar .brand { font-weight: 700; font-size: 15px; }
  .nav-toggle {
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 18px;
    padding: 4px 10px;
    cursor: pointer;
  }

  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: 260px;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    z-index: 50;
    overflow-y: auto;
  }
  .layout.nav-open .sidebar { transform: translateX(0); }

  .sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.35);
    z-index: 40;
  }
  .layout.nav-open .sidebar-overlay { display: block; }

  .main { padding: 18px 16px; max-width: 100%; }

  /* No wrapper divs in the existing templates, so make the table
     element itself the horizontally-scrollable region. */
  table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; white-space: nowrap; }
  thead, tbody { display: table; width: 100%; }

  .form-row { flex-direction: column; gap: 0; }

  .btn, .btn-primary { min-height: 42px; display: inline-flex; align-items: center; }

  input, select, textarea { font-size: 16px; } /* avoid iOS zoom-on-focus */
}

/* Per-page Help modal (2026-08-09) — a floating "?" button, present on
   every logged-in page via base.html, opens a centered popup with
   page-specific guidance (help_content.py, keyed by route endpoint). */
.help-fab {
  position: fixed;
  bottom: 22px;
  right: 22px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  border: none;
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,0.25);
  z-index: 45;
  display: flex;
  align-items: center;
  justify-content: center;
}
.help-fab:hover { background: var(--primary-dark); }

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-overlay[hidden] { display: none; }

.modal-box {
  background: var(--bg);
  border-radius: var(--radius);
  max-width: 520px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 8px 32px rgba(0,0,0,0.3);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg);
}
.modal-header h2 { margin: 0; font-size: 17px; }
.modal-close {
  background: transparent;
  border: none;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  color: var(--text-muted);
  padding: 4px 8px;
}
.modal-close:hover { color: var(--text); }
.modal-body { padding: 16px 20px 20px; }
.modal-body p { margin: 0 0 10px; }
.modal-body p:last-child { margin-bottom: 0; }
.modal-body h3 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.03em; color: var(--text-muted); margin: 16px 0 6px; }
.modal-body h3:first-child { margin-top: 0; }
.modal-body ul { margin: 0 0 10px; padding-left: 20px; }
.modal-body li { margin-bottom: 4px; }

@media (max-width: 860px) {
  .help-fab { bottom: 16px; right: 16px; width: 40px; height: 40px; font-size: 16px; }
}
