:root {
  --red: #b5121b;
  --red-dark: #8c0e15;
  --ink: #1d2129;
  --ink-2: #4b5262;
  --ink-3: #7a8194;
  --surface: #f4f5f7;
  --card: #ffffff;
  --line: #e2e5ea;
  --ok: #1e7f4f;
  --warn: #b26a00;
  --serious: #b5121b;
  --neutral: #5b6472;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(20, 24, 33, .08);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--surface); color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--red-dark); }
h1 { font-size: 1.45rem; margin: .2rem 0 1rem; }
h2 { font-size: 1.05rem; margin: 0 0 .6rem; }
small, .muted { color: var(--ink-3); }

/* ---- layout ---- */
.topbar {
  position: fixed; inset: 0 0 auto 0; height: 58px; z-index: 20;
  display: flex; align-items: center; gap: 14px; padding: 0 16px;
  background: var(--red); color: #fff; box-shadow: var(--shadow);
}
.brand { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; white-space: nowrap; }
.brand img { height: 40px; width: 40px; object-fit: contain; background: #fff; border-radius: 50%; padding: 2px; }
.brand span { display: flex; flex-direction: column; line-height: 1.15; }
.brand small { color: #ffd9db; font-size: .72rem; }
.topbar-search { flex: 1; max-width: 420px; }
.topbar-search input {
  width: 100%; border: none; border-radius: 8px; padding: 8px 12px;
  background: rgba(255,255,255,.92); font-size: .9rem;
}
.topbar-user { margin-left: auto; display: flex; align-items: center; gap: 10px; font-size: .88rem; }
.topbar-user em { font-style: normal; background: rgba(255,255,255,.2); padding: 1px 7px; border-radius: 999px; font-size: .72rem; }
.nav-toggle { display: none; background: none; border: none; color: #fff; font-size: 1.3rem; cursor: pointer; }

.sidenav {
  position: fixed; top: 58px; bottom: 0; left: 0; width: 210px; z-index: 15;
  background: var(--card); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; padding: 14px 10px; gap: 2px;
}
.sidenav a {
  padding: 9px 12px; border-radius: 8px; color: var(--ink-2);
  text-decoration: none; font-weight: 500;
}
.sidenav a:hover { background: var(--surface); }
.sidenav a.active { background: #fbe9ea; color: var(--red-dark); }
.sidenav-footer { margin-top: auto; border-top: 1px solid var(--line); padding-top: 10px; display: flex; flex-direction: column; gap: 2px; }
.sidenav-footer a { font-size: .8rem; color: var(--ink-3); font-weight: 400; }

main.with-nav { padding: 78px 24px 40px 234px; max-width: 1280px; }
main.centered { min-height: 100vh; display: flex; flex-direction: column; justify-content: center; align-items: center; padding: 20px; }

@media (max-width: 860px) {
  .nav-toggle { display: block; }
  .topbar-search { display: none; }
  .brand small { display: none; }
  .sidenav { transform: translateX(-100%); transition: transform .18s ease; width: 240px; }
  body.nav-open .sidenav { transform: none; box-shadow: 0 0 0 100vmax rgba(0,0,0,.35); }
  main.with-nav { padding: 74px 14px 40px; }
}

/* ---- cards, grids ---- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 18px; }
.grid { display: grid; gap: 14px; }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }

/* ---- stat tiles ---- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow); text-decoration: none; display: block;
}
.stat .n { font-size: 1.7rem; font-weight: 700; line-height: 1.1; color: var(--ink); }
.stat .l { font-size: .8rem; color: var(--ink-2); display: flex; align-items: center; gap: 6px; }
.stat .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--neutral); flex: none; }
.stat.s-ok .dot { background: var(--ok); }
.stat.s-warn .dot { background: var(--warn); }
.stat.s-serious .dot { background: var(--serious); }
.stat.s-serious .n { color: var(--serious); }
.stat:hover { border-color: var(--ink-3); }

/* ---- bar list (single-hue magnitude) ---- */
.barlist { display: flex; flex-direction: column; gap: 7px; }
.barlist .row { display: grid; grid-template-columns: 170px 1fr 42px; gap: 10px; align-items: center; font-size: .85rem; }
.barlist .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--ink-2); }
.barlist .track { background: var(--surface); border-radius: 4px; height: 14px; }
.barlist .fill { background: #a63d45; height: 100%; border-radius: 4px 4px 4px 4px; min-width: 2px; }
.barlist .val { text-align: right; color: var(--ink-2); font-variant-numeric: tabular-nums; }

/* ---- tables ---- */
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: .88rem; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .74rem; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-3); white-space: nowrap; }
th a { color: inherit; text-decoration: none; }
th a:hover { color: var(--ink); }
tbody tr:hover { background: #fafbfc; }
td.num { font-variant-numeric: tabular-nums; }
table.compact { font-size: .8rem; }
table.compact th, table.compact td { padding: 6px 6px; }
table.compact th { letter-spacing: 0; }

/* ---- status pills ---- */
.pill { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px; font-size: .74rem; font-weight: 600; white-space: nowrap; }
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill-ok        { background: #e3f2ea; color: var(--ok); }
.pill-monitor   { background: #fff3df; color: var(--warn); }
.pill-due-soon  { background: #fff3df; color: var(--warn); }
.pill-overdue   { background: #fbe9ea; color: var(--serious); }
.pill-failed    { background: #fbe9ea; color: var(--serious); }
.pill-quarantine{ background: #fbe9ea; color: var(--serious); }
.pill-retired   { background: #ece9fb; color: #5b4bb5; }
.pill-missing   { background: #eef0f3; color: var(--neutral); }
.pill-destroyed { background: #eef0f3; color: var(--neutral); }

/* ---- forms ---- */
form.stack { display: flex; flex-direction: column; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: .78rem; font-weight: 600; color: var(--ink-2); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 12px; }
input[type=text], input[type=search], input[type=number], input[type=date],
input[type=email], input[type=password], select, textarea {
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px;
  font: inherit; background: #fff; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid #d98a8f; border-color: var(--red); }
textarea { min-height: 70px; resize: vertical; }
.check { display: flex; align-items: center; gap: 8px; font-size: .88rem; color: var(--ink-2); }
.check input { width: auto; }

.btn {
  display: inline-block; border: none; border-radius: 8px; padding: 9px 16px;
  font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; text-align: center;
  background: var(--surface); color: var(--ink-2);
}
.btn:hover { filter: brightness(.97); }
.btn-primary { background: var(--red); color: #fff; }
.btn-primary:hover { background: var(--red-dark); filter: none; }
.btn-ghost { background: rgba(255,255,255,.15); color: #fff; padding: 6px 12px; font-size: .84rem; }
.btn-sm { padding: 5px 10px; font-size: .8rem; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

/* ---- filter bar ---- */
.filterbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; margin-bottom: 14px; }
.filterbar .field { min-width: 140px; flex: 0 1 auto; }
.filterbar .field.grow { flex: 1 1 220px; }

/* ---- flash ---- */
.flash { border-radius: 8px; padding: 10px 14px; margin-bottom: 14px; font-size: .9rem; border: 1px solid; }
.flash-success { background: #e3f2ea; color: #14532d; border-color: #bfe3cf; }
.flash-error { background: #fbe9ea; color: #7f1d1d; border-color: #f2c4c7; }

/* ---- login ---- */
.auth-card { width: 100%; max-width: 400px; }
.auth-card .brand-big { display: flex; flex-direction: column; align-items: center; gap: 8px; margin-bottom: 16px; text-align: center; }
.auth-card .brand-big img { width: 84px; height: 84px; object-fit: contain; }

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 6px; }
.kv { display: grid; grid-template-columns: 170px 1fr; gap: 6px 14px; font-size: .9rem; }
.kv dt { color: var(--ink-3); }
.kv dd { margin: 0; }
@media (max-width: 560px) { .kv { grid-template-columns: 130px 1fr; } }
