/* ==========================================
   GLOBAL STYLES — Dark/Light Theme
   ========================================== */

/* Dark — deep black with warm orange accent */
:root {
  --bg: #0a0a0a;
  --bg-gradient: linear-gradient(160deg, #0a0a0a 0%, #1a1408 50%, #0a0a0a 100%);
  --surface: #141414;
  --surface-hover: #1c1c1c;
  --border: #262626;
  --border-focus: #f97316;
  --text: #d4d4d4;
  --text-muted: #a3a3a3;
  --text-dim: #737373;
  --text-faint: #525252;
  --heading: #fafafa;
  --link: #f97316;
  --accent: #f97316;
  --accent-hover: #ea580c;
  --accent-glow: rgba(249, 115, 22, 0.12);
  --accent-gradient: linear-gradient(135deg, #f97316, #f59e0b);
  --facebook: #1877f2;
  --facebook-hover: #166fe5;
  --success: #22c55e;
  --error: #ef4444;
  --warning: #fbbf24;
  --highlight-bg: rgba(249, 115, 22, 0.08);
  --highlight-border: #f97316;
  --highlight-text: #fb923c;
  --secondary-bg: #1f1f1f;
  --secondary-hover: #2a2a2a;
}

/* Light — warm cream with orange accent */
[data-theme="light"] {
  --bg: #faf9f7;
  --bg-gradient: linear-gradient(160deg, #faf9f7 0%, #f5f0e8 50%, #faf9f7 100%);
  --surface: #ffffff;
  --surface-hover: #f7f5f2;
  --border: #e8e4de;
  --border-focus: #ea580c;
  --text: #44403c;
  --text-muted: #78716c;
  --text-dim: #a8a29e;
  --text-faint: #c4bfb9;
  --heading: #1c1917;
  --link: #ea580c;
  --accent: #ea580c;
  --accent-hover: #c2410c;
  --accent-glow: rgba(234, 88, 12, 0.08);
  --accent-gradient: linear-gradient(135deg, #ea580c, #d97706);
  --facebook: #1877f2;
  --facebook-hover: #166fe5;
  --success: #16a34a;
  --error: #dc2626;
  --warning: #d97706;
  --highlight-bg: #fef3e2;
  --highlight-border: #ea580c;
  --highlight-text: #9a3412;
  --secondary-bg: #f0ece6;
  --secondary-hover: #e7e2da;
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
  font-size: 16px;
  transition: background 0.3s, color 0.3s;
}

a {
  color: var(--link);
  text-decoration: none;
  transition: opacity 0.2s;
}

a:hover { opacity: 0.8; }

/* ==========================================
   THEME TOGGLE
   ========================================== */

.theme-toggle {
  position: fixed;
  top: 20px;
  right: 20px;
  background: var(--secondary-bg);
  border: 1px solid var(--border);
  color: var(--heading);
  width: 44px;
  height: 44px;
  border-radius: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  transition: all 0.3s;
  z-index: 10000;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

.theme-toggle:hover {
  border-color: var(--accent);
  color: var(--heading);
}

/* ==========================================
   APP — Layout
   ========================================== */

.app-container {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 240px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 20px 0;
  position: fixed;
  height: 100vh;
  overflow-y: auto;
  transition: background 0.3s;
}

.sidebar-logo {
  padding: 0 20px 24px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}

.sidebar-logo h1 {
  font-size: 18px;
  font-weight: 700;
  color: var(--heading);
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar-logo h1 .cfg-logo-letter {
  background: var(--accent-gradient);
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  color: #fff;
  flex-shrink: 0;
}

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

.sidebar-section-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 0 8px;
  margin-bottom: 8px;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 14px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s;
}

.sidebar-link:hover {
  background: var(--secondary-bg);
  color: var(--heading);
  opacity: 1;
}

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

.sidebar-link svg {
  width: 18px;
  height: 18px;
  opacity: 0.7;
}

.sidebar-link.active svg { opacity: 1; }

.main-content {
  flex: 1;
  margin-left: 240px;
  padding: 32px 40px;
}

/* ==========================================
   APP — Auth Screen
   ========================================== */

.auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-gradient);
}

.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 48px;
  width: 100%;
  max-width: 420px;
  text-align: center;
  transition: background 0.3s, border-color 0.3s;
}

.auth-logo {
  width: 64px;
  height: 64px;
  background: var(--accent-gradient);
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 24px;
  font-size: 24px;
  font-weight: 700;
  color: #fff;
}

.auth-card h1 {
  font-size: 24px;
  font-weight: 700;
  color: var(--heading);
  margin-bottom: 8px;
}

.auth-card p {
  color: var(--text-dim);
  font-size: 14px;
  margin-bottom: 32px;
  line-height: 1.5;
}

.auth-links {
  margin-top: 32px;
  font-size: 12px;
  color: var(--text-faint);
}

.auth-links a {
  color: var(--text-dim);
}

.auth-links a:hover { color: var(--link); }

/* ==========================================
   APP — Buttons
   ========================================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 12px 24px;
  font-size: 14px;
  font-weight: 600;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s;
  border: none;
  text-decoration: none;
}

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

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

.btn-facebook {
  background: var(--facebook);
  color: #fff;
  width: 100%;
  padding: 14px 24px;
}

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

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

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

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  padding: 8px 12px;
}

.btn-ghost:hover {
  background: var(--secondary-bg);
  color: var(--heading);
}

/* ==========================================
   APP — Page Header
   ========================================== */

.page-header { margin-bottom: 32px; }

.page-header h1 {
  font-size: 28px;
  font-weight: 700;
  color: var(--heading);
  margin-bottom: 8px;
  border: none;
  padding: 0;
  text-align: left;
}

.page-header p {
  color: var(--text-dim);
  font-size: 15px;
}

.page-header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 20px;
}

/* ==========================================
   APP — Cards
   ========================================== */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  margin-bottom: 24px;
  transition: background 0.3s, border-color 0.3s;
}

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

