:root {
  --bg: #0f1115;
  --panel: #171a21;
  --line: #262b36;
  --text: #e6e9ef;
  --muted: #8b93a3;
  --accent: #4f8cff;
  --error: #ff6b6b;
}

* { box-sizing: border-box; }

/* The canvas itself is dark, so no browser can show a light strip around the
   page when the window is wider than the document box. */
html { background: var(--bg); }

body {
  margin: 0;
  padding: 0 1rem 3rem;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 "Segoe UI", system-ui, sans-serif;
}

.top {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 1rem;
  max-width: 960px;
  margin: 0 auto;
  padding: 1rem 0;
  border-bottom: 1px solid var(--line);
}

nav { display: flex; align-items: center; gap: 1rem; }
nav a { color: var(--text); text-decoration: none; }
nav a:hover { color: var(--accent); }
nav form { margin: 0; }

main { max-width: 960px; margin: 1.5rem auto 0; display: grid; gap: 1rem; }

/* Login and registration are a single card; put it in the middle of the window
   instead of letting it hug the top edge. */
main.centered { min-height: calc(100vh - 5rem); align-content: center; }
main.centered .card { margin-top: 0; margin-bottom: 0; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1.25rem 1.5rem;
}

.card.narrow { width: 100%; max-width: 420px; margin: 2rem auto; }

h1 { font-size: 1.35rem; margin: 0 0 1rem; }
h2 { font-size: 1.05rem; margin: 0 0 .85rem; }

label { display: block; margin-bottom: .85rem; color: var(--muted); font-size: .9rem; }

input,
select {
  display: block;
  width: 100%;
  margin-top: .3rem;
  padding: .55rem .7rem;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
}

input::placeholder { color: #5c6373; }

/* Chrome paints autofilled fields with a light background and dark text, which
   breaks the dark card. An inset shadow covers the fill, the long transition
   keeps Chrome from repainting it, and !important wins over the autofill rule. */
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus,
input:-webkit-autofill:active {
  -webkit-box-shadow: 0 0 0 1000px var(--bg) inset !important;
  -webkit-text-fill-color: var(--text) !important;
  caret-color: var(--text);
  transition: background-color 600000s 0s;
}

/* Focus on a field is shown by the border colour only, so a focused input keeps
   exactly the size of its neighbour — the browser ring made the two login
   fields look like boxes of different sizes. Buttons keep a ring. */
input:focus,
select:focus {
  outline: none;
  border-color: var(--accent);
}

button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.field { margin: 0; }

.field > span { display: block; color: var(--muted); font-size: .9rem; }

.hint { display: block; margin-top: .25rem; color: #6b7386; font-size: .78rem; }

/* Form layout shared by the admin cards and the auth cards: every cell stacks
   label, control and hint, and the submit button takes its own full-width row.
   `.form-grid` uses three columns so a wide form reads as rows of fields
   instead of one cramped line (it collapses to a single column on narrow
   screens); `.form-stack` is the same layout with one column, for the narrow
   login and registration card. */
.form-grid,
.form-stack {
  display: grid;
  gap: 1rem 1.1rem;
  align-items: start;
}

.form-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }

.form-stack { grid-template-columns: minmax(0, 1fr); }

.form-grid .field,
.form-stack .field { display: flex; flex-direction: column; gap: .35rem; }

.form-grid .field input,
.form-grid .field select,
.form-stack .field input,
.form-stack .field select { margin-top: 0; }

.form-grid .hint,
.form-stack .hint { min-height: 1.1em; margin-top: 0; font-size: .78rem; }

.form-grid .submit,
.form-stack .submit { grid-column: 1 / -1; }

.form-grid .submit > span,
.form-stack .submit > span { display: none; }

.form-grid .submit button,
.form-stack .submit button { white-space: nowrap; }

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

button.small { padding: .45rem .8rem; font-size: .85rem; }

button {
  padding: .55rem 1.1rem;
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 8px;
  font: inherit;
  cursor: pointer;
}

button.link {
  background: none;
  color: var(--muted);
  padding: 0;
}

button.link:hover { color: var(--accent); }

form.inline { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 1rem; }
form.inline label { margin: 0; }

table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { text-align: left; padding: .55rem .5rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--muted); font-weight: 500; white-space: nowrap; vertical-align: bottom; }

.limits-table input,
.limits-table select { margin: 0; padding: .4rem .55rem; font-size: .85rem; }
.limits-table td:last-child { width: 1%; white-space: nowrap; }

code { font-family: Consolas, monospace; font-size: .85em; word-break: break-all; }

