:root {
  --bg:      #0d1117;
  --surface: #161b22;
  --card:    #21262d;
  --border:  #30363d;
  --accent:  #2563eb;
  --accent2: #1d4ed8;
  --success: #3fb950;
  --warning: #d29922;
  --danger:  #da3633;
  --text:    #e6edf3;
  --muted:   #8b949e;
  --sidebar-w: 230px;
  --sidebar-collapsed-w: 58px;
  --sidebar-transition: width 0.22s ease, margin-left 0.22s ease;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  font-size: 14px;
  line-height: 1.5;
}

a { color: inherit; text-decoration: none; }

/* ── Sidebar ──────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  overflow: hidden;
  transition: var(--sidebar-transition);
}

.sidebar-brand {
  padding: 1.25rem 1rem;
  border-bottom: 1px solid var(--border);
  font-size: 1rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  color: var(--text);
  white-space: nowrap;
  min-height: 60px;
  flex-shrink: 0;
}
.sidebar-brand .brand-icon {
  width: 28px; height: 28px;
  background: var(--accent);
  border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
}
.sidebar-brand .brand-name { flex: 1; transition: opacity 0.15s; }

/* Toggle button */
.sidebar-toggle {
  background: none;
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 4px;
  width: 22px; height: 22px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  font-size: 13px;
  flex-shrink: 0;
  transition: color 0.12s, background 0.12s;
  margin-left: auto;
  line-height: 1;
}
.sidebar-toggle:hover { color: var(--text); background: rgba(255,255,255,0.06); }

/* ── Collapsed state ──────────────────────────────────────────────── */
body.sidebar-collapsed .sidebar { width: var(--sidebar-collapsed-w); }
body.sidebar-collapsed .main    { margin-left: var(--sidebar-collapsed-w); }

body.sidebar-collapsed .sidebar-brand .brand-name { opacity: 0; width: 0; overflow: hidden; }
body.sidebar-collapsed .sidebar-toggle { margin-left: 0; }

body.sidebar-collapsed .nav-section { opacity: 0; height: 0; overflow: hidden; padding: 0; margin: 0; }
body.sidebar-collapsed .nav-link    { justify-content: center; padding: 0.55rem 0; margin: 2px 6px; position: relative; }
body.sidebar-collapsed .nav-link .label { opacity: 0; width: 0; overflow: hidden; }
body.sidebar-collapsed .nav-link .icon  { margin: 0; font-size: 18px; }

/* Tooltip on collapsed icons */
body.sidebar-collapsed .nav-link[data-tooltip]:hover::after {
  content: attr(data-tooltip);
  position: absolute;
  left: calc(100% + 10px);
  top: 50%;
  transform: translateY(-50%);
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.3rem 0.65rem;
  border-radius: 5px;
  font-size: 0.78rem;
  white-space: nowrap;
  z-index: 300;
  pointer-events: none;
  box-shadow: 0 2px 8px rgba(0,0,0,0.4);
}

body.sidebar-collapsed .sidebar-bottom .nav-link { justify-content: center; padding: 0.55rem 0; }
body.sidebar-collapsed .user-name  { opacity: 0; width: 0; overflow: hidden; }
body.sidebar-collapsed .sidebar-user { justify-content: center; }

/* ── Hover-expand when collapsed ──────────────────────────────────── */
body.sidebar-collapsed .sidebar:hover {
  width: var(--sidebar-w);
  box-shadow: 4px 0 16px rgba(0,0,0,0.35);
}
body.sidebar-collapsed .sidebar:hover .brand-name,
body.sidebar-collapsed .sidebar:hover .nav-link .label,
body.sidebar-collapsed .sidebar:hover .user-name {
  opacity: 1; width: auto; overflow: visible;
}
body.sidebar-collapsed .sidebar:hover .nav-section {
  opacity: 1; height: auto; overflow: visible;
  padding: 1rem 1rem 0.4rem;
  margin: 0;
}
body.sidebar-collapsed .sidebar:hover .nav-link {
  justify-content: flex-start;
  padding: 0.55rem 1rem;
  margin: 2px 8px;
}
body.sidebar-collapsed .sidebar:hover .sidebar-bottom .nav-link {
  justify-content: flex-start;
  padding: 0.55rem 1rem;
}
body.sidebar-collapsed .sidebar:hover .sidebar-user {
  justify-content: space-between;
}
/* Suppress the icon-tooltip while hover-expanded (the labels are visible) */
body.sidebar-collapsed .sidebar:hover .nav-link[data-tooltip]:hover::after {
  display: none;
}
body.sidebar-collapsed .logout-btn { margin: 0; }

