/* ═══════════════════════════════════════════════════════════
   RUAS JALAN — Panel UI (Redesigned from scratch)
   Premium data card: hero KPI → compact stats → sections.
   Dark theme = default; light overrides at the bottom.
   ═══════════════════════════════════════════════════════════ */

/* ── Panel Toggle (mobile) ────────────────────────────────── */
.panel-toggle-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  cursor: pointer;
  flex-shrink: 0;
  transition: all var(--transition-base);
}
.panel-toggle-btn:hover { background: var(--bg-tertiary); color: var(--text-primary); }

/* ── Panel Body ────────────────────────────────────────────── */
#panel-body {
  padding: 16px;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  scroll-behavior: smooth;
}
#panel-body::-webkit-scrollbar { width: 5px; }
#panel-body::-webkit-scrollbar-track { background: transparent; }
#panel-body::-webkit-scrollbar-thumb { background: var(--border-default); border-radius: 999px; }
#panel-body::-webkit-scrollbar-thumb:hover { background: var(--border-strong); }

/* ── Header ───────────────────────────────────────────────── */
#panel-header .panel-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  background: #2563EB;
  color: #FFFFFF;
  border-radius: 10px;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.35);
}
#panel-header h1 { font-size: 14px; font-weight: 600; }

.badge {
  margin-left: auto;
  background: rgba(37, 99, 235, 0.15);
  color: #93C5FD;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  font-family: 'Fira Code', 'Fira Sans', monospace;
  min-width: 32px;
  text-align: center;
  border: 1px solid rgba(37, 99, 235, 0.2);
}

/* ── Section Spacing ───────────────────────────────────────── */
.panel-section { margin-bottom: 16px; }
.panel-section:last-child { margin-bottom: 0; }

/* ── Stats: hero (first card) ──────────────────────────────── */
.stats-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }

.stat-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 12px 10px;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 10px;
  text-align: center;
  transition: all var(--transition-base);
}
.stat-card:hover {
  border-color: var(--border-strong);
  background: var(--bg-tertiary);
}

.stat-icon { display: none; }

.stat-content { flex: 1; min-width: 0; }

.stat-label {
  font-size: 9px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  line-height: 1.3;
  margin: 0;
}
.stat-value {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
  font-family: 'Fira Code', 'Fira Sans', monospace;
  line-height: 1.2;
}
.stat-value--blue { color: #60A5FA; }
.stat-value--green { color: #22C55E; }
.stat-value--purple { color: #A78BFA; }

/* HERO — "Total Ruas" is the primary KPI: spans full row. */
.stats-grid > .stat-card:first-child {
  grid-column: span 3;
  flex-direction: row;
  justify-content: flex-start;
  gap: 10px;
  padding: 10px 14px;
  text-align: left;
  background: linear-gradient(135deg, rgba(37, 99, 235, 0.14), rgba(37, 99, 235, 0.04));
  border-color: rgba(37, 99, 235, 0.3);
}
.stats-grid > .stat-card:first-child .stat-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: #2563EB;
  color: #FFFFFF;
  border-radius: 9px;
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(37, 99, 235, 0.35);
}
.stats-grid > .stat-card:first-child .stat-label {
  font-size: 9px;
  letter-spacing: 0.08em;
  color: #93C5FD;
  text-align: left;
}
.stats-grid > .stat-card:first-child .stat-value {
  font-size: 24px;
  font-weight: 800;
  color: #FFFFFF;
  line-height: 1.1;
}

/* ── Section Headers ───────────────────────────────────────── */
.section-header {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 9px;
  cursor: pointer;
  user-select: none;
}
.section-chevron {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-muted);
  font-size: 9px;
  transition: transform var(--transition-base), background var(--transition-base), color var(--transition-base);
}
.section-header:hover .section-chevron { color: #60A5FA; background: rgba(37, 99, 235, 0.12); }
.section-header:hover .section-title { color: #F8FAFC; }
.panel-section:not(.collapsed) .section-chevron { transform: rotate(90deg); }
.panel-section.collapsed .section-chevron { transform: rotate(0deg); }

.section-title {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  margin: 0;
  transition: color var(--transition-base);
}

.section-content {
  overflow: hidden;
  transition: max-height var(--transition-slow), opacity var(--transition-base);
  max-height: 2000px;
  opacity: 1;
}
.panel-section.collapsed .section-content { max-height: 0; opacity: 0; }

/* ── File Drop Zone ────────────────────────────────────────── */
#file-drop {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 16px 14px;
  background: var(--bg-elevated);
  border: 1.5px dashed var(--border-default);
  border-radius: 10px;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition-base);
  min-height: 84px;
}
#file-drop:hover {
  border-color: #3B82F6;
  background: rgba(37, 99, 235, 0.05);
}
#file-drop:focus-visible { outline: 2px solid var(--border-focus); outline-offset: 2px; }

