/* =========================================================
   Mastri Tour-Server — Shared Components
   Loaded after _tokens.css, before each dashboard's own CSS.
   Defines: page base, topbar+brand, buttons, pills, fields,
   cards, KPIs, segmented controls, toasts, modals.
   ========================================================= */

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }

html { color-scheme: light; }
body {
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.55;
  color: var(--fg);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

button, input, textarea, select {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}
button { background: none; border: none; cursor: pointer; padding: 0; }
input, textarea, select { outline: none; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

::selection { background: var(--accent-soft); color: var(--fg); }

/* =========================================================
   Topbar — uniform masthead across all dashboards
   ========================================================= */
.topbar,
header.header,
.driver-topbar,
.track-topbar {
  position: sticky;
  top: 0;
  height: 68px;
  padding: 0 24px;
  padding-top: var(--safe-t);
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  /* Muss über allen Leaflet-Panes (200–800) und Karten-Overlays (1000)
     liegen, damit beim Scrollen nichts darüber durchschlägt. */
  z-index: 1500;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.topbar .brand,
.driver-brand,
.track-brand,
.header-left {
  display: flex;
  align-items: center;
  gap: 16px;
  min-width: 0;
}

.brand-logo,
.track-logo {
  height: 40px;
  width: auto;
  display: block;
  flex-shrink: 0;
}

.brand-sub {
  display: flex;
  flex-direction: column;
  line-height: 1.25;
  padding-left: 16px;
  border-left: 1px solid var(--border);
  min-width: 0;
}
.brand-sub b {
  font-size: 15px;
  font-weight: 600;
  color: var(--fg);
  white-space: nowrap;
}
.brand-sub span {
  font-size: 13px;
  color: var(--fg-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* The legacy serif wordmark — hide once the image logo is in place. */
.brand-mark,
.brand-subline { display: none; }

/* =========================================================
   Sprachumschalter (DE/EN) für Confirm & Tracking
   ========================================================= */
.lang-switcher {
  display: inline-flex;
  gap: 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  height: 32px;
}
.lang-switcher button {
  height: 100%;
  min-width: 38px;
  padding: 0 10px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .04em;
  color: var(--fg-muted);
  background: transparent;
  border: none;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.lang-switcher button + button { border-left: 1px solid var(--border); }
.lang-switcher button:hover { color: var(--fg); background: var(--bg-warm); }
.lang-switcher button[aria-pressed="true"] {
  background: var(--accent);
  color: var(--accent-fg);
}

.topbar-left,
.topbar-right,
.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

/* Header links / nav inside topbar */
.header-link,
.topbar-nav a {
  font-size: 13px;
  color: var(--fg-muted);
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  transition: background .15s, color .15s;
}
.header-link:hover,
.topbar-nav a:hover { background: var(--bg-warm); color: var(--fg); text-decoration: none; }
.header-link.is-active,
.topbar-nav a.is-active { color: var(--brand); font-weight: 600; }

.header-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 26px;
  padding: 0 10px;
  border-radius: 999px;
  background: var(--good-soft);
  color: var(--good);
  font-size: 12px;
  font-weight: 600;
}

.header-time {
  font-size: 13px;
  color: var(--fg-muted);
  font-variant-numeric: tabular-nums;
}

/* Connection / online status pill */
.pill.online,
.pill.outbox,
.topbar-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: var(--good-soft);
  color: var(--good);
  border: none;
}
.pill.online .dot,
.pill.outbox .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: currentColor;
}
.pill.offline { background: var(--bad-soft); color: var(--bad); }
.pill.outbox { background: var(--warn-soft); color: var(--warn); }
.topbar-status .save-indicator {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: inherit;
  font-style: italic;
  font-size: 12px;
}
.topbar-status .save-indicator svg { width: 14px; height: 14px; }

/* Tour / vehicle pickers in topbar */
.tour-picker,
.driver-tour-select {
  height: 36px;
  padding: 0 12px;
  border-radius: var(--radius-sm);
  background: var(--bg-elev);
  border: 1px solid var(--border-strong);
  color: var(--fg);
  font-size: 13px;
  min-width: 160px;
}
.tour-picker:focus,
.driver-tour-select:focus { border-color: var(--accent); }

/* Icon buttons in topbar */
.icon-btn {
  width: 36px; height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--fg-muted);
  border: 1px solid transparent;
  transition: background .15s, color .15s, border-color .15s;
}
.icon-btn:hover { background: var(--bg-warm); color: var(--fg); border-color: var(--border); }
.icon-btn svg { width: 18px; height: 18px; stroke-width: 1.8; }

.user-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 36px;
  padding: 0 12px 0 6px;
  border-radius: 999px;
  background: var(--bg-warm);
  color: var(--fg);
  font-size: 13px;
  font-weight: 500;
  border: 1px solid var(--border);
}
.user-pill .user-avatar {
  width: 26px; height: 26px;
  border-radius: 50%;
  background: var(--brand);
  color: var(--accent-fg);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .04em;
}

@media (max-width: 720px) {
  .topbar, header.header, .driver-topbar, .track-topbar {
    height: 60px;
    padding: 0 14px;
  }
  .brand-logo, .track-logo { height: 30px; }
  .brand-sub { padding-left: 12px; }
  .brand-sub b { font-size: 13px; }
  .brand-sub span { font-size: 11px; }
  .header-link, .topbar-nav a { display: none; }
  .topbar-right .header-time { display: none; }
  .tour-picker, .driver-tour-select { min-width: 120px; font-size: 12px; }
}

/* =========================================================
   Typography helpers
   ========================================================= */
h1, h2, h3, h4 { color: var(--fg); }
h1, h2 {
  font-family: var(--font-serif);
  font-weight: 500;
  letter-spacing: -.005em;
  line-height: 1.2;
}
h3 { font-weight: 600; }

.eyebrow,
.section-eyebrow,
.overview-eyebrow {
  display: inline-block;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .14em;
  color: var(--accent);
  margin-bottom: 8px;
}
.eyebrow.is-brand,
.section-eyebrow.is-brand { color: var(--brand); }

/* =========================================================
   Buttons — single source of truth
   ========================================================= */
.btn,
.btn-primary,
.btn-secondary,
.btn-ghost,
.btn-save {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 44px;
  padding: 0 18px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  letter-spacing: .01em;
  border: 1px solid transparent;
  transition: background .15s, color .15s, border-color .15s;
  cursor: pointer;
  white-space: nowrap;
}
.btn-primary,
.btn-save {
  background: var(--accent);
  color: var(--accent-fg);
  height: 48px;
  padding: 0 22px;
  font-size: 15px;
}
.btn-primary:hover,
.btn-save:hover { background: var(--accent-dark); }
.btn-primary:disabled,
.btn-save:disabled,
.btn:disabled {
  background: var(--bg-sunk);
  color: var(--fg-faint);
  cursor: not-allowed;
  border-color: transparent;
}

.btn-secondary {
  background: var(--bg-elev);
  color: var(--accent);
  border-color: var(--accent);
}
.btn-secondary:hover { background: var(--accent-soft); }
.btn-secondary.is-active {
  background: var(--accent);
  color: var(--accent-fg);
}

.btn {
  background: var(--bg-elev);
  color: var(--fg);
  border-color: var(--border-strong);
}
.btn:hover { background: var(--bg-warm); border-color: var(--accent); color: var(--accent); }

.btn-ghost {
  background: transparent;
  color: var(--fg-muted);
  font-weight: 500;
}
.btn-ghost:hover { color: var(--fg); background: var(--bg-warm); }

.btn-danger {
  background: transparent;
  color: var(--bad);
  border: 1px solid var(--bad);
}
.btn-danger:hover { background: var(--bad-soft); }

.btn-sm { height: 36px; padding: 0 14px; font-size: 13px; }
.btn-lg { height: 52px; padding: 0 24px; font-size: 16px; }

/* Two-button group bar (already used in some files) */
.btn-toggle {
  display: inline-flex;
  background: var(--bg-elev);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 3px;
  gap: 2px;
}
.btn-toggle button {
  height: 36px;
  padding: 0 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  color: var(--fg-muted);
  background: transparent;
}
.btn-toggle button.active,
.btn-toggle button.is-active {
  background: var(--accent);
  color: var(--accent-fg);
  font-weight: 600;
}

/* =========================================================
   Pills / badges
   ========================================================= */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  padding: 0 11px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: .02em;
  background: var(--bg-sunk);
  color: var(--fg);
  border: 1px solid var(--border);
}
.pill.is-good { background: var(--good-soft); color: var(--good); border-color: transparent; }
.pill.is-warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.pill.is-bad  { background: var(--bad-soft);  color: var(--bad);  border-color: transparent; }
.pill.is-accent { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.pill.is-brand { background: var(--brand-soft); color: var(--brand); border-color: transparent; }
.pill .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

.info-chip,
.progress-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 26px;
  padding: 0 10px;
  border-radius: 999px;
  background: var(--bg-warm);
  color: var(--fg-muted);
  font-size: 12px;
  font-weight: 600;
  border: 1px solid var(--border);
}

