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

:root {
  --bg: #f0f2f5;
  --sidebar-bg: #111827;
  --sidebar-hover: #1f2937;
  --sidebar-active: rgba(99,102,241,0.15);
  --card: #fff;
  --border: #e5e7eb;
  --text: #111827;
  --text-secondary: #6b7280;
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --primary-light: #eef2ff;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --danger-light: #fef2f2;
  --success: #22c55e;
  --success-light: #f0fdf4;
  --warning: #f59e0b;
  --warning-light: #fffbeb;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.04), 0 2px 4px rgba(0,0,0,0.03);
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ── Sidebar ─────────────────────────────────────── */

.sidebar {
  width: 240px;
  background: var(--sidebar-bg);
  color: #fff;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  z-index: 100;
  overflow-y: auto;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 20px 16px;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.3px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  margin-bottom: 8px;
}

.sidebar-brand::before {
  content: '';
  display: inline-block;
  width: 28px;
  height: 28px;
  background: var(--primary);
  border-radius: 8px;
}

.nav-section {
  padding: 0 12px;
  margin-bottom: 4px;
}

.nav-section-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: rgba(255,255,255,0.35);
  padding: 16px 8px 6px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  color: rgba(255,255,255,0.65);
  text-decoration: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.15s;
  margin-bottom: 2px;
}

.nav-link:hover {
  color: #fff;
  background: var(--sidebar-hover);
}

.nav-link.active {
  color: #fff;
  background: var(--sidebar-active);
}

.nav-link .icon {
  width: 18px;
  height: 18px;
  opacity: 0.7;
  flex-shrink: 0;
}

.nav-logout {
  margin-top: auto;
  border-top: 1px solid rgba(255,255,255,0.08);
  padding-top: 8px;
  margin-bottom: 12px;
}

/* ── Content ─────────────────────────────────────── */

.content {
  margin-left: 240px;
  padding: 28px 32px;
  flex: 1;
  min-width: 0;
  max-width: 1280px;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}

.page-header h1 {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.page-header .count {
  color: var(--text-secondary);
  font-weight: 400;
  font-size: 15px;
  margin-left: 6px;
}

h2 {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 14px;
  color: var(--text);
}

h3 {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
  margin: 14px 0 8px;
}

/* ── Cards ────────────────────────────────────────── */

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.card-header h2 { margin-bottom: 0; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}

.stat-card::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
}

.stat-card:nth-child(1)::after { background: var(--primary); }
.stat-card:nth-child(2)::after { background: var(--success); }
.stat-card:nth-child(3)::after { background: var(--warning); }
.stat-card:nth-child(4)::after { background: #8b5cf6; }

.stat-value {
  font-size: 30px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -1px;
}

.stat-label {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 2px;
  font-weight: 500;
}

.stat-sub {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 6px;
}

/* ── Bar Chart ────────────────────────────────────── */

.chart-bar-container {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 120px;
  padding-top: 8px;
}

.chart-bar-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100%;
  justify-content: flex-end;
  min-width: 0;
}

.chart-bar {
  width: 100%;
  min-height: 2px;
  background: var(--primary);
  border-radius: 2px 2px 0 0;
  transition: height 0.3s ease;
  opacity: 0.8;
}

.chart-bar-col:hover .chart-bar { opacity: 1; }

.chart-bar-label {
  font-size: 9px;
  color: var(--text-secondary);
  margin-top: 4px;
  white-space: nowrap;
}

/* ── Breakdown Lists ─────────────────────────────── */

.breakdown-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.breakdown-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.breakdown-label {
  font-size: 13px;
  font-weight: 500;
  min-width: 80px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.breakdown-bar-wrap {
  flex: 1;
  height: 8px;
  background: #f3f4f6;
  border-radius: 100px;
  overflow: hidden;
}

.breakdown-bar {
  height: 100%;
  background: var(--success);
  border-radius: 100px;
  min-width: 4px;
  transition: width 0.4s ease;
}

.breakdown-bar.bar-blue { background: var(--primary); }
.breakdown-bar.bar-purple { background: #8b5cf6; }

.breakdown-value {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  min-width: 30px;
  text-align: right;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

.grid-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 20px;
  margin-bottom: 20px;
}

/* ── Tables ───────────────────────────────────────── */

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13px;
}

thead th {
  text-align: left;
  padding: 10px 14px;
  font-weight: 600;
  color: var(--text-secondary);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
  background: #fafafa;
  position: sticky;
  top: 0;
  white-space: nowrap;
}

thead th:first-child { border-radius: var(--radius-sm) 0 0 0; }
thead th:last-child { border-radius: 0 var(--radius-sm) 0 0; }

td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

tbody tr:last-child td { border-bottom: none; }

tr.clickable {
  cursor: pointer;
  transition: background 0.1s;
}

tr.clickable:hover { background: #f8f9fb; }

.mono {
  font-family: 'SF Mono', 'JetBrains Mono', Monaco, 'Cascadia Code', 'Courier New', monospace;
  font-size: 12px;
  letter-spacing: -0.2px;
}

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-secondary);
}

