:root {
  --navy: #0f1e4a;
  --blue: #1e3a8a;
  --blue2: #2563eb;
  --gold: #fcd34d;
  --bg: #f1f5f9;
  --card: #ffffff;
  --line: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --green: #15803d;
  --red: #b91c1c;
  --orange: #c2410c;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 14px; color: var(--text); background: var(--bg);
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--red); margin: 4px 0 0; }
.b { color: #fff; } .h { color: var(--gold); }

/* login */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px;
  background: linear-gradient(135deg, var(--blue2), var(--navy)); }
.login-card { width: 100%; max-width: 380px; background: var(--card); border-radius: 16px;
  padding: 28px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.login-card h1 { margin: 10px 0 2px; font-size: 22px; color: var(--navy); }
.login-card h1 .b { color: var(--navy); }
.login-card h1 .h { color: #d97706; }
.login-logo { width: 56px; height: 56px; border-radius: 14px; }
label { display: block; margin: 12px 0 0; font-weight: 600; font-size: 13px; color: #334155; }
input[type=text], input[type=tel], input[type=password], input[type=number], input[type=url], input[type=date], input[type=search] {
  display: block; width: 100%; margin-top: 6px; padding: 10px 12px; font: inherit;
  border: 1px solid #cbd5e1; border-radius: 10px; background: #fff; }
input:focus { outline: 2px solid #93c5fd; border-color: var(--blue2); }

/* buttons */
.btn { font: inherit; font-weight: 600; border: 1px solid var(--line); background: #fff;
  color: var(--text); padding: 9px 14px; border-radius: 10px; cursor: pointer; }
.btn:hover { background: #f8fafc; }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.primary:hover { background: #1d4ed8; }
.btn.danger { color: var(--red); border-color: #fecaca; }
.btn.danger.solid { background: var(--red); color: #fff; border-color: var(--red); }
.btn.ghost { background: transparent; color: #cbd5e1; border-color: #334155; }
.btn.small { padding: 6px 10px; font-size: 12px; }
.btn.wide { width: 100%; margin-top: 18px; padding: 12px; }
.btn:disabled { opacity: .5; cursor: default; }

/* layout */
.app { display: flex; min-height: 100%; }
.sidebar { width: 236px; flex: none; background: var(--navy); color: #fff; display: flex;
  flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; padding: 20px 18px; font-size: 19px; font-weight: 900; }
.brand img { width: 36px; height: 36px; border-radius: 10px; }
#nav { display: flex; flex-direction: column; padding: 4px 10px; gap: 2px; }
#nav a { padding: 11px 12px; border-radius: 10px; color: #cbd5e1; cursor: pointer; font-weight: 500; }
#nav a:hover { background: rgba(255,255,255,.07); }
#nav a.active { background: rgba(255,255,255,.14); color: #fff; font-weight: 700; box-shadow: inset 3px 0 0 var(--gold); }
.side-foot { margin-top: auto; padding: 14px 18px; border-top: 1px solid rgba(255,255,255,.1);
  display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.side-foot .muted { color: #94a3b8; }
.main { flex: 1; min-width: 0; padding: 24px 28px 48px; max-width: 1280px; }
h2 { margin: 0 0 16px; font-size: 22px; }
h3 { margin: 0 0 4px; font-size: 16px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head h2 { margin: 0; }
.search { max-width: 340px; margin: 0 !important; }

/* panels, cards, tables */
.panel { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 18px; margin-bottom: 16px; }
.panel.no-pad { padding: 0; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; margin-bottom: 16px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 16px; }
.card .n { font-size: 28px; font-weight: 800; color: var(--blue); margin-top: 4px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase;
  letter-spacing: .03em; padding: 12px 14px; border-bottom: 1px solid var(--line); background: #f8fafc; white-space: nowrap; }
td { padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
tbody tr.click { cursor: pointer; }
tbody tr.click:hover { background: #f8fafc; }
td .sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.empty { text-align: center; color: var(--muted); padding: 28px; }
.badge { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge.green { background: #dcfce7; color: var(--green); }
.badge.red { background: #fee2e2; color: var(--red); }
.badge.orange { background: #ffedd5; color: var(--orange); }
.badge.blue { background: #dbeafe; color: var(--blue); }
.badge.gray { background: #f1f5f9; color: #475569; }
.code { font-family: Consolas, Menlo, monospace; font-weight: 700; letter-spacing: .04em; }

/* forms */
.row-form { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.row-form label { margin: 0; }
.row-form .grow { flex: 1; min-width: 220px; }
.row-form input[type=number] { width: 110px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 600; margin-top: 12px; }
form .btn.primary { margin-top: 14px; }

/* dialog */
dialog { border: 0; border-radius: 16px; padding: 0; width: min(720px, calc(100vw - 32px)); box-shadow: 0 30px 80px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(15, 23, 42, .5); }
#dialog-body { padding: 22px; max-height: calc(100vh - 80px); overflow: auto; }
.dlg-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 12px; }
.dlg-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; justify-content: flex-end; }
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 6px 12px; margin: 8px 0; }
.kv div:nth-child(odd) { color: var(--muted); }
.secret { font-family: Consolas, Menlo, monospace; font-size: 20px; font-weight: 800; background: #f1f5f9;
  border: 1px dashed #94a3b8; padding: 12px; border-radius: 10px; text-align: center; margin: 12px 0; user-select: all; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #0f172a; color: #fff;
  padding: 12px 18px; border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,.25); z-index: 10; max-width: 90vw; }

@media (max-width: 760px) {
  .app { flex-direction: column; }
  .sidebar { width: auto; height: auto; position: static; }
  #nav { flex-direction: row; overflow-x: auto; }
  #nav a { white-space: nowrap; }
  .side-foot { display: none; }
  .main { padding: 16px; }
  .grid2 { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 1fr; }
}