/* =========================================================
   Form fields
   ========================================================= */
.input-field,
input[type="text"], input[type="number"], input[type="email"],
input[type="tel"], input[type="url"], input[type="date"],
input[type="time"], input[type="search"], textarea, select {
  width: 100%;
  min-height: 44px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--bg-elev);
  font-size: 15px;
  line-height: 1.5;
  color: var(--fg);
  transition: border-color .15s, background .15s;
  font-family: inherit;
}
.input-field::placeholder,
input::placeholder, textarea::placeholder { color: var(--fg-faint); font-style: italic; }
.input-field:focus,
input:focus, textarea:focus, select:focus {
  border-color: var(--accent);
  background: #fff;
}
textarea.input-field, textarea {
  resize: vertical;
  min-height: 88px;
  font-family: inherit;
}

.field-label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--fg);
}
.field-label .optional {
  color: var(--fg-faint);
  font-weight: 400;
  font-size: 13px;
  font-style: italic;
}
.field-hint {
  font-size: 13px;
  color: var(--fg-muted);
  margin: 0 0 8px;
  line-height: 1.5;
}

/* =========================================================
   Cards
   ========================================================= */
.card,
.section-card,
.fine-card,
.fine-map-card,
.scan-card,
.list-card,
.loading-card,
.status-card,
.track-map-panel {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 22px;
  box-shadow: var(--shadow-sm);
}
.card + .card,
.section-card + .section-card,
.fine-card + .fine-card { margin-top: 14px; }

