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

:root {
  --bg-primary: #0a0a0b;
  --bg-secondary: #111113;
  --bg-tertiary: #1a1a1d;
  --bg-hover: #222225;
  --border: #2a2a2d;
  --border-strong: #3a3a3d;
  --text-primary: #f0f0f2;
  --text-secondary: #a0a0a8;
  --text-tertiary: #6a6a72;
  --brand-500: #6366f1;
  --brand-600: #4f46e5;
  --brand-700: #4338ca;
  --brand-50: rgba(99, 102, 241, 0.08);
  --brand-100: rgba(99, 102, 241, 0.15);
  --green-500: #22c55e;
  --green-50: rgba(34, 197, 94, 0.1);
  --green-800: #166534;
  --amber-500: #f59e0b;
  --amber-50: rgba(245, 158, 11, 0.1);
  --amber-800: #92400e;
  --red-500: #ef4444;
  --red-50: rgba(239, 68, 68, 0.1);
  --red-800: #991b1b;
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.5);
  --sidebar-width: 240px;
}

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

/* === Auth Screen === */
.auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.auth-card {
  width: 100%;
  max-width: 400px;
  text-align: center;
}

.auth-logo {
  width: 56px;
  height: 56px;
  border-radius: var(--radius-xl);
  background: linear-gradient(135deg, var(--brand-500), var(--brand-700));
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 20px;
  font-size: 24px;
  font-weight: 700;
  color: white;
  box-shadow: var(--shadow-lg);
}

.auth-card h1 {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 4px;
}

.auth-subtitle {
  font-size: 14px;
  color: var(--text-tertiary);
  margin-bottom: 32px;
}

.form-group {
  text-align: left;
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

input[type="url"], input[type="password"], input[type="text"], input[type="email"] {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-tertiary);
  color: var(--text-primary);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s;
}

input:focus {
  border-color: var(--brand-500);
}

.error-text {
  color: var(--red-500);
  font-size: 13px;
  margin-top: 12px;
}

/* === Buttons === */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-primary {
  background: var(--brand-600);
  color: white;
}
.btn-primary:hover { background: var(--brand-700); }

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

.btn-sm { padding: 6px 14px; font-size: 13px; }
.btn-full { width: 100%; }
.btn-danger { background: var(--red-50); color: var(--red-500); border: 1px solid rgba(239,68,68,0.2); }
.btn-danger:hover { background: rgba(239,68,68,0.15); }

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

/* === Sidebar === */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 10;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 16px;
  border-bottom: 1px solid var(--border);
}

.sidebar-logo {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--brand-500), var(--brand-700));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 700;
  color: white;
}

.sidebar-title {
  font-size: 15px;
  font-weight: 600;
}

.sidebar-nav {
  flex: 1;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: none;
  background: none;
  color: var(--text-secondary);
  font-size: 14px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.15s;
  text-align: left;
  width: 100%;
}

.nav-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.nav-item.active { background: var(--brand-50); color: var(--brand-500); }
.nav-item.logout { color: var(--red-500); }
.nav-item.logout:hover { background: var(--red-50); }

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

/* === Content === */
.content {
  flex: 1;
  margin-left: var(--sidebar-width);
  padding: 24px 32px;
  min-height: 100vh;
}

.page { display: none; }
.page.active { display: block; }

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

.page-header h2 {
  font-size: 22px;
  font-weight: 700;
}

.header-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

/* === Stats Grid === */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
}

.stat-label {
  font-size: 13px;
  color: var(--text-tertiary);
  margin-bottom: 8px;
}

.stat-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--text-primary);
}

.stat-warning { color: var(--amber-500); }
.stat-danger { color: var(--red-500); }

/* === Cards === */
.card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
}

.card h3 {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 16px;
}

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

/* === Tables === */
.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table th {
  text-align: left;
  padding: 10px 12px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
}

.data-table td {
  padding: 12px;
  font-size: 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text-secondary);
}

.data-table tr:hover td { background: var(--bg-hover); }
.data-table tr:last-child td { border-bottom: none; }

/* === Badges === */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 100px;
  font-size: 12px;
  font-weight: 600;
}

