/* Self-hosted Lao font so the dashboard renders correctly with no internet on the LAN.
   One Medium file serves the whole UI; the browser synthesizes the bold (600/700) headings. */
@font-face {
  font-family: 'Noto Sans Lao';
  src: url('NotoSansLao-Medium.ttf') format('truetype');
  font-style: normal;
  font-display: swap;
}

:root {
  --forest-900: #0b3d2e;
  --forest-700: #14543c;
  --forest-500: #1f7a52;
  --leaf-400: #34c759;
  --leaf-300: #6fd98a;
  --bg: #eef4ec;
  --card: #ffffff;
  --ink: #15291f;
  --muted: #5e7064;
  --danger: #e0524b;
  --shadow: 0 10px 30px rgba(11, 61, 46, 0.10);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; } /* ensure the hidden attribute wins over display rules below */

html { height: 100%; }
body {
  font-family: 'Noto Sans Lao', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color: var(--ink);
  background:
    radial-gradient(1200px 500px at 50% -10%, rgba(31, 122, 82, 0.18), transparent 60%),
    var(--bg);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;            /* dashboard fits on one screen — no page scroll */
}

/* Top bar */
.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: .75rem 1.5rem;
  background: linear-gradient(135deg, var(--forest-900), var(--forest-500));
  color: #fff;
  box-shadow: var(--shadow);
}
.brand { display: flex; align-items: center; gap: 1rem; }
.brand .logo { height: 50px; width: auto; display: block; filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.3)); }
.brand-text { padding-left: 1rem; border-left: 1px solid rgba(255, 255, 255, 0.25); }
.brand h1 { font-size: 1.4rem; font-weight: 700; letter-spacing: .5px; }
.subtitle { font-size: .85rem; opacity: .85; font-weight: 300; }

