:root {
  --bg: #0b0c10;
  --card: #121318;
  --line: #22252c;
  --ink: #f7f7f7;
  --muted: #b9c2d0;
  --accent: #86c5ff;
  /* Chart/timeline plot padding (must match JS) */
  --chart-pad: 35px;
}

.light {
  --bg: #ffffff;
  --card: #f8f9fa;
  --line: #e9ecef;
  --ink: #212529;
  --muted: #6c757d;
  --accent: #0d6efd;
}

html, body {
  height: 100%;
}

body.dark {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, Noto Sans, sans-serif;
}

body.light {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, Noto Sans, sans-serif;
}

.container {
  max-width: 1200px;
  margin: 24px auto;
  padding: 0 16px;
}

h1 {
  font-size: 20px;
  margin: 0;
}

.row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}


@media (min-width: 992px) {
  .row {
    grid-template-columns: 5fr 7fr;
  }
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  box-shadow: 0 6px 20px rgba(0, 0, 0, .25);
  border-radius: 12px;
}

.card-header {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-body {
  padding: 12px;
  box-sizing: border-box;
}

.controls {
  display: flex;
  gap: 8px;
  align-items: center;
}

button {
  background: var(--bg);
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 6px 10px;
  cursor: pointer;
  transition: all 0.2s ease;
}

button:hover {
  background: var(--accent);
  color: var(--bg);
  transform: translateY(-1px);
}

.btn-primary {
  background: #2a79c5;
  border-color: #2a79c5;
  color: white;
}

.bucket-wrap {
  height: 320px;
  position: relative;
  padding-top: 8px;
}

.bucket-svg {
  width: 100%;
  height: 100%;
  display: block;
}

.banner {
  display: none;
  position: absolute;
  top: -20px;
  left: 12px;
  right: 12px;
  padding: 8px 12px;
  border-radius: 8px;
  z-index: 10;
}

.show {
  display: block;
}

.threshold-amber {
  background: #2c2200;
  border: 1px solid #5c4700;
  color: #ffc107;
}

.threshold-red {
  background: #2b1214;
  border: 1px solid #732428;
  color: #ff6b6b;
}

.threshold-over {
  background: #141e2b;
  border: 1px solid #244a73;
  color: #7ec8ff;
  margin-bottom: 10px;
}

#dateLabel {
  color: var(--muted);
}

.small-note {
  color: var(--muted);
  font-size: .92rem;
}

/* Simple grid (no Tabulator) */
table.grid {
  width: 100%;
  border-collapse: collapse;
}

table.grid th,
table.grid td {
  border-bottom: 1px solid var(--line);
  padding: 6px;
  vertical-align: top;
}

table.grid th {
  color: var(--ink);
  text-align: left;
  position: sticky;
  top: 0;
  background: var(--card);
}

table.grid input,
table.grid select,
table.grid textarea {
  width: 100%;
  box-sizing: border-box;
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--ink);
  border-radius: 6px;
  padding: 6px;
}

table.grid textarea {
  min-height: 32px;
}

.actions {
  white-space: nowrap;
}

.gridbar {
  display: flex;
  gap: 8px;
  align-items: center;
}

.file {
  color: var(--muted);
}

.range {
  width: 100%;
  margin: 0;
  padding: 0;
}

/* Align the timeline slider visually with the chart's plot area (accounts for left/right chart padding) */
#timeline {
  width: calc(100% - (2 * var(--chart-pad)));
  margin-left: var(--chart-pad);
  margin-right: var(--chart-pad);
}

/* Align the "Datum" line with the chart plot area as well */
#timeline + .small-note {
  margin-left: var(--chart-pad) !important;
  margin-right: var(--chart-pad) !important;
}


#chart {
  width: 100% !important;
  max-width: 100% !important;
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

/* Events section toggle - exactly like "Bekijk alle drivers" */
#eventsToggle {
  margin-top: 8px;
}

#eventsToggle > summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 0.9em;
  transition: all 0.2s ease;
  user-select: none;
}

#eventsToggle > summary:hover {
  color: var(--accent);
}

