:root {
  /* Professional slate/blue palette: quieter surfaces, crisp borders, and
     restrained status colors that still scan quickly on the shop floor. */
  --bg: #f6f8fb;
  --bg-soft: #eef2f7;
  --card: #ffffff;
  --card-hover: #f8fafc;
  --border: #d7dee8;
  --text: #111827;
  --text-dim: #607086;
  --accent: #1f5fbf;
  --accent-soft: #e8eef8;
  --price: #047857;
  --warn: #a85f12;
  --danger: #b42318;
  --radius: 8px;
  --radius-sm: 5px;
  --radius-md: 8px;
  --radius-lg: 10px;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 8px 18px rgba(15, 23, 42, 0.045);
  --font-sans: "Lexend", sans-serif;
  --font-display: var(--font-sans);
  --font-mono: "SF Mono", SFMono-Regular, ui-monospace, Menlo, Consolas, "Liberation Mono", monospace;
  --header-h: 112px; /* fallback; app.js sets the real measured height */
  --workspace-max: 1100px;
  --workspace-pad: clamp(16px, 4vw, 48px);
  --sidebar-w: 224px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }
.icon-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon { width: 1.15em; height: 1.15em; display: inline-block; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; vertical-align: -0.15em; }

body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

:focus-visible {
  outline: 2px solid #7aa2e3;
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}

/* ---------- Header ---------- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: max(env(safe-area-inset-top), 14px) var(--workspace-pad) 12px;
}

.header-row {
  display: grid;
  grid-template-columns: 40px 1fr 40px;
  align-items: center;
  gap: 12px;
  width: min(100%, var(--workspace-max));
  margin: 0 auto;
}
.brand { grid-column: 2; justify-content: center; }

.nav-menu-toggle {
  grid-column: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--card);
  color: var(--text);
  cursor: pointer;
  flex: none;
}
.nav-menu-toggle .icon { width: 20px; height: 20px; }
.nav-menu-toggle:active { transform: scale(0.96); }

.nav-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  z-index: 190;
  opacity: 0;
  transition: opacity 0.2s ease;
}
.nav-backdrop[hidden] { display: none; }
body.nav-open .nav-backdrop { opacity: 1; }

.brand {
  font-family: var(--font-display);
  font-size: 1.22rem;
  margin: 0;
  font-weight: 500;
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  gap: 8px;
}
.brand-logo {
  display: block;
  width: clamp(122px, 28vw, 160px);
  height: auto;
}
.brand-icon { width: 1.28em; height: 1.28em; color: var(--accent); stroke-width: 1.9; }
/* Signature element: a small powered-on LED pulse beside the brand mark */
.brand::after {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--price);
  box-shadow: 0 0 0 0 rgba(15, 122, 76, 0.5);
  animation: led-pulse 2.4s ease-out infinite;
}
.brand:has(.brand-logo)::after { display: none; }
@keyframes led-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(15, 122, 76, 0.45); }
  70%  { box-shadow: 0 0 0 6px rgba(15, 122, 76, 0); }
  100% { box-shadow: 0 0 0 0 rgba(15, 122, 76, 0); }
}

.info-banner {
  margin: 16px 0 0;
  font-size: 0.78rem;
  color: var(--text-dim);
  line-height: 1.4;
}

.status-line {
  margin: 8px 0 0;
  font-size: 0.75rem;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  gap: 7px;
  font-family: var(--font-mono);
}
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-dim);
  flex: none;
}
.status-dot.live { background: var(--price); box-shadow: 0 0 0 3px rgba(4, 120, 87, 0.12); }
.status-dot.stale { background: var(--warn); }
.status-dot.error { background: var(--danger); }

/* ---------- Container ---------- */
.container {
  width: min(100%, var(--workspace-max));
  margin: 0 auto;
  padding: 20px var(--workspace-pad) 48px;
}

/* ---------- Search ---------- */
/* Sticks just below the header so it stays reachable while a long list
   scrolls underneath. The opaque background + top padding masks list
   content scrolling up behind it. */
.search-wrap {
  position: relative;
  top: auto;
  z-index: 1;
  background: var(--bg);
  padding: 16px 0 14px;
  margin: 0;
}
#view-prices .search-wrap {
  position: sticky;
  top: var(--header-h);
  z-index: 20;
}
@media (max-width: 899px) {
  #view-prices .search-wrap { z-index: 5; }
}
#view-prices.focused-search-result .search-wrap {
  box-shadow: 0 8px 18px rgba(35, 45, 72, 0.08);
}
.search-input {
  width: 100%;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 1.05rem;
  padding: 14px 44px 14px 16px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  box-shadow: var(--shadow);
}
.search-input::placeholder { color: var(--text-dim); }
.search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(31, 95, 191, 0.12);
}
.clear-search {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: none;
  background: var(--bg-soft);
  color: var(--text);
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
}
.clear-search .icon { width: 16px; height: 16px; }

/* ---------- Filter chips ---------- */
.filter-chips {
  display: flex;
  flex-wrap: nowrap;
  gap: 8px;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  max-height: 58px;
  padding: 2px 2px 8px;
  margin-bottom: 12px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  opacity: 1;
  transition: max-height 0.18s ease, opacity 0.16s ease, padding 0.18s ease, margin 0.18s ease;
}
.filter-chips::-webkit-scrollbar { display: none; }
.brand-filter-chips.collapsed {
  max-height: 0;
  opacity: 0;
  padding-top: 0;
  padding-bottom: 0;
  margin-bottom: 0;
  overflow: hidden;
  pointer-events: none;
}
.chip {
  flex: none;
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: var(--radius-md);
  padding: 8px 16px;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s;
}
.chip:active { transform: scale(0.96); }
.chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.status-chip {
  gap: 7px;
  background: var(--status-bg);
  border-color: var(--status-border);
  color: var(--status-ink);
}
.status-chip::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--status-dot);
}
.status-chip.active {
  background: var(--status-ink);
  border-color: var(--status-ink);
  color: #fff;
}
.status-chip.active::before { background: #fff; }

/* ---------- Results ---------- */
.result-count {
  font-size: 0.78rem;
  color: var(--text-dim);
  margin: 0 0 10px 2px;
}
.results { display: flex; flex-direction: column; gap: 10px; }
#results { gap: 6px; }
.view-more-btn {
  grid-column: 1 / -1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 46px;
  margin-top: 4px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--card);
  color: var(--accent);
  font: 500 0.9rem var(--font-display);
  cursor: pointer;
  box-shadow: var(--shadow);
}
.view-more-btn:hover { background: var(--accent-soft); }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: background 0.15s;
  box-shadow: var(--shadow);
}
#results .card {
  border-radius: var(--radius-md);
  box-shadow: none;
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  cursor: pointer;
  user-select: none;
}
#results .card-head {
  min-height: 52px;
  padding: 10px 12px;
}
.card-head:hover { background: var(--card-hover); }
.card-model {
  font-size: 1.02rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 9px;
}
#results .card-model {
  min-width: 0;
  flex: 1;
  white-space: nowrap;
}
#results .card-model > span:first-child {
  overflow: hidden;
  text-overflow: ellipsis;
}
.brand-tag {
  font-size: 0.62rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 3px 7px;
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  color: var(--accent);
}
.card-right { display: flex; align-items: center; gap: 10px; flex: none; }
.from-price { display: flex; align-items: center; text-align: right; }
.from-label { font-size: 0.62rem; color: var(--text-dim); display: block; line-height: 1; }
.from-value { font-family: var(--font-mono); font-size: 0.92rem; font-weight: 500; color: var(--price); white-space: nowrap; }
.from-prefix { font-family: inherit; font-size: 0.72rem; font-weight: 500; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.03em; }
.from-value.na { color: var(--warn); font-family: inherit; font-size: 0.82rem; font-weight: 500; }
.chevron {
  color: var(--text-dim);
  font-size: 0.85rem;
  transition: transform 0.2s;
}
.card.open .chevron { transform: rotate(180deg); }

@media (max-width: 460px) {
  #results .brand-tag { display: none; }
  #results .card-head { gap: 8px; }
  #results .card-model { font-size: 0.96rem; }
  .from-prefix { display: none; }
}

.card-body {
  display: none;
  padding: 0 16px 14px;
  border-top: 1px solid var(--border);
}
.card.open .card-body { display: block; }
.price-grid {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 0;
  margin-top: 10px;
}
.price-row {
  display: contents;
  cursor: pointer;
}
.price-row > span {
  padding: 9px 2px;
  border-bottom: 1px solid var(--border);
  font-size: 0.92rem;
  transition: background 0.12s ease;
}
.price-row:last-child > span { border-bottom: none; }
/* .price-row uses display: contents (no box of its own), so hover/focus
   styling has to target the child spans, which are the actual grid items. */
.price-row:hover > span,
.price-row:focus-visible > span {
  background: var(--accent-soft);
}
.price-name { color: var(--text-dim); display: inline-flex; align-items: center; }
.price-val { text-align: right; font-weight: 500; color: var(--price); font-family: var(--font-mono); }
.price-stock-tick {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 18px;
  height: 18px;
  margin-left: 7px;
  border-radius: var(--radius-sm);
  background: #dff5ec;
  color: var(--price);
  font-size: 0.74rem;
  font-weight: 500;
  line-height: 1;
}
.price-add-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 18px;
  height: 18px;
  margin-right: 7px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 500;
  line-height: 1;
  pointer-events: none;
  transition: transform 0.12s ease;
}
.price-row:hover .price-add-btn,
.price-row:focus-visible .price-add-btn {
  transform: scale(1.15);
}
.price-edit-btn {
  width: 30px;
  height: 30px;
  padding: 0;
  flex: none;
  opacity: 0;
  transition: opacity 0.12s ease;
}
.price-edit-btn .icon { width: 14px; height: 14px; }
.price-row:hover .price-edit-btn,
.price-row:focus-within .price-edit-btn {
  opacity: 1;
}
.price-val-editing {
  grid-column: 2 / span 2;
  display: flex;
  align-items: center;
  gap: 6px;
  text-align: left;
}
.price-val-editing .price-inline-input {
  flex: 1;
  min-width: 0;
  padding: 6px 8px;
  font-size: 0.85rem;
}
.price-val-editing .icon-btn {
  width: 28px;
  height: 28px;
  padding: 0;
  flex: none;
}
.price-val-editing .icon-btn .icon { width: 14px; height: 14px; }
.price-inline-input.field-error-input { border-color: var(--danger); }
.no-prices {
  margin-top: 10px;
  font-size: 0.9rem;
  color: var(--warn);
}

