/* ============================================================
   Open Trough — Design System
   Warm editorial, earthy, a little whimsy.
   ============================================================ */

/* --- Design Tokens --- */
:root {
  /* Colors — earthy, warm, grounded */
  --color-primary:       #5C6B56;
  --color-primary-hover: #4A5745;
  --color-primary-light: #dfe5dc;
  --color-accent:        #C4704B;
  --color-accent-hover:  #A85D3D;
  --color-secondary:     #B8945A;
  --color-secondary-light: #f0e6d2;

  --color-bg:            #F5F1EB;
  --color-surface:       #FFFDF9;
  --color-text:          #2D2A26;
  --color-text-secondary:#6B655D;
  --color-muted:         #9C9590;
  --color-border:        #E2DDD5;
  --color-border-light:  #EDE9E3;
  --color-error:         #B94040;
  --color-success:       #5C6B56;
  --color-focus-ring:    rgba(92, 107, 86, 0.3);

  /* Badge colors */
  --color-badge-score-bg:   #dfe5dc;
  --color-badge-score-text: #3e4a39;
  --color-badge-signal-bg:  #f0ece6;
  --color-badge-signal-text:#6B655D;
  --color-badge-feed-bg:    #f5e6db;
  --color-badge-feed-text:  #8B5A3A;

  /* Typography */
  --font-body: 'DM Sans', -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;

  /* Spacing */
  --space-2xs: 2px;
  --space-xs:  4px;
  --space-sm:  8px;
  --space-md:  16px;
  --space-lg:  24px;
  --space-xl:  32px;
  --space-2xl: 48px;
  --space-3xl: 64px;

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

  /* Shadows — warm-toned, soft */
  --shadow-xs:  0 1px 2px rgba(45, 42, 38, 0.04);
  --shadow-sm:  0 1px 3px rgba(45, 42, 38, 0.06), 0 1px 2px rgba(45, 42, 38, 0.04);
  --shadow-md:  0 4px 12px rgba(45, 42, 38, 0.07), 0 1px 3px rgba(45, 42, 38, 0.04);
  --shadow-lg:  0 8px 24px rgba(45, 42, 38, 0.08), 0 2px 6px rgba(45, 42, 38, 0.04);

  /* Transitions */
  --transition-fast: 120ms ease;
  --transition: 200ms ease;
  --transition-slow: 350ms ease;
}

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

body {
  font-family: var(--font-body);
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

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

h1, h2, h3, h4 {
  font-family: var(--font-body);
  font-weight: 700;
  line-height: 1.25;
  color: var(--color-text);
  letter-spacing: -0.01em;
}

/* --- Layout --- */
.container {
  max-width: 800px;
  margin: 0 auto;
  padding: var(--space-lg);
}

.container:has(.login-split) {
  max-width: 100%;
  padding: 0;
}

.container:has(.studio-layout) {
  max-width: 1240px;
  padding: var(--space-md) var(--space-lg);
}

/* --- Header --- */
header {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding: var(--space-sm) var(--space-lg);
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 10;
}

header .brand {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  text-decoration: none;
  color: var(--color-text);
}

header .brand:hover { color: var(--color-text); }

header .brand h1 {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--color-text);
}

header .brand img {
  height: 28px;
  width: 28px;
}

header nav {
  display: flex;
  align-items: center;
  gap: var(--space-md);
}

header nav a {
  color: var(--color-text-secondary);
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 500;
  transition: color var(--transition-fast);
}
header nav a:hover { color: var(--color-text); }

header nav .nav-logout {
  background: none;
  border: none;
  color: var(--color-text-secondary);
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 500;
  font-family: var(--font-body);
  transition: color var(--transition-fast);
}
header nav .nav-logout:hover { color: var(--color-text); }

/* --- Cards --- */
.card {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  margin-bottom: var(--space-md);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--color-border-light);
}

.card h2 {
  font-size: 1.2rem;
  margin-bottom: var(--space-md);
}

