@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');

/* ═══════════════════════════════════════════════════════════
   CLOUD PBX SAAS — Design System
   Clean Enterprise Light Mode (High Contrast, Human-Designed)
═══════════════════════════════════════════════════════════ */

:root {
  /* Color Palette */
  --primary:        #4f46e5;
  --primary-light:  #6366f1;
  --primary-dark:   #3730a3;
  --secondary:      #0891b2;
  --accent:         #d97706;
  --danger:         #dc2626;
  --success:        #059669;
  --warning:        #d97706;
  --info:           #2563eb;

  /* Light Background System */
  --bg-base:        #f8fafc;
  --bg-surface:     #ffffff;
  --bg-card:        #ffffff;
  --bg-sidebar:     #ffffff;
  --bg-hover:       #f1f5f9;
  --bg-active:      #eef2ff;
  --bg-input:       #ffffff;

  /* Glass Effect - Light Mode */
  --glass-bg:       rgba(255, 255, 255, 0.95);
  --glass-border:   #e2e8f0;
  --glass-blur:     12px;

  /* Text Colors - High Contrast Dark Text (Never White) */
  --text-primary:   #0f172a;
  --text-secondary: #334155;
  --text-muted:     #64748b;
  --text-accent:    #4f46e5;

  /* Borders */
  --border:         #e2e8f0;
  --border-strong:  #cbd5e1;

  /* Gradients */
  --gradient-primary: linear-gradient(135deg, #4f46e5 0%, #0891b2 100%);
  --gradient-dark:    linear-gradient(180deg, #f8fafc 0%, #f1f5f9 100%);
  --gradient-card:    #ffffff;
  --gradient-sidebar: #ffffff;
  --gradient-glow:    radial-gradient(ellipse at top, rgba(79,70,229,0.06) 0%, transparent 70%);

  /* Shadows */
  --shadow-sm:   0 1px 2px 0 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);
  --shadow-glow: 0 0 20px rgba(79,70,229,0.12);
  --shadow-card: 0 1px 3px 0 rgba(0,0,0,0.06), 0 1px 2px -1px rgba(0,0,0,0.04);

  /* Spacing */
  --sidebar-width: 260px;
  --topbar-height: 64px;

  /* Radius */
  --radius-sm:  6px;
  --radius-md:  10px;
  --radius-lg:  16px;
  --radius-xl:  24px;

  /* Transitions */
  --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ── Reset & Base ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-base);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
}

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

.app-sidebar {
  width: var(--sidebar-width);
  min-height: 100vh;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  position: fixed;
  top: 0; left: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
}

.app-main {
  margin-left: var(--sidebar-width);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background: var(--bg-base);
}

.app-topbar {
  height: var(--topbar-height);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: var(--shadow-sm);
}

.app-content {
  padding: 28px 32px;
  flex: 1;
}

/* ── Sidebar ─────────────────────────────────────────────── */
.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border);
  text-decoration: none;
}

.sidebar-logo-icon {
  width: 36px;
  height: 36px;
  background: var(--gradient-primary);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: #ffffff;
  box-shadow: var(--shadow-sm);
  flex-shrink: 0;
}

.sidebar-logo-text {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.3px;
}

.sidebar-logo-badge {
  font-size: 10px;
  color: var(--primary);
  font-weight: 600;
}

.sidebar-nav {
  padding: 16px 12px;
  flex: 1;
}

.sidebar-section {
  margin-bottom: 24px;
}

.sidebar-section-title {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  padding: 0 10px;
  margin-bottom: 6px;
}

.sidebar-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 500;
  transition: var(--transition);
  position: relative;
  margin-bottom: 2px;
}

.sidebar-item:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.sidebar-item.active {
  background: var(--bg-active);
  color: var(--primary);
  font-weight: 600;
}

.sidebar-item.active::before {
  content: '';
  position: absolute;
  left: 0; top: 6px; bottom: 6px;
  width: 3.5px;
  background: var(--primary);
  border-radius: 0 3px 3px 0;
}

.sidebar-item .icon {
  width: 18px;
  height: 18px;
  opacity: 0.75;
  flex-shrink: 0;
}

.sidebar-item.active .icon { opacity: 1; color: var(--primary); }

.sidebar-badge {
  margin-left: auto;
  background: var(--primary);
  color: #fff;
  font-size: 10px;
  font-weight: 600;
  padding: 1px 7px;
  border-radius: 999px;
}

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

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-md);
  transition: var(--transition);
  cursor: pointer;
  text-decoration: none;
}

.sidebar-user:hover { background: var(--bg-hover); }

.sidebar-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--gradient-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}

