:root {
    --bg: #000000;
    --panel: #101008;
    --border: rgba(245, 242, 160, 0.18);
    --text: #edeae2;
    --subtle: rgba(237, 234, 226, 0.55);
    --accent: #f5f2a0;
    --accent-rgb: 232, 228, 74;
    --accent-dark: #e8e44a;
    --accent-glow: 0 0 8px rgba(232, 228, 74, 0.9), 0 0 20px rgba(232, 228, 74, 0.5);
    --ok: #3fb950;
    --fail: #f85149;
    --warn: #e3b341;
    --radius: 4px;
    --input-bg: #000000;
    --button-text: #0a0a05;
    --body-font: 'Roboto Condensed', -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --bg-glow: radial-gradient(ellipse at 50% 0%, rgba(232, 228, 74, 0.05) 0%, transparent 55%);
    --heading-transform: uppercase;
    --heading-spacing: 0.03em;
    --brand-color: var(--accent);
}

/* "Classic view" — the app's original look, before it picked up the
   electricgarage.nz colour scheme, for anyone who finds the dark theme
   annoying to work in all day. Toggled client-side (see the button in
   base.html) and remembered per-browser via localStorage. */
:root[data-theme="classic"] {
    --bg: #f4f5f7;
    --panel: #ffffff;
    --border: #dcdfe4;
    --text: #1c1f24;
    --subtle: #6b7280;
    --accent: #1f6feb;
    --accent-rgb: 31, 111, 235;
    --accent-dark: #14509c;
    --accent-glow: none;
    --ok: #1a7f37;
    --fail: #cf222e;
    --warn: #9a6700;
    --radius: 6px;
    --input-bg: #ffffff;
    --button-text: #ffffff;
    --body-font: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --bg-glow: none;
    --heading-transform: none;
    --heading-spacing: normal;
    --brand-color: var(--text);
}

* { box-sizing: border-box; }

a { color: var(--accent); }
a:hover { color: var(--accent-dark); }

body {
    margin: 0;
    font-family: var(--body-font);
    background-color: var(--bg);
    background-image: var(--bg-glow);
    background-attachment: fixed;
    color: var(--text);
}

.topbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 24px;
    padding: 10px 20px;
    background: var(--panel);
    border-bottom: 1px solid var(--border);
}

.brand { font-weight: 700; letter-spacing: 0.02em; color: var(--brand-color); }
.brand .subtle { font-weight: 400; color: var(--subtle); }

.topbar nav { display: flex; flex-wrap: wrap; gap: 8px 16px; flex: 1; }
.topbar nav a { color: var(--text); text-decoration: none; padding: 6px 4px; text-transform: var(--heading-transform); font-size: 13px; letter-spacing: 0.06em; font-weight: 700; }
.topbar nav a:hover { color: var(--accent); text-shadow: var(--accent-glow); }

.user-info { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; font-size: 14px; }
.user-info a { color: var(--subtle); text-decoration: none; }

.theme-toggle {
    position: fixed;
    bottom: 12px;
    right: 12px;
    z-index: 500;
    background: var(--panel);
    color: var(--subtle);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 6px 10px;
    font-size: 12px;
    font-weight: 400;
    cursor: pointer;
    opacity: 0.8;
}
.theme-toggle:hover { opacity: 1; color: var(--accent); border-color: var(--accent); }
.badge {
    background: rgba(var(--accent-rgb), 0.12);
    color: var(--accent);
    border: 1px solid rgba(var(--accent-rgb), 0.3);
    border-radius: 999px;
    padding: 2px 8px;
    font-size: 12px;
    text-transform: uppercase;
}

.container { max-width: 1000px; margin: 24px auto; padding: 0 20px; }

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

h1 { font-size: 22px; margin-top: 0; text-transform: var(--heading-transform); letter-spacing: var(--heading-spacing); }
h2 { font-size: 18px; text-transform: var(--heading-transform); letter-spacing: var(--heading-spacing); }
h3 { font-size: 15px; color: var(--subtle); text-transform: uppercase; letter-spacing: 0.05em; }

table { width: 100%; border-collapse: collapse; display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); font-size: 14px; }
th { color: var(--subtle); font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; font-size: 12px; }

