:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #f9fafc;
  --ink: #1a2233;
  --muted: #66748c;
  --faint: #98a3b8;
  --line: #e6e9f0;
  --line-strong: #d3d9e4;
  --brand: #4f46e5;
  --brand-ink: #4338ca;
  --brand-soft: #eef0fe;
  --green: #0f9d6c;
  --green-soft: #e5f6ef;
  --amber: #b7791f;
  --amber-soft: #fbf2df;
  --red: #d1483a;
  --red-soft: #fbecea;
  --shadow: 0 1px 2px rgba(20, 30, 60, .05), 0 4px 16px rgba(20, 30, 60, .04);
  --radius: 12px;
  --sidebar: 236px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font-family: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--brand-ink); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- App shell ---------- */
.app { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: 100vh; }

.sidebar {
  background: #14192b;
  color: #c8cfe0;
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: sticky;
  top: 0;
  align-self: start;
  height: 100vh;
  overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; }
.brand .logo {
  width: 30px; height: 30px; border-radius: 8px; flex: none;
  background: linear-gradient(135deg, #6366f1, #22d3ee);
  display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 15px;
}
.brand strong { color: #fff; font-size: 15px; letter-spacing: .2px; }
.nav-label { color: #64708c; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; padding: 14px 10px 6px; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  color: #c1c9dc; padding: 9px 10px; border-radius: 8px; font-weight: 500;
}
.nav a .ico { width: 18px; text-align: center; opacity: .85; }
.nav a:hover { background: rgba(255,255,255,.06); text-decoration: none; color: #fff; }
.nav a.active { background: var(--brand); color: #fff; }
.sidebar .spacer { flex: 1; }
.side-user { border-top: 1px solid rgba(255,255,255,.08); padding-top: 12px; margin-top: 8px; font-size: 12.5px; }
.side-user .name { color: #fff; font-weight: 600; }
.side-user .role { color: #7f8aa6; }
.side-user a { color: #9aa5c0; display: inline-block; margin-top: 6px; }

/* ---------- Main ---------- */
.main { min-width: 0; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 30px; border-bottom: 1px solid var(--line); background: var(--surface);
  position: sticky; top: 0; z-index: 5;
}
.topbar h1 { margin: 0; font-size: 20px; font-weight: 650; }
.topbar .sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.content { padding: 26px 30px 60px; max-width: 1200px; }

/* ---------- Flash ---------- */
.flash { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: 10px; margin-bottom: 16px; font-size: 13.5px; border: 1px solid; }
.flash.ok { background: var(--green-soft); border-color: #b7e6d2; color: #0b6b4b; }
.flash.err { background: var(--red-soft); border-color: #f1c4bd; color: #a5271a; }
.flash.info { background: var(--brand-soft); border-color: #cdd2fb; color: var(--brand-ink); }

/* ---------- Cards ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 20px; }
.card > .card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 18px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.card > .card-head h3 { margin: 0; font-size: 15px; font-weight: 650; }
.card > .card-head .hint { color: var(--muted); font-size: 12.5px; font-weight: 400; }
.card > .card-body { padding: 18px; }
.card.pad { padding: 18px; }

.grid { display: grid; gap: 18px; }
.grid.two { grid-template-columns: 1fr 1fr; }
.grid.cols { grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }

/* ---------- Stat tiles ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 22px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.stat .k { color: var(--muted); font-size: 12.5px; display: flex; align-items: center; gap: 7px; }
.stat .v { font-size: 26px; font-weight: 680; margin-top: 8px; letter-spacing: -.01em; }
.stat .v.sm { font-size: 18px; }
.stat .foot { color: var(--faint); font-size: 12px; margin-top: 4px; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
thead th {
  text-align: left; color: var(--muted); font-weight: 600; font-size: 11.5px;
  text-transform: uppercase; letter-spacing: .04em; padding: 11px 14px;
  border-bottom: 1px solid var(--line); background: var(--surface-2); white-space: nowrap;
}
tbody td { padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td.strong { font-weight: 680; }
.mono { font-variant-numeric: tabular-nums; }

/* ---------- Badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; border: 1px solid transparent; }
.badge.green { background: var(--green-soft); color: #0b6b4b; }
.badge.amber { background: var(--amber-soft); color: #8a5a08; }
.badge.red { background: var(--red-soft); color: #a5271a; }
.badge.gray { background: #eef1f6; color: #55627a; }
.badge.brand { background: var(--brand-soft); color: var(--brand-ink); }
.badge.dot::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* ---------- Forms ---------- */
label.field { display: grid; gap: 6px; font-size: 12.5px; color: var(--muted); font-weight: 500; }
input, select, textarea {
  width: 100%; min-height: 40px; border: 1px solid var(--line-strong); border-radius: 9px;
  padding: 9px 11px; font: inherit; color: var(--ink); background: #fff;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
input[type=file] { padding: 8px; background: var(--surface-2); }
.field-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; }
.inline { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.inline > * { margin: 0; }
.help { color: var(--faint); font-size: 12px; }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; gap: 7px; justify-content: center; min-height: 40px; padding: 9px 15px; border-radius: 9px; border: 1px solid var(--brand); background: var(--brand); color: #fff; font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--brand-ink); text-decoration: none; }
.btn.sm { min-height: 32px; padding: 5px 11px; font-size: 12.5px; border-radius: 8px; }
.btn.ghost { background: #fff; color: var(--ink); border-color: var(--line-strong); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { background: var(--red); border-color: var(--red); }
.btn.danger:hover { background: #b23a2e; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }

/* ---------- Workflow steps ---------- */
.steps { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 22px; }
.step { display: flex; align-items: center; gap: 9px; padding: 10px 14px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; flex: 1; min-width: 150px; box-shadow: var(--shadow); }
.step .n { width: 22px; height: 22px; border-radius: 50%; background: #eef1f6; color: var(--muted); display: grid; place-items: center; font-size: 12px; font-weight: 700; flex: none; }
.step.done .n { background: var(--green); color: #fff; }
.step.active { border-color: var(--brand); }
.step.active .n { background: var(--brand); color: #fff; }
.step .t { font-size: 12.5px; font-weight: 600; }
.step .d { font-size: 11.5px; color: var(--muted); }

/* ---------- Misc ---------- */
.empty { text-align: center; padding: 44px 20px; color: var(--muted); }
.empty .big { font-size: 30px; margin-bottom: 8px; }
.section-title { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--faint); margin: 26px 0 10px; font-weight: 700; }
.tag-list { display: flex; gap: 6px; flex-wrap: wrap; }
.kv { display: grid; grid-template-columns: 1fr auto; gap: 6px 16px; font-size: 13px; }
.kv .k { color: var(--muted); }
.kv .v { text-align: right; font-variant-numeric: tabular-nums; }
.divider { border: 0; border-top: 1px solid var(--line); margin: 12px 0; }
.right { text-align: right; }
.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; background: radial-gradient(1200px 500px at 50% -10%, #e9ecff, var(--bg)); padding: 20px; }
.login-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); padding: 30px; }
.login-card .brand { justify-content: center; padding-bottom: 8px; }
.login-card h2 { margin: 6px 0 2px; text-align: center; font-size: 19px; }
.login-card p { text-align: center; color: var(--muted); margin: 0 0 22px; }
.login-card label.field { margin-bottom: 14px; }

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; }
  .sidebar .brand { padding: 4px 8px; }
  .nav-label, .side-user, .spacer { display: none; }
  .nav { display: flex; flex-wrap: wrap; }
  .grid.two { grid-template-columns: 1fr; }
  .content, .topbar { padding-left: 18px; padding-right: 18px; }
}
