/* ============================================================
   1. CSS CUSTOM PROPERTIES
   ============================================================ */
:root {
  /* Colors — Light Theme */
  --bg:              #FFFFFF;
  --bg-secondary:    #F4F5F7;
  --bg-tertiary:     #EAECF0;
  --text:            #1A1A2E;
  --text-secondary:  #555770;
  --text-muted:      #8E8EA0;
  --border:          #D0D5DD;
  --border-light:    #E4E7EC;
  --accent:          #4361EE;
  --accent-hover:    #3651D4;
  --accent-light:    #EEF0FF;
  --success:         #2E7D32;
  --danger:          #D32F2F;
  --card-bg:         #FFFFFF;
  --card-shadow:     0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
  --card-radius:     12px;

  /* Timeline specific */
  --berlin-work:     #81C784;
  --bucharest-work:  #4DB6AC;
  --overlap-work:    #FFB300;
  --non-work:        #E8E8E8;
  --current-time:    #E53935;
  --dst-standard:    #42A5F5;
  --dst-daylight:    #FFA726;

  /* Spacing */
  --sp-xs:  4px;
  --sp-sm:  8px;
  --sp-md:  16px;
  --sp-lg:  24px;
  --sp-xl:  32px;
  --sp-2xl: 48px;

  /* Radii */
  --radius-sm:  4px;
  --radius-md:  8px;
  --radius-lg:  12px;
  --radius-xl:  16px;
  --radius-pill: 9999px;

  /* Shadows */
  --shadow-sm:  0 1px 2px rgba(0,0,0,0.05);
  --shadow-md:  0 4px 6px rgba(0,0,0,0.07);
  --shadow-lg:  0 10px 15px rgba(0,0,0,0.1);

  /* Layout */
  --header-height:   56px;
  --banner-height:   40px;
  --container-max:   960px;
  --footer-height:   44px;

  /* Transitions */
  --transition-fast: 0.15s ease;
  --transition-base: 0.25s ease;
}

/* ============================================================
   2. DARK THEME OVERRIDES
   ============================================================ */
html.theme-dark {
  --bg:              #0D0D1A;
  --bg-secondary:    #161628;
  --bg-tertiary:     #1E1E36;
  --text:            #E4E4F0;
  --text-secondary:  #A0A0BC;
  --text-muted:      #6E6E88;
  --border:          #2E2E4A;
  --border-light:    #242440;
  --accent:          #6C83F2;
  --accent-hover:    #8DA0FF;
  --accent-light:    #1A1E3A;
  --card-bg:         #161628;
  --card-shadow:     0 1px 3px rgba(0,0,0,0.3), 0 1px 2px rgba(0,0,0,0.2);

  --berlin-work:     #388E3C;
  --bucharest-work:  #00897B;
  --overlap-work:    #FF8F00;
  --non-work:        #2A2A40;
  --current-time:    #EF5350;
  --dst-standard:    #1E88E5;
  --dst-daylight:    #FB8C00;
}

/* ============================================================
   3. RESET & BASE
   ============================================================ */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  padding-top: calc(var(--header-height) + var(--banner-height));
  padding-bottom: calc(var(--footer-height) + var(--sp-xl));
  min-height: 100vh;
  transition: background var(--transition-base), color var(--transition-base);
}

img, svg { display: inline-block; max-width: 100%; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button { cursor: pointer; font-family: inherit; }
input, select { font-family: inherit; }

/* ============================================================
   4. TYPOGRAPHY
   ============================================================ */
h1 { font-size: 1.75rem; font-weight: 700; line-height: 1.3; margin-bottom: var(--sp-sm); color: var(--text); }
h2 { font-size: 1.25rem; font-weight: 600; line-height: 1.4; margin-bottom: var(--sp-sm); color: var(--text); }
h3 { font-size: 1.1rem;   font-weight: 600; line-height: 1.4; margin-bottom: var(--sp-xs); color: var(--text); }
p  { margin-bottom: var(--sp-md); color: var(--text-secondary); }
small { font-size: 0.85rem; color: var(--text-muted); }

/* ============================================================
   5. LAYOUT & CONTAINER
   ============================================================ */
.container {
  max-width: var(--container-max);
  margin: 0 auto;
  padding: 0 var(--sp-md);
}

.tool-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--card-radius);
  box-shadow: var(--card-shadow);
  padding: var(--sp-xl);
  margin: var(--sp-lg) 0;
}

