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

:root {
  --green:    #16a34a;
  --green-l:  #dcfce7;
  --yellow:   #d97706;
  --yellow-l: #fef3c7;
  --red:      #dc2626;
  --red-l:    #fee2e2;
  --blue:     #2563eb;
  --blue-l:   #dbeafe;
  --gray-50:  #f8fafc;
  --gray-100: #f1f5f9;
  --gray-200: #e2e8f0;
  --gray-300: #cbd5e1;
  --gray-400: #94a3b8;
  --gray-500: #64748b;
  --gray-600: #475569;
  --gray-700: #334155;
  --gray-800: #1e293b;
  --gray-900: #0f172a;
  --sidebar-bg: #0f172a;
  --sidebar-w:  240px;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 4px 12px rgba(0,0,0,.06);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--gray-50);
  color: var(--gray-900);
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

/* ── Login ─────────────────────────────────────────────────── */
.login-wrap {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--gray-900) 0%, #1e3a5f 100%);
  padding: 1.5rem;
}

.login-card {
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 8px 40px rgba(0,0,0,.3);
  padding: 2.5rem 2rem;
  width: 100%;
  max-width: 380px;
}

.login-logo {
  text-align: center;
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: -.5px;
  margin-bottom: .2rem;
}
.login-logo span { color: var(--green); }
.login-badge {
  text-align: center;
  font-size: .7rem;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--gray-500);
  margin-bottom: 2rem;
}

/* ── Layout ─────────────────────────────────────────────────── */
.app {
  display: flex;
  min-height: 100dvh;
}

/* ── Sidebar ─────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  color: #fff;
  display: flex;
  flex-direction: column;
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 200;
  overflow-y: auto;
}

.sidebar-logo {
  font-size: 1.1rem;
  font-weight: 800;
  letter-spacing: -.3px;
  padding: 1.5rem 1.25rem .5rem;
  color: #fff;
}
.sidebar-logo span { color: var(--green); }
.sidebar-badge {
  font-size: .62rem;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--gray-400);
  padding: 0 1.25rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,.08);
  margin-bottom: .5rem;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: .625rem;
  padding: .6rem 1.25rem;
  font-size: .82rem;
  font-weight: 500;
  color: rgba(255,255,255,.65);
  border: none;
  background: transparent;
  cursor: pointer;
  text-align: left;
  width: 100%;
  text-decoration: none;
  border-radius: 0;
  transition: color .12s, background .12s;
}
.nav-item svg { width: 16px; height: 16px; flex-shrink: 0; }
.nav-item:hover { color: #fff; background: rgba(255,255,255,.06); }
.nav-item.active { color: #fff; background: rgba(255,255,255,.12); font-weight: 600; }

.nav-section {
  font-size: .62rem;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: rgba(255,255,255,.3);
  padding: 1rem 1.25rem .3rem;
}

.sidebar-footer {
  margin-top: auto;
  padding: 1rem 1.25rem 1.5rem;
  border-top: 1px solid rgba(255,255,255,.08);
}
.admin-name {
  font-size: .8rem;
  font-weight: 600;
  color: #fff;
  margin-bottom: .15rem;
}
.admin-email {
  font-size: .73rem;
  color: var(--gray-400);
  margin-bottom: .75rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.btn-logout {
  background: rgba(255,255,255,.08);
  border: none;
  color: rgba(255,255,255,.65);
  font-size: .78rem;
  padding: .4rem .875rem;
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
  transition: background .12s, color .12s;
}
.btn-logout:hover { background: rgba(220,38,38,.2); color: #fca5a5; }

/* ── Main content ─────────────────────────────────────────────── */
.main {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  position: sticky;
  top: 0;
  background: #fff;
  border-bottom: 1px solid var(--gray-200);
  padding: 0 1.5rem;
  height: 56px;
  display: flex;
  align-items: center;
  gap: 1rem;
  z-index: 100;
}
.topbar-title {
  font-size: .95rem;
  font-weight: 700;
  color: var(--gray-900);
}
.topbar-spacer { flex: 1; }
.topbar-admin {
  font-size: .78rem;
  color: var(--gray-500);
}