/* ---------- Inventory ---------- */
.inventory-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin: 14px 0 14px;
}
.inventory-summary-tile {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 13px 14px;
  box-shadow: var(--shadow);
}
.inventory-summary-tile span {
  display: block;
  color: var(--text-dim);
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.inventory-summary-tile strong {
  display: block;
  margin-top: 4px;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 1.28rem;
}
.inventory-summary-tile.is-warn { background: #fffbeb; border-color: #f3d9a7; }
.inventory-summary-tile.is-warn strong { color: var(--warn); }
.inventory-summary-tile.is-danger { background: #fff5f5; border-color: #f4c7c3; }
.inventory-summary-tile.is-danger strong { color: var(--danger); }
.inventory-table-shell {
  overflow: hidden;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}
.inventory-table-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 64px;
  padding: 0 16px;
  background: linear-gradient(180deg, #fff, #f8fafc);
  border-bottom: 1px solid var(--border);
}
.inventory-filter-wrap {
  flex: none;
  min-width: 158px;
}
.inventory-filter {
  width: 100%;
  min-height: 52px;
  padding: 8px 42px 8px 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--card);
  color: var(--accent);
  font: 500 1.02rem var(--font-display);
  outline: none;
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
  box-shadow: 0 8px 22px rgba(35, 45, 72, 0.05);
  transition: border-color 0.14s ease, box-shadow 0.14s ease, transform 0.14s ease;
}
.inventory-filter:hover,
.inventory-filter:focus {
  border-color: rgba(31, 95, 191, 0.28);
  box-shadow: 0 8px 20px rgba(31, 95, 191, 0.08);
}
.inventory-stock-filters {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: none;
  max-width: min(42vw, 520px);
  overflow-x: auto;
  padding: 2px;
  scrollbar-width: none;
}
.inventory-stock-filters::-webkit-scrollbar { display: none; }
.inventory-stock-filter {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  flex: none;
  min-height: 38px;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--text-dim);
  font: 500 0.82rem var(--font-display);
  cursor: pointer;
  white-space: nowrap;
}
.inventory-stock-filter:hover,
.inventory-stock-filter.active {
  border-color: currentColor;
  color: var(--stock-filter-color, var(--accent));
}
.inventory-stock-filter-all { --stock-filter-color: var(--accent); }
.inventory-stock-filter-ok { --stock-filter-color: var(--price); }
.inventory-stock-filter-low,
.inventory-stock-filter-out { --stock-filter-color: var(--danger); }
.inventory-stock-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}
.inventory-search {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
  min-height: 44px;
  padding: 0 10px;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  background: var(--bg-soft);
  color: var(--text-dim);
}
.inventory-search:focus-within {
  border-color: rgba(31, 95, 191, 0.24);
  background: var(--card);
  box-shadow: 0 0 0 3px rgba(31, 95, 191, 0.08);
}
.inventory-search .icon { width: 20px; height: 20px; flex: none; }
.inventory-search input {
  width: 100%;
  min-height: 40px;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font: 500 0.98rem var(--font-display);
}
.inventory-search input::placeholder { color: var(--text-dim); }
.inventory-clear-search,
.inventory-view-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
}
.inventory-clear-search:hover,
.inventory-view-btn:hover { background: var(--bg-soft); color: var(--text); }
.inventory-view-btn {
  border: 1px solid var(--border);
  background: var(--card);
}
.inventory-table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.inventory-table {
  width: 100%;
  min-width: 920px;
  border-collapse: collapse;
  table-layout: auto;
}
.inventory-table th,
.inventory-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  font-size: 0.92rem;
  vertical-align: middle;
}
.inventory-table th {
  background: var(--bg-soft);
  color: var(--text-dim);
  font-weight: 500;
  text-align: left;
  letter-spacing: 0.02em;
}
.inventory-table th.num,
.inventory-table td.num {
  text-align: center;
  font-family: var(--font-mono);
  font-weight: 500;
}
.inventory-table th.num { font-family: var(--font-display); }
.inventory-row { border-left: 4px solid transparent; }
.inventory-row:hover { background: #f8fafc; }
.inventory-row.inventory-ok { border-left-color: rgba(4, 120, 87, 0.32); }
.inventory-row.inventory-low { border-left-color: var(--danger); }
.inventory-row.inventory-low td[data-label="On hand"],
.inventory-row.inventory-low .inventory-stock-status { color: var(--danger); }
.inventory-row.inventory-out { opacity: 0.72; }
.inventory-row.inventory-out { border-left-color: var(--danger); }
.inventory-row.inventory-out td[data-label="On hand"],
.inventory-row.inventory-out .inventory-stock-status { color: var(--danger); }
.inventory-product {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}
.inventory-thumb {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 46px;
  height: 46px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: linear-gradient(145deg, #fff, var(--bg-soft));
  color: var(--accent);
}
.inventory-thumb .icon { width: 24px; height: 24px; stroke-width: 1.7; }
.inventory-product-text {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}
.inventory-product-text strong {
  color: var(--text);
  font-weight: 500;
  line-height: 1.25;
  overflow-wrap: anywhere;
  white-space: normal;
}
.inventory-product-meta {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
  color: var(--text-dim);
  font-size: 0.8rem;
}
.inventory-pill {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 1px 8px;
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 500;
}
.inventory-category,
.inventory-stock-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 28px;
  padding: 5px 11px;
  border-radius: var(--radius-sm);
  background: var(--bg-soft);
  color: var(--text);
  font-weight: 500;
}
.inventory-stock-status {
  background: #fff;
  color: var(--price);
  box-shadow: none;
}
.inventory-stock-status::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}
.inventory-stock-low {
  background: #fff;
  color: var(--danger);
  box-shadow: none;
}
.inventory-stock-out {
  background: #fff;
  color: var(--danger);
  box-shadow: none;
}
.inventory-unavailable {
  display: block;
  margin-top: 4px;
  color: var(--text-dim);
  font-size: 0.74rem;
  font-weight: 500;
}
.inventory-note { color: var(--warn); }
.inventory-muted { color: var(--text-dim) !important; font-weight: 500; }
.inventory-adjust-col { min-width: 190px; }
.inventory-table th.inventory-adjust-col {
  padding-right: 34px;
  text-align: right;
}
.inventory-adjust {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 7px;
  width: 100%;
}
.inventory-adjust-btn,
.inventory-update-btn {
  min-height: 34px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--card);
  color: var(--text);
  font: 500 0.9rem var(--font-display);
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.12s ease, background 0.12s ease;
}
.inventory-adjust-btn {
  width: 34px;
  padding: 0;
  color: var(--accent);
  font-size: 1rem;
}
.inventory-update-btn {
  min-width: 72px;
  padding: 0 12px;
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.inventory-adjust-btn:hover,
.inventory-update-btn:hover:not(:disabled) {
  transform: translateY(-1px);
  border-color: rgba(31, 95, 191, 0.4);
}
.inventory-update-btn:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}
.inventory-delta {
  min-width: 34px;
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-weight: 500;
  text-align: center;
}
.inventory-delta.is-positive { color: var(--price); }
.inventory-delta.is-negative { color: var(--warn); }
.inventory-row-error {
  margin: 5px 0 0;
  color: var(--danger);
  font-size: 0.74rem;
  font-weight: 500;
  text-align: right;
}
@media (max-width: 820px) {
  .inventory-summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .inventory-table-toolbar { flex-wrap: wrap; }
  .inventory-stock-filters {
    order: 3;
    width: 100%;
    max-width: 100%;
  }
}
@media (max-width: 720px) {
  .inventory-table-toolbar {
    align-items: stretch;
    flex-direction: column;
    gap: 10px;
    padding: 12px;
  }
  .inventory-filter-wrap,
  .inventory-filter { width: 100%; }
  .inventory-stock-filters { order: initial; }
  .inventory-view-btn { display: none; }
  .inventory-table-scroll { overflow: visible; }
  .inventory-table,
  .inventory-table tbody,
  .inventory-table tr,
  .inventory-table td { display: block; width: 100%; min-width: 0; }
  .inventory-table thead { display: none; }
  .inventory-table tr.inventory-row {
    width: auto;
  }
  .inventory-row {
    margin: 10px;
    border: 1px solid var(--border);
    border-left-width: 5px;
    border-radius: var(--radius-md);
    background: var(--card);
    box-shadow: 0 6px 14px rgba(15, 23, 42, 0.045);
  }
  .inventory-table td {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    padding: 9px 12px;
    border-bottom: 0;
  }
  .inventory-table td::before {
    content: attr(data-label);
    color: var(--text-dim);
    font-size: 0.74rem;
    font-weight: 500;
    letter-spacing: 0.03em;
    text-transform: uppercase;
  }
  .inventory-table td:first-child {
    display: block;
    padding-top: 12px;
  }
  .inventory-table td:first-child::before { display: none; }
  .inventory-table td.num { text-align: right; }
  .inventory-table td[data-label="Update"] {
    display: block;
  }
  .inventory-table td[data-label="Update"]::before {
    display: block;
    margin-bottom: 8px;
  }
  .inventory-adjust {
    justify-content: stretch;
  }
  .inventory-adjust-btn {
    width: 44px;
    min-height: 44px;
  }
  .inventory-update-btn {
    flex: 1;
    min-height: 44px;
  }
  .inventory-row-error { text-align: left; }
  .inventory-product { align-items: flex-start; }
}

/* ---------- States ---------- */
.empty-state, .error-state {
  text-align: center;
  padding: 50px 20px;
  color: var(--text-dim);
}
.empty-icon { width: 48px; height: 48px; display: inline-flex; align-items: center; justify-content: center; margin: 0 0 12px; border-radius: var(--radius-md); color: var(--accent); background: var(--accent-soft); }
.empty-icon .icon { width: 25px; height: 25px; stroke-width: 1.65; }
.empty-icon.error { color: var(--danger); background: #fce7e5; }
.empty-title { font-size: 1.05rem; font-weight: 500; color: var(--text); margin: 0 0 4px; }
.empty-sub { font-size: 0.88rem; margin: 0; }

.skeleton {
  height: 56px;
  border-radius: var(--radius);
  background: linear-gradient(90deg, var(--bg-soft) 25%, #f9fafd 50%, var(--bg-soft) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.3s infinite;
}
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------- Footer ---------- */
.app-footer {
  text-align: center;
  padding: 18px 16px max(env(safe-area-inset-bottom), 18px);
  color: var(--text-dim);
  font-size: 0.72rem;
  border-top: 1px solid var(--border);
}

@media (min-width: 600px) {
  .brand { font-size: 1.35rem; }
}

/* ---------- View nav ---------- */
/* Mobile default: a slide-out drawer triggered by .nav-menu-toggle, opened via
   body.nav-open. Replaced by an always-visible sidebar at the 900px+ breakpoint. */
.view-nav {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 4px;
  position: fixed;
  top: 0;
  left: 0;
  height: 100dvh;
  width: min(78vw, 280px);
  margin: 0;
  background: var(--card);
  padding: max(env(safe-area-inset-top), 16px) 12px 16px;
  border-radius: 0;
  box-shadow: 8px 0 28px rgba(15, 23, 42, 0.18);
  z-index: 200;
  overflow-y: auto;
  transform: translateX(-100%);
  transition: transform 0.25s ease;
}
body.nav-open .view-nav { transform: translateX(0); }
.nav-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 0 4px 14px;
  margin-bottom: 6px;
  border-bottom: 1px solid var(--border);
}
.nav-drawer-logo { width: 128px; height: auto; }
.nav-drawer-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  flex: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--card);
  color: var(--text-dim);
  cursor: pointer;
}
.nav-drawer-close .icon { width: 16px; height: 16px; }
.nav-drawer-close:hover { color: var(--text); background: var(--bg-soft); }
.nav-btn {
  display: inline-flex;
  align-items: center;
  justify-content: flex-start;
  gap: 7px;
  flex: none;
  width: 100%;
  min-height: 44px;
  white-space: nowrap;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-dim);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}
