:root {
  --bg: #f4f6fa; --card: #fff; --text: #16202e; --muted: #6b7686; --line: #e3e7ee;
  --primary: #1b3d5c; --brand-red: #d90a0a; --primary-ink: #fff; --danger: #dc2626; --ok: #15803d; --warn: #b45309;
  --ok-bg: #e7f6ec; --danger-bg: #fdecec; --warn-bg: #fdf3e2;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 15px; }
.hidden { display: none !important; }
a { color: var(--primary); text-decoration: none; }
h1 { font-size: 22px; margin: 0 0 16px; }
h2 { font-size: 18px; margin: 28px 0 12px; }

.top { display: flex; align-items: center; gap: 24px; padding: 0 24px; background: #000; color: #fff; min-height: 60px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; color: #fff; font-weight: 700; font-size: 16px; line-height: 1.1; }
.brand img { border-radius: 6px; display: block; }
.brand small { display: block; font-size: 11px; font-weight: 600; color: var(--brand-red); letter-spacing: .08em; text-transform: uppercase; margin-top: 2px; }
nav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
nav a { color: #cbd5e1; padding: 8px 14px; border-radius: 8px; }
nav a:hover { color: #fff; background: #1a1a1a; }
nav a.active { color: #fff; background: var(--brand-red); }
.who { color: #94a3b8; font-size: 14px; }
.who a { color: #cbd5e1; }

main { max-width: 1150px; margin: 0 auto; padding: 24px; }
.bar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.bar h1 { margin: 0; flex: 1; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat { padding: 14px 16px; }
.stat .k { color: var(--muted); font-size: 13px; }
.stat .v { font-size: 22px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; background: #f9fafc; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.wrap { white-space: normal; min-width: 220px; }
td.actions { text-align: right; }
tr.inactive td { color: var(--muted); }
.empty { padding: 32px; text-align: center; color: var(--muted); }
.pill { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; }
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.no { background: var(--danger-bg); color: var(--danger); }
.pill.part { background: var(--warn-bg); color: var(--warn); }
.pill.off { background: #eef0f3; color: var(--muted); }
.red { color: var(--danger); font-weight: 600; }

.btn { border: 1px solid var(--line); background: #fff; color: var(--text); padding: 8px 14px; border-radius: 8px; font: inherit; cursor: pointer; }
.btn:hover { border-color: #c7cdd8; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn.danger { color: var(--danger); }
input, select, textarea { font: inherit; padding: 8px 10px; border: 1px solid #cfd5df; border-radius: 8px; background: #fff; color: var(--text); width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid #c3d3e3; border-color: var(--primary); }
.bar input, .bar select { width: auto; }
.bar input[type=search] { min-width: 220px; }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
label input, label select, label textarea { margin-top: 4px; color: var(--text); }
label.check { display: flex; gap: 8px; align-items: center; color: var(--text); font-size: 14px; }
label.check input { width: auto; margin: 0; }

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; padding: 28px; }
.login-card .btn { width: 100%; padding: 10px; }
.login-card h1 { text-align: center; font-size: 18px; color: var(--muted); font-weight: 600; }
.login-logo { display: block; width: 180px; height: 180px; margin: 0 auto 14px; border-radius: 16px; }
.error { color: var(--danger); min-height: 1.2em; margin: 0 0 10px; font-size: 14px; }

dialog { border: 0; border-radius: 14px; padding: 0; width: min(460px, calc(100vw - 32px)); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(15, 23, 42, .45); }
.dialog { padding: 22px; }
.dialog h3 { margin: 0 0 16px; font-size: 18px; }
.dialog .row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.dialog .foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.dialog .hint { font-size: 13px; color: var(--muted); margin: -4px 0 12px; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(20px); background: #000; color: #fff; padding: 10px 18px; border-radius: 10px; opacity: 0; transition: .2s; pointer-events: none; z-index: 10; }
.toast.show { opacity: 1; transform: translateX(-50%); }
.toast.bad { background: var(--danger); }

.banner { background: #fef2f2; color: #7f1d1d; border-bottom: 1px solid #fecaca; padding: 10px 24px; font-size: 14px; }
.banner a { font-weight: 600; margin-left: 6px; color: #b91c1c; text-decoration: underline; }
.tabs { display: inline-flex; background: #e9edf3; border-radius: 10px; padding: 3px; }
.tab { border: 0; background: none; padding: 6px 14px; border-radius: 8px; font: inherit; font-size: 14px; cursor: pointer; color: var(--muted); }
.tab.active { background: #fff; color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
dialog.wide { width: min(720px, calc(100vw - 32px)); }
.dialog h3 + .table-wrap, .dialog .table-wrap { max-height: 320px; overflow: auto; border: 1px solid var(--line); border-radius: 10px; }
textarea { resize: vertical; }
.roles { padding: 6px 16px; margin-top: 16px; font-size: 14px; }
.roles p { margin: 8px 0; }
select.role-select { width: auto; padding: 4px 8px; font-size: 13px; }
.method-row { display: flex; justify-content: space-between; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--line); }
.method-row:last-child { border-bottom: 0; }
.spend td.num b { font-size: 15px; }
.spend tr.current td { background: #f3f6fa; }
.total-stat { border-color: #f1c4c4; }
.cats { margin: -8px 0 20px; font-size: 14px; }
.cats span { white-space: nowrap; }
.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; padding: 14px 16px 2px; margin-bottom: 12px; }
tr.det td { background: #f9fafc; }
table.details { width: auto; }
table.details td { border: 0; padding: 3px 10px 3px 0; font-size: 13px; white-space: normal; }
table.details td:first-child { color: var(--muted); }
.import-map { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; padding: 16px; }
.muted { color: var(--muted); }

@media (max-width: 1000px) {
  .top { gap: 12px; padding: 8px 16px; }
  nav a { padding: 6px 10px; }
}
@media (max-width: 700px) {
  .top { padding: 8px 16px; gap: 8px; }
  main { padding: 16px; }
  .dialog .row { grid-template-columns: 1fr; }
}
@media print {
  .top, .banner, .tabs, .bar button, .bar input, td.actions, th.actions { display: none !important; }
  body { background: #fff; }
}