.card h3 {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: var(--space-sm);
}

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-xs);
  padding: var(--space-sm) var(--space-md);
  background: var(--color-primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 600;
  font-family: var(--font-body);
  letter-spacing: 0.01em;
  transition: background var(--transition-fast), box-shadow var(--transition-fast), transform var(--transition-fast);
  text-decoration: none;
  line-height: 1.5;
}
.btn:hover {
  background: var(--color-primary-hover);
  color: #fff;
  text-decoration: none;
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}
.btn:active {
  transform: translateY(0);
}
.btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--color-focus-ring);
}

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

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

/* Saved flash on save button */
.btn-saved {
  background: var(--color-success) !important;
  transform: translateY(-1px);
}

/* --- Forms --- */
input[type="text"],
input[type="password"],
input[type="number"],
select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-family: var(--font-body);
  color: var(--color-text);
  background: var(--color-surface);
  margin-bottom: var(--space-sm);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
input[type="text"]:focus,
input[type="password"]:focus,
input[type="number"]:focus,
select:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-focus-ring);
}

label {
  display: block;
  margin-bottom: var(--space-xs);
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--color-text);
}

/* --- Error --- */
.error {
  color: var(--color-error);
  background: #fdf2f2;
  border: 1px solid #f5d5d5;
  border-radius: var(--radius-sm);
  padding: var(--space-sm) var(--space-md);
  margin-bottom: var(--space-md);
  font-size: 0.875rem;
}

/* --- Login Page --- */
.login-split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  min-height: calc(100vh - 60px);
  gap: 0;
  margin: calc(-1 * var(--space-lg));
}

.login-hero {
  background: var(--color-primary-light);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-2xl) var(--space-xl);
}

.login-hero-inner {
  max-width: 340px;
}

.login-hero-logo {
  width: 48px;
  height: 48px;
  margin-bottom: var(--space-md);
}

.login-hero h2 {
  font-size: 1.8rem;
  line-height: 1.2;
  letter-spacing: -0.025em;
  color: var(--color-text);
  margin-bottom: var(--space-md);
}

.login-hero-desc {
  font-size: 0.95rem;
  line-height: 1.6;
  color: var(--color-text-secondary);
  margin-bottom: var(--space-xl);
}

.login-visual {
  margin-bottom: var(--space-xl);
}

.login-diagram {
  width: 100%;
  height: auto;
}

.login-steps {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.login-step {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--color-text-secondary);
}

.login-step-num {
  width: 22px;
  height: 22px;
  border-radius: var(--radius-full);
  background: var(--color-primary);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.login-form-side {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-2xl) var(--space-xl);
}

.login-card {
  width: 100%;
  max-width: 360px;
  margin: 0;
}

.login-card h2 {
  font-size: 1.3rem;
  margin-bottom: var(--space-lg);
}

.login-hint {
  margin-top: var(--space-md);
  font-size: 0.8rem;
  color: var(--color-muted);
  text-align: center;
}

.coming-soon-side {
  align-items: flex-start;
  overflow-y: auto;
  padding-top: var(--space-2xl);
  padding-bottom: var(--space-2xl);
}

.coming-soon-content {
  width: 100%;
  max-width: 400px;
}

@media (max-width: 768px) {
  .login-split {
    grid-template-columns: 1fr;
    min-height: auto;
  }
  .login-hero {
    padding: var(--space-xl) var(--space-lg);
  }
  .login-hero h2 {
    font-size: 1.4rem;
  }
  .login-form-side {
    padding: var(--space-lg);
  }
  .coming-soon-side {
    padding-top: var(--space-lg);
    padding-bottom: var(--space-lg);
  }
}

/* --- Feeds / Dashboard --- */
.feed-item {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-sm) 0;
  border-bottom: 1px solid var(--color-border-light);
}
.feed-item:last-child { border-bottom: none; }
.feed-item input[type="checkbox"] {
  accent-color: var(--color-primary);
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}
.feed-name { font-weight: 600; font-size: 0.9rem; }
.feed-desc { font-size: 0.8rem; color: var(--color-muted); margin-top: 1px; }
.feed-avatar {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  flex-shrink: 0;
}

