/* Delta 3K Service Assistant: styles. Phone first, iOS-like: a navy top bar,
   a light grey background and white rounded cards with big code numbers. */

:root {
  --bg: #eef2f5;
  --card: #ffffff;
  --card-line: #dde3ea;
  --text: #16222d;
  --muted: #5b6875;
  --bar-bg: #13202d;
  --bar-text: #ffffff;
  --pill-bg: #f2c45a;
  --pill-text: #2b1f00;
  --notice-bg: #fff4d6;
  --notice-text: #5c4400;
  --draft-bg: #fbe3c8;
  --draft-text: #8a3c00;
  --draft-line: #f0b97f;
  --error-bg: #fde2e1;
  --error-text: #8a1c14;
  --chip-on-bg: #2f6b88;
  --chip-on-text: #ffffff;
  --remote: #2f6b88;
  --onsite: #2e7d4f;
  --partium-bg: #539987;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1720;
    --card: #1a2430;
    --card-line: #2a3644;
    --text: #e8eef3;
    --muted: #9aa8b5;
    --bar-bg: #0a1118;
    --bar-text: #ffffff;
    --pill-bg: #e0b24a;
    --pill-text: #1f1600;
    --notice-bg: #33290a;
    --notice-text: #ffe08a;
    --draft-bg: #4a2a0c;
    --draft-text: #ffc58a;
    --draft-line: #7a4a1a;
    --error-bg: #4a1512;
    --error-text: #ffb4ab;
    --chip-on-bg: #5aa3c7;
    --chip-on-text: #0b141c;
    --remote: #3d86ab;
    --onsite: #3f9a64;
  }
}

/* Theme chosen in Settings: Dark always, Light always, otherwise the phone decides */
:root[data-theme="dark"] {
    --bg: #0f1720;
    --card: #1a2430;
    --card-line: #2a3644;
    --text: #e8eef3;
    --muted: #9aa8b5;
    --bar-bg: #0a1118;
    --bar-text: #ffffff;
    --pill-bg: #e0b24a;
    --pill-text: #1f1600;
    --notice-bg: #33290a;
    --notice-text: #ffe08a;
    --draft-bg: #4a2a0c;
    --draft-text: #ffc58a;
    --draft-line: #7a4a1a;
    --error-bg: #4a1512;
    --error-text: #ffb4ab;
    --chip-on-bg: #5aa3c7;
    --chip-on-text: #0b141c;
    --remote: #3d86ab;
    --onsite: #3f9a64;
   --stock-bg: #1c3a25; --stock-text: #9fdcad; }
/* color-scheme tells the browser to draw its own controls (scrollbars, inputs) to match */
:root { color-scheme: light dark; }
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  /* -apple-system = SF Pro, the iPhone's own font; the others for Windows/Android */
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 18px;
  line-height: 1.35;
  -webkit-tap-highlight-color: transparent;
}

/* Top bar. env(safe-area-inset-top) is the height of the iPhone notch area. */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--bar-bg);
  color: var(--bar-text);
  padding: calc(14px + env(safe-area-inset-top)) 20px 14px;
  min-height: 68px;
  position: sticky;           /* stays at the top while the page scrolls */
  top: 0;
  z-index: 10;
}

/* Back button in the top bar, styled like the iOS Settings back button */
.nav-back {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font: inherit;
  font-size: 17px;
  font-weight: 600;
  color: var(--bar-text);
  background: rgba(255, 255, 255, 0.16);
  border: none;
  border-radius: 999px;
  padding: 6px 16px 6px 10px;
  min-height: 40px;
  cursor: pointer;
}
.nav-back:active { background: rgba(255, 255, 255, 0.28); }
.nav-back-chevron { font-size: 28px; line-height: 0.8; margin-top: -3px; }
.nav-back[hidden], .app-name[hidden] { display: none; }

.app-name {
  margin: 0;
  font-size: 24px;
  font-weight: 800;
  letter-spacing: -0.3px;
}

.pill {
  background: var(--pill-bg);
  color: var(--pill-text);
  font-size: 14px;
  font-weight: 700;
  padding: 5px 12px;
  border-radius: 999px;     /* fully rounded ends */
  white-space: nowrap;
}

.notice {
  margin: 0;
  background: var(--notice-bg);
  color: var(--notice-text);
  padding: 8px 20px;
  font-size: 14px;
  font-weight: 600;
}

main {
  /* bottom: room for the tab bar (about 64px) so it never covers the last card */
  padding: 12px 16px calc(96px + env(safe-area-inset-bottom));
  max-width: 720px;
  margin: 0 auto;
}

.build-info, .count { color: var(--muted); font-size: 14px; margin: 4px 4px; }

.warning, .error {
  padding: 12px 14px;
  border-radius: 14px;
  font-weight: 600;
}
.warning { background: var(--notice-bg); color: var(--notice-text); }
/* "A new version is ready" with its Update button (hosted app, decision 019) */
#update-ready .paste-button { display: block; margin: 10px 0 0; }
.error { background: var(--error-bg); color: var(--error-text); }

/* ---------- search ---------- */

