:root {
  --pine: #0e7c66;
  --pine-dark: #0a5f4e;
  --ink: #1d3557;
  --road: #2f3a40;
  --sun: #f0b429;
  --cloud: #f7f7f2;
  --coral: #c8472b;
  --mist: #e8ece7;
  --line: #d5dbd4;
  --text: #1f2a30;
  --muted: #5d6b72;
  --white: #ffffff;
  --radius: 10px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--cloud);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

a { color: var(--pine-dark); }
a:hover { color: var(--ink); }

h1 { font-size: 1.6rem; line-height: 1.25; margin: 0 0 1rem; color: var(--ink); }
h2 { font-size: 1.05rem; margin: 0 0 0.75rem; color: var(--ink); }
p { margin: 0 0 0.75rem; }

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.92em;
  background: var(--mist);
  padding: 0.1em 0.35em;
  border-radius: 4px;
}

.muted, .hint, .sub { color: var(--muted); }
.hint { font-size: 0.86rem; font-weight: 400; }
.sub { display: block; font-size: 0.82rem; }
.nowrap { white-space: nowrap; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: 1.25rem; flex-wrap: wrap;
  background: var(--ink); color: var(--white);
  padding: 0.6rem 1.25rem;
}
.brand { display: flex; align-items: center; gap: 0.6rem; color: var(--white); text-decoration: none; font-weight: 650; }
.brand:hover { color: var(--white); }
.brand-mark {
  display: inline-grid; place-items: center; width: 30px; height: 30px;
  background: var(--pine); color: var(--white); border-radius: 8px; font-weight: 700;
}
.brand-mark.big { width: 52px; height: 52px; font-size: 1.5rem; border-radius: 14px; margin-bottom: 0.75rem; }
.nav { display: flex; gap: 0.25rem; flex-wrap: wrap; flex: 1; }
.nav a {
  color: #dfe6ee; text-decoration: none; padding: 0.4rem 0.75rem; border-radius: 8px;
}
.nav a:hover { background: rgba(255, 255, 255, 0.1); color: var(--white); }
.nav a.current { background: var(--white); color: var(--ink); font-weight: 600; }
.signout { display: flex; align-items: center; gap: 0.75rem; margin: 0; }
.who { color: #dfe6ee; font-size: 0.9rem; }

/* ---------- layout ---------- */
.page { max-width: 1120px; margin: 0 auto; padding: 1.5rem 1.25rem 3rem; }
.plain .page { max-width: 520px; padding-top: 8vh; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 1rem; }
.card {
  background: var(--white); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1.25rem; margin-bottom: 1rem;
}
.grid-2 > .card { margin-bottom: 0; }
.grid-2 { margin-bottom: 1rem; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; flex-wrap: wrap; }
.crumb { font-size: 0.9rem; color: var(--muted); margin-bottom: 0.4rem; }
.empty { color: var(--muted); padding: 0.75rem 0; margin: 0; }

.auth-card {
  background: var(--white); border: 1px solid var(--line); border-radius: 14px;
  padding: 2rem; text-align: center;
}
.auth-card form { text-align: left; margin-top: 1.25rem; }
.auth-card .auth-alt { text-align: center; margin-top: 0.75rem; }
.auth-card.wide { text-align: left; }
.steps { padding-left: 1.2rem; }
.steps li { margin-bottom: 0.6rem; }
.qr { margin: 0.75rem 0 0.5rem; }
.qr img { display: block; border: 1px solid var(--line); border-radius: 8px; }
.secret { font-size: 1rem; letter-spacing: 0.04em; user-select: all; }

/* ---------- tiles ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 0.75rem; margin-bottom: 1rem; }
.tile {
  display: flex; flex-direction: column; gap: 0.15rem; text-decoration: none;
  background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem;
}
.tile:hover { border-color: var(--pine); }
.tile-num { font-size: 1.9rem; font-weight: 700; color: var(--ink); line-height: 1.1; font-variant-numeric: tabular-nums; }
.tile-label { color: var(--muted); font-size: 0.9rem; }

/* ---------- forms ---------- */
label { display: block; font-weight: 600; margin: 0.9rem 0 0.3rem; }
form > label:first-of-type { margin-top: 0; }
input[type="text"], input[type="password"], input[type="number"], input[type="search"], input[type="date"], select, textarea {
  width: 100%; padding: 0.55rem 0.7rem; font: inherit; color: var(--text);
  background: var(--white); border: 1px solid #aab4ae; border-radius: 8px;
}
input:focus-visible, select:focus-visible, textarea:focus-visible, .btn:focus-visible, a:focus-visible {
  outline: 3px solid rgba(14, 124, 102, 0.45); outline-offset: 1px;
}
input[readonly], textarea[readonly] { background: #fafbf9; }
fieldset { border: 0; padding: 0; margin: 0.9rem 0 0; }
legend { font-weight: 600; padding: 0; margin-bottom: 0.3rem; }
.radio { display: flex; align-items: center; gap: 0.5rem; font-weight: 400; margin: 0.35rem 0; }
.radio input[type="radio"] { width: 1.05rem; height: 1.05rem; accent-color: var(--pine); flex: none; }
.inline-num { width: 6rem !important; display: inline-block; margin: 0 0.25rem; }
.inline-date { width: 11rem !important; display: inline-block; margin: 0 0.25rem; }
.inline-form { display: flex; gap: 0.5rem; align-items: center; }
.inline-form input { flex: 1; min-width: 0; }
.code-input { font-size: 1.5rem !important; letter-spacing: 0.3em; text-align: center; font-variant-numeric: tabular-nums; }
.codes-box { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.95rem; resize: vertical; }
.search { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 0.75rem; }
.search input[type="search"] { flex: 2 1 220px; }
.search select { flex: 1 1 180px; width: auto; }
form .btn { margin-top: 1rem; }
.inline-form .btn, .search .btn, .signout .btn, .row-action .btn, .actions .btn, .action .btn { margin-top: 0; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0.55rem 1rem; font: inherit; font-weight: 600; line-height: 1.2;
  color: var(--ink); background: var(--white); border: 1px solid #aab4ae; border-radius: 8px;
  text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--mist); color: var(--ink); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--pine); border-color: var(--pine); color: var(--white); }