a.button, button, input[type=submit] {
    display: inline-block;
    background: var(--accent);
    color: var(--button-text);
    border: none;
    border-radius: var(--radius);
    padding: 8px 14px;
    font-size: 14px;
    font-weight: 700;
    text-decoration: none;
    cursor: pointer;
}
a.button:hover, button:hover, input[type=submit]:hover { background: var(--accent-dark); }
a.button.secondary, button.secondary { background: transparent; color: var(--accent); border: 1px solid rgba(var(--accent-rgb), 0.45); }
a.button.secondary:hover, button.secondary:hover { background: rgba(var(--accent-rgb), 0.08); border-color: var(--accent); }
a.button.danger, button.danger { background: var(--fail); color: #fff; }
a.button.danger:hover, button.danger:hover { background: #ff6a62; }
button:disabled { opacity: 0.5; cursor: not-allowed; }

input[type=text], input[type=password], input[type=number], select, textarea {
    width: 100%;
    padding: 8px 10px;
    background: var(--input-bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    /* 16px, not 14 — iOS Safari auto-zooms the page on focus for any input
       below 16px, which is disorienting on a shop-floor phone/tablet. */
    font-size: 16px;
    margin-top: 4px;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }

textarea.autogrow { resize: vertical; min-height: 44px; overflow-y: hidden; font-family: inherit; }

label { display: block; margin-bottom: 12px; font-size: 14px; font-weight: 600; }

.error { color: var(--fail); background: rgba(248, 81, 73, 0.12); border: 1px solid rgba(248, 81, 73, 0.4); padding: 8px 12px; border-radius: var(--radius); margin-bottom: 16px; }
.notice { color: var(--warn); background: rgba(227, 179, 65, 0.12); border: 1px solid rgba(227, 179, 65, 0.4); padding: 8px 12px; border-radius: var(--radius); margin-bottom: 16px; }
:root[data-theme="classic"] .error { background: #ffebe9; border-color: #ffc1bc; }
:root[data-theme="classic"] .notice { background: #fff8c5; border-color: #eac54f; }

.status-pill { border-radius: 999px; padding: 2px 10px; font-size: 12px; font-weight: 600; }
.status-in_progress { background: rgba(227, 179, 65, 0.14); color: var(--warn); }
.status-complete { background: rgba(63, 185, 80, 0.14); color: var(--ok); }
.status-scrapped { background: rgba(248, 81, 73, 0.14); color: var(--fail); }
.status-in_stock { background: rgba(63, 185, 80, 0.14); color: var(--ok); }
.status-installed { background: rgba(var(--accent-rgb), 0.14); color: var(--accent); }
:root[data-theme="classic"] .status-in_progress { background: #fff8c5; }
:root[data-theme="classic"] .status-complete,
:root[data-theme="classic"] .status-in_stock { background: #dafbe1; }
:root[data-theme="classic"] .status-scrapped { background: #ffebe9; }
:root[data-theme="classic"] .status-installed { background: #eef2ff; }

.step-card { border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.step-card.done { border-color: rgba(63, 185, 80, 0.5); background: rgba(63, 185, 80, 0.05); }
:root[data-theme="classic"] .step-card.done { border-color: var(--ok); background: #f8fff9; }
.step-card h3 { margin-top: 0; }

.qc-check { display: flex; align-items: center; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--border); }
.qc-check:last-child { border-bottom: none; }

.row { display: flex; gap: 10px; align-items: flex-end; }
.row > * { flex: 1; }

.flex-between { display: flex; justify-content: space-between; align-items: center; }

.login-wrap { max-width: 360px; margin: 80px auto; }

small.subtle, .subtle { color: var(--subtle); }

.qr-modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.9);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}
.qr-modal.open { display: flex; }
.qr-modal-inner {
    background: var(--panel);
    border: 1px solid var(--border);
    padding: 16px;
    border-radius: var(--radius);
    max-width: 420px;
    width: 90%;
    text-align: center;
}
#qr-video { width: 100%; border-radius: 4px; background: #000; display: block; }
.button.scan { padding: 8px 12px; }

.photo-lightbox-inner {
    background: var(--panel);
    border: 1px solid var(--border);
    padding: 16px;
    border-radius: var(--radius);
    /* Flex items don't shrink below their content's natural size by default
       (min-width: auto) — without an explicit width here, a full-resolution
       phone photo (e.g. 3024x4032) forces this box, and the whole modal,
       wider than the viewport, which mobile browsers "fix" by zooming the
       page out until it fits. width + min-width: 0 gives it a real size to
       shrink to instead of expanding around the image. */
    width: 90%;
    max-width: 900px;
    min-width: 0;
    max-height: 90vh;
    max-height: 90dvh; /* dvh accounts for mobile browser toolbars; vh above is the fallback */
    overflow: auto;
    box-sizing: border-box;
    text-align: center;
}
#photo-lightbox-img {
    display: block;
    max-width: 100%;
    max-height: 75vh;
    max-height: 75dvh;
    width: auto;
    height: auto;
    object-fit: contain;
    border-radius: 4px;
    margin: 0 auto;
}

@media (max-width: 700px) {
    /* Use nearly the whole screen on mobile instead of a small centered
       card — the point is to inspect detail, so give it all the room
       there is rather than a padded box eating into it. */
    .photo-lightbox-inner { width: 97%; padding: 10px; max-height: 96vh; max-height: 96dvh; }
    #photo-lightbox-img { max-height: 82vh; max-height: 82dvh; }
}

.disclosure { margin-top: 12px; }
.disclosure > summary {
    cursor: pointer;
    font-weight: 600;
    list-style: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--accent);
}
.disclosure > summary::-webkit-details-marker { display: none; }
.disclosure > summary::before {
    content: "\25B8";
    display: inline-block;
    transition: transform 0.15s;
}
.disclosure[open] > summary::before { transform: rotate(90deg); }
.disclosure-body {
    margin-top: 12px;
    padding: 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    max-width: 480px;
}

@media (max-width: 700px) {
    .container { padding: 0 12px; margin: 16px auto; }
    .panel { padding: 14px; }

    /* Stack brand/nav/user-info as full-width blocks instead of squeezing
       nav into a narrow leftover flex column, which forced every link onto
       its own line in a tall strip down the right edge. */
    .topbar { flex-direction: column; align-items: stretch; gap: 10px; }
    .topbar nav { flex: none; width: 100%; }
    .user-info { width: 100%; }

    /* .row is used throughout for side-by-side fields (search/filter bars,
       receive/adjust forms, serial+scan rows) — equal-width flex columns get
       too cramped to use comfortably below ~700px, so stack them instead. */
    .row { flex-direction: column; align-items: stretch; gap: 8px; }
    .row > * { flex: none; width: 100%; }

    .qc-check { flex-direction: column; align-items: flex-start; gap: 6px; }

    /* Bigger tap targets — Apple/Google both recommend ~44px minimum. */
    a.button, button, input[type=submit] { padding: 12px 16px; min-height: 44px; }
    input[type=checkbox], input[type=radio] { width: 20px; height: 20px; }

    h1 { font-size: 19px; }

    .topbar { padding: 10px 12px; gap: 6px 14px; }
    .user-info { font-size: 13px; gap: 8px; }
}