.card-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--heading);
}

/* ==========================================
   APP — Stats
   ========================================== */

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

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px 24px;
  transition: background 0.3s, border-color 0.3s;
}

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

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

.stat-change { font-size: 13px; margin-top: 8px; }
.stat-change.positive { color: var(--success); }
.stat-change.negative { color: var(--error); }

/* ==========================================
   APP — Tables
   ========================================== */

.table-container { overflow-x: auto; }

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

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

td {
  padding: 16px;
  font-size: 14px;
  border-bottom: 1px solid var(--border);
}

tr:hover { background: var(--surface-hover); }

.table-name { font-weight: 500; color: var(--heading); }

.table-id {
  font-size: 12px;
  color: var(--text-dim);
  font-family: monospace;
}

/* ==========================================
   APP — Forms
   ========================================== */

.form-group { margin-bottom: 20px; }

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

.form-input,
.form-select {
  width: 100%;
  max-width: 400px;
  padding: 12px 16px;
  font-size: 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--heading);
  font-family: inherit;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.form-input:focus,
.form-select:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.form-select { cursor: pointer; }

/* ==========================================
   APP — Alerts
   ========================================== */

.alert {
  padding: 16px 20px;
  border-radius: 8px;
  font-size: 14px;
  margin-bottom: 20px;
}

.alert-success {
  background: rgba(34, 197, 94, 0.1);
  border: 1px solid rgba(34, 197, 94, 0.2);
  color: var(--success);
}

.alert-error {
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.2);
  color: var(--error);
}

.alert-info {
  background: rgba(59, 130, 246, 0.1);
  border: 1px solid rgba(59, 130, 246, 0.2);
  color: var(--accent);
}

.alert-title { font-weight: 600; margin-bottom: 4px; }

/* ==========================================
   APP — Badges
   ========================================== */

.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 500;
  border-radius: 9999px;
}

.badge-active {
  background: rgba(34, 197, 94, 0.1);
  color: var(--success);
}

.badge-paused {
  background: rgba(251, 191, 36, 0.1);
  color: var(--warning);
}

