* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html { font-size: 16px; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: #f2f2f7;
  color: #1c1c1e;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

header {
  background: linear-gradient(135deg, #007aff 0%, #0051d5 100%);
  color: white;
  padding: 1rem 1rem 0.5rem;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 12px rgba(0,0,0,0.15);
}
header h1 { font-size: 1.3rem; font-weight: 700; margin-bottom: 0.75rem; letter-spacing: -0.3px; }

.tabs {
  display: flex;
  gap: 0.5rem;
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: 0.25rem;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  background: rgba(255,255,255,0.2);
  border: none;
  color: rgba(255,255,255,0.9);
  padding: 0.5rem 1rem;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  transition: all 0.2s;
  backdrop-filter: blur(10px);
}
.tab.active { background: white; color: #007aff; box-shadow: 0 2px 8px rgba(0,0,0,0.1); }
.tab:active { transform: scale(0.95); }

.tab-content { display: none; padding: 0.75rem; padding-bottom: 100px; animation: fadeIn 0.25s ease; }
.tab-content.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

.card {
  background: white;
  border-radius: 16px;
  padding: 1rem;
  margin-bottom: 0.75rem;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
  border: 1px solid rgba(0,0,0,0.04);
}
.card h2 {
  font-size: 1.05rem;
  font-weight: 700;
  margin-bottom: 0.75rem;
  color: #007aff;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.card h2::before {
  content: '';
  display: inline-block;
  width: 4px;
  height: 18px;
  background: #007aff;
  border-radius: 2px;
}

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0.5rem; }

label {
  display: block;
  font-size: 0.8rem;
  color: #8e8e93;
  font-weight: 500;
  margin-bottom: 0.3rem;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
input[type="text"], input[type="number"], input[type="date"], input[type="time"], select {
  width: 100%;
  padding: 0.75rem 0.875rem;
  border: 1.5px solid #e5e5ea;
  border-radius: 12px;
  font-size: 1rem;
  background: #fafafa;
  color: #1c1c1e;
  transition: border-color 0.2s, box-shadow 0.2s;
  -webkit-appearance: none;
}
input:focus, select:focus {
  outline: none;
  border-color: #007aff;
  box-shadow: 0 0 0 3px rgba(0,122,255,0.12);
  background: white;
}
input::placeholder { color: #c7c7cc; }

.checkbox {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-top: 0.75rem;
  font-size: 0.9rem;
  color: #3a3a3c;
  cursor: pointer;
  padding: 0.5rem;
  border-radius: 10px;
  background: #f2f2f7;
}
.checkbox input[type="checkbox"] {
  width: 22px;
  height: 22px;
  accent-color: #007aff;
  flex-shrink: 0;
}

.hint {
  font-size: 0.8rem;
  color: #8e8e93;
  margin-bottom: 0.75rem;
  line-height: 1.4;
}

.btn-primary {
  width: 100%;
  padding: 0.875rem;
  background: linear-gradient(135deg, #007aff 0%, #0051d5 100%);
  color: white;
  border: none;
  border-radius: 14px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.2s;
  box-shadow: 0 4px 12px rgba(0,122,255,0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
}
.btn-primary:active { transform: scale(0.97); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }

.btn-secondary {
  width: 100%;
  padding: 0.75rem;
  background: #f2f2f7;
  color: #007aff;
  border: 1.5px solid #e5e5ea;
  border-radius: 14px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
}
.btn-secondary:active { background: #e5e5ea; transform: scale(0.97); }

.btn-danger {
  width: 100%;
  padding: 0.6rem;
  background: #ff3b30;
  color: white;
  border: none;
  border-radius: 10px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

.hidden { display: none !important; }

/* Tankovania */
.tankovanie-row {
  background: #fafafa;
  border: 1.5px solid #e5e5ea;
  border-radius: 12px;
  padding: 0.75rem;
  margin-bottom: 0.5rem;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 0.5fr;
  gap: 0.5rem;
  align-items: end;
}
.tankovanie-row input { font-size: 0.9rem; padding: 0.6rem; }
.tankovanie-row .btn-remove {
  background: #ff3b30;
  color: white;
  border: none;
  border-radius: 8px;
  width: 36px;
  height: 36px;
  font-size: 1.2rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Dialnice */
.dialnica-row {
  background: #fafafa;
  border: 1.5px solid #e5e5ea;
  border-radius: 12px;
  padding: 0.75rem;
  margin-bottom: 0.5rem;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1fr 0.5fr;
  gap: 0.5rem;
  align-items: end;
}
.dialnica-row input { font-size: 0.85rem; padding: 0.6rem; }

/* Stats */
.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  margin-bottom: 1rem;
}
.stat-box {
  background: linear-gradient(135deg, #f2f2f7 0%, #e5e5ea 100%);
  padding: 0.75rem;
  border-radius: 12px;
  text-align: center;
}
.stat-box .value {
  font-size: 1.3rem;
  font-weight: 700;
  color: #007aff;
  display: block;
}
.stat-box .label {
  font-size: 0.75rem;
  color: #8e8e93;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-top: 0.2rem;
}
.stat-box.ok { background: linear-gradient(135deg, #d4edda 0%, #c3e6cb 100%); }
.stat-box.ok .value { color: #28a745; }
.stat-box.err { background: linear-gradient(135deg, #f8d7da 0%, #f5c6cb 100%); }
.stat-box.err .value { color: #dc3545; }

/* Mapa */
#map {
  height: 320px;
  border-radius: 14px;
  margin: 0.75rem 0;
  border: 2px solid #e5e5ea;
  overflow: hidden;
}

/* Tabuľka trasy */
.trasa-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; margin-top: 0.5rem; }
.trasa-table th {
  background: #f2f2f7;
  color: #8e8e93;
  font-weight: 600;
  text-align: left;
  padding: 0.6rem 0.5rem;
  position: sticky;
  top: 0;
}
.trasa-table td { padding: 0.6rem 0.5rem; border-bottom: 1px solid #f2f2f7; vertical-align: middle; }
.trasa-table tr:hover { background: #fafafa; }
.trasa-table .typ-tankovanie { background: #fff8e1; }
.trasa-table .typ-navrat { background: #e3f2fd; font-weight: 600; }
.trasa-table .km { font-weight: 600; color: #007aff; text-align: right; white-space: nowrap; }
.trasa-table .cas { font-size: 0.75rem; color: #8e8e93; white-space: nowrap; }
.trasa-table input.ucel-input {
  width: 100%;
  padding: 0.4rem 0.5rem;
  font-size: 0.85rem;
  border: 1px solid #e5e5ea;
  border-radius: 6px;
}

/* Actions */
.actions { display: flex; gap: 0.5rem; margin-top: 1rem; }
.actions button, .actions a { flex: 1; text-decoration: none; }

/* História */
.history-item {
  background: white;
  border: 1.5px solid #e5e5ea;
  border-radius: 14px;
  padding: 1rem;
  margin-bottom: 0.6rem;
  cursor: pointer;
  transition: all 0.15s;
}
.history-item:active { transform: scale(0.98); background: #fafafa; }
.history-item .header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.4rem;
}
.history-item .datum { font-weight: 700; color: #1c1c1e; }
.history-item .km { color: #007aff; font-weight: 600; font-size: 0.95rem; }
.history-item .meta { font-size: 0.8rem; color: #8e8e93; }

/* Import */
.file-drop {
  border: 2px dashed #c7c7cc;
  border-radius: 14px;
  padding: 2rem 1rem;
  text-align: center;
  color: #8e8e93;
  transition: all 0.2s;
  cursor: pointer;
  background: #fafafa;
}
.file-drop.active { border-color: #007aff; background: rgba(0,122,255,0.05); color: #007aff; }
.file-drop input { display: none; }

/* Toast */
.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: #1c1c1e;
  color: white;
  padding: 0.875rem 1.5rem;
  border-radius: 12px;
  font-size: 0.9rem;
  font-weight: 500;
  z-index: 1000;
  opacity: 0;
  transition: all 0.3s ease;
  box-shadow: 0 8px 24px rgba(0,0,0,0.2);
  max-width: 90vw;
  text-align: center;
}
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }

/* Loading */
.spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 3px solid rgba(255,255,255,0.3);
  border-radius: 50%;
  border-top-color: white;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Responsive */
@media (max-width: 380px) {
  .grid-2 { grid-template-columns: 1fr; }
  .tankovanie-row { grid-template-columns: 1fr 1fr; }
  .tankovanie-row .btn-remove { grid-column: span 2; width: 100%; height: 32px; }
  .dialnica-row { grid-template-columns: 1fr 1fr; }
}


/* ==================== PWA STANDALONE MODE ==================== */

/* Safe areas for notched phones */
@supports (padding-top: env(safe-area-inset-top)) {
  header { padding-top: calc(1rem + env(safe-area-inset-top)); }
  .tab-content { padding-bottom: calc(100px + env(safe-area-inset-bottom)); }
}

/* Hide scrollbar in standalone */
@media (display-mode: standalone) {
  body { overscroll-behavior-y: none; }
  header { padding-top: max(1rem, env(safe-area-inset-top)); }
}

/* Install banner */
.install-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  background: linear-gradient(135deg, #007aff 0%, #0051d5 100%);
  color: white;
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  z-index: 1001;
  font-size: 0.9rem;
  font-weight: 500;
  box-shadow: 0 2px 12px rgba(0,0,0,0.15);
  animation: slideDown 0.3s ease;
}
@keyframes slideDown {
  from { transform: translateY(-100%); }
  to { transform: translateY(0); }
}
.install-banner.hidden { display: none !important; }
.install-banner button {
  background: white;
  color: #007aff;
  border: none;
  padding: 0.4rem 1rem;
  border-radius: 20px;
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  white-space: nowrap;
}
.install-banner button.close {
  background: rgba(255,255,255,0.2);
  color: white;
  padding: 0.3rem 0.6rem;
  border-radius: 50%;
  font-size: 1.1rem;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Pull-to-refresh indicator */
.ptr-indicator {
  position: fixed;
  top: 0;
  left: 50%;
  transform: translateX(-50%) translateY(-40px);
  background: white;
  padding: 0.5rem 1rem;
  border-radius: 0 0 12px 12px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  z-index: 999;
  transition: transform 0.2s;
  font-size: 0.85rem;
  color: #8e8e93;
}
.ptr-indicator.visible { transform: translateX(-50%) translateY(0); }

/* Network status indicator */
.net-status {
  position: fixed;
  top: env(safe-area-inset-top, 0);
  left: 50%;
  transform: translateX(-50%) translateY(-40px);
  background: #ff3b30;
  color: white;
  padding: 0.4rem 1.2rem;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 600;
  z-index: 1002;
  transition: transform 0.3s;
  box-shadow: 0 4px 12px rgba(255,59,48,0.3);
}
.net-status.offline { transform: translateX(-50%) translateY(10px); }

/* Better touch targets for mobile */
@media (pointer: coarse) {
  .tab { min-height: 44px; }
  input, select, button { min-height: 44px; }
  .trasa-table td { padding: 0.75rem 0.5rem; }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
  body { background: #000; color: #fff; }
  .card { background: #1c1c1e; border-color: rgba(255,255,255,0.08); }
  input, select { background: #2c2c2e; border-color: #3a3a3c; color: #fff; }
  input::placeholder { color: #636366; }
  .hint { color: #8e8e93; }
  .stat-box { background: linear-gradient(135deg, #2c2c2e 0%, #3a3a3c 100%); }
  .history-item { background: #1c1c1e; border-color: #3a3a3c; }
  .file-drop { background: #2c2c2e; border-color: #3a3a3c; }
  .tankovanie-row, .dialnica-row { background: #2c2c2e; border-color: #3a3a3c; }
  .checkbox { background: #2c2c2e; }
  .trasa-table th { background: #2c2c2e; }
  .trasa-table td { border-color: #3a3a3c; }
  .btn-secondary { background: #2c2c2e; border-color: #3a3a3c; }
}

/* Landscape mode adjustments */
@media (orientation: landscape) and (max-height: 500px) {
  header h1 { font-size: 1rem; margin-bottom: 0.3rem; }
  .tabs { padding-bottom: 0.1rem; }
  .tab { padding: 0.3rem 0.8rem; font-size: 0.8rem; }
  #map { height: 200px; }
}

/* Tablet adjustments */
@media (min-width: 768px) {
  #app { max-width: 600px; margin: 0 auto; }
  .grid-2 { grid-template-columns: 1fr 1fr; }
}
