:root {
  --bg: #f5f4f1;
  --surface: #ffffff;
  --surface-2: #f9f8f6;
  --text: #1d1b18;
  --muted: #6d6a64;
  --border: #e4e1db;
  --primary: #e8590c;
  --primary-hover: #cf4f0a;
  --primary-soft: #fdeee4;
  --danger: #d63c2f;
  --danger-soft: #fbe9e7;
  --success: #2f9e44;
  --success-soft: #e6f5e9;
  --warning: #e8a10c;
  --sidebar: #1c1b19;
  --sidebar-text: #c9c6c0;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .05), 0 4px 16px rgba(0, 0, 0, .05);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151412;
    --surface: #1f1d1b;
    --surface-2: #262421;
    --text: #edeae5;
    --muted: #a19d96;
    --border: #35322e;
    --primary-soft: #3a2415;
    --danger-soft: #3b1d1a;
    --success-soft: #1a3320;
    --sidebar: #0f0e0d;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; height: 100%; }

body {
  font-family: system-ui, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
}

h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 22px; font-weight: 700; }
h2 { font-size: 17px; font-weight: 650; }
h3 { font-size: 15px; font-weight: 650; }
p { margin: 0; }
a { color: var(--primary); }

.muted { color: var(--muted); }
.ellipsis { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; min-width: 0; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.spacer { flex: 1; }
[hidden] { display: none !important; }

.icon { display: inline-flex; width: 16px; height: 16px; flex: none; }
.icon svg { width: 100%; height: 100%; }

/* ---------- Shell ---------- */

.shell { display: flex; height: 100vh; }

.sidebar {
  width: 232px;
  flex: none;
  display: flex;
  flex-direction: column;
  background: var(--sidebar);
  color: var(--sidebar-text);
  padding: 16px 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  font-size: 18px;
  color: #fff;
  padding: 4px 10px 20px;
}
.brand .icon { width: 22px; height: 22px; color: var(--primary); }
.brand.big { color: var(--text); font-size: 24px; padding: 0 0 4px; justify-content: center; }
.brand.big .icon { width: 28px; height: 28px; }

.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 12px;
  border-radius: 8px;
  color: var(--sidebar-text);
  text-decoration: none;
  font-weight: 500;
}
.nav-link:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.nav-link.active { background: var(--primary); color: #fff; }
.nav-link .icon { width: 18px; height: 18px; }

.sidebar-footer { border-top: 1px solid rgba(255, 255, 255, .08); padding-top: 12px; display: flex; align-items: center; gap: 8px; }
.sidebar-footer .btn { color: var(--sidebar-text); }
.user { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; color: #fff; }
.avatar {
  width: 28px; height: 28px; flex: none;
  border-radius: 50%;
  display: grid; place-items: center;
  background: #3a3734; color: #fff; font-weight: 700; font-size: 13px;
}

.content { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: none; }
#main { flex: 1; overflow: auto; }
.view { max-width: 1280px; margin: 0 auto; padding: 28px 32px 64px; }

@media (max-width: 860px) {
  .sidebar {
    position: fixed; z-index: 50; top: 0; bottom: 0; left: 0;
    transform: translateX(-100%);
    transition: transform .2s ease;
  }
  .nav-open .sidebar { transform: none; box-shadow: 0 0 40px rgba(0, 0, 0, .4); }
  .topbar {
    display: flex; align-items: center; gap: 8px;
    padding: 8px 12px;
    background: var(--sidebar);
  }
  .topbar .brand { padding: 0; font-size: 16px; }
  .topbar .btn { color: #fff; }
  .view { padding: 20px 16px 48px; }
}

/* ---------- Page structure ---------- */

.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 22px;
}
.page-header p { margin-top: 4px; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.back-link { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); text-decoration: none; margin-bottom: 10px; font-weight: 500; }
.back-link:hover { color: var(--text); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.card-header h2, .card-header h3 { flex: 1; min-width: 0; }
.card-body { padding: 18px; }

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; align-items: start; }
.stack > * + * { margin-top: 16px; }

.empty {
  text-align: center;
  padding: 48px 24px;
  border: 1.5px dashed var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
.empty p { margin: 6px 0 16px; }

/* ---------- Stats ---------- */

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 22px; }
.stat {
  display: block;
  padding: 16px 18px;
  text-decoration: none;
  color: inherit;
}
.stat:hover { border-color: var(--primary); }
.stat-label { color: var(--muted); font-size: 13px; display: flex; align-items: center; gap: 8px; }
.stat-value { font-size: 28px; font-weight: 750; margin-top: 4px; }
.stat-value small { font-size: 14px; color: var(--muted); font-weight: 500; }

.steps { margin: 0; padding-left: 20px; }
.steps li { padding: 4px 0; }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 36px;
  padding: 0 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 550;
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: default; }
.btn:focus-visible, .nav-link:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}
.btn-sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn-icon { padding: 0; width: 36px; }
.btn-sm.btn-icon { width: 30px; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(.95); background: var(--danger); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--surface-2); }
.btn-ghost.danger:hover { color: var(--danger); background: var(--danger-soft); }
.btn-block { width: 100%; height: 40px; }
.btn.on { color: var(--warning); }
.btn.on svg { fill: currentColor; }