.topbar-right { display: flex; align-items: center; gap: 1.25rem; flex-wrap: wrap; }
.status { display: flex; align-items: center; gap: .5rem; font-size: .85rem; font-weight: 500; }
.status .dot { width: 10px; height: 10px; border-radius: 50%; background: #ffd34d; box-shadow: 0 0 0 4px rgba(255,255,255,.15); }
.status.ok .dot { background: var(--leaf-400); }
.status.bad .dot { background: var(--danger); }

/* Layout — fill the viewport height so everything fits without scrolling */
.wrap {
  flex: 1 1 auto;
  min-height: 0;               /* allow the cards row to shrink to fit */
  width: 100%;
  max-width: 1500px;
  margin: 0 auto;
  padding: 1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* Hero */
.hero {
  position: relative;
  flex: 0 0 auto;
  background: linear-gradient(160deg, var(--forest-700), var(--forest-900));
  color: #fff;
  border-radius: 20px;
  padding: clamp(.8rem, 2.4vh, 1.6rem) 1.5rem;
  text-align: center;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.hero::after {
  content: "";
  position: absolute; inset: auto -40px -60px auto;
  width: 240px; height: 240px;
  background: radial-gradient(circle, rgba(111,217,138,.35), transparent 70%);
}
.hero-label { font-size: 1rem; font-weight: 300; opacity: .9; letter-spacing: .5px; }
.hero-number {
  font-size: clamp(2.5rem, 9vh, 5.5rem);
  font-weight: 700;
  line-height: 1.02;
  margin: .1rem 0 .4rem;
  text-shadow: 0 4px 20px rgba(0,0,0,.25);
  font-variant-numeric: tabular-nums;
}
.hero-breakdown {
  display: inline-flex; align-items: center; gap: 1.25rem;
  font-size: 1.05rem; font-weight: 300;
  background: rgba(255,255,255,.10);
  padding: .5rem 1.25rem; border-radius: 999px;
}
.hero-breakdown b { font-weight: 600; color: var(--leaf-300); }
.hero-breakdown .divider { width: 1px; height: 18px; background: rgba(255,255,255,.3); }
.mock-badge {
  display: inline-block; margin-top: .6rem;
  font-size: .75rem; font-weight: 500;
  background: #ffd34d; color: #5b4a00;
  padding: .25rem .75rem; border-radius: 999px;
}

/* Start-time filter — sits in the top bar, next to the connection status */
.timefilter {
  display: flex; align-items: center;
  gap: .55rem;
}
.tf-label { font-size: .9rem; font-weight: 500; color: rgba(255, 255, 255, .85); }
.tf-input {
  font: inherit; font-size: .92rem; font-weight: 600;
  color: var(--forest-700); background: #fff;
  border: 1px solid rgba(20, 84, 60, .25); border-radius: 999px;
  padding: .38rem .8rem; cursor: pointer;
}
.tf-input:focus { outline: none; border-color: var(--leaf-400); box-shadow: 0 0 0 3px rgba(52, 199, 89, .18); }
.tf-clear {
  font: inherit; font-size: .82rem; font-weight: 600;
  color: var(--forest-700); background: #e8f3ec;
  border: 1px solid rgba(20, 84, 60, .18); border-radius: 999px;
  padding: .34rem .8rem; cursor: pointer; transition: background .15s;
}
.tf-clear:hover { background: #d9ecdf; }
.tf-clear:active { transform: scale(.97); }
.tf-note { font-size: .82rem; font-weight: 500; color: var(--danger); }

/* Camera cards — one row, fills the remaining height */
.cards {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-auto-flow: column;              /* keep all cameras on a single row */
  grid-auto-columns: 1fr;
  gap: 1.1rem;
}
.card {
  display: flex;
  flex-direction: column;              /* image on top, stats below */
  gap: .85rem;
  min-height: 0;
  background: var(--card);
  border-radius: 18px;
  padding: 1rem;
  box-shadow: var(--shadow);
  border-top: 4px solid var(--leaf-400);
  transition: transform .15s ease;
}
.card:hover { transform: translateY(-3px); }
.card.offline { border-top-color: var(--danger); opacity: .9; }

/* Live image (top) */
.cam-snap-wrap {
  position: relative;
  flex: 1 1 auto;                      /* absorbs the leftover card height */
  min-height: 120px;
  width: 100%;
  border-radius: 12px;
  overflow: hidden;
  background: var(--forest-900);
}
.cam-snap { width: 100%; height: 100%; object-fit: cover; display: block; }
.cam-snap-ph {
  position: absolute; inset: 0;
  display: none; align-items: center; justify-content: center;
  color: #cfe6d8; font-size: .9rem; font-weight: 500; letter-spacing: .5px;
  background:
    repeating-linear-gradient(45deg, rgba(255,255,255,.04) 0 10px, transparent 10px 20px),
    var(--forest-900);
}
.cam-snap-wrap.no-signal .cam-snap { display: none; }
.cam-snap-wrap.no-signal .cam-snap-ph { display: flex; }

/* Stats (below the image) */
.card-body { flex: 0 0 auto; display: flex; flex-direction: column; min-width: 0; }
.card-head { display: flex; align-items: center; gap: .55rem; margin-bottom: .25rem; }
.cam-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--leaf-400); }
.card.offline .cam-dot { background: var(--danger); }
.cam-name { font-size: 1.05rem; font-weight: 600; color: var(--forest-700); }
.cam-number {
  font-size: clamp(2rem, 5.5vh, 3.2rem); font-weight: 700; color: var(--ink);
  line-height: 1.05; font-variant-numeric: tabular-nums;
}
.cam-metric-label { margin-top: .25rem; font-size: 1.05rem; font-weight: 600; color: var(--forest-500); letter-spacing: .5px; }
.cam-error { margin-top: .5rem; font-size: .78rem; color: var(--danger); word-break: break-word; }

/* Footer */
.foot {
  flex: 0 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 .25rem;
  font-size: .85rem; color: var(--muted);
}
#refresh-btn {
  font: inherit; font-size: .85rem; font-weight: 500;
  color: var(--forest-700); background: #fff;
  border: 1px solid rgba(20,84,60,.2); border-radius: 999px;
  padding: .45rem 1rem; cursor: pointer; transition: background .15s;
}
#refresh-btn:hover { background: #f0f7f2; }
#refresh-btn:active { transform: scale(.97); }

/* Small screens: stack and allow normal scrolling (single-screen layout targets the big display) */
@media (max-width: 820px) {
  body { height: auto; min-height: 100vh; overflow: auto; }
  .wrap { max-width: 1040px; }
  .cards { grid-auto-flow: row; grid-auto-columns: auto; grid-template-columns: 1fr; }
  .cam-snap-wrap { flex: none; aspect-ratio: 16 / 9; min-height: 0; }
}
@media (max-width: 480px) {
  .topbar { flex-direction: column; align-items: flex-start; }
}