.sidebar-nav { padding: 0.6rem 0; flex: 1; }

.nav-section {
  padding: 0.75rem 1rem 0.25rem;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-weight: 600;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0.75rem;
  margin: 1px 0.5rem;
  border-radius: 6px;
  color: var(--muted);
  font-size: 0.875rem;
  transition: background 0.12s, color 0.12s, padding 0.22s;
  white-space: nowrap;
  overflow: hidden;
}
.nav-link:hover { background: rgba(255,255,255,0.05); color: var(--text); }
.nav-link.active { background: rgba(37,99,235,0.18); color: var(--accent); font-weight: 500; }
.nav-link .icon  { font-size: 16px; width: 18px; text-align: center; flex-shrink: 0; }
.nav-link .label { transition: opacity 0.15s, width 0.15s; }

.sidebar-bottom {
  padding: 0.5rem 0;
  border-top: 1px solid var(--border);
}

.sidebar-user {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 1rem;
  margin: 0.25rem 0.5rem;
  border-radius: 6px;
  background: rgba(255,255,255,0.04);
}
.user-name { font-size: 0.8rem; color: var(--muted); }
.logout-btn {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 1rem;
  padding: 0.1rem 0.3rem;
  border-radius: 4px;
  transition: color 0.12s;
  text-decoration: none;
}
.logout-btn:hover { color: var(--danger); }

/* ── Main ─────────────────────────────────────────────────────────── */
.main {
  margin-left: var(--sidebar-w);
  flex: 1;
  padding: 1.75rem 2rem;
  min-height: 100vh;
  transition: var(--sidebar-transition);
}

/* ── Page header ──────────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
  gap: 0.75rem;
}
.page-title { font-size: 1.4rem; font-weight: 700; }
.page-subtitle { font-size: 0.875rem; color: var(--muted); margin-top: 0.15rem; }

/* ── Flash messages ───────────────────────────────────────────────── */
.alerts { margin-bottom: 1.25rem; }
.alert {
  padding: 0.65rem 1rem;
  border-radius: 6px;
  margin-bottom: 0.5rem;
  font-size: 0.875rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.alert-success { background: rgba(63,185,80,0.1); border: 1px solid rgba(63,185,80,0.3); color: var(--success); }
.alert-error   { background: rgba(218,54,51,0.1); border: 1px solid rgba(218,54,51,0.3); color: var(--danger); }
.alert-info    { background: rgba(37,99,235,0.1); border: 1px solid rgba(37,99,235,0.3); color: #60a5fa; }

/* ── Stat row ─────────────────────────────────────────────────────── */
.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem 1.25rem;
}
.stat-value { font-size: 2rem; font-weight: 700; line-height: 1; }
.stat-value.green { color: var(--success); }
.stat-value.yellow { color: var(--warning); }
.stat-value.red { color: var(--danger); }
.stat-label { font-size: 0.75rem; color: var(--muted); margin-top: 0.3rem; }

/* ── Cards ────────────────────────────────────────────────────────── */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.card-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}
.card-title { font-weight: 600; font-size: 0.9rem; }
.card-body { padding: 1.25rem; }

/* ── Device grid ──────────────────────────────────────────────────── */
.device-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
  gap: 1rem;
}
.device-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.25rem;
  display: block;
  transition: border-color 0.15s, transform 0.15s;
}
.device-card:hover { border-color: var(--accent); transform: translateY(-1px); }

.device-name { font-weight: 600; font-size: 1rem; margin-bottom: 0.25rem; }
.device-location { font-size: 0.8rem; color: var(--muted); margin-bottom: 0.75rem; }
.device-meta { font-size: 0.8rem; color: var(--muted); display: flex; gap: 1rem; flex-wrap: wrap; }

