/* ui/style.css */
/* ── TOKENS ── */
:root {
  --bg: #0f0f0f;
  --bg1: #141414;
  --bg2: #1a1a1a;
  --bg3: #202020;
  --border: rgba(255, 255, 255, 0.07);
  --border2: rgba(255, 255, 255, 0.12);
  --t1: #e8e8e8;
  --t2: #8b8b8b;
  --t3: #525252;
  --accent: #8b5cf6;
  --ok: #22c55e;
  --warn: #f59e0b;
  --err: #ef4444;
  --info: #60a5fa;
  --r: 6px;
  --sidebar: 220px;
}

/* ── LIGHT THEME OVERRIDES ── */
html.light-theme {
  --bg: #f8fafc;
  --bg1: #ffffff;
  --bg2: #f1f5f9;
  --bg3: #e2e8f0;
  --border: rgba(0, 0, 0, 0.08);
  --border2: rgba(0, 0, 0, 0.14);
  --t1: #0f172a;
  --t2: #475569;
  --t3: #94a3b8;
  --accent: #7c3aed;
}

/* ── RESET ── */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 13px;
}

body {
  font-family: 'Inter', -apple-system, sans-serif;
  background: var(--bg);
  color: var(--t1);
  display: flex;
  height: 100vh;
  overflow: hidden;
}

::-webkit-scrollbar {
  width: 5px;
  height: 5px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--bg3);
  border-radius: 99px;
}

/* ── SIDEBAR ── */
#sidebar {
  width: var(--sidebar);
  flex-shrink: 0;
  background: var(--bg1);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.s-logo {
  padding: 20px 16px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 9px;
}

.s-logo-mark {
  width: 22px;
  height: 22px;
  background: var(--accent);
  border-radius: 5px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: white;
  flex-shrink: 0;
}

.s-logo-text {
  font-weight: 600;
  font-size: 13px;
  color: var(--t1);
  line-height: 1;
}

.s-logo-sub {
  font-size: 10px;
  color: var(--t3);
  margin-top: 2px;
}

.s-nav {
  padding: 8px 8px;
  flex: 1;
}

.s-section {
  font-size: 10px;
  font-weight: 500;
  color: var(--t3);
  text-transform: uppercase;
  letter-spacing: .08em;
  padding: 12px 8px 4px;
}

.s-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 5px;
  cursor: pointer;
  color: var(--t2);
  font-size: 12.5px;
  font-weight: 400;
  transition: background .1s, color .1s;
  user-select: none;
  position: relative;
}

.s-item:hover {
  background: var(--bg2);
  color: var(--t1);
}

.s-item.active {
  background: var(--bg2);
  color: var(--t1);
  font-weight: 500;
}

.s-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 20%;
  bottom: 20%;
  width: 2px;
  background: var(--accent);
  border-radius: 1px;
}

.s-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  opacity: .7;
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.s-icon svg {
  width: 14px;
  height: 14px;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}

.s-badge {
  margin-left: auto;
  font-size: 10px;
  font-weight: 500;
  color: var(--t3);
  background: var(--bg3);
  padding: 1px 5px;
  border-radius: 4px;
}

.s-badge.err {
  color: var(--err);
  background: rgba(239, 68, 68, .1);
}

.s-badge.warn {
  color: var(--warn);
  background: rgba(245, 158, 11, .1);
}

.s-badge.ok {
  color: var(--ok);
  background: rgba(34, 197, 94, .1);
}

.s-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 7px;
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ok);
  flex-shrink: 0;
}

.status-dot.err {
  background: var(--err);
}

.s-footer-text {
  font-size: 11px;
  color: var(--t3);
}

.s-footer-link {
  font-size: 11px;
  color: var(--t3);
  text-decoration: none;
  transition: color .15s;
}

.s-footer-link:hover {
  color: var(--t2);
}

.theme-toggle {
  background: transparent;
  border: none;
  color: var(--t3);
  cursor: pointer;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
  border-radius: 4px;
  transition: color .15s, background .15s;
  margin-left: 8px;
}

.theme-toggle:hover {
  color: var(--t1);
  background: var(--bg2);
}

/* Thème sombre par défaut -> cacher l'icône lune, montrer l'icône soleil */
html .theme-toggle .moon-icon {
  display: none;
}

html .theme-toggle .sun-icon {
  display: block;
}

/* Thème clair -> cacher l'icône soleil, montrer l'icône lune */
html.light-theme .theme-toggle .sun-icon {
  display: none;
}

html.light-theme .theme-toggle .moon-icon {
  display: block;
}

/* ── MAIN ── */
#main {
  flex: 1;
  overflow-y: auto;
  padding: 28px 32px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* ── PAGE ── */
.page {
  display: none;
  flex-direction: column;
  gap: 20px;
  animation: fadein .2s;
}

.page.active {
  display: flex;
}

@keyframes fadein {
  from {
    opacity: 0;
    transform: translateY(6px);
  }

  to {
    opacity: 1;
    transform: none;
  }
}

.page-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
}

.page-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--t1);
}

.page-desc {
  font-size: 12px;
  color: var(--t3);
  margin-top: 3px;
}

