:root {
  --bg: #f5f6f0;
  --surface: #ffffff;
  --border: #dce3d9;
  --border-soft: #edf0eb;
  --ink: #223029;
  --muted: #5a6b62;
  --brand: #173c2d;
  --brand-2: #22543e;
  --brand-hover: #1b4633;
  --ok-bg: #dff2e5;
  --ok-ink: #164b30;
  --info-bg: #e5f0f9;
  --info-ink: #10476d;
  --warn-bg: #fff4d6;
  --warn-ink: #6e4a00;
  --bad-bg: #fde7e7;
  --bad-ink: #8f1d1d;
  --muted-bg: #eef0ed;
  --radius: 12px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 "Segoe UI", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--brand-2); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Header */
.topbar {
  background: var(--brand);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-inner, .wrap {
  width: min(1140px, calc(100% - 32px));
  margin: 0 auto;
}

.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 60px;
  flex-wrap: wrap;
  padding: 8px 0;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: #fff;
  font-weight: 700;
  font-size: 17px;
  text-decoration: none;
}
.brand:hover { text-decoration: none; opacity: .92; }

.env-pill {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .04em;
  padding: 2px 8px;
  border-radius: 999px;
  text-transform: uppercase;
}
.env-pill.prod { background: #2d7a56; color: #fff; }
.env-pill.homo { background: #e8b948; color: #2b2100; }

.nav {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.nav a, .nav-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border-radius: 8px;
  color: rgba(255, 255, 255, .86);
  font-weight: 500;
  font-size: 14px;
  background: transparent;
  border: 0;
  cursor: pointer;
  font-family: inherit;
  text-decoration: none;
}
.nav a:hover, .nav-btn:hover { background: rgba(255, 255, 255, .12); color: #fff; text-decoration: none; }
.nav a.active { background: rgba(255, 255, 255, .18); color: #fff; font-weight: 600; }

/* Main */
.wrap { padding: 26px 0 48px; }

h1 {
  margin: 0 0 6px;
  font: 600 clamp(28px, 4vw, 40px)/1.15 Georgia, "Times New Roman", serif;
  color: var(--brand);
}
h2 { margin: 0 0 10px; font-size: 18px; color: var(--brand); }
h3 { margin: 0 0 8px; font-size: 15px; color: var(--brand); }
p { margin: 0 0 10px; }
.muted { color: var(--muted); font-size: 14px; }
.small { font-size: 13px; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }

/* Flash alerts */
.alert {
  padding: 12px 16px;
  border-radius: 10px;
  margin-bottom: 16px;
  border: 1px solid transparent;
  font-size: 14px;
}
.alert-ok { background: var(--ok-bg); color: var(--ok-ink); border-color: #bde4ca; }
.alert-bad { background: var(--bad-bg); color: var(--bad-ink); border-color: #f4c2c2; }
.alert-warn { background: var(--warn-bg); color: var(--warn-ink); border-color: #ebdcb2; }
.alert-info { background: var(--info-bg); color: var(--info-ink); border-color: #c5def2; }

/* Toolbar & buttons */
.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin: 18px 0;
}
.group { display: inline-flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.btn, button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font: 500 14px/1.2 inherit;
  cursor: pointer;
  color: var(--ink);
  border: 1px solid #c5d1c8;
  background: #fff;
  border-radius: 8px;
  padding: 9px 14px;
  min-height: 38px;
  text-decoration: none;
  transition: background .15s, border-color .15s;
}
.btn:hover, button:hover { background: #f2f5f2; text-decoration: none; }
.btn:disabled, button:disabled { opacity: .55; cursor: not-allowed; }

.btn-primary, button.primary, button[aria-pressed="true"] {
  background: var(--brand-2);
  border-color: var(--brand-2);
  color: #fff;
}
.btn-primary:hover, button.primary:hover { background: var(--brand-hover); }

.btn-danger { color: var(--bad-ink); border-color: #e6b8b8; background: #fff; }
.btn-danger:hover { background: var(--bad-bg); }

.btn-sm { padding: 5px 10px; min-height: 30px; font-size: 13px; border-radius: 6px; }

.ic { flex-shrink: 0; vertical-align: middle; }

/* Cards & panels */
.cards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}

.card, .panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
}

.card-label { font-size: 13px; color: var(--muted); }
.card strong {
  display: block;
  margin-top: 4px;
  font-size: clamp(20px, 3vw, 28px);
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}
.card.warn { background: #fff9e8; border-color: #ebdcb2; }
.card.ok strong { color: var(--ok-ink); }

.panel { margin-bottom: 18px; }
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

/* Badges */
.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 6px;
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
}
.badge-ok { background: var(--ok-bg); color: var(--ok-ink); }
.badge-info { background: var(--info-bg); color: var(--info-ink); }
.badge-warn { background: var(--warn-bg); color: var(--warn-ink); }
.badge-bad { background: var(--bad-bg); color: var(--bad-ink); }
.badge-muted { background: var(--muted-bg); color: var(--muted); }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; text-align: left; font-size: 14px; }
th, td { padding: 10px 10px; border-bottom: 1px solid var(--border-soft); vertical-align: middle; }
th { font-size: 12.5px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); white-space: nowrap; }
tbody tr:hover { background: #fafbf8; }
.note-line { display: block; font-size: 12px; color: var(--muted); margin-top: 2px; max-width: 320px; white-space: normal; }
.note-line.err { color: var(--bad-ink); }
.actions-cell { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }

/* Forms */
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }

.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
.field label { font-size: 13.5px; font-weight: 600; color: var(--ink); }
.field .help { font-size: 12.5px; color: var(--muted); }

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
select,
textarea {
  font: inherit;
  padding: 9px 11px;
  border: 1px solid #c5d1c8;
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  width: 100%;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid #22543e44;
  border-color: var(--brand-2);
}
textarea { min-height: 90px; resize: vertical; }

.dates { display: inline-flex; gap: 10px; flex-wrap: wrap; align-items: end; }
.dates label { display: flex; flex-direction: column; gap: 3px; font-size: 12.5px; color: var(--muted); }
.dates input[type="date"] { width: auto; padding: 7px 10px; }

.switch {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fafbf8;
  cursor: pointer;
  margin-bottom: 10px;
}
.switch input { width: 18px; height: 18px; margin-top: 2px; accent-color: var(--brand-2); }

.copy-box {
  display: flex;
  gap: 8px;
  align-items: center;
}
.copy-box input { font-family: ui-monospace, Consolas, monospace; font-size: 13px; background: #f8faf8; }

/* Dialogs */
dialog {
  border: 1px solid var(--border);
  border-radius: 14px;
  width: min(820px, 94vw);
  max-height: 90vh;
  padding: 22px;
  color: var(--ink);
}
dialog::backdrop { background: rgba(23, 47, 37, .55); }
dialog.narrow { width: min(480px, 94vw); }

.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  margin-right: 6px;
  vertical-align: text-bottom;
  border: 2px solid #c6d8cc;
  border-top-color: var(--brand-2);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
.spinner[hidden] { display: none; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Auth centered layout */
.auth-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.auth-card {
  width: min(440px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px;
}
.auth-card h1 { font-size: 28px; margin-bottom: 4px; }

@media (max-width: 860px) {
  .cards { grid-template-columns: repeat(2, 1fr); }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
}
@media (max-width: 520px) {
  .cards { grid-template-columns: 1fr; }
  .wrap { padding-top: 18px; }
}

@media print {
  .topbar, .no-print { display: none !important; }
  body { background: #fff; }
  .wrap { width: 100%; padding: 0; }
  .panel { border: 0; padding: 0; }
}
