/* ==========================================================================
   CAR TRACKER — barevné schéma
   Celá paleta je definovaná zde, v :root. Chceš-li změnit vzhled aplikace,
   stačí upravit hodnoty proměnných níže — zbytek souboru se na ně jen odkazuje.
   ========================================================================== */

:root {
  /* --- Základ (pozadí, povrchy) --- */
  --color-bg: #14181f;
  /* hlavní pozadí stránky */
  --color-surface: #1c222c;
  /* karty, panely */
  --color-surface-raised: #232a36;
  /* zvýrazněné/hover panely */
  --color-border: #2c3444;
  /* jemné oddělovací linky */

  /* --- Text --- */
  --color-text: #e8eaed;
  /* primární text */
  --color-text-muted: #8b93a3;
  /* sekundární text, popisky */
  --color-text-faint: #5b6478;
  /* nejméně důležitý text */

  /* --- Akcent (značka aplikace) --- */
  --color-accent: #e8923c;
  /* jantarová — servisní/výstražná estetika */
  --color-accent-hover: #f5a656;
  --color-accent-muted: #4a3a24;
  /* tlumené pozadí pro accent chip */

  /* --- Stavové barvy (sledování intervalů) --- */
  --color-ok: #4caf7d;
  --color-ok-bg: #1a2e24;
  --color-warn: #e8b93c;
  --color-warn-bg: #332c16;
  --color-danger: #e05c4e;
  --color-danger-bg: #331e1c;
  --color-neutral: #5b6478;
  --color-neutral-bg: #1e232c;

  /* --- Kategorie nákladů (grafy) --- */
  --cat-servis: #e8923c;
  --cat-benzin: #4c9fe8;
  --cat-pojisteni: #9c7ce0;
  --cat-vybava: #4caf7d;
  --cat-ostatni: #8b93a3;

  /* --- Typografie --- */
  --font-display: "Space Grotesk", "Segoe UI", system-ui, sans-serif;
  --font-body: "Inter", "Segoe UI", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", "Consolas", monospace;

  /* --- Odvozené rozměry --- */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --shadow-card: 0 4px 16px rgba(0, 0, 0, 0.25);
  --transition: 150ms ease;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
}

body {
  min-height: 100vh;
  padding-bottom: 4rem;
}

h1,
h2,
h3,
h4 {
  font-family: var(--font-display);
  font-weight: 600;
  margin: 0 0 0.5rem 0;
  letter-spacing: -0.01em;
}

a {
  color: var(--color-accent);
}

/* ==========================================================================
   Layout
   ========================================================================== */

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding: 0.9rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.app-header .brand {
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.app-header .brand .dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--color-accent);
  box-shadow: 0 0 8px var(--color-accent);
  flex-shrink: 0;
}

.vehicle-picker {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.vehicle-picker select {
  max-width: 40vw;
}

.modal-backdrop.blocking .modal-close {
  display: none;
}

.tabs {
  display: flex;
  gap: 0.25rem;
  overflow-x: auto;
  padding: 0.5rem 1.25rem 0;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}

.tab-btn {
  background: none;
  border: none;
  color: var(--color-text-muted);
  font-family: var(--font-body);
  font-size: 0.9rem;
  font-weight: 500;
  padding: 0.6rem 0.9rem;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  transition: color var(--transition), border-color var(--transition);
}

.tab-btn:hover {
  color: var(--color-text);
}

.tab-btn.active {
  color: var(--color-accent);
  border-bottom-color: var(--color-accent);
}

main {
  max-width: 920px;
  margin: 0 auto;
  padding: 1.25rem;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

/* ==========================================================================
   Karty / panely
   ========================================================================== */

.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow-card);
}

.card-title {
  font-size: 1rem;
  color: var(--color-text);
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.section-title {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-faint);
  margin: 1.5rem 0 0.6rem;
}

.section-title:first-child {
  margin-top: 0;
}

/* ==========================================================================
   Přehled — souhrnné statistiky
   ========================================================================== */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  margin-bottom: 1rem;
}

.stat-box-centered:nth-of-type(5) {
  grid-column: 3 / 4;
}

.stat-box-centered:nth-of-type(6) {
  grid-column: 4 / 4;
}

.stat-box {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 1rem;
}

.stat-box .value {
  font-family: var(--font-display);
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--color-text);
  line-height: 1.2;
}