.search { margin: 12px 0 8px; }

#search, #part-search {
  width: 100%;
  font: inherit;
  font-size: 17px;            /* 16px or more: iPhone Safari does not zoom in */
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--card-line);
  border-radius: 14px;
  padding: 14px 16px;
  -webkit-appearance: none;
  appearance: none;
}
#search:focus, #part-search:focus { outline: 2px solid var(--chip-on-bg); outline-offset: 1px; }

/* One row: each switch is as wide as its word, then all stretch to fill the row */
.switches {
  display: flex;
  flex-wrap: nowrap;
  gap: 6px;
  margin-top: 10px;
  max-width: 560px;
}
/* Very narrow screens (first iPhone SE): two rows rather than cut-off words */
@media (max-width: 359px) {
  .switches { flex-wrap: wrap; }
}

.chip {
  flex: 1 1 auto;
  min-width: 0;
  font: inherit;
  font-size: clamp(12px, 3.7vw, 15px);   /* adapts to the screen width */
  font-weight: 600;
  min-height: 38px;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--card-line);
  background: var(--card);
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
}
/* "On" = filled dark, "off" = empty outline: clear even in black and white */
.chip[aria-pressed="true"] {
  background: var(--chip-on-bg);
  border-color: var(--chip-on-bg);
  color: var(--chip-on-text);
}
.chip-exact[aria-pressed="false"] { border-style: dashed; }

.search-hint {
  margin: 4px 0 8px;
  padding: 10px 14px;
  border-radius: 14px;
  background: var(--notice-bg);
  color: var(--notice-text);
  font-size: 15px;
  font-weight: 600;
}

.found-in { color: var(--muted); font-size: 14px; }

/* ---------- results ---------- */

.fault-list { list-style: none; padding: 0; margin: 12px 0 0; }

/* One card per fault code; the whole card is a link */
.fault-item {
  color: inherit;
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 76px;           /* comfortable to tap, even with gloves */
  padding: 14px 16px;
  margin-bottom: 12px;
  background: var(--card);
  border: 1px solid var(--card-line);
  border-radius: 16px;
}

.code {
  flex: 0 0 auto;
  font-size: 26px;
  font-weight: 800;
  letter-spacing: -0.5px;
  min-width: 3.4em;
  font-variant-numeric: tabular-nums;
}

/* Title and badge stacked in one column. min-width: 0 allows the column to
   shrink and wrap its text instead of pushing past the card's edge. */
.text {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
}

.title { font-size: 18px; overflow-wrap: anywhere; }

.chevron {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 28px;
  line-height: 1;
}

.badge-draft {
  background: var(--draft-bg);
  color: var(--draft-text);
  border: 1px solid var(--draft-line);
  font-size: 13px;
  font-weight: 700;
  padding: 2px 9px;
  border-radius: 999px;
  white-space: nowrap;
}

/* Small pills under the title: Reset / Deac levels and Draft */
.pills { display: flex; flex-wrap: wrap; gap: 6px; }
.level-pill {
  font-size: 13px;
  font-weight: 600;
  padding: 2px 9px;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--card-line);
  color: var(--muted);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.level-pill-draft { border-color: var(--draft-line); color: var(--draft-text); }

/* ---------- detail view ---------- */

.detail-head { margin: 4px 0 12px; }
.detail-code {
  font-size: 40px;
  font-weight: 800;
  letter-spacing: -0.8px;
  line-height: 1.1;
}
.detail-title { font-size: 22px; font-weight: 700; margin: 4px 0 0; }

.draft-banner {
  margin: 0 0 12px;
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--draft-bg);
  color: var(--draft-text);
  border: 1px solid var(--draft-line);
  font-weight: 700;
}

.levels { display: flex; gap: 12px; margin-bottom: 16px; }
.level {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  background: var(--card);
  border: 1px solid var(--card-line);
  border-radius: 14px;
  padding: 10px 14px;
}
.level-label { color: var(--muted); font-size: 14px; }
.level-value { font-size: 24px; font-weight: 800; font-variant-numeric: tabular-nums; }
.level-unverified {
  font-size: 12px;
  font-weight: 700;
  color: var(--draft-text);
  background: var(--draft-bg);
  border: 1px solid var(--draft-line);
  border-radius: 999px;
  padding: 1px 8px;
}
.levels-note { color: var(--muted); font-size: 13px; margin: 6px 4px 12px; }

.detail-section {
  background: var(--card);
  border: 1px solid var(--card-line);
  border-radius: 16px;
  padding: 12px 16px;
  margin-bottom: 12px;
}
/* Section name as a pill, in the manual's wording */
.section-pill {
  display: inline-block;
  margin: 0 0 4px;
  font-size: 14px;
  font-weight: 700;
  padding: 3px 12px;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--card-line);
  color: var(--muted);
}

