*,*::before,*::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }

body {
  font-family: var(--font-family);
  font-size: var(--font-base);
  color: var(--text-primary);
  background: var(--surface-bg);
  min-height: 100vh;
  line-height: 1.6;
}

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--scrollbar-track); }
::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: 3px; }

/* ── App Shell ─────────────────────────────────────────────────────────── */
.app-shell { display: flex; min-height: 100vh; }

/* ── Sidebar ───────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-width);
  background: var(--surface-sidebar);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  overflow-y: auto;
  overflow-x: hidden;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0 1rem;
  height: var(--topbar-height);
  border-bottom: 1px solid rgba(255,255,255,0.06);
  flex-shrink: 0;
}
.sidebar-logo svg { width: 26px; height: 26px; color: var(--color-primary); flex-shrink: 0; }
.sidebar-logo span {
  font-size: var(--font-md);
  font-weight: 700;
  color: #fff;
  letter-spacing: -0.01em;
}

.sidebar-nav { flex: 1; padding: 0.75rem; display: flex; flex-direction: column; gap: 2px; }

.nav-section {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  padding: 0.75rem 0.5rem 0.25rem;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-size: var(--font-sm);
  font-weight: 500;
  text-decoration: none;
  transition: background var(--transition), color var(--transition);
}
.nav-link:hover { background: var(--surface-hover); color: var(--text-primary); }
.nav-link.active { background: var(--color-primary-muted); color: var(--color-primary); font-weight: 600; }
.nav-link svg { width: 15px; height: 15px; flex-shrink: 0; }

.sidebar-footer {
  padding: 0.75rem;
  border-top: 1px solid var(--border-color);
  font-size: var(--font-xs);
  color: var(--text-muted);
  text-align: center;
}

/* ── Topbar ────────────────────────────────────────────────────────────── */
.topbar {
  height: var(--topbar-height);
  background: var(--surface-topbar);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  position: fixed;
  top: 0; left: var(--sidebar-width); right: 0;
  z-index: 99;
}
.topbar-title { font-size: var(--font-md); font-weight: 600; color: var(--text-primary); }
.topbar-right { display: flex; align-items: center; gap: 1rem; }
.user-badge { display: flex; align-items: center; gap: 0.5rem; font-size: var(--font-sm); color: var(--text-secondary); }
.user-avatar {
  width: 28px; height: 28px;
  background: var(--color-primary-muted);
  color: var(--color-primary);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.65rem; font-weight: 700;
}
.topbar-logout {
  font-size: var(--font-sm);
  color: var(--text-muted);
  text-decoration: none;
  padding: 0.3rem 0.6rem;
  border-radius: var(--radius-sm);
  transition: color var(--transition), background var(--transition);
}
.topbar-logout:hover { color: var(--color-danger); background: var(--color-danger-muted); }

/* ── Theme Toggle ──────────────────────────────────────────────────────── */
.theme-toggle {
  background: none; border: none; cursor: pointer;
  color: var(--text-muted);
  padding: 0.3rem;
  border-radius: var(--radius-sm);
  transition: color var(--transition);
  display: flex; align-items: center;
}
.theme-toggle:hover { color: var(--text-primary); }
.theme-toggle svg { width: 16px; height: 16px; }

/* ── Main Content ──────────────────────────────────────────────────────── */
.main-content {
  margin-left: var(--sidebar-width);
  margin-top: var(--topbar-height);
  flex: 1;
  padding: 1.75rem;
  min-height: calc(100vh - var(--topbar-height));
}

/* ── Page Header ───────────────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
  gap: 0.75rem;
}
.page-header h1 { font-size: var(--font-xl); font-weight: 700; color: var(--text-primary); }
.page-header p { font-size: var(--font-sm); color: var(--text-muted); margin-top: 0.2rem; }

/* ── Cards ─────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border-color);
}
.card-header h2 { font-size: var(--font-md); font-weight: 600; }

/* ── Stat Cards ────────────────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.stat-card {
  background: var(--surface-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.stat-card-icon { width: 32px; height: 32px; border-radius: var(--radius-sm); display: flex; align-items: center; justify-content: center; margin-bottom: 0.5rem; }
.stat-card-icon svg { width: 18px; height: 18px; }
.stat-card-value { font-size: 1.6rem; font-weight: 700; color: var(--text-primary); line-height: 1; }
.stat-card-label { font-size: var(--font-sm); color: var(--text-muted); }
.stat-card-sub { font-size: var(--font-xs); color: var(--text-muted); margin-top: 0.25rem; }

/* ── Buttons ───────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 0.4rem;
  padding: 0.45rem 0.9rem;
  border-radius: var(--radius-sm);
  font-size: var(--font-sm); font-weight: 600;
  cursor: pointer; text-decoration: none;
  border: none; transition: background var(--transition), color var(--transition), opacity var(--transition);
  white-space: nowrap;
}
.btn svg { width: 14px; height: 14px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--color-primary); color: #fff; }
.btn-primary:hover { background: var(--color-primary-hover); }
.btn-danger  { background: var(--color-danger); color: #fff; }
.btn-danger:hover  { opacity: 0.85; }
.btn-ghost   { background: transparent; color: var(--text-secondary); border: 1px solid var(--border-color); }
.btn-ghost:hover   { background: var(--surface-hover); color: var(--text-primary); }
.btn-sm { padding: 0.3rem 0.65rem; font-size: var(--font-xs); }
.btn-icon { padding: 0.4rem; border-radius: var(--radius-sm); background: none; border: none; cursor: pointer; color: var(--text-muted); transition: color var(--transition), background var(--transition); }
.btn-icon:hover { color: var(--text-primary); background: var(--surface-hover); }
.btn-icon svg { width: 15px; height: 15px; display: block; }

/* ── Forms ─────────────────────────────────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: 0.35rem; margin-bottom: 1rem; }
.form-group label { font-size: var(--font-sm); font-weight: 600; color: var(--text-secondary); }
.form-control {
  background: var(--surface-input);
  border: 1px solid var(--border-input);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-family);
  font-size: var(--font-sm);
  padding: 0.5rem 0.75rem;
  width: 100%;
  transition: border-color var(--transition);
}
.form-control:focus { outline: none; border-color: var(--color-primary); }
select.form-control { cursor: pointer; }

/* ── Search + Filter Bar ───────────────────────────────────────────────── */
.toolbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}
.search-wrap { position: relative; flex: 1; min-width: 200px; max-width: 380px; }
.search-wrap svg { position: absolute; left: 0.6rem; top: 50%; transform: translateY(-50%); width: 15px; height: 15px; color: var(--text-muted); pointer-events: none; }
.search-wrap input { padding-left: 2rem; }

