:root {
  --bg: #0f1117;
  --panel: #171a23;
  --panel-2: #1e222d;
  --line: #262a36;
  --text: #e7e9ee;
  --dim: #8a90a0;
  --accent: #7c6cf6;
  --accent-hover: #8d7ff8;
  --on: #3ecf8e;
  --off: #6b7280;
  --warn: #f2b84b;
  --danger: #ef6b6b;
  --r: 12px;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

h1, h2, p { margin: 0; }
button, input { font: inherit; }
a { color: inherit; text-decoration: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.dim { color: var(--dim); font-size: 13px; }

/* Shell */
.app { display: flex; min-height: 100vh; }
.side {
  width: 220px;
  flex: none;
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 20px 14px;
}
.side-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.logo { font-weight: 700; font-size: 15px; }
.logo i { color: var(--accent); font-style: normal; }
.logo-lg { font-size: 18px; margin-bottom: 18px; }
.menu-toggle { display: none; background: none; border: 1px solid var(--line); border-radius: 8px; color: var(--text); padding: 4px 10px; cursor: pointer; }
.side-nav { display: flex; flex-direction: column; gap: 3px; }
.nav {
  display: block;
  width: 100%;
  padding: 8px 11px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--dim);
  text-align: left;
  cursor: pointer;
}
.nav:hover { color: var(--text); background: var(--panel-2); }
.nav.on { background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--text); }
.nav-logout { margin-top: 14px; }
.main { flex: 1; min-width: 0; padding: 26px 28px; }

.top { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 18px; }
.title { font-size: 21px; font-weight: 600; }

/* Buttons */
.btn {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 8px;
  padding: 8px 14px;
  font-weight: 600;
  font-size: 13px;
  text-align: center;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--accent-hover); }
.btn:disabled { opacity: .45; cursor: not-allowed; background: var(--accent); }
.btn-wide { display: block; width: 100%; margin-top: 16px; padding: 10px 14px; }
.btn-danger-solid { background: var(--danger); }
.btn-danger-solid:hover { background: #f38484; }
.btn-s {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 5px 10px;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
}
.btn-s:hover { border-color: var(--dim); }
.btn-s:disabled { opacity: .4; cursor: not-allowed; border-color: var(--line); }
.btn-danger { color: var(--danger); }

/* Banners */
.banner {
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 40%, transparent);
  border-radius: 10px;
  padding: 10px 14px;
  margin-bottom: 14px;
  font-size: 13px;
}
.banner-warn {
  background: color-mix(in srgb, var(--warn) 12%, transparent);
  border-color: color-mix(in srgb, var(--warn) 40%, transparent);
  color: var(--warn);
}

/* Stats */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 18px; }
.s { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 13px 16px; min-width: 0; }
.s small { color: var(--dim); display: block; font-size: 12px; margin-bottom: 2px; }
.s b { font-size: 21px; font-weight: 600; }

