* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #f8fafc;
  color: #1e293b;
  line-height: 1.5;
}

.container {
  max-width: 800px;
  margin: 0 auto;
  padding: 1rem;
}

.header-row {
  display: flex;
  justify-content: center;
  align-items: center;
  margin-bottom: 1rem;
  position: relative;
}

h1 {
  font-size: 1.5rem;
  text-align: center;
}

.lang-btn {
  position: absolute;
  right: 0;
  padding: 0.3rem 0.7rem;
  border: 1px solid #cbd5e1;
  background: #fff;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 600;
  color: #475569;
}

.lang-btn:hover {
  background: #f1f5f9;
}

/* Tabs */
.tabs {
  display: flex;
  border-bottom: 2px solid #e2e8f0;
  margin-bottom: 1.5rem;
  gap: 0;
}

.tab-btn {
  padding: 0.75rem 1.5rem;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 500;
  color: #64748b;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: color 0.2s, border-color 0.2s;
}

.tab-btn:hover {
  color: #1e293b;
}

.tab-btn.active {
  color: #2563eb;
  border-bottom-color: #2563eb;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

/* Calculator layout */
.calc-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  margin-bottom: 1.5rem;
}

.input-section,
.output-section {
  background: #fff;
  border-radius: 8px;
  padding: 1.25rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

/* Sliders */
.slider-group {
  margin-bottom: 1.25rem;
}

.slider-group label {
  display: flex;
  justify-content: space-between;
  font-weight: 500;
  margin-bottom: 0.35rem;
  font-size: 0.9rem;
}

.slider-group input[type='range'] {
  width: 100%;
  accent-color: #2563eb;
}

/* Radio groups */
.radio-group {
  margin-bottom: 1.25rem;
}

.radio-group p {
  font-weight: 500;
  margin-bottom: 0.35rem;
  font-size: 0.9rem;
}

.radio-options {
  display: flex;
  gap: 1rem;
}

.radio-options label {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.9rem;
  cursor: pointer;
}

/* SoC input */
.soc-group {
  margin-bottom: 1.25rem;
}

.soc-group label {
  display: block;
  font-weight: 500;
  margin-bottom: 0.35rem;
  font-size: 0.9rem;
}

.soc-group input[type='number'] {
  width: 80px;
  padding: 0.35rem 0.5rem;
  border: 1px solid #cbd5e1;
  border-radius: 4px;
  font-size: 0.95rem;
}

/* Output values */
.output-value {
  margin-bottom: 1rem;
}

.output-value .label {
  font-size: 0.85rem;
  color: #64748b;
  margin-bottom: 0.15rem;
}

.output-value .value {
  font-size: 1.8rem;
  font-weight: 700;
  color: #1e293b;
}

.output-value .value.range-value {
  color: #2563eb;
}

.wltp-positive {
  color: #16a34a;
}

.wltp-negative {
  color: #dc2626;
}

/* Chart */
.chart-container {
  background: #fff;
  border-radius: 8px;
  padding: 1rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  margin-bottom: 1.5rem;
  height: 300px;
}

/* Calibration */
.cal-wrapper {
  margin-bottom: 1.5rem;
}

#cal-toggle {
  background: none;
  border: 1px solid #cbd5e1;
  padding: 0.5rem 1rem;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.85rem;
  color: #64748b;
}

#cal-toggle:hover {
  background: #f1f5f9;
}

#cal-section {
  display: none;
  margin-top: 1rem;
  background: #fff;
  border-radius: 8px;
  padding: 1rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.cal-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.cal-table th,
.cal-table td {
  padding: 0.5rem;
  text-align: left;
  border-bottom: 1px solid #e2e8f0;
}

.cal-table th {
  font-weight: 600;
  color: #64748b;
}

.cal-pass-cell {
  color: #16a34a;
  font-weight: 600;
}

.cal-fail-cell {
  color: #dc2626;
  font-weight: 600;
}

.cal-fail-row {
  background: #fef2f2;
}

.cal-pass {
  color: #16a34a;
  font-weight: 500;
  margin-top: 0.75rem;
}

.cal-warn {
  color: #dc2626;
  font-weight: 500;
  margin-top: 0.75rem;
}

/* Placeholder */
.placeholder-message {
  text-align: center;
  color: #94a3b8;
  padding: 3rem 1rem;
  font-style: italic;
}

/* Supabase config */
.supabase-config {
  margin-bottom: 1.25rem;
}

.supabase-config summary {
  cursor: pointer;
  font-size: 0.9rem;
  color: #64748b;
}

.config-fields {
  margin-top: 0.75rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: flex-end;
}

.config-fields label {
  display: flex;
  flex-direction: column;
  font-size: 0.8rem;
  color: #64748b;
  flex: 1;
  min-width: 150px;
}

.config-fields input[type='text'] {
  padding: 0.35rem 0.5rem;
  border: 1px solid #cbd5e1;
  border-radius: 4px;
  font-size: 0.85rem;
  margin-top: 0.2rem;
}

.config-fields button {
  padding: 0.35rem 1rem;
  border: 1px solid #2563eb;
  background: #2563eb;
  color: #fff;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.85rem;
}

.sb-ok {
  color: #16a34a;
  font-size: 0.85rem;
}

.sb-error {
  color: #dc2626;
  font-size: 0.85rem;
}

/* Trip form */
#trip-form {
  background: #fff;
  border-radius: 8px;
  padding: 1.25rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.mode-selector {
  margin-bottom: 1rem;
}