.card-head,
.card-header,
.fine-card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.card-head h2,
.card-head h3,
.card-header h3,
.fine-card-head h2,
.fine-card-head h3 {
  font-family: var(--font-serif);
  font-size: 22px;
  font-weight: 500;
  margin: 0;
  letter-spacing: -.005em;
}
.fine-card-head.compact { padding-bottom: 8px; margin-bottom: 10px; }
.fine-card-head .eyebrow { margin-bottom: 4px; }

/* =========================================================
   KPIs
   ========================================================= */
.kpi,
.kpi-tile {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px 18px;
}
.kpi-row,
.kpi-grid,
.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}
.kpi-label,
.kpi-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .12em;
  color: var(--fg-muted);
  margin-bottom: 6px;
}
.kpi-value,
.kpi-number {
  font-family: var(--font-sans);
  font-size: 30px;
  font-weight: 600;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
  letter-spacing: -.01em;
  color: var(--fg);
}
.kpi-unit,
.kpi-sub {
  font-size: 14px;
  color: var(--fg-muted);
  font-weight: 500;
  margin-left: 4px;
  letter-spacing: 0;
}
.kpi-trend { font-size: 12px; color: var(--good); margin-top: 4px; }
.kpi-trend.is-bad { color: var(--bad); }

/* =========================================================
   Segmented control
   ========================================================= */
.segmented {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--bg-elev);
}
.segmented button {
  height: 44px;
  font-size: 13px;
  font-weight: 600;
  color: var(--fg-muted);
  border-right: 1px solid var(--border);
  transition: background .15s, color .15s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0 10px;
}
.segmented button:last-child { border-right: none; }
.segmented button:hover { background: var(--bg-warm); color: var(--fg); }
.segmented button.is-active {
  background: var(--accent);
  color: var(--accent-fg);
}
.segmented button.is-active.is-good { background: var(--good); }
.segmented button.is-active.is-warn { background: var(--warn); }
.segmented button.is-active.is-bad { background: var(--bad); }

/* =========================================================
   Toasts (existing markup uses #toastHost)
   ========================================================= */
.toast-host {
  position: fixed;
  bottom: calc(20px + var(--safe-b));
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 200;
  pointer-events: none;
}
.toast {
  background: var(--fg);
  color: var(--accent-fg);
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  box-shadow: var(--shadow-lg);
  pointer-events: auto;
  max-width: 360px;
}
.toast.is-good { background: var(--good); }
.toast.is-warn { background: var(--warn); }
.toast.is-bad  { background: var(--bad); }

/* =========================================================
   Modal scrim + card (used in prep + driver)
   ========================================================= */
.modal-scrim,
.sheet-scrim,
.pause-scrim,
.done-scrim {
  position: fixed;
  inset: 0;
  background: rgba(31, 35, 48, .42);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  /* Über Topbar (1500), Tabs (1400) und Leaflet-Karten-Layer (≤1000). */
  z-index: 1700;
  padding: 16px;
}
.modal-scrim.is-open,
.sheet-scrim.is-open,
.pause-scrim.is-open,
.done-scrim.is-open { display: flex; }

.modal-card,
.pause-card,
.done-card {
  background: var(--bg-elev);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
  width: 100%;
  max-width: 460px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 12px;
  border-bottom: 1px solid var(--border);
}
.modal-head h3 {
  font-family: var(--font-serif);
  font-size: 22px;
  font-weight: 500;
  margin: 0;
}
.modal-close {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--bg-warm);
  color: var(--fg-muted);
  font-size: 16px;
  line-height: 1;
}
.modal-close:hover { color: var(--fg); }
.modal-body { padding: 16px 20px; }
.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  background: var(--bg);
}

/* =========================================================
   Maps — uniform container
   ========================================================= */
.leaflet-container {
  font-family: var(--font-sans);
  background: var(--bg-sunk);
}

/* =========================================================
   Utility helpers
   ========================================================= */
.text-muted { color: var(--fg-muted); }
.text-sm { font-size: 13px; }
.text-faint { color: var(--fg-faint); }
.mono { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }
.sep { color: var(--fg-faint); padding: 0 4px; }
.lbl { color: var(--fg-muted); font-size: 12px; }

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