/* ==========================================================================
   Social Connectors — Shared Design System
   Dark theme SaaS. CSS variables + layout primitives + component styles.
   ========================================================================== */

/* ---------- Design Tokens ---------- */
:root {
  /* Core palette (exact names required by spec) */
  --bg: #0a0a0f;
  --surface: #14141f;
  --accent: #6366f1;
  --text: #e2e8f0;
  --muted: #64748b;
  --success: #22c55e;
  --error: #ef4444;
  --warning: #f59e0b;

  /* Extended palette */
  --surface-2: #1c1c2b;
  --surface-3: #252538;
  --border: #2a2a3d;
  --accent-hover: #818cf8;
  --accent-dim: rgba(99, 102, 241, 0.12);
  --success-dim: rgba(34, 197, 94, 0.12);
  --error-dim: rgba(239, 68, 68, 0.12);
  --warning-dim: rgba(245, 158, 11, 0.12);

  /* Spacing scale (4px base) */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;
  --space-8: 3rem;

  /* Radii */
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 16px;
  --radius-full: 9999px;

  /* Typography */
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: "JetBrains Mono", "SF Mono", "Fira Code", Consolas, monospace;
  --text-xs: 0.75rem;
  --text-sm: 0.875rem;
  --text-base: 1rem;
  --text-lg: 1.125rem;
  --text-xl: 1.25rem;
  --text-2xl: 1.5rem;
  --text-3xl: 1.875rem;
  --text-4xl: 2.25rem;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
  --shadow-glow: 0 0 32px rgba(99, 102, 241, 0.2);

  /* Transitions */
  --transition: 150ms ease;

  /* Layout */
  --sidebar-w: 240px;
  --topbar-h: 64px;
}

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

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  font-size: var(--text-base);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
}

a {
  color: var(--accent);
  text-decoration: none;
  transition: color var(--transition);
}
a:hover {
  color: var(--accent-hover);
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

input,
select,
textarea {
  font-family: inherit;
  font-size: inherit;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-5);
  border-radius: var(--radius);
  font-size: var(--text-sm);
  font-weight: 600;
  transition: all var(--transition);
  border: 1px solid transparent;
  white-space: nowrap;
  line-height: 1.2;
}
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

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

.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--border);
}
.btn-secondary:hover:not(:disabled) {
  background: var(--surface-3);
  border-color: var(--muted);
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
}
.btn-ghost:hover:not(:disabled) {
  color: var(--text);
  background: var(--surface-2);
}

.btn-danger {
  background: var(--error-dim);
  color: var(--error);
  border-color: rgba(239, 68, 68, 0.3);
}
.btn-danger:hover:not(:disabled) {
  background: rgba(239, 68, 68, 0.2);
}

.btn-sm {
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-xs);
}

.btn-block {
  width: 100%;
}

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
}

.card-title {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: var(--space-3);
}

/* ---------- Forms ---------- */
.form-group {
  margin-bottom: var(--space-4);
}

.form-label {
  display: block;
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--muted);
  margin-bottom: var(--space-2);
}

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: var(--space-3) var(--space-4);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: var(--text-sm);
  transition: border-color var(--transition);
}
.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}
.form-input::placeholder {
  color: var(--muted);
  opacity: 0.6;
}

/* ---------- Tables ---------- */
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}
.table th {
  text-align: left;
  padding: var(--space-3) var(--space-4);
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  font-size: var(--text-xs);
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
}
.table td {
  padding: var(--space-4);
  border-bottom: 1px solid var(--border);
}
.table tbody tr:last-child td {
  border-bottom: none;
}
.table tbody tr:hover {
  background: var(--surface-2);
}

/* ---------- Badges ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.badge-success {
  background: var(--success-dim);
  color: var(--success);
}
.badge-error {
  background: var(--error-dim);
  color: var(--error);
}
.badge-warning {
  background: var(--warning-dim);
  color: var(--warning);
}
.badge-muted {
  background: var(--surface-3);
  color: var(--muted);
}
.badge-accent {
  background: var(--accent-dim);
  color: var(--accent-hover);
}

/* ---------- Toast ---------- */
#toast-container {
  position: fixed;
  bottom: var(--space-5);
  right: var(--space-5);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  max-width: 400px;
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  font-size: var(--text-sm);
  pointer-events: auto;
  animation: toast-in 200ms ease;
  border-left: 3px solid var(--muted);
}
.toast-success {
  border-left-color: var(--success);
}
.toast-error {
  border-left-color: var(--error);
}
.toast-warning {
  border-left-color: var(--warning);
}
.toast-info {
  border-left-color: var(--accent);
}
.toast.fade-out {
  animation: toast-out 200ms ease forwards;
}
@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateX(100%);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}
@keyframes toast-out {
  from {
    opacity: 1;
    transform: translateX(0);
  }
  to {
    opacity: 0;
    transform: translateX(100%);
  }
}