/* Dashboard config cards */
.config-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-md) 0;
  border-bottom: 1px solid var(--color-border-light);
}
.config-row:last-child { border-bottom: none; }

.config-info .feed-name {
  font-size: 0.95rem;
}

.config-actions {
  display: flex;
  gap: var(--space-xs);
  flex-shrink: 0;
}

/* --- Mixed Feed Page --- */
.controls {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
  align-items: flex-end;
}

.weight-control {
  display: flex;
  flex-direction: column;
  font-size: 0.85rem;
}
.weight-control input[type="number"] {
  width: 80px;
  padding: var(--space-xs) var(--space-sm);
  margin-top: 2px;
  margin-bottom: 0;
}

/* --- Post Cards --- */
.post-card {
  background: var(--color-surface);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  margin-bottom: var(--space-sm);
  border: 1px solid var(--color-border-light);
  transition: box-shadow var(--transition), transform var(--transition);
}
.post-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.post-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: var(--space-sm);
}
.post-avatar {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-full);
  object-fit: cover;
}
.post-avatar-placeholder {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-full);
  background: var(--color-primary-light);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--color-primary);
}
.post-author { font-weight: 600; font-size: 0.9rem; }
.post-handle { color: var(--color-muted); font-size: 0.8rem; }
.post-text {
  margin-bottom: var(--space-sm);
  white-space: pre-wrap;
  line-height: 1.55;
  font-size: 0.9rem;
}
.post-meta {
  display: flex;
  gap: var(--space-md);
  font-size: 0.8rem;
  color: var(--color-muted);
}

/* --- Badges --- */
.signals {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-xs);
  margin-top: var(--space-sm);
}

.badge {
  padding: 2px 8px;
  border-radius: var(--radius-full);
  font-size: 0.7rem;
  font-weight: 600;
  white-space: nowrap;
  letter-spacing: 0.02em;
}

.badge-score {
  background: var(--color-badge-score-bg);
  color: var(--color-badge-score-text);
}

.badge-signal {
  background: var(--color-badge-signal-bg);
  color: var(--color-badge-signal-text);
}

.badge-feed {
  background: var(--color-badge-feed-bg);
  color: var(--color-badge-feed-text);
}

/* --- Feed Studio (Three-Panel Layout) --- */
.studio-layout {
  display: grid;
  grid-template-columns: 260px 1fr 200px;
  gap: var(--space-md);
  align-items: start;
}

.studio-content-wrapper {
  display: contents;
}

/* Left panel — tool palette */
.studio-left {
  position: sticky;
  top: 60px;
  max-height: calc(100vh - 76px);
  overflow-y: auto;
  overflow-x: hidden;
  /* Hide scrollbar but keep functionality */
  scrollbar-width: thin;
  scrollbar-color: var(--color-border) transparent;
}

.studio-left::-webkit-scrollbar {
  width: 4px;
}
.studio-left::-webkit-scrollbar-thumb {
  background: var(--color-border);
  border-radius: 2px;
}

.studio-left .card {
  margin-bottom: var(--space-sm);
  padding: var(--space-md);
  border-radius: var(--radius-md);
}

.studio-left .card h2 {
  font-size: 1rem;
  margin-bottom: var(--space-sm);
}

.studio-left .card h3 {
  font-size: 0.75rem;
  margin-bottom: var(--space-sm);
}

.studio-left select {
  font-size: 0.85rem;
  padding: var(--space-sm);
  margin-bottom: 0;
}

.studio-left input[type="text"] {
  font-size: 0.85rem;
  padding: var(--space-sm);
}

/* Center — the canvas */
.studio-center {
  min-width: 0;
}

/* Right panel — info */
.studio-right {
  position: sticky;
  top: 60px;
  background: var(--color-surface);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  border: 1px solid var(--color-border-light);
  box-shadow: var(--shadow-xs);
  font-size: 0.8rem;
}

.studio-right h3 {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: var(--space-sm);
}

.studio-actions {
  display: flex;
  gap: var(--space-xs);
  margin-bottom: var(--space-md);
  flex-wrap: wrap;
}