/* ── Status badges ────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
}
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-online  { background: rgba(63,185,80,0.12);  color: var(--success); }
.badge-idle    { background: rgba(210,153,34,0.12);  color: var(--warning); }
.badge-offline { background: rgba(218,54,51,0.12);   color: var(--danger); }
.badge-never   { background: rgba(139,148,158,0.12); color: var(--muted); }
/* Asset / loan lifecycle badges (in_stock / deployed / returned / retired) */
.badge-deployed { background: rgba(63,185,80,0.12);  color: var(--success); }
.badge-in_stock { background: rgba(37,99,235,0.14);  color: var(--accent); }
.badge-returned { background: rgba(210,153,34,0.12); color: var(--warning); }
.badge-retired  { background: rgba(139,148,158,0.12);color: var(--muted); }

/* ── Video clip-trim scrubber (video_trim.js / _video_trim.html) ───────── */
.vtrim { margin: 0.25rem 0 0.5rem; }
.vtrim-vid {
  width: 100%; max-height: 240px; background: #000;
  border-radius: 6px; display: block; object-fit: contain;
}
.vtrim-slider { position: relative; height: 34px; margin-top: 0.5rem; }
.vtrim-track {
  position: absolute; top: 50%; left: 0; right: 0; height: 6px;
  transform: translateY(-50%); background: var(--border); border-radius: 3px;
}
.vtrim-fill { position: absolute; top: 0; bottom: 0; background: var(--accent); border-radius: 3px; }
/* Two ranges share the track; only their thumbs receive pointer events so
   both handles stay grabbable. */
.vtrim-r {
  position: absolute; top: 0; left: 0; width: 100%; height: 34px; margin: 0;
  background: transparent; pointer-events: none;
  -webkit-appearance: none; appearance: none;
}
.vtrim-r-start { z-index: 4; }
.vtrim-r-end   { z-index: 5; }
.vtrim-r::-webkit-slider-runnable-track { background: transparent; border: none; }
.vtrim-r::-moz-range-track { background: transparent; border: none; }
.vtrim-r::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--accent); border: 2px solid #fff; cursor: pointer;
  pointer-events: auto; box-shadow: 0 1px 3px rgba(0,0,0,0.5);
}
.vtrim-r::-moz-range-thumb {
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--accent); border: 2px solid #fff; cursor: pointer;
  pointer-events: auto; box-shadow: 0 1px 3px rgba(0,0,0,0.5);
}
.vtrim-readouts {
  display: flex; gap: 0.75rem; align-items: center; flex-wrap: wrap;
  font-size: 0.78rem; color: var(--muted); margin-top: 0.4rem;
}
.vtrim-readouts b { color: var(--text); font-weight: 600; }

/* ── Sidebar attention badge (new bug reports) ─────────────────────────── */
.nav-link { position: relative; }   /* anchor for the badge in expanded mode */
.nav-badge {
  position: absolute; top: 50%; right: 10px; transform: translateY(-50%);
  min-width: 17px; height: 17px; padding: 0 5px; box-sizing: border-box;
  background: var(--danger); color: #fff;
  font-size: 0.64rem; font-weight: 700; line-height: 15px;
  text-align: center; border-radius: 9px;
}
body.sidebar-collapsed .nav-badge { top: 5px; right: 6px; transform: none; }

/* ── Report a bug / request a feature modal ────────────────────────────── */
.report-overlay {
  position: fixed; inset: 0; z-index: 200; background: rgba(0,0,0,0.55);
  display: flex; align-items: center; justify-content: center; padding: 1rem;
}
.report-modal {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; width: 100%; max-width: 520px;
  padding: 1.25rem; box-shadow: 0 10px 40px rgba(0,0,0,0.45);
}
.report-modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.report-close { background: transparent; border: none; color: var(--muted); font-size: 1.1rem; cursor: pointer; line-height: 1; }
.report-close:hover { color: var(--text); }
.report-kinds { display: flex; flex-direction: column; gap: 0.4rem; }
.report-kind { display: flex; align-items: center; gap: 0.5rem; font-size: 0.88rem; cursor: pointer; }

/* Report kind + status badges (Reports list) */
.badge-bug          { background: rgba(218,54,51,0.14);  color: var(--danger); }
.badge-feature      { background: rgba(37,99,235,0.14);  color: var(--accent); }
.badge-new          { background: rgba(218,54,51,0.14);  color: var(--danger); }
.badge-in_progress  { background: rgba(210,153,34,0.14); color: var(--warning); }
.badge-ignored      { background: rgba(139,148,158,0.14);color: var(--muted); }
.badge-completed    { background: rgba(63,185,80,0.14);  color: var(--success); }

