:root {
  color-scheme: light;
  --brand: #b16500;
  --brand-ink: #8a4f00;
  --brand-soft: #fbf1e4;
  --navy: #181928;
  --page: #f5f4f1;
  --surface: #ffffff;
  --surface-2: #f1efea;
  --ink: #181928;
  --ink-2: #4f4e57;
  --muted: #85838c;
  --border: rgba(24, 25, 40, 0.12);
  --good: #0a8a0a;
  --good-soft: #e4f4e4;
  --bad: #c62f2f;
  --bad-soft: #fbe9e9;
  --warn: #b57f00;
  --warn-soft: #fdf3dc;
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--page); color: var(--ink); font: 14px/1.45 var(--font); }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand-ink); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 30px 26px; }
.login-logo { height: 46px; }
.login-card h1 { font-size: 20px; margin: 14px 0 4px; }
.login-card p { margin: 0 0 18px; color: var(--ink-2); }
.login-card label, .field label { display: block; font-weight: 600; font-size: 13px; margin: 12px 0 5px; }
.form-error { color: var(--bad); font-size: 13px; min-height: 18px; margin: 8px 0; }

/* Shell */
.shell { display: grid; grid-template-columns: 230px 1fr; min-height: 100vh; }
.side { background: var(--navy); color: #e8e7ef; padding: 18px 12px; display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh; }
.brand { padding: 4px 10px 18px; display: flex; flex-direction: column; gap: 4px; }
.brand img { background: #fff; border-radius: 8px; padding: 6px 10px; align-self: flex-start; box-sizing: content-box; }
.brand small { color: #a9a7b8; font-size: 12px; }
.side nav a { display: block; padding: 9px 12px; border-radius: 8px; color: #cfcde0; text-decoration: none; font-weight: 500; }
.side nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.side nav a.active { background: var(--brand); color: #fff; }
.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 6px; padding: 10px; }
.side-foot .btn { background: transparent; color: #cfcde0; border-color: rgba(255,255,255,.18); }
.me { font-size: 12.5px; color: #a9a7b8; margin-bottom: 4px; }
.me b { color: #fff; display: block; font-size: 13px; }
.main { padding: 24px 28px 48px; min-width: 0; }
.mobile-bar { display: none; }

.topbar { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.topbar h2 { margin: 0; font-size: 22px; }
.topbar p { margin: 3px 0 0; color: var(--ink-2); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* Primitives */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.card-h { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 14px 16px 0; }
.card-h h3 { margin: 0; font-size: 14.5px; }
.card-b { padding: 12px 16px 16px; }
.grid { display: grid; gap: 14px; }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.stat { padding: 16px; }
.stat .k { color: var(--ink-2); font-size: 13px; }
.stat .v { font-size: 26px; font-weight: 700; margin-top: 4px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 34px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-weight: 600; white-space: nowrap; text-decoration: none; color: var(--ink); }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-ink); }
.btn.danger { color: var(--bad); }
.btn.sm { height: 28px; padding: 0 10px; font-size: 13px; }
.btn.block { width: 100%; }
.btn.icon { width: 36px; padding: 0; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
input[type=text], input[type=email], input[type=password], input[type=number], select, textarea {
  width: 100%; height: 36px; padding: 0 10px; border: 1px solid var(--border); border-radius: 8px; background: #fff; outline: none;
}
textarea { height: 160px; padding: 8px 10px; font-family: ui-monospace, Consolas, monospace; font-size: 12.5px; }
input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(177, 101, 0, .18); }
.badge { display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--ink-2); white-space: nowrap; }
.badge.good { background: var(--good-soft); color: var(--good); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.brand { background: var(--brand-soft); color: var(--brand-ink); }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 9px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: #faf9f6; }
td .sub { color: var(--muted); font-size: 12px; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.empty { padding: 28px; text-align: center; color: var(--muted); }
.clickable { cursor: pointer; }

/* Modal */
.overlay { position: fixed; inset: 0; background: rgba(10, 10, 20, .45); display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal { width: 100%; max-width: 560px; max-height: calc(100vh - 32px); overflow: auto; background: var(--surface); border-radius: 14px; }
.modal-h { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px 4px; }
.modal-h h3 { margin: 0; font-size: 17px; }
.modal-b { padding: 6px 20px 16px; }
.modal-f { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px 16px; border-top: 1px solid var(--border); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.help { font-size: 12px; color: var(--muted); margin-top: 4px; }
.errors { background: var(--bad-soft); color: var(--bad); border-radius: 8px; padding: 8px 12px; font-size: 12.5px; margin-top: 10px; white-space: pre-wrap; }

.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast { background: var(--navy); color: #fff; padding: 10px 14px; border-radius: 8px; font-size: 13px; max-width: 360px; }
.toast.bad { background: var(--bad); }

@media (max-width: 900px) { .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 auto 0 0; width: 240px; z-index: 40; transform: translateX(-100%); transition: transform .2s; }
  .side.open { transform: none; }
  .mobile-bar { display: flex; justify-content: space-between; align-items: center; padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 30; }
  .main { padding: 16px; }
  .row2 { grid-template-columns: 1fr; }
}