/* Remote and onsite: separate cards, each with a label and its own colour edge */
.detail-section.remote { border-left: 6px solid var(--remote); }
.detail-section.onsite { border-left: 6px solid var(--onsite); }
.remote .section-pill { background: var(--remote); border-color: var(--remote); color: #ffffff; }
.onsite .section-pill { background: var(--onsite); border-color: var(--onsite); color: #ffffff; }

.detail-text { margin: 6px 0 0; white-space: pre-line; } /* keeps the manual's line breaks */

.items { margin: 6px 0 0; padding-left: 22px; }
.items li { margin: 6px 0; }
.lead-in { list-style: none; margin-left: -22px; font-weight: 700; }

.none { margin: 6px 0 0; font-style: italic; color: var(--muted); }

.source { color: var(--muted); font-size: 14px; margin: 4px 4px 0; }
.source p { margin: 2px 0; }

/* ---------- related codes ---------- */

.related-list { list-style: none; padding: 0; margin: 6px 0 0; }
.related { padding: 8px 0; border-top: 1px solid var(--card-line); }
.related:first-child { border-top: none; }

.related-link, .related-missing {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;           /* Apple's minimum touch target */
  color: inherit;
  text-decoration: none;
}
.related-code {
  flex: 0 0 auto;
  font-size: 19px;
  font-weight: 800;
  min-width: 3.4em;
  font-variant-numeric: tabular-nums;
}
.related-title { font-size: 17px; }
.related-missing .related-code { color: var(--muted); }
.missing-pill {
  font-size: 13px;
  font-weight: 600;
  padding: 2px 9px;
  border-radius: 999px;
  border: 1px dashed var(--card-line);
  color: var(--muted);
}

.mentions { margin: 2px 0 0; }
.mention { margin: 2px 0; font-size: 15px; color: var(--muted); }
.mention-field { font-weight: 700; }
.mention-line { font-style: italic; }

.auto-note { margin: 8px 0 0; font-size: 13px; color: var(--muted); }

/* ---------- fault set ---------- */

.set-entry {
  display: flex;
  align-items: center;
    gap: 4px 10px;
  min-height: 52px;
  margin: 4px 0 8px;
  padding: 10px 16px;
  background: var(--card);
  border: 1px solid var(--card-line);
  border-radius: 16px;
  color: inherit;
  text-decoration: none;
}
.set-entry-text { color: var(--muted); font-size: 15px; flex: 1 1 auto; min-width: 0; }
.set-entry-label, .set-entry .chevron { flex: 0 0 auto; white-space: nowrap; }
.set-entry-label { font-weight: 700; color: var(--chip-on-bg); }

.set-toggle {
  font: inherit;
  font-size: 16px;
  font-weight: 600;
  width: 100%;
  min-height: 46px;
  margin: 0 0 12px;
  border-radius: 14px;
  border: 1px dashed var(--chip-on-bg);
  background: var(--card);
  color: var(--chip-on-bg);
  cursor: pointer;
}
.set-toggle-on { border-style: solid; background: var(--chip-on-bg); color: var(--chip-on-text); }

.set-title { font-size: 26px; font-weight: 800; margin: 8px 0 4px; }
.set-intro { color: var(--muted); font-size: 15px; margin: 0 0 12px; }

.note {
  width: 100%;
  font: inherit;
  font-size: 16px;            /* 16px or more: iPhone Safari does not zoom in */
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--card-line);
  border-radius: 12px;
  padding: 10px 12px;
  resize: vertical;
}
.set-note { margin-bottom: 12px; }

.set-add { display: flex; gap: 8px; }
.set-input {
  flex: 1 1 auto;
  min-width: 0;
  font: inherit;
  font-size: 17px;
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--card-line);
  border-radius: 14px;
  padding: 12px 14px;
}
.add-button {
  font: inherit;
  font-weight: 700;
  min-width: 72px;
  border: none;
  border-radius: 14px;
  background: var(--chip-on-bg);
  color: var(--chip-on-text);
  cursor: pointer;
}
.set-message { color: var(--muted); font-size: 14px; margin: 6px 4px 0; min-height: 1em; }

.set-list { list-style: none; padding: 0; margin: 12px 0 0; }
.set-item {
  background: var(--card);
  border: 1px solid var(--card-line);
  border-radius: 16px;
  padding: 12px 14px;
  margin-bottom: 12px;
}
.set-item-top { display: flex; align-items: center; gap: 12px; }
.set-code-link { flex: 1 1 auto; min-width: 0; color: inherit; text-decoration: none; }
.set-code { font-size: 21px; font-weight: 800; font-variant-numeric: tabular-nums; }
.set-tools { display: flex; gap: 4px; flex: 0 0 auto; }
.tool-button {
  font: inherit;
  font-size: 17px;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: 1px solid var(--card-line);
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
}
.tool-button:disabled { opacity: 0.35; cursor: default; }
.set-pills { margin: 8px 0; }

.shared-head { font-size: 15px; margin: 12px 0 2px; }
.shared-remote { color: var(--remote); }
.shared-onsite { color: var(--onsite); }
.shared-line { margin: 0; }
.shared-codes { margin: 2px 0 0; font-size: 14px; font-weight: 700; color: var(--muted); }

.clear-button {
  font: inherit;
  font-size: 16px;
  width: 100%;
  min-height: 46px;
  margin-top: 4px;
  border-radius: 14px;
  border: 1px solid var(--error-text);
  background: transparent;
  color: var(--error-text);
  cursor: pointer;
}