.page {
  padding: 1.5rem;
  max-width: 1200px;
}

/* ── Cards / panels ─────────────────────────────────────────────── */
.card {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}
.card-title {
  font-size: .88rem;
  font-weight: 700;
  color: var(--gray-700);
  margin-bottom: 1rem;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem;
  margin-bottom: 1.25rem;
}
.stat-card {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.1rem 1.25rem;
}
.stat-label {
  font-size: .73rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--gray-500);
  margin-bottom: .4rem;
}
.stat-value {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--gray-900);
  line-height: 1;
}
.stat-sub {
  font-size: .73rem;
  color: var(--gray-400);
  margin-top: .25rem;
}

/* ── Toolbar / filters ─────────────────────────────────────────── */
.toolbar {
  display: flex;
  gap: .625rem;
  align-items: center;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.search-input {
  flex: 1;
  min-width: 200px;
  padding: .5rem .75rem;
  border: 1.5px solid var(--gray-200);
  border-radius: 8px;
  font-size: .85rem;
  font-family: inherit;
  outline: none;
  transition: border-color .12s;
}
.search-input:focus { border-color: var(--blue); }

select.filter-select {
  padding: .5rem .75rem;
  border: 1.5px solid var(--gray-200);
  border-radius: 8px;
  font-size: .82rem;
  font-family: inherit;
  background: #fff;
  outline: none;
  cursor: pointer;
}

/* ── Table ─────────────────────────────────────────────────────── */
.tbl-wrap { overflow-x: auto; border-radius: var(--radius); box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; background: #fff; }
thead th {
  text-align: left;
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--gray-500);
  padding: .75rem 1rem;
  background: var(--gray-50);
  border-bottom: 1px solid var(--gray-200);
  white-space: nowrap;
}
tbody td {
  padding: .75rem 1rem;
  font-size: .82rem;
  border-bottom: 1px solid var(--gray-100);
  vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--gray-50); }

/* ── Badges ─────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  font-size: .68rem;
  font-weight: 700;
  padding: .2rem .55rem;
  border-radius: 99px;
  white-space: nowrap;
}
.badge-green  { background: var(--green-l);  color: #15803d; }
.badge-yellow { background: var(--yellow-l); color: #92400e; }
.badge-red    { background: var(--red-l);    color: #991b1b; }
.badge-blue   { background: var(--blue-l);   color: #1d4ed8; }
.badge-gray   { background: var(--gray-100); color: var(--gray-600); }

/* ── Buttons ─────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .5rem 1rem;
  border-radius: 8px;
  font-size: .82rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  border: 1.5px solid transparent;
  transition: opacity .12s, background .12s;
  text-decoration: none;
  white-space: nowrap;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary   { background: var(--gray-900); color: #fff; }
.btn-primary:hover { opacity: .85; }
.btn-green   { background: var(--green); color: #fff; }
.btn-green:hover { opacity: .85; }
.btn-red     { background: var(--red); color: #fff; }
.btn-red:hover { opacity: .85; }
.btn-outline  { background: #fff; color: var(--gray-700); border-color: var(--gray-200); }
.btn-outline:hover { background: var(--gray-50); }
.btn-sm { padding: .3rem .7rem; font-size: .76rem; border-radius: 6px; }

/* ── Forms ─────────────────────────────────────────────────────── */
.form-row { margin-bottom: 1rem; }
.form-label {
  display: block;
  font-size: .78rem;
  font-weight: 600;
  color: var(--gray-700);
  margin-bottom: .35rem;
}
.form-input, .form-select, .form-textarea {
  width: 100%;
  padding: .55rem .8rem;
  border: 1.5px solid var(--gray-200);
  border-radius: 8px;
  font-size: .85rem;
  font-family: inherit;
  background: #fff;
  outline: none;
  transition: border-color .12s;
}
.form-input:focus, .form-select:focus, .form-textarea:focus { border-color: var(--blue); }
.form-textarea { resize: vertical; min-height: 80px; }
.form-hint { font-size: .72rem; color: var(--gray-400); margin-top: .3rem; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
@media (max-width: 600px) { .form-grid { grid-template-columns: 1fr; } }

/* ── Modal ─────────────────────────────────────────────────────── */
.modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 500;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 8px 40px rgba(0,0,0,.2);
  width: 100%;
  max-width: 560px;
  max-height: 90dvh;
  overflow-y: auto;
}
.modal-lg { max-width: 720px; }
.modal-header {
  padding: 1.25rem 1.5rem 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-title {
  font-size: .95rem;
  font-weight: 700;
  color: var(--gray-900);
}
.modal-close {
  background: none;
  border: none;
  font-size: 1.25rem;
  cursor: pointer;
  color: var(--gray-400);
  padding: .25rem;
  line-height: 1;
}
.modal-body { padding: 1.25rem 1.5rem; }
.modal-footer {
  padding: .75rem 1.5rem 1.25rem;
  display: flex;
  gap: .625rem;
  justify-content: flex-end;
  border-top: 1px solid var(--gray-100);
}

/* ── Detail rows ─────────────────────────────────────────────────── */
.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .75rem 1.25rem;
  margin-bottom: 1rem;
}
@media (max-width: 500px) { .detail-grid { grid-template-columns: 1fr; } }
.detail-item {}
.detail-key {
  font-size: .7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--gray-400);
  margin-bottom: .2rem;
}
.detail-val {
  font-size: .85rem;
  color: var(--gray-900);
  font-weight: 500;
}