.nav-btn:active { transform: scale(0.98); }
.nav-btn.active {
  background: var(--card);
  border-color: var(--border);
  color: var(--accent);
  box-shadow: 0 1px 2px rgba(18, 24, 38, 0.08);
}
@media (min-width: 900px) {
  :root {
    --workspace-max: 1280px;
    --workspace-pad: clamp(18px, 2.4vw, 34px);
  }
  body {
    padding-left: var(--sidebar-w);
  }
  .app-header {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 30;
    display: flex;
    flex-direction: column;
    width: var(--sidebar-w);
    height: 100dvh;
    padding: max(env(safe-area-inset-top), 18px) 12px 16px;
    overflow-y: auto;
    background: #f1f5f9;
    border-right: 1px solid var(--border);
    border-bottom: 0;
    box-shadow: 8px 0 24px rgba(18, 24, 38, 0.04);
  }
  .header-row {
    display: flex;
    justify-content: flex-start;
    width: 100%;
    margin: 0;
    padding: 2px 8px 14px;
  }
  .nav-menu-toggle { display: none; }
  .nav-backdrop { display: none; }
  .nav-drawer-header { display: none; }
  .brand-logo {
    width: 158px;
  }
  .view-nav {
    position: static;
    height: auto;
    transform: none;
    transition: none;
    box-shadow: none;
    z-index: auto;
    overflow-y: visible;
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
    width: 100%;
    margin: 4px 0 0;
    padding: 0;
    background: transparent;
    border-radius: 0;
  }
  .nav-btn {
    justify-content: flex-start;
    flex: none;
    width: 100%;
    min-height: 42px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    color: #475569;
    font-size: 0.95rem;
    font-weight: 500;
  }
  .nav-btn:hover {
    background: rgba(255, 255, 255, 0.64);
    color: var(--text);
  }
  .nav-btn.active {
    background: var(--card);
    border-color: rgba(255, 255, 255, 0.9);
    color: var(--text);
    box-shadow: 0 1px 2px rgba(18, 24, 38, 0.05);
  }
  .nav-btn.active .icon {
    color: var(--accent);
  }
  .nav-btn .icon {
    width: 20px;
    height: 20px;
    color: #4c5563;
  }
  .settings-nav-btn {
    margin-top: 2px;
    padding-top: 12px;
    border-top-color: var(--border);
  }
  .container {
    padding-top: 24px;
  }
  .app-footer {
    margin-left: 0;
  }
}
.view[hidden] { display: none; }
/* Animation is on the element itself (not a toggled class), so it replays
   automatically each time `hidden` is removed and the view re-enters layout.
   Also reused for sub-tab/step panels (.appt-panel, .form-step) so switching
   between any "page" in the app — top nav or in-flow steps — feels dynamic
   rather than an abrupt cut. */
.view:not([hidden]),
.appt-panel:not([hidden]),
.form-step:not([hidden]),
.completed-repairs-section {
  animation: view-in 0.32s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes view-in {
  from { opacity: 0; transform: translateY(10px) scale(0.99); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.nav-btn { position: relative; }
.nav-btn.active { transition: background 0.2s ease, color 0.2s ease, box-shadow 0.2s ease; }

/* ---------- Business dashboard ---------- */
.dashboard-kpi-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin: 18px 0 18px;
}
.dashboard-kpi-card,
.today-focus-card,
.dashboard-target-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}
.dashboard-target-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px 18px;
  margin: 16px 0 0;
  padding: 15px 16px;
}
.targets-page-card {
  margin-top: 18px;
  padding: 20px;
}
.targets-history-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  margin-top: 18px;
  padding: 20px;
}
.targets-history-list { margin-top: 14px; }
.target-history-row small { color: var(--text-dim); font-size: 0.8rem; flex: none; }
.targets-progress {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 16px;
}
.targets-progress-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 16px 18px;
  display: grid;
  gap: 8px;
  align-content: start;
}
.targets-progress-value {
  margin: 0;
  display: flex;
  align-items: baseline;
  gap: 7px;
}
.targets-progress-value strong {
  font-family: var(--font-display);
  font-size: 1.45rem;
  font-weight: 500;
  letter-spacing: -0.02em;
}
.targets-progress-value span {
  color: var(--text-dim);
  font-size: 0.85rem;
}
.targets-progress-sub {
  margin: 0;
  color: var(--text-dim);
  font-size: 0.82rem;
}
.target-clear-done {
  padding: 2px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-dim);
  font-size: 0.74rem;
  cursor: pointer;
}
.target-clear-done:hover { border-color: var(--danger); color: var(--danger); }
.target-card-age {
  display: block;
  margin-top: 4px;
  color: var(--text-dim);
  font-size: 0.72rem;
}
@media (max-width: 680px) {
  .targets-progress { grid-template-columns: 1fr; }
}
.targets-title {
  margin: 3px 0 0;
  font-family: var(--font-display);
  font-size: 1.35rem;
  font-weight: 500;
  letter-spacing: -0.02em;
}
.dashboard-target-help {
  margin: 4px 0 0;
  color: var(--text-dim);
  font-size: 0.84rem;
}
.dashboard-target-form {
  display: inline-grid;
  grid-template-columns: minmax(150px, 1fr) minmax(150px, 1fr) auto;
  align-items: end;
  gap: 8px;
}
.target-input-group {
  display: grid;
  gap: 6px;
  color: var(--text-dim);
  font-size: 0.76rem;
  font-weight: 500;
}
.target-money-input {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 6px;
}
.dashboard-currency {
  color: var(--text-dim);
  font-size: 0.95rem;
  font-weight: 500;
}
.dashboard-target-form input {
  min-height: 40px;
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-soft);
  color: var(--text);
  padding: 8px 10px;
  font: 500 0.95rem var(--font-display);
  outline: none;
}
.dashboard-target-form input:focus {
  border-color: rgba(31, 95, 191, 0.32);
  background: var(--card);
  box-shadow: 0 0 0 3px rgba(31, 95, 191, 0.08);
}
.dashboard-target-form .ghost-btn {
  min-height: 40px;
  white-space: nowrap;
  align-self: end;
}
.dashboard-target-message {
  grid-column: 2 / -1;
  margin: -6px 0 0;
  color: var(--price);
  font-size: 0.76rem;
  font-weight: 500;
}
.targets-action-card {
  margin-top: 14px;
  padding: 18px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}
.target-plan-form {
  display: grid;
  gap: 10px;
  padding-top: 14px;
}
.target-plan-form .ghost-btn {
  justify-self: start;
  min-width: 150px;
}
.target-card-create {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 140px auto;
  gap: 8px;
}
.target-board {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.target-board-column {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: #f8fafc;
  overflow: hidden;
}
.target-board-heading {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
/* Label absorbs the free space so the count (and Done's Clear button)
   group on the right regardless of how many controls a column has. */
.target-board-heading span:first-child { margin-right: auto; }
.target-board-heading b {
  display: inline-grid;
  place-items: center;
  min-width: 24px;
  height: 24px;
  border-radius: var(--radius-sm);
  background: var(--card);
  color: var(--text);
  font-weight: 500;
}
.target-board-cards {
  display: grid;
  gap: 10px;
  padding: 10px;
}
.target-inline-composer {
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--card);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}
.target-inline-title,
.target-inline-notes {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font: 500 0.9rem var(--font-display);
}
.target-inline-title::placeholder,
.target-inline-notes::placeholder {
  color: var(--text-dim);
}
.target-inline-notes {
  min-height: 38px;
  resize: vertical;
  color: var(--text-dim);
  font-size: 0.82rem;
  line-height: 1.35;
}
.target-inline-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.target-inline-actions .dashboard-target-message {
  margin: 0;
  min-width: 0;
}
.target-inline-add {
  width: auto;
  min-height: 34px;
  padding: 6px 10px;
  flex: none;
}
.target-inline-add .icon {
  width: 15px;
  height: 15px;
}
.target-action-card {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--card);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}
.target-action-card strong {
  display: block;
  font-weight: 500;
}
.target-action-card p {
  margin: 6px 0 0;
  color: var(--text-dim);
  font-size: 0.82rem;
  line-height: 1.35;
}
.target-card-actions,
.ops-row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}
.target-card-actions button,
.ops-row-actions button {
  min-height: 30px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--card);
  color: var(--text-dim);
  padding: 5px 9px;
  font: 500 0.75rem var(--font-display);
  cursor: pointer;
}
.target-card-actions button:hover,
.ops-row-actions button:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.danger-text { color: var(--danger) !important; }
.ops-card {
  margin-top: 18px;
  padding: 18px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}
.ops-list {
  display: grid;
  gap: 10px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}
.ops-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: #f8fafc;
}
.ops-row.is-complete { opacity: 0.68; }
.ops-row strong {
  display: block;
  font-weight: 500;
}
.ops-row p,
.ops-row small {
  display: block;
  margin: 4px 0 0;
  color: var(--text-dim);
}
/* ---------- Diagnose (device testing wizard) ---------- */
.diagnose-wizard-card {
  max-width: 720px;
  margin-top: 14px;
}
.diagnose-start { text-align: left; }
.diagnose-start-icon {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  margin-bottom: 16px;
  border-radius: var(--radius-md);
  background: var(--accent-soft);
  color: var(--accent);
}
.diagnose-start-icon .icon { width: 26px; height: 26px; }
.diagnose-start .field-label { margin-bottom: 6px; }
.diagnose-resume-note {
  margin: 14px 0 0;
  padding: 10px 13px;
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.86rem;
}
.diagnose-start-actions { margin-top: 18px; }

.diagnose-seg-bar {
  display: flex;
  gap: 6px;
  margin-bottom: 16px;
}
.diagnose-seg {
  flex: 1;
  height: 14px;
  padding: 0;
  border: none;
  border-radius: 999px;
  background: var(--bg-soft);
  box-shadow: inset 0 0 0 1px var(--border);
  cursor: pointer;
  transition: background 0.15s, box-shadow 0.15s;
}
.diagnose-seg:hover { box-shadow: inset 0 0 0 1px var(--text-dim); }
.diagnose-seg.is-complete { background: #cfe3d8; box-shadow: inset 0 0 0 1px #b7e0cd; }
.diagnose-seg.has-fail { background: #f3d2cd; box-shadow: inset 0 0 0 1px #f2c6c0; }
.diagnose-seg.is-current { box-shadow: inset 0 0 0 2px var(--accent); }

.diagnose-step-meta {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}
.diagnose-step-meta .form-section-label { margin: 0; }
.diagnose-step-count {
  flex: none;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-dim);
}
.diagnose-step-count.is-complete { color: var(--price); }
.diagnose-step .form-step-heading { margin-top: 8px; }

.diagnose-test-list {
  display: grid;
  gap: 8px;
}
.diagnose-test {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-soft);
}
.diagnose-test.state-pass { border-color: #b7e0cd; background: #f0f9f4; }
.diagnose-test.state-fail { border-color: #f2c6c0; background: #fff5f5; }
.diagnose-test.state-na { border-color: #ecd4ac; background: #fdf7ec; }
.diagnose-test-label {
  font-size: 0.9rem;
  font-weight: 500;
}
.diagnose-test-actions {
  display: inline-flex;
  gap: 6px;
}
.diagnose-state-btn {
  min-width: 52px;
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--card);
  color: var(--text-dim);
  font: 500 0.82rem var(--font-sans);
  cursor: pointer;
  transition: background 0.12s, color 0.12s, border-color 0.12s, transform 0.1s;
}
.diagnose-state-btn:hover { border-color: var(--text-dim); }
.diagnose-state-btn:active { transform: scale(0.96); }
.diagnose-state-btn.state-pass.active {
  background: var(--price); border-color: var(--price); color: #fff;
}
.diagnose-state-btn.state-fail.active {
  background: var(--danger); border-color: var(--danger); color: #fff;
}
.diagnose-state-btn.state-na.active {
  background: var(--warn); border-color: var(--warn); color: #fff;
}

.diagnose-step-actions {
  border-top: 1px solid var(--border);
  margin-top: 18px;
  padding-top: 16px;
}
.diagnose-step-actions #diagnoseBack { margin-right: auto; }
.diagnose-step-actions .primary-btn.attention {
  animation: diagnose-nudge 1.4s ease-in-out 2;
}
@keyframes diagnose-nudge {
  0%, 100% { box-shadow: 0 0 0 0 rgba(31, 95, 191, 0.35); }
  50% { box-shadow: 0 0 0 6px rgba(31, 95, 191, 0); }
}

.diagnose-summary {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 18px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-soft);
}
.diagnose-summary-counts {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
}
.diagnose-tally {
  display: inline-flex;
  align-items: baseline;
  gap: 5px;
  font-size: 0.82rem;
  color: var(--text-dim);
}
.diagnose-tally strong {
  font-size: 0.98rem;
  color: var(--text);
}
.diagnose-tally.is-pass strong { color: var(--price); }
.diagnose-tally.is-fail strong { color: var(--danger); }
.diagnose-tally.is-na strong { color: var(--warn); }
.diagnose-progress {
  position: relative;
  flex: 1;
  min-width: 160px;
  height: 22px;
  border-radius: 999px;
  background: var(--card);
  border: 1px solid var(--border);
  overflow: hidden;
}
.diagnose-progress-fill {
  position: absolute;
  inset: 0 auto 0 0;
  background: var(--accent);
  transition: width 0.2s ease;
}
.diagnose-progress-label {
  position: relative;
  z-index: 1;
  display: block;
  text-align: center;
  line-height: 20px;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text);
  mix-blend-mode: luminosity;
}