/* ---------- ticks: cross off causes and remedies ---------- */

.tick-list { list-style: none; padding-left: 0; }
.tick-list .lead-in { margin-left: 0; padding: 6px 0 0; }
.tick-row { margin: 0; }

/* The whole line is the button: easy to hit with gloves */
.tick {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  width: 100%;
  min-height: 44px;           /* Apple's minimum touch target */
  padding: 8px 0;
  font: inherit;
  color: inherit;
  text-align: left;
  background: none;
  border: none;
  cursor: pointer;
}
.tick-box {
  flex: 0 0 24px;
  height: 24px;
  margin-top: 1px;
  border-radius: 999px;
  border: 2px solid var(--muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 800;
}
.tick[aria-pressed="true"] .tick-box {
  background: var(--chip-on-bg);
  border-color: var(--chip-on-bg);
  color: var(--chip-on-text);
}
.remote .tick[aria-pressed="true"] .tick-box { background: var(--remote); border-color: var(--remote); color: #fff; }
.onsite .tick[aria-pressed="true"] .tick-box { background: var(--onsite); border-color: var(--onsite); color: #fff; }
.tick[aria-pressed="true"] .tick-box::after { content: "✓"; }
/* Crossed off but still readable: never hidden */
.tick[aria-pressed="true"] .tick-text { text-decoration: line-through; opacity: 0.55; }

.tick-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 4px;
  font-size: 13px;
  color: var(--muted);
}
.tick-reset {
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  color: var(--chip-on-bg);
  background: none;
  border: 1px solid var(--card-line);
  border-radius: 999px;
  padding: 4px 12px;
  min-height: 32px;
  cursor: pointer;
}
.tick-reset[hidden] { display: none; }

/* ---------- tab bar (Alarms / Parts) ---------- */

/* Fixed to the bottom of the screen; env(safe-area-inset-bottom) is the
   height of the iPhone's home bar, so the buttons sit above it. */
.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  display: flex;
  background: var(--card);
  border-top: 1px solid var(--card-line);
  padding: 4px 0 calc(4px + env(safe-area-inset-bottom));
}
.tabbar[hidden] { display: none; }

.tab {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 52px;           /* easy to hit with gloves */
  color: var(--muted);
  text-decoration: none;
  font-size: 12px;
  font-weight: 600;
}
.tab svg { width: 26px; height: 26px; }
/* aria-current="page" marks the open tab (screen readers announce it too) */
.tab[aria-current="page"] { color: var(--chip-on-bg); }

/* ---------- parts ---------- */

.part-sap {
  color: var(--muted);
  font-size: 15px;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;     /* a 15-character number may wrap on narrow phones */
}

.more { color: var(--muted); font-size: 14px; text-align: center; margin: 4px 0 12px; }

.part-sap-big {
  font-size: 30px;
  font-weight: 800;
  letter-spacing: -0.5px;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}
.aliases { color: var(--muted); font-size: 15px; margin: 4px 0 0; }

/* One card per store, side by side */
.stores { display: flex; gap: 12px; margin-bottom: 12px; }
@media (max-width: 359px) {
  .stores { flex-direction: column; }
}
.store-card {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  background: var(--card);
  border: 1px solid var(--card-line);
  border-radius: 14px;
  padding: 10px 14px;
}
.store-name { color: var(--muted); font-size: 14px; font-weight: 700; }
.store-qty { font-size: 26px; font-weight: 800; font-variant-numeric: tabular-nums; }
.store-qty-zero { color: var(--muted); }
.store-label { color: var(--muted); font-size: 13px; margin-top: 6px; }
.store-shelf { font-size: 20px; font-weight: 700; overflow-wrap: anywhere; }
.store-none { font-size: 15px; font-style: italic; color: var(--muted); }

/* ---------- demo BOM (Contains / Part of) ---------- */

.assembly-pill { background: var(--bar-bg); border-color: var(--bar-bg); color: var(--bar-text); }
.bom-qty { color: var(--text); font-weight: 700; }
/* Children of an assembly, indented under it on a fault's Parts section */
.bom-children {
  margin: 0 0 4px 14px;
  padding-left: 12px;
  border-left: 3px solid var(--card-line);
}

/* ---------- tiles (parts list, part screen, a fault's Parts section) ---------- */

:root { --stock-bg: #e3f3e6; --stock-text: #2e6b3c; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --stock-bg: #1c3a25; --stock-text: #9fdcad; }
}

.tile-wrap { margin-bottom: 12px; }
.tile {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 84px;
  padding: 12px 12px 12px 6px;
  background: var(--card);
  border: 1px solid var(--card-line);
  border-radius: 18px;
}
/* ▸ / ▾ on assemblies; an empty space of the same width on other parts,
   so all names line up */
.tile-toggle, .tile-toggle-space { flex: 0 0 30px; align-self: stretch; }
.tile-toggle {
  font: inherit;
  font-size: 15px;
  color: var(--muted);
  background: none;
  border: none;
  border-radius: 10px;
  cursor: pointer;
}
.tile-toggle:active { background: var(--bg); }

/* The tappable middle: name, SAP number, pills */
.tile-main {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  color: inherit;
  text-decoration: none;
}
/* Part names look like alarm titles (.title): same size, normal weight */
.tile-title { font-size: 18px; line-height: 1.2; overflow-wrap: anywhere; }
/* Between the part name (18 px) and the stock pills (13 px) */
.tile .part-sap { font-size: 14px; }

/* Copy and + : big square buttons, easy with gloves */
.tile-actions { flex: 0 0 auto; display: flex; gap: 8px; }
.tile-button {
  font: inherit;
  font-size: 16px;
  font-weight: 700;
  min-width: 56px;
  height: 56px;
  padding: 0 8px;
  border-radius: 14px;
  border: 2px solid var(--card-line);
  background: var(--card);
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
}
.tile-button:active { background: var(--bg); }
.tile-button.copied { border-color: var(--onsite); color: var(--onsite); }
.tile-plus { font-size: 20px; }
.tile-plus.in-list {
  font-size: 15px;
  background: var(--chip-on-bg);
  border-color: var(--chip-on-bg);
  color: var(--chip-on-text);
}

/* Children of an assembly, indented under it with a line on the left */
.tile-children {
  margin: 10px 0 0 22px;
  padding-left: 12px;
  border-left: 3px solid var(--card-line);
}
.tile-children[hidden] { display: none; }

.stock-pill { white-space: normal; }
.stock-pill.in-stock { background: var(--stock-bg); border-color: var(--stock-bg); color: var(--stock-text); }
.assembly-pill { background: var(--bg); border-color: var(--card-line); color: var(--muted); }
.bom-qty { color: var(--text); font-weight: 700; }

.tile-section { margin: 0 0 16px; }
.tile-section > .section-pill { margin: 4px 0 10px; }
.tile-missing { gap: 12px; }

/* Very narrow phones: smaller buttons so the name keeps some room */
@media (max-width: 359px) {
  .tile-button { min-width: 46px; height: 48px; font-size: 14px; }
}

/* ---------- part screen buttons ---------- */

.part-actions, .material-actions { display: flex; gap: 10px; margin: 0 0 12px; }
.wide-button {
  flex: 1 1 0;
  font: inherit;
  font-size: 16px;
  font-weight: 700;
  min-height: 52px;
  padding: 8px 12px;
  border-radius: 14px;
  border: 2px solid var(--card-line);
  background: var(--card);
  color: var(--text);
  cursor: pointer;
}
.wide-button.copied { border-color: var(--onsite); color: var(--onsite); }
.wide-plus { border-color: var(--chip-on-bg); color: var(--chip-on-bg); }
.wide-plus.in-list, .material-actions .wide-plus {
  background: var(--chip-on-bg);
  color: var(--chip-on-text);
}

/* ---------- material list ---------- */

.material-note { margin-top: 12px; }
.material-list { list-style: none; padding: 0; margin: 12px 0; }
.material-row {
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
  padding: 12px 14px;
  margin-bottom: 12px;
}
.qty { display: flex; align-items: center; gap: 8px; }
.qty-step { font-size: 22px; min-width: 52px; height: 52px; }
.qty-input {
  width: 88px;
  height: 52px;
  font: inherit;
  font-size: 20px;            /* 16px or more: iPhone Safari does not zoom in */
  font-weight: 800;
  text-align: center;
  color: var(--text);
  background: var(--bg);
  border: 2px solid var(--card-line);
  border-radius: 12px;
}
.qty-unit { flex: 1 1 auto; color: var(--muted); font-weight: 700; }
.qty-remove { color: var(--error-text); }

/* Pills inside tiles may wrap their text instead of running under the buttons */
.tile .level-pill { white-space: normal; }
.tile .pills { max-width: 100%; }

/* Phone width: Copy above +, so the name gets the room */
@media (max-width: 480px) {
  .tile-actions { flex-direction: column; gap: 6px; }
  .tile-button { min-width: 64px; height: 44px; }
  .tile-plus { font-size: 18px; }
  .tile-children { margin-left: 10px; padding-left: 8px; }
  .tile-toggle, .tile-toggle-space { flex-basis: 24px; }
  /* the material list keeps its big row buttons */
  .material-row .tile-button { height: 52px; min-width: 52px; }
}


/* ---------- text size (Settings) ---------- */
/* zoom scales everything in the content at once; the top bar and tab bar stay the same */
main { zoom: var(--text-zoom, 1); }

/* ---------- top bar: settings gear ---------- */

.topbar-right { display: flex; align-items: center; gap: 10px; }
.settings-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;                /* Apple's minimum touch target */
  height: 44px;
  border-radius: 999px;
  color: var(--bar-text);
  background: rgba(255, 255, 255, 0.12);
}
.settings-button:active { background: rgba(255, 255, 255, 0.26); }
.settings-button svg { width: 24px; height: 24px; }
.settings-button[hidden] { display: none; }
.settings-chips { flex-wrap: wrap; }