/* ── Table ─────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: var(--font-sm); }
th {
  text-align: left;
  font-size: var(--font-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
}
td {
  padding: 0.65rem 0.75rem;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-primary);
  vertical-align: middle;
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--surface-hover); }
.td-muted { color: var(--text-muted); }

/* ── Badges ────────────────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 0.15rem 0.55rem;
  border-radius: 20px;
  font-size: var(--font-xs);
  font-weight: 600;
  white-space: nowrap;
}
.badge-success { background: var(--color-success-muted); color: var(--color-success); }
.badge-warning { background: var(--color-warning-muted); color: var(--color-warning); }
.badge-danger  { background: var(--color-danger-muted);  color: var(--color-danger); }
.badge-info    { background: var(--color-info-muted);    color: var(--color-info); }
.badge-muted   { background: var(--color-muted-bg);      color: var(--color-muted); }

/* ── Alert / Flash ─────────────────────────────────────────────────────── */
.alert {
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  font-size: var(--font-sm);
  margin-bottom: 1rem;
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
}
.alert svg { width: 16px; height: 16px; flex-shrink: 0; margin-top: 1px; }
.alert-success { background: var(--color-success-muted); color: var(--color-success); }
.alert-error   { background: var(--color-danger-muted);  color: var(--color-danger); }
.alert-info    { background: var(--color-info-muted);    color: var(--color-info); }
.alert-warning { background: var(--color-warning-muted); color: var(--color-warning); }

/* ── Pagination ────────────────────────────────────────────────────────── */
.pagination {
  display: flex; align-items: center; gap: 0.4rem;
  margin-top: 1.25rem; flex-wrap: wrap;
}
.page-btn {
  min-width: 32px; height: 32px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm);
  font-size: var(--font-sm); font-weight: 500;
  text-decoration: none;
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  background: var(--surface-card);
  transition: background var(--transition), color var(--transition), border-color var(--transition);
  padding: 0 0.5rem;
}
.page-btn:hover { background: var(--surface-hover); color: var(--text-primary); }
.page-btn.active { background: var(--color-primary); color: #fff; border-color: var(--color-primary); font-weight: 700; }
.page-btn.disabled { opacity: 0.4; pointer-events: none; }
.page-info { font-size: var(--font-xs); color: var(--text-muted); margin-left: 0.5rem; }

/* ── Modal ─────────────────────────────────────────────────────────────── */
.modal-backdrop {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 200;
  align-items: center; justify-content: center;
  padding: 1rem;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: var(--surface-modal);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  width: 100%; max-width: 520px;
  max-height: 90vh; overflow-y: auto;
  padding: 1.5rem;
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 1.25rem;
}
.modal-header h2 { font-size: var(--font-lg); font-weight: 700; }
.modal-close { background: none; border: none; cursor: pointer; color: var(--text-muted); padding: 0.2rem; border-radius: var(--radius-sm); transition: color var(--transition); }
.modal-close:hover { color: var(--text-primary); }
.modal-close svg { width: 18px; height: 18px; display: block; }
.modal-footer { display: flex; gap: 0.5rem; justify-content: flex-end; margin-top: 1.25rem; padding-top: 1rem; border-top: 1px solid var(--border-color); }

/* ── Login Page ─────────────────────────────────────────────────────────── */
.login-wrap {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background: var(--surface-bg);
  padding: 1rem;
}
.login-card {
  background: var(--surface-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 2.5rem 2rem;
  width: 100%; max-width: 380px;
}
.login-logo {
  display: flex; flex-direction: column; align-items: center;
  gap: 0.5rem; margin-bottom: 1.75rem;
}
.login-logo svg { width: 40px; height: 40px; color: var(--color-primary); }
.login-logo h1 { font-size: var(--font-lg); font-weight: 700; }
.login-logo p { font-size: var(--font-sm); color: var(--text-muted); }

/* ── Utility ─────────────────────────────────────────────────────────────── */
.text-muted { color: var(--text-muted); }
.text-sm    { font-size: var(--font-sm); }
.text-xs    { font-size: var(--font-xs); }
.mt-1  { margin-top: 0.25rem; }
.mt-2  { margin-top: 0.5rem; }
.mt-4  { margin-top: 1rem; }
.mb-4  { margin-bottom: 1rem; }
.gap-2 { gap: 0.5rem; }
.flex  { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.w-full { width: 100%; }
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
}
.empty-state svg { width: 40px; height: 40px; margin: 0 auto 0.75rem; opacity: 0.4; }
.empty-state p { font-size: var(--font-sm); }