/* ── Plan cards ─────────────────────────────────────────────────── */
.plan-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1.25rem;
}
.plan-card {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
  border: 2px solid var(--gray-100);
}
.plan-card.featured { border-color: var(--green); }
.plan-name { font-size: .95rem; font-weight: 800; margin-bottom: .25rem; }
.plan-price { font-size: 1.4rem; font-weight: 800; color: var(--green); }
.plan-price span { font-size: .75rem; font-weight: 400; color: var(--gray-400); }
.plan-meta { font-size: .78rem; color: var(--gray-500); margin-top: .4rem; }

/* ── Progress bar ─────────────────────────────────────────────────── */
.progress-bar {
  height: 6px;
  background: var(--gray-100);
  border-radius: 99px;
  overflow: hidden;
  margin-top: .4rem;
}
.progress-fill {
  height: 100%;
  border-radius: 99px;
  background: var(--green);
  transition: width .3s;
}
.progress-fill.warn  { background: var(--yellow); }
.progress-fill.over  { background: var(--red); }

/* ── Toast ─────────────────────────────────────────────────────── */
#toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  background: var(--gray-900);
  color: #fff;
  padding: .7rem 1.1rem;
  border-radius: 8px;
  font-size: .82rem;
  font-weight: 500;
  box-shadow: 0 4px 16px rgba(0,0,0,.2);
  z-index: 9999;
  opacity: 0;
  transition: opacity .2s;
  pointer-events: none;
  max-width: 300px;
}
#toast.show { opacity: 1; }
#toast.error { background: var(--red); }
#toast.success { background: var(--green); }

/* ── Misc ─────────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--gray-400);
  font-size: .85rem;
}

.divider-row {
  display: flex;
  align-items: center;
  gap: .75rem;
  margin: 1rem 0;
  color: var(--gray-300);
  font-size: .75rem;
}
.divider-row::before, .divider-row::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--gray-200);
}

.spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--gray-200);
  border-top-color: var(--gray-700);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 200px;
  color: var(--gray-400);
  font-size: .85rem;
  gap: .75rem;
}

.text-link {
  color: var(--blue);
  text-decoration: none;
  font-weight: 500;
}
.text-link:hover { text-decoration: underline; }

.flex { display: flex; }
.gap-sm { gap: .5rem; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.mt-1 { margin-top: .5rem; }
.mb-1 { margin-bottom: .5rem; }

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}
.section-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--gray-900);
}

/* ── Responsive ─────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); transition: transform .25s; }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; }
  .menu-btn { display: flex !important; }
}

.menu-btn {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: .4rem;
  color: var(--gray-700);
  align-items: center;
  justify-content: center;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 199;
}
.sidebar-overlay.open { display: block; }
