:root {
  --navy: #1f3864;
  --blue: #2e75b6;
  --blue-light: #bdd7ee;
  --bg: #f4f6f9;
  --card-bg: #ffffff;
  --text: #1a1a2e;
  --text-muted: #6b7280;
  --border: #e2e6ec;
  --danger: #c00000;
  --success: #1a7f37;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

.topbar {
  background: linear-gradient(135deg, var(--navy), var(--blue));
  color: #fff;
  padding: 18px 24px;
}

.topbar-inner {
  max-width: 1000px;
  margin: 0 auto;
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.brand { font-size: 22px; font-weight: 700; }
.brand-sub { font-size: 15px; opacity: 0.85; }

.topbar-account {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-version {
  font-size: 12px;
  font-family: "SF Mono", "Courier New", monospace;
  background: rgba(255, 255, 255, 0.15);
  padding: 3px 8px;
  border-radius: 12px;
  opacity: 0.9;
}

.account-email {
  font-size: 13px;
  opacity: 0.9;
}

.topbar-account .btn-secondary {
  background: transparent;
  color: #fff;
  border-color: rgba(255, 255, 255, 0.6);
  padding: 6px 14px;
  font-size: 13px;
}
.topbar-account .btn-secondary:hover {
  background: rgba(255, 255, 255, 0.15);
}

main {
  max-width: 1000px;
  margin: 24px auto;
  padding: 0 16px 48px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px 24px 24px;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04);
}

.card h2 {
  margin: 0 0 16px;
  font-size: 16px;
  color: var(--navy);
  border-bottom: 2px solid var(--blue);
  padding-bottom: 8px;
}

.grid {
  display: grid;
  gap: 14px 18px;
}

.grid-3 { grid-template-columns: repeat(3, 1fr); }

@media (max-width: 640px) {
  .grid-3 { grid-template-columns: 1fr; }
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 600;
}

input[type="date"] {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 14px;
  color: var(--text);
  background: #fff;
  font-weight: 400;
}

input:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(46, 117, 182, 0.15);
}

.presets {
  display: flex;
  gap: 6px;
}

.presets button {
  flex: 1;
  font-size: 12px;
  font-weight: 600;
  padding: 8px 6px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text-muted);
  cursor: pointer;
}
.presets button:hover { border-color: var(--blue); color: var(--blue); }

.row-actions {
  margin-top: 18px;
  display: flex;
  align-items: center;
  gap: 12px;
}

button {
  font-size: 14px;
  font-weight: 600;
  border-radius: 6px;
  border: none;
  padding: 10px 18px;
  cursor: pointer;
}

.btn-primary {
  background: var(--blue);
  color: #fff;
}
.btn-primary:hover { background: var(--navy); }

.btn-secondary {
  background: #fff;
  color: var(--blue);
  border: 1px solid var(--blue);
}
.btn-secondary:hover { background: var(--blue-light); }