.actions { display: flex; gap: 2px; justify-content: flex-end; flex-wrap: nowrap; }

/* ---------- Tables ---------- */

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; background: var(--surface-2); }
tr:last-child td { border-bottom: none; }
td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td.shrink { width: 1%; white-space: nowrap; }
tr.dim td:not(.keep) { opacity: .5; }

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12px; font-weight: 600;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--muted);
  white-space: nowrap;
}
.pill.success { background: var(--success-soft); border-color: transparent; color: var(--success); }
.pill.danger { background: var(--danger-soft); border-color: transparent; color: var(--danger); }
.pill.primary { background: var(--primary-soft); border-color: transparent; color: var(--primary); }

.dot { width: 9px; height: 9px; border-radius: 50%; background: #b5b1aa; flex: none; display: inline-block; }
.dot.on { background: var(--success); box-shadow: 0 0 0 3px var(--success-soft); }

/* ---------- Forms ---------- */

input[type=text], input[type=password], input[type=number], input[type=time], input[type=url], select, textarea {
  width: 100%;
  height: 38px;
  padding: 0 11px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
}
textarea { height: auto; padding: 9px 11px; resize: vertical; }
input[type=color] { width: 52px; height: 36px; padding: 2px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); cursor: pointer; }
input[type=color].unset { opacity: .35; }
input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--primary); margin: 0; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 16px; margin: 18px 0 4px; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field.full, .field-check.full { grid-column: 1 / -1; }
.field > label { font-weight: 600; font-size: 13px; }
.field-check { justify-content: flex-end; }
.help { font-size: 12px; color: var(--muted); }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-weight: 500; }
.form-error {
  margin-top: 14px;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--danger-soft);
  color: var(--danger);
  font-weight: 550;
}
.checklist { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 6px 14px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); }