/* ── Buttons ──────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.45rem 1rem;
  border-radius: 6px;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.12s;
  white-space: nowrap;
}
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { background: var(--accent2); border-color: var(--accent2); }
.btn-outline { background: transparent; color: var(--text); border-color: var(--border); }
.btn-outline:hover { background: var(--surface); }
.btn-danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: rgba(218,54,51,0.1); }
.btn-sm { padding: 0.3rem 0.65rem; font-size: 0.8rem; }
.btn-xs { padding: 0.2rem 0.5rem; font-size: 0.75rem; }

/* Submit buttons (save / add) are always blue unless they're danger */
button[type="submit"].btn-outline:not(.btn-danger) {
  background: var(--accent); color: #fff; border-color: var(--accent);
}
button[type="submit"].btn-outline:not(.btn-danger):hover {
  background: var(--accent2); border-color: var(--accent2);
}

/* ── Forms ────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 1rem; }
.form-label { display: block; margin-bottom: 0.35rem; font-size: 0.8rem; color: var(--muted); font-weight: 500; }
.form-control {
  width: 100%;
  padding: 0.5rem 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 0.875rem;
  transition: border-color 0.12s;
}
.form-control:focus { outline: none; border-color: var(--accent); }
.form-control::placeholder { color: var(--muted); }
select.form-control { cursor: pointer; }
textarea.form-control { resize: vertical; min-height: 80px; }

.form-row { display: flex; gap: 0.75rem; }
.form-row .form-group { flex: 1; }

.form-help { font-size: 0.75rem; color: var(--muted); margin-top: 0.25rem; }

/* ── Tables ───────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th {
  text-align: left;
  padding: 0.6rem 1rem;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
td {
  padding: 0.7rem 1rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.875rem;
}
tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: rgba(255,255,255,0.02); }

/* ── Playlist editor ──────────────────────────────────────────────── */
.slide-list { display: flex; flex-direction: column; gap: 0.5rem; }

.slide-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: grab;
  transition: border-color 0.12s;
  user-select: none;
}
.slide-item:hover { border-color: var(--muted); }
.slide-item.drag-over { border-color: var(--accent); background: rgba(37,99,235,0.08); }
.slide-item.dragging { opacity: 0.4; }

.drag-handle { color: var(--muted); font-size: 18px; cursor: grab; line-height: 1; }
.slide-thumb {
  width: 80px; height: 45px;
  border-radius: 4px;
  object-fit: cover;
  background: var(--bg);
  border: 1px solid var(--border);
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
  color: var(--muted);
  overflow: hidden;
}
/* Portrait slides get a portrait thumbnail so the list visually distinguishes
   orientation at a glance instead of squishing 9:16 art into a 16:9 box. */
.slide-thumb.portrait { width: 45px; height: 80px; }
.slide-thumb img, .slide-thumb video {
  width: 100%; height: 100%; object-fit: cover; border-radius: 3px;
}

.slide-info { flex: 1; min-width: 0; }
.slide-info .s-title { font-weight: 500; font-size: 0.875rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.slide-info .s-meta  { font-size: 0.75rem; color: var(--muted); margin-top: 0.1rem; }

.slide-actions { display: flex; gap: 0.4rem; flex-shrink: 0; }

/* ── Add slide tabs ───────────────────────────────────────────────── */
.tabs { display: flex; border-bottom: 1px solid var(--border); margin-bottom: 1.25rem; }
.tab-btn {
  padding: 0.5rem 1.1rem;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.875rem;
  margin-bottom: -1px;
  transition: all 0.12s;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 500; }

.tab-pane { display: none; }
.tab-pane.active { display: block; }

/* ── Code / ID display ────────────────────────────────────────────── */
.code-block {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.65rem 1rem;
  font-family: 'Cascadia Code', 'Consolas', monospace;
  font-size: 0.8rem;
  word-break: break-all;
  color: #79c0ff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}
.code-block .copy-btn {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 0.2rem 0.4rem;
  border-radius: 4px;
  font-size: 0.75rem;
  flex-shrink: 0;
  transition: color 0.12s;
}
.code-block .copy-btn:hover { color: var(--text); }

/* ── Detail layout (cards stack full width) ──────────────────────── */
.detail-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.25rem;
  align-items: stretch;
}

/* ── Device-page card grid (reorderable + customisable) ──────────── */
/* Used on /devices/<id>. Each child is a top-level .card carrying a
   data-card-key + a width class (.dc-w-1 … .dc-w-4) chosen from defaults
   in ALL_DEVICE_CARDS or the user's saved prefs. CSS Grid auto-flows the
   cards into rows of 4 units; cards that don't fit on the current row
   wrap to the next. Collapses to a single column on narrow screens. */
.device-card-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  align-items: start;
}
.device-card-grid > .dc-w-1 { grid-column: span 1; }
.device-card-grid > .dc-w-2 { grid-column: span 2; }
.device-card-grid > .dc-w-3 { grid-column: span 3; }
.device-card-grid > .dc-w-4 { grid-column: span 4; }
@media (max-width: 900px) {
  .device-card-grid { grid-template-columns: repeat(2, 1fr); }
  .device-card-grid > .dc-w-3,
  .device-card-grid > .dc-w-4 { grid-column: span 2; }
}
@media (max-width: 560px) {
  .device-card-grid { grid-template-columns: 1fr; }
  .device-card-grid > [class*="dc-w-"] { grid-column: span 1; }
}