.btn-danger {
  background: #fff;
  color: var(--danger);
  border: 1px solid var(--danger);
}
.btn-danger:hover { background: #fdecea; }

.status-text {
  font-size: 13px;
  color: var(--text-muted);
}
.status-text.error { color: var(--danger); }
.status-text.ok { color: var(--success); }

.kpi-row {
  display: flex;
  gap: 24px;
  flex-wrap: wrap;
}

.kpi {
  flex: 1;
  min-width: 200px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.kpi-label {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.kpi-value {
  font-size: 40px;
  font-weight: 700;
  color: var(--navy);
  line-height: 1.1;
}

.kpi-hint {
  font-size: 12px;
  color: var(--text-muted);
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  margin-bottom: 12px;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
  font-family: "SF Mono", "Courier New", monospace;
}

.legend-swatch {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  display: inline-block;
}

.chart-scroll {
  overflow-x: auto;
  padding-bottom: 4px;
}

.avg-label {
  font-size: 13px;
  color: var(--text-muted);
  margin: 0 0 12px;
}
.avg-label strong { color: var(--navy); }

.empty-state {
  font-size: 13px;
  fill: var(--text-muted);
}

.tabs {
  display: flex;
  gap: 8px;
}

.tab-btn {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 8px 8px 0 0;
  padding: 10px 18px;
  border-bottom: none;
}
.tab-btn:hover { color: var(--blue); }
.tab-btn.active {
  background: var(--card-bg);
  color: var(--navy);
  border-color: var(--border);
  box-shadow: 0 -1px 2px rgba(16, 24, 40, 0.04);
}

.tab-panel {
  display: flex;
  flex-direction: column;
  gap: 20px;
  margin-top: -20px;
}
.tab-panel[hidden] { display: none; }

.patterns-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.patterns-table th {
  text-align: left;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  border-bottom: 2px solid var(--border);
  padding: 8px 10px;
}

.patterns-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  font-family: "SF Mono", "Courier New", monospace;
}

.patterns-table td.status-text {
  font-family: inherit;
  text-align: center;
}

.card-hint {
  margin: -8px 0 16px;
  font-size: 13px;
  color: var(--text-muted);
}

.shop-setup-table .shop-id-cell {
  font-size: 12px;
  word-break: break-all;
}

.shop-setup-table td {
  vertical-align: middle;
}

.shop-setup-table input[type="text"] {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 13px;
  color: var(--text);
}

.shop-setup-table input[type="text"]:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(46, 117, 182, 0.15);
}

.shop-setup-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  white-space: nowrap;
}

.shop-setup-actions .btn-primary,
.shop-setup-actions .btn-secondary {
  padding: 6px 14px;
  font-size: 13px;
  white-space: nowrap;
}

.shop-map {
  height: 360px;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 16px;
}

.shop-setup-table input[type="number"] {
  width: 100px;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 13px;
  color: var(--text);
}

.shop-setup-table input[type="number"]:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(46, 117, 182, 0.15);
}

.shop-setup-table tr.picking {
  background: var(--blue-light);
}

.ads-setup-table td {
  vertical-align: middle;
}

.ads-setup-table input[type="number"] {
  width: 90px;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 13px;
  color: var(--text);
}

.ads-setup-table input[type="text"] {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 13px;
  color: var(--text);
}

.ads-setup-table input:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(46, 117, 182, 0.15);
}

.ads-setup-table .ads-remove-cell {
  white-space: nowrap;
}

.ads-setup-table .btn-danger {
  padding: 6px 14px;
  font-size: 13px;
}

/* A row with an edited-but-not-yet-saved field, in Shop Setup or Ads
   Setup. The badge is deliberate, not just the tinted background/border --
   color alone isn't an accessible way to convey state. */
.shop-setup-table tr.dirty,
.ads-setup-table tr.dirty {
  background: #fff8e1;
  box-shadow: inset 3px 0 0 #e08a00;
}

.dirty-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: #7a4a00;
  background: #ffe8b3;
  white-space: nowrap;
}

/* Without this, the rule above (same specificity as the browser's own
   [hidden] { display: none } default, but in the author stylesheet, which
   always wins ties over the UA stylesheet) keeps every badge visible
   regardless of its hidden attribute. */
.dirty-badge[hidden] {
  display: none;
}

.status-table .shop-id-cell {
  font-size: 12px;
  word-break: break-all;
}

.status-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
}