/* ── BUTTONS ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 12px;
  border-radius: var(--r);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  font-family: inherit;
  transition: all .15s;
}

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

.btn-primary:hover {
  opacity: .85;
}

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border2);
  color: var(--t2);
}

.btn-ghost:hover {
  color: var(--t1);
  background: var(--bg2);
}

/* ── STAT CARDS ── */
.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: var(--r);
  overflow: hidden;
}

.stat-cell {
  background: var(--bg1);
  padding: 16px 18px;
  transition: background .15s;
}

.stat-cell:hover {
  background: var(--bg2);
}

.stat-label {
  font-size: 11px;
  color: var(--t3);
  margin-bottom: 6px;
}

.stat-value {
  font-size: 22px;
  font-weight: 600;
  color: var(--t1);
  letter-spacing: -.02em;
}

.stat-value.accent {
  color: var(--accent);
}

.stat-sub {
  font-size: 10px;
  color: var(--t3);
  margin-top: 3px;
}

/* ── CARDS ── */
.card {
  background: var(--bg1);
  border: 1px solid var(--border);
  border-radius: var(--r);
  overflow: hidden;
}

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

.card-title {
  font-size: 12px;
  font-weight: 500;
  color: var(--t2);
}

.card-body {
  padding: 16px;
}

/* ── TABLES ── */
.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

thead th {
  padding: 8px 14px;
  text-align: left;
  font-size: 11px;
  font-weight: 500;
  color: var(--t3);
  background: var(--bg1);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}

thead th:hover {
  color: var(--t2);
}

tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background .1s;
}

tbody tr:last-child {
  border-bottom: none;
}

tbody tr:hover {
  background: var(--bg2);
}

tbody td {
  padding: 8px 14px;
  color: var(--t2);
  vertical-align: middle;
}

.td-em {
  color: var(--t1);
  font-weight: 500;
}

/* ── BADGES ── */
.badge {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 500;
}

.badge-ok {
  background: rgba(34, 197, 94, .12);
  color: var(--ok);
}

.badge-warn {
  background: rgba(245, 158, 11, .12);
  color: var(--warn);
}

.badge-err {
  background: rgba(239, 68, 68, .12);
  color: var(--err);
}

.badge-info {
  background: rgba(96, 165, 250, .12);
  color: var(--info);
}

.badge-neu {
  background: var(--bg3);
  color: var(--t2);
}

/* ── INPUTS ── */
.input {
  background: var(--bg1);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 7px 11px;
  color: var(--t1);
  font-size: 12px;
  font-family: inherit;
  outline: none;
  transition: border-color .15s;
  min-width: 200px;
}

.input::placeholder {
  color: var(--t3);
}

.input:focus {
  border-color: var(--accent);
}

/* ── ROUTE PILL ── */
.route-pill {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
}

/* ── MAP ── */
#map {
  height: 420px;
  border-radius: var(--r);
  border: 1px solid var(--border);
  overflow: hidden;
}

.leaflet-container {
  background: var(--bg) !important;
  font-family: 'Inter', sans-serif !important;
}

/* ── CALENDAR ── */
.svc-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
  transition: background .1s;
}

.svc-row:last-child {
  border-bottom: none;
}

.svc-row:hover {
  background: var(--bg2);
}