/* ============================================================
   6. HEADER
   ============================================================ */
.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  height: var(--header-height);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 var(--sp-md);
  transition: background var(--transition-base);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  max-width: var(--container-max);
  margin: 0 auto;
}

.header-logo {
  display: flex;
  align-items: center;
  gap: var(--sp-sm);
  text-decoration: none;
  color: var(--text);
  font-weight: 700;
  font-size: 1.15rem;
}

.header-logo img,
.header-logo svg {
  width: 28px;
  height: 28px;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: var(--sp-sm);
}

/* Language switcher */
.lang-switcher {
  display: flex;
  gap: var(--sp-xs);
  background: var(--bg-secondary);
  border-radius: var(--radius-pill);
  padding: 3px;
}

.lang-btn {
  border: none;
  background: transparent;
  color: var(--text-secondary);
  padding: 4px 12px;
  border-radius: var(--radius-pill);
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  transition: all var(--transition-fast);
}

.lang-btn.active {
  background: var(--accent);
  color: #FFFFFF;
}

.lang-btn:hover:not(.active) {
  color: var(--text);
  background: var(--bg-tertiary);
}

/* Theme toggle */
.theme-toggle {
  border: 1px solid var(--border);
  background: var(--bg-secondary);
  color: var(--text);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  transition: all var(--transition-fast);
}

.theme-toggle:hover {
  border-color: var(--accent);
  background: var(--accent-light);
}

/* ============================================================
   7. SUB-SITE BANNER
   ============================================================ */
.subsite-banner {
  position: sticky;
  top: var(--header-height);
  z-index: 49;
  height: var(--banner-height);
  background: var(--accent);
  color: #FFFFFF;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-sm);
  font-size: 0.85rem;
  font-weight: 500;
}

.subsite-banner a {
  color: #FFFFFF;
  text-decoration: underline;
}

.subsite-banner a:hover {
  opacity: 0.9;
}

/* ============================================================
   8. MAIN CONTENT & TOOL CARD
   ============================================================ */
.tool-card h1 {
  text-align: center;
}

.tool-card > p {
  text-align: center;
  max-width: 600px;
  margin: 0 auto var(--sp-lg);
}

.input-section {
  display: flex;
  flex-direction: column;
  gap: var(--sp-md);
  margin-bottom: var(--sp-lg);
}

.form-row {
  display: flex;
  gap: var(--sp-md);
  flex-wrap: wrap;
}

.form-row .form-group {
  flex: 1;
  min-width: 140px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: var(--sp-xs);
}

.form-group label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.form-actions {
  display: flex;
  gap: var(--sp-sm);
  flex-wrap: wrap;
  margin-top: var(--sp-sm);
}

/* DST Info Section */
.dst-info {
  display: flex;
  gap: var(--sp-md);
  flex-wrap: wrap;
  margin-bottom: var(--sp-lg);
  padding: var(--sp-md);
  background: var(--bg-secondary);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-light);
}

.dst-card {
  flex: 1;
  min-width: 200px;
  padding: var(--sp-md);
  background: var(--card-bg);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-light);
}

.dst-card h3 {
  display: flex;
  align-items: center;
  gap: var(--sp-sm);
  font-size: 0.95rem;
}

.dst-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  color: #FFFFFF;
}

.dst-badge.standard { background: var(--dst-standard); }
.dst-badge.daylight { background: var(--dst-daylight); }

.dst-card p {
  font-size: 0.85rem;
  margin-bottom: var(--sp-xs);
}

.time-diff-card {
  flex: 1;
  min-width: 200px;
  padding: var(--sp-md);
  background: var(--card-bg);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-light);
  text-align: center;
}

.time-diff-card .diff-value {
  font-size: 2rem;
  font-weight: 700;
  color: var(--accent);
}

/* Slots Section */
.slots-section {
  margin-top: var(--sp-lg);
}

.slots-section h2 {
  margin-bottom: var(--sp-md);
}

.slots-list {
  display: flex;
  flex-direction: column;
  gap: var(--sp-sm);
}

.slot-item {
  display: flex;
  align-items: center;
  gap: var(--sp-md);
  padding: var(--sp-md);
  background: var(--bg-secondary);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-light);
  transition: border-color var(--transition-fast);
}

.slot-item:hover {
  border-color: var(--accent);
}

.slot-number {
  width: 32px;
  height: 32px;
  background: var(--accent);
  color: #FFFFFF;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
  flex-shrink: 0;
}

