:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #0f1419;
  --muted: #596170;
  --faint: #8a93a2;
  --line: #e8ebef;
  --line-soft: #f0f2f5;
  --brand: #4f46e5;
  --brand-ink: #4338ca;
  --green: #15803d; --green-bg: #e7f6ec;
  --amber: #b45309; --amber-bg: #fdf1de;
  --blue: #1d4ed8; --blue-bg: #e7eefb;
  --red: #b42318; --red-bg: #fdeaea;
  --radius: 12px;
  --shadow-sm: 0 1px 2px rgba(15,20,25,.05);
  --shadow: 0 4px 16px rgba(15,20,25,.06);
  --shadow-lg: 0 24px 60px -18px rgba(15,20,25,.22);
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: var(--font); color: var(--ink); background: var(--bg); -webkit-font-smoothing: antialiased; line-height: 1.5; }
a { color: var(--brand-ink); text-decoration: none; }
h1,h2,h3,h4 { letter-spacing: -.01em; }

/* ── Login ── */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow-lg); padding: 32px 30px; }
.login-card .brand { display: flex; align-items: center; gap: 9px; font-weight: 700; font-size: 17px; margin-bottom: 22px; }
.login-card h1 { font-size: 21px; margin: 0 0 4px; }
.login-card .sub { color: var(--muted); font-size: 14px; margin: 0 0 22px; }

/* ── App shell ── */
.shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar { background: #0d1117; color: #c9d1d9; padding: 18px 14px; display: flex; flex-direction: column; }
.sidebar .brand { display: flex; align-items: center; gap: 9px; font-weight: 700; font-size: 16px; color: #fff; padding: 6px 8px 18px; }
.sidebar .brand img { height: 26px; width: auto; }
.side-nav { display: flex; flex-direction: column; gap: 2px; }
.side-nav a { display: flex; align-items: center; gap: 11px; padding: 10px 12px; border-radius: 9px; color: #9aa4b2; font-size: 14.5px; font-weight: 500; cursor: pointer; }
.side-nav a svg { flex: none; }
.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; border-top: 1px solid rgba(255,255,255,.08); padding-top: 14px; }
.side-user { display: flex; align-items: center; gap: 10px; padding: 6px 8px; }
.side-user .avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--brand); display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 13px; flex: none; }
.side-user .who { min-width: 0; }
.side-user .who .nm { font-size: 13.5px; color: #fff; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side-user .who .rl { font-size: 11.5px; color: #8a93a2; text-transform: capitalize; }
.side-foot button { width: 100%; margin-top: 8px; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { height: 64px; background: var(--panel); border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; padding: 0 28px; position: sticky; top: 0; z-index: 5; }
.topbar h1 { font-size: 19px; margin: 0; }
.content { padding: 28px; }

/* ── Buttons ── */
.btn { display: inline-flex; align-items: center; gap: 7px; padding: 9px 15px; border-radius: 9px; background: var(--ink); color: #fff; font-weight: 600; font-size: 14px; border: 1px solid var(--ink); cursor: pointer; font-family: inherit; transition: opacity .15s ease; white-space: nowrap; }
.btn:hover { opacity: .9; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.brand { background: var(--brand); border-color: var(--brand); }
.btn.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.btn.ghost:hover { background: var(--bg); opacity: 1; }
.btn.danger { background: var(--red); border-color: var(--red); }
.btn.sm { padding: 6px 11px; font-size: 13px; border-radius: 8px; }
.btn.block { width: 100%; justify-content: center; padding: 11px; }

/* ── Cards / stats ── */
.cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 24px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow-sm); }
.stat .k { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--faint); }
.stat .v { font-size: 28px; font-weight: 700; letter-spacing: -.02em; margin-top: 4px; }
.stat .sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-sm); overflow: hidden; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.panel-head h2 { font-size: 16px; margin: 0; }
.panel-head .tools { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ── Table ── */
table.tbl { width: 100%; border-collapse: collapse; }
table.tbl th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--faint); font-weight: 600; padding: 11px 20px; border-bottom: 1px solid var(--line); background: var(--bg); }
table.tbl td { padding: 13px 20px; border-bottom: 1px solid var(--line-soft); font-size: 14px; vertical-align: middle; }
table.tbl tr:last-child td { border-bottom: 0; }
table.tbl tr.clickable { cursor: pointer; }
table.tbl tr.clickable:hover td { background: #fafbfc; }
.muted { color: var(--muted); }
.faint { color: var(--faint); font-size: 12.5px; }

/* ── Badges / pills ── */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge.green { background: var(--green-bg); color: var(--green); }
.badge.amber { background: var(--amber-bg); color: var(--amber); }
.badge.blue { background: var(--blue-bg); color: var(--blue); }
.badge.red { background: var(--red-bg); color: var(--red); }
.badge.gray { background: var(--line-soft); color: var(--muted); }

/* ── Forms ── */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--ink); }
.field input, .field select { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 9px; font-size: 14px; font-family: inherit; background: #fff; color: var(--ink); }
.field input:focus, .field select:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(79,70,229,.12); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ── Filter inputs ── */
.inp { padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; font-size: 13px; font-family: inherit; color: var(--ink); background: #fff; }
.inp:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(79, 70, 229, .12); }

/* ── Filters ── */
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; background: #fff; }
.seg button { border: 0; background: transparent; padding: 8px 14px; font-size: 13px; font-weight: 600; color: var(--muted); cursor: pointer; font-family: inherit; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.active { background: var(--brand); color: #fff; }

/* ── Modal ── */
.modal-back { position: fixed; inset: 0; background: rgba(13,17,23,.45); display: grid; place-items: center; z-index: 40; padding: 24px; }
.modal { background: var(--panel); border-radius: 16px; box-shadow: var(--shadow-lg); width: 100%; max-width: 560px; max-height: 88vh; overflow: auto; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px; border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0; font-size: 17px; }
.modal-head .x { background: none; border: 0; font-size: 22px; line-height: 1; color: var(--faint); cursor: pointer; }
.modal-body { padding: 22px; }
.modal-foot { padding: 16px 22px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 10px; }

/* ── Toast ── */
#toast { position: fixed; bottom: 22px; right: 22px; z-index: 60; display: flex; flex-direction: column; gap: 10px; }
.toast { background: var(--ink); color: #fff; padding: 12px 16px; border-radius: 10px; font-size: 14px; box-shadow: var(--shadow-lg); max-width: 360px; }
.toast.ok { background: var(--green); }
.toast.err { background: var(--red); }

/* ── Misc ── */
.empty { padding: 40px 20px; text-align: center; color: var(--muted); }
.err-text { color: var(--red); font-size: 13px; margin: 8px 0 0; min-height: 18px; }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 8px 14px; font-size: 14px; }
.kv .k { color: var(--muted); }
.loading { padding: 40px; text-align: center; color: var(--faint); }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { flex-direction: row; align-items: center; overflow-x: auto; }
  .side-nav { flex-direction: row; }
  .side-foot { display: none; }
  .cards { grid-template-columns: repeat(2, 1fr); }
}