.status-dot-active { background: var(--success); }
.status-dot-maybe_active { background: #e08a00; }
.status-dot-inactive { background: var(--danger); }

.status-label {
  display: inline-flex;
  align-items: center;
  font-weight: 600;
  font-size: 13px;
}

.status-label.status-active { color: var(--success); }
.status-label.status-maybe_active { color: #e08a00; }
.status-label.status-inactive { color: var(--danger); }

.last-active-cell {
  font-size: 13px;
}

.patterns-table td.pattern-action-cell {
  font-family: inherit;
  text-align: right;
  white-space: nowrap;
}

.patterns-table td.pattern-action-cell .btn-secondary {
  padding: 5px 12px;
  font-size: 12px;
}

/* Leaflet's default .leaflet-div-icon draws its own white box + border --
   both of these icons supply their own visuals, so that default chrome is
   turned off here rather than fighting it per-icon. */
.pattern-map-number-icon,
.pattern-map-arrowhead-icon {
  background: transparent;
  border: none;
}

.pattern-map-number {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--navy);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 12px;
  border: 2px solid #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}

.pattern-map-arrowhead {
  font-size: 16px;
  line-height: 1;
  color: var(--blue);
  text-shadow: 0 0 2px #fff, 0 0 2px #fff, 0 0 2px #fff;
}

.pattern-fallback-list {
  margin: 0 0 16px;
  padding-left: 24px;
  font-size: 14px;
}

.pattern-fallback-list li {
  padding: 4px 0;
}

.pattern-fallback-list .no-location {
  color: var(--text-muted);
  font-style: italic;
}

.last-active-cell .last-active-exact {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
}

.users-table td {
  vertical-align: middle;
}

.users-table .users-remove-cell {
  text-align: right;
}

.users-table .btn-danger {
  padding: 6px 14px;
  font-size: 13px;
}

#tab-users .row-actions input[type="email"] {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 14px;
  color: var(--text);
  background: #fff;
  min-width: 240px;
}

#tab-users .row-actions input[type="email"]:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(46, 117, 182, 0.15);
}

.mode-options {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.mode-option {
  flex-direction: row;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 400;
  color: var(--text);
  cursor: pointer;
}

.mode-option input[type="radio"] {
  margin: 0;
}

.media-slots {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 16px;
}

.media-slot-row {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.media-slot-header {
  font-size: 13px;
  font-weight: 700;
  color: var(--navy);
}

.media-slot-current {
  font-size: 13px;
  color: var(--text-muted);
  font-family: "SF Mono", "Courier New", monospace;
}

.media-slot-preview-link {
  font-size: 13px;
  color: var(--blue);
  align-self: flex-start;
}

.media-slot-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.media-slot-controls input[type="file"] {
  font-size: 13px;
  max-width: 220px;
}

.media-slot-controls .btn-secondary,
.media-slot-controls .btn-danger {
  padding: 6px 14px;
  font-size: 13px;
}

.age-range-fields {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-muted);
}

.age-range-fields input[type="number"] {
  width: 70px;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 13px;
  color: var(--text);
}

.age-range-fields input[type="number"]:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(46, 117, 182, 0.15);
}

/* ---- SpaceBox login (login page + Users tab account linking) --------- */
/* Shared here rather than in login.css since the Users tab's own linking
   card needs the same QR overlay/fallback styling on index.html, which
   never loads login.css. */

.qr-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
/* An unconditional `display` on a class always beats the browser's own
   [hidden] rule (author styles win over UA styles regardless of selector
   specificity), so this has to be stated explicitly or toggling `.hidden`
   via JS does nothing visually. */
.qr-overlay[hidden] {
  display: none;
}

.qr-overlay-inner {
  background: var(--card-bg);
  border-radius: 10px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  max-width: 90vw;
}

.qr-overlay video {
  width: 320px;
  max-width: 80vw;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  border-radius: 8px;
  background: #000;
}

/* The typed login code, folded under the scanner. Scanning is the way in;
   this is for a machine with no camera. Deliberately quiet -- a text field
   competing with the scan button is what sends people back to typing 32
   characters by hand. */
.login-fallback {
  margin-top: 0.75rem;
}

.login-fallback > summary {
  cursor: pointer;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.login-fallback > .row-actions {
  margin-top: 0.5rem;
}

.login-fallback input[type="text"] {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: 0.04em;
  min-width: 22rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 14px;
  color: var(--text);
}
