:root {
  --bg: #f4f6fa; --surface: #ffffff; --surface-2: #f0f2f7; --border: #dfe3ec;
  --text: #18202f; --muted: #5d6779; --accent: #2563eb; --accent-text: #ffffff; --accent-soft: #e5edff;
  --ok: #15803d; --ok-soft: #dcfce7; --warn: #b45309; --warn-soft: #fef3c7; --danger: #b91c1c; --danger-soft: #fee2e2;
  --nav-bg: #111827; --nav-text: #cbd5e1; --nav-active: #ffffff;
  --radius: 10px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1117; --surface: #161b24; --surface-2: #1d2430; --border: #2a3342;
    --text: #e6e9ef; --muted: #96a0b2; --accent: #4f8bff; --accent-soft: #1b2a4a;
    --ok: #4ade80; --ok-soft: #12301f; --warn: #fbbf24; --warn-soft: #33270c; --danger: #f87171; --danger-soft: #3a1515;
    --nav-bg: #0a0d13; --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font-size: 15px; line-height: 1.45; }
a { color: var(--accent); }
h1 { font-size: 1.45rem; margin: 0; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
h3 { font-size: .95rem; margin: 0 0 .5rem; }
.boot { padding: 3rem; text-align: center; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.mono { font-family: ui-monospace, Consolas, monospace; }
.hidden { display: none !important; }

/* layout */
.layout { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.nav { background: var(--nav-bg); color: var(--nav-text); padding: 1rem .75rem; display: flex; flex-direction: column; gap: .25rem; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: .5rem; color: #fff; font-weight: 700; padding: .25rem .5rem 1rem; font-size: 1.05rem; }
.brand svg { width: 26px; height: 26px; }
.nav a { color: var(--nav-text); text-decoration: none; padding: .55rem .75rem; border-radius: 8px; display: flex; align-items: center; gap: .6rem; white-space: nowrap; }
.nav a:hover { background: rgba(255,255,255,.06); }
.nav a.active { background: rgba(255,255,255,.12); color: var(--nav-active); }
.nav .spacer { flex: 1; }
.client-head { margin: .75rem 0 .5rem; padding: .7rem .75rem; border-radius: 8px; background: rgba(255,255,255,.07); }
.client-label { font-size: .7rem; text-transform: uppercase; letter-spacing: .06em; color: #8892a6; }
.client-title { color: #fff; font-weight: 700; font-size: 1rem; overflow-wrap: anywhere; }
.client-head .pill { margin-top: .35rem; }
a.stat.link { text-decoration: none; color: inherit; }
a.stat.link:hover { border-color: var(--accent); }
.nav .who { font-size: .8rem; padding: .5rem .75rem; color: #8892a6; overflow: hidden; text-overflow: ellipsis; }
main { padding: 1.5rem 2rem 3rem; min-width: 0; max-width: 1200px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.page-head .actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.back { display: inline-block; margin-bottom: .5rem; font-size: .9rem; text-decoration: none; }

@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .nav { position: sticky; top: 0; z-index: 20; height: auto; flex-direction: row; align-items: center; overflow-x: auto; padding: .5rem; gap: .15rem; }
  .brand { padding: .25rem .5rem; }
  .brand span, .nav .who, .nav .spacer { display: none; }
  .client-head { display: none; } /* the client's name is shown under each page title instead */
  /* Content ▾ group: show its pages inline in the scrolling bar */
  .navgroup { display: contents; }
  .navgroup-head { display: none; }
  .submenu, .submenu.open { display: contents; }
  .nav a.sub { padding-left: .65rem; font-size: .9rem; }
  .nav a { padding: .5rem .65rem; font-size: .9rem; }
  main { padding: 1rem 16px 3rem; }
}

/* components */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.1rem; box-shadow: var(--shadow); }
.grid { display: grid; gap: 1rem; }
.grid.stats { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); align-items: start; }
.stat .num { font-size: 1.9rem; font-weight: 700; line-height: 1.1; }
.stat .lbl { color: var(--muted); font-size: .85rem; }
.stack > * + * { margin-top: 1rem; }

button, .btn { font: inherit; border: 1px solid var(--border); background: var(--surface); color: var(--text); padding: .5rem .9rem; border-radius: 8px; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: .4rem; white-space: nowrap; }
button:hover, .btn:hover { background: var(--surface-2); }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.primary:hover { filter: brightness(1.08); }
button.danger { color: var(--danger); }
button.small, .btn.small { padding: .3rem .6rem; font-size: .85rem; }
button:disabled { opacity: .55; cursor: default; }
button.icon { padding: .35rem .5rem; }

label { display: block; font-size: .85rem; font-weight: 600; margin-bottom: .3rem; }
input, select, textarea { font: inherit; width: 100%; padding: .5rem .65rem; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
input[type=checkbox] { width: auto; }
input[type=color] { width: 56px; height: 38px; padding: 3px; cursor: pointer; }
input[type=range] { padding: 0; }
.field { margin-bottom: .9rem; }
.row { display: flex; gap: .75rem; flex-wrap: wrap; align-items: end; }
.row > .field { flex: 1 1 160px; }
.form-error { color: var(--danger); font-size: .9rem; margin: .25rem 0 .75rem; min-height: 1em; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .6rem .5rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--surface-2); }
.table-wrap { overflow-x: auto; }

.pill { display: inline-flex; align-items: center; gap: .35rem; padding: .15rem .55rem; border-radius: 99px; font-size: .78rem; font-weight: 600; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.danger { background: var(--danger-soft); color: var(--danger); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }

.empty { text-align: center; padding: 2.5rem 1rem; color: var(--muted); }
.empty .btn, .empty button { margin-top: .75rem; }

dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1rem; margin: 0; font-size: .9rem; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; overflow-wrap: anywhere; }

/* dialog */
dialog { border: none; border-radius: 12px; padding: 0; width: min(480px, calc(100vw - 32px)); background: var(--surface); color: var(--text); box-shadow: 0 20px 50px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(10,15,25,.5); }
dialog form { padding: 1.25rem; }
dialog .dlg-actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: .5rem; }

#toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%) translateY(20px); background: #111827; color: #fff; padding: .65rem 1rem; border-radius: 8px; opacity: 0; transition: .2s; pointer-events: none; z-index: 100; max-width: calc(100vw - 32px); }
#toast.show { opacity: 1; transform: translateX(-50%); }
#toast.err { background: #991b1b; }

/* login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login { width: min(380px, 100%); }
.login .brand { color: var(--text); justify-content: center; padding-bottom: 1.25rem; font-size: 1.25rem; }

/* media */
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: .9rem; }
.media-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; }
.thumb { aspect-ratio: 16/9; background: var(--surface-2); display: grid; place-items: center; overflow: hidden; color: var(--muted); font-size: .8rem; }
.thumb img, .thumb video { width: 100%; height: 100%; object-fit: cover; display: block; }
.media-card .meta { padding: .55rem .65rem; font-size: .85rem; flex: 1; }
.media-card .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.media-card .acts { display: flex; gap: .25rem; padding: 0 .5rem .5rem; }
.dropzone { border: 2px dashed var(--border); border-radius: var(--radius); padding: 1.5rem; text-align: center; color: var(--muted); margin-bottom: 1rem; transition: .15s; }
.dropzone.over { border-color: var(--accent); background: var(--accent-soft); color: var(--text); }
.progress { height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin-top: .75rem; }
.progress > div { height: 100%; background: var(--accent); width: 0; transition: width .15s; }

/* playlist editor */
.pl-items { list-style: none; margin: 0; padding: 0; }
.pl-item { display: flex; align-items: center; gap: .65rem; padding: .5rem; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); margin-bottom: .5rem; }
.pl-item.dragging { opacity: .4; }
.pl-item.drop-before { box-shadow: 0 -3px 0 var(--accent); }
.pl-item .handle { cursor: grab; color: var(--muted); padding: 0 .25rem; user-select: none; font-size: 1.1rem; }
.pl-item .mini { width: 64px; height: 36px; border-radius: 4px; background: var(--surface-2); overflow: hidden; flex: none; display: grid; place-items: center; font-size: .7rem; color: var(--muted); }
.pl-item .mini img, .pl-item .mini video { width: 100%; height: 100%; object-fit: cover; }
.pl-item .info { flex: 1; min-width: 0; }
.pl-item .info .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pl-item .dur { display: flex; align-items: center; gap: .3rem; font-size: .85rem; color: var(--muted); }
.pl-item .dur input { width: 70px; padding: .3rem .4rem; }
.picker { max-height: 420px; overflow: auto; }
.picker .pick { display: flex; align-items: center; gap: .6rem; padding: .4rem; border-radius: 8px; cursor: pointer; }
.picker .pick:hover { background: var(--surface-2); }

/* schedules */
.slot { border: 1px solid var(--border); border-radius: 8px; padding: .75rem; margin-bottom: .6rem; display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; }
.slot select { flex: 1 1 180px; width: auto; }
.days { display: flex; gap: .2rem; flex-wrap: wrap; }
.days button { padding: .3rem .45rem; font-size: .8rem; min-width: 2.4rem; justify-content: center; }
.days button.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.times { display: flex; align-items: center; gap: .35rem; }
.times input { width: 115px; }
/* menu group (Content ▾) */
.navgroup-head { width: 100%; background: none; border: 0; color: var(--nav-text); padding: .55rem .75rem; border-radius: 8px; display: flex; align-items: center; gap: .6rem; font: inherit; cursor: pointer; text-align: left; }
.navgroup-head:hover { background: rgba(255,255,255,.06); }
.navgroup-head.active { color: var(--nav-active); }
.navgroup-head .caret { margin-left: auto; border: 4px solid transparent; border-top-color: currentColor; margin-top: 4px; transition: transform .15s; }
.navgroup-head[aria-expanded="true"] .caret { transform: rotate(180deg); margin-top: -4px; }
.submenu { display: none; }
.submenu.open { display: block; }
.nav a.sub { padding-left: 2.4rem; font-size: .92rem; }

/* white label */
.brand-icon { display: inline-flex; }
.brand-logo { height: 28px; width: auto; max-width: 120px; object-fit: contain; border-radius: 4px; }
.login .brand-logo { height: 40px; }
.brand-preview { border: 1px solid var(--border); border-radius: 10px; overflow: hidden; align-self: start; }
.bp-nav { display: flex; align-items: center; gap: .6rem; padding: .8rem 1rem; background: var(--nav-bg); color: #fff; }
.bp-nav svg { width: 24px; height: 24px; }
.bp-body { display: flex; gap: .75rem; align-items: center; padding: 1rem; }

/* billing */
.link-cell { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; }
.link-select { width: auto; min-width: 160px; max-width: 240px; padding: .3rem .5rem; font-size: .85rem; }

/* reports */
.day-chart { display: flex; align-items: flex-end; gap: 4px; height: 220px; padding-top: 1.2rem; overflow-x: auto; }
.day-col { flex: 1 0 18px; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; min-width: 18px; }
.day-bar { width: 100%; max-width: 46px; background: var(--accent); border-radius: 4px 4px 0 0; min-height: 2px; }
.day-val { font-size: .72rem; color: var(--muted); margin-bottom: 2px; }
.day-lbl { font-size: .72rem; color: var(--muted); margin-top: 4px; white-space: nowrap; }

/* channels */
.check-list { display: flex; flex-direction: column; gap: .25rem; margin-bottom: .75rem; }
.check-row { display: flex; align-items: center; gap: .6rem; padding: .5rem .6rem; border: 1px solid var(--border); border-radius: 8px; font-weight: 400; margin: 0; cursor: pointer; }
.check-row:hover { background: var(--surface-2); }

/* widgets */
.widget-gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: .9rem; }
.widget-type { display: flex; flex-direction: column; align-items: flex-start; gap: .35rem; text-align: left; white-space: normal; padding: 1rem; background: var(--surface); border-radius: var(--radius); }
.widget-type:hover { border-color: var(--accent); }
.wt-icon { font-size: 2rem; line-height: 1; }
.wt-name { font-weight: 700; font-size: 1.05rem; }
.widget-type .btn { margin-top: auto; pointer-events: none; }
.thumb, .pl-item .mini, .picker .mini { position: relative; }
.widget-thumb > div { position: absolute; top: 0; right: 0; bottom: 0; left: 0; }
dialog:has(.widget-dialog) { width: min(920px, calc(100vw - 32px)); }
.widget-dialog { display: grid; grid-template-columns: 1.1fr 1fr; gap: 1.25rem; align-items: start; }
.widget-preview { position: relative; width: 100%; padding-top: 56.25%; border-radius: 8px; overflow: hidden; background: #000; margin-bottom: .4rem; }
.widget-preview > .sw-root, .widget-preview.sw-root { position: absolute; }
@media (max-width: 760px) { .widget-dialog { grid-template-columns: 1fr; } }

/* address search results (weather widget) */
.geo-results { display: flex; flex-direction: column; gap: .25rem; margin-bottom: .5rem; }
.geo-hit { justify-content: flex-start; white-space: normal; text-align: left; font-size: .85rem; }

/* wizard */
.wizard-step { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.step-num { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; background: var(--accent-soft); color: var(--accent); flex: none; }
.wizard-step.done .step-num { background: var(--ok-soft); color: var(--ok); }

/* monitoring */
.uptime-bars { display: flex; align-items: flex-end; gap: 2px; height: 26px; min-width: 150px; }
.uptime-bars span { flex: 1; height: 100%; border-radius: 1px; background: var(--danger); opacity: .85; }
.uptime-bars span.up { background: var(--ok); }
.uptime-bars span.part { background: var(--warn); }
.uptime-bars span.down { height: 15% !important; }
.uptime-bars span.na { background: var(--surface-2); height: 15%; }
.shot-wall { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1rem; }
.shot-tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; text-decoration: none; color: inherit; }
.shot-tile img, .shot-tile .noshot { width: 100%; aspect-ratio: 16/9; object-fit: cover; display: block; background: #000; }
.shot-tile .noshot { display: grid; place-items: center; color: #94a3b8; font-size: .85rem; }
.shot-meta { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem .6rem; padding: .6rem .75rem; }

/* layers editor */
.layers-grid { display: grid; grid-template-columns: minmax(320px, 1fr) minmax(340px, 1fr); gap: 1rem; align-items: start; }
.preview-col { position: sticky; top: 1rem; }
.preview { position: relative; width: 100%; padding-top: 56.25%; background: #000; border-radius: 8px; overflow: hidden; }
.preview.portrait { width: 56.25%; padding-top: 100%; margin: 0 auto; }
.pv-bg { position: absolute; top: 0; right: 0; bottom: 0; left: 0; background: linear-gradient(135deg, #1f2937, #0b1220); }
.pv-video { position: absolute; overflow: hidden; background: #111; }
.pv-video img, .pv-video video { width: 100%; height: 100%; object-fit: cover; display: block; }
.pv-placeholder { position: absolute; top: 0; right: 0; bottom: 0; left: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; color: #94a3b8; font-weight: 600; border: 2px dashed #334155; }
.pv-placeholder small { font-weight: 400; margin-top: .25rem; }
.pv-overlay { position: absolute; top: 0; right: 0; bottom: 0; left: 0; }
.layer-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: .75rem; }
.layer-head h2 { margin: 0; }
.layer-body.off { opacity: .45; pointer-events: none; }
.sub-item { border: 1px solid var(--border); border-radius: 8px; padding: .75rem; margin-bottom: .6rem; }
.colors { display: flex; flex-wrap: wrap; gap: .5rem 1rem; align-items: center; margin-bottom: .75rem; }
.color-in { display: inline-flex; align-items: center; gap: .4rem; font-weight: 400; font-size: .85rem; margin: 0; }
.color-in input[type=color] { width: 34px; height: 28px; padding: 0; border: 1px solid var(--border); border-radius: 6px; background: none; cursor: pointer; }
.chips { display: flex; flex-wrap: wrap; gap: .4rem; }
.switch { position: relative; display: inline-block; width: 44px; height: 24px; margin: 0; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background: var(--border); border-radius: 24px; transition: .15s; }
.switch span::before { content: ""; position: absolute; height: 18px; width: 18px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .15s; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::before { transform: translateX(20px); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (max-width: 900px) {
  .layers-grid { grid-template-columns: 1fr; }
  .preview-col { position: static; }
}

.screenshot { width: 100%; border-radius: 8px; border: 1px solid var(--border); background: #000; display: block; }
.cmds { display: flex; gap: .5rem; flex-wrap: wrap; }
.bulkbar { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; padding: .6rem .75rem; background: var(--accent-soft); border-radius: 8px; margin-bottom: .75rem; }
.bulkbar select { width: auto; flex: 1 1 180px; }

/* Phone layout for parts defined above (kept last so it wins). */
@media (max-width: 760px) {
  .navgroup { display: contents; }
  .navgroup-head { display: none; }
  .submenu, .submenu.open { display: contents; }
  .nav a.sub { padding-left: .65rem; font-size: .9rem; }
  .widget-dialog { grid-template-columns: 1fr; }
}
