:root {
  color-scheme: light dark;
  --bg: #0f1115;
  --panel: #171a21;
  --border: #2a2e37;
  --text: #e6e8eb;
  --muted: #9aa2af;
  --accent: #4f8cff;
  --danger: #e5534b;
  --ok: #3fb950;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, Segoe UI, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

header {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

header nav a {
  color: var(--muted);
  text-decoration: none;
  margin-left: 1.25rem;
}

header nav a:hover { color: var(--text); }

.brand { display: flex; align-items: center; gap: 0.6rem; font-weight: 600; }
.brand img { height: 28px; width: 28px; object-fit: cover; border-radius: 6px; }

main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 1.5rem;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 0.5rem 0.6rem; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 500; font-size: 0.85rem; white-space: nowrap; }

/* A table with enough columns (e.g. the Users table) doesn't fit a
   narrow viewport — rather than let it grow past its container and
   force a horizontal scrollbar, action buttons wrap onto their own
   lines instead (see .actions-stack) so the table itself never needs
   to be wider than its container. overflow-x here is just a safety
   net for extreme cases, not the normal path. */
.table-scroll { overflow-x: auto; }
.table-scroll table { width: 100%; }

.badge {
  display: inline-block;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
}
.badge.ok { background: rgba(63,185,80,.15); color: var(--ok); }
.badge.off { background: rgba(154,162,175,.15); color: var(--muted); }
.badge.live { background: rgba(79,140,255,.15); color: var(--accent); }
.badge.danger { background: rgba(229,83,75,.15); color: var(--danger); }

input, button, select {
  font: inherit;
  padding: 0.5rem 0.7rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #0f1115;
  color: var(--text);
}

button {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  cursor: pointer;
}
button.danger { background: var(--danger); border-color: var(--danger); }
button.secondary { background: transparent; color: var(--text); }

form.inline { display: inline; }

.row { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }

.actions-stack { display: flex; flex-direction: row; flex-wrap: wrap; gap: 0.35rem; align-items: center; }
.actions-stack form { display: block; }
.actions-stack button { white-space: nowrap; }

/* Username + badges ("админ", "(вы)") on one line — a short label that
   should never itself be the reason the table needs to scroll. */
.user-name-cell { white-space: nowrap; }

/* Per-user device list (dashboard.html): a <details> popout rather than
   its own dashboard column so it doesn't widen the Users table for
   accounts with zero or one device — the common case. */
details summary { cursor: pointer; color: var(--accent); }
details .devices-table {
  margin-top: 0.5rem;
  min-width: 32rem;
}
.devices-table th, .devices-table td { padding: 0.4rem 0.5rem; font-size: 0.9rem; }

/* A plain tap-through menu (Account page): each row is either a bare
   button or a one-button form (Выход needs a POST), so the row border
   lives on the wrapping .menu-row rather than the button itself — that
   way both cases look identical regardless of which one a given row is. */
.menu-list { display: flex; flex-direction: column; }
.menu-row { border-bottom: 1px solid var(--border); }
.menu-row:last-child { border-bottom: none; }
.menu-item, .menu-item-form { width: 100%; }
/* Qualified as "button.menu-item" (not just ".menu-item") so this beats
   the generic button/button.danger rules above on specificity — with a
   bare class, button.danger's background:var(--danger) still won on tie
   and gave a solid-red button with red-on-red (invisible) text. */
button.menu-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  padding: 0.9rem 0.2rem;
  border: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 1rem;
  text-align: left;
  cursor: pointer;
}
button.menu-item:hover { color: var(--accent); }
button.menu-item::after { content: "\203A"; color: var(--muted); font-size: 1.3rem; margin-left: 0.5rem; }
button.menu-item.danger { color: var(--danger); }
button.menu-item.danger::after { content: none; }

pre {
  background: #0b0d11;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
  overflow-x: auto;
  font-size: 0.85rem;
}

.muted { color: var(--muted); font-size: 0.9rem; }
.error { color: var(--danger); }
.success { color: var(--ok); }

a.button-link {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  text-decoration: none;
  padding: 0.5rem 0.9rem;
  border-radius: 6px;
  margin-right: 0.5rem;
}

dialog.modal {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.5rem;
  width: min(480px, 90vw);
  max-height: 85vh;
  overflow-y: auto;
}
dialog.modal::backdrop { background: rgba(0, 0, 0, 0.6); }
dialog.modal h3 { margin-top: 0; margin-bottom: 0.5rem; }
dialog.modal p.muted { margin-top: 0; margin-bottom: 1.1rem; }

/* A column of labeled fields — label above its input, input full-width,
   so fields line up in a straight column regardless of how long each
   label's text is (inline label+input pairs left inputs staggered at
   whatever x position the label text happened to end at). Used for every
   form on this page, inside dialogs or not. */
.form-fields {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.75rem;
  max-width: 480px;
}
.form-fields label {
  display: block;
  font-size: 0.9rem;
  color: var(--muted);
}
.form-fields label input,
.form-fields label select {
  display: block;
  width: 100%;
  margin-top: 0.35rem;
  color: var(--text);
  font-size: 1rem;
}