#eventsToggle > summary::-webkit-details-marker {
  display: none;
}

#eventsToggle > summary::after {
  content: "▶";
  margin-left: 8px;
  font-size: 8px;
  color: var(--muted);
  transition: transform 0.2s ease;
  transform: rotate(0deg);
}

#eventsToggle[open] > summary::after {
  transform: rotate(90deg);
}

#eventsToggle > div {
  margin-top: 12px;
}

/* ===== Site Header & Navigation ===== */
.site-header {
  background: var(--card);
  border-bottom: 1px solid var(--line);
  padding: 12px 0;
  margin-bottom: 20px;
  max-width: 1200px;
  margin-left: auto;
  margin-right: auto;
  padding-left: 16px;
  padding-right: 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.logo-section {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 0;
}

.logo-placeholder {
  width: 40px;
  height: 40px;
  background: transparent;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  color: var(--bg);
  flex-shrink: 0;
  overflow: hidden;
}

.logo-placeholder img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: 8px;
  background: transparent;
}

.site-title {
  font-size: 24px;
  margin: 0;
  color: var(--accent);
  font-weight: 700;
}

.main-nav {
  display: flex;
  gap: 20px;
  align-items: center;
  flex-wrap: nowrap;
  margin: 0;
}

.nav-link {
  color: var(--ink);
  text-decoration: none;
  padding: 8px 16px;
  border-radius: 6px;
  font-weight: 500;
  transition: all 0.2s ease;
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 14px;
}

.nav-link:hover {
  background: var(--line);
  color: var(--accent);
}

.nav-link.active {
  background: var(--accent);
  color: var(--bg);
}

.login-btn {
  background: var(--accent) !important;
  color: var(--bg) !important;
  font-weight: 600;
}

.login-btn:hover {
  background: var(--accent) !important;
  opacity: 0.8;
}

.login-btn:active,
.login-btn.active {
  background: var(--accent) !important;
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
  transform: translateY(1px);
}

.login-btn.logged-in {
  background: var(--accent) !important;
  color: var(--bg) !important;
  font-weight: 600;
}

.login-btn.logged-in:hover {
  background: var(--accent) !important;
  opacity: 0.9;
}

/* ===== Login Modal Styles ===== */
#loginModal {
  z-index: 2000;
}

#loginModal > div {
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  animation: modalSlideIn 0.3s ease-out;
}

@keyframes modalSlideIn {
  from {
    opacity: 0;
    transform: translate(-50%, -60%);
  }
  to {
    opacity: 1;
    transform: translate(-50%, -50%);
  }
}

.login-logo {
  display: inline-block;
  background: transparent;
  border-radius: 50%;
  color: var(--bg);
  overflow: hidden;
}

.login-logo img {
  border-radius: 50%;
  background: transparent;
}

#googleLoginBtn {
  transition: all 0.2s ease;
}

#googleLoginBtn:hover {
  background: #3367d6 !important;
  transform: translateY(-1px);
}

#emailLoginBtn {
  transition: all 0.2s ease;
}

#emailLoginBtn:hover {
  background: var(--accent) !important;
  opacity: 0.9;
  transform: translateY(-1px);
}

#loginModal input {
  transition: all 0.2s ease;
  border: 1px solid var(--line);
}

#loginModal input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.1);
}

#forgotPassword {
  transition: color 0.2s ease;
}

#forgotPassword:hover {
  color: var(--accent) !important;
  text-decoration: underline;
}

/* ===== Mobile Responsiveness (max-width: 991px) ===== */
@media (max-width: 991px) {
  .site-header {
    padding: 8px 0;
    margin-bottom: 16px;
    padding-left: 12px;
    padding-right: 12px;
  }

  .logo-section {
    justify-content: center;
    margin-bottom: 8px;
  }

  .site-title {
    font-size: 20px;
  }

  .logo-placeholder {
    width: 32px;
    height: 32px;
    font-size: 16px;
  }

  .main-nav {
    gap: 8px;
    justify-content: center;
  }

  .nav-link {
    font-size: 12px;
    padding: 6px 12px;
  }
}

