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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #0d0d0d;
  color: #f5f5f5;
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 16px;
}

/* ===== Kiosk grid =====
   Left half  (50%): clock (full height)
   Right half (50%): today-curve | warning | tomorrow
   Rows:              ~63%       |  ~5.5%  |  ~31.5%
   Proportions preserved from original 680:60:340 = 34:3:17
*/
.kiosk-layout {
  position: relative;
  display: grid;
  width: 100vw;
  height: 100vh;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 34fr 3fr 17fr;
  grid-template-areas:
    "clock  main"
    "clock  warning"
    "clock  tomorrow";
  background: #0d0d0d;
}

.kiosk-pill {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 100;
}

.kiosk-clock {
  grid-area: clock;
  display: flex;
  align-items: center;
  justify-content: center;
  border-right: 1px solid #1e1e1e;
}

.kiosk-main {
  grid-area: main;
  display: flex;
  align-items: stretch;
  padding: 20px 24px 0 20px;
  overflow: hidden;
}

.kiosk-warning {
  grid-area: warning;
  display: flex;
  align-items: center;
  padding: 0 24px 0 20px;
  border-top: 1px solid #1e1e1e;
}

.kiosk-tomorrow {
  grid-area: tomorrow;
  display: flex;
  flex-direction: column;
  padding: 8px 20px 10px 16px;
  background: #111;
  border-top: 1px solid #1e1e1e;
  border-left: 1px solid #1e1e1e;
  overflow: hidden;
}

