:root {
  --bg: #f3f5f7;
  --panel: #ffffff;
  --ink: #1c2430;
  --ink-soft: #5b6675;
  --line: #e2e6ec;
  --sidebar: #131b2b;
  --sidebar-ink: #c7cfdb;
  --sidebar-ink-active: #ffffff;
  --accent: #2f6f6b;
  --accent-ink: #ffffff;
  --ok: #2e7d5b;
  --warn: #c98a2c;
  --bad: #c1483d;
  --radius: 10px;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html.dark {
  --bg: #0f1420;
  --panel: #171f30;
  --ink: #e8ecf3;
  --ink-soft: #8b96a8;
  --line: #2a3448;
  --sidebar: #0a0f1a;
}

html.dark .field input,
html.dark select,
html.dark textarea {
  background: #10182a;
  color: var(--ink);
  border-color: var(--line);
}

html.dark .thumb-card img,
html.dark .order-row img,
html.dark .pick-row img {
  background: #232d42;
}

/* ---------- Settings sub-tabs ---------- */

.subtabs { display: flex; gap: 4px; margin-bottom: 20px; border-bottom: 1px solid var(--line); }
.subtab {
  padding: 9px 16px; cursor: pointer; font-size: 13px; color: var(--ink-soft);
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.subtab:hover { color: var(--ink); }
.subtab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

.swatch-row { display: flex; gap: 8px; margin: 8px 0 4px; flex-wrap: wrap; }
.swatch {
  width: 28px; height: 28px; border-radius: 6px; cursor: pointer; border: 2px solid transparent;
}
.swatch.selected { border-color: var(--ink); }

.role-badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11px; font-weight: 600; }
.role-badge.administrator { background: #e6dff5; color: #6a3fb5; }
.role-badge.content_manager { background: #d9efe8; color: #1f7a5c; }
.role-badge.operator { background: #fdecd2; color: #a8650f; }
.role-badge.viewer { background: var(--line); color: var(--ink-soft); }
html.dark .role-badge.administrator { background: #2c2043; color: #c9aef0; }
html.dark .role-badge.content_manager { background: #163429; color: #7fd6b4; }
html.dark .role-badge.operator { background: #3a2a10; color: #f0b25e; }

/* ---------- Schedule calendar ---------- */

.cal-dow-row { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin-bottom: 6px; }
.cal-dow { text-align: center; font-size: 11px; font-weight: 600; color: var(--ink-soft); text-transform: uppercase; letter-spacing: 0.03em; }
.cal-cells { display: grid; grid-template-columns: repeat(7, 1fr); grid-auto-rows: minmax(92px, auto); gap: 6px; }
.cal-cell { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 6px; overflow: hidden; }
.cal-cell-outside { opacity: 0.4; }
.cal-cell-today { border-color: var(--accent); border-width: 2px; }
.cal-daynum { font-size: 12px; font-weight: 600; margin-bottom: 4px; }
.cal-chips { display: flex; flex-direction: column; gap: 3px; }
.cal-chip {
  font-size: 10px; padding: 2px 5px; border-radius: 4px; background: var(--accent); color: #fff;
  cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.cal-chip:hover { filter: brightness(1.1); }
.cal-chip-paused { background: var(--line); color: var(--ink-soft); }

.device-name-link { color: var(--ink); text-decoration: none; border-bottom: 1px dashed var(--ink-soft); }
.device-name-link:hover { color: var(--accent); border-bottom-color: var(--accent); }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.45;
}

button, input, select, textarea { font-family: inherit; font-size: inherit; }

a { color: var(--accent); text-decoration: none; }

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

.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 40px;
  width: 320px;
  box-shadow: 0 12px 32px rgba(19, 27, 43, 0.08);
}

.login-mark {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 24px;
}

.login-mark .dot { width: 12px; height: 12px; border-radius: 50%; background: var(--accent); }
.login-mark span { font-weight: 700; letter-spacing: 0.02em; font-size: 16px; }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12px; color: var(--ink-soft); margin-bottom: 5px; }
.field input {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fbfcfd;
}
.field input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: 7px;
  padding: 9px 16px;
  background: var(--accent);
  color: var(--accent-ink);
  cursor: pointer;
  font-weight: 600;
}
.btn:hover { filter: brightness(1.08); }
.btn:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.btn.secondary { background: var(--panel); color: var(--ink); border: 1px solid var(--line); }
.btn.danger { background: var(--bad); }
.btn.full { width: 100%; }
.btn:disabled { opacity: 0.6; cursor: default; }

.error-msg { color: var(--bad); font-size: 13px; margin: 8px 0 0; min-height: 16px; }

/* ---------- App shell ---------- */

.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 216px;
  flex-shrink: 0;
  background: var(--sidebar);
  color: var(--sidebar-ink);
  display: flex;
  flex-direction: column;
  padding: 18px 12px;
}

.sidebar .mark { display: flex; align-items: center; gap: 9px; padding: 6px 10px 20px; }
.sidebar .mark .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }
.sidebar .mark span { color: #fff; font-weight: 700; font-size: 14px; letter-spacing: 0.01em; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 7px;
  cursor: pointer;
  margin-bottom: 2px;
  color: var(--sidebar-ink);
  font-size: 13px;
}
.nav-item:hover { background: rgba(255,255,255,0.06); }
.nav-item.active { background: var(--accent); color: var(--sidebar-ink-active); font-weight: 600; }

.sidebar-footer { margin-top: auto; padding: 10px; font-size: 12px; color: #7c8698; }
.sidebar-footer .who { color: #dfe4ec; margin-bottom: 6px; }

.main {
  flex: 1;
  min-width: 0;
  padding: 26px 32px 60px;
}

.page-header { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 20px; }
.page-header h1 { font-size: 20px; margin: 0; }
.page-header .sub { color: var(--ink-soft); font-size: 13px; margin-top: 3px; }

/* ---------- Cards / grid ---------- */

.grid { display: grid; gap: 16px; }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
}

.stat .label { color: var(--ink-soft); font-size: 12px; margin-bottom: 6px; }
.stat .value { font-size: 26px; font-weight: 700; }
.stat .value.ok { color: var(--ok); }
.stat .value.bad { color: var(--bad); }

.card h2 { font-size: 14px; margin: 0 0 12px; }

/* ---------- Table ---------- */

table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--ink-soft); padding: 8px 10px; border-bottom: 1px solid var(--line); }
td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
.table-wrap { overflow-x: auto; }

.status-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; margin-right: 7px; }
.status-dot.ok { background: var(--ok); }
.status-dot.bad { background: var(--bad); }
.status-dot.warn { background: var(--warn); }

