:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --primary-soft: #eef2ff;
  --success: #15803d;
  --success-soft: #dcfce7;
  --warning: #b45309;
  --warning-soft: #fef3c7;
  --danger: #b91c1c;
  --danger-soft: #fee2e2;
  --sidebar: #0f172a;
  --sidebar-2: #1e293b;
  --sidebar-muted: #94a3b8;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 10px 30px rgba(15, 23, 42, .07);
  --sidebar-w: 260px;
}

*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, p { margin: 0; }
button, input, select { font: inherit; }
code {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1px 5px;
  font-size: .85em;
}

.is-hidden { display: none !important; }
.muted { color: var(--muted); }
.ta-right { text-align: right; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 9px 16px;
  font-weight: 600;
  font-size: .9rem;
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .05s, box-shadow .15s;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .6; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 6px 16px rgba(79, 70, 229, .25); }
.btn-primary:hover { background: var(--primary-dark); }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--text); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.btn-danger:hover { background: #fecaca; }
.btn-sm { padding: 6px 12px; font-size: .82rem; border-radius: 8px; }
.btn-block { width: 100%; }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

/* ---------- Brand ---------- */
.brand { display: flex; align-items: center; gap: 10px; }
.brand-icon { font-size: 1.5rem; line-height: 1; }
.brand-name { font-size: 1.05rem; font-weight: 500; letter-spacing: -.01em; color: #fff; }
.brand-name b { font-weight: 800; }
.brand-lg .brand-name { color: var(--text); font-size: 1.25rem; }
.brand-lg .brand-icon { font-size: 2rem; }

/* ---------- Auth ---------- */
.auth-screen {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 28px;
  background:
    radial-gradient(circle at 15% 15%, rgba(79, 70, 229, .14), transparent 45%),
    radial-gradient(circle at 85% 85%, rgba(14, 165, 233, .12), transparent 45%),
    var(--bg);
}
.auth-card {
  width: min(430px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 34px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.auth-lead { font-size: .92rem; }
.auth-hint { font-size: .78rem; color: var(--muted); line-height: 1.5; }
.auth-footer { font-size: .78rem; color: var(--muted); }

.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.tab {
  border: 0;
  background: transparent;
  border-radius: 9px;
  padding: 8px;
  font-weight: 600;
  font-size: .88rem;
  color: var(--muted);
  cursor: pointer;
  transition: background .15s, color .15s, box-shadow .15s;
}
.tab.is-active { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(15, 23, 42, .12); }

.auth-form { display: flex; flex-direction: column; gap: 14px; }

/* ---------- Fields ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: .82rem; font-weight: 600; color: var(--muted); }
.field input,
.field select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.field input:focus,
.field select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, .15);
}
.field input::placeholder { color: #94a3b8; }
.field-inline { flex-direction: row; align-items: center; gap: 10px; }
.field-inline input { width: auto; }

/* ---------- App shell ---------- */
.app { min-height: 100vh; }

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar-w);
  background: var(--sidebar);
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  gap: 26px;
  z-index: 40;
  transition: transform .22s ease;
}
.sidebar .brand { padding: 0 8px; }

.nav { display: flex; flex-direction: column; gap: 4px; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--sidebar-muted);
  padding: 11px 12px;
  border-radius: 10px;
  font-weight: 600;
  font-size: .9rem;
  text-align: left;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.nav-item:hover { background: var(--sidebar-2); color: #fff; }
.nav-item.is-active { background: var(--primary); color: #fff; }
.nav-ico { width: 20px; text-align: center; }

.sidebar-footer { margin-top: auto; display: flex; flex-direction: column; gap: 12px; }
.user-box {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-radius: 12px;
  background: var(--sidebar-2);
}
.avatar {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-weight: 700;
  flex: 0 0 auto;
}
.user-meta { display: flex; flex-direction: column; min-width: 0; }
.user-meta strong { color: #fff; font-size: .85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.role-badge {
  align-self: flex-start;
  margin-top: 3px;
  font-size: .68rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: #c7d2fe;
}
.sidebar-footer .btn-ghost { color: #cbd5e1; border-color: #334155; }
.sidebar-footer .btn-ghost:hover { background: var(--sidebar-2); color: #fff; }

.main { margin-left: var(--sidebar-w); min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 20px 30px;
  background: rgba(244, 246, 251, .88);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.topbar-title { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.topbar-title h1 { font-size: 1.35rem; letter-spacing: -.02em; }
.topbar-title .muted { font-size: .84rem; }
.topbar-title { flex: 1; }
.pill {
  display: inline-flex;
  align-items: center;
  padding: 5px 12px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary-dark);
  font-size: .75rem;
  font-weight: 700;
  letter-spacing: .04em;
}
.menu-btn { display: none; }

.view { padding: 26px 30px 48px; display: flex; flex-direction: column; gap: 22px; }

.scrim {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .45);
  z-index: 30;
}

/* ---------- Cards / stats ---------- */
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.stat {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  text-align: left;
  cursor: pointer;
  transition: transform .12s, box-shadow .15s;
}
.stat:hover { transform: translateY(-2px); box-shadow: 0 12px 30px rgba(15, 23, 42, .1); }
.stat-top { display: flex; align-items: center; justify-content: space-between; }
.stat-ico { font-size: 1.2rem; }
.stat-value { font-size: 1.9rem; font-weight: 800; letter-spacing: -.03em; line-height: 1; }
.stat-label { font-size: .82rem; color: var(--muted); font-weight: 600; }

.grid-2 { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr); gap: 18px; align-items: start; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
}
.card-head h2 { font-size: 1rem; letter-spacing: -.01em; }
.card-body { padding: 18px; }

.quick-actions { display: flex; flex-direction: column; gap: 10px; padding: 16px; }
.quick {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  font-weight: 600;
  font-size: .9rem;
  text-align: left;
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
.quick:hover { background: var(--primary-soft); border-color: #c7d2fe; }

/* ---------- Toolbar ---------- */
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap; }
.search {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 220px;
  max-width: 420px;
  padding: 9px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.search input { flex: 1; border: 0; outline: none; background: transparent; color: var(--text); min-width: 0; }

.segmented { display: inline-flex; gap: 4px; padding: 4px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; }
.segmented button {
  border: 0;
  background: transparent;
  padding: 7px 14px;
  border-radius: 8px;
  font-size: .84rem;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
}
.segmented button.is-active { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(15, 23, 42, .12); }

/* ---------- Table ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .88rem; }
.table th {
  text-align: left;
  padding: 12px 18px;
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table td { padding: 13px 18px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: #fbfcff; }
.table .actions { display: flex; gap: 8px; justify-content: flex-end; }
.table .cell-main { display: flex; flex-direction: column; gap: 2px; }
.table .cell-main small { color: var(--muted); }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: .74rem;
  font-weight: 700;
  white-space: nowrap;
}
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-neutral { background: var(--surface-2); color: var(--muted); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }

/* ---------- Empty / loading ---------- */
.empty { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 38px 18px; text-align: center; color: var(--muted); }
.empty-ico { font-size: 1.8rem; }
.empty strong { color: var(--text); }
.loading { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 60px 0; color: var(--muted); font-weight: 600; }
.spinner {
  width: 20px; height: 20px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(15, 23, 42, .5);
  backdrop-filter: blur(3px);
  animation: fade .15s ease;
}
.modal {
  width: min(460px, 100%);
  max-height: 90vh;
  overflow-y: auto;
  background: var(--surface);
  border-radius: 18px;
  box-shadow: 0 24px 70px rgba(15, 23, 42, .3);
  animation: pop .18s ease;
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-head h2 { font-size: 1.05rem; }
.modal-body { padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.modal-text { color: var(--muted); line-height: 1.55; font-size: .92rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; }
.form-error {
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--danger-soft);
  color: var(--danger);
  font-size: .84rem;
  font-weight: 600;
}
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } }

/* ---------- Toasts ---------- */
.toast-root {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 80;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: min(360px, calc(100vw - 36px));
}
.toast {
  padding: 12px 16px;
  border-radius: 12px;
  background: var(--text);
  color: #fff;
  font-size: .86rem;
  font-weight: 600;
  box-shadow: 0 12px 30px rgba(15, 23, 42, .25);
  animation: slide .2s ease;
  transition: opacity .25s, transform .25s;
}
.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }
.toast.is-leaving { opacity: 0; transform: translateX(12px); }
@keyframes slide { from { opacity: 0; transform: translateX(12px); } }

/* ---------- Responsive ---------- */
@media (max-width: 1024px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-2 { grid-template-columns: 1fr; }
}

@media (max-width: 860px) {
  .sidebar { transform: translateX(-100%); box-shadow: 0 0 50px rgba(0, 0, 0, .35); }
  .app.nav-open .sidebar { transform: translateX(0); }
  .app.nav-open .scrim { display: block; }
  .main { margin-left: 0; }
  .menu-btn { display: inline-grid; }
  .topbar { padding: 14px 18px; }
  .view { padding: 18px 18px 40px; }
  .topbar-title h1 { font-size: 1.15rem; }
  .topbar-title .muted { display: none; }
}

@media (max-width: 560px) {
  .stats { grid-template-columns: 1fr; }
  .auth-card { padding: 26px 22px; }
  .toolbar { flex-direction: column; align-items: stretch; }
  .search { max-width: none; }
  .segmented { width: 100%; }
  .segmented button { flex: 1; }
  .topbar { gap: 10px; }
  .pill { display: none; }
}