:root {
  color-scheme: light;
  --page: #e9f0fb;
  --shell: #f8fafc;
  --surface: #ffffff;
  --surface-soft: #f3f6fb;
  --ink: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --accent: #2f7df6;
  --accent-strong: #1f6feb;
  --accent-soft: #86b7ff;
  --green: #1f9d62;
  --amber: #b7791f;
  --red: #d14343;
  --shadow: 0 22px 70px rgba(37, 63, 96, .14);
}

body.dark {
  color-scheme: dark;
  --page: #000000;
  --shell: #050505;
  --surface: #0a0a0a;
  --surface-soft: #101010;
  --ink: #f7f7f7;
  --muted: #a3a3a3;
  --line: #232323;
  --shadow: 0 24px 80px rgba(0, 0, 0, .72);
}

body[data-accent="blue"] {
  --accent: #2f7df6;
  --accent-strong: #1f6feb;
  --accent-soft: #86b7ff;
}

body[data-accent="violet"] {
  --accent: #8b5cf6;
  --accent-strong: #7c3aed;
  --accent-soft: #c4b5fd;
}

body[data-accent="green"] {
  --accent: #18a058;
  --accent-strong: #128046;
  --accent-soft: #86efac;
}

body[data-accent="coral"] {
  --accent: #f06449;
  --accent-strong: #dc4a31;
  --accent-soft: #f8b4a4;
}

body[data-accent="gold"] {
  --accent: #d99a1e;
  --accent-strong: #b7791f;
  --accent-soft: #f6d365;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--page);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, input, textarea, select { font: inherit; }

button {
  min-height: 42px;
  border: 0;
  border-radius: 14px;
  background: var(--accent);
  color: white;
  padding: 0 16px;
  font-weight: 800;
  cursor: pointer;
}

button:hover { background: var(--accent-strong); }
button.secondary { background: #222b3a; }
button.ghost, .icon-button { background: var(--surface); color: var(--ink); border: 1px solid var(--line); }
button.danger { background: var(--red); }

input, textarea, select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  color: var(--ink);
  padding: 10px 13px;
  outline: none;
}

input:focus, textarea:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent);
}

textarea {
  min-height: 150px;
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(420px, 100%);
  display: grid;
  gap: 16px;
  padding: 34px;
  border-radius: 28px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.login-card h1, .login-card p { margin: 0; }
.login-card p { color: var(--muted); }
.form-error { min-height: 20px; color: var(--red) !important; font-weight: 700; }

.brand-mark {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 15px;
  background: linear-gradient(135deg, var(--accent-soft), var(--accent-strong));
  color: white;
  font-weight: 950;
  letter-spacing: 0;
}

.app-shell {
  width: min(1800px, calc(100vw - 48px));
  min-height: calc(100vh - 48px);
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 0;
  margin: 24px auto;
  border-radius: 28px;
  background: var(--shell);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.sidebar {
  display: grid;
  align-content: start;
  gap: 24px;
  padding: 26px;
  background: var(--surface);
  border-right: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand strong, .brand span { display: block; }
.brand strong { font-size: 20px; }
.brand span { color: var(--muted); font-size: 13px; }

.nav {
  display: grid;
  gap: 8px;
}

.nav button {
  justify-content: flex-start;
  text-align: left;
  background: transparent;
  color: var(--muted);
}

.nav button.active {
  background: var(--surface-soft);
  color: var(--ink);
  box-shadow: inset 4px 0 0 var(--accent);
}

.content {
  min-width: 0;
  padding: 26px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: center;
  margin-bottom: 24px;
}

.topbar p, .topbar h1, .panel h2, .panel p { margin: 0; }
.topbar p { color: var(--muted); font-weight: 800; }
.topbar h1 { font-size: clamp(28px, 4vw, 42px); letter-spacing: 0; }

.top-actions, .section-actions, .filters, .actions {
  display: flex;
  align-items: end;
  gap: 12px;
  flex-wrap: wrap;
}

.top-actions input { width: min(420px, 32vw); }

.view { display: none; }
.view.active { display: block; }

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 16px;
  margin: 18px 0 22px;
}

.device-status-panel {
  margin-bottom: 18px;
}

.status-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}

.status-card {
  display: grid;
  gap: 10px;
  min-height: 154px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface-soft);
}

.status-card h3 {
  margin: 0;
  font-size: 18px;
}

.status-card .actions {
  margin-top: auto;
}

.metric, .panel, .card, .qr-panel, .table {
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--surface);
}

.metric {
  padding: 20px;
}

.metric span {
  color: var(--muted);
  font-weight: 800;
  font-size: 13px;
}

.metric strong {
  display: block;
  margin-top: 9px;
  font-size: clamp(28px, 4vw, 42px);
  letter-spacing: 0;
}

.chart-grid {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(320px, 1fr);
  gap: 18px;
}

.panel {
  padding: 22px;
  overflow: hidden;
}

.panel.wide { min-height: 340px; }
.panel-heading {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
  margin-bottom: 18px;
}

.panel-heading span, .panel p { color: var(--muted); }

.bar-chart {
  min-height: 230px;
  display: grid;
  grid-template-columns: repeat(var(--count, 7), 1fr);
  gap: 12px;
  align-items: end;
}

.bar {
  display: grid;
  gap: 8px;
  align-items: end;
  min-width: 0;
}

.bar-fill {
  min-height: 8px;
  border-radius: 999px 999px 10px 10px;
  background: linear-gradient(180deg, var(--accent), var(--accent-soft));
}