.diagnose-review-groups {
  display: grid;
  gap: 6px;
  margin: 14px 0 18px;
}
.diagnose-review-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--card);
}
.diagnose-review-name {
  flex: 1;
  font-size: 0.88rem;
  font-weight: 500;
}
.diagnose-review-stats {
  display: inline-flex;
  align-items: baseline;
  gap: 10px;
  font-size: 0.8rem;
  color: var(--text-dim);
}
.diagnose-review-fail { color: var(--danger); font-weight: 600; }
.diagnose-review-tested.is-complete { color: var(--price); font-weight: 600; }
.diagnose-review-edit {
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--card);
  color: var(--accent);
  font: 500 0.78rem var(--font-sans);
  padding: 4px 12px;
  cursor: pointer;
}
.diagnose-review-edit:hover { background: var(--accent-soft); }
.diagnose-review .field-label { margin-bottom: 6px; }
.diagnose-review textarea { resize: vertical; min-height: 68px; }

@media (max-width: 520px) {
  .diagnose-test { justify-content: flex-start; }
  .diagnose-test-actions { width: 100%; }
  .diagnose-state-btn { flex: 1; }
  .diagnose-step-actions { flex-wrap: wrap; }
  .diagnose-step-actions .primary-btn { width: 100%; order: -1; }
  .diagnose-step-actions #diagnoseBack { margin-right: 0; }
}

.leads-workspace { margin-top: 14px; }
.leads-topbar {
  position: sticky;
  top: var(--header-h);
  z-index: 18;
  display: grid;
  grid-template-columns: minmax(240px, 1fr) minmax(150px, 0.32fr) minmax(170px, 0.36fr) auto auto;
  gap: 10px;
  align-items: center;
  padding: 12px 0;
  background: var(--bg);
}
.leads-searchbar {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  min-height: 50px;
  padding: 0 10px 0 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--card);
  box-shadow: var(--shadow);
  color: var(--text-dim);
}
.leads-searchbar .icon { width: 20px; height: 20px; flex: none; }
.leads-searchbar input {
  width: 100%;
  min-width: 0;
  min-height: 46px;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font: 500 1rem var(--font-display);
}
.leads-heading-row {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
  margin: 8px 0 12px;
}
.leads-heading-row h2 {
  margin: 2px 0 0;
  font-family: var(--font-display);
  font-size: 1.1rem;
}
.leads-form {
  margin-bottom: 14px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--card);
  box-shadow: var(--shadow);
}
.leads-form-actions {
  grid-column: 1 / -1;
  justify-content: flex-start;
  margin-top: 0;
}
.leads-list {
  margin-top: 0;
  padding-top: 0;
  border-top: 0;
  gap: 10px;
}
.lead-card {
  --lead-tone: var(--accent);
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr) minmax(190px, auto);
  grid-template-areas: "avatar main side";
  align-items: start;
  gap: 16px;
  padding: 16px 18px;
  background: var(--card);
  border: 1px solid var(--border);
  border-left: 4px solid var(--lead-tone);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  cursor: pointer;
}
.lead-card:hover { background: var(--card-hover); }
.lead-card:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.lead-status-new { --lead-tone: var(--accent); }
.lead-status-contacted { --lead-tone: #416aa3; }
.lead-status-quoted,
.lead-status-follow-up { --lead-tone: var(--warn); }
.lead-status-won { --lead-tone: var(--price); }
.lead-status-lost { --lead-tone: var(--danger); }
.lead-avatar {
  grid-area: avatar;
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  border: 1px solid color-mix(in srgb, var(--lead-tone) 28%, var(--border));
  border-radius: var(--radius-md);
  background: color-mix(in srgb, var(--lead-tone) 11%, var(--card));
  color: var(--lead-tone);
}
.lead-avatar .icon {
  width: 27px;
  height: 27px;
  stroke-width: 1.8;
}
.lead-card-main {
  grid-area: main;
  min-width: 0;
}
.lead-card-top {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.lead-card-title {
  min-width: 0;
  color: var(--text);
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.2;
}
.lead-status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--lead-tone) 12%, var(--card));
  color: var(--lead-tone);
  font-size: 0.72rem;
  font-weight: 600;
}
.lead-status-won .lead-status-pill { background: #dff5ec; color: var(--price); }
.lead-status-lost .lead-status-pill { background: #fff5f5; color: var(--danger); }
.lead-status-follow-up .lead-status-pill,
.lead-status-quoted .lead-status-pill { background: #fffbeb; color: var(--warn); }
.lead-card-sub {
  margin-top: 3px;
  color: var(--text-dim);
  font-size: 0.88rem;
  line-height: 1.35;
}
.lead-phone-wrap {
  margin-top: 10px;
  max-width: 360px;
}
.lead-detail-grid {
  display: flex;
  align-items: stretch;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 10px;
}
.lead-detail {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 30px;
  padding: 6px 9px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-soft);
  color: var(--text-dim);
  font-size: 0.8rem;
}
.lead-detail .icon {
  width: 15px;
  height: 15px;
  flex: none;
  stroke-width: 1.9;
}
.lead-detail.is-due {
  border-color: #f2c6c0;
  background: #fff5f5;
  color: var(--danger);
  font-weight: 600;
}
.lead-followup-label {
  position: relative;
  cursor: pointer;
}
.lead-followup-label:hover {
  border-color: var(--accent);
}
.lead-followup-input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: transparent;
  opacity: 0;
  cursor: pointer;
}
.lead-side-row {
  display: flex;
  gap: 8px;
}
.lead-side-row .lead-notes-btn { width: auto; flex: 1; }
.lead-notes-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  width: 100%;
  min-height: 36px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--card);
  color: var(--text-dim);
  padding: 7px 12px;
  font: 600 0.78rem var(--font-display);
  cursor: pointer;
  white-space: nowrap;
}
.lead-notes-btn .icon { width: 15px; height: 15px; flex: none; stroke-width: 1.9; }
.lead-notes-btn:hover, .lead-notes-btn:focus-visible {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--card-hover);
}
.lead-notes-btn.has-notes {
  border-color: #86cfa3;
  background: var(--card);
  color: #14783e;
}
.lead-notes-btn.has-notes:hover,
.lead-notes-btn.has-notes:focus-visible {
  border-color: #42a96c;
  background: var(--card);
  color: #0f6a35;
}
.lead-notes-btn.has-notes .lead-notes-count {
  background: #e4f8ec;
  color: #14783e;
}
.lead-notes-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.7rem;
  font-weight: 700;
}
.lead-notes-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 320px;
  overflow-y: auto;
  margin-bottom: 14px;
}
.lead-note-row {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  background: var(--bg-soft);
}
.lead-note-row p { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.lead-note-row small { display: block; margin-top: 6px; color: var(--text-dim); font-size: 0.76rem; }
.lead-notes-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.lead-card-side {
  grid-area: side;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  width: min(100%, 248px);
  justify-self: end;
}
.lead-card-status {
  width: 100%;
  min-height: 38px;
  padding: 8px 10px;
  font-size: 0.84rem;
  font-weight: 600;
}
.lead-card-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}
.lead-card-actions button {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--card);
  color: var(--text-dim);
  padding: 7px 12px;
  font: 600 0.78rem var(--font-display);
  cursor: pointer;
}
.lead-card-side .lead-notes-btn {
  min-height: 38px;
}
.lead-card-actions button:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--card-hover);
}
.lead-card-actions .danger-text:hover {
  border-color: var(--danger);
  color: var(--danger) !important;
}
.ops-empty {
  margin: 0;
  color: var(--text-dim);
  font-size: 0.86rem;
}
.expense-total {
  text-align: right;
}
.expense-total span {
  display: block;
  color: var(--text-dim);
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.expense-total strong {
  display: block;
  margin-top: 2px;
  color: var(--danger);
  font-size: 1.25rem;
  font-weight: 500;
}
.expenses-workspace { margin-top: 14px; }
.expenses-topbar { grid-template-columns: minmax(240px, 1fr) auto; }
.expense-category-chips { margin-top: 4px; }
.expenses-heading-row { align-items: center; }
.expense-breakdown {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}
.expense-breakdown-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: var(--radius-md);
  background: var(--card);
  border: 1px solid var(--border);
  font-size: 0.82rem;
}
.expense-breakdown-item span { color: var(--text-dim); }
.expense-breakdown-item strong { color: var(--text); }
.dashboard-kpi-card {
  min-height: 152px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  position: relative;
  overflow: hidden;
}
.dashboard-kpi-card::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 3px;
  background: transparent;
}
.dashboard-kpi-card.is-warn::before { background: var(--warn); }
.dashboard-kpi-card.is-urgent::before { background: #d97706; }
.dashboard-kpi-card.is-clickable {
  cursor: pointer;
  transition: transform 0.14s ease, border-color 0.14s ease, box-shadow 0.14s ease;
}
.dashboard-kpi-card.is-clickable:hover {
  transform: translateY(-1px);
  border-color: #b8c5d8;
  box-shadow: 0 2px 4px rgba(15, 23, 42, 0.06), 0 12px 22px rgba(15, 23, 42, 0.07);
}
.dashboard-card-top {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}
.dashboard-card-icon {
  width: 34px;
  height: 34px;
  display: inline-grid;
  place-items: center;
  border-radius: var(--radius-sm);
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid #d4def1;
}
.dashboard-card-label,
.dashboard-eyebrow {
  color: var(--text-dim);
  font-family: var(--font-display);
  font-size: 0.74rem;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.dashboard-card-value {
  display: block;
  color: var(--text);
  font-family: var(--font-display);
  font-size: clamp(1.65rem, 3vw, 2.15rem);
  line-height: 1;
  letter-spacing: -0.03em;
}
.dashboard-card-sub {
  color: var(--text-dim);
  font-size: 0.88rem;
  font-weight: 500;
}
.dashboard-progress {
  width: 100%;
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--bg-soft);
  border: 1px solid #dde5f0;
}
.dashboard-progress span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), #3b82f6);
}
.today-focus-card {
  padding: 18px;
}
.today-focus-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}
.today-focus-header h2 {
  margin: 2px 0 0;
  font-family: var(--font-display);
  font-size: 1.35rem;
  line-height: 1.1;
  letter-spacing: -0.02em;
}
.dashboard-eyebrow { margin: 0; }
.today-focus-date {
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: 0.76rem;
  font-weight: 500;
  white-space: nowrap;
}
.today-focus-list {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  padding-top: 14px;
}
.today-focus-item {
  min-height: 112px;
  padding: 14px;
  text-align: left;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 12px;
  font: inherit;
}
.today-focus-item.is-clickable {
  cursor: pointer;
  background: #fff;
}
.today-focus-item.is-clickable:hover {
  border-color: #b8c5d8;
  background: var(--card-hover);
}
.today-focus-item:disabled {
  opacity: 1;
  cursor: default;
}
.today-focus-item strong {
  display: block;
  font-weight: 500;
}
.today-focus-item small {
  display: block;
  margin-top: 4px;
  color: var(--text-dim);
  font-size: 0.78rem;
  line-height: 1.25;
}
.today-focus-item b {
  color: var(--accent);
  font-family: var(--font-display);
  font-size: 1.35rem;
  letter-spacing: -0.02em;
}
.today-focus-empty {
  margin: 14px 0 0;
  color: var(--text-dim);
  font-weight: 500;
}

