/* Two themes, both dark. `:root` is the default ("precision"); `data-theme="warm"`
   overrides the palette. Both share structure (radius, shadow, tap-min), so a theme
   changes colour and temperature, never layout. */
:root {
  --bg: #0b0e13;
  --panel: #11161d;
  --panel-raised: #171e27;
  --border: #232b36;
  --text: #e8ecef;
  --muted: #8b96a3;
  --accent: #3fb6e0;
  --accent-ink: #07141c;
  --accent2: #6fc6e8;
  --danger: #e05a5a;
  --ok: #3ecf8e;
  --warn: #e0a33d;
  --field-bg: #0e131a;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.25), 0 4px 16px rgba(0, 0, 0, 0.3);
  --tap-min: 44px;
}

[data-theme="warm"] {
  --bg: #12100c;
  --panel: #1a1610;
  --panel-raised: #221c13;
  --border: #2e2720;
  --text: #ede6da;
  --muted: #a89a84;
  --accent: #e0a33d;
  --accent-ink: #241a06;
  --accent2: #d9b87c;
  --danger: #d96a5a;
  --ok: #7fce7a;
  --warn: #e0a33d;
  --field-bg: #16120c;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, sans-serif;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
}

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

a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent2);
  outline-offset: 2px;
}

header.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 6px 18px;
  padding: 12px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

header.topbar .brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font-weight: 700;
  color: var(--accent);
  font-size: 1.15rem;
  line-height: 1;
  white-space: nowrap;
  letter-spacing: 0.01em;
}
header.topbar .brand:hover { text-decoration: none; opacity: 0.85; }
header.topbar .brand svg { flex: none; display: block; }

/* Brand logo lockup */
@font-face {
  font-family: "Space Grotesk";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("fonts/space-grotesk-600.25ea4a783c12.woff2") format("woff2");
}
@font-face {
  font-family: "Space Grotesk";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("fonts/space-grotesk-700.25ea4a783c12.woff2") format("woff2");
}