.bar label, .bar small {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.day-chart {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 8px;
}

.day-cell {
  display: grid;
  place-items: center;
  gap: 2px;
  min-height: 54px;
  border-radius: 12px;
  background: var(--surface-soft);
  color: var(--muted);
  font-weight: 800;
}
.day-cell .day-num { font-size: 11px; opacity: .7; }
.day-cell .day-val { font-size: 16px; }

.hour-chart {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
}

.hour-cell {
  display: grid;
  place-items: center;
  min-height: 42px;
  border-radius: 12px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.device-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(270px, 1fr));
  gap: 16px;
  margin: 18px 0;
}

.card {
  display: grid;
  gap: 12px;
  padding: 18px;
}

.card h3 { margin: 0; }
.meta { display: grid; gap: 6px; color: var(--muted); font-size: 13px; }
.subtle, .hint {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.hint {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface-soft);
  font-weight: 700;
}

.badge {
  width: fit-content;
  border-radius: 999px;
  padding: 5px 10px;
  color: white;
  background: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.badge.online { background: var(--green); }
.badge.warn { background: var(--amber); }
.badge.archived { background: var(--red); }

.swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.swatch {
  display: grid;
  grid-template-columns: 28px auto;
  align-items: center;
  gap: 9px;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface-soft);
  color: var(--ink);
  padding: 0 13px 0 9px;
}

.swatch:hover {
  background: var(--surface-soft);
}

.swatch.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}

.swatch-dot {
  width: 24px;
  height: 24px;
  border-radius: 999px;
  background: var(--swatch-color);
}

.inline-form, .qr-panel, .settings-grid {
  display: grid;
  gap: 12px;
  margin-top: 16px;
}

.inline-form {
  grid-template-columns: repeat(3, minmax(160px, 1fr)) auto auto;
}

.qr-panel {
  grid-template-columns: minmax(220px, 1fr) 220px minmax(260px, 1fr);
  padding: 18px;
  align-items: start;
}

.qr-panel img {
  width: 220px;
  height: 220px;
  border: 1px solid var(--line);
  border-radius: 18px;
}

.detail-panel {
  margin-top: 18px;
}

.detail-grid, .settings-grid {
  grid-template-columns: minmax(300px, 420px) 1fr;
}

.settings-panel {
  display: grid;
  gap: 16px;
}

.stack-form {
  display: grid;
  gap: 12px;
}

.warning {
  padding: 12px;
  border-radius: 14px;
  background: rgba(183, 121, 31, .12);
  color: var(--amber);
  font-weight: 800;
}

.table {
  margin-top: 16px;
  overflow: auto;
}

table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
}

.compact-table table { min-width: 0; }

th, td {
  padding: 13px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.empty {
  padding: 24px;
  color: var(--muted);
  text-align: center;
}

#toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  max-width: 380px;
  padding: 13px 15px;
  border-radius: 16px;
  background: var(--ink);
  color: var(--surface);
  box-shadow: var(--shadow);
  transform: translateY(90px);
  opacity: 0;
  transition: .18s ease;
}

#toast.show {
  transform: translateY(0);
  opacity: 1;
}

@media (max-width: 1000px) {
  .app-shell {
    width: 100%;
    min-height: 100vh;
    margin: 0;
    border-radius: 0;
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .nav, .metric-grid, .chart-grid, .detail-grid, .settings-grid, .inline-form, .qr-panel {
    grid-template-columns: 1fr;
  }

  .topbar {
    display: grid;
  }

  .top-actions input {
    width: 100%;
  }
}

/* Remote administration: printer panel, artwork, settings form */
.section-title {
  margin: 22px 0 10px;
  font-size: 15px;
  font-weight: 800;
  letter-spacing: .02em;
}

.badge-row, .badge-row .badge { display: inline-flex; }
.badge-row { display: flex; flex-wrap: wrap; gap: 8px; }
.badge.badge-ok { background: var(--green); }
.badge.badge-bad { background: var(--red); }
.badge.badge-muted { background: var(--muted); }

.printer-panel, .artwork-panel {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px 16px;
  background: var(--surface-soft);
  margin-top: 14px;
}
.printer-panel .actions { margin-top: 12px; }

.artwork-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.artwork-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.artwork-head { display: flex; justify-content: space-between; align-items: center; font-weight: 700; }
.artwork-thumb {
  min-height: 92px;
  border-radius: 8px;
  background: var(--surface-soft);
  border: 1px dashed var(--line);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.artwork-thumb img { width: 100%; height: auto; display: block; }
.artwork-actions { display: flex; gap: 8px; align-items: center; }
.upload-btn {
  display: inline-block;
  cursor: pointer;
  background: var(--accent);
  color: #fff;
  border-radius: 10px;
  padding: 8px 14px;
  font-weight: 700;
  font-size: 14px;
}
.upload-btn:hover { background: var(--accent-strong); }

.settings-form { display: grid; gap: 14px; }
.settings-group {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 16px 16px;
  margin: 0;
}
.settings-group legend { padding: 0 6px; font-weight: 800; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .08em; }
.settings-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 18px; }
.field-line { display: flex; flex-direction: column; gap: 4px; font-size: 14px; }
.field-line input, .field-line select { width: 100%; }
.field-toggle { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.field-toggle input { width: 18px; height: 18px; }
.field-multi { grid-column: 1 / -1; display: flex; flex-direction: column; gap: 6px; }
.field-multi-label { font-size: 14px; font-weight: 600; }
.field-multi-options { display: flex; flex-wrap: wrap; gap: 8px 18px; }

.advanced-json { margin-top: 14px; }
.advanced-json summary { cursor: pointer; color: var(--muted); font-weight: 700; }
.advanced-json textarea { margin-top: 8px; }

@media (max-width: 720px) {
  .settings-fields { grid-template-columns: 1fr; }
  .artwork-row { grid-template-columns: 1fr; }
}
