/* ==========================================================================
   Design System & Premium Theme Variables
   ========================================================================== */
:root {
  /* Fonts */
  --font-headers: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;

  /* Colors (Light Theme Defaults) */
  --bg-gradient: linear-gradient(135deg, #f5f7fa 0%, #e4e8f0 100%);
  --bg-card: rgba(255, 255, 255, 0.85);
  --bg-input: #ffffff;
  --text-main: #1e293b;
  --text-muted: #64748b;
  --text-inverse: #ffffff;
  
  --primary: hsl(142, 60%, 40%);         /* Premium Emerald/Communauto Green */
  --primary-hover: hsl(142, 60%, 35%);
  --primary-light: hsl(142, 50%, 93%);
  --primary-glow: rgba(76, 175, 80, 0.2);

  --accent: #0b57d0;                      /* Cobalt Accent */
  --border-color: rgba(226, 232, 240, 0.8);
  --border-focus: #4caf50;
  
  --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.02);
  --shadow-md: 0 10px 25px -5px rgba(0, 0, 0, 0.05), 0 8px 10px -6px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 20px 40px -10px rgba(0, 0, 0, 0.08);
  
  --glass-border: rgba(255, 255, 255, 0.4);
  --glass-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.05);

  --transition-speed: 0.25s;
  --radius-lg: 18px;
  --radius-md: 12px;
  --radius-sm: 8px;
}

/* Dark Theme Variables */
[data-theme="dark"] {
  --bg-gradient: linear-gradient(135deg, #0f172a 0%, #1e1b4b 100%); /* Slate to Indigo deep */
  --bg-card: rgba(30, 41, 59, 0.7);
  --bg-input: rgba(15, 23, 42, 0.6);
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-inverse: #0f172a;
  
  --primary: hsl(142, 70%, 45%);         /* Lighter, high-contrast green for dark mode */
  --primary-hover: hsl(142, 70%, 50%);
  --primary-light: rgba(16, 185, 129, 0.15);
  --primary-glow: rgba(16, 185, 129, 0.35);
  
  --accent: #38bdf8;
  --border-color: rgba(255, 255, 255, 0.08);
  --border-focus: hsl(142, 70%, 45%);
  
  --shadow-md: 0 10px 30px -10px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 25px 50px -12px rgba(0, 0, 0, 0.7);
  
  --glass-border: rgba(255, 255, 255, 0.05);
  --glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.3);
}

/* ==========================================================================
   Reset & Base Styles
   ========================================================================== */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-body);
  background: var(--bg-gradient);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 2rem 1rem;
  transition: background var(--transition-speed) ease, color var(--transition-speed) ease;
}

