:root {
  --ink: #111111; --dim: #6b6b6b; --line: #e6e3dc; --bg: #f4f3ef;
  --card: #ffffff; --dark: #0D0D0D; --accent: #FF1744; --ok: #1c8a4a;
  --warn: #b8860b; --sidebar-w: 210px; --bottom-h: 64px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
body {
  margin: 0; font-family: 'Segoe UI', system-ui, Arial, sans-serif;
  background: var(--bg); color: var(--ink);
}
a { text-decoration: none; color: inherit; }
button, input { font-family: inherit; }

/* ---- desktop/tablet sidebar ---- */
.side {
  position: fixed; top: 0; left: 0; bottom: 0; width: var(--sidebar-w);
  background: var(--dark); color: #fff; padding: 24px 0; display: none;
  flex-direction: column;
}
.side .brand {
  padding: 0 22px 22px; font-size: 22px; font-weight: 800; letter-spacing: 1px;
}
.side .brand span { display: block; font-size: 11px; color: var(--accent); letter-spacing: 3px; font-weight: 700; }
.side a {
  padding: 14px 22px; font-size: 15.5px; color: #ccc; display: flex; align-items: center; gap: 10px;
}
.side a.on { color: #fff; background: rgba(255,255,255,0.06); border-left: 3px solid var(--accent); }
.side a.logout { margin-top: auto; color: #999; }
.side .ic { width: 18px; text-align: center; opacity: 0.85; }

.side-live {
  display: flex; align-items: center; gap: 8px; padding: 0 22px 20px;
  font-size: 13px; color: #aaa; font-weight: 600;
}
.live-dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--ok);
  box-shadow: 0 0 0 3px rgba(28,138,74,0.25); flex-shrink: 0;
}
.navbadge {
  margin-left: auto; background: rgba(255,255,255,0.12); color: #ddd;
  font-size: 11.5px; font-weight: 700; padding: 2px 8px; border-radius: 10px;
}
.navbadge.warn { background: var(--accent); color: #fff; }
.side-foot {
  padding: 16px 22px 4px; font-size: 11px; line-height: 1.5; color: #777;
  border-top: 1px solid rgba(255,255,255,0.08); margin-top: 10px;
}

/* ---- mobile bottom nav ---- */
.bottom {
  position: fixed; left: 0; right: 0; bottom: 0; height: var(--bottom-h);
  background: var(--dark); display: flex; z-index: 10;
}
.bottom a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; color: #999; font-size: 11px; letter-spacing: 0.5px;
}
.bottom a.on { color: #fff; }
.bottom .ic { font-size: 18px; }

.content { padding: 24px 20px calc(var(--bottom-h) + 24px); max-width: 1500px; }

@media (min-width: 900px) {
  .side { display: flex; }
  .bottom { display: none; }
  .content { margin-left: var(--sidebar-w); padding: 32px 44px; }
}

/* ---- page head ---- */
.pagehead { margin-bottom: 24px; }
.pagehead h1 { font-size: 30px; font-weight: 800; margin: 4px 0 6px; }
.pagehead .back { font-size: 13.5px; color: var(--dim); font-weight: 600; }
.pagehead .muted { font-size: 15px; }
.muted { color: var(--dim); }
.muted.small { font-size: 13px; }
.center { text-align: center; }
.section-title { font-size: 13px; font-weight: 800; letter-spacing: 1.5px; color: var(--dim); margin: 30px 0 12px; }

/* ---- tiles (layouts / groups) ---- */
.cardgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 14px; }
.tile {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: 18px; display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center;
}
.tile-name { font-weight: 800; font-size: 16px; }
.tile-sub { font-size: 13px; color: var(--dim); }
.tile-shape {
  display: grid; gap: 3px; width: 64px; height: 88px;
}
.tile-shape span { background: #ddd; border-radius: 2px; }
.tile-shape.r1.c1 { grid-template-columns: 1fr; grid-template-rows: 1fr; }
.tile-shape.r2.c1 { grid-template-columns: 1fr; grid-template-rows: 1fr 1fr; }
.tile-shape.r3.c1 { grid-template-columns: 1fr; grid-template-rows: 1fr 1fr 1fr; }
.tile-shape.r2.c2 { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }
.tile-shape.r3.c2 { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr 1fr; }
.tile-shape.r4.c2 { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr 1fr 1fr; }

/* ---- forms ---- */
.inline-add { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 20px; }
.inline-add input {
  padding: 12px 15px; border: 1px solid var(--line); border-radius: 10px; font-size: 15px; min-width: 200px;
}
.push {
  background: var(--dark); color: #fff; border: none; border-radius: 10px;
  padding: 12px 22px; font-size: 14.5px; font-weight: 700; letter-spacing: 1px; cursor: pointer;
}
.push:disabled { background: #ccc; cursor: not-allowed; }
.empty { color: var(--dim); padding: 30px; text-align: center; border: 1.5px dashed var(--line); border-radius: 12px; }

/* ---- booth assignment chips ---- */
.boothrow { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 20px;
  border: 1.5px solid var(--line); font-size: 13px; font-weight: 600; cursor: pointer; background: #fff;
}
.chip.on, .chip:has(input:checked) { background: var(--dark); color: #fff; border-color: var(--dark); }
.chip input { accent-color: var(--accent); }

/* ---- frame upload + gallery ---- */
.frame-upload { display: flex; align-items: center; gap: 12px; margin: 8px 0 16px; flex-wrap: wrap; }
.uploadbtn {
  background: #fff; border: 1.5px dashed var(--line); border-radius: 10px; padding: 12px 18px;
  font-size: 13px; font-weight: 700; letter-spacing: 0.5px; cursor: pointer; color: var(--ink);
}
.uploadbtn input { display: none; }
.framegrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 14px; }
.framecard {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px; position: relative;
}
.framecard img, .framecard video { width: 100%; aspect-ratio: 2 / 3; object-fit: cover; border-radius: 8px; background: #222; }
/* Branding gallery: show the true aspect ratio of each background, never crop. */
.mediacard img, .mediacard video { aspect-ratio: auto; height: auto; object-fit: contain; }
.fname { font-size: 12.5px; font-weight: 700; margin-top: 8px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { font-size: 10.5px; font-weight: 800; letter-spacing: 0.5px; padding: 2px 8px; border-radius: 10px; display: inline-block; margin-top: 4px; }
.badge.ok { background: #e3f5ea; color: var(--ok); }
.badge.warn { background: #fbf0d9; color: var(--warn); }
.framecard-actions { display: flex; align-items: center; justify-content: space-between; margin-top: 8px; }
.fbtn {
  font-size: 12px; font-weight: 700; color: var(--ink); background: #f1efe9; border: none;
  padding: 7px 12px; border-radius: 8px; cursor: pointer;
}
.fdel {
  width: 28px; height: 28px; border-radius: 50%; border: none; background: #f1efe9; color: #a33;
  font-size: 16px; cursor: pointer; line-height: 1;
}
.draghandle {
  cursor: grab; color: var(--dim); font-size: 20px; line-height: 1; user-select: none;
  padding: 4px 6px; border-radius: 8px; touch-action: none;
}
.draghandle:hover { background: #f1efe9; color: var(--ink); }
.groupcard.grabbing { opacity: 0.5; cursor: grabbing; }
/* device cards get their own grid (bigger tiles) — kept separate from
   .framegrid so frame-thumbnail grids elsewhere aren't affected */
.devicegrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 18px; }
.boothcard { padding: 26px; }
.boothlink { display: block; }
.boothcard .fname { font-size: 18px; margin-top: 0; }
.boothcard .badge { font-size: 12px; padding: 4px 11px; margin-top: 10px; }
.boothgo { margin-top: 16px; font-size: 13.5px; font-weight: 800; letter-spacing: 0.5px; color: var(--accent); }

/* ---- per-screen branding slots ---- */
.slotgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; margin-bottom: 8px; }
.slotcard { display: flex; flex-direction: column; gap: 8px; }
.slotthumb {
  width: 100%; aspect-ratio: 3 / 2; background: #f1efe9; border-radius: 8px;
  overflow: hidden; display: flex; align-items: center; justify-content: center;
}
.slotthumb img, .slotthumb video { width: 100%; height: 100%; object-fit: contain; }
.slotempty { color: var(--dim); font-size: 13px; font-weight: 700; letter-spacing: 0.5px; }
.slotname { font-weight: 800; font-size: 13.5px; }
.slotselect {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px;
  font-size: 13px; background: #fff; cursor: pointer;
}
.uploadbtn.small { padding: 8px 12px; font-size: 12px; text-align: center; width: 100%; }

/* ---- "applies on next restart" banner ---- */
.applynote {
  background: #fbf0d9; color: #7a5b12; border: 1px solid #efd9a6;
  border-radius: 10px; padding: 13px 16px; font-size: 14px; font-weight: 600;
  margin: -6px 0 18px;
}
.applynote strong { font-weight: 800; }

/* ---- per-booth tab bar ---- */
.boothtabs {
  display: flex; gap: 6px; border-bottom: 1.5px solid var(--line);
  margin: 0 0 22px; flex-wrap: wrap;
}
.boothtabs a {
  padding: 10px 18px; font-size: 13.5px; font-weight: 700; letter-spacing: 0.5px;
  color: var(--dim); border-bottom: 2.5px solid transparent; margin-bottom: -1.5px;
}
.boothtabs a.on { color: var(--ink); border-bottom-color: var(--accent); }

/* ---- calibration ---- */
.calwrap { display: flex; gap: 24px; flex-wrap: wrap; align-items: flex-start; }
.calstage { position: relative; max-width: 420px; flex: 1 1 320px; touch-action: none; }
.calstage img { width: 100%; display: block; border-radius: 10px; border: 1px solid var(--line); }
.calstage canvas { position: absolute; inset: 0; width: 100%; height: 100%; cursor: crosshair; }
.calside { flex: 0 0 220px; display: flex; flex-direction: column; gap: 10px; }
.calcount { font-size: 20px; font-weight: 800; }
.calside .fbtn, .calside .push { width: 100%; }

/* ---- settings ---- */
.settingscard {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: 18px 20px; margin-bottom: 16px;
}
.settingscard h3 { margin: 0 0 12px; font-size: 13px; font-weight: 800; letter-spacing: 1px; color: var(--dim); text-transform: uppercase; }
.settingsrow {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 10px 0; border-top: 1px solid var(--line);
}
.settingsrow:first-of-type { border-top: none; }
.settingsrow label { font-size: 14px; font-weight: 600; flex: 1; }
.settingsrow input[type="number"], .settingsrow input[type="text"] {
  padding: 9px 12px; border: 1px solid var(--line); border-radius: 8px; font-size: 14px;
  width: 160px; text-align: right;
}
.colorinput { width: 52px; height: 36px; padding: 2px; border: 1px solid var(--line); border-radius: 8px; cursor: pointer; background: none; }
.push.wide { width: 100%; padding: 14px; font-size: 14px; margin-top: 6px; }

/* ---- flash toast (save confirmations) ---- */
.flashwrap {
  position: fixed; top: 18px; left: 50%; transform: translateX(-50%);
  z-index: 50; display: flex; flex-direction: column; gap: 8px;
  transition: opacity 0.5s ease;
}
.flashwrap.fade { opacity: 0; }
.toast {
  background: var(--ok); color: #fff; padding: 12px 22px; border-radius: 10px;
  font-size: 13.5px; font-weight: 700; letter-spacing: 0.5px;
  box-shadow: 0 6px 22px rgba(0,0,0,0.18); animation: toastin 0.22s ease;
  white-space: nowrap;
}
@keyframes toastin { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }

/* ---- login ---- */
body.loginpage { background: var(--dark); display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.loginbox {
  background: #fff; border-radius: 18px; padding: 40px 34px 34px; width: 340px; display: flex;
  flex-direction: column; gap: 14px; box-shadow: 0 18px 50px rgba(0,0,0,0.35);
}
.loginbox .loginlogo { display: block; width: 190px; max-width: 70%; height: auto; margin: 4px auto 2px; }
.loginbox .logintag {
  text-align: center; font-size: 12px; font-weight: 800; letter-spacing: 3px;
  color: var(--ink); margin: 0;
}
.loginbox .loginver { text-align: center; font-size: 11px; color: var(--dim); margin: -8px 0 4px; letter-spacing: 0.5px; }
.loginbox input { padding: 13px 14px; border: 1px solid var(--line); border-radius: 10px; font-size: 15px; }
.err { color: var(--accent); font-size: 13px; text-align: center; }