.stat-box .label {
  font-size: 0.78rem;
  color: var(--color-text-muted);
  margin-top: 0.25rem;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem 1rem;
  margin-top: 0.75rem;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.82rem;
  color: var(--color-text-muted);
}

.legend-swatch {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  flex-shrink: 0;
}

/* ==========================================================================
   Servisní intervaly — "palubní deska"
   ========================================================================== */

.gauge-list {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.gauge-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 0.25rem 0.75rem;
  padding: 0.75rem;
  background: var(--color-surface-raised);
  border-radius: var(--radius-md);
  border-left: 3px solid var(--color-neutral);
}

.gauge-row.status-ok {
  border-left-color: var(--color-ok);
}

.gauge-row.status-blizi_se {
  border-left-color: var(--color-warn);
}

.gauge-row.status-po_terminu {
  border-left-color: var(--color-danger);
}

.gauge-row.status-neznamo {
  border-left-color: var(--color-neutral);
}

.gauge-name {
  font-weight: 600;
  font-size: 0.9rem;
}

.gauge-name-link {
  cursor: pointer;
  text-decoration: underline;
  text-decoration-color: var(--color-border);
  text-underline-offset: 2px;
}

.gauge-name-link:hover {
  color: var(--color-accent);
  text-decoration-color: var(--color-accent);
}

.gauge-meta {
  grid-column: 1;
  font-size: 0.78rem;
  color: var(--color-text-muted);
}

.gauge-badge {
  grid-column: 2;
  grid-row: 1 / span 2;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 0.3rem 0.6rem;
  border-radius: 999px;
  white-space: nowrap;
}

.status-ok .gauge-badge {
  background: var(--color-ok-bg);
  color: var(--color-ok);
}

.status-blizi_se .gauge-badge {
  background: var(--color-warn-bg);
  color: var(--color-warn);
}

.status-po_terminu .gauge-badge {
  background: var(--color-danger-bg);
  color: var(--color-danger);
}

.status-neznamo .gauge-badge {
  background: var(--color-neutral-bg);
  color: var(--color-neutral);
}

.gauge-bar-track {
  grid-column: 1 / span 2;
  height: 6px;
  border-radius: 999px;
  background: var(--color-border);
  overflow: hidden;
  margin-top: 0.4rem;
}

.gauge-bar-fill {
  height: 100%;
  border-radius: 999px;
  transition: width var(--transition);
}

/* ==========================================================================
   Formuláře
   ========================================================================== */

.field {
  margin-bottom: 1rem;
}

.field label {
  display: block;
  font-size: 0.82rem;
  color: var(--color-text-muted);
  margin-bottom: 0.35rem;
  font-weight: 500;
}

input,
select,
textarea {
  width: 100%;
  background: var(--color-surface-raised);
  border: 1px solid var(--color-border);
  color: var(--color-text);
  font-family: var(--font-body);
  font-size: 0.95rem;
  padding: 0.65rem 0.75rem;
  border-radius: var(--radius-sm);
  transition: border-color var(--transition);
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--color-accent);
}

/* Viditelný focus i pro klávesnicové ovládání (accessibility) */
button:focus-visible,
.tab-btn:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
.chip:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