.sidebar-user-info .name { font-size: 13px; font-weight: 600; color: var(--text-primary); line-height: 1.3; }
.sidebar-user-info .role { font-size: 11px; color: var(--text-muted); }

/* ── Topbar ──────────────────────────────────────────────── */
.topbar-title { font-size: 17px; font-weight: 700; color: var(--text-primary); }
.topbar-subtitle { font-size: 12px; color: var(--text-muted); }

.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar-btn {
  width: 36px; height: 36px;
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  cursor: pointer;
  transition: var(--transition);
  font-size: 15px;
}

.topbar-btn:hover { background: var(--bg-hover); color: var(--text-primary); border-color: var(--border-strong); }

/* ── Cards ───────────────────────────────────────────────── */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  overflow: hidden;
}

.card-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #ffffff;
}

.card-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
}

.card-subtitle {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.card-body { padding: 24px; }

/* ── Stats Cards ─────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 20px;
  margin-bottom: 28px;
}

.stat-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px;
  box-shadow: var(--shadow-card);
  position: relative;
  overflow: hidden;
  transition: var(--transition-slow);
}

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

.stat-card .icon-wrap {
  width: 44px; height: 44px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  margin-bottom: 16px;
  background: #f1f5f9;
}

.stat-card .value {
  font-size: 28px;
  font-weight: 800;
  color: var(--text-primary);
  line-height: 1;
  margin-bottom: 6px;
  letter-spacing: -1px;
}

.stat-card .label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 600;
}

.stat-card .change {
  font-size: 12px;
  font-weight: 600;
  margin-top: 8px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.change.up { color: var(--success); }
.change.down { color: var(--danger); }

/* ── Tables ──────────────────────────────────────────────── */
.table-wrapper {
  overflow-x: auto;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--bg-surface);
}

table { width: 100%; border-collapse: collapse; }

thead th {
  background: #f8fafc;
  padding: 12px 16px;
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody tr {
  border-bottom: 1px solid var(--border);
  transition: var(--transition);
}

tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--bg-hover); }

tbody td {
  padding: 14px 16px;
  font-size: 13.5px;
  color: var(--text-secondary);
  vertical-align: middle;
}

tbody td strong, tbody td .font-medium { color: var(--text-primary); }

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 16px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: var(--transition);
  text-decoration: none;
  white-space: nowrap;
}

.btn-primary {
  background: var(--primary);
  color: #ffffff;
  box-shadow: 0 2px 4px rgba(79,70,229,0.2);
}
.btn-primary:hover { background: var(--primary-dark); transform: translateY(-1px); }

.btn-secondary {
  background: var(--bg-surface);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--bg-hover); color: var(--text-primary); border-color: var(--border-strong); }

.btn-danger {
  background: #fef2f2;
  color: var(--danger);
  border: 1px solid #fecaca;
}
.btn-danger:hover { background: #fee2e2; }

.btn-success {
  background: #ecfdf5;
  color: var(--success);
  border: 1px solid #a7f3d0;
}
.btn-success:hover { background: #d1fae5; }

.btn-sm { padding: 5px 11px; font-size: 12px; }
.btn-lg { padding: 12px 24px; font-size: 15px; }

/* ── Badges / Status Chips (High Contrast Dark Text) ───────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
}

.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

.badge-active    { background: #d1fae5; color: #065f46; }
.badge-trial     { background: #dbeafe; color: #1e40af; }
.badge-suspended { background: #fee2e2; color: #991b1b; }
.badge-pending   { background: #fef3c7; color: #92400e; }
.badge-inactive  { background: #f1f5f9; color: #475569; }
.badge-terminated{ background: #fee2e2; color: #b91c1c; }
.badge-paid      { background: #d1fae5; color: #065f46; }
.badge-failed    { background: #fee2e2; color: #991b1b; }

/* ── Forms ───────────────────────────────────────────────── */
.form-group { margin-bottom: 20px; }

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.form-label .required { color: var(--danger); margin-left: 3px; }

.form-control,
.form-select {
  width: 100%;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  color: var(--text-primary);
  font-size: 14px;
  font-family: inherit;
  transition: var(--transition);
  outline: none;
}

.form-control:focus,
.form-select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79,70,229,0.12);
}

.form-control::placeholder { color: var(--text-muted); }

.form-error {
  font-size: 12px;
  color: var(--danger);
  margin-top: 6px;
  font-weight: 500;
}

.form-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 6px;
}

/* Checkbox / Toggle */
.form-check {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
}

.form-check input[type="checkbox"] {
  width: 16px; height: 16px;
  accent-color: var(--primary);
  cursor: pointer;
}

