:root {
  --primary: #00A86B;
  --primary-dark: #008F5B;
  --primary-light: #e8f7f0;
  --primary-soft: rgba(0, 168, 107, 0.08);
  --white: #ffffff;
  --bg: #f0f9f4;
  --card-bg: #ffffff;
  --text: #0f172a;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -2px rgba(0, 0, 0, 0.04);
  --radius: 16px;
  --radius-sm: 10px;
}

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

html, body {
  overflow-x: hidden;
}

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

/* Sidebar */
.sidebar {
  width: 260px;
  background: var(--card-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  z-index: 100;
  box-shadow: var(--shadow-md);
}

.sidebar-brand {
  padding: 1.5rem;
  display: flex;
  align-items: center;
  gap: 0.875rem;
  border-bottom: 1px solid var(--border);
}

.sidebar-logo {
  width: 44px;
  height: 44px;
  object-fit: contain;
}

.sidebar-title {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--primary);
  line-height: 1.2;
}

.sidebar-subtitle {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

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

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 0.875rem;
  padding: 0.875rem 1rem;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  text-decoration: none;
  font-weight: 500;
  transition: all 0.2s;
}

.sidebar-link svg {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.sidebar-link:hover {
  background: var(--primary-soft);
  color: var(--primary);
}

.sidebar-link.active {
  background: var(--primary);
  color: var(--white);
  box-shadow: 0 4px 12px rgba(0, 168, 107, 0.25);
}

.sidebar-footer {
  padding: 1rem;
  border-top: 1px solid var(--border);
}

.sidebar-link.logout {
  color: #dc2626;
}

.sidebar-link.logout:hover {
  background: #fef2f2;
  color: #b91c1c;
}

/* Main content */
.main-content {
  flex: 1;
  margin-left: 260px;
  padding: 2rem;
  max-width: calc(100% - 260px);
  min-width: 0;
  width: 100%;
}

/* Mobile header */
.mobile-header {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 60px;
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  align-items: center;
  justify-content: space-between;
  padding: 0 1rem;
  z-index: 90;
  box-shadow: var(--shadow-md);
}

.menu-toggle,
.menu-close {
  background: transparent;
  border: none;
  color: var(--text);
  cursor: pointer;
  padding: 0.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.menu-toggle svg,
.menu-close svg {
  width: 24px;
  height: 24px;
}

.mobile-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-weight: 700;
  color: var(--primary);
  font-size: 1rem;
}

.mobile-logo {
  width: 32px;
  height: 32px;
  object-fit: contain;
}

.mobile-spacer {
  width: 40px;
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 99;
}

/* Page header */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 0.5rem;
  gap: 1rem;
  flex-wrap: wrap;
}

.page-header h1 {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--text);
}

.text-muted {
  color: var(--text-muted);
  font-size: 0.95rem;
}

.last-updated {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-bottom: 1.5rem;
}

/* Filter form */
.filter-form {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.filter-form label {
  font-weight: 500;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.filter-form select {
  padding: 0.5rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--white);
  color: var(--text);
  font-size: 0.9rem;
  cursor: pointer;
}

/* Cards */
.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow-md);
  margin-bottom: 1.5rem;
}

/* Stats grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1.25rem;
  margin-bottom: 1.5rem;
  min-width: 0;
}

.stat-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow-md);
  display: flex;
  align-items: center;
  gap: 1rem;
  transition: transform 0.2s, box-shadow 0.2s;
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.stat-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: var(--primary-soft);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  flex-shrink: 0;
}

.stat-info {
  min-width: 0;
}

.stat-label {
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.25rem;
}

.stat-value {
  color: var(--text);
  font-size: 1.5rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Funnel */
.funnel-card {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow-md);
  margin-bottom: 1.5rem;
  color: var(--white);
}

.funnel-card h2 {
  font-size: 1.125rem;
  margin-bottom: 1.25rem;
  font-weight: 600;
}

.funnel-steps {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.funnel-step {
  flex: 1;
  min-width: 120px;
  text-align: center;
  padding: 1rem;
  background: rgba(255, 255, 255, 0.12);
  border-radius: var(--radius-sm);
  backdrop-filter: blur(4px);
}

.funnel-step.premium {
  background: rgba(255, 255, 255, 0.25);
}

.funnel-number {
  font-size: 1.75rem;
  font-weight: 700;
  margin-bottom: 0.25rem;
}

.funnel-label {
  font-size: 0.85rem;
  opacity: 0.9;
}

.funnel-arrow {
  width: 24px;
  height: 24px;
  opacity: 0.9;
  position: relative;
}

.funnel-arrow::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 0;
  width: 16px;
  height: 2px;
  background: rgba(255, 255, 255, 0.9);
  transform: translateY(-50%);
}

.funnel-arrow::after {
  content: '';
  position: absolute;
  top: 50%;
  right: 0;
  width: 8px;
  height: 8px;
  border-top: 2px solid rgba(255, 255, 255, 0.9);
  border-right: 2px solid rgba(255, 255, 255, 0.9);
  transform: translateY(-50%) rotate(45deg);
}

/* Charts */
.charts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(380px, 1fr));
  gap: 1.5rem;
  margin-bottom: 1.5rem;
  min-width: 0;
}

.chart-card {
  max-height: 420px;
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow-md);
  min-width: 0;
}

.chart-card.wide {
  grid-column: span 2;
}

.chart-card h2 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 1rem;
}

.chart-card canvas {
  height: 280px !important;
  max-height: 280px;
  min-height: 280px;
  max-width: 100% !important;
}

.chart-card.state-chart-card {
  max-height: 620px;
}

