*, *::before, *::after { box-sizing: border-box; }

:root {
  --bg: #0f0f13;
  --surface: #1a1a22;
  --surface2: #22222e;
  --border: #2e2e3e;
  --text: #e8e8f0;
  --text-muted: #888898;
  --accent: #7c6af7;
  --accent-hover: #9080ff;
  --success: #2ecc71;
  --danger: #e74c3c;
  --warning: #f39c12;
  --radius: 8px;
}

html, body { margin: 0; padding: 0; height: 100%; }

body {
  font-family: system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.6;
}

/* Nav */
nav {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 0.75rem 2rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.nav-brand { font-weight: 700; font-size: 1.1rem; margin-right: auto; }
nav a { color: var(--text-muted); text-decoration: none; transition: color 0.15s; }
nav a:hover, nav a.active { color: var(--text); }
.nav-logout {
  background: none; border: none; cursor: pointer;
  color: var(--text-muted); font-size: 15px; padding: 0;
}
.nav-logout:hover { color: var(--text); }

/* Main */
main { max-width: 860px; margin: 0 auto; padding: 2rem 1.5rem; }

.page-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 2rem;
}
.page-header h1 { margin: 0; font-size: 1.6rem; }
.header-actions { display: flex; gap: 0.75rem; }

/* Stats */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}
.stat-value { font-size: 2rem; font-weight: 700; }
.stat-label { color: var(--text-muted); font-size: 0.85rem; margin-top: 0.25rem; }
.stat-link { display: inline-block; margin-top: 0.5rem; font-size: 0.85rem; color: var(--accent); text-decoration: none; }
.stat-link:hover { color: var(--accent-hover); }
.ratings-seen { font-size: 0.8rem; color: var(--text-muted); margin: -0.5rem 0 0; }

/* Settings */
.settings-section { margin-top: 2rem; }
.settings-section h2 { font-size: 1.1rem; margin-bottom: 1rem; }
.setting-row {
  display: flex; align-items: center; gap: 1rem;
  padding: 0.875rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.setting-status { font-size: 0.8rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; }
.status-on { color: var(--success); }
.status-off { color: var(--text-muted); }

/* Queue */
@keyframes slide-in {
  from { opacity: 0; transform: translateY(-12px); }
  to   { opacity: 1; transform: translateY(0); }
}
#queue-list { display: flex; flex-direction: column; gap: 1rem; }
.queue-item--new { animation: slide-in 0.25s ease-out both; }
.queue-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}
.queue-item--posted { opacity: 0.6; }
.queue-item--rejected { opacity: 0.45; }
.queue-item--failed { border-color: var(--danger); }
.queue-item__text { font-style: italic; font-size: 1.05rem; margin: 0 0 0.5rem; }
.queue-item__context { color: var(--text-muted); font-size: 0.9rem; margin: 0 0 0.5rem; }

/* Text editor */
.text-editor {
  padding: 0.75rem 1.25rem;
  border-top: 1px solid var(--border);
}
.text-edit-area {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.95rem;
  line-height: 1.5;
  padding: 0.5em 0.75em;
  resize: vertical;
  font-family: inherit;
}
.text-edit-area:focus { outline: 2px solid var(--accent); border-color: transparent; }
.text-editor-controls {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 0.5rem;
  flex-wrap: wrap;
}
.font-size-label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}
.font-size-input {
  width: 64px;
  padding: 0.3em 0.5em;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.9rem;
  text-align: center;
}
.font-size-input:focus { outline: 2px solid var(--accent); border-color: transparent; }
.revert-btn { font-size: 0.8rem; }
.font-picker {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  margin-top: 0.5rem;
}
.font-option {
  display: flex;
  align-items: center;
  padding: 0.25em 0.7em;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 1.05rem;
  line-height: 1.3;
  transition: border-color 0.15s;
  user-select: none;
}
.font-option input[type="radio"] { display: none; }
.font-option--active { border-color: var(--accent); background: #1e1a3a; }
.font-option:hover:not(.font-option--active) { border-color: var(--text-muted); }

/* Canvas image preview */
.preview-wrapper {
  margin: 0.75rem -1.25rem;
  position: relative;
}
.preview-wrapper[hidden] { display: none; }
.image-preview {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 9;
  background: var(--bg);
}
.queue-item--pending .image-preview { cursor: default; }
.preview-wrapper--empty {
  margin: 0.75rem -1.25rem;
  padding: 0;
}
.preview-refresh {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 1.25rem;
  flex-wrap: wrap;
}
.preview-query-input {
  flex: 1;
  min-width: 140px;
  max-width: 260px;
  padding: 0.35em 0.6em;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.85rem;
}
.preview-query-input:focus { outline: 2px solid var(--accent); border-color: transparent; }
.preview-source-link {
  font-size: 0.78rem;
  color: var(--text-muted);
  text-decoration: none;
  white-space: nowrap;
}
.preview-source-link:hover { color: var(--text); }
.queue-item__meta { display: flex; align-items: center; gap: 0.75rem; margin: 0.75rem 0; }
.queue-item__date { font-size: 0.8rem; color: var(--text-muted); }
.queue-item__actions { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; padding-top: 0.75rem; border-top: 1px solid var(--border); }
.queue-item__actions--draft { flex-wrap: wrap; }
.scheduled-input {
  padding: 0.35em 0.6em;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.85rem;
  color-scheme: dark;
}
.scheduled-input:focus { outline: 2px solid var(--accent); border-color: transparent; }
.scheduled-time { font-size: 0.85rem; color: var(--text-muted); }
.queue-item__error { font-size: 0.85rem; color: var(--danger); flex: 1; }
.checkbox-label { display: flex; align-items: center; gap: 0.4rem; font-size: 0.9rem; cursor: pointer; }

/* History */
.history-list { display: flex; flex-direction: column; gap: 0.75rem; }
.history-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
}
.history-item--error { border-color: var(--danger); }
.history-item__text { font-style: italic; margin: 0 0 0.5rem; }
.history-item__meta { display: flex; align-items: center; gap: 0.75rem; font-size: 0.85rem; color: var(--text-muted); flex-wrap: wrap; }
.history-link { color: var(--accent); text-decoration: none; }
.history-link:hover { color: var(--accent-hover); }