@media (max-width: 1100px) {
  .dashboard-kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .today-focus-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 680px) {
  .dashboard-kpi-grid,
  .today-focus-list { grid-template-columns: 1fr; }
  .dashboard-target-card,
  .dashboard-target-form {
    grid-template-columns: 1fr;
  }
  .target-card-create,
  .target-board,
  .leads-topbar { grid-template-columns: 1fr; position: static; }
  .leads-heading-row { align-items: start; flex-direction: column; }
  .lead-card {
    grid-template-columns: 48px minmax(0, 1fr);
    grid-template-areas:
      "avatar main"
      "side side";
    gap: 12px;
    padding: 14px;
  }
  .lead-avatar {
    width: 46px;
    height: 46px;
    border-radius: var(--radius-sm);
  }
  .lead-card-side {
    width: 100%;
    justify-self: stretch;
  }
  .lead-card-actions { justify-content: stretch; }
  .lead-card-actions button { flex: 1; }
  .lead-phone-wrap { max-width: none; }
  .dashboard-target-message { grid-column: 1; }
  .dashboard-kpi-card { min-height: 134px; }
  .today-focus-header { flex-direction: column; }
}

/* ---------- Buttons / inputs (shared) ---------- */
.primary-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  background: var(--accent);
  border: 1px solid var(--accent);
  color: #fff;
  border-radius: var(--radius-sm);
  padding: 11px 16px;
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  transition: filter 0.15s, transform 0.1s;
}
.primary-btn:active { transform: scale(0.98); }
.primary-btn:hover { filter: brightness(1.1); }
.primary-btn:disabled { opacity: 0.55; cursor: default; }
.ghost-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 10px 13px;
  font-size: 1rem;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}
.ghost-btn:hover { background: var(--card-hover); }
.ghost-btn:active { transform: scale(0.97); }
.icon-btn { width: 42px; height: 42px; padding: 0; }
.icon-btn .icon { width: 19px; height: 19px; }
.danger-btn {
  color: var(--danger);
  border-color: rgba(180, 35, 24, 0.32);
}
.danger-btn:hover { background: rgba(180, 35, 24, 0.08); }
.primary-btn.danger-btn {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}
.primary-btn.danger-btn:hover { filter: brightness(1.08); }
.text-input {
  width: 100%;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 1rem;
  padding: 11px 13px;
  outline: none;
  box-sizing: border-box;
  font-family: inherit;
}
.text-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(31, 95, 191, 0.12);
}
.field-label {
  display: block;
  font-size: 0.74rem;
  color: var(--text-dim);
  font-weight: 500;
  margin: 0 0 5px 2px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.field-error {
  color: var(--danger);
  font-size: 0.85rem;
  margin: 10px 0 0;
}
.field-hint {
  text-transform: none;
  font-weight: 500;
  letter-spacing: 0;
  color: var(--text-dim);
  font-size: 0.78rem;
}

/* ---------- Issue tags: multi-select toggle chips ---------- */
.issue-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}
.issue-toggle {
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text-dim);
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}
.issue-toggle:hover { background: var(--card-hover); }
.issue-toggle.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.issue-other-input { margin-top: 14px; }

/* Button on the form that opens the issue-picker modal */
.issue-select-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 11px 13px;
  font-size: 1rem;
  color: var(--text-dim);
  cursor: pointer;
  font-family: inherit;
}
.issue-select-btn:hover { background: var(--card-hover); }
.issue-select-btn.has-selection #issueSelectLabel,
.issue-select-btn.has-selection #apptIssueSelectLabel,
.issue-select-btn.has-selection { color: var(--text); }
.issue-select-chevron { color: var(--text-dim); width: 18px; height: 18px; }

/* Read-only issue chips shown on a ticket card, or as a selection summary */
.issue-tags-readonly { margin-top: 6px; }
.issue-chip {
  display: inline-block;
  background: var(--bg-soft);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 3px 8px;
  font-size: 0.72rem;
  font-weight: 500;
  margin: 0 6px 6px 0;
}
.issue-chip.muted { color: var(--text-dim); font-weight: 500; background: none; border-style: dashed; }

/* ---------- Setup card ---------- */
.setup-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 16px;
  margin-top: 6px;
  box-shadow: var(--shadow);
}
.setup-title { margin: 0 0 6px; font-family: var(--font-display); font-size: 1.1rem; }
.setup-sub { margin: 0 0 16px; font-size: 0.85rem; color: var(--text-dim); }
.setup-card .field-label { margin-top: 12px; }
.setup-card .primary-btn { width: 100%; margin-top: 16px; }
.settings-maintenance { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--border); }
.settings-help { margin: 5px 0 12px; color: var(--text-dim); font-size: 0.82rem; line-height: 1.45; }
.settings-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.settings-actions .ghost-btn { justify-content: center; min-height: 42px; }
.settings-actions .danger-btn { grid-column: 1 / -1; }
.settings-back { width: 100%; justify-content: center; margin-top: 12px; }
.technician-settings {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.technician-create-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: stretch;
}
.technician-create-row .primary-btn {
  width: auto;
  min-height: 44px;
  margin-top: 0;
  padding-inline: 14px;
}
.technician-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 12px;
}
.technician-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 44px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-soft);
}
.technician-row span {
  min-width: 0;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--text);
}
.technician-row .icon {
  width: 17px;
  height: 17px;
  color: var(--accent);
}
.technician-delete {
  width: 36px;
  min-height: 36px;
  padding: 0;
  color: var(--danger);
  flex: none;
}
.technician-delete .icon { width: 16px; height: 16px; }
.technician-default {
  flex: none;
  color: var(--text-dim);
  font-size: 0.72rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
@media (max-width: 420px) {
  .technician-create-row { grid-template-columns: 1fr; }
  .technician-create-row .primary-btn { width: 100%; }
}
.technician-combobox {
  position: relative;
  z-index: 1200;
}
.technician-combobox .text-input {
  padding-right: 44px;
}
.technician-dropdown-btn {
  position: absolute;
  right: 6px;
  top: 6px;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-dim);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.technician-dropdown-btn:hover,
.technician-combobox.open .technician-dropdown-btn {
  background: var(--accent-soft);
  color: var(--accent);
}
.technician-dropdown-btn .icon {
  width: 16px;
  height: 16px;
  transition: transform 0.15s ease;
}
.technician-combobox.open .technician-dropdown-btn .icon {
  transform: rotate(180deg);
}
.technician-dropdown {
  position: absolute;
  z-index: 2000;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  max-height: min(380px, 48vh);
  overflow-y: auto;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--card);
  box-shadow: var(--shadow);
}
.technician-option {
  width: 100%;
  min-height: 42px;
  display: flex;
  align-items: center;
  gap: 8px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  padding: 9px 10px;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
}
.technician-option:hover,
.technician-option:focus-visible,
.technician-option.active {
  background: var(--accent-soft);
  color: var(--accent);
  outline: none;
}
.technician-option.add-option {
  color: var(--price);
}
.technician-option.add-option .icon {
  width: 16px;
  height: 16px;
}

.device-combobox {
  position: relative;
  z-index: 20;
}
.device-combobox.open {
  z-index: 40;
}
.device-combobox .text-input {
  padding-right: 44px;
}
.device-dropdown-btn {
  position: absolute;
  right: 6px;
  top: 6px;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-dim);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.device-dropdown-btn:hover,
.device-combobox.open .device-dropdown-btn {
  background: var(--accent-soft);
  color: var(--accent);
}
.device-dropdown-btn .icon {
  width: 16px;
  height: 16px;
  transition: transform 0.15s ease;
}
.device-combobox.open .device-dropdown-btn .icon {
  transform: rotate(180deg);
}
.device-dropdown {
  position: absolute;
  z-index: 1;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  max-height: min(380px, 48vh);
  overflow-y: auto;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--card);
  box-shadow: var(--shadow);
}
.device-option {
  width: 100%;
  min-height: 42px;
  display: flex;
  align-items: center;
  gap: 8px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  padding: 9px 10px;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
}
.device-option:hover,
.device-option:focus-visible,
.device-option.active {
  background: var(--accent-soft);
  color: var(--accent);
  outline: none;
}
.device-dropdown-empty { padding: 9px 10px; color: var(--text-dim); font-size: 0.86rem; }

/* ---------- Toolbar ---------- */
.repairs-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

/* Fixed bottom-right so it's reachable without scrolling back to the top of
   a long ticket list; sits inside #view-intake so the existing
   `.view[hidden] { display: none }` rule hides it for free on other tabs.
   z-index 50 stays below .modal-backdrop's 100, so opening the device-log
   modal correctly dims/covers it instead of floating above it. */
.intake-action-row {
  display: flex;
  justify-content: flex-end;
  margin: 0 0 12px;
}
.intake-fab {
  position: static;
  min-width: 134px;
  height: 42px;
  padding: 0 15px;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  background: #111827;
  border: 1px solid #111827;
  color: #fff;
  font: 500 0.9rem var(--font-display);
  letter-spacing: -0.01em;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.22), 0 8px 18px rgba(15, 23, 42, 0.12);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s, box-shadow 0.15s;
}
.intake-fab .icon { width: 17px; height: 17px; stroke-width: 2; }
.intake-fab:hover {
  background: #0f172a;
  border-color: #0f172a;
  box-shadow: 0 2px 4px rgba(15, 23, 42, 0.24), 0 10px 22px rgba(15, 23, 42, 0.14);
}
.intake-fab:active { transform: scale(0.98); }
.intake-fab:focus-visible { outline: 2px solid #94a3b8; outline-offset: 3px; }
.intake-filter-bar {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  min-height: 62px;
  margin: 0 0 16px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--card);
  box-shadow: var(--shadow);
}
.intake-status-filter-wrap {
  width: 184px;
}
.intake-status-select {
  width: 100%;
  min-height: 42px;
  padding: 8px 34px 8px 12px;
  border: 0;
  border-radius: var(--radius-md);
  background: var(--bg-soft);
  color: var(--text);
  font: 500 0.9rem var(--font-display);
  outline: none;
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
}
.intake-status-filter-wrap::after {
  content: "";
  position: absolute;
  right: 13px;
  top: 50%;
  width: 8px;
  height: 8px;
  border-right: 2px solid var(--text-dim);
  border-bottom: 2px solid var(--text-dim);
  transform: translateY(-65%) rotate(45deg);
  pointer-events: none;
}
.intake-search-field {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  min-height: 42px;
  padding: 0 10px;
  border-left: 1px solid var(--border);
  color: var(--text-dim);
}
.intake-search-field .icon {
  width: 20px;
  height: 20px;
}
.intake-search-field input {
  width: 100%;
  min-height: 40px;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font: 500 0.98rem var(--font-display);
}
.intake-search-field input::placeholder {
  color: var(--text-dim);
}