.studio-actions .btn {
  font-size: 0.8rem;
  padding: 6px var(--space-md);
}

.studio-spinner {
  position: fixed;
  top: var(--space-md);
  right: var(--space-md);
  background: var(--color-primary-light);
  color: var(--color-primary);
  padding: var(--space-xs) var(--space-md);
  border-radius: var(--radius-full);
  font-size: 0.8rem;
  font-weight: 600;
  z-index: 100;
  box-shadow: var(--shadow-md);
}

/* HTMX indicator: hidden by default, shown when active */
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator,
.htmx-indicator.htmx-request { display: block; }

/* --- Slider Controls --- */
.slider-control {
  margin-bottom: var(--space-md);
}

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

.slider-header label {
  font-size: 0.8rem;
  font-weight: 500;
  margin-bottom: 0;
  color: var(--color-text-secondary);
}

.slider-value {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--color-accent);
  min-width: 3em;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  background: var(--color-border);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
  transition: background var(--transition-fast);
}

input[type="range"]:hover {
  background: var(--color-muted);
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: var(--radius-full);
  background: var(--color-accent);
  cursor: pointer;
  border: 2px solid var(--color-surface);
  box-shadow: 0 1px 4px rgba(196, 112, 75, 0.3);
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.2);
  box-shadow: 0 2px 8px rgba(196, 112, 75, 0.4);
}

input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: var(--radius-full);
  background: var(--color-accent);
  cursor: pointer;
  border: 2px solid var(--color-surface);
  box-shadow: 0 1px 4px rgba(196, 112, 75, 0.3);
}

input[type="range"]:focus { outline: none; }
input[type="range"]:focus::-webkit-slider-thumb {
  box-shadow: 0 0 0 3px var(--color-focus-ring);
}

/* --- Analytics --- */
.analytics-bar-row {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  margin-bottom: 6px;
}

.analytics-bar-label {
  flex: 0 0 70px;
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--color-text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.analytics-bar-track {
  flex: 1;
  height: 6px;
  background: var(--color-border-light);
  border-radius: 3px;
  overflow: hidden;
}

.analytics-bar-fill {
  height: 100%;
  background: var(--color-accent);
  border-radius: 3px;
  transition: width var(--transition-slow);
}

.analytics-bar-value {
  flex: 0 0 30px;
  font-size: 0.7rem;
  font-weight: 700;
  text-align: right;
  color: var(--color-text);
  font-variant-numeric: tabular-nums;
}

.analytics-empty {
  color: var(--color-muted);
  font-size: 0.8rem;
}

.analytics-stats {
  display: flex;
  gap: var(--space-md);
  flex-wrap: wrap;
}

.analytics-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.analytics-stat-value {
  font-size: 1rem;
  font-weight: 700;
  color: var(--color-text);
  font-variant-numeric: tabular-nums;
}

.analytics-stat-label {
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--color-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* --- Responsive: collapse studio on narrow screens --- */
@media (max-width: 900px) {
  .studio-layout {
    grid-template-columns: 1fr;
  }
  .studio-left {
    position: static;
    max-height: none;
  }
  .studio-right {
    position: static;
  }
}

/* --- Utilities --- */
.mt-sm { margin-top: var(--space-sm); }
.mt-md { margin-top: var(--space-md); }
.mt-lg { margin-top: var(--space-lg); }
.text-center { text-align: center; }
.w-full { width: 100%; }

/* --- Page-load animation --- */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.card, .post-card {
  animation: fadeInUp var(--transition-slow) ease both;
}

/* Stagger post cards */
.post-card:nth-child(1) { animation-delay: 0ms; }
.post-card:nth-child(2) { animation-delay: 40ms; }
.post-card:nth-child(3) { animation-delay: 80ms; }
.post-card:nth-child(4) { animation-delay: 120ms; }
.post-card:nth-child(5) { animation-delay: 160ms; }
.post-card:nth-child(6) { animation-delay: 200ms; }
.post-card:nth-child(7) { animation-delay: 240ms; }
.post-card:nth-child(8) { animation-delay: 280ms; }