/* Badges */
.badge {
  display: inline-block; padding: 0.15em 0.55em;
  border-radius: 4px; font-size: 0.75rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em;
}
.badge--draft { background: #1a1e2a; color: #7ab4f5; }
.badge--pending { background: #2a2a1a; color: var(--warning); }
.badge--approved { background: #1a2a1a; color: var(--success); }
.badge--posted { background: #1a1a2a; color: var(--accent); }
.badge--rejected { background: #2a1a1a; color: var(--danger); }
.badge--failed { background: #2a1a1a; color: var(--danger); }
.badge--image { background: #1e1e2e; color: #aaa; }

/* Buttons */
.btn {
  display: inline-block; padding: 0.45em 1em;
  border-radius: var(--radius); border: none; cursor: pointer;
  font-size: 0.9rem; font-weight: 500; text-decoration: none;
  transition: opacity 0.15s;
}
.btn:hover { opacity: 0.85; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }

/* Login */
body.login-page {
  display: flex; align-items: center; justify-content: center; min-height: 100vh;
}
.login-box {
  width: 100%; max-width: 360px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 2rem;
}
.login-box h1 { margin: 0 0 1.5rem; text-align: center; font-size: 1.4rem; }
.login-box label { display: flex; flex-direction: column; gap: 0.35rem; margin-bottom: 1rem; font-size: 0.9rem; color: var(--text-muted); }
.login-box input {
  padding: 0.6em 0.75em; background: var(--bg);
  border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text); font-size: 1rem;
}
.login-box input:focus { outline: 2px solid var(--accent); border-color: transparent; }
.login-box button { width: 100%; padding: 0.7em; background: var(--accent); color: #fff; border: none; border-radius: var(--radius); font-size: 1rem; cursor: pointer; margin-top: 0.5rem; }
.login-box button:hover { background: var(--accent-hover); }

/* Messages */
.error { color: var(--danger); background: #2a1a1a; border: 1px solid var(--danger); border-radius: var(--radius); padding: 0.5rem 0.75rem; }
.success { color: var(--success); background: #1a2a1a; border: 1px solid var(--success); border-radius: var(--radius); padding: 0.5rem 0.75rem; }
.empty-state { color: var(--text-muted); text-align: center; padding: 3rem 0; }

/* Enqueue form */
.enqueue-form {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

/* HTMX loading indicator */
.htmx-indicator { opacity: 0; transition: opacity 0.2s; }
.htmx-request .htmx-indicator { opacity: 1; }

/* ── Mobile ─────────────────────────────────────────────────────────────── */
@media (max-width: 600px) {
  /* Nav: tighten up, allow wrapping */
  nav {
    padding: 0.5rem 1rem;
    gap: 0.75rem;
    flex-wrap: wrap;
  }
  .nav-brand { font-size: 1rem; }
  nav a, .nav-logout { font-size: 0.875rem; }

  /* Main */
  main { padding: 1rem; }
  .page-header { margin-bottom: 1rem; }
  .page-header h1 { font-size: 1.3rem; }

  /* Queue cards: less padding, keep negative-margin bleed matching */
  .queue-item { padding: 1rem; }
  .preview-wrapper { margin: 0.75rem -1rem; }
  .preview-wrapper--empty { margin: 0.75rem -1rem; }
  .preview-refresh { padding: 0.4rem 1rem; }
  .text-editor { padding: 0.75rem 1rem; }

  /* Query input stretches to fill available row space */
  .preview-query-input { max-width: none; }

  /* Scheduled datetime takes full row on mobile */
  .enqueue-form { gap: 0.5rem; }
  .scheduled-input { width: 100%; }

  /* Prevent iOS Safari zooming on input focus (requires font-size >= 16px) */
  input, textarea, select {
    font-size: 16px !important;
  }
  /* But keep the font-size-input compact visually */
  .font-size-input { font-size: 14px !important; }

  /* Bigger touch targets */
  .btn { min-height: 40px; padding: 0.55em 1em; }
  .font-option { padding: 0.45em 0.85em; }
  .checkbox-label { min-height: 40px; }

  /* Stats: 2 columns */
  .stats-grid { grid-template-columns: 1fr 1fr; }

  /* Login page */
  .login-box { padding: 1.5rem 1rem; }
}