.chart-card.state-chart-card canvas {
  height: 480px !important;
  max-height: 480px;
  min-height: 480px;
}

.table-card {
  grid-column: 1 / -1;
}

/* Tables */
.table-wrapper {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

th, td {
  text-align: left;
  padding: 0.875rem 1rem;
  border-bottom: 1px solid var(--border);
}

th {
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.7rem;
  letter-spacing: 0.05em;
  background: #f8fafc;
}

td {
  color: var(--text);
}

tbody tr:hover {
  background: #f8fafc;
}

.badge {
  display: inline-block;
  padding: 0.25rem 0.75rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge-success {
  background: var(--primary-light);
  color: var(--primary-dark);
}

.badge-inactive {
  background: #f1f5f9;
  color: var(--text-muted);
}

.badge-plan {
  background: #eff6ff;
  color: #1d4ed8;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.625rem 1.25rem;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
}

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  background: var(--primary);
  color: var(--white);
}

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

.btn-secondary {
  background: #f1f5f9;
  color: var(--text);
}

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

.btn-block {
  width: 100%;
}

/* Forms */
.form-group {
  margin-bottom: 1.25rem;
}

.form-group label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: 500;
  color: var(--text);
  font-size: 0.9rem;
}

.form-group input,
.form-group select {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  transition: border-color 0.2s, box-shadow 0.2s;
  background: var(--white);
  color: var(--text);
}

.form-group input:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(0, 168, 107, 0.15);
}

/* Login */
.login-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  background: linear-gradient(135deg, #f0fdf6 0%, #e0f7ed 50%, #d4f0e3 100%);
  margin-left: 0;
}

.login-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 2.5rem;
  width: 100%;
  max-width: 420px;
}

.login-brand {
  text-align: center;
  margin-bottom: 2rem;
}

.login-logo {
  width: 80px;
  height: 80px;
  object-fit: contain;
  margin-bottom: 1rem;
}

.login-brand h1 {
  color: var(--primary);
  font-size: 1.75rem;
  margin-bottom: 0.25rem;
}

.login-brand p {
  color: var(--text-muted);
}

.alert {
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.alert-success {
  background: var(--primary-light);
  color: var(--primary-dark);
  border: 1px solid rgba(0, 168, 107, 0.2);
}

.alert-error {
  background: #fee2e2;
  color: #991b1b;
  border: 1px solid #fecaca;
}

/* Search form */
.search-form {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.search-form input {
  flex: 1;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
}

.search-form input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(0, 168, 107, 0.15);
}

/* Pagination */
.pagination {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.page-info {
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* Settings */
.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
  gap: 1.5rem;
}

.settings-form {
  max-width: 400px;
}

.info-row {
  display: flex;
  justify-content: space-between;
  padding: 0.875rem 0;
  border-bottom: 1px solid var(--border);
}

.info-row:last-child {
  border-bottom: none;
}

.info-label {
  color: var(--text-muted);
  font-weight: 500;
}

.info-value {
  color: var(--text);
  font-weight: 600;
}

.info-value a {
  color: var(--primary);
  text-decoration: none;
}

/* Responsive */
@media (max-width: 1024px) {
  .chart-card.wide {
    grid-column: span 1;
  }
}

@media (max-width: 768px) {
  body {
    flex-direction: column;
  }

  .mobile-header {
    display: flex;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 280px;
    height: 100vh;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    z-index: 100;
  }

  body.menu-open .sidebar {
    transform: translateX(0);
  }

  body.menu-open .sidebar-backdrop {
    display: block;
  }

  .sidebar-brand {
    padding-right: 1rem;
  }

  .menu-close {
    margin-left: auto;
  }

  .main-content {
    margin-left: 0;
    max-width: 100%;
    padding: 1rem;
    padding-top: calc(60px + 1rem);
    min-width: 0;
    width: 100%;
  }

  .page-header {
    flex-direction: column;
    gap: 0.75rem;
  }

  .page-header h1 {
    font-size: 1.4rem;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
  }

  .stat-card {
    padding: 1rem;
    gap: 0.75rem;
  }

  .stat-icon {
    width: 40px;
    height: 40px;
    font-size: 0.75rem;
  }

  .stat-value {
    font-size: 1.25rem;
  }

  .stat-label {
    font-size: 0.7rem;
  }

  .charts-grid {
    grid-template-columns: 1fr;
    gap: 1rem;
  }

  .chart-card {
    padding: 1rem;
  }

  .chart-card canvas {
    height: 240px !important;
    max-height: 240px;
    min-height: 240px;
  }

  .chart-card.state-chart-card {
    max-height: 520px;
  }

  .chart-card.state-chart-card canvas {
    height: 380px !important;
    max-height: 380px;
    min-height: 380px;
  }

  .funnel-steps {
    flex-direction: column;
  }

  .funnel-arrow {
    transform: rotate(90deg);
    width: 20px;
    height: 20px;
  }

  .funnel-arrow::before {
    width: 12px;
  }

  .funnel-arrow::after {
    width: 6px;
    height: 6px;
  }

  .settings-grid {
    grid-template-columns: 1fr;
  }

  .users-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 1rem;
  }

  .search-form {
    flex-direction: column;
    width: 100%;
  }

  .search-form input {
    width: 100%;
  }

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

  table {
    min-width: 700px;
  }

  .pagination {
    flex-direction: column;
    gap: 1rem;
    align-items: flex-start;
  }

  .login-card {
    padding: 2rem 1.5rem;
    margin: 1rem;
  }
}

@media (max-width: 480px) {
  .stats-grid {
    grid-template-columns: 1fr;
  }
}
