/* ==========================================================================
   IRIE Model Viewer — Dark Mode Stylesheet
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

/* ---------- Reset & Base ---------- */

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

html, body {
  height: 100%;
  overflow: hidden;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: #1a1a2e;
  color: #e0e0e0;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

/* ---------- App Shell ---------- */

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  height: 100dvh;
  position: relative;
}

/* ---------- Header ---------- */

.viewer-header {
  background: #16213e;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  padding: 8px 14px;
  flex-shrink: 0;
  z-index: 20;
}

.header-selection {
  font-size: 13px;
  font-weight: 600;
  color: #e0e0e0;
  letter-spacing: 0.2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-selection .sep {
  color: #4a5568;
  margin: 0 5px;
}

.header-times {
  font-size: 11px;
  color: #8892a0;
  margin-top: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-times .dot {
  margin: 0 6px;
  color: #4a5568;
}

/* ---------- Image Area ---------- */

.image-area {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
  background: #111827;
  touch-action: none;
}

.image-container {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  transform-origin: center center;
  transition: none;
}

.image-container img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  display: block;
  opacity: 1;
  transition: opacity 0.15s ease;
}

.image-container img.loading {
  opacity: 0.3;
}

/* Loading spinner overlay */
.image-spinner {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 36px;
  height: 36px;
  border: 3px solid rgba(255,255,255,0.1);
  border-top-color: #0ea5e9;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  pointer-events: none;
  z-index: 5;
  display: none;
}

.image-spinner.active {
  display: block;
}

@keyframes spin {
  to { transform: translate(-50%, -50%) rotate(360deg); }
}

/* ---------- Playback Bar ---------- */

.playback-bar {
  background: #16213e;
  border-top: 1px solid rgba(255,255,255,0.08);
  padding: 8px 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  z-index: 20;
}

/* Forecast hour dropdown trigger */
.fh-dropdown-wrap {
  position: relative;
  flex-shrink: 0;
}

.fh-trigger {
  background: #1e2a4a;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 6px;
  color: #e0e0e0;
  font-family: 'Inter', sans-serif;
  font-size: 12px;
  font-weight: 600;
  padding: 6px 10px;
  min-width: 80px;
  text-align: left;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
  transition: border-color 0.2s;
}

.fh-trigger:hover, .fh-trigger:focus {
  border-color: #0ea5e9;
  outline: none;
}

.fh-trigger .caret {
  font-size: 8px;
  color: #8892a0;
  margin-left: auto;
}

/* Forecast hour dropdown list (opens upward) */
.fh-list {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 0;
  background: #1e2a4a;
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 8px;
  max-height: 260px;
  overflow-y: auto;
  min-width: 120px;
  box-shadow: 0 -8px 32px rgba(0,0,0,0.5);
  z-index: 100;
  display: none;
  scrollbar-width: thin;
  scrollbar-color: #3a4a6a #1e2a4a;
}

.fh-list.open {
  display: block;
  animation: slideUp 0.2s ease-out;
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.fh-list button {
  display: block;
  width: 100%;
  background: none;
  border: none;
  color: #c0c8d4;
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  padding: 8px 14px;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s;
}

.fh-list button:hover {
  background: rgba(14,165,233,0.15);
}

.fh-list button.active {
  background: rgba(14,165,233,0.2);
  color: #0ea5e9;
  font-weight: 600;
}

/* Slider */
.slider-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  min-width: 0;
}

input[type="range"].fh-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  background: #2a3a5e;
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}

input[type="range"].fh-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #0ea5e9;
  border: 2px solid #16213e;
  box-shadow: 0 0 6px rgba(14,165,233,0.4);
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
}

input[type="range"].fh-slider::-webkit-slider-thumb:hover {
  transform: scale(1.2);
  box-shadow: 0 0 10px rgba(14,165,233,0.6);
}

input[type="range"].fh-slider::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #0ea5e9;
  border: 2px solid #16213e;
  box-shadow: 0 0 6px rgba(14,165,233,0.4);
  cursor: pointer;
}

input[type="range"].fh-slider::-moz-range-track {
  height: 4px;
  background: #2a3a5e;
  border-radius: 2px;
}