.slot-times {
  flex: 1;
}

.slot-times .slot-city {
  font-weight: 600;
  color: var(--text);
}

.slot-times small {
  color: var(--text-muted);
}

.slot-export {
  border: 1px solid var(--accent);
  background: transparent;
  color: var(--accent);
  padding: var(--sp-xs) var(--sp-md);
  border-radius: var(--radius-pill);
  font-size: 0.8rem;
  font-weight: 600;
  transition: all var(--transition-fast);
  flex-shrink: 0;
}

.slot-export:hover {
  background: var(--accent);
  color: #FFFFFF;
}

.no-slots {
  text-align: center;
  padding: var(--sp-xl);
  color: var(--text-muted);
  font-style: italic;
}

/* ============================================================
   9. TIMELINE COMPONENT
   ============================================================ */
.timeline-section {
  margin-top: var(--sp-lg);
}

.timeline-section h2 {
  margin-bottom: var(--sp-md);
}

.timeline-wrapper {
  position: relative;
  overflow-x: auto;
  padding-bottom: var(--sp-sm);
}

.timeline {
  position: relative;
  min-width: 700px;
}

.timeline-row {
  display: flex;
  align-items: center;
  margin-bottom: var(--sp-xs);
}

.timeline-label {
  width: 90px;
  flex-shrink: 0;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  padding-right: var(--sp-sm);
  text-align: right;
}

.timeline-bar {
  position: relative;
  flex: 1;
  height: 40px;
  display: flex;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border-light);
}

.timeline-bar .hour-segment {
  flex: 1;
  height: 100%;
  background: var(--non-work);
  border-right: 1px solid var(--border-light);
  transition: background var(--transition-fast);
}

.timeline-bar .hour-segment:last-child {
  border-right: none;
}

.timeline-bar .hour-segment.work-berlin {
  background: var(--berlin-work);
}

.timeline-bar .hour-segment.work-bucharest {
  background: var(--bucharest-work);
}

.timeline-bar .hour-segment.work-overlap {
  background: var(--overlap-work);
}

.timeline-bar .hour-segment.work-both {
  background: var(--overlap-work);
}

/* Current time line */
.timeline-current-line {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--current-time);
  z-index: 5;
  pointer-events: none;
}

.timeline-current-line::after {
  content: '';
  position: absolute;
  top: -4px;
  left: -3px;
  width: 8px;
  height: 8px;
  background: var(--current-time);
  border-radius: 50%;
}

/* Hour labels row */
.timeline-hours {
  display: flex;
  align-items: center;
  margin-bottom: var(--sp-sm);
}

.timeline-hours .timeline-label {
  width: 90px;
  flex-shrink: 0;
}

.timeline-hours-labels {
  flex: 1;
  display: flex;
  justify-content: space-between;
  font-size: 0.7rem;
  color: var(--text-muted);
  padding: 0 1px;
}

.timeline-hours-labels span {
  text-align: center;
  width: 0;
}

/* Timeline legend */
.timeline-legend {
  display: flex;
  gap: var(--sp-lg);
  margin-top: var(--sp-md);
  flex-wrap: wrap;
  justify-content: center;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: var(--sp-xs);
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.legend-swatch {
  width: 16px;
  height: 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-light);
}

.legend-swatch.sw-berlin    { background: var(--berlin-work); }
.legend-swatch.sw-bucharest { background: var(--bucharest-work); }
.legend-swatch.sw-overlap   { background: var(--overlap-work); }
.legend-swatch.sw-nonwork   { background: var(--non-work); }
.legend-swatch.sw-current   { background: var(--current-time); width: 2px; border: none; border-radius: 0; }

/* Tooltip on hover */
.timeline-bar .hour-segment[data-tooltip]:hover::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 4px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  font-size: 0.7rem;
  white-space: nowrap;
  z-index: 10;
  pointer-events: none;
}

/* ============================================================
   10. FORM CONTROLS
   ============================================================ */
input[type="date"],
input[type="time"],
select {
  height: 40px;
  padding: 0 var(--sp-md);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg);
  color: var(--text);
  font-size: 0.9rem;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  width: 100%;
}

input[type="date"]:focus,
input[type="time"]:focus,
select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-xs);
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  font-weight: 600;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

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

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

.btn-secondary {
  background: var(--bg-secondary);
  color: var(--text);
  border: 1px solid var(--border);
}

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

.btn-sm {
  padding: 6px 12px;
  font-size: 0.8rem;
}