/* ==========================================
   APP — Misc
   ========================================== */

.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-dim);
}

.empty-state svg {
  width: 48px;
  height: 48px;
  margin-bottom: 16px;
  opacity: 0.5;
}

.loading {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text-dim);
  padding: 24px;
}

.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--text-dim);
  margin-bottom: 16px;
}

.breadcrumb a {
  color: var(--text-dim);
  cursor: pointer;
}

.breadcrumb a:hover { color: var(--heading); opacity: 1; }

.breadcrumb-separator { opacity: 0.5; }

.data-block {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  font-family: 'Monaco', 'Menlo', monospace;
  font-size: 12px;
  color: var(--text-muted);
  overflow-x: auto;
  white-space: pre-wrap;
  max-height: 300px;
  overflow-y: auto;
}

.timestamp {
  font-size: 12px;
  color: var(--text-faint);
  margin-top: 16px;
}

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

.selected-context {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--secondary-bg);
  padding: 8px 14px;
  border-radius: 6px;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 24px;
}

.selected-context strong { color: var(--heading); }

.insights-section { margin-top: 32px; }

.insights-section h3 {
  font-size: 16px;
  font-weight: 600;
  color: var(--heading);
  margin-bottom: 16px;
}

.quick-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.app-footer {
  padding: 24px 40px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-faint);
  text-align: center;
}

.app-footer a {
  color: var(--text-dim);
}

.app-footer a:hover { color: var(--link); }

/* ==========================================
   LEGAL PAGES — Container
   ========================================== */

.legal-container {
  max-width: 800px;
  margin: 0 auto;
  background: var(--surface);
  min-height: 100vh;
  padding: 60px 80px;
  box-shadow: 0 0 60px rgba(0,0,0,0.15);
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
  transition: background 0.3s, border-color 0.3s;
}

@media (max-width: 768px) {
  .legal-container { padding: 40px 24px; }
}

.back-to-app {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 32px;
}

.back-to-app:hover {
  color: var(--accent);
  opacity: 1;
}

.legal-container header {
  text-align: center;
  margin-bottom: 50px;
  padding-bottom: 30px;
  border-bottom: 1px solid var(--border);
}

.legal-container h1 {
  border: none;
  padding: 0;
}

.subtitle {
  font-size: 16px;
  color: var(--text-muted);
  letter-spacing: 0.5px;
  text-transform: uppercase;
  font-weight: 500;
}

.last-updated {
  font-size: 13px;
  color: var(--text-dim);
  margin-top: 16px;
}

.legal-container h2 {
  font-size: 20px;
  font-weight: 600;
  color: var(--heading);
  margin-top: 40px;
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.legal-container h3 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  margin-top: 24px;
  margin-bottom: 12px;
}

/* Highlight box */
.highlight-box {
  background: var(--highlight-bg);
  border-left: 4px solid var(--highlight-border);
  padding: 16px 20px;
  margin: 20px 0;
  border-radius: 0 8px 8px 0;
}

.highlight-box p {
  margin: 0;
  color: var(--highlight-text);
}

/* Contact info */
.contact-info {
  background: var(--bg);
  padding: 24px;
  border-radius: 10px;
  margin-top: 16px;
  border: 1px solid var(--border);
}

.contact-info p { margin-bottom: 8px; }
.contact-info strong { color: var(--heading); }

/* Email box */
.email-box {
  background: var(--bg);
  padding: 16px 20px;
  border-radius: 0 8px 8px 0;
  margin-top: 20px;
  word-break: break-all;
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
}

/* Footer */
.footer-note {
  margin-top: 50px;
  padding-top: 30px;
  border-top: 1px solid var(--border);
  font-size: 14px;
  color: var(--text-dim);
  font-style: italic;
  text-align: center;
}

.legal-links {
  margin-top: 30px;
  text-align: center;
  font-size: 14px;
}

.legal-links a {
  color: var(--text-muted);
  margin: 0 8px;
}

.legal-links a:hover { color: var(--link); }