/* Step arrows */
.step-arrows {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.step-btn {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background: #1e2a4a;
  border: 1px solid rgba(255,255,255,0.1);
  color: #e0e0e0;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}

.step-btn:hover {
  background: #263555;
  border-color: #0ea5e9;
}

.step-btn:active {
  transform: scale(0.93);
  background: #0ea5e9;
  color: #fff;
}

/* ---------- Navigation Tabs (Bottom) ---------- */

.nav-tabs {
  display: flex;
  background: #0f1629;
  border-top: 1px solid rgba(255,255,255,0.08);
  flex-shrink: 0;
  z-index: 20;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.nav-tab {
  flex: 1;
  padding: 10px 0 8px;
  background: none;
  border: none;
  color: #8892a0;
  font-family: 'Inter', sans-serif;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  cursor: pointer;
  transition: color 0.2s, background 0.2s;
  -webkit-tap-highlight-color: transparent;
  position: relative;
}

.nav-tab::after {
  content: '';
  position: absolute;
  top: 0;
  left: 20%;
  right: 20%;
  height: 2px;
  background: #0ea5e9;
  border-radius: 0 0 2px 2px;
  opacity: 0;
  transition: opacity 0.2s;
}

.nav-tab:hover {
  color: #c0c8d4;
}

.nav-tab.active {
  color: #0ea5e9;
}

.nav-tab.active::after {
  opacity: 1;
}

/* ---------- Panel Overlay (Backdrop) ---------- */

.panel-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 50;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.panel-backdrop.visible {
  opacity: 1;
  pointer-events: auto;
}

/* ---------- Slide-Up Panel ---------- */

.slide-panel {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: #16213e;
  border-top-left-radius: 16px;
  border-top-right-radius: 16px;
  z-index: 60;
  max-height: 70vh;
  overflow-y: auto;
  transform: translateY(100%);
  transition: transform 0.3s ease-out, box-shadow 0.3s ease-out;
  box-shadow: none;
  scrollbar-width: thin;
  scrollbar-color: #3a4a6a #16213e;
}

.slide-panel.open {
  transform: translateY(0);
  box-shadow: 0 -12px 48px rgba(0,0,0,0.5);
}

.panel-handle {
  display: flex;
  justify-content: center;
  padding: 10px 0 4px;
  position: sticky;
  top: 0;
  background: #16213e;
  border-top-left-radius: 16px;
  border-top-right-radius: 16px;
  z-index: 2;
}

.panel-handle::after {
  content: '';
  width: 36px;
  height: 4px;
  background: #3a4a6a;
  border-radius: 2px;
}

.panel-title {
  font-size: 14px;
  font-weight: 700;
  color: #e0e0e0;
  padding: 4px 18px 12px;
  letter-spacing: 0.3px;
  text-transform: uppercase;
  position: sticky;
  top: 28px;
  background: #16213e;
  z-index: 2;
}

.panel-list {
  padding: 0 10px 20px;
}

/* ---------- Panel Items (Models / Params / Runs) ---------- */

.panel-item {
  display: flex;
  align-items: center;
  padding: 12px 14px;
  margin: 2px 0;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  font-size: 14px;
  font-weight: 500;
  color: #c0c8d4;
  -webkit-tap-highlight-color: transparent;
}

.panel-item:hover {
  background: rgba(14,165,233,0.08);
}

.panel-item.selected {
  background: rgba(14,165,233,0.15);
  color: #0ea5e9;
  font-weight: 600;
}

.panel-item .item-label {
  flex: 1;
}

.panel-item .item-meta {
  font-size: 11px;
  color: #6b7a8e;
  font-weight: 400;
}

/* Expand arrow for multi-domain models */
.panel-item .expand-arrow {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  margin-left: 8px;
  color: #6b7a8e;
  font-size: 12px;
  transition: transform 0.25s, background 0.15s, color 0.15s;
  flex-shrink: 0;
}

.panel-item .expand-arrow:hover {
  background: rgba(255,255,255,0.06);
  color: #e0e0e0;
}

.panel-item .expand-arrow.rotated {
  transform: rotate(180deg);
}

/* Domain sub-items */
.domain-sub {
  overflow: hidden;
  max-height: 0;
  transition: max-height 0.3s ease-out;
}

.domain-sub.expanded {
  max-height: 500px;
}

.domain-sub .panel-item {
  padding-left: 38px;
  font-size: 13px;
  color: #a0aab4;
}

.domain-sub .panel-item.selected {
  color: #0ea5e9;
}

/* ---------- Empty State ---------- */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: #4a5568;
  gap: 12px;
}

.empty-state .icon {
  font-size: 48px;
  opacity: 0.4;
}

.empty-state .msg {
  font-size: 14px;
  font-weight: 500;
}

/* ---------- Scrollbar styling (Webkit) ---------- */

::-webkit-scrollbar {
  width: 6px;
}

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

::-webkit-scrollbar-thumb {
  background: #3a4a6a;
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: #4a5a7a;
}

/* ---------- Desktop tweaks (wider screens) ---------- */

@media (min-width: 600px) {
  .viewer-header {
    padding: 10px 20px;
  }

  .header-selection {
    font-size: 14px;
  }

  .header-times {
    font-size: 12px;
  }

  .playback-bar {
    padding: 10px 20px;
  }

  .slide-panel {
    max-width: 480px;
    left: 50%;
    transform: translateX(-50%) translateY(100%);
  }

  .slide-panel.open {
    transform: translateX(-50%) translateY(0);
  }

  .fh-trigger {
    min-width: 100px;
    font-size: 13px;
    padding: 7px 12px;
  }
}
