:root {
  --brand: #ff6a00;
  --brand-dark: #e05a00;
  --brand-soft: #fff1e6;
  --navy: #0b1f4d;
  --navy-2: #16306b;
  --bg: #f5f6f9;
  --card: #fff;
  --text: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --ok: #1b7f3b;
  --ok-bg: #e3f5ea;
  --warn: #9a6200;
  --warn-bg: #fff4d6;
  --bad: #b42318;
  --bad-bg: #fdecea;
  --radius: 12px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.5 "Segoe UI", system-ui, -apple-system, sans-serif; }
a { color: var(--brand-dark); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; }
input, select, textarea, button { font: inherit; color: inherit; }

/* Layout */
.shell { display: flex; min-height: 100vh; }
.side {
  width: 240px; flex: none; background: var(--navy); color: #d5dcef; display: flex; flex-direction: column;
  padding: 18px 12px; position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 2px 8px 20px; color: #fff; }
.brand img { width: 50px; }
.brand b { display: block; font-size: 15px; }
.brand small { opacity: .6; font-size: 12px; }
.side nav { display: flex; flex-direction: column; gap: 2px; flex: 1; overflow: auto; }
.side nav a { display: flex; align-items: center; gap: 10px; color: inherit; padding: 9px 12px; border-radius: 8px; }
.side nav a:hover { background: var(--navy-2); text-decoration: none; }
.side nav a.on { background: var(--brand); color: #fff; font-weight: 600; }
.side nav .sep { height: 1px; background: rgba(255,255,255,.1); margin: 8px 4px; }
.side nav .cap { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; opacity: .5; padding: 10px 12px 4px; }
.side .me { font-size: 12px; padding: 10px 12px; background: rgba(0,0,0,.18); border-radius: 8px; }
.side .me form { margin-top: 6px; }
.side .me button { background: none; border: 0; color: #ffb27a; padding: 0; cursor: pointer; }
.main { flex: 1; min-width: 0; padding: 26px 32px 60px; }
.impersonating { background: #fff4d6; border: 1px solid #f3d27a; padding: 8px 14px; border-radius: 8px; margin-bottom: 16px; display: flex; justify-content: space-between; align-items: center; }

.head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.head h1 { font-size: 22px; }
.head p { margin: 3px 0 0; color: var(--muted); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* Components */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.card + .card { margin-top: 16px; }
.grid > .card + .card { margin-top: 0; }
.card h3 { font-size: 15px; margin-bottom: 12px; }
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.stats { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); margin-bottom: 18px; }
.stat .n { font-size: 26px; font-weight: 700; }
.stat .l { color: var(--muted); font-size: 13px; }
a.stat:hover { border-color: var(--brand); text-decoration: none; }
a.stat { color: inherit; display: block; }

.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: #fff; color: var(--text); padding: 7px 14px; border-radius: 8px; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: #c7cbd3; text-decoration: none; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--brand-dark); }
.btn.navy { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 3px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
.link { background: none; border: 0; color: var(--brand-dark); cursor: pointer; padding: 0; }

.pill { display: inline-block; padding: 1px 9px; border-radius: 10px; font-size: 12px; background: #eef0f3; color: #374151; text-transform: capitalize; }
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.bad { background: var(--bad-bg); color: var(--bad); }

.alert { padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; }
.alert.ok { background: var(--ok-bg); color: var(--ok); }
.alert.bad { background: var(--bad-bg); color: var(--bad); }
.alert ul { margin: 0; padding-left: 18px; }

/* Forms */
.form { display: grid; gap: 14px; }
.form .row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form .row3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
label.f { display: grid; gap: 5px; font-weight: 600; font-size: 13px; }
label.f small { font-weight: 400; color: var(--muted); }
.in, select.in, textarea.in { width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; font-weight: 400; }
.in:focus { outline: 2px solid #ffd2b0; border-color: var(--brand); }
.check { display: flex; gap: 8px; align-items: center; font-weight: 400; }
.inline { display: flex; gap: 8px; align-items: end; flex-wrap: wrap; }
.inline .in { width: auto; }

/* Tables */
.tbl-wrap { overflow: auto; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }
.tbl-wrap.tall { max-height: calc(100vh - 260px); }
table.tbl { border-collapse: collapse; width: 100%; font-size: 13px; }
.tbl th, .tbl td { padding: 9px 12px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
.tbl td.wrap { white-space: normal; }
.tbl th { background: #f7f8fb; font-weight: 600; position: sticky; top: 0; z-index: 1; }
.tbl tr:hover td { background: #fbf8f5; }
.tbl tr.sel td { background: var(--brand-soft); }
.tbl .num { text-align: right; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.empty { text-align: center; padding: 50px 20px; color: var(--muted); }
.empty h2 { color: var(--text); font-size: 18px; margin-bottom: 6px; }
.pagination { margin-top: 14px; }
.pagination nav > div:first-child { display: none; }
.kv { display: grid; grid-template-columns: minmax(90px, max-content) 1fr; word-break: break-word; gap: 6px 12px; }
.kv > div:nth-child(odd) { color: var(--muted); }

/* Data explorer (client) */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; flex-wrap: wrap; }
.tabs button { background: none; border: 0; padding: 10px 14px; cursor: pointer; border-bottom: 2px solid transparent; color: var(--muted); font-weight: 600; }
.tabs button.on { color: var(--brand-dark); border-color: var(--brand); }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.toolbar .search { flex: 1; min-width: 200px; }
.chip { display: inline-flex; gap: 6px; align-items: center; padding: 5px 10px; border: 1px solid var(--line); border-radius: 16px; background: #fff; font-size: 13px; cursor: pointer; user-select: none; }
.split { display: grid; grid-template-columns: 290px 1fr; gap: 14px; align-items: start; }
.picker { max-height: calc(100vh - 230px); display: flex; flex-direction: column; padding: 12px; }
.picker .list { overflow: auto; flex: 1; margin: 8px 0; }
.pick { display: flex; gap: 8px; align-items: center; padding: 6px; border-radius: 6px; cursor: pointer; }
.pick:hover { background: var(--brand-soft); }
.pick .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pick .cnt { margin-left: auto; color: var(--muted); font-size: 12px; }
.sw { width: 10px; height: 10px; border-radius: 50%; background: #cfd4dc; flex: none; }
.more { padding: 10px; text-align: center; color: var(--muted); }

.qr-box { display: grid; grid-template-columns: 300px 1fr; gap: 26px; align-items: center; }
.qr { width: 280px; height: 280px; border: 1px solid var(--line); border-radius: 12px; display: flex; align-items: center; justify-content: center; background: #fff; }
.qr img { width: 264px; height: 264px; }
.steps { margin: 0; padding-left: 20px; line-height: 2; }
.spinner { display: inline-block; width: 16px; height: 16px; border: 2px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -3px; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: #1f2937; color: #fff; padding: 10px 18px; border-radius: 10px; z-index: 50; }

/* Login */
.login { min-height: 100vh; display: grid; grid-template-columns: 1fr 1fr; }
.login .art { background: var(--navy); display: flex; flex-direction: column; justify-content: center; align-items: center; color: #d5dcef; padding: 40px; text-align: center; }
.login .art img { width: 160px; margin-bottom: 22px; }
.login .art h2 { color: #fff; font-size: 26px; }
.login .box { display: flex; align-items: center; justify-content: center; padding: 30px; }
.login .box .card { width: 100%; max-width: 380px; padding: 28px; }

@media (max-width: 900px) {
  .shell { flex-direction: column; }
  .side { width: 100%; height: auto; position: static; }
  .side nav { flex-direction: row; flex-wrap: wrap; }
  .main { padding: 18px 16px 40px; }
  .g2, .g3, .split, .qr-box, .login, .form .row2, .form .row3 { grid-template-columns: 1fr; }
  .login .art { display: none; }
}

/* "hidden" must win over display rules like .btn { display: inline-flex } */
[hidden] { display: none !important; }