/* ============================================================
   11. MODAL
   ============================================================ */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 100;
  justify-content: center;
  align-items: center;
  padding: var(--sp-lg);
}

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

.modal-container {
  background: var(--card-bg);
  border-radius: var(--card-radius);
  box-shadow: var(--shadow-lg);
  max-width: 680px;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
  position: relative;
}

.modal-close {
  position: absolute;
  top: var(--sp-md);
  right: var(--sp-md);
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  color: var(--text);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  cursor: pointer;
  z-index: 2;
  transition: all var(--transition-fast);
}

.modal-close:hover {
  background: var(--danger);
  color: #FFFFFF;
  border-color: var(--danger);
}

.modal-content {
  padding: var(--sp-xl);
}

.modal-content .loading {
  text-align: center;
  padding: var(--sp-2xl);
  color: var(--text-muted);
}

/* ============================================================
   12. DONATE BUTTON & LEGAL FOOTER
   ============================================================ */
.donate-btn {
  position: fixed;
  bottom: calc(var(--footer-height) + var(--sp-md));
  right: var(--sp-md);
  z-index: 90;
  background: #FFDD00;
  color: #1A1A2E;
  border: none;
  border-radius: var(--radius-pill);
  padding: 12px 24px;
  font-size: 0.9rem;
  font-weight: 700;
  display: none;
  align-items: center;
  gap: var(--sp-sm);
  box-shadow: var(--shadow-md);
  cursor: pointer;
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

.donate-btn.visible {
  display: flex;
}

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

.donate-btn svg {
  width: 18px;
  height: 18px;
}

.legal-footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 9998;
  height: var(--footer-height);
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-sm);
  font-size: 0.8rem;
  color: var(--text-muted);
}

.legal-footer a {
  color: var(--text-secondary);
  text-decoration: underline;
}

.legal-footer a:hover {
  color: var(--accent);
}

/* ============================================================
   13. RESPONSIVE
   ============================================================ */
@media (max-width: 768px) {
  :root {
    --header-height: 50px;
    --banner-height: 36px;
  }

  body {
    padding-top: calc(var(--header-height) + var(--banner-height));
  }

  .tool-card {
    padding: var(--sp-md);
  }

  h1 { font-size: 1.35rem; }
  h2 { font-size: 1.1rem; }

  .form-row {
    flex-direction: column;
  }

  .form-row .form-group {
    min-width: 0;
  }

  .form-actions {
    flex-direction: column;
  }

  .form-actions .btn {
    width: 100%;
  }

  .dst-info {
    flex-direction: column;
  }

  .dst-card,
  .time-diff-card {
    min-width: 0;
  }

  .timeline-label {
    width: 70px;
    font-size: 0.7rem;
  }

  .slot-item {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--sp-sm);
  }

  .slot-export {
    align-self: flex-end;
  }

  .donate-btn {
    bottom: calc(var(--footer-height) + var(--sp-sm));
    right: var(--sp-sm);
    padding: 10px 16px;
    font-size: 0.8rem;
  }

  .lang-switcher {
    gap: 0;
    padding: 2px;
  }

  .lang-btn {
    padding: 4px 8px;
    font-size: 0.7rem;
  }
}

@media (max-width: 480px) {
  .timeline-label {
    width: 55px;
    font-size: 0.65rem;
  }

  .timeline-legend {
    gap: var(--sp-sm);
  }
}

/* ============================================================
   14. PRINT
   ============================================================ */
@media print {
  .site-header,
  .subsite-banner,
  .donate-btn,
  .legal-footer,
  .form-actions,
  .theme-toggle,
  .lang-switcher {
    display: none !important;
  }

  body {
    padding: 0;
    background: #FFFFFF;
    color: #000000;
  }

  .tool-card {
    box-shadow: none;
    border: 1px solid #CCC;
  }

  .timeline-bar .hour-segment.work-berlin,
  .timeline-bar .hour-segment.work-bucharest,
  .timeline-bar .hour-segment.work-overlap {
    print-color-adjust: exact;
    -webkit-print-color-adjust: exact;
  }
}

/* ============================================================
   15. ACCESSIBILITY
   ============================================================ */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* High contrast mode support */
@media (forced-colors: active) {
  .btn-primary {
    border: 2px solid ButtonText;
  }

  .timeline-bar .hour-segment {
    border: 1px solid ButtonText;
  }

  .dst-badge {
    border: 1px solid;
  }
}