@media (max-width: 620px) {
  .intake-action-row { justify-content: stretch; }
  .intake-fab { width: 100%; }
  .intake-filter-bar {
    grid-template-columns: 1fr;
    gap: 8px;
  }
  .intake-status-filter-wrap { width: 100%; }
  .intake-search-field {
    border-left: 0;
    border-top: 1px solid var(--border);
    padding-top: 8px;
  }
}

/* ---------- Intake form ---------- */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.form-field-full { grid-column: 1 / -1; }
.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 14px;
}
@media (max-width: 460px) {
  .form-grid { grid-template-columns: 1fr; }
}

/* ---------- Form polish: section labels, custom selects ---------- */
.form-section-label {
  font-family: var(--font-display);
  font-size: 0.7rem;
  font-weight: 500;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 18px 0 10px;
}
.form-section-label:first-child { margin-top: 2px; }
.form-step[hidden],
.form-actions > [hidden] { display: none !important; }
.form-progress { display: flex; align-items: flex-start; gap: 7px; margin: 0 0 22px; }
/* Quick-log from a price row already knows the device/issue, so the wizard
   skips from Customer details to Payment — collapse the middle step visually. */
#intakeFormModal.quick-log [data-progress-step="2"],
#intakeFormModal.quick-log .form-progress-line:first-of-type {
  display: none;
}
#repairCostField[hidden] { display: none; }
.quoted-price-summary {
  margin: -4px 0 16px;
  padding: 10px 13px;
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.88rem;
  font-weight: 500;
}
.form-progress-step { position: relative; display: flex; align-items: center; justify-content: center; flex: none; width: 28px; height: 28px; border: 1px solid var(--border); border-radius: 50%; color: var(--text-dim); font-size: 0.74rem; font-weight: 500; line-height: 1; }
.form-progress-step > span { position: absolute; top: calc(100% + 10px); left: 50%; transform: translateX(-50%); color: var(--text-dim); font-size: 0.67rem; font-weight: 500; line-height: 1; white-space: nowrap; }
.form-progress-step.active { border-color: var(--accent); background: var(--accent); color: #fff; }
.form-progress-step.complete { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.form-progress-step.active > span,
.form-progress-step.complete > span { color: var(--accent); }
.form-progress-line { height: 1px; flex: 1; min-width: 18px; margin-top: 14px; background: var(--border); }
.form-progress-line.complete { background: var(--accent); }
.form-step-heading { margin: 0 0 18px; }
.form-step-heading .form-section-label { margin: 0 0 5px; }
.form-step-heading h4 { margin: 0; font-family: var(--font-display); font-size: 1.18rem; }
.form-step-heading p:last-child { margin: 5px 0 0; color: var(--text-dim); font-size: 0.88rem; line-height: 1.45; }
.invoice-request {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-soft);
  color: var(--text);
  cursor: pointer;
}
.invoice-request input { width: 18px; height: 18px; margin: 1px 0 0; accent-color: var(--accent); flex: none; }
.invoice-request strong, .invoice-request small { display: block; }
.invoice-request strong { font-size: 0.9rem; }
.invoice-request small { margin-top: 2px; color: var(--text-dim); font-size: 0.78rem; line-height: 1.35; }
.form-success { text-align: center; padding: 24px 8px 12px; }
.success-check {
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  margin: 0 auto 18px;
  border-radius: 50%;
  background: rgba(15, 122, 76, 0.12);
  color: var(--price);
  font-size: 2rem;
  font-weight: 500;
}
.form-success .form-step-heading { margin-bottom: 0; }

.select-wrap { position: relative; }
.select-input {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 36px;
  cursor: pointer;
}
.select-wrap::after {
  content: "";
  position: absolute;
  right: 14px;
  top: 50%;
  width: 8px;
  height: 8px;
  border-right: 2px solid var(--text-dim);
  border-bottom: 2px solid var(--text-dim);
  transform: translateY(-65%) rotate(45deg);
  pointer-events: none;
}

/* ---------- Ticket cards ---------- */
.ticket {
  background: var(--card);
  border: 1px solid var(--border);
  border-left: 4px solid var(--status-dot, var(--border));
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.ticket-head {
  display: grid;
  grid-template-columns: 64px minmax(180px, 0.85fr) minmax(180px, 1.45fr) minmax(128px, auto) 44px;
  grid-template-areas: "thumb identity repair status activity";
  align-items: center;
  gap: 16px;
  min-height: 104px;
  padding: 16px 18px;
  cursor: pointer;
}
.ticket-head:hover { background: var(--card-hover); }
.ticket-head:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.ticket-device-thumb {
  grid-area: thumb;
  display: grid;
  place-items: center;
  width: 64px;
  height: 64px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: linear-gradient(145deg, var(--bg-soft), var(--card));
  color: var(--accent);
}
.ticket-device-fallback { width: 30px; height: 30px; stroke-width: 1.6; }
.ticket-device-thumb img { display: none; width: 100%; height: 100%; object-fit: contain; padding: 9px; }
.ticket-device-thumb.has-image img { display: block; }
.ticket-device-thumb.has-image .ticket-device-fallback { display: none; }
.ticket-identity { grid-area: identity; min-width: 0; }
.ticket-num {
  display: block;
  margin-bottom: 3px;
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--text-dim);
  letter-spacing: 0.02em;
}
.ticket-customer {
  font-size: 1rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ticket-sub {
  margin-top: 1px;
  font-size: 0.86rem;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ticket-repair {
  grid-area: repair;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 5px;
  min-width: 0;
}
.ticket-repair-label {
  color: var(--text-dim);
  font-size: 0.68rem;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.ticket-repair .issue-tags {
  justify-content: flex-start;
  margin-top: 0;
  max-width: 100%;
}
.ticket-status {
  grid-area: status;
  justify-self: end;
  min-width: 128px;
  text-align: right;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 7px;
}
.ticket-activity {
  grid-area: activity;
  justify-self: end;
}
.ticket-head.no-click { cursor: default; }
.ticket-head.no-click:hover { background: none; }
.ticket-tech-label { font-size: 0.72rem; color: var(--text-dim); }
.ticket-row-actions { display: flex; gap: 6px; }
.ticket-status button[data-complete],
.ticket-status button[data-delete] {
  min-height: 30px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-soft);
  color: var(--text-dim);
  padding: 5px 10px;
  font-size: 0.72rem;
  font-weight: 500;
  cursor: pointer;
}
.ticket-status button[data-complete]:hover { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.ticket-status button[data-delete] { color: #c0392b; border-color: #f3c9c2; }
.ticket-status button[data-delete]:hover { background: #fdf0ee; }
.ticket-activity .activity-log-btn { width: 44px; height: 44px; }
@media (max-width: 760px) {
  .ticket-head {
    grid-template-columns: 64px minmax(0, 1fr) auto;
    grid-template-areas:
      "thumb identity activity"
      "phone phone phone"
      "repair repair status";
    align-items: start;
    gap: 12px;
    padding: 14px;
  }
  .ticket-status { min-width: 0; align-self: center; }
  .ticket-activity { align-self: start; }
  .ticket-repair { padding-top: 2px; }
  .ticket-identity .ticket-phone { display: none; }
  .ticket-head .ticket-phone-row { display: block; grid-area: phone; }
}
@media (max-width: 390px) {
  .ticket-head {
    grid-template-columns: 56px minmax(0, 1fr) auto;
    gap: 10px;
    padding: 12px;
  }
  .ticket-device-thumb { width: 56px; height: 56px; border-radius: var(--radius-md); }
  .ticket-device-thumb img { padding: 8px; }
}
/* Full-width duplicate of the phone link, shown only on the narrow mobile
   ticket-head layout where the identity column is too cramped for it. */
.ticket-phone-row { display: none; }
/* Tap-to-call number shown right on the card */
.ticket-phone {
  display: flex;
  width: 100%;
  box-sizing: border-box;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  margin-top: 6px;
  padding: 8px 12px 8px 10px;
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.9rem;
  font-weight: 500;
  font-family: var(--font-mono);
  text-decoration: none;
  transition: background 0.15s, transform 0.1s;
}
.ticket-phone:hover { background: #dde6fb; }
.ticket-phone:active { transform: scale(0.97); }
.ticket-phone-icon { width: 17px; height: 17px; stroke-width: 1.9; }
.ticket-phone.no-phone {
  background: var(--bg-soft);
  color: var(--text-dim);
  font-weight: 500;
  font-family: inherit;
}
.status-badge {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.7rem;
  font-weight: 500;
  padding: 5px 10px;
  border-radius: var(--radius-sm);
  white-space: nowrap;
  background: var(--status-bg, var(--accent-soft));
  color: var(--status-ink, var(--accent));
}
.status-badge::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--status-dot, currentColor);
}
.status-badge-btn {
  border: none;
  font-family: inherit;
  cursor: pointer;
}
.status-badge-btn:hover, .status-badge-btn:focus-visible { filter: brightness(0.94); }
.status-badge-btn:focus-visible { outline: 2px solid var(--status-ink, var(--accent)); outline-offset: 1px; }
.ticket-body {
  display: none;
  padding: 4px 15px 15px;
  border-top: 1px solid var(--border);
}
.ticket.open .ticket-body { display: block; }
.ticket-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}
.ticket-row .k { color: var(--text-dim); }
.ticket-row .v { text-align: right; font-weight: 500; }
.ticket-row .v.mono { font-family: var(--font-mono); }
.ticket-actions { margin-top: 14px; }
.status-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 8px;
}
.status-set {
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--text-dim);
  border-radius: var(--radius-sm);
  padding: 7px 12px;
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease, background 0.15s ease;
}
.status-set:hover { background: var(--card-hover); color: var(--text); }
.status-set.current { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.ticket-tech-btn {
  min-height: 30px;
  max-width: 190px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-soft);
  color: var(--text-dim);
  padding: 5px 10px;
  font-size: 0.72rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ticket-tech-btn:hover,
.ticket-tech-btn:focus-visible {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
  outline: none;
}
.ticket-edit-btn { margin-top: 12px; }
.ticket-client-btn { margin-top: 12px; margin-left: 8px; }
.ticket-delete-btn { margin-top: 12px; margin-left: 8px; color: var(--danger); }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

.repair-loading {
  text-align: center;
  color: var(--text-dim);
  font-size: 0.9rem;
  padding: 30px 0;
}

.ticket-tel {
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
}
.ticket-tel:hover { text-decoration: underline; }

/* Status colour map — one palette powers card borders, pills, and filters. */
.st-received {
  --status-bg: #e8eef8;
  --status-border: #c7d5ee;
  --status-ink: #1f5fbf;
  --status-dot: #1f5fbf;
}
.st-diagnosing {
  --status-bg: #f1eafe;
  --status-border: #dfcffb;
  --status-ink: #7c3aed;
  --status-dot: #7c3aed;
}
.st-parts {
  --status-bg: #fffbeb;
  --status-border: #f3d9a7;
  --status-ink: #a85f12;
  --status-dot: #c8791a;
}
.st-progress {
  --status-bg: #ecfdf5;
  --status-border: #bfe8d8;
  --status-ink: #047857;
  --status-dot: #0d946b;
}
.st-repaired {
  --status-bg: #ecfdf5;
  --status-border: #bfe8d8;
  --status-ink: #047857;
  --status-dot: #047857;
}
.st-pickedup {
  --status-bg: #eef2f7;
  --status-border: #d7dee8;
  --status-ink: #607086;
  --status-dot: #94a3b8;
}
.st-cancelled {
  --status-bg: #fff5f5;
  --status-border: #f4c7c3;
  --status-ink: #b42318;
  --status-dot: #b42318;
}

/* ---------- Mono utility (ticket IDs, PIN dots) ---------- */
.mono { font-family: var(--font-mono); }

/* ---------- Activity log (history timeline) ---------- */
.activity-log-backdrop { z-index: 110; }
.activity-log-panel { max-width: 480px; }
.activity-log-section + .activity-log-section { margin-top: 18px; }
.activity-log-note { margin-top: 8px; }
.activity-log-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--card);
  color: var(--text-dim);
  cursor: pointer;
  flex: none;
}
.activity-log-btn .icon { width: 17px; height: 17px; }
.activity-log-btn:hover,
.activity-log-btn:focus-visible {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
  outline: none;
}
.activity-log-badge {
  position: absolute;
  top: -5px;
  right: -5px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #fff;
  font-size: 0.62rem;
  font-weight: 500;
  line-height: 16px;
  text-align: center;
}
.ticket-detail-hero-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex: none;
}
.ticket-detail-hero-main { min-width: 0; flex: 1; }
.history-list {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.history-item {
  display: flex;
  gap: 10px;
  align-items: flex-start;
}
.history-dot {
  flex: none;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  margin-top: 5px;
}
.history-msg { font-size: 0.88rem; font-weight: 500; }
.history-when { font-size: 0.72rem; color: var(--text-dim); margin-top: 1px; }

/* Subtle interaction polish */
.text-input, .primary-btn, .ghost-btn, .chip, .nav-btn {
  transition: border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}

/* ---------- Issue picker modal ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 5000;
  background: rgba(18, 24, 38, 0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
}
.modal-backdrop[hidden] { display: none; }
/* Applies to every modal that reuses this backdrop/panel pattern. Defined on
   the element itself, so it replays each time `hidden` is removed. */
.modal-backdrop:not([hidden]) { animation: modal-fade 0.18s ease; }
.modal-backdrop:not([hidden]) .modal-panel { animation: modal-pop 0.22s cubic-bezier(0.2, 0.8, 0.2, 1); }
@keyframes modal-fade {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes modal-pop {
  from { opacity: 0; transform: translateY(18px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
@media (min-width: 560px) {
  .modal-backdrop { align-items: center; padding: 20px; }
}
.modal-panel {
  position: relative;
  z-index: 1;
  background: var(--card);
  width: 100%;
  max-width: 480px;
  max-height: min(82vh, 640px);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  display: flex;
  flex-direction: column;
  box-shadow: 0 -8px 30px rgba(18, 24, 38, 0.18);
}
@media (max-width: 559px) {
  .modal-panel {
    height: 100dvh;
    max-height: none;
    border-radius: 0;
  }
}
@media (min-width: 560px) {
  .modal-panel { border-radius: var(--radius); box-shadow: var(--shadow); }
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
  flex: none;
}
.modal-header h3 { margin: 0; font-family: var(--font-display); font-size: 1.05rem; }
.modal-eyebrow { margin: 0 0 2px; color: var(--text-dim); font-size: 0.7rem; font-weight: 500; letter-spacing: 0.06em; text-transform: uppercase; }
.modal-close {
  background: var(--bg-soft);
  border: none;
  color: var(--text-dim);
  width: 30px;
  height: 30px;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.modal-close .icon { width: 17px; height: 17px; }
.modal-close:hover { background: var(--border); }
.modal-body {
  padding: 16px 18px;
  overflow-y: auto;
  flex: 1;
}
.modal-footer {
  padding: 14px 18px max(env(safe-area-inset-bottom), 14px);
  border-top: 1px solid var(--border);
  flex: none;
}
.modal-footer .primary-btn { width: 100%; }
.modal-footer .form-actions { margin-top: 0; }
.modal-footer .form-actions .ghost-btn,
.modal-footer .form-actions .primary-btn { flex: 1; width: auto; }
#technicianModal .modal-panel {
  max-width: min(760px, calc(100vw - 32px));
  max-height: min(92vh, 760px);
}
#technicianModal .modal-body {
  min-height: 360px;
  overflow: visible;
}
.technician-modal-footer {
  display: flex;
  gap: 8px;
}
.technician-modal-footer .ghost-btn,
.technician-modal-footer .primary-btn {
  flex: 1;
  width: auto;
}

/* ---------- Ticket detail sheet ---------- */
.ticket-modal-panel { max-width: 560px; }
.ticket-detail-hero { display: flex; align-items: center; gap: 12px; padding: 2px 0 16px; border-bottom: 1px solid var(--border); }
.ticket-device-icon { width: 42px; height: 42px; display: inline-flex; align-items: center; justify-content: center; flex: none; border-radius: var(--radius-md); background: var(--accent-soft); color: var(--accent); }
.ticket-device-icon .icon { width: 22px; height: 22px; }
.ticket-detail-title { margin: 0; font-size: 1.05rem; font-family: var(--font-display); }
.ticket-detail-issue { margin: 2px 0 0; color: var(--danger); font-size: 0.84rem; font-weight: 500; overflow-wrap: anywhere; }
.ticket-detail-id { margin: 2px 0 0; font-size: 0.72rem; color: var(--text-dim); }
.ticket-detail-section { margin-top: 18px; }
.ticket-detail-section .field-label { margin-bottom: 8px; }
.ticket-detail-grid { border-top: 1px solid var(--border); }
.ticket-detail-row { display: grid; grid-template-columns: 26px minmax(88px, 0.6fr) minmax(0, 1.4fr) auto; align-items: center; gap: 8px; padding: 10px 0; border-bottom: 1px solid var(--border); font-size: 0.88rem; }
.ticket-detail-row .icon { width: 17px; height: 17px; color: var(--text-dim); }
.ticket-detail-label { color: var(--text-dim); }
.ticket-detail-value { min-width: 0; text-align: right; font-weight: 500; overflow-wrap: anywhere; }
.ticket-detail-value.money-positive { color: var(--price); }
.ticket-detail-value.money-due { color: var(--danger); }
.ticket-detail-value .ticket-tel { font-size: inherit; }
.ticket-detail-edit-btn { width: 28px; height: 28px; padding: 0; flex: none; }
.ticket-detail-edit-btn .icon { width: 14px; height: 14px; }
.ticket-detail-value.ticket-detail-editing { grid-column: 3 / span 2; display: flex; align-items: center; gap: 6px; text-align: left; }
.ticket-detail-value.ticket-detail-editing .ticket-inline-input { flex: 1; min-width: 0; padding: 6px 8px; font-size: 0.85rem; }
.ticket-detail-value.ticket-detail-editing .icon-btn { width: 28px; height: 28px; padding: 0; flex: none; }
.ticket-detail-value.ticket-detail-editing .icon-btn .icon { width: 14px; height: 14px; }
.ticket-inline-input.field-error-input { border-color: var(--danger); }
.ticket-media-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
  gap: 8px;
  margin-bottom: 10px;
}
.ticket-media-gallery .ops-empty { grid-column: 1 / -1; }
.ticket-media-item {
  position: relative;
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--card-hover);
  border: 1px solid var(--border);
}
.ticket-media-link {
  display: block;
  width: 100%;
  height: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
}
.ticket-media-item img,
.ticket-media-item video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.ticket-media-play {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.25);
  color: #fff;
  pointer-events: none;
}
.ticket-media-play .icon { width: 22px; height: 22px; }
.ticket-media-delete {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 22px;
  height: 22px;
  padding: 0;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.ticket-media-delete .icon { width: 12px; height: 12px; }
.ticket-media-add-btn { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.ticket-media-add-btn.is-uploading { opacity: 0.6; pointer-events: none; }
.form-media-pending { margin-bottom: 8px; }
.media-viewer-backdrop {
  z-index: 5200;
  align-items: stretch;
  padding: 0;
  background: rgba(5, 10, 20, 0.9);
}
.media-viewer-panel {
  width: 100%;
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  color: #fff;
  background: #050a14;
}
.media-viewer-topbar,
.media-viewer-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: max(env(safe-area-inset-top), 14px) 16px 12px;
}
.media-viewer-footer {
  padding: 12px 16px max(env(safe-area-inset-bottom), 14px);
  border-top: 1px solid rgba(255, 255, 255, 0.12);
}
.media-viewer-topbar h3 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.02rem;
}
.media-viewer-topbar .modal-eyebrow { color: rgba(255, 255, 255, 0.62); }
.media-viewer-close,
.media-viewer-nav {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  cursor: pointer;
}
.media-viewer-close {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
}
.media-viewer-close .icon,
.media-viewer-nav .icon {
  width: 20px;
  height: 20px;
}
.media-viewer-stage-wrap {
  position: relative;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr;
  align-items: center;
}
.media-viewer-stage {
  min-width: 0;
  min-height: 0;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px 56px;
}
.media-viewer-media {
  display: block;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}
video.media-viewer-media {
  width: min(100%, 1080px);
  height: auto;
  max-height: 100%;
  background: #000;
}
.media-viewer-nav {
  position: absolute;
  top: 50%;
  z-index: 1;
  width: 42px;
  height: 48px;
  border-radius: var(--radius-sm);
  transform: translateY(-50%);
}
.media-viewer-prev { left: 10px; }
.media-viewer-next { right: 10px; }
.media-viewer-nav:disabled {
  opacity: 0;
  pointer-events: none;
}
.media-viewer-counter {
  color: rgba(255, 255, 255, 0.72);
  font-size: 0.84rem;
}
.media-viewer-footer .ghost-btn {
  width: auto;
  border-color: rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}
.media-viewer-footer .ghost-btn[hidden] { display: none; }
@media (min-width: 760px) {
  .media-viewer-backdrop { padding: 18px; }
  .media-viewer-panel {
    min-height: 0;
    height: min(920px, calc(100dvh - 36px));
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.38);
  }
}
@media (max-width: 520px) {
  .media-viewer-stage { padding: 8px 0; }
  .media-viewer-nav {
    top: auto;
    bottom: 12px;
    transform: none;
  }
}
.field-optional { color: var(--text-dim); font-weight: 400; text-transform: none; }
.ticket-detail-notes { margin: 0; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 11px 12px; color: var(--text-dim); font-size: 0.88rem; white-space: pre-wrap; }
.ticket-modal-footer {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  align-items: stretch;
  gap: 8px;
}
.ticket-modal-footer .primary-btn,
.ticket-modal-footer .ghost-btn {
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 42px;
  padding-inline: 8px;
  white-space: normal;
  text-align: center;
  line-height: 1.2;
  font-size: clamp(0.72rem, 2.5vw, 0.92rem);
}
.ticket-modal-footer .icon {
  width: 16px;
  height: 16px;
}
.ticket-modal-footer .danger-btn {
  margin-left: 0;
}
.ticket-modal-footer .danger-btn .icon {
  width: 18px;
  height: 18px;
}
@media (max-width: 420px) {
  .ticket-modal-footer {
    gap: 6px;
    padding-inline: 10px;
  }
  .ticket-modal-footer .primary-btn,
  .ticket-modal-footer .ghost-btn {
    min-height: 40px;
    padding-inline: 5px;
    gap: 4px;
  }
}