.badge-active { background: var(--green-50); color: var(--green-500); }
.badge-past-due { background: var(--amber-50); color: var(--amber-500); }
.badge-canceled { background: var(--red-50); color: var(--red-500); }
.badge-none { background: var(--bg-tertiary); color: var(--text-tertiary); }
.badge-platform {
  background: var(--brand-50);
  color: var(--brand-500);
}

/* === Search === */
.search-input {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-tertiary);
  color: var(--text-primary);
  font-size: 13px;
  outline: none;
  min-width: 240px;
}
.search-input:focus { border-color: var(--brand-500); }

.select-input {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-tertiary);
  color: var(--text-primary);
  font-size: 13px;
  outline: none;
}

/* === Modal === */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.6);
}

.modal-content {
  position: relative;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  width: 90%;
  max-width: 640px;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 { font-size: 16px; font-weight: 600; }

.modal-close {
  background: none;
  border: none;
  color: var(--text-tertiary);
  font-size: 24px;
  cursor: pointer;
  padding: 0 4px;
}
.modal-close:hover { color: var(--text-primary); }

.modal-body { padding: 20px; }

/* === Detail Items === */
.detail-grid {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 8px 16px;
  font-size: 14px;
}

.detail-label {
  color: var(--text-tertiary);
  font-weight: 500;
}

.detail-value {
  color: var(--text-primary);
  word-break: break-all;
}

.detail-section {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.detail-section h4 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--text-secondary);
}

/* === Lists === */
.list-container {
  max-height: 300px;
  overflow-y: auto;
}

.list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}

.list-item:last-child { border-bottom: none; }

.list-item-left {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.list-item-primary { color: var(--text-primary); font-weight: 500; }
.list-item-secondary { color: var(--text-tertiary); font-size: 12px; }

/* === Functions Grid === */
.functions-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.fn-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
}

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

.fn-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

.fn-status {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green-500);
}
.fn-status.inactive { background: var(--red-500); }

.fn-meta {
  font-size: 12px;
  color: var(--text-tertiary);
}

/* === Function Tester === */
.fn-tester {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.textarea-input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-tertiary);
  color: var(--text-primary);
  font-size: 13px;
  font-family: 'SF Mono', Menlo, monospace;
  resize: vertical;
  outline: none;
}
.textarea-input:focus { border-color: var(--brand-500); }

.code-block {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px;
  font-size: 13px;
  font-family: 'SF Mono', Menlo, monospace;
  color: var(--text-secondary);
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 400px;
  overflow-y: auto;
}

/* === Quick Actions === */
.quick-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* === Activity Timeline === */
.timeline-item {
  display: flex;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.timeline-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--brand-500);
  margin-top: 6px;
  flex-shrink: 0;
}

.timeline-content {
  flex: 1;
}

.timeline-title {
  font-size: 14px;
  color: var(--text-primary);
  font-weight: 500;
}

.timeline-time {
  font-size: 12px;
  color: var(--text-tertiary);
  margin-top: 2px;
}

/* === Loading === */
.loading {
  color: var(--text-tertiary);
  font-size: 14px;
  padding: 20px;
  text-align: center;
}

/* === User avatar === */
.avatar-sm {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
}

.user-cell {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* === Empty state === */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-tertiary);
  font-size: 14px;
}

/* === Scrollbar === */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-strong); }

/* === Pagination === */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 16px;
  border-top: 1px solid var(--border);
}

.pagination-info {
  font-size: 13px;
  color: var(--text-secondary);
}

.pagination button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* === Auth Divider === */
.auth-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 16px 0;
  color: var(--text-tertiary);
  font-size: 12px;
}

.auth-divider::before,
.auth-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* === Revenue Cards === */
.stat-card-accent {
  border-left: 3px solid var(--brand-500);
}

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

/* === Date Filter === */
.date-filter {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.date-filter-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
}

.date-input {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  padding: 6px 10px;
  font-size: 13px;
  font-family: inherit;
}

.date-input:focus {
  outline: none;
  border-color: var(--brand-500);
}

.date-filter-result {
  font-size: 13px;
  color: var(--text-secondary);
  margin-left: 8px;
}

.date-filter-result strong {
  color: var(--green-500);
}

/* === Responsive === */
@media (max-width: 1024px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .grid-2 { grid-template-columns: 1fr; }
  .functions-grid { grid-template-columns: repeat(2, 1fr); }
}
