:root {
  --bg: #f4f6fb; --card: #ffffff; --ink: #1d2540; --muted: #6b7491; --line: #e2e6f0;
  --primary: #3d6fe0; --primary-ink: #fff; --ok: #2aa36b; --warn: #e0a22d; --bad: #d8493e; --gold: #f1b72f;
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0f1424; --card: #171e35; --ink: #e8ecfb; --muted: #94a0c4; --line: #27304f; --primary: #5b8cff; }
}
* { box-sizing: border-box; }
body { margin: 0; font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--ink); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
h1, h2, h3 { margin: 0 0 .6rem; }
button { font: inherit; border: 1px solid var(--line); background: var(--card); color: var(--ink); padding: .5rem .9rem; border-radius: 9px; cursor: pointer; }
button:hover { border-color: var(--primary); }
button.primary { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
button.danger { background: var(--bad); color: #fff; border-color: var(--bad); }
button.ghost { background: transparent; }
input, select, textarea { font: inherit; width: 100%; padding: .5rem .65rem; border: 1px solid var(--line); border-radius: 9px; background: var(--bg); color: var(--ink); }
textarea { min-height: 7rem; resize: vertical; }
label { display: block; margin: .6rem 0; font-size: .9rem; color: var(--muted); }
label > input, label > select, label > textarea { margin-top: .25rem; color: var(--ink); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem; box-shadow: 0 1px 3px rgba(20,30,60,.06); }
.error { color: var(--bad); min-height: 1.2em; }

.login { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.login-card { width: min(380px, 100%); }
.login-card h1 { font-size: 1.8rem; }

.topbar { display: flex; align-items: center; gap: 1rem; padding: .6rem 1rem; background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; flex-wrap: wrap; }
.brand { font-weight: 800; font-size: 1.15rem; }
nav { display: flex; gap: .3rem; flex-wrap: wrap; flex: 1; }
nav button { border-color: transparent; background: transparent; }
nav button.active { background: var(--primary); color: var(--primary-ink); }
.badge { display: inline-block; background: var(--bad); color: #fff; border-radius: 999px; padding: 0 .45rem; font-size: .75rem; margin-left: .25rem; }
main { padding: 1rem; max-width: 1200px; margin: 0 auto; }

.grid { display: grid; gap: .9rem; }
.stats { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.stat .n { font-size: 1.8rem; font-weight: 800; }
.cols2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; margin-top: 1rem; }
.row > * { flex: 0 0 auto; }
.row .grow { flex: 1 1 200px; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .45rem .6rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; }
tr.click { cursor: pointer; }
tr.click:hover td { background: color-mix(in srgb, var(--primary) 8%, transparent); }
.scroll { overflow-x: auto; }
.pill { display: inline-block; padding: .05rem .5rem; border-radius: 999px; font-size: .78rem; background: var(--line); }
.pill.ok { background: color-mix(in srgb, var(--ok) 25%, transparent); color: var(--ok); }
.pill.bad { background: color-mix(in srgb, var(--bad) 25%, transparent); color: var(--bad); }
.pill.warn { background: color-mix(in srgb, var(--warn) 25%, transparent); color: var(--warn); }

.bars { display: grid; gap: .3rem; }
.bar { display: grid; grid-template-columns: 70px 1fr 40px; gap: .5rem; align-items: center; font-size: .85rem; }
.bar .fill { height: 14px; border-radius: 7px; background: linear-gradient(90deg, var(--primary), var(--gold)); }

.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: .3rem .8rem; }
.items { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .5rem .8rem; }

.modal { position: fixed; inset: 0; background: rgba(8, 12, 28, .6); display: grid; place-items: center; padding: 1rem; z-index: 20; }
.modal-card { width: min(520px, 100%); }
.code { font: 700 1.8rem/1.2 ui-monospace, Consolas, monospace; letter-spacing: .1em; text-align: center; padding: .8rem; background: var(--bg); border-radius: 10px; border: 1px dashed var(--primary); user-select: all; }
.toast { position: fixed; bottom: 1rem; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: .6rem 1rem; border-radius: 10px; z-index: 30; }
.ticket { margin-bottom: .8rem; }
.ticket .msg { white-space: pre-wrap; background: var(--bg); padding: .6rem .8rem; border-radius: 9px; margin: .5rem 0; }
.small { font-size: .85rem; }
@media (max-width: 640px) { .topbar { gap: .4rem; } main { padding: .6rem; } }