.svc-id {
  font-family: monospace;
  font-size: 11px;
  color: var(--accent);
  min-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.day-dots {
  display: flex;
  gap: 3px;
}

.dd {
  width: 18px;
  height: 18px;
  border-radius: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  font-weight: 600;
}

.dd.on {
  background: var(--accent);
  color: white;
}

.dd.off {
  background: var(--bg3);
  color: var(--t3);
}

.svc-date {
  font-size: 10px;
  color: var(--t3);
  white-space: nowrap;
}

.svc-count {
  margin-left: auto;
  font-size: 11px;
  color: var(--t3);
  white-space: nowrap;
}

/* ── VALIDITY BAR ── */
.vbar-wrap {
  position: relative;
  height: 4px;
  background: var(--bg3);
  border-radius: 2px;
}

.vbar-fill {
  position: absolute;
  left: 0;
  top: 0;
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width .8s ease;
}

.vbar-today {
  position: absolute;
  top: -3px;
  bottom: -3px;
  width: 2px;
  background: var(--ok);
  border-radius: 1px;
  transition: left .5s;
}

/* ── QUALITY ── */
.qcheck {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 14px;
  border-bottom: 1px solid var(--border);
}

.qcheck:last-child {
  border-bottom: none;
}

.qcheck-icon {
  font-size: 13px;
  flex-shrink: 0;
}

.qcheck-name {
  font-weight: 500;
  color: var(--t1);
  font-size: 12px;
  flex: 1;
}

.qcheck-detail {
  font-size: 11px;
  color: var(--t3);
}

/* ── SCORE CIRCLE ── */
.score-wrap {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 16px;
}

.score-svg-wrap {
  position: relative;
  width: 80px;
  height: 80px;
  flex-shrink: 0;
}

.score-svg {
  transform: rotate(-90deg);
}

.score-track {
  fill: none;
  stroke: var(--bg3);
  stroke-width: 6;
}

.score-fill {
  fill: none;
  stroke-width: 6;
  stroke-linecap: round;
  transition: stroke-dashoffset .9s ease;
}

.score-label {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 17px;
}

.score-sub {
  font-size: 9px;
  color: var(--t3);
  font-weight: 400;
}

.score-stats {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.score-stat {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
}

.score-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ── TABS ── */
.tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0;
}

.tab {
  padding: 8px 14px;
  font-size: 12px;
  font-weight: 500;
  color: var(--t3);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color .15s, border-color .15s;
}

.tab:hover {
  color: var(--t2);
}

.tab.active {
  color: var(--t1);
  border-bottom-color: var(--accent);
}

.tab-panel {
  display: none;
}

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

/* ── SKELETON ── */
.skel {
  background: linear-gradient(90deg, var(--bg2) 25%, var(--bg3) 50%, var(--bg2) 75%);
  background-size: 200% 100%;
  animation: skel .9s infinite;
  border-radius: 4px;
}

@keyframes skel {
  0% {
    background-position: 200% 0;
  }

  100% {
    background-position: -200% 0;
  }
}

.spinner {
  width: 14px;
  height: 14px;
  border: 1.5px solid var(--bg3);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .6s linear infinite;
  display: inline-block;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.empty {
  padding: 32px;
  text-align: center;
  color: var(--t3);
  font-size: 12px;
}

.err-msg {
  color: var(--err);
  font-size: 11px;
  padding: 8px 14px;
}

code {
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  font-size: .9em;
}

/* ── MOBILE RESPONSIVENESS ── */
.mobile-header {
  display: none;
}

.menu-toggle {
  background: transparent;
  border: none;
  color: var(--t1);
  cursor: pointer;
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
  border-radius: 4px;
  transition: background .15s;
}

.menu-toggle:hover {
  background: var(--bg2);
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(2px);
  z-index: 1999;
  opacity: 0;
  transition: opacity 0.3s;
}

.sidebar-overlay.visible {
  display: block;
  opacity: 1;
}

@media (max-width: 768px) {
  body {
    flex-direction: column;
  }

  .mobile-header {
    display: flex;
    align-items: center;
    gap: 12px;
    height: 52px;
    padding: 0 16px;
    background: var(--bg1);
    border-bottom: 1px solid var(--border);
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1000;
  }

  .mobile-header-title {
    font-weight: 600;
    font-size: 14px;
    color: var(--t1);
  }

  #sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 2000;
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.4);
  }

  #sidebar.open {
    transform: translateX(0);
  }

  #main {
    padding: 16px;
    margin-top: 52px;
    height: calc(100vh - 52px);
    overflow-y: auto;
  }

  .page-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }

  /* Stack layout grids */
  div[style*="display:grid;grid-template-columns:1fr 1fr"],
  div[style*="display: grid; grid-template-columns: 1fr 1fr"],
  div[style*="grid-template-columns:1fr 1fr"],
  div[style*="grid-template-columns: 1fr 1fr"] {
    grid-template-columns: 1fr !important;
  }

  #map {
    height: 300px;
  }
}

/* ── MODAL GRILLE HORAIRE (GRID) ── */
.grid-container {
  overflow: auto;
  flex-grow: 1;
  position: relative;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  margin: 16px;
}

.grid-table {
  border-collapse: separate;
  border-spacing: 0;
  font-size: 11.5px;
  width: 100%;
}

.grid-table th,
.grid-table td {
  padding: 8px 12px;
  text-align: center;
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  white-space: nowrap;
}

.grid-table th {
  background: var(--bg2);
  color: var(--t2);
  font-weight: 500;
  position: sticky;
  top: 0;
  z-index: 10;
}

/* Sticky stop list column on the left */
.grid-table th.sticky-col,
.grid-table td.sticky-col {
  position: sticky;
  left: 0;
  background: var(--bg1);
  text-align: left;
  z-index: 5;
  border-right: 2px solid var(--border2);
  font-weight: 500;
}

.grid-table th.sticky-col {
  z-index: 15;
  background: var(--bg2);
}

/* Hover effects */
.grid-table tr:hover td {
  background: var(--bg2);
}

.grid-table tr:hover td.sticky-col {
  background: var(--bg3);
}

/* Timeline dots and line */
.timeline-cell {
  display: flex;
  align-items: center;
  gap: 10px;
}

.timeline-track {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.timeline-track::before {
  content: '';
  position: absolute;
  top: -10px;
  bottom: -10px;
  width: 2px;
  background: var(--line-color, var(--accent));
  opacity: 0.8;
}

tr:first-child .timeline-track::before {
  top: 50%;
}

tr:last-child .timeline-track::before {
  bottom: 50%;
}

.timeline-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--bg1);
  border: 2px solid var(--line-color, var(--accent));
  z-index: 1;
  box-shadow: 0 0 0 2px var(--bg);
}

.time-text {
  font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
  font-weight: 500;
  color: var(--accent);
}

.time-empty {
  color: var(--t3);
  font-weight: 300;
}