/* ============ Appointments — Cal.com-style booking ============ */
.booking-card {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.booking-calendar-panel { padding: 24px; border-bottom: 1px solid var(--border); }
.booking-calendar-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.booking-calendar-header strong { font-family: var(--font-display); font-size: 1.15rem; }
.booking-calendar-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  text-align: center;
  color: var(--text-dim);
  font-size: 0.78rem;
  font-weight: 600;
  margin-bottom: 10px;
}
.booking-calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}
.booking-day {
  aspect-ratio: 1;
  max-width: 76px;
  max-height: 76px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 1.12rem;
  cursor: pointer;
}
.booking-day.is-empty { visibility: hidden; cursor: default; }
.booking-day:not(:disabled):hover { background: var(--card-hover); }
.booking-day.is-today { box-shadow: inset 0 0 0 1px var(--accent); }
.booking-day.is-selected { background: var(--accent); color: #fff; }
.booking-day:disabled { color: var(--text-dim); opacity: 0.4; cursor: not-allowed; }

.booking-slots-panel { padding: 24px; }
.booking-slots-label { margin: 0 0 14px; font-weight: 600; font-size: 1rem; }
.booking-slots-list { display: flex; flex-direction: column; gap: 8px; max-height: 420px; overflow-y: auto; }
.booking-slot-btn {
  padding: 12px 14px;
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  background: var(--card);
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 0.92rem;
  cursor: pointer;
  text-align: center;
}
.booking-slot-btn:hover { background: var(--accent-soft); }
.booking-slot-btn.is-selected { background: var(--accent); color: #fff; }
.booking-slot-btn.has-bookings { display: flex; align-items: center; justify-content: center; gap: 8px; }
.booking-slot-count {
  font-family: var(--font-sans, inherit);
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
}
.booking-slot-btn.is-selected .booking-slot-count { background: rgba(255, 255, 255, 0.25); color: #fff; }
.booking-slots-empty { color: var(--text-dim); font-size: 0.86rem; }
.booking-existing-list { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--border); }
.booking-existing-heading {
  margin: 0 0 8px;
  color: var(--text-dim);
  font-size: 0.74rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.booking-existing-row {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.86rem;
}
.booking-existing-row:last-child { border-bottom: none; }
.booking-existing-time { flex: none; font-family: var(--font-mono); color: var(--text-dim); font-size: 0.82rem; }
.booking-existing-details { color: var(--text); }

@media (min-width: 720px) {
  .booking-card { grid-template-columns: 1fr 240px; }
  .booking-calendar-panel { border-bottom: none; border-right: 1px solid var(--border); }
}

.booking-details-card {
  margin-top: 16px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}
.booking-selected-summary { margin: 0 0 14px; font-weight: 600; color: var(--accent); }

.booking-list-card {
  margin-top: 16px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}
.booking-list-title { margin: 0 0 14px; font-family: var(--font-display); font-size: 1.1rem; }
.booking-list { display: flex; flex-direction: column; gap: 10px; }
.booking-empty { color: var(--text-dim); font-size: 0.9rem; }
.booking-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.booking-row:hover { background: var(--card-hover); }
.booking-row:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.booking-row.is-completed { opacity: 0.6; }
.booking-row-main p { margin: 2px 0; color: var(--text-dim); font-size: 0.86rem; }
.booking-row-main small { color: var(--text-dim); font-size: 0.8rem; }
.booking-row-datetime { display: inline-flex; align-items: center; gap: 4px; }
.appt-reschedule-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  padding: 0;
  border: none;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--text-dim);
  cursor: pointer;
}
.appt-reschedule-btn .icon { width: 13px; height: 13px; stroke-width: 2; }
.appt-reschedule-btn:hover, .appt-reschedule-btn:focus-visible {
  color: var(--accent);
  background: var(--accent-soft);
}
.ticket-detail-row .appt-reschedule-btn { margin-left: auto; }
.reschedule-slots { max-height: 280px; }
.booking-row-actions { display: flex; gap: 8px; flex: none; }
.booking-row-actions button {
  border: 1px solid var(--border);
  background: var(--card);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  font-size: 0.8rem;
  cursor: pointer;
}
.booking-row-actions .danger-text { color: var(--danger); border-color: var(--danger); }

.appt-sidebar-subnav { display: none; }
.appt-subnav { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 18px; }
.appt-subnav-btn {
  padding: 10px 16px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--card);
  color: var(--text-dim);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
}
.appt-subnav-btn:hover { background: var(--card-hover); }
.appt-subnav-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.completed-repairs-section { margin-bottom: 24px; }
.completed-repairs-section .booking-list-title { margin-bottom: 12px; }
.completed-repairs-list,
.completed-repairs-list #completedTicketsList,
.completed-repairs-list #completedAppointmentsList {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
[data-completed-ticket] .booking-row-main { cursor: pointer; }