.facts { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1rem; margin: 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }

.muted { color: var(--muted); }
.error { color: var(--error); margin: 0 0 1rem; }

.messages { list-style: none; margin: 0; padding: .75rem 1rem; border: 1px solid var(--error); border-radius: 10px; color: var(--error); }

/* Flashed messages show up as toasts in the corner: green for a success,
   red for a refusal, and they fade away on their own. */
.toasts {
  position: fixed;
  right: 1.25rem;
  bottom: 1.25rem;
  z-index: 30;
  display: flex;
  flex-direction: column;
  gap: .6rem;
  max-width: min(26rem, calc(100vw - 2.5rem));
}

.toast {
  padding: .7rem 1rem;
  border: 1px solid #2f9e63;
  border-radius: 10px;
  background: #12291d;
  color: #63d69a;
  box-shadow: 0 12px 30px rgba(0, 0, 0, .45);
  opacity: 0;
  transform: translateY(.5rem);
  transition: opacity .18s ease, transform .18s ease;
}

.toast.show { opacity: 1; transform: none; }
.toast.toast-error { border-color: var(--error); background: #2a1618; color: var(--error); }

form.inline-form { display: flex; gap: .75rem; margin-bottom: 1rem; }
form.inline-form input { margin-top: 0; flex: 1 1 auto; }
form.inline-form button { white-space: nowrap; }

/* Filter rows: every control takes the same share of the row, so the search
   field and the selects line up as equal boxes. */
form.inline-form.filters input:not([type="hidden"]),
form.inline-form.filters select { flex: 1 1 0; min-width: 9rem; }

/* One height for the search field, the selects and the button: a text input
   otherwise renders taller than a select, and the button taller still. */
form.inline-form.filters input:not([type="hidden"]),
form.inline-form.filters select,
form.inline-form.filters button {
  height: 2.5rem;
  margin: 0;
  padding: 0 .7rem;
  font-size: .9rem;
  line-height: 1;
}

/* The filter button is a touch smaller than the fields and stays centred. */
form.inline-form.filters button {
  height: 2.1rem;
  align-self: center;
  padding: 0 1rem;
}

td a:not(.chip) { margin-right: .6rem; }
td form.inline { display: inline; margin: 0; }

.actions { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; }

/* Table row actions sit on one line: "Редактировать" and "Удалить" side by side. */
.limits-table td.actions { flex-wrap: nowrap; }

.chips { display: flex; gap: .35rem; }

a.chip,
button.chip {
  display: inline-block;
  margin: 0;
  padding: .2rem .6rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(79, 140, 255, .07);
  color: var(--text);
  font: inherit;
  font-size: .85rem;
  line-height: 1.5;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
}

a.chip:hover,
button.chip:hover { border-color: var(--accent); background: rgba(79, 140, 255, .16); color: var(--accent); }

button.danger {
  background: none;
  border: 1px solid var(--error);
  border-radius: 8px;
  color: var(--error);
  padding: .45rem .8rem;
  font-size: .85rem;
  line-height: 1.5;
  white-space: nowrap;
}

button.danger:hover { background: rgba(255, 107, 107, .14); }

/* A row of card title and its action button. */
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.card-head h2 { margin: 0; }

/* A checkbox that lines up with the other fields of a form grid. */
.form-grid .field.checkbox,
.form-stack .field.checkbox { flex-direction: row; align-items: center; gap: .55rem; }
.form-grid .field.checkbox input,
.form-stack .field.checkbox input { width: auto; margin: 0; }
.form-grid .field.checkbox span,
.form-stack .field.checkbox span { color: var(--text); font-size: .9rem; }

dialog.sheet {
  width: min(680px, 92vw);
  padding: 1.2rem 1.4rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  color: var(--text);
}

dialog.sheet::backdrop { background: rgba(0, 0, 0, .6); }

dialog.sheet h3 { margin-top: 0; }

.snippet {
  margin: .8rem 0 0;
  padding: .7rem .8rem;
  max-height: 12rem;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(0, 0, 0, .25);
  color: var(--muted);
  font-size: .8rem;
  white-space: pre-wrap;
  word-break: break-all;
}

img.qr {
  display: block;
  width: min(320px, 70vw);
  margin: .8rem 0 0;
  padding: .6rem;
  border-radius: 8px;
  background: #fff;
}

.dialog-actions { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: .9rem; }

.pager { display: flex; gap: .4rem; flex-wrap: wrap; align-items: center; margin-top: .8rem; }

.pager .chip.current { background: var(--accent); border-color: var(--accent); color: #fff; }
