:root {
  --brand: #6366f1;
  --brand-dark: #4f46e5;
  --brand-light: #818cf8;
  --bg: #f8fafc;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #64748b;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif; background: var(--bg); color: var(--text); }

.loading-spinner {
  width: 32px; height: 32px;
  border: 3px solid #e2e8f0;
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Layout ---- */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 240px; background: var(--surface); border-right: 1px solid var(--border);
  padding: 1.5rem 1rem; display: flex; flex-direction: column; gap: 0.25rem;
  position: sticky; top: 0; height: 100vh;
}
.sidebar-brand { display: flex; align-items: center; gap: 0.6rem; padding: 0.5rem 0.75rem; margin-bottom: 1rem; }
.sidebar-brand img { max-height: 32px; width: auto; }
.sidebar-brand .name { font-weight: 700; font-size: 1.05rem; }
.sidebar-nav-item {
  display: flex; align-items: center; gap: 0.65rem; padding: 0.6rem 0.85rem;
  border-radius: 0.6rem; color: var(--text-muted); font-weight: 500; cursor: pointer;
  border: none; background: transparent; text-align: left; font-size: 0.93rem; transition: all 0.15s;
}
.sidebar-nav-item:hover { background: #f1f5f9; color: var(--text); }
.sidebar-nav-item.active { background: color-mix(in srgb, var(--brand) 12%, white); color: var(--brand); }
.sidebar-nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }
.sidebar-footer { margin-top: auto; padding-top: 1rem; border-top: 1px solid var(--border); font-size: 0.8rem; color: var(--text-muted); }

.main { flex: 1; padding: 2rem 2.5rem; max-width: 100%; overflow-x: hidden; }
.page-title { font-size: 1.65rem; font-weight: 800; letter-spacing: -0.02em; margin: 0 0 0.25rem; }
.page-sub { color: var(--text-muted); margin: 0 0 1.5rem; font-size: 0.95rem; }

/* ---- Cards / Stats ---- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 1rem; padding: 1.5rem; }
.card-title { font-size: 1.05rem; font-weight: 700; margin: 0 0 1rem; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.stat-tile { background: var(--surface); border: 1px solid var(--border); border-radius: 1rem; padding: 1.25rem; }
.stat-label { font-size: 0.8rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; font-weight: 600; }
.stat-value { font-size: 1.65rem; font-weight: 800; margin-top: 0.5rem; color: var(--text); }
.stat-hint { font-size: 0.78rem; color: var(--text-muted); margin-top: 0.25rem; }

/* ---- Forms ---- */
.form-row { display: flex; flex-direction: column; gap: 0.4rem; margin-bottom: 1rem; }
.form-row label { font-size: 0.83rem; font-weight: 600; color: var(--text); }
.form-row .hint { font-size: 0.78rem; color: var(--text-muted); }
.input, input[type=text], input[type=email], input[type=password], input[type=number], input[type=url], select, textarea {
  border: 1px solid var(--border); border-radius: 0.6rem; padding: 0.6rem 0.8rem;
  font-size: 0.93rem; font-family: inherit; color: var(--text); background: white; width: 100%;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.input:focus, input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 18%, transparent);
}
textarea { resize: vertical; min-height: 90px; }

.btn { display: inline-flex; align-items: center; gap: 0.5rem; padding: 0.6rem 1.1rem; border-radius: 0.6rem; font-weight: 600; font-size: 0.9rem; border: 1px solid transparent; cursor: pointer; transition: all 0.15s; }
.btn-primary { background: var(--brand); color: white; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-secondary { background: white; color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: #f8fafc; }
.btn-danger { background: #ef4444; color: white; }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: #f1f5f9; color: var(--text); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---- Tables ---- */
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: 1rem; overflow: hidden; }
table.tbl { width: 100%; border-collapse: collapse; }
table.tbl th { text-align: left; padding: 0.85rem 1rem; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); background: #f8fafc; border-bottom: 1px solid var(--border); font-weight: 600; }
table.tbl td { padding: 1rem; border-bottom: 1px solid var(--border); font-size: 0.92rem; }
table.tbl tr:last-child td { border-bottom: none; }
table.tbl tr.clickable { cursor: pointer; }
table.tbl tr.clickable:hover { background: #f8fafc; }

.badge { display: inline-flex; align-items: center; gap: 0.3rem; padding: 0.18rem 0.55rem; border-radius: 999px; font-size: 0.75rem; font-weight: 600; }
.badge-ok { background: #dcfce7; color: #166534; }
.badge-muted { background: #f1f5f9; color: #475569; }
.badge-warn { background: #fef3c7; color: #92400e; }

/* ---- Auth screen ---- */
.auth-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1rem; background: linear-gradient(135deg, color-mix(in srgb, var(--brand) 8%, #f8fafc), #ffffff 60%); }
.auth-card { background: white; border-radius: 1.25rem; padding: 2.5rem; max-width: 420px; width: 100%; box-shadow: 0 20px 60px -20px rgba(15,23,42,0.18); border: 1px solid var(--border); }
.auth-logo { display: flex; align-items: center; justify-content: center; margin-bottom: 1.5rem; }
.auth-logo img { max-height: 56px; width: auto; }
.auth-title { font-size: 1.5rem; font-weight: 800; text-align: center; margin: 0 0 0.5rem; }
.auth-sub { text-align: center; color: var(--text-muted); margin: 0 0 1.75rem; font-size: 0.95rem; }

/* ---- Pack pricing ---- */
.pack-card { border: 1px solid var(--border); border-radius: 1rem; padding: 1.25rem; background: white; }
.pack-card h4 { margin: 0 0 0.25rem; font-size: 1.05rem; font-weight: 700; }
.pack-card .pack-quota { color: var(--text-muted); font-size: 0.88rem; margin-bottom: 1rem; }
.pack-card .pack-wholesale { font-size: 0.82rem; color: var(--text-muted); margin-top: 0.4rem; }
.pack-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 1rem; }

/* ---- Misc ---- */
.row { display: flex; gap: 0.75rem; align-items: center; }
.between { display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
.muted { color: var(--text-muted); font-size: 0.88rem; }
.error-banner { background: #fee2e2; color: #991b1b; padding: 0.75rem 1rem; border-radius: 0.6rem; font-size: 0.9rem; margin-bottom: 1rem; }
.success-banner { background: #dcfce7; color: #166534; padding: 0.75rem 1rem; border-radius: 0.6rem; font-size: 0.9rem; margin-bottom: 1rem; }
