:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --text: #1d2330;
  --muted: #6b7280;
  --border: #e3e5ea;
  --primary: #2453d6;
  --primary-hover: #1c43b0;
  --ok: #157f3b;      --ok-bg: #e5f5eb;
  --warn: #8a5a00;    --warn-bg: #fdf3dc;
  --error: #b42318;   --error-bg: #fdecea;
  --info: #1f4fae;    --info-bg: #e8effc;
  --muted-bg: #eef0f3;
  --radius: 8px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111418; --surface: #1a1e24; --text: #e6e8eb; --muted: #9aa1ab; --border: #2b313a;
    --primary: #5b84f0; --primary-hover: #7a9bf3;
    --ok: #5fd08a; --ok-bg: #173323; --warn: #f0c060; --warn-bg: #3a2e12;
    --error: #ff8a80; --error-bg: #3d1a18; --info: #8fb0f5; --info-bg: #1a2742; --muted-bg: #252a32;
  }
}

* { box-sizing: border-box; }
html { font-size: 15px; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; line-height: 1.45;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0 0 .5rem; display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
code, pre, .mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: .9em; }
pre { white-space: pre-wrap; word-break: break-word; }

.topbar {
  display: flex; align-items: center; gap: 1.5rem; padding: .6rem 1.25rem;
  background: var(--surface); border-bottom: 1px solid var(--border); flex-wrap: wrap;
}
.brand { font-weight: 700; font-size: 1.1rem; color: var(--text); }
.nav { display: flex; gap: .25rem; flex-wrap: wrap; flex: 1; }
.nav a { padding: .4rem .7rem; border-radius: 6px; color: var(--muted); }
.nav a:hover { background: var(--muted-bg); text-decoration: none; color: var(--text); }
.nav a.active { background: var(--info-bg); color: var(--info); font-weight: 600; }
.account { display: flex; gap: .75rem; align-items: center; }

.container { max-width: 1280px; margin: 1.25rem auto; padding: 0 1rem; }
.container.narrow { max-width: 420px; margin-top: 12vh; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1rem 1.25rem; margin-bottom: 1rem; min-width: 0;
}
.login-card h1 { justify-content: center; }
.login-card > p { text-align: center; }
.narrow-card { max-width: 520px; }

.grid { display: grid; gap: 1rem; margin-bottom: 1rem; }
.grid > .card { margin-bottom: 0; }
.cards-4 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.cards-2 { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }

.stat { display: flex; flex-direction: column; gap: .3rem; }
.stat-label { color: var(--muted); font-size: .85rem; text-transform: uppercase; letter-spacing: .03em; }
.stat-value.big { font-size: 1.9rem; font-weight: 700; }
.stat.link { color: var(--text); }
.stat.link:hover { border-color: var(--primary); text-decoration: none; }
.stat.danger { border-color: var(--error); }

.page-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.page-head h1, .page-head h2 { margin: 0; }

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: .5rem .6rem; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.table th { font-size: .8rem; text-transform: uppercase; color: var(--muted); letter-spacing: .03em; }
.table tbody tr:hover { background: var(--muted-bg); }
.table tfoot td, .table tfoot th { border-bottom: none; }
.num { text-align: right !important; font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }

.badge {
  display: inline-block; padding: .1rem .5rem; border-radius: 999px; font-size: .8rem; font-weight: 600;
  white-space: nowrap;
}
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-error { background: var(--error-bg); color: var(--error); }
.badge-info { background: var(--info-bg); color: var(--info); }
.badge-muted { background: var(--muted-bg); color: var(--muted); }

.alert { padding: .75rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; border: 1px solid transparent; }
.alert-success { background: var(--ok-bg); color: var(--ok); border-color: var(--ok); }
.alert-error { background: var(--error-bg); color: var(--error); border-color: var(--error); }
.alert-warn { background: var(--warn-bg); color: var(--warn); border-color: var(--warn); }
.alert-info { background: var(--info-bg); color: var(--info); border-color: var(--info); }

.btn {
  display: inline-flex; align-items: center; gap: .35rem; padding: .45rem .9rem; border-radius: 6px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer;
  font: inherit; font-weight: 500; white-space: nowrap;
}
.btn:hover { border-color: var(--primary); text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { color: var(--error); border-color: var(--error); }
.btn-link { border: none; background: none; color: var(--primary); padding: 0; cursor: pointer; font: inherit; }

input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 6px; padding: .45rem .6rem; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
input[type="checkbox"], input[type="radio"] { width: auto; }
label { display: block; font-weight: 500; }
.form { display: flex; flex-direction: column; gap: .8rem; }
.form label input, .form label select, .form label textarea { margin-top: .25rem; }
.check { display: flex; align-items: center; gap: .5rem; font-weight: 400; }
fieldset { border: 1px solid var(--border); border-radius: 6px; padding: .5rem .9rem; }
legend { font-weight: 600; padding: 0 .3rem; }
.inline { display: inline; }
.inline-form { display: flex; gap: .5rem; align-items: center; }
.mt { margin-top: .75rem; }

.filters { display: flex; flex-wrap: wrap; gap: .75rem; align-items: flex-end; }
.filters label { flex: 1 1 160px; font-size: .85rem; color: var(--muted); }
.filters label input, .filters label select { margin-top: .2rem; }
.filter-actions { display: flex; gap: .5rem; }

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 1rem 1.5rem; }
.field label { margin-bottom: .25rem; }
.field.wide { grid-column: 1 / -1; }
.field.has-error input, .field.has-error textarea, .field.has-error select { border-color: var(--error); }
.help { color: var(--muted); font-size: .85rem; margin: .3rem 0 0; }
.error-text { color: var(--error); font-size: .9rem; margin: .3rem 0 0; }
.actions-bar { position: sticky; bottom: 0; padding: .75rem 0; background: var(--bg); margin-bottom: 1rem; }

.dl { display: grid; grid-template-columns: minmax(140px, auto) 1fr; gap: .35rem 1rem; margin: 0 0 1rem; }
.dl dt { color: var(--muted); }
.dl dd { margin: 0; word-break: break-word; }

.muted { color: var(--muted); }
.small { font-size: .85rem; }
.code { background: var(--muted-bg); padding: .75rem; border-radius: 6px; margin: 0; }
.log-details summary { cursor: pointer; color: var(--muted); font-size: .8rem; }
.log-details pre { background: var(--muted-bg); padding: .5rem; border-radius: 6px; max-height: 320px; overflow: auto; }
.pagination { display: flex; gap: 1rem; justify-content: center; align-items: center; padding-top: .75rem; }