.pill { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11px; background: var(--line); color: var(--ink-soft); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }

.actions-row { display: flex; gap: 8px; margin-bottom: 16px; justify-content: flex-end; }

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

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(19,27,43,0.45);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
.modal {
  background: var(--panel); border-radius: var(--radius); padding: 24px;
  width: 460px; max-width: 92vw; max-height: 88vh; overflow-y: auto;
}
.modal h2 { margin-top: 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

.hint { color: var(--ink-soft); font-size: 12px; margin-top: 4px; }
.empty-state { color: var(--ink-soft); padding: 30px; text-align: center; }

/* ---------- Content library / playlist builder ---------- */

.thumb-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 12px; }
.thumb-card { border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--panel); }
.thumb-card img { width: 100%; height: 90px; object-fit: cover; display: block; background: #eef0f3; }
.thumb-card .meta { padding: 8px; font-size: 11px; }
.thumb-card .meta .name { font-weight: 600; font-size: 12px; margin-bottom: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.builder { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.pick-list, .order-list { border: 1px solid var(--line); border-radius: 8px; padding: 10px; max-height: 420px; overflow-y: auto; }
.pick-row, .order-row {
  display: flex; align-items: center; gap: 10px; padding: 7px 8px; border-radius: 6px;
}
.pick-row:hover { background: #f5f7f9; }
.order-row { background: #f9fafb; margin-bottom: 6px; }
.order-row img, .pick-row img { width: 40px; height: 30px; object-fit: cover; border-radius: 4px; background: #eef0f3; }
.order-row .dur { width: 60px; padding: 4px 6px; border: 1px solid var(--line); border-radius: 5px; }
.order-row .grip { cursor: grab; color: var(--ink-soft); }

select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 7px; background: #fbfcfd;
}

.checkbox-row { display: flex; align-items: center; gap: 8px; margin: 10px 0; }

.badge-count { background: var(--accent); color: #fff; border-radius: 999px; font-size: 10px; padding: 1px 6px; margin-left: auto; }

/* ---------- Media type indicators ---------- */

.type-badge {
  position: absolute; top: 4px; right: 4px; background: rgba(0,0,0,0.65); color: #fff;
  font-size: 9px; font-weight: 700; letter-spacing: 0.04em; padding: 2px 6px; border-radius: 4px;
}
.mini-audio {
  width: 40px; height: 30px; border-radius: 4px; background: #232d42; color: #9aa5b6;
  display: flex; align-items: center; justify-content: center; font-size: 15px; flex-shrink: 0;
}
.order-row video { width: 40px; height: 30px; object-fit: cover; border-radius: 4px; background: #111; }
.pick-row video { width: 40px; height: 30px; object-fit: cover; border-radius: 4px; background: #111; }
.mini-check { display: flex; align-items: center; gap: 4px; font-size: 11px; color: var(--ink-soft); white-space: nowrap; }

/* ---------- Device mode / remote control ---------- */

.mode-badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 10px; font-weight: 600; background: var(--line); color: var(--ink-soft); }
.mode-badge.web_app { background: #ded6f7; color: #6a3fb5; }
html.dark .mode-badge.web_app { background: #2c2043; color: #c9aef0; }

.remote-controls { display: flex; align-items: center; gap: 6px; justify-content: center; }
.remote-controls button {
  width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--line); background: var(--panel);
  cursor: pointer; font-size: 15px; display: flex; align-items: center; justify-content: center; color: var(--ink);
}
.remote-controls button:hover { border-color: var(--accent); color: var(--accent); }
.remote-controls button.primary { width: 44px; height: 44px; background: var(--accent); color: #fff; border: none; }