textarea {
  min-height: 70px;
  resize: vertical;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.radio-group {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.radio-chip {
  flex: 1;
  min-width: 100px;
  text-align: center;
  padding: 0.6rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
  background: var(--color-surface-raised);
  color: var(--color-text-muted);
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 500;
  transition: all var(--transition);
}

.radio-chip input {
  display: none;
}

.radio-chip.checked {
  border-color: var(--color-accent);
  color: var(--color-accent);
  background: var(--color-accent-muted);
}

button.btn {
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 0.9rem;
  padding: 0.7rem 1.3rem;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  transition: background var(--transition), transform var(--transition);
}

.btn-primary {
  background: var(--color-accent);
  color: #1a1408;
}

.btn-primary:hover {
  background: var(--color-accent-hover);
}

.btn-secondary {
  background: var(--color-surface-raised);
  color: var(--color-text);
  border: 1px solid var(--color-border) !important;
}

.btn-secondary:hover {
  background: var(--color-border);
}

.btn-danger {
  background: var(--color-danger-bg);
  color: var(--color-danger);
}

.btn-small {
  padding: 0.4rem 0.75rem;
  font-size: 0.8rem;
}

.btn-row {
  display: flex;
  gap: 0.6rem;
  margin-top: 1.25rem;
}

/* ==========================================================================
   Servisní karta — dynamický seznam položek
   ========================================================================== */

.service-item-row {
  background: var(--color-surface-raised);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 0.9rem;
  margin-bottom: 0.75rem;
}

.service-item-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.6rem;
}

.remove-item-btn {
  background: none;
  border: none;
  color: var(--color-text-faint);
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  padding: 0.2rem 0.4rem;
}

.remove-item-btn:hover {
  color: var(--color-danger);
}

/* ==========================================================================
   Kartotéka — seznam surových záznamů
   ========================================================================== */

.filter-bar {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.chip {
  padding: 0.4rem 0.8rem;
  border-radius: 999px;
  border: 1px solid var(--color-border);
  background: var(--color-surface-raised);
  color: var(--color-text-muted);
  font-size: 0.82rem;
  cursor: pointer;
  transition: all var(--transition);
}

.chip.active {
  background: var(--color-accent-muted);
  border-color: var(--color-accent);
  color: var(--color-accent);
}

.record-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.8rem 0.9rem;
  border-bottom: 1px solid var(--color-border);
  cursor: pointer;
}

.record-row:hover {
  background: var(--color-surface-raised);
}

.record-row:last-child {
  border-bottom: none;
}

.record-cat-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.record-main {
  flex: 1;
  min-width: 0;
}

.record-title {
  font-size: 0.9rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.record-sub {
  font-size: 0.78rem;
  color: var(--color-text-muted);
}

.record-cost {
  font-family: var(--font-mono);
  font-weight: 600;
  white-space: nowrap;
}

.empty-state {
  text-align: center;
  padding: 2.5rem 1rem;
  color: var(--color-text-faint);
}

/* ==========================================================================
   Modal (detail karty)
   ========================================================================== */

.modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(10, 12, 16, 0.7);
  z-index: 100;
  align-items: flex-end;
  justify-content: center;
}

.modal-backdrop.active {
  display: flex;
}

.modal-box {
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  width: 100%;
  max-width: 600px;
  max-height: 88vh;
  overflow-y: auto;
  padding: 1.25rem;
}

@media (min-width: 640px) {
  .modal-backdrop {
    align-items: center;
  }

  .modal-box {
    border-radius: var(--radius-lg);
    margin-bottom: 2rem;
  }
}

.modal-close {
  float: right;
  background: none;
  border: none;
  color: var(--color-text-faint);
  font-size: 1.3rem;
  cursor: pointer;
}

/* ==========================================================================
   Nastavení — správa sledovaných dílů
   ========================================================================== */

.item-type-row {
  display: grid;
  grid-template-columns: 1fr 90px 90px 90px auto;
  gap: 0.5rem;
  align-items: center;
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--color-border);
}

.item-type-row input {
  padding: 0.4rem 0.5rem;
  font-size: 0.85rem;
}

.tire-swap-toggle {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.75rem;
  color: var(--color-text-muted);
  white-space: nowrap;
}

.tire-set-row {
  padding: 0.8rem 0;
  border-bottom: 1px solid var(--color-border);
}

.tire-set-row:last-child {
  border-bottom: none;
}

/* ==========================================================================
   Responsivita
   ========================================================================== */

@media (max-width: 480px) {
  .field-row {
    grid-template-columns: 1fr;
  }

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

  .item-type-row {
    grid-template-columns: 1fr 70px 70px 70px auto;
    font-size: 0.85rem;
  }
}

/* Respekt k preferenci omezeného pohybu */
@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
  }
}

.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.stats-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
  white-space: nowrap;
}

.stats-table thead th {
  text-align: left;
  padding: 0.6rem 0.9rem;
  font-family: "Space Grotesk", sans-serif;
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--color-text-muted, #888);
  border-bottom: 2px solid var(--color-border, #e2e2e2);
  position: sticky;
  top: 0;
  background: var(--color-surface, #fff);
}

.stats-table thead th:first-child {
  color: var(--color-text, #1a1a1a);
}

.stats-table tbody td {
  padding: 0.55rem 0.9rem;
  border-bottom: 1px solid var(--color-border, #eee);
  font-variant-numeric: tabular-nums;
}

.stats-table tbody td:first-child {
  font-weight: 600;
  font-family: "JetBrains Mono", monospace;
}

.stats-table tbody tr:hover {
  background: var(--color-accent-muted, #f5f5f5);
}

.stats-table tbody tr:last-child td {
  border-bottom: none;
}