/* ── Page Header ─────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 28px;
  flex-wrap: wrap;
  gap: 16px;
}

.page-title {
  font-size: 22px;
  font-weight: 800;
  color: var(--text-primary);
  letter-spacing: -0.5px;
  line-height: 1.2;
}

.page-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 4px;
}

.page-actions { display: flex; gap: 10px; align-items: center; }

/* ── Alerts ──────────────────────────────────────────────── */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius-md);
  font-size: 13px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 20px;
  font-weight: 500;
}

.alert-success { background: #ecfdf5; border: 1px solid #a7f3d0; color: #047857; }
.alert-error   { background: #fef2f2; border: 1px solid #fecaca; color: #b91c1c; }
.alert-warning { background: #fffbeb; border: 1px solid #fde68a; color: #b45309; }
.alert-info    { background: #eff6ff; border: 1px solid #bfdbfe; color: #1d4ed8; }

/* ── Auth Pages ──────────────────────────────────────────── */
.auth-body {
  min-height: 100vh;
  background: linear-gradient(135deg, #f8fafc 0%, #eef2ff 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 40px 36px;
  box-shadow: var(--shadow-lg);
  position: relative;
  z-index: 1;
  animation: slideUp 0.4s ease;
}

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

.auth-logo {
  text-align: center;
  margin-bottom: 32px;
}

.auth-logo-icon {
  width: 52px; height: 52px;
  background: var(--gradient-primary);
  border-radius: var(--radius-lg);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  color: #ffffff;
  margin-bottom: 12px;
  box-shadow: var(--shadow-sm);
}

.auth-logo h1 {
  font-size: 22px;
  font-weight: 800;
  color: var(--text-primary);
  letter-spacing: -0.5px;
}

.auth-logo p {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ── Pagination ──────────────────────────────────────────── */
.pagination {
  display: flex;
  align-items: center;
  gap: 6px;
  justify-content: center;
  padding: 20px 0 0;
}

.pagination a, .pagination span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px; height: 34px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  transition: var(--transition);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  background: var(--bg-surface);
}

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

/* ── Search / Filters ────────────────────────────────────── */
.filter-bar {
  display: flex;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
  align-items: center;
}

.search-input {
  flex: 1;
  min-width: 200px;
  max-width: 360px;
}

/* ── Progress Bars ───────────────────────────────────────── */
.progress {
  background: #e2e8f0;
  border-radius: 999px;
  height: 6px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  background: var(--gradient-primary);
  border-radius: 999px;
  transition: width 0.5s ease;
}

.progress-bar.warning { background: linear-gradient(90deg, var(--warning), #fb923c); }
.progress-bar.danger  { background: linear-gradient(90deg, var(--danger), #f87171); }

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 768px) {
  .app-sidebar { transform: translateX(-100%); }
  .app-sidebar.open { transform: translateX(0); }
  .app-main { margin-left: 0; }
  .app-content { padding: 16px; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
}

/* ── Utility Classes ─────────────────────────────────────── */
.text-primary    { color: var(--text-primary) !important; }
.text-secondary  { color: var(--text-secondary) !important; }
.text-muted      { color: var(--text-muted) !important; }
.text-accent     { color: var(--primary) !important; }
.text-success    { color: var(--success) !important; }
.text-danger     { color: var(--danger) !important; }
.text-warning    { color: var(--warning) !important; }
.flex            { display: flex; }
.items-center    { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2           { gap: 8px; }
.gap-3           { gap: 12px; }
.gap-4           { gap: 16px; }
.mb-4            { margin-bottom: 16px; }
.mb-6            { margin-bottom: 24px; }
.mb-8            { margin-bottom: 32px; }
.mt-4            { margin-top: 16px; }
.w-full          { width: 100%; }
.font-bold       { font-weight: 700; }
.font-semibold   { font-weight: 600; }
.text-sm         { font-size: 12px; }
.text-lg         { font-size: 16px; }
.grid            { display: grid; }
.grid-2          { grid-template-columns: repeat(2, 1fr); gap: 20px; }
.grid-3          { grid-template-columns: repeat(3, 1fr); gap: 20px; }
.grid-4          { grid-template-columns: repeat(4, 1fr); gap: 20px; }
.rounded         { border-radius: var(--radius-md); }
.rounded-lg      { border-radius: var(--radius-lg); }
.p-4             { padding: 16px; }
.p-6             { padding: 24px; }
.truncate        { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 20px 0;
}

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

.empty-state .icon { font-size: 48px; margin-bottom: 16px; opacity: 0.5; }
.empty-state h3 { font-size: 16px; font-weight: 600; color: var(--text-secondary); margin-bottom: 8px; }
.empty-state p { font-size: 13px; }