.days { display: flex; gap: 6px; flex-wrap: wrap; }
.day { position: relative; cursor: pointer; }
.day input { position: absolute; opacity: 0; pointer-events: none; }
.day span {
  display: inline-block; min-width: 46px; text-align: center;
  padding: 6px 8px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface);
  font-weight: 600; font-size: 13px; color: var(--muted);
}
.day input:checked + span { background: var(--primary); border-color: var(--primary); color: #fff; }
.day input:focus-visible + span { outline: 2px solid var(--primary); outline-offset: 1px; }

@media (max-width: 640px) {
  .form-grid { grid-template-columns: 1fr; }
}

/* Switch */
.switch { position: relative; display: inline-block; width: 38px; height: 22px; flex: none; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: #c9c5be; transition: background .15s; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0, 0, 0, .25); }
.switch input:checked + span { background: var(--success); }
.switch input:checked + span::after { transform: translateX(16px); }
.switch input:focus-visible + span { outline: 2px solid var(--primary); outline-offset: 2px; }

/* ---------- Dialogs ---------- */

.dialog {
  width: min(560px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  border: none;
  border-radius: 14px;
  padding: 22px 24px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
}
.dialog.wide { width: min(920px, calc(100vw - 32px)); }
.dialog::backdrop { background: rgba(20, 18, 16, .5); }
.dialog-text { margin-top: 10px; color: var(--muted); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
.toolbar { display: flex; gap: 8px; margin: 14px 0; flex-wrap: wrap; align-items: center; }

/* ---------- Toasts ---------- */

#toasts { position: fixed; right: 20px; bottom: 20px; z-index: 1000; display: flex; flex-direction: column; gap: 8px; align-items: flex-end; }
.toast {
  min-width: 220px; max-width: 420px;
  padding: 11px 16px;
  border-radius: 10px;
  background: #23211e; color: #fff;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .25);
  font-weight: 500;
  transition: opacity .3s, transform .3s;
  border-left: 4px solid var(--success);
}
.toast-error { border-left-color: var(--danger); }
.toast-info { border-left-color: var(--primary); }
.toast.hide { opacity: 0; transform: translateY(8px); }
.upload-toast { display: flex; flex-direction: column; gap: 8px; }
.progress { height: 6px; border-radius: 3px; background: rgba(255, 255, 255, .15); overflow: hidden; }
.progress-bar { height: 100%; width: 0; background: var(--primary); transition: width .2s; }

/* ---------- Media ---------- */

.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 14px; }
.dialog .media-grid { max-height: 55vh; overflow: auto; padding: 2px; }
.media-card {
  display: flex; flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  text-align: left;
  padding: 0;
  font: inherit;
  color: inherit;
}
.media-card.selectable { cursor: pointer; }
.media-card.selectable:hover { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-soft); }
.media-thumb { position: relative; aspect-ratio: 16 / 10; background: var(--surface-2); display: grid; place-items: center; overflow: hidden; }
.media-thumb img, .media-thumb video { width: 100%; height: 100%; object-fit: cover; display: block; }
.media-thumb .type { position: absolute; left: 6px; top: 6px; padding: 2px 6px; border-radius: 6px; background: rgba(0, 0, 0, .65); color: #fff; font-size: 11px; font-weight: 600; display: flex; gap: 4px; align-items: center; }
.media-thumb .type .icon { width: 12px; height: 12px; }
.media-thumb.small { width: 64px; aspect-ratio: 4 / 3; border-radius: 6px; border: 1px solid var(--border); flex: none; }
.thumb-empty { color: var(--muted); display: grid; place-items: center; }
.media-name { padding: 8px 10px 2px; font-weight: 550; font-size: 13px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.media-meta { padding: 0 10px 8px; font-size: 12px; color: var(--muted); display: flex; align-items: center; justify-content: space-between; }
.media-field { display: flex; align-items: center; gap: 10px; }
.pick-order:empty { display: none; }
.pick-order {
  position: absolute; top: 6px; right: 6px;
  min-width: 24px; height: 24px; padding: 0 6px;
  border-radius: 12px; background: var(--primary); color: #fff;
  font-weight: 700; font-size: 13px; display: grid; place-items: center;
}
.media-card.picked { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary); }

.image-list { display: flex; flex-direction: column; gap: 6px; }
.image-item { display: flex; align-items: center; gap: 10px; padding: 6px 8px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); }
.image-item .ellipsis { flex: 1; }
.image-num { width: 22px; text-align: center; font-weight: 700; color: var(--muted); }
.media-field .ellipsis { flex: 1; }

.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 26px;
  text-align: center;
  background: var(--surface);
  margin-bottom: 18px;
  transition: border-color .15s, background .15s;
}
.dropzone.over { border-color: var(--primary); background: var(--primary-soft); }
.dropzone .icon { width: 28px; height: 28px; color: var(--muted); margin-bottom: 6px; }

.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--surface); }
.segmented button { border: none; background: transparent; padding: 6px 12px; font: inherit; font-weight: 550; color: var(--muted); cursor: pointer; }
.segmented button.active { background: var(--primary); color: #fff; }

/* ---------- Menu editor ---------- */

.item-row { display: flex; align-items: center; gap: 12px; padding: 10px 18px; border-bottom: 1px solid var(--border); }
.item-row:last-child { border-bottom: none; }
.item-row.soldout .item-main, .item-row.soldout .item-price { opacity: .5; }
.item-thumb { width: 52px; height: 40px; border-radius: 6px; overflow: hidden; background: var(--surface-2); flex: none; display: grid; place-items: center; color: var(--muted); }
.item-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.item-main { flex: 1; min-width: 0; }
.item-name { font-weight: 600; }
.item-desc { font-size: 12.5px; color: var(--muted); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.item-price { font-weight: 650; font-variant-numeric: tabular-nums; min-width: 72px; text-align: right; }
.item-toggle { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.card-empty { padding: 16px 18px; color: var(--muted); }

@media (max-width: 720px) {
  .item-row { flex-wrap: wrap; }
  .item-main { flex-basis: calc(100% - 70px); }
}

/* ---------- Playlist editor ---------- */

.editor { display: grid; grid-template-columns: minmax(0, 1fr) 420px; gap: 20px; align-items: start; }
@media (max-width: 1100px) { .editor { grid-template-columns: 1fr; } }
.slide-row { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.slide-row:last-child { border-bottom: none; }
.slide-row.dim .slide-info { opacity: .45; }
.slide-num { width: 22px; text-align: center; color: var(--muted); font-weight: 600; font-variant-numeric: tabular-nums; }
.slide-type { width: 36px; height: 36px; border-radius: 8px; display: grid; place-items: center; background: var(--primary-soft); color: var(--primary); flex: none; }
.slide-type .icon { width: 18px; height: 18px; }
.slide-info { flex: 1; min-width: 0; }
.slide-title { font-weight: 600; }
.slide-sub { font-size: 12.5px; color: var(--muted); }

.preview-panel { position: sticky; top: 16px; }
.preview-box { background: #000; border-radius: 8px; overflow: hidden; margin: 0 auto; }
.preview-box.landscape { aspect-ratio: 16 / 9; width: 100%; }
.preview-box.portrait { aspect-ratio: 9 / 16; width: 56%; }
.preview-box iframe { width: 100%; height: 100%; border: 0; display: block; }

.type-picker { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-top: 16px; }
.type-option {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 14px; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--surface);
  text-align: left; font: inherit; color: inherit; cursor: pointer;
}
.type-option:hover { border-color: var(--primary); background: var(--primary-soft); }
.type-option strong { display: block; margin-bottom: 2px; }
.type-option .slide-type { width: 40px; height: 40px; }

/* ---------- Video walls ---------- */

.wall-grid { display: grid; gap: 6px; max-width: 420px; }
.wall-cell {
  aspect-ratio: 16 / 9;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  padding: 4px 8px;
  border: 1.5px dashed var(--border);
  border-radius: 6px;
  background: var(--surface-2);
  font-size: 12.5px; font-weight: 600;
  min-width: 0;
}
.wall-cell.filled { border-style: solid; border-color: var(--primary); background: var(--primary-soft); }
.wall-pick { display: grid; gap: 10px; }
.wall-pick-cell {
  display: flex; flex-direction: column; gap: 6px;
  padding: 10px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface-2);
  font-size: 12px; font-weight: 600; color: var(--muted);
}
.wall-preview { display: grid; background: #2a2a2a; padding: 6px; border-radius: 8px; }
.wall-preview iframe { width: 100%; height: 100%; border: 0; background: #000; display: block; }

/* ---------- Login ---------- */

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: min(380px, 100%);
  display: flex; flex-direction: column; gap: 14px;
  padding: 32px 28px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  text-align: center;
}
.login-card label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: 13px; text-align: left; }
.login-card .form-error { margin: 0; }

/* ---------- Misc ---------- */

.url-box { display: flex; gap: 8px; align-items: center; padding: 10px 12px; border-radius: 8px; background: var(--surface-2); border: 1px solid var(--border); font-family: Consolas, "Roboto Mono", monospace; font-size: 13.5px; word-break: break-all; }
.url-box code { flex: 1; }
.notice { padding: 12px 14px; border-radius: 8px; background: var(--primary-soft); color: var(--text); font-size: 13.5px; }
ol.compact { margin: 8px 0 0; padding-left: 20px; }
ol.compact li { padding: 2px 0; }