.btn-primary:hover { background: var(--pine-dark); border-color: var(--pine-dark); color: var(--white); }
.btn-danger { background: var(--white); border-color: var(--coral); color: var(--coral); }
.btn-danger:hover { background: var(--coral); color: var(--white); }
.btn-ghost { background: transparent; border-color: transparent; }
.topbar .btn-ghost { color: var(--white); border-color: rgba(255, 255, 255, 0.35); }
.topbar .btn-ghost:hover { background: rgba(255, 255, 255, 0.12); color: var(--white); }
.btn-link { background: none; border: 0; color: var(--pine-dark); font-weight: 400; text-decoration: underline; }
.btn-small { padding: 0.3rem 0.65rem; font-size: 0.88rem; }
.btn-block { width: 100%; }
.actions { display: flex; gap: 0.5rem; flex-wrap: wrap; margin: 0.75rem 0; }
.actions form { margin: 0; }

.action-list { display: grid; gap: 0; }
.action {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap;
  padding: 0.85rem 0; border-top: 1px solid var(--mist);
}
.action:first-child { border-top: 0; padding-top: 0; }
.action > div { flex: 1 1 280px; }
.action .hint { margin: 0.1rem 0 0; }
.action form { margin: 0; flex: 0 1 auto; }
.action .inline-form input { width: 15rem; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 0.55rem 0.6rem; border-bottom: 1px solid var(--mist); vertical-align: top; }
th { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); white-space: nowrap; }
tbody tr:hover { background: #fafbf9; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.row-action { text-align: right; }
td.row-action form { margin: 0; }
td.detail { font-size: 0.82rem; color: var(--muted); word-break: break-word; max-width: 22rem; }

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

/* ---------- badges, alerts ---------- */
.badge {
  display: inline-block; padding: 0.1rem 0.55rem; border-radius: 999px; font-size: 0.8rem; font-weight: 600;
  background: var(--mist); color: var(--road); vertical-align: middle; white-space: nowrap;
}
.badge-active, .badge-available { background: #d9f0ea; color: #0a5f4e; }
.badge-used { background: #dde6f2; color: var(--ink); }
.badge-blocked, .badge-disabled { background: #f8ddd6; color: #8f2c16; }
.badge-expired, .badge-lapsed { background: #fbeccb; color: #7a5200; }

.alert { padding: 0.75rem 1rem; border-radius: 8px; margin-bottom: 1rem; border: 1px solid transparent; }
.alert-ok { background: #d9f0ea; border-color: #9fd3c6; color: #0a4f41; }
.alert-error { background: #f8ddd6; border-color: #e9a999; color: #7d2512; }
.alert-warn { background: #fbeccb; border-color: #ecc874; color: #5e3f00; }

.filters { display: flex; gap: 0.25rem; flex-wrap: wrap; }
.filters a { padding: 0.25rem 0.7rem; border-radius: 999px; text-decoration: none; color: var(--muted); }
.filters a.current { background: var(--ink); color: var(--white); }
.pager { display: flex; align-items: center; justify-content: center; gap: 1rem; margin-top: 1rem; color: var(--muted); }

@media (max-width: 640px) {
  .topbar { padding: 0.6rem 0.75rem; gap: 0.6rem; }
  .who { display: none; }
  .signout { margin-left: auto; }
  .nav { order: 3; flex: 1 0 100%; flex-wrap: nowrap; overflow-x: auto; padding-bottom: 0.2rem; }
  .nav a { white-space: nowrap; }
  .table-wrap table { min-width: 620px; }
  .page { padding: 1rem 0.75rem 2.5rem; }
  .card { padding: 1rem; }
  .facts { grid-template-columns: 1fr; gap: 0 0; }
  .facts dd { margin-bottom: 0.5rem; }
  .action .inline-form input { width: auto; }
}