.trip-form-section {
  display: none;
}

.trip-form-section.active {
  display: block;
}

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

.form-grid label {
  display: flex;
  flex-direction: column;
  font-size: 0.85rem;
  color: #475569;
}

.form-grid input,
.form-grid select {
  padding: 0.35rem 0.5rem;
  border: 1px solid #cbd5e1;
  border-radius: 4px;
  font-size: 0.9rem;
  margin-top: 0.2rem;
}

.checkbox-row {
  display: flex;
  gap: 1.5rem;
  margin-top: 0.75rem;
  font-size: 0.9rem;
}

.checkbox-row label {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  cursor: pointer;
}

/* Segments */
.segment-row {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  padding: 0.75rem;
  margin-bottom: 0.75rem;
}

.segment-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
  font-size: 0.9rem;
}

.remove-segment-btn {
  background: none;
  border: none;
  color: #dc2626;
  cursor: pointer;
  font-size: 0.8rem;
}

.segment-fields {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.field-row {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.field-row label {
  display: flex;
  flex-direction: column;
  font-size: 0.8rem;
  color: #475569;
  flex: 1;
  min-width: 100px;
}

.field-row input[type='text'],
.field-row input[type='number'],
.field-row select {
  padding: 0.3rem 0.4rem;
  border: 1px solid #cbd5e1;
  border-radius: 4px;
  font-size: 0.85rem;
  margin-top: 0.15rem;
}

.field-row input[type='checkbox'] {
  margin-top: 0.5rem;
}

/* Buttons */
.primary-btn {
  display: block;
  width: 100%;
  margin-top: 1rem;
  padding: 0.6rem;
  background: #2563eb;
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
}

.primary-btn:hover {
  background: #1d4ed8;
}

.secondary-btn {
  padding: 0.4rem 1rem;
  background: none;
  border: 1px solid #cbd5e1;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.85rem;
  color: #475569;
  margin-top: 0.5rem;
}

.secondary-btn:hover {
  background: #f1f5f9;
}

#parse-maps-btn {
  padding: 0.35rem 1rem;
  background: #2563eb;
  color: #fff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.85rem;
  align-self: flex-end;
}

/* Trip status */
.trip-status {
  margin-top: 0.75rem;
  font-size: 0.85rem;
}

.trip-status.success {
  color: #16a34a;
}

.trip-status.error {
  color: #dc2626;
}

#maps-status {
  font-size: 0.85rem;
  margin-bottom: 0.5rem;
  color: #64748b;
}

/* Route Estimate */
.re-input-section {
  background: #fff;
  border-radius: 8px;
  padding: 1.25rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  margin-bottom: 1rem;
}

.re-status {
  font-size: 0.85rem;
  color: #64748b;
}

.re-status.error {
  color: #dc2626;
}

.re-global-controls {
  background: #fff;
  border-radius: 8px;
  padding: 1.25rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  margin-bottom: 1rem;
}

.re-globals-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  align-items: start;
}

.re-globals-grid label {
  display: flex;
  flex-direction: column;
  font-size: 0.85rem;
  color: #475569;
}

.re-globals-grid input[type='number'] {
  width: 80px;
  padding: 0.35rem 0.5rem;
  border: 1px solid #cbd5e1;
  border-radius: 4px;
  font-size: 0.9rem;
  margin-top: 0.2rem;
}

.re-segments {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.re-segment {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  overflow: hidden;
  display: flex;
  flex-direction: row;
}

.re-seg-map {
  width: 200px;
  height: 150px;
  flex-shrink: 0;
}

.re-seg-body {
  padding: 0.75rem;
  flex: 1;
  min-width: 0;
}

.re-seg-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 0.3rem;
  vertical-align: middle;
}

.re-seg-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.4rem;
  font-size: 0.9rem;
}

.re-seg-dist {
  color: #64748b;
  font-size: 0.85rem;
}

.re-seg-controls {
  display: flex;
  align-items: center;
  gap: 1rem;
  font-size: 0.85rem;
}

.re-seg-controls label {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  color: #475569;
}

.re-speed-input {
  width: 60px;
  padding: 0.25rem 0.4rem;
  border: 1px solid #cbd5e1;
  border-radius: 4px;
  font-size: 0.85rem;
}

.re-seg-consumption {
  color: #2563eb;
  font-weight: 500;
}

.re-totals {
  background: #fff;
  border-radius: 8px;
  padding: 1.25rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.re-totals-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 1rem;
}

.re-total-item {
  text-align: center;
}

.re-total-label {
  font-size: 0.8rem;
  color: #64748b;
  margin-bottom: 0.2rem;
}

.re-total-value {
  font-size: 1.2rem;
  font-weight: 700;
  color: #1e293b;
}

.re-ok {
  color: #16a34a;
}

.re-warn {
  color: #dc2626;
}

/* Responsive */
@media (max-width: 640px) {
  .calc-grid,
  .form-grid,
  .re-globals-grid,
  .re-totals-grid {
    grid-template-columns: 1fr;
  }

  .tabs {
    overflow-x: auto;
  }

  .tab-btn {
    padding: 0.6rem 1rem;
    font-size: 0.85rem;
    white-space: nowrap;
  }

  .output-value .value {
    font-size: 1.4rem;
  }

  h1 {
    font-size: 1.25rem;
  }

  .re-segment {
    flex-direction: column;
  }

  .re-seg-map {
    width: 100%;
    height: 150px;
  }
}