/* ===== Analog Clock ===== */
.analog-clock {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.clock-svg {
  width: min(90%, 90vh);
  height: min(90%, 90vh);
  display: block;
}

/* ===== Today Curve ===== */
.today-curve {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.curve-header {
  height: 36px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 4px 4px;
  border-bottom: 1px solid #222;
  margin-bottom: 6px;
}

.curve-date {
  font-size: 1rem;
  font-weight: 600;
  color: #bdbdbd;
  letter-spacing: 0.04em;
}

/* The chart area: SVG + overlay labels side by side */
.curve-main {
  flex: 1;
  position: relative;
  min-height: 0;
}

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

/* Price labels overlaid on the chart */
.curve-price-labels {
  position: absolute;
  top: 0;
  right: 0;
  height: 100%;
  pointer-events: none;
}

.price-label {
  position: absolute;
  right: 4px;
  transform: translateY(-50%);
  font-size: 0.65rem;
  font-weight: 600;
  padding: 1px 4px;
  border-radius: 3px;
  white-space: nowrap;
}

.price-label-low {
  color: #2196f3;
  background: rgba(13, 13, 13, 0.75);
}

.price-label-high {
  color: #f44336;
  background: rgba(13, 13, 13, 0.75);
}

/* Bar visual state — driven by CSS so raw-JS class toggle works without WASM */
.bar .bar-rect    { opacity: 0.72; }
.bar-now .bar-rect { opacity: 1.0; }
.bar .bar-overlay    { opacity: 0; }
.bar-now .bar-overlay { opacity: 0.14; }

/* SVG gridlines */
.gridline {
  stroke-width: 0.4;
  stroke-dasharray: 2 2;
  vector-effect: non-scaling-stroke;
}

.gridline-low  { stroke: #2196f3; opacity: 0.55; }
.gridline-high { stroke: #f44336; opacity: 0.55; }
.gridline-base { stroke: #444;    opacity: 0.4;  stroke-dasharray: none; }

/* Hour labels row */
.curve-hours {
  height: 26px;
  flex-shrink: 0;
  display: grid;
  grid-template-columns: repeat(24, 1fr);
  padding: 4px 0 0;
}

.hour-cell {
  display: flex;
  justify-content: center;
  align-items: flex-start;
}

.hour-label {
  font-size: 0.6rem;
  color: #555;
  line-height: 1;
}

/* ===== Tomorrow Panel ===== */
.tomorrow-panel {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: stretch;
}

.tomorrow-panel--awaiting {
  align-items: center;
  justify-content: center;
}

.tomorrow-svg {
  width: 100%;
  height: 100%;
  flex: 1;
  display: block;
}

/* ===== Warning Banner ===== */
.warning-banner {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 1.5rem;
  font-weight: 700;
  padding: 8px 16px;
  border-radius: 6px;
}

.warning-high {
  background: rgba(244, 67, 54, 0.12);
  color: #f44336;
  border: 1px solid rgba(244, 67, 54, 0.35);
}

.warning-low {
  background: rgba(33, 150, 243, 0.12);
  color: #2196f3;
  border: 1px solid rgba(33, 150, 243, 0.35);
}

.warning-none { display: none; }

.warning-glyph {
  font-size: 2rem;
  line-height: 1;
}

/* ===== Connectivity Pill ===== */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.03em;
}

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

.pill-label { white-space: nowrap; }

.pill-green {
  background: rgba(76, 175, 80, 0.18);
  border: 1px solid rgba(76, 175, 80, 0.45);
  color: #81c784;
}
.pill-green .pill-dot { background: #4caf50; box-shadow: 0 0 6px #4caf50; }

.pill-amber {
  background: rgba(255, 152, 0, 0.18);
  border: 1px solid rgba(255, 152, 0, 0.45);
  color: #ffb74d;
}
.pill-amber .pill-dot { background: #ff9800; box-shadow: 0 0 6px #ff9800; }

.pill-red {
  background: rgba(244, 67, 54, 0.18);
  border: 1px solid rgba(244, 67, 54, 0.45);
  color: #e57373;
}
.pill-red .pill-dot { background: #f44336; box-shadow: 0 0 6px #f44336; }

/* ===== Empty States ===== */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  width: 100%;
  height: 100%;
  color: #616161;
}

.empty-icon  { font-size: 3.5rem; line-height: 1; }
.empty-label { font-size: 1.2rem; color: #757575; }

/* ===== Config page ===== */
.config-page {
  max-width: 480px;
  margin: 60px auto;
  padding: 32px;
  background: #1a1a1a;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.config-page h1 { font-size: 1.5rem; color: #f5f5f5; }

.form-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-field label { font-size: 0.875rem; color: #9e9e9e; }

.form-field input {
  padding: 10px 12px;
  background: #0d0d0d;
  border: 1px solid #333;
  border-radius: 6px;
  color: #f5f5f5;
  font-size: 1rem;
  outline: none;
}

.form-field input:focus { border-color: #616161; }

.save-button {
  padding: 12px;
  background: #2196f3;
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}

.save-button:disabled {
  background: #333;
  color: #666;
  cursor: not-allowed;
}

.validation-error { color: #f44336; font-size: 0.875rem; }
.save-feedback    { color: #4caf50; font-size: 0.875rem; }
.config-meta      { font-size: 0.75rem; color: #616161; display: flex; flex-direction: column; gap: 4px; }

/* ===== Hamburger menu (portrait/mobile only) ===== */
.kiosk-hamburger-wrap {
  position: absolute;
  top: 14px;
  left: 14px;
  z-index: 100;
  display: none;
}

.kiosk-hamburger {
  width: 40px;
  height: 40px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 5px;
  background: rgba(20, 20, 20, 0.85);
  border: 1px solid #2a2a2a;
  border-radius: 6px;
  cursor: pointer;
  padding: 0;
}

.kiosk-hamburger span {
  display: block;
  width: 20px;
  height: 2px;
  background: #f5f5f5;
  border-radius: 1px;
}

.kiosk-menu {
  position: absolute;
  top: 48px;
  left: 0;
  min-width: 140px;
  background: #141414;
  border: 1px solid #2a2a2a;
  border-radius: 6px;
  display: none;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
}

.kiosk-menu-open { display: flex; }

.kiosk-menu-item {
  background: transparent;
  border: none;
  color: #f5f5f5;
  text-align: left;
  padding: 12px 16px;
  font-size: 0.95rem;
  cursor: pointer;
}

.kiosk-menu-item:hover { background: #1e1e1e; }
.kiosk-menu-item.active { background: #2196f3; color: #fff; }

/* ===== Portrait (mobile) layout =====
   When viewport is taller than wide, collapse to a single-area grid
   and let the hamburger menu pick which panel is shown.

   Notes:
   - 100dvh tracks the actually-visible viewport on mobile (excludes the
     address bar when retracted), unlike 100vh which is fixed and bleeds
     under the bar on Android Chrome.
   - overflow:auto on html/body so the warning banner is reachable and
     the stacked curves view can scroll.
*/
@media (orientation: portrait) {
  html, body {
    height: auto;
    min-height: 100dvh;
    overflow-y: auto;
    overflow-x: hidden;
  }

  .kiosk-hamburger-wrap { display: block; }

  .kiosk-layout {
    width: 100vw;
    height: auto;
    grid-template-columns: 1fr;
  }

  /* Clock view: fit one screen exactly (no scroll). */
  .kiosk-layout.view-clock {
    min-height: 100dvh;
    height: 100dvh;
    grid-template-rows: 1fr auto;
    grid-template-areas:
      "main"
      "warning";
  }
  .kiosk-layout.view-clock .kiosk-clock {
    grid-area: main;
    border-right: none;
  }
  .kiosk-layout.view-clock .kiosk-main,
  .kiosk-layout.view-clock .kiosk-tomorrow { display: none; }

  /* Curves view: tall, scrollable, generous fixed heights so 96 bars
     and the tomorrow panel render legibly. */
  .kiosk-layout.view-curves {
    min-height: 100dvh;
    grid-template-rows: 60dvh auto 50dvh;
    grid-template-areas:
      "main"
      "warning"
      "tomorrow";
  }
  .kiosk-layout.view-curves .kiosk-clock { display: none; }
  .kiosk-layout.view-curves .kiosk-tomorrow { border-left: none; }
  .kiosk-layout.view-curves .kiosk-main {
    padding: 16px 16px 8px;
  }
  .kiosk-layout.view-curves .kiosk-warning {
    padding: 8px 16px;
  }
  .kiosk-layout.view-curves .kiosk-tomorrow {
    padding: 12px 16px 16px;
  }
}