header.topbar .brand-text {
  display: flex;
  flex-direction: column;
  gap: 1px;
  line-height: 1.12;
  min-width: 0;
}
header.topbar .brand-credit {
  font-family: "Space Grotesk", "Inter", -apple-system, sans-serif;
  font-weight: 700;
  font-size: 12.5px;
  letter-spacing: 0.01em;
  color: var(--muted);
}
header.topbar .brand-apos {
  color: #6fc6e8;
  text-shadow: 0 0 4px currentColor, 0 0 9px currentColor;
  animation: brand-apos-cycle 9s linear infinite, brand-apos-breathe 3.4s ease-in-out infinite;
}
@keyframes brand-apos-cycle {
  0% { color: #6fc6e8; } 16% { color: #8a86f0; } 33% { color: #c58ae8; }
  50% { color: #e87f9a; } 66% { color: #e0b45a; } 83% { color: #7fdcb0; } 100% { color: #6fc6e8; }
}
@keyframes brand-apos-breathe {
  0%, 100% { opacity: 0.75; }
  50% { opacity: 1; }
}
header.topbar .brand-tagline {
  font-family: "Space Grotesk", "Inter", sans-serif;
  font-weight: 600;
  font-size: 7.5px;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--muted);
  opacity: 0.75;
}
header.topbar .brand-owner {
  font-family: "Space Grotesk", "Inter", -apple-system, sans-serif;
  font-weight: 700;
  font-size: 16px;
  letter-spacing: -0.01em;
  color: var(--text);
  margin-top: 3px;
}

/* The flashing locate dot on the drawer mark */
.brand-dot, .brand-dot-glow { animation: brand-dot-cycle 9s linear infinite; }
.brand-dot-glow { animation: brand-dot-cycle 9s linear infinite, brand-dot-breathe 3.4s ease-in-out infinite; }
@keyframes brand-dot-cycle {
  0% { fill: #6fc6e8; } 16% { fill: #8a86f0; } 33% { fill: #c58ae8; }
  50% { fill: #e87f9a; } 66% { fill: #e0b45a; } 83% { fill: #7fdcb0; } 100% { fill: #6fc6e8; }
}
@keyframes brand-dot-breathe { 0%, 100% { opacity: 0.35; } 50% { opacity: 0.8; } }
@media (prefers-reduced-motion: reduce) {
  .brand-dot, .brand-dot-glow, .brand-apos { animation: none; }
  .brand-dot-glow { opacity: 0.55; }
}

header.topbar nav { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
header.topbar nav a {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 500;
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--panel-raised);
  border: 1px solid var(--border);
  white-space: nowrap;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
header.topbar nav a:hover { color: var(--text); background: #2a2f3a; border-color: var(--muted); text-decoration: none; }

/* "More" nav overflow -- a CSS-only checkbox toggle (no JS, no <details>, so it
   behaves identically in every browser) holding the less-used links. */
.nav-more { position: relative; }
.nav-more-input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.nav-more-summary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 500;
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--panel-raised);
  border: 1px solid var(--border);
  white-space: nowrap;
  user-select: none;
}
.nav-more-summary:hover { color: var(--text); background: #2a2f3a; border-color: var(--muted); }
.nav-more-input:checked ~ .nav-more-summary { color: var(--text); background: #2a2f3a; }
.nav-more-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 20;
  background: var(--panel-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  padding: 6px;
  display: none;
  flex-direction: column;
  min-width: 160px;
}
.nav-more-input:checked ~ .nav-more-menu { display: flex; }
.nav-more-menu a {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--text);
  background: none;
  border: none;
  white-space: nowrap;
}
.nav-more-menu a:hover { background: var(--panel); text-decoration: none; }

/* Inline SVG icons (replacing emoji) align with their surrounding text and match
   the button/nav line height. The brand logo already sets its own size via
   `header.topbar .brand svg`. */
header.topbar nav a { display: inline-flex; align-items: center; gap: 6px; }
header.topbar nav a svg, .btn svg { width: 15px; height: 15px; flex: none; }
h1 svg, h2 svg, p svg { vertical-align: -0.15em; }

main { max-width: 760px; margin: 0 auto; padding: 22px 16px 60px; }

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

h1 { font-size: 1.45rem; margin: 0 0 4px; letter-spacing: -0.01em; }
h2 { font-size: 1.05rem; margin: 0 0 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; }

.muted { color: var(--muted); }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); font-size: 0.95rem; }
tr:last-child td { border-bottom: none; }
th { color: var(--muted); font-weight: 600; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.03em; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: var(--accent2);
  color: var(--accent-ink);
  border: none;
  border-radius: var(--radius-sm);
  padding: 11px 18px;
  min-height: var(--tap-min);
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  transition: filter 0.15s ease, transform 0.05s ease;
}
.btn:hover { filter: brightness(1.08); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn.secondary { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn.secondary:hover { background: var(--panel-raised); border-color: var(--muted); }

input[type=text], input[type=search], input[type=url], input[type=number], input[type=password], input[type=email], select, textarea {
  background: var(--field-bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 11px 13px;
  border-radius: var(--radius-sm);
  font-size: 0.98rem;
  font-family: inherit;
  min-height: var(--tap-min);
}
input[type=text], input[type=search], input[type=url], input[type=password], input[type=email], textarea { width: 100%; }
textarea { min-height: 70px; resize: vertical; }
select { cursor: pointer; }

/* A smaller .btn variant for secondary inline actions (a per-field "save" tick,
   "Remove") that don't need to compete visually with primary actions -- still
   sized well above a comfortable tap target, just not full .btn size. */
.btn-sm { padding: 8px 14px; font-size: 0.88rem; min-height: 40px; }
html.pi-kiosk .btn-sm { padding: 11px 18px; font-size: 1rem; min-height: 48px; }

/* The login page. A narrow column and no topbar, because someone who isn't signed in
   has nowhere to navigate to yet -- so this is the one page that doesn't inherit
   base.html. */
.login-main { max-width: 420px; padding-top: 8vh; }
.login-main h1 { color: var(--accent); }
.login-main form p { margin: 0 0 14px; }
.login-main form label { display: block; margin-bottom: 5px; }

/* "Log out" sits in the More menu alongside links, so it has to look like one while
   still being a button (it posts a form -- see base.html). */
.nav-more-menu form { margin: 0; display: flex; }
.nav-more-menu button {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--text);
  background: none;
  border: none;
  font: inherit;
  text-align: left;
  width: 100%;
  cursor: pointer;
  white-space: nowrap;
}
.nav-more-menu button:hover { background: var(--panel); }

/* One card per "where it lives" location on the part page -- replaces a wide
   table whose cells crammed several small buttons together on one side. */
.location-card {
  background: var(--panel-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin-bottom: 10px;
}
.location-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 10px;
  font-weight: 600;
}
.location-card-fields {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}
.location-card-fields .field-group {
  display: flex;
  align-items: center;
  gap: 8px;
}
.location-card-fields label { color: var(--muted); font-size: 0.85rem; }
.location-card-fields input { width: 70px; }
.location-card-remove { text-align: right; }

.pill {
  display: inline-block;
  background: var(--panel-raised);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 11px;
  font-size: 0.78rem;
  color: var(--muted);
}

.msg-success, .msg-error, .msg-warn, .msg-info, .msg-warning {
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  margin: 0 0 12px;
  font-size: 0.92rem;
  font-weight: 600;
}
.msg-success { color: var(--ok); background: rgba(111, 191, 115, 0.1); border: 1px solid rgba(111, 191, 115, 0.3); }
.msg-error { color: var(--danger); background: rgba(227, 93, 93, 0.1); border: 1px solid rgba(227, 93, 93, 0.3); }
.msg-warn { color: var(--warn); background: rgba(224, 163, 61, 0.1); border: 1px solid rgba(224, 163, 61, 0.3); }
.msg-info { color: var(--accent2); background: rgba(111, 198, 232, 0.1); border: 1px solid rgba(111, 198, 232, 0.3); }
.msg-warning { color: var(--warn); background: rgba(224, 163, 61, 0.1); border: 1px solid rgba(224, 163, 61, 0.3); }

.dup-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 8px 0; }
.dup-row a { color: var(--text); text-decoration: none; }
.dup-row a:hover { text-decoration: underline; }

.label-sheet { display: flex; flex-wrap: wrap; gap: 12px; }
.label-tile {
  border: 1px dashed var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  width: 260px;
  text-align: center;
  background: #fff;
  color: #111;
}
.label-tile .title { font-weight: 700; font-size: 0.95rem; margin-bottom: 2px; }
.label-tile .code { font-family: monospace; font-size: 0.8rem; margin-top: 4px; }

/* Any touch-capable pointer (a phone, a tablet, someone else's touchscreen) --
   bigger targets and type, independent of viewport width. The desktop/mouse
   "web version" is untouched by this block. Kept separate from html.pi-kiosk
   below since Chromium/Wayland on the Pi doesn't reliably report pointer:
   coarse for its actual touchscreen -- .pi-kiosk is the one guaranteed to
   apply on the real device regardless of that. */
@media (pointer: coarse) {
  .btn { padding: 13px 20px; font-size: 1.02rem; }
  header.topbar nav a { padding: 11px 14px; font-size: 1rem; }
  input[type=text], input[type=search], input[type=url], input[type=number], input[type=password], select, textarea {
    padding: 13px 14px;
    font-size: 1.05rem;
  }
  th, td { padding: 13px 8px; }
}

/* The Pi's actual current touchscreen is a big 1920x1200 HDMI panel (swapped
   from an earlier small DSI one -- don't assume a small screen again if it
   changes once more; .pi-kiosk itself, not a screen-size guess, is what's
   reliable long-term). Content was stuck at the same 760px desktop-reading
   width as everyone else, an awkwardly narrow island on a screen this size --
   widen it, and force the same touch-friendly sizing as the (unreliable, on
   this hardware) pointer:coarse block above, guaranteed regardless of pointer
   detection. */
html.pi-kiosk main { max-width: 1400px; }
html.pi-kiosk .btn { padding: 16px 26px; font-size: 1.15rem; }
html.pi-kiosk header.topbar nav a { padding: 14px 18px; font-size: 1.1rem; }
html.pi-kiosk input[type=text], html.pi-kiosk input[type=search], html.pi-kiosk input[type=url],
html.pi-kiosk input[type=number], html.pi-kiosk input[type=password], html.pi-kiosk select, html.pi-kiosk textarea {
  padding: 15px 16px;
  font-size: 1.15rem;
}
html.pi-kiosk th, html.pi-kiosk td { padding: 15px 10px; font-size: 1.05rem; }
html.pi-kiosk h1 { font-size: 1.8rem; }
html.pi-kiosk h2 { font-size: 1.2rem; }

/* .touch-only: shown on any touch device (phone or the Pi) -- e.g. the photo
   capture button, which genuinely works on either. .pi-only: shown only when
   the Pi's local kiosk-helper service answers at page load (see the <script>
   in base.html) -- for things that only function on the Pi specifically
   (on-screen keyboard, exit-to-desktop), regardless of screen size or touch
   capability, so a phone or a differently-sized future display never shows
   them. Both placed after .btn/.card etc so display:none reliably wins the
   cascade regardless of what other classes an element also carries. */
.touch-only, .pi-only { display: none; }
@media (pointer: coarse) {
  .touch-only { display: inline-flex; }
}
html.pi-kiosk .pi-only { display: inline-flex; }

@media print {
  header.topbar, .no-print { display: none !important; }
  body { background: #fff; color: #000; }
  .label-tile { break-inside: avoid; }
}

/* Wide screens (desktop and the Pi's 1920x1200 touchscreen): a fixed left sidebar
   instead of the horizontal top bar. Phones and tablets below 1024px keep the top
   bar with its "More" collapse. Padding and font-size are deliberately left alone
   here, so the pointer:coarse and .pi-kiosk touch-sizing rules still apply. */
@media (min-width: 1024px) {
  body { padding-left: 236px; }
  header.topbar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 236px;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    flex-wrap: nowrap;
    gap: 8px;
    padding: 16px 12px;
    border-bottom: none;
    border-right: 1px solid var(--border);
    overflow-y: auto;
  }
  header.topbar .brand { padding: 4px 10px 12px; }
  header.topbar nav { flex-direction: column; align-items: stretch; gap: 2px; }
  header.topbar nav a {
    border-radius: var(--radius-sm);
    background: none;
    border: none;
    width: 100%;
  }
  header.topbar nav a:hover { background: var(--panel-raised); border: none; }

  /* "More" stays a dropdown in the sidebar too — just styled to match the flat
     sidebar links rather than the pill it uses in the top bar. */
  .nav-more { position: relative; }
  .nav-more-summary {
    border-radius: var(--radius-sm);
    background: none;
    border: none;
    width: 100%;
  }
  .nav-more-summary:hover,
  .nav-more-input:checked ~ .nav-more-summary { background: var(--panel-raised); color: var(--text); }
  .nav-more-menu { left: 0; right: auto; }
}