/* ── Customise-layout edit mode (device page + sidebar) ──────────── */
/* Triggered by adding .editing to the grid container. Cards get a soft
   outline and grab cursor; a tiny ✕ hide button appears in the header;
   forms inside cards are pointer-events-disabled so dragging never
   accidentally triggers a Save or Reboot. */
.device-card-grid.editing > .card {
  outline: 2px dashed var(--accent);
  outline-offset: -2px;
  cursor: grab;
}
.device-card-grid.editing > .card.dragging { opacity: 0.45; }
.device-card-grid.editing > .card .card-body,
.device-card-grid.editing > .card form {
  pointer-events: none;
}
.device-card-grid.editing > .card .dc-hide-btn { display: inline-flex; }
.dc-hide-btn {
  display: none; /* shown only in editing mode */
  align-items: center; justify-content: center;
  width: 22px; height: 22px;
  border: none; border-radius: 4px;
  background: var(--danger, #b62a2a);
  color: #fff;
  cursor: pointer;
  font-size: 12px; line-height: 1;
  pointer-events: auto !important; /* override the editing-mode block */
}
.dc-hide-btn:hover { filter: brightness(1.15); }

/* Hidden-card ghost tiles shown in edit mode (clickable to restore) */
.dc-ghost {
  border: 2px dashed var(--border);
  border-radius: 8px;
  padding: 1rem;
  display: flex; align-items: center; justify-content: center;
  text-align: center;
  font-size: 0.85rem;
  color: var(--muted);
  cursor: pointer;
  background: transparent;
  min-height: 64px;
  transition: border-color 0.12s, color 0.12s;
}
.dc-ghost:hover { border-color: var(--accent); color: var(--text); }

/* Floating customise toolbar */
.dc-edit-bar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  gap: 0.5rem;
  align-items: center;
  padding: 0.55rem 0.9rem;
  margin-bottom: 0.85rem;
  background: var(--surface);
  border: 1px solid var(--accent);
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.25);
  font-size: 0.85rem;
}
.dc-edit-bar .dc-save-status { color: var(--muted); font-size: 0.75rem; }