/* ---------- Utilities ---------- */
.text-muted { color: var(--muted); }
.text-success { color: var(--success); }
.text-error { color: var(--error); }
.text-warning { color: var(--warning); }
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-mono { font-family: var(--font-mono); font-size: var(--text-xs); }
.font-bold { font-weight: 700; }
.font-semibold { font-weight: 600; }
.mt-1 { margin-top: var(--space-1); }
.mt-2 { margin-top: var(--space-2); }
.mt-3 { margin-top: var(--space-3); }
.mt-4 { margin-top: var(--space-4); }
.mt-5 { margin-top: var(--space-5); }
.mt-6 { margin-top: var(--space-6); }
.mb-1 { margin-bottom: var(--space-1); }
.mb-2 { margin-bottom: var(--space-2); }
.mb-3 { margin-bottom: var(--space-3); }
.mb-4 { margin-bottom: var(--space-4); }
.mb-5 { margin-bottom: var(--space-5); }
.mb-6 { margin-bottom: var(--space-6); }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: var(--space-1); }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }
.flex-1 { flex: 1; }
.w-full { width: 100%; }
.hidden { display: none !important; }

/* ---------- Spinner ---------- */
.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 600ms linear infinite;
}
.spinner-sm {
  width: 14px;
  height: 14px;
  border-width: 2px;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.loading-overlay {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  padding: var(--space-6);
  color: var(--muted);
}

/* ---------- Responsive helpers ---------- */
@media (max-width: 768px) {
  .hide-mobile {
    display: none !important;
  }
}
@media (min-width: 769px) {
  .hide-desktop {
    display: none !important;
  }
}

/* ---------- Layout: Container ---------- */
.container {
  width: 100%;
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 var(--space-4);
}
.container-narrow {
  max-width: 760px;
}
.section {
  padding: var(--space-8) 0;
}
.section-sm {
  padding: var(--space-6) 0;
}

/* ---------- Layout: Grid ---------- */
.grid {
  display: grid;
  gap: var(--space-5);
}
.grid-2 {
  grid-template-columns: repeat(2, 1fr);
}
.grid-3 {
  grid-template-columns: repeat(3, 1fr);
}
.grid-4 {
  grid-template-columns: repeat(4, 1fr);
}
@media (max-width: 900px) {
  .grid-3,
  .grid-4 {
    grid-template-columns: repeat(2, 1fr);
  }
}
@media (max-width: 600px) {
  .grid-2,
  .grid-3,
  .grid-4 {
    grid-template-columns: 1fr;
  }
}

/* ---------- Button sizes ---------- */
.btn-lg {
  padding: var(--space-4) var(--space-6);
  font-size: var(--text-base);
}

/* ---------- Card hover ---------- */
.card-hover {
  transition: border-color var(--transition), box-shadow var(--transition), transform var(--transition);
}
.card-hover:hover {
  border-color: var(--accent);
  box-shadow: 0 0 32px rgba(99, 102, 241, 0.2);
  transform: translateY(-2px);
}
.card-glow {
  border-color: var(--accent);
  box-shadow: 0 0 32px rgba(99, 102, 241, 0.2);
}

/* ---------- Navigation ---------- */
.nav {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(10, 10, 15, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.nav-inner {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
}
.nav-logo {
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.nav-logo:hover {
  color: var(--text);
}
.nav-logo .logo-mark {
  width: 28px;
  height: 28px;
  background: var(--accent);
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 700;
  font-size: var(--text-sm);
}
.nav-links {
  display: flex;
  align-items: center;
  gap: var(--space-6);
}
.nav-links a {
  color: var(--muted);
  font-size: var(--text-sm);
  font-weight: 500;
}
.nav-links a:hover,
.nav-links a.active {
  color: var(--text);
}
.nav-toggle {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: var(--space-2);
  color: var(--text);
}
.nav-toggle span {
  display: block;
  width: 22px;
  height: 2px;
  background: var(--text);
  border-radius: 2px;
  transition: all var(--transition);
}
.nav-toggle span + span {
  margin-top: 5px;
}
@media (max-width: 768px) {
  .nav-links {
    position: fixed;
    top: var(--topbar-h);
    left: 0;
    right: 0;
    flex-direction: column;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: var(--space-4) var(--space-6);
    gap: var(--space-4);
    transform: translateY(-120%);
    transition: transform var(--transition);
  }
  .nav-links.open {
    transform: translateY(0);
  }
  .nav-toggle {
    display: block;
  }
}

/* ---------- Footer ---------- */
.footer {
  border-top: 1px solid var(--border);
  background: var(--surface);
  padding: var(--space-6) 0;
}
.footer-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
}
.footer-links {
  display: flex;
  gap: var(--space-6);
  flex-wrap: wrap;
}
.footer-links a {
  color: var(--muted);
  font-size: var(--text-sm);
}
.footer-links a:hover {
  color: var(--text);
}
.footer-copy {
  color: var(--muted);
  font-size: var(--text-sm);
}

/* ---------- Input group ---------- */
.input-group {
  display: flex;
  gap: var(--space-2);
}
.input-group .form-input {
  flex: 1;
}

/* ---------- Code blocks ---------- */
pre {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: var(--space-4);
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  line-height: 1.7;
}
code.code-inline {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: var(--space-1) var(--space-2);
  font-family: var(--font-mono);
  font-size: 0.9em;
}
pre code {
  background: none;
  border: none;
  padding: 0;
}

/* ---------- Misc utilities ---------- */
.justify-center {
  justify-content: center;
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
.divider {
  height: 1px;
  background: var(--border);
  border: none;
  margin: var(--space-6) 0;
}
.hidden {
  display: none !important;
}
@media (max-width: 600px) {
  .container {
    padding: 0 var(--space-3);
  }
  .section {
    padding: var(--space-6) 0;
  }
}