/* ---------- tab bar: the whole open tab is lit ---------- */

.tabbar { padding-top: 0; }
.tab {
  position: relative;
  min-height: 58px;
  padding: 6px 4px 4px;
  font-size: 13px;
  text-align: center;
  line-height: 1.15;
}
.tab[aria-current="page"] { background: var(--bg); }
/* The bar on top of the open tab, as in the mockup */
.tab[aria-current="page"]::before {
  content: "";
  position: absolute;
  top: 0;
  left: 16%;
  right: 16%;
  height: 4px;
  border-radius: 0 0 4px 4px;
  background: var(--chip-on-bg);
}
.tab:active { background: var(--bg); }

/* The app name stays on one line next to the pill and the gear */
.app-name { white-space: nowrap; font-size: clamp(18px, 5.4vw, 24px); }
.topbar { padding-left: 16px; padding-right: 12px; }
/* Very narrow phones: the gear always fits; the pill shortens with "…" if it must */
.topbar-right { min-width: 0; flex: 0 1 auto; }
.topbar-right .pill { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.settings-button { flex: 0 0 44px; }
.app-name { font-size: clamp(16px, 5vw, 24px); flex: 0 0 auto; }


/* ---------- sticky search and keyboard ---------- */

/* The search bar scrolls up to the top bar, then stays there. It sits inside the
   zoomed content (Settings > Text size), so the top bar height is divided by the
   zoom to land exactly under it. The background hides the results scrolling under it. */
.sticky-search {
  position: -webkit-sticky;   /* older Safari */
  position: sticky;
  top: calc(var(--topbar-h, 72px) / var(--text-zoom, 1));
  z-index: 5;
  background: var(--bg);
  box-shadow: 0 6px 8px -8px rgba(0, 0, 0, 0.25);   /* a soft edge over the results */
  margin: 0 -16px 8px;
  padding: 10px 16px 10px;
}

/* The tab bar is moved by app.js (transform) to stay at the bottom of the screen
   while the keyboard is open; will-change keeps that move smooth on phones */
.tabbar { will-change: transform; }


/* ---------- clear button (✕) in the search fields ---------- */

.search-field { position: relative; }
.search-field input { padding-right: 56px; }     /* room for the ✕ */
/* Browsers' own small ✕ (Chrome, Edge) is switched off, so there is only one */
.search-field input::-webkit-search-cancel-button { -webkit-appearance: none; appearance: none; display: none; }

.search-clear {
  position: absolute;
  right: 4px;
  /* top + bottom + auto margin: centred on whole pixels,
     no half-pixel shift that could blur or offset it */
  top: 0;
  bottom: 0;
  margin: auto 0;
  width: 48px;                /* easy to hit, even with gloves */
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: none;
  background: none;
  cursor: pointer;
}
.search-clear[hidden] { display: none; }
/* Circle and cross are one drawing, like Apple's own symbol: an 18px circle with
   a cross about a third as wide, so they can never shift apart */
.clear-icon { display: block; width: 18px; height: 18px; }
.clear-icon circle { fill: var(--text); }
.clear-icon path {
  fill: none;
  stroke: var(--card);
  stroke-width: 2;            /* in the 20-unit drawing: 1.8px on screen */
  stroke-linecap: round;
}


/* ---------- the pill as a button, and the bottom sheet (placeholders) ---------- */

.pill-button {
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  border: none;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  max-width: 100%;
  min-height: 32px;
  cursor: pointer;
}
.pill-button[hidden] { display: none; }
.pill-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.pill-chevron { flex: 0 0 auto; font-size: 11px; opacity: 0.75; }

/* Camera button in the parts search field; the ✕ moves left of it */
.search-field.has-camera input { padding-right: 100px; }
.search-field.has-camera .search-clear { right: 52px; }   /* camera: right 4px + 48px wide */
.search-camera {
  position: absolute;
  right: 4px;
  top: 0;
  bottom: 0;
  margin: auto 0;
  width: 48px;                /* easy to hit, even with gloves */
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: none;
  background: none;
  color: var(--muted);
  cursor: pointer;
}
.search-camera svg { width: 24px; height: 24px; }

.sheet {
  border: none;
  padding: 0;
  margin: auto 0 0;           /* sits at the bottom of the screen */
  width: 100%;
  max-width: 100%;
  background: transparent;
  color: var(--text);
}
.sheet::backdrop { background: rgba(0, 0, 0, 0.45); }
.sheet-panel {
  max-width: 560px;
  margin: 0 auto;
  background: var(--card);
  border-radius: 20px 20px 0 0;
  padding: 18px 18px calc(18px + env(safe-area-inset-bottom));
}
.sheet-title { font-size: 20px; font-weight: 800; margin: 0 0 12px; }
.sheet-option {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 52px;
  padding: 10px 14px;
  border-radius: 14px;
  background: var(--bg);
  border: 2px solid var(--chip-on-bg);
}
.sheet-check { flex: 0 0 auto; font-weight: 800; color: var(--chip-on-bg); font-size: 18px; }
.sheet-option-name { display: block; font-weight: 700; }
.sheet-option-detail { display: block; font-size: 14px; color: var(--muted); }
.sheet-later {
  margin-top: 8px;
  min-height: 48px;
  display: flex;
  align-items: center;
  padding: 10px 14px;
  border-radius: 14px;
  border: 1px dashed var(--card-line);
  color: var(--muted);
  font-size: 15px;
}
.sheet-note { color: var(--muted); font-size: 14px; margin: 12px 2px 0; }
/* Replace and Remove in the data sheets (decision 019): clear of the rows above */
.sheet-data-buttons { margin-top: 20px; }
.sheet-data-buttons .paste-button:last-child { margin-bottom: 0; }
/* A link that looks like a button, inside a sheet (Partium, decision 014) */
.sheet-action {
  display: block;
  margin: 4px 0 0;
  padding: 14px 16px;
  border-radius: 12px;
  background: var(--partium-bg);
  color: #ffffff;
  font-size: 19px;
  font-weight: 700;
  text-align: center;
  text-decoration: none;
}
/* List of fault sets (decision 015) */
.sets-new { display: block; width: 100%; margin: 4px 0 0; padding: 12px 16px; }
.sets-list { list-style: none; margin: 16px 0 0; padding: 0; display: grid; gap: 10px; }
.sets-card {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px;
  background: var(--card); border: 1px solid var(--card-line); border-radius: 16px;
  color: var(--text); text-decoration: none;
}
.sets-card .text { flex: 1; min-width: 0; }
.sets-name { display: block; font-size: 18px; font-weight: 800; }
.sets-detail { display: block; font-size: 14px; color: var(--muted); }
/* Set heading with its Rename button (decision 015) */
.set-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.set-head .set-title { min-width: 0; overflow-wrap: anywhere; }
.rename-button {
  flex: 0 0 auto;
  padding: 8px 14px;
  border: 1px solid var(--card-line); border-radius: 999px;
  background: var(--card); color: var(--chip-on-bg);
  font: inherit; font-size: 15px; font-weight: 700;
}
/* Long set names wrap instead of stretching the card */
.sets-list > li { min-width: 0; }
.sets-name { overflow-wrap: anywhere; }
/* A long back label: one line, and the back button shrinks before the pill does.
   The pill must stay readable: it says whether this is sample data or which manual. */
.nav-back { white-space: nowrap; min-width: 0; flex: 0 1 auto; overflow: hidden; }
.nav-back:not([hidden]) ~ .topbar-right { flex-shrink: 0; }
/* Swipe left to delete a set (decision 015 update) */
.sets-row { position: relative; }
.sets-delete {
  position: absolute; top: 0; right: 0; bottom: 0; width: 88px;
  border: 0; border-radius: 14px; background: #d92d20; color: #fff;
  font: inherit; font-weight: 600; cursor: pointer;
}
/* Hidden while the row is at rest, so no red shows at the card's round corners */
.sets-row:not(.open):not(.swiping) .sets-delete { visibility: hidden; }
.sets-row .sets-card {
  position: relative;            /* lies on top of the Delete button */
  touch-action: pan-y;           /* the phone scrolls up and down; sideways is ours */
  user-select: none; -webkit-user-select: none; -webkit-user-drag: none;
  transition: transform 0.2s ease;
}
.sets-row.swiping .sets-card { transition: none; } /* follows the finger exactly */
  .sets-row.open .sets-card { transform: translateX(-96px); }
/* Fault screen: set buttons and the unfolding list of sets (decision 015) */
.set-actions { display: grid; gap: 8px; margin-bottom: 16px; }
.set-actions .set-toggle { margin: 0; }          /* the box sets the spacing now */
.set-choices { display: grid; gap: 6px; padding-left: 16px; }
.set-choices[hidden] { display: none; }          /* "hidden" must win over "grid" */
.set-choice:disabled { opacity: 0.45; cursor: default; }
.set-added { color: var(--muted); font-size: 14px; margin: 2px 4px 0; }
.set-open { font-weight: 600; }
/* Code suggestions in a fault set (decision 015) */
.set-suggestions { list-style: none; margin: 6px 0 0; padding: 0; display: grid; gap: 4px; }
.set-suggestion {
  display: flex; gap: 10px; align-items: baseline; width: 100%; text-align: left;
  padding: 10px 12px; border: 1px solid rgba(127, 127, 127, 0.35); border-radius: 12px;
  background: transparent; color: inherit; font: inherit; cursor: pointer;
}
.set-suggestion-code { font-weight: 700; white-space: nowrap; }
.set-suggestion-title { min-width: 0; overflow-wrap: anywhere; }
.set-suggestion:disabled { opacity: 0.45; cursor: default; }
.set-suggestion-more { color: var(--muted); font-size: 13px; padding: 2px 4px; }
.sheet-action:active { opacity: 0.7; }
.sheet-action-note { color: var(--muted); font-size: 14px; text-align: center; margin: 6px 0 0; }
/* Sheet titles are labels, not headings: small and grey, so the action stands out
   (Search by photo, Turbine spec, Wind park). */
.sheet-title { font-size: 15px; font-weight: 600; color: var(--muted); margin-bottom: 12px; }
/* Delete buttons (Delete set, Delete all sets): bold. Delete all sets keeps the same gap as between sets (10 px). */
.clear-button { font-weight: 700; }
.sets-delete-all { margin-top: 10px; }
/* Questions before deleting (iOS action sheet): red action, Cancel well apart */
.sheet-destructive, .sheet-cancel {
  display: block; width: 100%; padding: 14px 16px; border-radius: 14px;
  font: inherit; font-weight: 700; cursor: pointer;
}
.sheet-destructive { background: #d92d20; color: #fff; border: 0; margin-top: 4px; }
.sheet-cancel {
  background: transparent; color: inherit;
  border: 1px solid rgba(127, 127, 127, 0.35); margin-top: 24px;
}

/* ---------- paste screen (decision 016) ---------- */
.paste-steps { margin: 8px 0 12px; padding-left: 22px; color: var(--muted); font-size: 15px; }
.paste-steps li { margin: 4px 0; }
/* Paste screen buttons: full width and tall enough to hit with gloves (52 px, like the entry rows) */
.paste-button { width: 100%; min-height: 52px; padding: 12px 16px; margin-bottom: 8px; }
.paste-list { list-style: none; padding: 0; margin: 8px 0 0; }
.paste-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  font: inherit;
  color: inherit;
  cursor: pointer;
  background: var(--card);
  border: 1px solid var(--card-line);
  border-radius: 16px;
  padding: 12px 14px;
  margin-bottom: 8px;
}
.paste-row .text { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; }
.paste-check {
  flex: 0 0 auto;
  width: 26px;
  height: 26px;
  border-radius: 999px;
  border: 2px solid var(--card-line);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  color: transparent;            /* the ✓ shows only when chosen */
}
.paste-row[aria-pressed="true"] { border-color: var(--chip-on-bg); }
.paste-row[aria-pressed="true"] .paste-check {
  background: var(--chip-on-bg);
  border-color: var(--chip-on-bg);
  color: var(--chip-on-text);
}
.paste-row:disabled { opacity: 0.45; cursor: default; }
.paste-add { width: 100%; min-height: 52px; padding: 12px 16px; margin: 8px 0 4px; }
.paste-add:disabled { opacity: 0.5; cursor: default; }
.set-camera {
  flex: 0 0 auto;
  width: 46px;
  height: auto;
  align-self: stretch;           /* as tall as the code field */
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.set-camera svg { width: 22px; height: 22px; }
/* ---------- photo of the alarm log -> pills (preliminary, decision 018 to follow) ---------- */
.photo-area { margin: 0 0 4px; }
.photo-status { color: var(--muted); font-size: 15px; font-weight: 600; margin: 8px 4px 12px; }
.photo-status::before {
  content: "";
  display: inline-block;
  width: 14px; height: 14px;
  margin-right: 8px;
  vertical-align: -2px;
  border: 2px solid var(--card-line);
  border-top-color: var(--chip-on-bg);
  border-radius: 50%;
  animation: photo-spin 0.9s linear infinite;
}
@keyframes photo-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .photo-status::before { animation: none; } }
.photo-note { font-size: 14px; margin: 6px 0 10px; }
.photo-pills { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; }
/* A pill is dashed until tapped: read from a photo, not verified. Tapped: filled with
   the peach-red of the NC2 screen (#F2C0A5, measured on a screenshot in the spike), dark
   text, the same in light and dark mode. */
.photo-pill {
  display: inline-flex; align-items: center;
  min-height: 44px; padding: 8px 16px;
  border-radius: 999px;
  border: 2px dashed var(--muted);
  background: var(--card); color: var(--text);
  font: inherit; cursor: pointer;
}
.photo-pill[aria-pressed="true"] {
  border-style: solid; border-color: #f2c0a5;
  background: #f2c0a5; color: #2b1400;
}
.photo-pill:disabled { opacity: 0.45; cursor: default; }
.photo-unread { list-style: none; padding: 0; margin: 4px 0 12px; }
.photo-unread li { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; margin: 0 0 8px; }
.photo-cell {
  display: block; height: 36px; width: auto; max-width: 100%;
  border: 1px solid var(--card-line); border-radius: 6px; background: #fff;
}
.photo-why { color: var(--muted); font-size: 13px; }
/* ---------- photo of the alarm log (old spike screens, not used by the app) ---------- */
.photo-canvas { display: block; width: 100%; height: auto; border-radius: 12px; margin: 8px 0 4px; }
.cascade-choices { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0 8px; }
.cascade-choice {
  font: inherit;
  font-weight: 700;
  padding: 10px 14px;
  border-radius: 12px;
  border: 2px solid #22c55e;
  background: transparent;
  color: inherit;
  cursor: pointer;
}
.cascade-choice[aria-pressed="true"] { background: #22c55e; color: #fff; }
.cascade-strip {
  display: block;
  width: 100%;
  height: auto;
  margin: 6px 0;
  border: 1px solid var(--card-line);
  border-radius: 8px;
  background: #fff;
}