/* Table */
.tb {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r);
  overflow: hidden;
}
.tb th { color: var(--dim); font-weight: 500; font-size: 12px; text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.tb td { padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tb tbody tr:last-child td { border-bottom: 0; }
.tb tbody tr:hover td { background: color-mix(in srgb, var(--panel-2) 60%, transparent); }
.th-actions { text-align: right !important; }
.cell-name { max-width: 300px; overflow-wrap: anywhere; }
.cell-actions { text-align: right; }
.cell-actions .btn-s { margin: 2px 0 2px 5px; }
.row-empty td { text-align: center; color: var(--dim); padding: 32px 14px; }

.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--on); margin-right: 8px; }
.dot.x { background: var(--off); }
.tag { display: inline-block; font-size: 11.5px; padding: 2px 8px; border-radius: 20px; background: color-mix(in srgb, var(--on) 18%, transparent); color: var(--on); white-space: nowrap; }
.tag.x { background: color-mix(in srgb, var(--off) 25%, transparent); color: var(--dim); }
.row-note { display: block; margin-top: 4px; color: var(--warn); font-size: 11.5px; }
.tag-ext { margin-left: 8px; background: color-mix(in srgb, var(--accent) 20%, transparent); color: #b3a9fb; }

/* Modals */
.modal {
  position: fixed;
  inset: 0;
  z-index: 10;
  background: rgba(5, 6, 10, .65);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  overflow-y: auto;
}
.dialog {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 22px;
  width: 100%;
  max-width: 400px;
  margin: auto;
}
.dialog h2 { font-size: 17px; font-weight: 600; margin-bottom: 8px; overflow-wrap: anywhere; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.dialog-actions .btn-s { padding: 8px 14px; font-size: 13px; }
.qr { background: #fff; border-radius: 10px; padding: 12px; margin-top: 14px; }
.qr img { display: block; width: 100%; height: auto; min-height: 120px; }

.field { display: block; margin-top: 14px; }
.field span { display: block; color: var(--dim); font-size: 12px; margin-bottom: 5px; }
.field input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  padding: 9px 11px;
}
.field input:focus { outline: 0; border-color: var(--accent); }
.form-error { color: var(--danger); font-size: 13px; margin-top: 12px; }

/* Login and enrollment */
.auth { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 28px; width: 100%; max-width: 380px; }
.card h1 { font-size: 19px; font-weight: 600; margin-bottom: 6px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  z-index: 20;
  max-width: calc(100vw - 32px);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 13px;
}

@media (max-width: 768px) {
  .app { display: block; }
  .side { width: auto; border-right: 0; border-bottom: 1px solid var(--line); padding: 12px 16px; }
  .side-top { margin-bottom: 0; }
  .menu-toggle { display: block; }
  .side-nav { display: none; margin-top: 10px; }
  .side.open .side-nav { display: flex; }
  .main { padding: 16px; }
  .stats { grid-template-columns: 1fr 1fr; gap: 8px; }
  .s:first-child { grid-column: 1 / -1; }
  .s b { font-size: 18px; }
}

/* The sidebar is still present down to 769 px, so the table needs its list form earlier. */
@media (max-width: 960px) {
  .tb, .tb tbody, .tb tr, .tb td { display: block; width: 100%; }
  .tb { background: none; border: 0; border-radius: 0; overflow: visible; }
  .tb thead { display: none; }
  .tb tbody tr { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 6px 14px; margin-bottom: 10px; }
  .tb tbody tr:hover td { background: none; }
  .tb td, .tb tbody tr:last-child td { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 7px 0; border-bottom: 1px solid var(--line); text-align: right; overflow-wrap: anywhere; }
  .tb td::before { content: attr(data-label); color: var(--dim); font-size: 12px; flex: none; }
  .tb td.cell-name { max-width: none; justify-content: flex-start; font-weight: 600; text-align: left; }
  .tb td.cell-name::before { content: none; }
  .tb td.cell-name .tag-ext { margin-left: auto; font-weight: 400; }
  .tb td.cell-name .dot { flex: none; margin-right: 0; }
  .tb td.cell-actions { border-bottom: 0; justify-content: flex-end; flex-wrap: wrap; white-space: normal; padding-top: 10px; }
  .tb td.cell-actions::before { content: none; }
  .cell-actions .btn-s { margin: 0; padding: 7px 11px; }
  .row-empty td { justify-content: center !important; }
  .row-empty td::before { content: none !important; }
}

/* Overview, backups, audit, settings */
.section { font-size: 15px; font-weight: 600; margin: 22px 0 10px; }
.top-sub { margin-top: 22px; }
.top-sub .section { margin: 0; }
.note { margin: 8px 0 14px; font-size: 13px; }
.filter { display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; }
.field-inline span { display: block; color: var(--dim); font-size: 12px; margin-bottom: 5px; }
.filter select {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  padding: 8px 11px;
  min-width: 220px;
}
.filter .btn-s { padding: 9px 14px; }
.tb td.wrap { overflow-wrap: anywhere; max-width: 280px; }
.plan { list-style: none; margin: 10px 0 0; padding: 0; font-size: 13px; }
.plan li { margin-bottom: 8px; }
.plan code { display: inline-block; margin: 2px 4px 0 0; padding: 1px 6px; background: var(--bg); border-radius: 6px; font-size: 12px; }
@media (max-width: 960px) {
  .tb td.wrap { max-width: none; }
}