.source-tag {
  display: inline-block;
  margin-left: 6px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  vertical-align: middle;
}
.source-tag-checkin { background: var(--accent-soft); color: var(--accent); }
.source-tag-appointment { background: #fdf2e9; color: #b9650a; }

.booking-wizard-card {
  max-width: min(1200px, 100%);
  margin: 0 auto;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
}
.booking-wizard-card .booking-card { border: none; box-shadow: none; border-radius: 0; }
.appt-wizard-footer { border-top: 1px solid var(--border); margin-top: 18px; padding-top: 16px; background: none; }
.booking-list-card { max-width: min(1060px, 100%); margin-left: auto; margin-right: auto; }

.appt-device-row { display: flex; align-items: center; gap: 12px; }
.appt-device-row .text-input { flex: 1; }
.appt-device-row .device-combobox { flex: 1; }
.appt-device-thumb { flex: none; width: 56px; height: 56px; }

.technician-picker { display: flex; flex-wrap: wrap; gap: 10px; }
.technician-chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: 76px;
  border: none;
  background: none;
  color: var(--text);
  cursor: pointer;
  padding: 4px;
}
.technician-chip-avatar {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 1px solid var(--accent);
  background: var(--card);
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 600;
}
.technician-chip-avatar .icon { width: 20px; height: 20px; }
.technician-chip-name { font-size: 0.74rem; text-align: center; line-height: 1.25; color: var(--text-dim); }
.technician-chip.is-selected .technician-chip-avatar { background: var(--accent); color: #fff; }
.technician-chip.is-selected .technician-chip-name { color: var(--text); font-weight: 600; }

@media (min-width: 900px) {
  .nav-btn[data-target="appointments"]:not(.active) + .appt-sidebar-subnav,
  .nav-btn[data-target="targets"]:not(.active) + .appt-sidebar-subnav {
    display: none;
  }
  #view-targets > .targets-content-subnav {
    display: none;
  }
  .appt-sidebar-subnav {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin: -1px 0 6px 34px;
    padding: 0 0 2px;
  }
  .appt-sidebar-subnav .appt-subnav-btn {
    position: relative;
    justify-content: flex-start;
    min-height: 34px;
    padding: 7px 10px 7px 22px;
    border: 0;
    border-radius: var(--radius-sm);
    background: transparent;
    box-shadow: none;
    color: #475569;
    font-size: 0.84rem;
    font-weight: 500;
    text-align: left;
  }
  .appt-sidebar-subnav .appt-subnav-btn::before {
    content: "";
    position: absolute;
    left: 8px;
    top: 50%;
    width: 5px;
    height: 5px;
    border: 1px solid currentColor;
    border-radius: 50%;
    transform: translateY(-50%);
  }
  .appt-sidebar-subnav .appt-subnav-btn:hover {
    background: rgba(255, 255, 255, 0.64);
    color: var(--text);
  }
  .appt-sidebar-subnav .appt-subnav-btn.active {
    background: var(--accent);
    color: #fff;
  }
  .appt-sidebar-subnav .appt-subnav-btn.active::before {
    background: currentColor;
  }

  #view-appointments:not([hidden]) {
    display: flex;
    flex-direction: column;
    gap: clamp(8px, 1.2vh, 12px);
    height: 100dvh;
    max-width: none;
    padding-top: clamp(12px, 1.8vh, 20px);
    padding-bottom: clamp(12px, 1.8vh, 20px);
    overflow-y: auto;
  }
  #view-appointments > .info-banner {
    flex: none;
    margin: 0;
  }
  #view-appointments > .appt-content-subnav {
    display: none;
  }
  #view-appointments > .appt-panel[data-appt-panel-section="create"]:not([hidden]) {
    display: flex;
    flex: 1;
    min-height: 0;
  }
  #view-appointments .booking-wizard-card {
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: none;
    height: 100%;
    min-height: 0;
    margin: 0;
    padding: clamp(14px, 1.8vh, 20px);
    overflow: hidden;
  }
  #view-appointments .form-progress {
    flex: none;
    margin-bottom: clamp(16px, 2vh, 22px);
  }
  #view-appointments .booking-wizard-card .form-step:not([hidden]) {
    display: flex;
    flex: 1;
    flex-direction: column;
    min-height: 0;
  }
  #view-appointments .form-step-heading {
    flex: none;
    margin-bottom: clamp(10px, 1.5vh, 16px);
  }
  #view-appointments .booking-card {
    flex: 1;
    min-height: 0;
    grid-template-columns: minmax(360px, 1.75fr) minmax(190px, 0.8fr);
  }
  #view-appointments .booking-calendar-panel,
  #view-appointments .booking-slots-panel {
    min-height: 0;
    padding: clamp(14px, 1.8vh, 20px);
  }
  #view-appointments .booking-calendar-panel,
  #view-appointments .booking-slots-panel {
    display: flex;
    flex-direction: column;
  }
  #view-appointments .booking-calendar-header {
    flex: none;
    margin-bottom: clamp(8px, 1.3vh, 14px);
  }
  #view-appointments .booking-calendar-weekdays {
    flex: none;
    margin-bottom: 8px;
  }
  #view-appointments .booking-calendar-grid {
    flex: none;
    gap: 4px;
    align-content: start;
  }
  #view-appointments .booking-day {
    width: min(42px, 5.2vh);
    height: min(42px, 5.2vh);
    max-width: none;
    max-height: none;
    aspect-ratio: auto;
    font-size: clamp(0.88rem, 1.9vh, 1rem);
  }
  #view-appointments .booking-slots-label {
    flex: none;
    margin-bottom: 10px;
  }
  #view-appointments .booking-slots-list {
    flex: 1;
    min-height: 0;
    max-height: none;
    overflow-y: auto;
  }
  #view-appointments .booking-slot-btn {
    min-height: 38px;
    padding: 8px 12px;
    font-size: 0.86rem;
  }
  #view-appointments .appt-wizard-footer {
    flex: none;
    margin-top: clamp(10px, 1.4vh, 14px);
    padding-top: clamp(10px, 1.4vh, 14px);
  }
  #view-appointments .appt-wizard-footer .form-actions {
    margin-top: 0;
  }
}

@media (min-width: 900px) and (max-width: 1080px) {
  #view-appointments .booking-card {
    grid-template-columns: 1fr;
    overflow-y: auto;
  }
  #view-appointments .booking-calendar-panel {
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }
}

/* ---- Toasts (in-app replacement for browser alert() popups) ------------- */
.app-toasts {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  /* Above .modal-backdrop (5000) so save errors/confirmations are visible
     while a modal like the ticket detail sheet is open — that's exactly
     where inline edits happen. */
  z-index: 6000;
  width: min(440px, calc(100vw - 32px));
  pointer-events: none;
}
.app-toast {
  background: var(--text);
  color: #fff;
  border-radius: var(--radius-sm);
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.25);
  padding: 12px 16px;
  font-size: 0.88rem;
  line-height: 1.4;
  opacity: 1;
  transition: opacity 0.3s ease, transform 0.3s ease;
}
.app-toast.is-error { background: #b42318; }
.app-toast.is-leaving { opacity: 0; transform: translateY(6px); }

/* ---- WhatsApp client notifications --------------------------------------- */
.whatsapp-btn { color: #128c4b; border-color: #9ad9b8; }
.whatsapp-btn:hover { background: #ecfdf3; }
.status-notify-copy {
  width: 100%;
  margin: 0 0 4px;
  color: var(--text);
  font-size: 0.9rem;
  line-height: 1.45;
}
#statusModalOptions .primary-btn,
#statusModalOptions .ghost-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