/* Sidebar edit mode — drag/hide for nav links */
.sidebar.editing .nav-link {
  outline: 2px dashed var(--accent);
  outline-offset: -2px;
  cursor: grab;
}
.sidebar.editing .nav-link.dragging { opacity: 0.45; }
.sidebar.editing .nav-link .sb-hide-btn { display: inline-flex; }
.sb-hide-btn {
  display: none;
  align-items: center; justify-content: center;
  width: 18px; height: 18px;
  border: none; border-radius: 3px;
  background: var(--danger, #b62a2a);
  color: #fff;
  cursor: pointer;
  font-size: 10px; line-height: 1;
  margin-left: auto;
}
.sidebar .sb-ghost {
  display: none; /* only visible while the sidebar is in editing mode */
  align-items: center; gap: 0.55rem;
  padding: 0.4rem 0.7rem;
  border: 1px dashed var(--border); border-radius: 6px;
  font-size: 0.78rem; color: var(--muted);
  cursor: pointer;
  margin: 0.15rem 0.65rem;
  text-decoration: none;
}
.sidebar.editing .sb-ghost { display: flex; }
.sidebar .sb-ghost:hover { color: var(--text); border-color: var(--accent); }
.sidebar .sb-ghost .icon { width: 16px; display: inline-flex; }
.sidebar .sb-ghost .label { flex: 1; }
.sb-edit-toggle {
  display: flex; align-items: center; justify-content: center;
  width: 22px; height: 22px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--muted);
  cursor: pointer;
  font-size: 11px;
}
.sb-edit-toggle:hover { color: var(--text); border-color: var(--accent); }
.sidebar.editing .sb-edit-toggle { background: var(--accent); color:#fff; border-color: var(--accent); }

/* ── Empty state ──────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--muted);
}
.empty-state .empty-icon { font-size: 3rem; margin-bottom: 0.75rem; }
.empty-state .empty-title { font-size: 1rem; font-weight: 600; color: var(--text); margin-bottom: 0.4rem; }
.empty-state .empty-desc  { font-size: 0.875rem; margin-bottom: 1.25rem; }

/* ── Customer / location tags ─────────────────────────────────────── */
.customer-tag {
  display: inline-flex;
  align-items: center;
  padding: 0.18rem 0.55rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  background: rgba(37,99,235,0.15);
  color: #60a5fa;
  white-space: nowrap;
}
.location-tag {
  display: inline-flex;
  align-items: center;
  padding: 0.18rem 0.55rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  background: rgba(63,185,80,0.12);
  color: var(--success);
  white-space: nowrap;
}

/* ── Locations list (on customers page) ───────────────────────────── */
.location-list {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-top: 0.5rem;
}
.location-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.6rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 5px;
  font-size: 0.8rem;
}
.location-row .loc-name { flex: 1; color: var(--muted); }
.location-row form { display: flex; gap: 0.35rem; align-items: center; }

/* ── Tab links (anchor-tag variant for filter tabs) ───────────────── */
a.tab-btn { text-decoration: none; display: inline-block; }

/* ── Playlist grid ────────────────────────────────────────────────── */
.playlist-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1rem;
}
.playlist-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  transition: border-color 0.15s;
}
.playlist-card:hover { border-color: var(--accent); }
.playlist-card .pl-name { font-weight: 600; font-size: 1rem; }
.playlist-card .pl-meta { font-size: 0.8rem; color: var(--muted); }
.playlist-card .pl-actions { display: flex; gap: 0.5rem; margin-top: auto; }

/* ── Breadcrumb ───────────────────────────────────────────────────── */
.breadcrumb { display: flex; align-items: center; gap: 0.4rem; font-size: 0.8rem; color: var(--muted); margin-bottom: 1.25rem; }
.breadcrumb a:hover { color: var(--text); }
.breadcrumb .sep { color: var(--border); }

