:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --text: #1a1d23;
  --text-muted: #5b6270;
  --border: #e1e4e9;
  --primary: #1e5fbf;
  --primary-dark: #164a96;
  --accent: #d97706;
  --drive-color: #1e5fbf;
  --break-color: #d97706;
  --rest-color: #16794f;
  --danger: #b3261e;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --surface: #1d2026;
    --text: #eef0f3;
    --text-muted: #a3a9b5;
    --border: #2c303a;
    --primary: #5b9bff;
    --primary-dark: #4785ea;
    --accent: #f0a63a;
    --drive-color: #5b9bff;
    --break-color: #f0a63a;
    --rest-color: #3fbf82;
    --danger: #ff6b64;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.4), 0 1px 2px rgba(0, 0, 0, 0.3);
  }
}

:root[data-theme="dark"] {
  --bg: #14161a;
  --surface: #1d2026;
  --text: #eef0f3;
  --text-muted: #a3a9b5;
  --border: #2c303a;
  --primary: #5b9bff;
  --primary-dark: #4785ea;
  --accent: #f0a63a;
  --drive-color: #5b9bff;
  --break-color: #f0a63a;
  --rest-color: #3fbf82;
  --danger: #ff6b64;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.4), 0 1px 2px rgba(0, 0, 0, 0.3);
}

:root[data-theme="light"] {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --text: #1a1d23;
  --text-muted: #5b6270;
  --border: #e1e4e9;
  --primary: #1e5fbf;
  --primary-dark: #164a96;
  --accent: #d97706;
  --drive-color: #1e5fbf;
  --break-color: #d97706;
  --rest-color: #16794f;
  --danger: #b3261e;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.06);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.header-inner h1 {
  margin: 0 0 4px;
  font-size: 1.4rem;
}

.subtitle {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.icon-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  width: 40px;
  height: 40px;
  font-size: 1.1rem;
  cursor: pointer;
  color: var(--text);
  flex-shrink: 0;
}

.icon-btn:hover {
  background: var(--bg);
}

.settings-panel {
  max-width: 640px;
  margin: 16px auto 0;
  padding: 20px 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.settings-panel h2 {
  margin-top: 0;
  font-size: 1.05rem;
}

.settings-panel label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 6px;
}

.settings-panel input[type="password"] {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.95rem;
  margin-bottom: 8px;
}

.hint {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin: 4px 0 0;
}

.hint a {
  color: var(--primary);
}

.truck-profile {
  margin-top: 16px;
  border-top: 1px solid var(--border);
  padding-top: 12px;
}

.truck-profile summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
}

.profile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.profile-grid label {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
}

.profile-grid input[type="number"] {
  width: 100%;
  margin-top: 4px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 6px;
}

.checkbox-label input {
  width: auto;
  margin: 0;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 10px 18px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  margin-top: 8px;
}

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

.btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.hidden {
  display: none !important;
}

main {
  max-width: 1100px;
  margin: 24px auto;
  padding: 0 20px 40px;
}

.route-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
}

.field-group {
  display: flex;
  flex-direction: column;
  position: relative;
}

.field-group label {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 8px;
  color: var(--text);
  display: inline-block;
}

.field-group input,
.field-group select {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.95rem;
}

.btn-calc {
  grid-column: 1 / -1;
  justify-self: start;
}

.autocomplete-wrap {
  position: relative;
}

.suggestions {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 50;
  list-style: none;
  margin: 4px 0 0;
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  max-height: 240px;
  overflow-y: auto;
}

.suggestions li {
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
}

.suggestions li:hover,
.suggestions li.active {
  background: var(--bg);
}

.suggestions li small {
  display: block;
  color: var(--text-muted);
  font-size: 0.75rem;
}

.status-msg {
  max-width: 1100px;
  margin: 16px auto 0;
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 0.9rem;
}

.status-msg.info {
  background: rgba(30, 95, 191, 0.1);
  color: var(--primary);
}

.status-msg.error {
  background: rgba(179, 38, 30, 0.1);
  color: var(--danger);
}

.results {
  margin-top: 24px;
}

.summary-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  box-shadow: var(--shadow);
}

.card-label {
  font-size: 0.78rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.card-value {
  font-size: 1.4rem;
  font-weight: 700;
}

.card-highlight {
  border-color: var(--primary);
}

.card-highlight .card-value {
  color: var(--primary);
}

#map {
  height: 420px;
  width: 100%;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  margin-bottom: 20px;
  background: var(--surface);
}

.panels {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  min-width: 0;
}

.panel h2 {
  margin-top: 0;
  font-size: 1.05rem;
}

.timeline {
  list-style: none;
  margin: 0;
  padding: 0;
}

.timeline li {
  position: relative;
  padding: 10px 0 10px 28px;
  border-left: 2px solid var(--border);
  margin-left: 6px;
  font-size: 0.88rem;
}

.timeline li:last-child {
  border-left-color: transparent;
}

.timeline li::before {
  content: "";
  position: absolute;
  left: -7px;
  top: 14px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--drive-color);
}

.timeline li.event-break::before {
  background: var(--break-color);
}

.timeline li.event-arrive::before {
  background: var(--danger);
}

.timeline li.event-daily-rest::before,
.timeline li.event-weekly-rest::before {
  background: var(--rest-color);
}

.timeline li.event-daily-rest .t-desc strong,
.timeline li.event-weekly-rest .t-desc strong {
  color: var(--text);
  font-weight: 900;
}


.timeline .t-time {
  font-weight: 700;
  margin-right: 6px;
}

.timeline .t-desc {
  color: var(--text-muted);
}

.explanation p {
  font-size: 0.9rem;
  margin: 0 0 12px;
}

.explanation ul {
  font-size: 0.88rem;
  padding-left: 20px;
  margin: 0 0 12px;
}

.explanation li {
  margin-bottom: 6px;
}

.explanation .rule-tag {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--border);
  margin-right: 6px;
}

.app-footer {
  max-width: 1100px;
  margin: 0 auto 30px;
  padding: 0 20px;
  font-size: 0.78rem;
  color: var(--text-muted);
  text-align: center;
}

@media (max-width: 720px) {
  .route-form {
    grid-template-columns: 1fr;
  }

  .panels {
    grid-template-columns: 1fr;
  }
}

.panel,
.card,
#qrWrapper,
.timeline li {
  page-break-inside: avoid;
  break-inside: avoid;
}

.pdf-mode .panels {
  display: block !important;
}

.pdf-mode .panel {
  margin-bottom: 20px !important;
  page-break-inside: auto !important;
}

.pdf-mode .timeline li {
  page-break-inside: avoid !important;
}

.pdf-mode #qrWrapper {
  page-break-inside: avoid !important;
  margin-top: 40px !important;
}

.pdf-mode #timelineList button {
  display: none !important;
}

.timeline::before {
  z-index: 1 !important;
}

.timeline li::before {
  z-index: 2 !important;
}