/* ============================================================
   EcoVision — index.html (the screen at the machine + teachers' dashboard)
   Mint theme, same palette as phone.css / game.css: emerald→teal hero, pale mint
   page, white cards. Bin colours match phone.html and room.html.
   Two modes: body.mode-kiosk (หน้าเครื่อง) / body.mode-dash (แดชบอร์ด).
   Dark: body.dark-theme (toggled from the dashboard).
   Previous look (iOS): kept in the backup taken before this redesign.
   ============================================================ */

/* ---------- Tokens: light ---------- */
:root {
  --plastic: #2F80ED;
  --glass:   #27AE60;
  --can:     #F2994A;
  --paper:   #A07850;
  --ewaste:  #D92D20;

  --brand: #059669;
  --brand-2: #047857;
  --brand-soft: #E3F6EE;
  --hero: linear-gradient(135deg, #059669 0%, #0D9488 55%, #0891B2 100%);
  --hero-busy: linear-gradient(135deg, #B45309 0%, #D97706 55%, #F59E0B 100%);
  --hero-paused: linear-gradient(135deg, #475569 0%, #64748B 100%);
  --pop: linear-gradient(135deg, #10B981, #059669);

  --bg:        #F2FAF6;
  --card:      #FFFFFF;
  --fill:      rgba(16,80,55,0.07);
  --fill-2:    rgba(16,80,55,0.12);
  --separator: rgba(16,80,55,0.10);
  --bar-bg:    rgba(242,250,246,0.82);

  --text:   #0F241B;
  --text-2: #4B5F56;
  --text-3: #8A9A92;

  --accent:      #059669;
  --accent-soft: rgba(16,185,129,0.12);
  --ok:      #16A34A;
  --warn:    #D97706;
  --danger:  #DC2626;
  --danger-soft: rgba(220,38,38,0.12);
  --gold-hi: #FFE37A;

  --font: 'IBM Plex Sans Thai', 'Noto Sans Thai', system-ui, -apple-system, sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, Consolas, monospace;

  --r-xl: 30px;
  --r-lg: 24px;
  --r-md: 18px;
  --r-sm: 12px;

  --shadow: 0 1px 2px rgba(4,60,40,0.05), 0 10px 28px rgba(4,60,40,0.08);
  --shadow-pop: 0 24px 60px rgba(4,40,28,0.22), 0 4px 14px rgba(4,40,28,0.08);
  --ease: cubic-bezier(0.32, 0.72, 0, 1);
  --page-bg:
    radial-gradient(900px 600px at 0% 0%, rgba(167,243,208,0.55) 0%, transparent 60%),
    radial-gradient(800px 600px at 100% 0%, rgba(204,251,241,0.65) 0%, transparent 60%),
    linear-gradient(160deg, #F4FCF7 0%, #FBFEFC 50%, #F1FAF6 100%);
}

/* ---------- Tokens: dark ---------- */
body.dark-theme {
  --brand: #34D399;
  --brand-2: #10B981;
  --brand-soft: rgba(52,211,153,0.14);

  --bg:        #0A1712;
  --card:      #12261E;
  --fill:      rgba(255,255,255,0.06);
  --fill-2:    rgba(255,255,255,0.10);
  --separator: rgba(255,255,255,0.08);
  --bar-bg:    rgba(10,23,18,0.82);

  --text:   #ECFDF5;
  --text-2: rgba(236,253,245,0.74);
  --text-3: rgba(236,253,245,0.48);

  --accent: #34D399;
  --accent-soft: rgba(52,211,153,0.16);
  --danger: #F87171;
  --danger-soft: rgba(239,68,68,0.16);

  --shadow: 0 10px 28px rgba(0,0,0,0.35);
  --shadow-pop: 0 24px 60px rgba(0,0,0,0.6);
  --page-bg:
    radial-gradient(900px 600px at 0% 0%, rgba(5,150,105,0.3) 0%, transparent 60%),
    radial-gradient(800px 600px at 100% 0%, rgba(13,148,136,0.22) 0%, transparent 60%),
    linear-gradient(160deg, #0B1A14 0%, #08140F 100%);
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; background: var(--bg); }
body {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--page-bg); background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
body.dark-theme { background-color: var(--bg); }
button { font-family: var(--font); color: inherit; cursor: pointer; border: 0; background: none; }
input { font-family: var(--font); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 8px; }
svg.i { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.num, .value, .clock strong { font-variant-numeric: tabular-nums; }

.app { max-width: 1680px; margin: 0 auto; padding: 0 clamp(16px, 2.2vw, 36px) 28px; }

/* ---------- Mode visibility ---------- */
body.mode-kiosk #dashView, body.mode-kiosk .dash-only { display: none !important; }
body.mode-dash #kioskView, body.mode-dash .kiosk-only { display: none !important; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  margin: 0 calc(-1 * clamp(16px, 2.2vw, 36px));
  padding: 12px clamp(16px, 2.2vw, 36px);
  display: flex; align-items: center; gap: 16px;
  -webkit-backdrop-filter: saturate(1.6) blur(18px); backdrop-filter: saturate(1.6) blur(18px);
}
/* background reaches the screen edges even when .app is capped at 1680px */
.topbar::before { content: ""; position: absolute; top: 0; bottom: 0; left: -100vw; right: -100vw; background: var(--bar-bg); z-index: -1; }
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.logo { width: 44px; height: 44px; border-radius: 14px; background: var(--pop); color: #fff; display: grid; place-items: center; flex: none; box-shadow: 0 6px 14px rgba(5,150,105,0.28); }
.logo svg.i { width: 24px; height: 24px; }
.brand h1 { font-size: 20px; font-weight: 700; line-height: 1.2; color: var(--brand-2); }
body.dark-theme .brand h1 { color: var(--brand); }
.brand p { font-size: 13px; color: var(--text-3); line-height: 1.3; }

.modes { display: flex; background: var(--fill); border-radius: 14px; padding: 4px; margin-left: 12px; }
.modes button { display: flex; align-items: center; gap: 8px; padding: 8px 16px; border-radius: 11px; font-weight: 600; font-size: 15px; color: var(--text-3); }
.modes button svg.i { width: 18px; height: 18px; }
.modes button.on { background: var(--card); color: var(--text); box-shadow: var(--shadow); }

.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.clock { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.1; padding-left: 6px; }
.clock strong { font-size: 26px; font-weight: 700; }
.clock span { font-size: 13px; color: var(--text-3); }

.status-pill {
  display: inline-flex; align-items: center; gap: 8px;
  height: 38px; padding: 0 14px; border-radius: 99px;
  background: var(--card); box-shadow: var(--shadow);
  font-size: 14px; font-weight: 600; color: var(--text-2); white-space: nowrap;
}
.status-pill svg.i { width: 18px; height: 18px; color: var(--brand); }
.status-pill b { color: var(--text); font-size: 16px; }
.status-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--text-3); }
.status-pill.on .status-dot { background: #22C55E; box-shadow: 0 0 0 4px rgba(34,197,94,0.2); }
.status-pill.off .status-dot { background: #F59E0B; box-shadow: 0 0 0 4px rgba(245,158,11,0.2); }

/* Shared buttons */
.theme-toggle, .export-btn, .pill-btn, .popup-confirm {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 38px; padding: 0 16px; border-radius: 12px;
  font-size: 14px; font-weight: 600; white-space: nowrap;
  background: var(--card); color: var(--brand-2); box-shadow: var(--shadow);
  transition: transform .2s var(--ease), filter .2s, opacity .2s;
}
body.dark-theme .theme-toggle, body.dark-theme .pill-btn { color: var(--brand); }
.theme-toggle:active, .export-btn:active, .pill-btn:active, .popup-confirm:active { transform: scale(0.96); }
.theme-toggle svg.i, .export-btn svg.i, .pill-btn svg.i { width: 17px; height: 17px; stroke-width: 2; }
.export-btn { background: var(--pop); color: #fff; box-shadow: 0 8px 18px rgba(5,150,105,0.28); }
.export-btn:hover { filter: brightness(1.06); }
.pill-btn:disabled { opacity: 0.5; cursor: default; }

.theme-icon { display: inline-flex; }
.theme-icon .sun { display: none; }
body.dark-theme .theme-icon .sun { display: block; }
body.dark-theme .theme-icon .moon { display: none; }

.export-wrap { position: relative; }
.export-menu {
  position: absolute; right: 0; top: calc(100% + 8px); min-width: 180px; z-index: 60;
  display: none; flex-direction: column; padding: 6px;
  background: var(--card); border-radius: 14px; box-shadow: var(--shadow-pop);
}
.export-menu.show { display: flex; animation: menuIn .22s var(--ease); }
.export-menu button { text-align: left; padding: 10px 12px; border-radius: 9px; font-size: 14px; font-weight: 500; }
.export-menu button:hover { background: var(--fill); }
@keyframes menuIn { from { opacity: 0; transform: translateY(-6px) scale(0.97); } }

/* ============================================================
   MODE 1 — หน้าเครื่อง (kiosk)
   Fills the screen on a landscape monitor; everything sized to be read from 2–3 m.
   ============================================================ */
.kiosk {
  display: grid; gap: clamp(14px, 1.4vw, 22px); padding-top: 10px;
  grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr) auto;
}
@media (min-width: 1000px) and (min-height: 620px) {
  .kiosk { height: calc(100vh - 78px - 28px); }   /* topbar + bottom padding */
}

/* Whose turn */
.turn {
  position: relative; overflow: hidden; color: #fff;
  background: var(--hero); border-radius: var(--r-xl);
  padding: clamp(22px, 2.4vw, 40px);
  display: flex; flex-direction: column; min-height: 0;
  box-shadow: 0 18px 40px rgba(5,150,105,0.3);
  transition: background .4s var(--ease), box-shadow .4s var(--ease);
}
.turn::after { content: ""; position: absolute; right: -90px; top: -90px; width: 300px; height: 300px; border-radius: 50%; background: rgba(255,255,255,0.1); pointer-events: none; }
.turn.busy { background: var(--hero-busy); box-shadow: 0 18px 40px rgba(217,119,6,0.3); }
.turn.paused { background: var(--hero-paused); box-shadow: 0 18px 40px rgba(71,85,105,0.3); }
.turn-badge { display: inline-flex; align-items: center; gap: 10px; width: fit-content; font-size: clamp(15px, 1.25vw, 20px); font-weight: 600; background: rgba(255,255,255,0.18); border-radius: 99px; padding: 6px 16px; position: relative; z-index: 1; }
.turn-badge i { width: 12px; height: 12px; border-radius: 50%; background: #86EFAC; box-shadow: 0 0 0 5px rgba(134,239,172,0.3); animation: blink 2s infinite; }
.turn.busy .turn-badge i { background: #FEF3C7; box-shadow: 0 0 0 5px rgba(254,243,199,0.3); }
.turn.paused .turn-badge i { background: #CBD5E1; box-shadow: none; animation: none; }

.turn-free h2 { font-size: clamp(34px, 4.3vw, 76px); line-height: 1.12; font-weight: 700; margin-top: clamp(12px, 1.4vw, 22px); }
.turn-sub { font-size: clamp(16px, 1.5vw, 24px); opacity: 0.92; margin-top: 8px; }
.turn-busy { display: none; align-items: center; gap: clamp(16px, 1.8vw, 28px); margin-top: clamp(12px, 1.4vw, 22px); }
.turn.busy .turn-free { display: none; }
.turn.busy .turn-busy { display: flex; }
.turn-ring { position: relative; width: clamp(110px, 10vw, 170px); aspect-ratio: 1; flex: none; }
.turn-ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.turn-ring circle { fill: none; stroke-width: 10; }
.turn-ring .t { stroke: rgba(255,255,255,0.25); }
.turn-ring .b { stroke: #fff; stroke-linecap: round; transition: stroke-dashoffset .25s linear; }
.turn-ring > div { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.turn-ring b { font-size: clamp(38px, 3.6vw, 58px); line-height: 1; font-variant-numeric: tabular-nums; }
.turn-ring small { font-size: 14px; opacity: 0.85; }
.turn-who h2 { font-size: clamp(34px, 3.8vw, 64px); line-height: 1.12; }
.turn-who p { font-size: clamp(15px, 1.35vw, 21px); opacity: 0.92; margin-top: 6px; }

.turn-steps { margin-top: auto; padding-top: 18px; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: clamp(10px, 1vw, 16px); position: relative; z-index: 1; }
.turn-steps div { background: rgba(255,255,255,0.14); border-radius: 20px; padding: clamp(12px, 1.2vw, 18px); transition: background .3s; }
.turn-steps b { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 50%; background: #fff; color: var(--brand-2); font-size: 18px; margin-bottom: 8px; }
.turn.busy .turn-steps b { color: #B45309; }
.turn-steps b svg.i { width: 20px; height: 20px; stroke-width: 3; }
.turn-steps span { font-size: clamp(14px, 1.2vw, 19px); line-height: 1.4; display: block; }
.turn-steps .nb { display: inline; white-space: nowrap; }   /* keep “เสร็จแล้ว”, มือถือ… in one piece */
.turn-steps .active { background: rgba(255,255,255,0.3); animation: pulseBox 1.4s infinite; }
.turn-steps .done { background: rgba(255,255,255,0.24); }
.turn-steps .bad { background: rgba(127,29,29,0.45); }
.turn-steps .bad b { background: #FEE2E2; color: #B91C1C; }

/* Camera + result */
.kiosk-side { display: grid; grid-template-rows: minmax(0, 1fr) auto; gap: clamp(14px, 1.4vw, 22px); min-width: 0; min-height: 0; }
.live-camera { min-height: 0; display: flex; }
.live-stage {
  position: relative; flex: 1; border-radius: var(--r-lg); overflow: hidden;
  min-height: 220px;
  background: radial-gradient(120% 90% at 50% 40%, #1E3A2F 0%, #0B1712 75%);
}
.live-stage video { display: none; width: 100%; height: 100%; object-fit: cover; }
.live-camera.streaming .live-stage video { display: block; }
.camera-placeholder {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  color: rgba(236,253,245,0.6); text-align: center; padding: 20px;
}
.camera-placeholder .camera-symbol { width: 44px; height: 44px; stroke-width: 1.4; margin-bottom: 6px; color: rgba(236,253,245,0.45); }
.camera-placeholder strong { color: #fff; font-size: 17px; font-weight: 600; }
.camera-placeholder span { font-size: 14px; }
.live-camera.streaming .camera-placeholder { display: none; }

.live-badge {
  position: absolute; top: 14px; left: 14px; display: none; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 8px; font-size: 13px; font-weight: 700; color: #fff; letter-spacing: 0.5px;
  background: rgba(220,38,38,0.92);
}
.live-badge span { width: 7px; height: 7px; border-radius: 50%; background: #fff; animation: blink 1.6s infinite; }
.live-camera.streaming .live-badge { display: flex; }

.scan-frame { position: absolute; left: 22%; top: 18%; right: 22%; bottom: 26%; pointer-events: none; }
.scan-frame i { position: absolute; width: 26px; height: 26px; border: 3px solid rgba(255,255,255,0.5); }
.scan-frame i:nth-child(1) { top: 0; left: 0; border-right: 0; border-bottom: 0; border-top-left-radius: 12px; }
.scan-frame i:nth-child(2) { top: 0; right: 0; border-left: 0; border-bottom: 0; border-top-right-radius: 12px; }
.scan-frame i:nth-child(3) { bottom: 0; left: 0; border-right: 0; border-top: 0; border-bottom-left-radius: 12px; }
.scan-frame i:nth-child(4) { bottom: 0; right: 0; border-left: 0; border-top: 0; border-bottom-right-radius: 12px; }
.scan-frame span { display: none; }
.live-camera.streaming .scan-frame i { border-color: rgba(255,255,255,0.9); }

.cam-actions { position: absolute; top: 12px; right: 12px; display: flex; gap: 8px; }
.cam-btn { display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 12px; border-radius: 10px; font-size: 13px; font-weight: 600; color: #fff; background: rgba(0,0,0,0.42); -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); }
.cam-btn svg.i { width: 15px; height: 15px; }
.cam-btn:disabled { opacity: 0.5; }
.cam-caption { position: absolute; left: 0; right: 0; bottom: 0; padding: 30px 18px 14px; background: linear-gradient(transparent, rgba(0,0,0,0.65)); color: #fff; font-size: clamp(15px, 1.25vw, 19px); font-weight: 600; display: flex; align-items: center; gap: 10px; }
.cam-caption i { width: 11px; height: 11px; border-radius: 50%; background: #86EFAC; flex: none; }
.cam-caption i.busy { background: #FCD34D; animation: blink 1s infinite; }
.cam-caption i.bad { background: #F87171; }
.camera-status { display: none; }
.live-camera.camera-error .camera-status { display: block; position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); padding: 6px 12px; border-radius: 10px; font-size: 13px; color: #fff; background: rgba(220,38,38,0.9); }

.result {
  background: var(--card); border-radius: var(--r-lg); box-shadow: var(--shadow);
  padding: clamp(14px, 1.4vw, 22px) clamp(16px, 1.6vw, 24px);
  display: flex; align-items: center; gap: clamp(14px, 1.4vw, 20px);
  border: 3px solid transparent; transition: border-color .3s;
}
.result:not(.idle):not(.unsure) { border-color: var(--c); }
.hero-ring {
  width: clamp(72px, 6.5vw, 100px); aspect-ratio: 1; border-radius: 50%; flex: none;
  display: grid; place-items: center;
  background: color-mix(in srgb, var(--c, #8A9A92) 16%, transparent); color: var(--c, var(--text-3));
}
.result.idle .hero-ring, .result.unsure .hero-ring { background: var(--fill); color: var(--text-3); }
.result.unsure .hero-ring { color: var(--warn); }
.hero-ring svg.i { width: 46%; height: 46%; stroke-width: 1.8; }
.hero-ring.active { animation: pop .45s var(--ease); }
.result-body { min-width: 0; flex: 1; }
.result-kicker { font-size: 14px; color: var(--text-3); }
.hero-type { font-size: clamp(26px, 2.5vw, 40px); font-weight: 700; line-height: 1.15; color: var(--c, var(--text)); }
.hero-type.none { color: var(--text-2); font-size: clamp(20px, 1.8vw, 28px); font-weight: 600; }
.result.unsure .hero-type { color: var(--warn); }
.result-bin { display: inline-flex; align-items: center; gap: 8px; margin-top: 6px; font-size: clamp(17px, 1.6vw, 24px); font-weight: 700; background: var(--c); color: #fff; padding: 5px 16px; border-radius: 14px; }
.result-bin:empty { display: none; }
.result-bin svg.i { width: 22px; height: 22px; stroke-width: 2.4; }
.result.alert .result-bin { background: var(--danger-soft); color: var(--danger); font-size: 15px; }
.result-conf { margin-left: auto; text-align: right; flex: none; }
.result-conf b { display: block; font-size: clamp(24px, 2.2vw, 34px); line-height: 1.1; }
.result-conf span { font-size: 13px; color: var(--text-3); }

/* Bins (physical order 1-2-3-4) */
.bins { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: clamp(12px, 1.2vw, 18px); }
.bin {
  position: relative; display: flex; align-items: center; gap: 14px;
  background: var(--card); border-radius: var(--r-lg); box-shadow: var(--shadow);
  padding: clamp(14px, 1.3vw, 20px) clamp(14px, 1.4vw, 22px);
  border: 3px solid transparent; transition: transform .35s var(--ease), border-color .3s, box-shadow .35s;
}
.bin.hit { border-color: var(--c); transform: translateY(-4px); box-shadow: 0 16px 34px color-mix(in srgb, var(--c) 30%, transparent); }
.bin-no { position: absolute; top: 12px; right: 14px; font-size: 13px; font-weight: 700; color: #fff; background: var(--c); border-radius: 8px; padding: 2px 9px; }
.bin-ic { width: clamp(48px, 4vw, 60px); height: clamp(48px, 4vw, 60px); border-radius: 16px; display: grid; place-items: center; flex: none; background: color-mix(in srgb, var(--c) 14%, transparent); color: var(--c); }
.bin-ic svg.i { width: 56%; height: 56%; stroke-width: 1.9; }
.bin-t { min-width: 0; flex: 1; }
.bin-t > b { display: block; font-size: clamp(15px, 1.2vw, 18px); line-height: 1.3; padding-right: 50px; }
.value-wrap { position: relative; display: flex; align-items: baseline; gap: 6px; }
.value { font-size: clamp(30px, 2.6vw, 44px); font-weight: 700; line-height: 1.05; color: var(--c); }
.value.bump { animation: pop .45s var(--ease); }
.unit { font-size: 15px; font-weight: 500; color: var(--text-3); }
.float-badge { position: absolute; left: 0; top: -10px; font-size: 18px; font-weight: 700; animation: floatUp .9s var(--ease) forwards; pointer-events: none; }
.progress-bar { height: 6px; border-radius: 6px; background: var(--fill); overflow: hidden; margin-top: 6px; }
.progress-fill { height: 100%; width: 0; border-radius: 6px; background: var(--c); transition: width .7s var(--ease); }
.value-sub { font-size: 12.5px; color: var(--text-3); margin-top: 4px; }

/* ============================================================
   MODE 2 — แดชบอร์ด
   ============================================================ */
.dash { display: flex; flex-direction: column; gap: 16px; padding-top: 10px; }

.toolbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.filter-group { display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.filter-group.segmented { gap: 0; padding: 4px; border-radius: 12px; background: var(--fill); }
.segmented .filter-btn { height: 32px; padding: 0 16px; border-radius: 9px; font-size: 14px; font-weight: 600; color: var(--text-3); transition: background-color .25s var(--ease); }
.segmented .filter-btn.active { background: var(--card); color: var(--text); box-shadow: var(--shadow); }

.date-range { display: inline-flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.date-range span { color: var(--text-3); }
.date-range input { height: 38px; padding: 0 10px; border-radius: 12px; border: 0; background: var(--card); box-shadow: var(--shadow); color: var(--text); font-size: 14px; color-scheme: light; }
body.dark-theme .date-range input { color-scheme: dark; }

.chips .filter-btn, .filter-checkbox {
  height: 36px; padding: 0 14px; border-radius: 99px;
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 14px; font-weight: 600; cursor: pointer; user-select: none;
  background: var(--card); color: var(--text); box-shadow: var(--shadow);
  transition: opacity .2s;
}
.chips .filter-btn.active { background: var(--brand); color: #fff; }
.filter-checkbox input { display: none; }
.filter-checkbox .dot { width: 10px; height: 10px; border-radius: 50%; }
.filter-checkbox:not(.checked) { opacity: 0.45; }
.filter-checkbox:not(.checked) .dot { background: transparent !important; box-shadow: inset 0 0 0 1.5px var(--text-3); }

.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.kpi { background: var(--card); border-radius: var(--r-lg); padding: 18px 20px; box-shadow: var(--shadow); min-width: 0; }
.kpi.hero { background: var(--hero); color: #fff; box-shadow: 0 16px 34px rgba(5,150,105,0.28); }
.kpi > span { font-size: 14px; color: var(--text-3); display: block; }
.kpi.hero > span { color: rgba(255,255,255,0.85); }
.kpi b { display: block; font-size: clamp(28px, 2.6vw, 40px); line-height: 1.15; margin-top: 4px; font-variant-numeric: tabular-nums; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kpi b small { font-size: 15px; font-weight: 500; margin-left: 4px; opacity: 0.7; }
.kpi em { display: block; font-style: normal; font-size: 13px; font-weight: 600; color: var(--text-3); margin-top: 2px; }
.kpi.hero em { color: #D1FAE5; }

.charts { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 16px; }
.chart-card { background: var(--card); border-radius: var(--r-lg); box-shadow: var(--shadow); padding: 18px 20px 12px; display: flex; flex-direction: column; min-width: 0; }
.chart-card.ai-card { grid-column: 1 / -1; }
.ai-card .ai-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }
.chart-title { display: flex; align-items: center; gap: 10px; font-size: 17px; font-weight: 600; margin-bottom: 6px; flex-wrap: wrap; }
.chart-title svg.i { width: 20px; height: 20px; color: var(--brand); }
.chart-note { font-size: 12.5px; font-weight: 400; color: var(--text-3); margin-left: auto; }
.chart-container { width: 100%; min-height: 260px; flex: 1; }

.ai-list { display: flex; flex-direction: column; gap: 8px; margin-top: 6px; }
.ai-item { display: flex; align-items: flex-start; gap: 12px; padding: 10px 12px; border-radius: 14px; background: var(--fill); font-size: 14px; color: var(--text); line-height: 1.45; }
.ai-item.alert { background: rgba(245,183,0,0.14); }
.ai-icon { width: 28px; height: 28px; border-radius: 9px; flex: none; display: grid; place-items: center; font-size: 14px; font-weight: 700; background: var(--brand); color: #fff; }
.ai-item.alert .ai-icon { background: #F59E0B; }
.ai-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.ai-basis { font-size: 12px; color: var(--text-3); }

.site-foot { margin-top: 12px; text-align: center; font-size: 12px; color: var(--text-3); }

/* ---------- Detection alert ---------- */
.popup-overlay {
  position: fixed; inset: 0; z-index: 100; display: none;
  align-items: center; justify-content: center; padding: 20px;
  background: rgba(6,20,14,0.4);
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
}
.popup-overlay.show { display: flex; animation: fadeIn .2s var(--ease) both; }
.popup-overlay.closing { animation: fadeOut .22s ease-in both; }
.popup {
  width: 400px; max-width: 100%; position: relative; overflow: hidden;
  padding: 34px 26px 24px; border-radius: 30px; text-align: center;
  background: var(--card); color: var(--text);
  box-shadow: var(--shadow-pop);
  display: flex; flex-direction: column; align-items: center; gap: 6px;
}
.popup::before { content: ""; position: absolute; inset: 0 0 auto; height: 8px; background: var(--c, var(--accent)); }
.popup-overlay.show .popup { animation: alertIn .42s var(--ease) both; }
.popup-overlay.closing .popup { animation: alertOut .22s ease-in both; }

.fx-box { position: relative; margin-bottom: 8px; }
.fx-sparks, .fx-stamp { display: none; }
.popup-icon {
  width: 104px; height: 104px; border-radius: 50%; display: grid; place-items: center;
  background: color-mix(in srgb, var(--c, var(--accent)) 16%, transparent); color: var(--c, var(--accent));
}
.popup-icon svg.i { width: 54px; height: 54px; stroke-width: 1.7; }
.popup-kicker { font-size: 15px; font-weight: 500; color: var(--text-3); }
.popup-type { font-size: 34px; font-weight: 700; line-height: 1.2; color: var(--c, var(--text)); }
.popup-count { display: flex; gap: 14px; justify-content: center; align-items: center; font-size: 16px; color: var(--text-2); margin-top: 4px; }
.popup-count b { color: var(--text); font-weight: 700; }
#popupBin { display: inline-block; background: var(--c); color: #fff; padding: 2px 12px; border-radius: 10px; font-size: 20px; }
.count-part { display: inline-flex; align-items: center; gap: 6px; }
.odo { display: inline-block; height: 1.25em; overflow: hidden; vertical-align: bottom; font-size: 19px; font-variant-numeric: tabular-nums; }
.odo > span { display: flex; flex-direction: column; }
.odo b { display: block; line-height: 1.25em; }
.popup-overlay.show .odo > span { animation: odo .45s var(--ease) .35s both; }
.popup-bar { width: 100%; height: 8px; margin-top: 14px; border-radius: 8px; background: var(--fill); overflow: hidden; }
.popup-bar-fill { width: var(--conf, 0%); height: 100%; border-radius: 8px; background: var(--c, var(--accent)); }
.popup-overlay.show .popup-bar-fill { animation: grow .7s var(--ease) .15s both; }
.popup-confidence { font-size: 13.5px; color: var(--text-3); }
.popup-warning { display: none; font-size: 15px; line-height: 1.5; color: var(--text-2); margin-top: 8px; }
.popup-warning.show { display: block; }
.popup-overlay.alert .popup-count, .popup-overlay.alert .popup-bar { display: none; }
.popup-overlay.alert .popup-kicker { color: var(--danger); font-weight: 600; }
.popup-confirm { display: none; width: 100%; height: 50px; margin-top: 14px; border-radius: 14px; font-size: 16px; background: var(--danger); color: #fff; box-shadow: none; }
.popup-confirm.show { display: flex; }

.confetti-wrap { display: none; }

/* ---------- Motion ---------- */
@keyframes blink { 50% { opacity: 0.35; } }
@keyframes pop { 0% { transform: scale(1); } 40% { transform: scale(1.08); } 100% { transform: scale(1); } }
@keyframes pulseBox { 50% { background: rgba(255,255,255,0.38); } }
@keyframes floatUp { from { opacity: 1; transform: translate(0, 0); } to { opacity: 0; transform: translate(0, -24px); } }
@keyframes fadeIn { from { opacity: 0; } }
@keyframes fadeOut { to { opacity: 0; } }
@keyframes alertIn { from { opacity: 0; transform: scale(1.12); } }
@keyframes alertOut { to { opacity: 0; transform: scale(0.94); } }
@keyframes odo { to { transform: translateY(-50%); } }
@keyframes grow { from { width: 0; } }

/* ---------- ApexCharts integration ---------- */
.apexcharts-canvas, .apexcharts-svg { background: transparent !important; }
.apexcharts-text, .apexcharts-legend-text, .apexcharts-datalabel-label, .apexcharts-datalabel-value { font-family: var(--font) !important; }
.apexcharts-tooltip { border-radius: 12px !important; border: 0 !important; box-shadow: var(--shadow-pop) !important; }
.apexcharts-tooltip.apexcharts-theme-light { background: rgba(255,255,255,0.96) !important; }
.apexcharts-tooltip.apexcharts-theme-dark { background: rgba(18,38,30,0.96) !important; }
.apexcharts-tooltip-title { border-bottom: 1px solid var(--separator) !important; background: transparent !important; font-weight: 600; }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 1180px) {
  .brand p { display: none; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
/* Below a landscape monitor: stack the kiosk, it scrolls */
@media (max-width: 999px) {
  .kiosk { grid-template-columns: 1fr; grid-template-rows: none; height: auto; }
  .turn { min-height: 340px; }
  .kiosk-side { grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); grid-template-rows: none; }
  .live-stage { aspect-ratio: 4 / 3; }
  .bins { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .charts { grid-template-columns: 1fr; }
}
@media (max-width: 999px) {
  .topbar { flex-wrap: wrap; gap: 10px; }
  .modes { order: 3; width: 100%; margin-left: 0; }
  .modes button { flex: 1; justify-content: center; }
}
@media (max-width: 760px) {
  .clock { display: none; }
  .status-pill #connText, .status-pill #arduinoText { display: none; }
  .status-pill { padding: 0 12px; }
  #themeLabel { display: none; }
  .kiosk-side { grid-template-columns: 1fr; }
  .live-stage { aspect-ratio: 16 / 10; }
  .turn-steps { grid-template-columns: 1fr; }
  .turn-steps div { display: flex; align-items: center; gap: 12px; }
  .turn-steps b { margin-bottom: 0; flex: none; }
  .turn-busy { flex-direction: column; align-items: flex-start; }
  .result { flex-wrap: wrap; }
  .date-range { width: 100%; }
}
@media (max-width: 520px) {
  .app { padding: 0 12px 24px; }
  .topbar { margin: 0 -12px; padding: 10px 12px; }
  .total-pill { display: none !important; }
  .kpis { grid-template-columns: 1fr 1fr; gap: 10px; }
  .kpi { padding: 14px; }
  .bins { gap: 10px; }
  .bin { flex-direction: column; align-items: flex-start; gap: 8px; }
  .bin-ic { width: 44px; height: 44px; border-radius: 13px; }
  .bin-t > b { padding-right: 0; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