/* ── Slide builder modal ──────────────────────────────────────────── */
.builder-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.88);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.builder-modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 100%;
  max-width: 1140px;
  max-height: 94vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.builder-modal-header {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
.builder-modal-header h2 { font-size: 1rem; font-weight: 600; }
.builder-close {
  background: none; border: none; color: var(--muted);
  font-size: 1.2rem; cursor: pointer; padding: 0.25rem 0.5rem;
  border-radius: 4px; transition: color 0.12s;
}
.builder-close:hover { color: var(--text); }

.builder-modal-body {
  display: grid;
  grid-template-columns: 360px 1fr;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}
.builder-left {
  padding: 1.25rem;
  border-right: 1px solid var(--border);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.builder-right {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  background: #000;
  padding: 1.5rem;
}
.builder-preview-wrap {
  width: 100%;
  max-width: 800px;
  aspect-ratio: 16/9;
  position: relative;
}
#builder-preview {
  width: 100%; height: 100%;
  display: block;
  border-radius: 4px;
}
.builder-preview-label {
  font-size: 0.72rem;
  color: rgba(255,255,255,0.3);
  text-align: center;
}

/* Template picker */
.template-picker {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.5rem;
}
.tpl-card {
  aspect-ratio: 16/9;
  border-radius: 6px;
  border: 2px solid var(--border);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  transition: border-color 0.12s, transform 0.1s;
  overflow: hidden;
  padding: 0.3rem;
}
.tpl-card:hover { border-color: var(--muted); transform: translateY(-1px); }
.tpl-card.active { border-color: var(--accent); }
.tpl-card .tpl-icon { font-size: 1.1rem; line-height: 1; }
.tpl-card .tpl-name { font-size: 0.58rem; font-weight: 600; color: var(--text); text-align: center; line-height: 1.2; }

/* Builder form */
.builder-section-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  font-weight: 600;
  margin-bottom: 0.5rem;
}
.color-row {
  display: flex;
  gap: 0.75rem;
}
.color-row .form-group { flex: 1; }
.color-swatch {
  width: 100%; height: 36px;
  border-radius: 5px;
  border: 1px solid var(--border);
  cursor: pointer;
  padding: 0.15rem;
  background: var(--bg);
}
.builder-footer {
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.builder-footer .form-group { margin-bottom: 0; }

/* Fit toggle in image upload form */
.fit-toggle { display: flex; gap: 1rem; flex-wrap: wrap; }
.fit-option {
  display: flex; align-items: center; gap: 0.4rem;
  cursor: pointer; font-size: 0.8rem; color: var(--muted);
  padding: 0.35rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 5px;
  transition: all 0.12s;
}
.fit-option input[type=radio] { accent-color: var(--accent); }
.fit-option:has(input:checked) {
  border-color: var(--accent);
  background: rgba(37,99,235,0.1);
  color: var(--text);
}

/* ── Time Conditions ──────────────────────────────────────────────── */
.tc-plan-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1rem;
}
.tc-plan-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.tc-plan-name { font-weight: 600; font-size: 1rem; }
.tc-plan-meta { font-size: 0.8rem; color: var(--muted); }
.tc-plan-actions { display: flex; gap: 0.5rem; margin-top: auto; padding-top: 0.5rem; }

.tc-bar-wrap { margin-top: 0.25rem; }
.tc-bar {
  position: relative;
  height: 22px;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--border);
  border-radius: 11px;
  overflow: hidden;
}
.tc-bar-fill {
  position: absolute;
  top: 0; bottom: 0;
  background: var(--accent);
  opacity: 0.85;
  border-radius: 11px;
  transition: left 0.15s, width 0.15s;
}
.tc-bar-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.68rem;
  color: var(--muted);
  margin-top: 0.3rem;
  padding: 0 2px;
}

.tc-day-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.7rem 1.25rem;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.tc-day-row:last-child { border-bottom: none; }
.tc-day-name { width: 90px; font-size: 0.875rem; font-weight: 500; flex-shrink: 0; }
.tc-day-badge {
  display: inline-flex;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  background: rgba(218,54,51,0.12);
  color: var(--danger);
}

/* ── Playlist preview panels ──────────────────────────────────────── */
.preview-panel {
  position: absolute;
  inset: 0;
  opacity: 0;
  transition: opacity 0.7s ease;
}
.preview-panel.active { opacity: 1; }
.preview-title-bar {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  background: rgba(0,0,0,0.55);
  padding: 0.65rem 1rem;
  color: #fff;
  font-size: 0.9rem;
  font-weight: 500;
}
.pv-headline {
  color: #fff;
  font-size: clamp(1.2rem, 3.5vw, 2.5rem);
  font-weight: 800;
  text-align: center;
  margin-bottom: 0.75rem;
  line-height: 1.2;
}
.pv-body {
  color: rgba(255,255,255,0.75);
  font-size: clamp(0.8rem, 2vw, 1.4rem);
  text-align: center;
}

/* ── Contact card preview ─────────────────────────────────────────── */
.contact-card-preview {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.85rem 1rem;
}
.cc-name { font-weight: 600; font-size: 0.95rem; }
.cc-role { font-size: 0.78rem; color: var(--muted); margin-top: 0.15rem; }
.cc-row  { font-size: 0.82rem; color: var(--text); margin-top: 0.35rem; display: flex; align-items: center; gap: 0.4rem; }

/* ── Divider ──────────────────────────────────────────────────────── */
.divider { border: none; border-top: 1px solid var(--border); margin: 1.25rem 0; }

/* ── Role badge ───────────────────────────────────────────────────── */
.role-badge {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  background: rgba(37,99,235,0.15);
  color: #60a5fa;
  white-space: nowrap;
}

/* ── Permission grid ──────────────────────────────────────────────── */
.perm-grid-wrap { overflow-x: auto; }