#file-drop .file-drop-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  background: rgba(37, 99, 235, 0.12);
  color: #60A5FA;
  border-radius: 9px;
  margin-bottom: 8px;
}
#file-drop .file-drop-text { font-size: 12px; color: var(--text-secondary); margin: 0; }
#file-drop .file-drop-text strong { color: var(--text-primary); font-weight: 600; }
#file-drop .file-drop-hint { font-size: 10px; color: var(--text-muted); margin-top: 3px; }

/* Loaded state — single compact row: check icon + status */
#file-drop.file-drop-zone--loaded {
  flex-direction: row;
  justify-content: flex-start;
  gap: 10px;
  padding: 9px 12px;
  border-style: solid;
  border-color: rgba(34, 197, 94, 0.4);
  background: rgba(34, 197, 94, 0.06);
  min-height: auto;
}
#file-drop.file-drop-zone--loaded:hover {
  border-color: rgba(34, 197, 94, 0.55);
  background: rgba(34, 197, 94, 0.09);
}
#file-drop.file-drop-zone--loaded .file-drop-icon {
  width: 28px;
  height: 28px;
  margin: 0;
  background: rgba(34, 197, 94, 0.14);
  color: #22C55E;
  border-radius: 8px;
  flex-shrink: 0;
}
#file-drop.file-drop-zone--loaded .file-drop-text,
#file-drop.file-drop-zone--loaded .file-drop-hint { display: none; }

#file-drop .file-status {
  font-size: 11px;
  font-weight: 600;
  margin: 0;
  line-height: 1.4;
}
#file-drop .file-status--success { color: #22C55E; }
#file-drop .file-status--error { color: #EF4444; }
#file-drop .file-status--loading { color: #F59E0B; }

/* ── UPTD List ─────────────────────────────────────────────── */
.uptd-list { display: flex; flex-direction: column; gap: 6px; }

.uptd-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: 8px;
  cursor: pointer;
  transition: all var(--transition-base);
  min-height: 40px;
}
.uptd-item:hover {
  border-color: var(--border-strong);
  background: var(--bg-tertiary);
}
.uptd-item:focus-visible { outline: 2px solid var(--border-focus); outline-offset: 2px; }

.uptd-item input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.uptd-item-check {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  background: transparent;
  border: 1.5px solid var(--border-strong);
  border-radius: 5px;
  color: transparent;
  flex-shrink: 0;
  transition: all var(--transition-base);
}
.uptd-item[aria-checked="true"] .uptd-item-check {
  background: var(--uptd-color, #2563EB);
  border-color: var(--uptd-color, #2563EB);
  color: #FFFFFF;
}

.uptd-item-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--uptd-color, var(--color-uptd-default));
  flex-shrink: 0;
}

.uptd-item-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-primary);
  flex: 1;
  min-width: 0;
}

.uptd-item-count {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
  padding: 2px 7px;
  border-radius: 999px;
  font-family: 'Fira Code', monospace;
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}

/* ── Legend ────────────────────────────────────────────────── */
#legend {
  position: absolute;
  bottom: 45px;
  right: 12px;
  left: auto;
  z-index: 10;
  background: #0F172A;
  color: var(--text-primary);
  font-family: 'Fira Sans', system-ui, -apple-system, sans-serif;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 10px;
  padding: 12px 14px;
  box-shadow: var(--shadow-md);
  min-width: 140px;
  backdrop-filter: blur(6px);
}
.legend-title {
  font-size: 10px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin: 0 0 10px 0;
}
.legend-content { display: flex; flex-direction: column; gap: 6px; }
.legend-row { display: flex; align-items: center; gap: 8px; }
.legend-color-dot { width: 14px; height: 4px; border-radius: 999px; flex-shrink: 0; }
.legend-label { font-size: 11px; color: var(--text-secondary); }