/* ===== Mobile Navigation ===== */
@media (max-width: 991px) {
  .container {
    margin: 16px auto;
    padding: 0 12px;
  }

  h1 {
    font-size: 18px;
    margin-bottom: 8px;
  }

  .topbar {
    flex-direction: column;
    gap: 12px;
    align-items: stretch;
    margin-bottom: 16px;
  }

  .controls {
    flex-wrap: wrap;
    justify-content: center;
    gap: 6px;
  }

  .controls button {
    font-size: 12px;
    padding: 4px 8px;
    min-width: 60px;
  }

  .controls label {
    font-size: 11px;
  }

  .controls input[type="range"] {
    width: 60px;
  }

  .controls .file {
    font-size: 11px;
  }

  .bucket-wrap {
    height: 280px;
  }

  .card {
    margin-bottom: 16px;
  }

  .card-header {
    padding: 8px 10px;
  }

  .card-body {
    padding: 10px;
  }

  .gridbar {
    flex-wrap: wrap;
    justify-content: center;
    gap: 6px;
  }

  .gridbar button {
    font-size: 11px;
    padding: 6px 10px;
    min-width: 70px;
  }

  .button-group {
    gap: 2px;
  }

  .btn-compact {
    font-size: 12px;
    min-width: 32px;
    min-height: 32px;
    padding: 6px 8px;
  }

  .gridbar label {
    font-size: 11px;
    margin-top: 8px;
    width: 100%;
    text-align: center;
  }

  table.grid {
    font-size: 12px;
  }

  table.grid th,
  table.grid td {
    padding: 4px 2px;
  }

  table.grid input,
  table.grid select,
  table.grid textarea {
    font-size: 12px;
    padding: 4px;
  }

  table.grid textarea {
    min-height: 28px;
  }

  .small-note {
    font-size: 11px;
    line-height: 1.4;
  }

  .banner {
    font-size: 11px;
    padding: 6px 8px;
    left: 8px;
    right: 8px;
    top: -15px;
  }

  /* Manual decay modal mobile improvements */
  #manualModal > div {
    margin: 10px;
    min-width: auto;
    width: calc(100vw - 20px);
    max-width: none;
    max-height: calc(100vh - 20px);
  }

  /* Better mobile scrolling for events table */
  #eventsToggle > div {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Mobile-friendly button sizes */
  button {
    min-height: 36px;
    touch-action: manipulation;
  }

  /* Improve readability on mobile */
  .manual-section {
    padding: 16px;
    margin-bottom: 20px;
  }

  .manual-section h2 {
    font-size: 20px;
  }

  .manual-section h3 {
    font-size: 16px;
  }

  .feature-list {
    gap: 8px;
  }

  .feature-item {
    padding: 10px;
  }

  .tip-box {
    padding: 12px;
    margin: 12px 0;
  }

  .code-example {
    padding: 12px;
    font-size: 12px;
  }

  /* Mobile-friendly button styles */
  .mobile-friendly-btn {
      font-size: 12px !important;
      padding: 6px 10px !important;
      min-width: 60px !important;
      min-height: 36px !important;
      touch-action: manipulation !important;
    }
  
    /* Compact icon buttons - Improved Design */
    .btn-compact {
      background: var(--bg) !important;
      color: var(--accent) !important;
      border: 1px solid var(--accent) !important;
      border-radius: 8px !important;
      padding: 8px 12px !important;
      cursor: pointer !important;
      font-size: 16px !important;
      font-weight: 600 !important;
      min-width: 40px !important;
      min-height: 40px !important;
      display: flex !important;
      align-items: center !important;
      justify-content: center !important;
      transition: all 0.2s ease !important;
      touch-action: manipulation !important;
      box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1) !important;
    }
  
    .btn-compact:hover {
      background: var(--accent) !important;
      color: var(--bg) !important;
      border-color: var(--accent) !important;
      transform: translateY(-2px) !important;
      box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15) !important;
    }
  
    .button-group {
      display: flex;
      gap: 6px;
      align-items: center;
    }
  
    .file-btn {
      background: var(--bg) !important;
      color: var(--accent) !important;
      border: 1px solid var(--accent) !important;
      border-radius: 8px !important;
      padding: 8px 12px !important;
      cursor: pointer !important;
      font-size: 16px !important;
      font-weight: 600 !important;
      min-width: 40px !important;
      min-height: 40px !important;
      display: flex !important;
      align-items: center !important;
      justify-content: center !important;
      transition: all 0.2s ease !important;
      position: relative !important;
      touch-action: manipulation !important;
      box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1) !important;
    }
  
    .file-btn:hover {
      background: var(--accent) !important;
      color: var(--bg) !important;
      border-color: var(--accent) !important;
      transform: translateY(-2px) !important;
      box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15) !important;
    }
  
    .file-btn input[type="file"] {
      position: absolute !important;
      opacity: 0 !important;
      width: 100% !important;
      height: 100% !important;
      cursor: pointer !important;
    }
  
    /* Ensure file-btn inherits all btn-compact styles */
    .btn-compact.file-btn {
      background: var(--bg) !important;
      color: var(--accent) !important;
      border: 1px solid var(--accent) !important;
    }

  .baseline-control {
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 4px 8px;
  }

  .baseline-control label {
    font-size: 11px;
    color: var(--muted);
    margin: 0;
  }

  .baseline-control input[type="range"] {
    width: 50px;
    margin: 0;
  }

  .baseline-control span {
    font-size: 11px;
    color: var(--muted);
    min-width: 20px;
  }

  .language-control {
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 4px 8px;
  }

  .language-control label {
    font-size: 11px;
    color: var(--muted);
    margin: 0;
  }

  .language-control select {
    background: var(--bg);
    border: 1px solid var(--line);
    color: var(--ink);
    border-radius: 4px;
    padding: 2px 6px;
    font-size: 11px;
  }

  /* Improve touch targets for mobile */
  .card-header {
    min-height: 48px;
  }

  .card-header span {
    font-size: 16px;
    font-weight: 600;
  }

  /* Better mobile table scrolling */
  .card-body {
    position: relative;
  }

  /* Improve modal mobile experience */
  #manualModal {
    padding: 0;
  }

  #manualModal > div {
    border-radius: 12px 12px 0 0;
    margin: 0;
    width: 100vw;
    max-width: none;
    height: 100vh;
    max-height: none;
    border-radius: 0;
    display: flex;
    flex-direction: column;
  }

  #manualModal .manual-section {
    flex: 1;
    overflow-y: auto;
    margin: 0;
    border-radius: 0;
  }

  /* Mobile viewport improvements */
  * {
    -webkit-tap-highlight-color: transparent;
  }

  /* Better form elements on mobile */
  input, select, textarea, button {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
  }

  /* Prevent zoom on input focus (iOS) */
  input[type="text"],
  input[type="number"],
  input[type="email"],
  input[type="password"],
  textarea,
  select {
    font-size: 16px !important;
  }

  /* Mobile login modal */
  #loginModal > div {
    margin: 10px;
    min-width: auto;
    width: calc(100vw - 20px);
    max-width: none;
    height: auto;
    max-height: calc(100vh - 20px);
    border-radius: 12px 12px 0 0;
    margin: 0;
    width: 100vw;
    max-width: none;
    height: 100vh;
    max-height: none;
    border-radius: 0;
    display: flex;
    flex-direction: column;
    animation: modalSlideUp 0.3s ease-out;
  }

  @keyframes modalSlideUp {
    from {
      transform: translate(-50%, 100%);
    }
    to {
      transform: translate(-50%, -50%);
    }
  }

  .login-logo {
    font-size: 40px;
    padding: 12px;
  }

  #loginModal h3 {
    font-size: 20px;
  }

  #googleLoginBtn,
  #emailLoginBtn {
    padding: 14px 20px;
    font-size: 16px;
  }

  #loginModal input {
    padding: 14px;
    font-size: 16px;
  }
}