.perm-table {
  width: 100%;
  border-collapse: collapse;
}
.perm-table thead th {
  padding: 0.65rem 0.75rem;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  text-align: center;
}
.perm-table .perm-section-col { text-align: left; }
.perm-table tbody tr { border-bottom: 1px solid var(--border); }
.perm-table tbody tr:last-child { border-bottom: none; }
.perm-table tbody tr:hover { background: rgba(255,255,255,0.02); }

.perm-section-name {
  padding: 0.65rem 0.75rem;
  font-size: 0.875rem;
  font-weight: 500;
}
.perm-action-cell {
  padding: 0.65rem 0.75rem;
  text-align: center;
}
.perm-check {
  width: 16px;
  height: 16px;
  cursor: pointer;
  accent-color: var(--accent);
}
.perm-na {
  color: var(--border);
  font-size: 0.85rem;
}

/* ═════════════════════════════════════════════════════════════════
   Light theme — opt in via [data-theme="light"] on <html>.
   Default (no attribute) keeps the dark palette defined at :root.
   ═════════════════════════════════════════════════════════════════ */
[data-theme="light"] {
  --bg:      #f6f8fa;
  --surface: #ffffff;
  --card:    #ffffff;
  --border:  #d0d7de;
  --accent:  #2563eb;
  --accent2: #1d4ed8;
  --success: #1a7f37;
  --warning: #9a6700;
  --danger:  #cf222e;
  --text:    #1f2328;
  --muted:   #57606a;
}

/* Subtle card shadow in light mode (borders alone read flat on white) */
[data-theme="light"] .card,
[data-theme="light"] .device-card,
[data-theme="light"] .stat-card {
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}
[data-theme="light"] .nav-link:hover     { background: rgba(0, 0, 0, 0.045); color: var(--text); }
[data-theme="light"] .nav-link.active    { background: rgba(37, 99, 235, 0.12); }
[data-theme="light"] .sidebar-toggle:hover { background: rgba(0, 0, 0, 0.05); color: var(--text); }
[data-theme="light"] .sidebar-user       { background: rgba(0, 0, 0, 0.035); }
[data-theme="light"] tbody tr:hover td   { background: rgba(0, 0, 0, 0.025); }
[data-theme="light"] .alert-info         { color: #0969da; }
[data-theme="light"] .form-control       { background: #ffffff; }

/* ═════════════════════════════════════════════════════════════════
   Collapsible cards — JS marks every .card with .collapsible.
   Click anywhere on the header (except buttons/links) to toggle.
   ═════════════════════════════════════════════════════════════════ */
.card.collapsible > .card-header {
  cursor: pointer;
  user-select: none;
  position: relative;
}
.card.collapsible > .card-header::after {
  content: '';
  width: 8px;
  height: 8px;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(45deg);
  margin-left: 0.6rem;
  margin-top: -3px;
  align-self: center;
  flex-shrink: 0;
  transition: transform 0.18s ease;
}
.card.collapsible.collapsed > .card-header {
  border-bottom: none;
}
.card.collapsible.collapsed > .card-header::after {
  transform: rotate(-45deg);
  margin-top: 0;
}
.card.collapsible.collapsed > .card-body {
  /* !important so we win against the many inline `style="display:flex; ..."`
     attributes scattered across .card-body elements. */
  display: none !important;
}

/* ═════════════════════════════════════════════════════════════════
   Theme toggle button (sits in the sidebar-user row in both bases)
   ═════════════════════════════════════════════════════════════════ */
.theme-toggle-btn {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 0.1rem 0.35rem;
  margin: 0 0.1rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  line-height: 1;
  border-radius: 4px;
  transition: color 0.12s, background 0.12s;
  text-decoration: none;
}
.theme-toggle-btn:hover { color: var(--text); }
.theme-toggle-btn .icon-sun  { display: none; }
.theme-toggle-btn .icon-moon { display: block; }
[data-theme="light"] .theme-toggle-btn .icon-sun  { display: block; }
[data-theme="light"] .theme-toggle-btn .icon-moon { display: none; }
body.sidebar-collapsed .theme-toggle-btn { display: none; }
body.sidebar-collapsed .sidebar:hover .theme-toggle-btn { display: inline-flex; }

/* Portal: cards take the full width of the page */
.portal-main { max-width: none !important; width: 100% !important; }