/* ── Drop Overlay ──────────────────────────────────────────── */
#drop-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  background: var(--surface-scrim);
  justify-content: center;
  align-items: center;
  backdrop-filter: blur(4px);
}
#drop-overlay.active { display: flex; }
.drop-overlay-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: var(--space-12) var(--space-16);
  border: 3px dashed var(--accent-primary);
  border-radius: var(--radius-xl);
  text-align: center;
}
.drop-overlay-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 80px;
  height: 80px;
  background: var(--color-primary-100);
  color: var(--color-primary-600);
  border-radius: 999px;
  margin-bottom: var(--space-4);
}
.drop-overlay-title {
  font-size: var(--text-xl);
  font-weight: 700;
  color: var(--accent-primary);
  margin: 0 0 var(--space-2) 0;
}
.drop-overlay-text { font-size: var(--text-sm); color: var(--text-secondary); margin: 0; }

/* ═══════════════════════════════════════════════════════════
   Mobile (bottom sheet)
   ═══════════════════════════════════════════════════════════ */
@media (max-width: 600px) {
  .panel-toggle-btn { display: flex; }

  #sheet-handle {
    display: flex;
    align-items: flex-start;
    justify-content: center;
    height: 20px;
    padding-top: 8px;
    touch-action: none;
    user-select: none;
  }
  #sheet-handle::before {
    content: "";
    width: 36px;
    height: 4px;
    border-radius: 999px;
    background: var(--text-muted);
  }

  #panel {
    position: fixed;
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-height: 50vh;
    max-height: 50dvh;
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -4px 24px rgba(2, 8, 23, 0.4);
    will-change: transform;
    transition: transform var(--transition-spring);
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  #panel-header {
    height: 54px;
    padding: 0 var(--space-4);
    padding-bottom: env(safe-area-inset-bottom, 0px);
    box-sizing: border-box;
    touch-action: none;
    user-select: none;
  }
  #panel-body {
    max-height: calc(50dvh - 74px);
    padding-bottom: calc(var(--space-3) + env(safe-area-inset-bottom, 0px));
    transition: visibility 0s var(--transition-slow);
  }
  #panel.collapsed #panel-body { visibility: hidden; }

  .stats-grid { grid-template-columns: repeat(3, 1fr); gap: 6px; }
  .stat-card { padding: 8px 6px; }
  .stat-icon { display: none; }
  .stat-value { font-size: 15px; }
  .stats-grid > .stat-card:first-child { grid-column: span 3; }
  #legend { display: none; }
}

/* ═══════════════════════════════════════════════════════════
   Light Theme Overrides
   ═══════════════════════════════════════════════════════════ */
body.light #panel-header h1 { color: #0F172A; }
body.light .badge { background: rgba(37, 99, 235, 0.1); color: #1D4ED8; border-color: rgba(37, 99, 235, 0.2); }

body.light .stat-card:hover { box-shadow: 0 4px 14px rgba(15, 23, 42, 0.08); }

body.light .stats-grid > .stat-card:first-child {
  background: linear-gradient(135deg, #DBEAFE, #EFF6FF);
  border-color: #93C5FD;
}
body.light .stats-grid > .stat-card:first-child .stat-label { color: #1D4ED8; }
body.light .stats-grid > .stat-card:first-child .stat-value { color: #1D4ED8; text-shadow: none; }

body.light .section-header:hover .section-title { color: #0F172A; }
body.light .section-chevron { background: rgba(15, 23, 42, 0.05); }
body.light .section-header:hover .section-chevron { background: rgba(37, 99, 235, 0.12); color: #1D4ED8; }

body.light #file-drop.file-drop-zone--loaded { border-color: #86EFAC; background: #F0FDF4; }
body.light #file-drop.file-drop-zone--loaded:hover { border-color: #4ADE80; background: #ECFDF5; }
body.light #file-drop .file-status--success { color: #16A34A; }

body.light .uptd-item-count { background: #F1F5F9; }
body.light .uptd-item[aria-checked="true"] .uptd-item-check { box-shadow: 0 2px 6px rgba(37, 99, 235, 0.25); }