.empty-state p { font-size: 14px; }

/* ── Badges ───────────────────────────────────────── */

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 100px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.2px;
  white-space: nowrap;
}

.badge-free { background: #f3f4f6; color: var(--text-secondary); }
.badge-pro { background: #dbeafe; color: #1e40af; }
.badge-pro_plus { background: #ede9fe; color: #6d28d9; }
.badge-status-active { background: var(--success-light); color: #15803d; }
.badge-status-canceled { background: var(--warning-light); color: #92400e; }
.badge-status-past_due { background: var(--danger-light); color: var(--danger); }
.badge-status-expired { background: #f3f4f6; color: var(--text-secondary); }
.badge-status-refunded { background: var(--danger-light); color: var(--danger); }

/* ── Forms ────────────────────────────────────────── */

input, select, textarea {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-family: inherit;
  color: var(--text);
  background: #fff;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input::placeholder { color: #9ca3af; }

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99,102,241,0.12);
}

input[readonly] {
  background: #f9fafb;
  color: var(--text-secondary);
}

.form-row {
  display: flex;
  gap: 10px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.form-row input, .form-row select { flex: 1; min-width: 140px; }

.form-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
  min-width: 140px;
}

.form-group label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
}

.search-form {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
}

.search-form input {
  flex: 1;
  padding: 10px 14px;
}

.comp-form {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: flex-end;
}

.comp-form select, .comp-form input { min-width: 140px; }

/* ── Buttons ──────────────────────────────────────── */

.btn, button[type="submit"] {
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  white-space: nowrap;
}

.btn:disabled, button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary, button[type="submit"] {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover, button[type="submit"]:hover {
  background: var(--primary-hover);
}

.btn-secondary {
  background: #fff;
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover { background: #f9fafb; }

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-danger:hover { background: var(--danger-hover); }

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  padding: 6px 10px;
}

.btn-ghost:hover { background: #f3f4f6; color: var(--text); }

.btn-sm { padding: 5px 10px; font-size: 12px; }

/* ── Detail Layout ────────────────────────────────── */

.detail-grid {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 10px 20px;
  align-items: baseline;
}

.detail-label {
  font-weight: 600;
  color: var(--text-secondary);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.detail-value {
  font-size: 14px;
  word-break: break-all;
}

.copyable {
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  transition: background 0.15s;
}

.copyable:hover { background: var(--primary-light); color: var(--primary); }

.muted { color: var(--text-secondary); }

/* ── Pagination ───────────────────────────────────── */

.pagination {
  display: flex;
  gap: 4px;
  margin-top: 20px;
  justify-content: center;
}

.pagination a {
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  transition: all 0.15s;
}

.pagination a:hover { background: #f3f4f6; }

.pagination a.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

/* ── Alerts & Toasts ──────────────────────────────── */

.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  font-size: 14px;
  font-weight: 500;
}

.alert-error { background: var(--danger-light); color: var(--danger); border: 1px solid #fecaca; }
.alert-success { background: var(--success-light); color: #15803d; border: 1px solid #bbf7d0; }

.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 12px 20px;
  border-radius: var(--radius);
  background: var(--sidebar-bg);
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  box-shadow: 0 10px 25px rgba(0,0,0,0.15);
  z-index: 1000;
  animation: slideUp 0.3s ease;
  opacity: 0;
  pointer-events: none;
}

.toast.show { opacity: 1; pointer-events: auto; }

@keyframes slideUp {
  from { transform: translateY(12px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* ── Login ────────────────────────────────────────── */

.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1e1b4b 0%, #312e81 50%, #4338ca 100%);
}

.login-box {
  background: var(--card);
  padding: 44px 40px;
  border-radius: 16px;
  width: 380px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.login-box h1 {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 6px;
  letter-spacing: -0.5px;
}

.login-box .subtitle {
  color: var(--text-secondary);
  font-size: 14px;
  margin-bottom: 28px;
}

.login-box input {
  width: 100%;
  margin-bottom: 16px;
  padding: 12px 14px;
  font-size: 14px;
}

.login-box button {
  width: 100%;
  padding: 12px;
  font-size: 15px;
  font-weight: 600;
  border-radius: 8px;
}

/* ── Responsive ───────────────────────────────────── */

@media (max-width: 1024px) {
  .grid-2 { grid-template-columns: 1fr; }
  .grid-3 { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.25s ease;
  }
  .sidebar.open { transform: translateX(0); }
  .content { margin-left: 0; padding: 20px 16px; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .detail-grid { grid-template-columns: 1fr; }
  .page-header { flex-direction: column; align-items: flex-start; gap: 12px; }
  .comp-form { flex-direction: column; }
}