/* App Container Layout */
.app-container {
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

/* ==========================================================================
   Typography & Typography Improvements
   ========================================================================== */
h1 {
  font-family: var(--font-headers);
  font-size: 2.2rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  background: linear-gradient(to right, var(--primary), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

h2, h3 {
  font-family: var(--font-headers);
  font-weight: 700;
  letter-spacing: -0.01em;
}

/* ==========================================================================
   Header & Controls
   ========================================================================== */
.app-header {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border-color);
}

.logo-area {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.logo-icon {
  font-size: 2rem;
  filter: drop-shadow(0 2px 8px var(--primary-glow));
}

.tagline {
  font-size: 1rem;
  color: var(--text-muted);
}

/* Theme Toggle Button */
.theme-btn {
  position: absolute;
  top: 0;
  right: 0;
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background: var(--bg-card);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-speed) ease;
  outline-offset: 4px;
  box-shadow: var(--shadow-sm);
}

.theme-btn:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.theme-btn:focus-visible {
  outline: 2px solid var(--primary);
}

[data-theme="dark"] .light-icon,
:not([data-theme="dark"]) .dark-icon {
  display: none;
}

/* ==========================================================================
   Layout Grid
   ========================================================================== */
.calculator-grid {
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: 2rem;
}

@media (max-width: 850px) {
  .calculator-grid {
    grid-template-columns: 1fr;
  }
}

/* Glassmorphism Card Style */
.card {
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--glass-shadow), var(--shadow-lg);
  padding: 2rem;
  transition: transform var(--transition-speed) ease, box-shadow var(--transition-speed) ease, border-color var(--transition-speed) ease;
}

.panel-title {
  font-size: 1.4rem;
  margin-bottom: 1.5rem;
  position: relative;
  display: inline-block;
}

.panel-title::after {
  content: '';
  position: absolute;
  left: 0;
  bottom: -6px;
  width: 40px;
  height: 4px;
  background: var(--primary);
  border-radius: 2px;
}

/* ==========================================================================
   Form Styling (Inputs, Choices, Labels)
   ========================================================================== */
.form-group {
  margin-bottom: 1.5rem;
}

.input-label {
  display: block;
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 0.5rem;
  color: var(--text-main);
}

.hint-text {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
  display: block;
}

/* Choice Chips (Mutually Exclusive Radios) */
.radio-group-fieldset {
  border: none;
  padding: 0;
  margin: 0;
}

.choice-chips {
  display: flex;
  gap: 1rem;
  width: 100%;
}

.chip-label {
  flex: 1;
  cursor: pointer;
  position: relative;
}

.chip-label input[type="radio"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.chip-content {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding: 0.85rem 1.25rem;
  border-radius: var(--radius-md);
  border: 2px solid var(--border-color);
  background: var(--bg-input);
  transition: all var(--transition-speed) ease;
  min-height: 72px;
}

.chip-title {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--text-main);
}

.chip-desc {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.chip-label input[type="radio"]:checked + .chip-content {
  border-color: var(--primary);
  background: var(--primary-light);
  box-shadow: 0 0 12px var(--primary-glow);
}

.chip-label input[type="radio"]:focus-visible + .chip-content {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Toggle Switch (Checkbox styling) */
.mode-toggle-container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(0, 0, 0, 0.02);
  padding: 0.75rem 1rem;
  border-radius: var(--radius-md);
  border: 1px dashed var(--border-color);
}

.switch-container {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.85rem;
  font-weight: 500;
}

.switch {
  position: relative;
  display: inline-block;
  width: 48px;
  height: 24px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--text-muted);
  transition: .3s;
  border-radius: 34px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: .3s;
  border-radius: 50%;
}

.switch input:checked + .slider {
  background-color: var(--primary);
}

.switch input:focus-visible + .slider {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.switch input:checked + .slider:before {
  transform: translateX(24px);
}

/* Date / Simple Inputs Layout */
.dates-grid, .simple-time-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

@media (max-width: 480px) {
  .dates-grid, .simple-time-grid {
    grid-template-columns: 1fr;
  }
}

input[type="datetime-local"],
input[type="number"],
select {
  width: 100%;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background: var(--bg-input);
  color: var(--text-main);
  font-family: var(--font-body);
  font-size: 0.95rem;
  min-height: 48px;
  transition: border-color var(--transition-speed) ease, box-shadow var(--transition-speed) ease;
  outline: none;
}

input[type="datetime-local"]:focus,
input[type="number"]:focus,
select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

/* Distance Selector layout with Range and Input */
.label-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}

.badge {
  background: var(--primary);
  color: var(--text-inverse);
  font-size: 0.8rem;
  font-weight: 700;
  padding: 0.25rem 0.6rem;
  border-radius: 20px;
}

.slider-row {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.slider-row input[type="range"] {
  flex: 1;
  height: 8px;
  border-radius: 4px;
  background: var(--border-color);
  outline: none;
  cursor: pointer;
  accent-color: var(--primary);
}

.small-num-input {
  width: 80px;
  text-align: center;
  min-height: 40px;
  padding: 0.4rem;
}

.hidden {
  display: none !important;
}

/* ==========================================================================
   Results Panel Styling
   ========================================================================== */
.results-panel {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  background: var(--bg-card);
  position: sticky;
  top: 2rem;
}

.total-cost-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 1.75rem;
  border-radius: var(--radius-lg);
  background: linear-gradient(135deg, var(--primary-light) 0%, rgba(11, 87, 208, 0.06) 100%);
  border: 1px solid var(--border-color);
  text-align: center;
}

.total-label {
  font-weight: 600;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.total-amount {
  font-family: var(--font-headers);
  font-size: 3rem;
  font-weight: 800;
  color: var(--primary);
  margin-bottom: 0.25rem;
  letter-spacing: -0.02em;
}

.tax-note {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Breakdown Table */
.cost-breakdown h3 {
  font-size: 1.1rem;
  margin-bottom: 1rem;
  color: var(--text-main);
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 0.5rem;
}

.breakdown-table {
  width: 100%;
  border-collapse: collapse;
}

.breakdown-table td {
  padding: 0.85rem 0;
  font-size: 0.9rem;
  color: var(--text-muted);
  vertical-align: top;
}

.breakdown-table tr:not(:last-child) {
  border-bottom: 1px solid rgba(226, 232, 240, 0.4);
}

.breakdown-table td:last-child {
  text-align: right;
  font-weight: 600;
  color: var(--text-main);
  white-space: nowrap;
}

.calc-formula {
  display: block;
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 400;
  margin-top: 0.15rem;
}

.subtotal-row {
  border-top: 2px solid var(--border-color) !important;
  font-weight: 600;
}
.subtotal-row td {
  color: var(--text-main) !important;
  padding-top: 1.1rem !important;
}

/* Informative Alerts */
.alert-box {
  display: flex;
  gap: 0.75rem;
  padding: 1rem 1.25rem;
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  line-height: 1.45;
}

.info-box {
  background: var(--primary-light);
  border: 1px solid rgba(76, 175, 80, 0.2);
  color: var(--text-main);
}

.alert-icon {
  font-size: 1.2rem;
  flex-shrink: 0;
}

/* Accordion reference rules */
.plan-rules-accordion details {
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--bg-input);
}

.plan-rules-accordion summary {
  padding: 0.85rem 1rem;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  outline: none;
  background: var(--bg-card);
  transition: background var(--transition-speed) ease;
}

.plan-rules-accordion summary:hover {
  background: var(--primary-light);
}

.accordion-content {
  padding: 1rem;
  border-top: 1px solid var(--border-color);
}

.accordion-content ul {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.accordion-content li {
  font-size: 0.8rem;
  line-height: 1.4;
  position: relative;
  padding-left: 1.25rem;
  color: var(--text-muted);
}

.accordion-content li::before {
  content: "✦";
  position: absolute;
  left: 0;
  color: var(--primary);
}

/* ==========================================================================
   Footer
   ========================================================================== */
.app-footer {
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 1rem;
  padding: 1rem 0;
  border-top: 1px dashed var(--border-color);
}
