:root {
  --bg: #0d0d0d;
  --surface: #1a1a1a;
  --surface2: #242424;
  --text: #f5f0e8;
  --muted: #9a9a9a;
  --accent: #c9a96e;
  --accent-dim: #8a7349;
  --success: #6abf8a;
  --danger: #e07070;
  --border: #2e2e2e;
  --radius: 12px;
}

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

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

.nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 2rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.nav-brand { font-weight: 700; color: var(--accent); }
.nav-links { display: flex; gap: 1.5rem; align-items: center; }
.nav-links a { color: var(--muted); text-decoration: none; font-size: 0.95rem; }
.nav-links a:hover, .nav-links a.active { color: var(--accent); }
.nav-links .logout { color: var(--danger); }

.container { max-width: 1200px; margin: 0 auto; padding: 2rem; }

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 2rem;
  flex-wrap: wrap;
  gap: 1rem;
}

h1 { font-size: 1.75rem; margin-bottom: 0.25rem; }
h2 { font-size: 1.25rem; margin-bottom: 1rem; color: var(--accent); }
.subtitle { color: var(--muted); font-size: 0.95rem; }
.hint { color: var(--muted); font-size: 0.85rem; margin: 0.5rem 0 1rem; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-card.posting .stat-num { color: #7eb8ff; }

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  text-align: center;
}

.stat-num { display: block; font-size: 2rem; font-weight: 700; color: var(--accent); }
.stat-label { color: var(--muted); font-size: 0.85rem; }
.stat-card.posted .stat-num { color: var(--success); }
.stat-card.failed .stat-num { color: var(--danger); }

.info-banner {
  background: var(--surface2);
  border-left: 3px solid var(--accent);
  padding: 1rem 1.25rem;
  border-radius: var(--radius);
  margin-bottom: 2rem;
  font-size: 0.9rem;
}

.info-banner a { color: var(--accent); margin-left: 0.5rem; }

.next-up-banner {
  background: linear-gradient(135deg, #1a1a1a 0%, #2a2418 100%);
  border: 2px solid var(--accent);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}
.next-up-label {
  font-size: 0.75rem; font-weight: 700; letter-spacing: 0.15em;
  color: var(--accent); margin-bottom: 0.75rem;
}
.next-up-main { display: flex; gap: 1.25rem; align-items: center; }
.next-up-thumb {
  width: 80px; height: 80px; border-radius: 8px;
  object-fit: cover; flex-shrink: 0;
}
.next-up-time { font-size: 1.15rem; margin-bottom: 0.35rem; }
.next-up-quote { font-size: 0.95rem; margin-bottom: 0.25rem; }
.next-up-meta { font-size: 0.8rem; color: var(--muted); }
.slot-badge {
  display: inline-block; background: var(--accent); color: #000;
  font-size: 0.7rem; font-weight: 700; padding: 0.15rem 0.5rem;
  border-radius: 4px; margin-right: 0.5rem; text-transform: uppercase;
}
.post-card.is-next { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent-dim); }
.badge-next { top: auto; bottom: 0.75rem; right: 0.75rem; background: var(--accent); color: #000; }

.posts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 1.5rem;
}

.post-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.post-card.status-posted { opacity: 0.75; }
.post-card.status-failed { border-color: var(--danger); }
.post-card.status-skipped { opacity: 0.5; }

.post-image { position: relative; aspect-ratio: 1; background: #111; }
.post-image img { width: 100%; height: 100%; object-fit: cover; }
.no-image {
  display: flex; align-items: center; justify-content: center;
  height: 100%; color: var(--muted);
}

.badge {
  position: absolute; top: 0.75rem; right: 0.75rem;
  padding: 0.25rem 0.6rem; border-radius: 20px;
  font-size: 0.75rem; font-weight: 600; text-transform: uppercase;
  background: var(--surface2);
}
.badge-pending, .badge-scheduled { background: var(--accent-dim); color: #fff; }
.badge-posting { background: #3d6fa8; color: #fff; animation: pulse 1.2s infinite; }
.badge-posted { background: var(--success); color: #000; }
.badge-failed { background: var(--danger); color: #fff; }
.badge-skipped { background: var(--muted); }

.post-card.status-posting { border-color: #3d6fa8; }
.posting-line { color: #7eb8ff; font-size: 0.85rem; margin-bottom: 0.5rem; }

.book-upload-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1.5rem;
}
.book-upload-header h2 { margin: 0 0 0.25rem; font-size: 1rem; color: var(--accent); }
.book-upload-form { margin-top: 1rem; }
.upload-zone {
  display: block;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 2rem 1rem;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s;
}
.upload-zone:hover { border-color: var(--accent); }
.upload-zone-text { color: var(--muted); font-size: 0.95rem; }
.upload-zone-preview {
  display: block;
  margin-top: 0.5rem;
  color: var(--accent);
  font-size: 0.85rem;
}
.book-upload-options {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-top: 1rem;
  flex-wrap: wrap;
}
.book-upload-options label {
  color: var(--muted);
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.book-upload-options select {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.4rem 0.6rem;
  border-radius: 6px;
}
.book-upload-status {
  margin-top: 1rem;
  padding: 0.75rem 1rem;
  background: var(--surface2);
  border-radius: 8px;
  font-size: 0.9rem;
}
.book-upload-status ul {
  margin: 0.5rem 0 0 1rem;
  color: var(--muted);
  font-size: 0.85rem;
}

.canva-prompts-section {
  margin: 1.25rem 0;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}
.canva-prompts-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
}
.canva-prompts-header h3 {
  margin: 0;
  font-size: 0.95rem;
  color: var(--accent);
}
.canva-steps {
  margin: 0 0 1rem 1.1rem;
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.6;
}
.canva-prompt-hint {
  margin: 0 0 0.75rem;
}

.canva-prompt-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  max-height: 320px;
  overflow-y: auto;
}
.canva-prompt-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.85rem 1rem;
}
.category-badge {
  font-size: 0.7rem;
  background: var(--accent-dim);
  color: #fff;
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.usage-badge {
  font-size: 0.75rem;
  color: var(--muted);
}
.category-select {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  margin-bottom: 0.75rem;
  min-width: 200px;
}
.section-sub {
  font-size: 0.95rem;
  color: var(--accent);
  margin: 1.25rem 0 0.5rem;
}
.field-label {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 0.35rem;
}
.bg-library-grid {
  margin-top: 1.25rem;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 0.75rem;
}
.bg-library-item img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--border);
}
.bg-library-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  margin-top: 0.25rem;
}
.canva-prompt-top {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 0.5rem;
}
.canva-prompt-top .btn { margin-left: auto; }
.canva-prompt-label {
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text);
}
.canva-prompt-text {
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.45;
  margin: 0;
}

.replace-check {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--muted);
  cursor: pointer;
}
.replace-check input { accent-color: var(--accent); }
.queue-slots-hint strong { color: var(--accent); }

.activity-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1.5rem;
}
.activity-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}
.activity-header h2 { margin: 0; font-size: 1rem; }
.live-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--success);
  animation: pulse 2s infinite;
}
.activity-list {
  list-style: none;
  max-height: 220px;
  overflow-y: auto;
}
.activity-item {
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: baseline;
}
.activity-time { color: var(--muted); min-width: 130px; }
.activity-id { color: var(--accent); font-size: 0.75rem; }
.activity-item.level-success .activity-msg { color: var(--success); }
.activity-item.level-error .activity-msg { color: var(--danger); }
.activity-item.level-posting .activity-msg { color: #7eb8ff; }
.activity-empty { color: var(--muted); font-size: 0.85rem; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}

.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.post-body { padding: 1.25rem; }
.post-meta { display: flex; gap: 0.5rem; margin-bottom: 0.75rem; flex-wrap: wrap; }
.type-tag, .theme-tag {
  font-size: 0.75rem; padding: 0.2rem 0.5rem;
  border-radius: 4px; background: var(--surface2); color: var(--muted);
}
.quote { font-size: 1rem; margin-bottom: 0.75rem; line-height: 1.4; }
.schedule-line { font-size: 0.85rem; color: var(--accent); margin-bottom: 0.5rem; }
.posted-line { color: var(--success); }
.error-line { color: var(--danger); font-size: 0.85rem; margin-bottom: 0.5rem; }

.caption-details { margin: 1rem 0; }
.caption-details summary { cursor: pointer; color: var(--muted); font-size: 0.9rem; }
.caption-details textarea, .caption-details input {
  width: 100%; margin: 0.5rem 0; padding: 0.5rem;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 6px; color: var(--text); font-size: 0.85rem;
}
.caption-details textarea { min-height: 100px; resize: vertical; }
.caption-details label { font-size: 0.8rem; color: var(--muted); }

.post-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 1rem; }

.btn {
  padding: 0.6rem 1.2rem; border: none; border-radius: 8px;
  cursor: pointer; font-size: 0.9rem; font-weight: 500;
  transition: opacity 0.15s;
}
.btn:hover { opacity: 0.85; }
.btn-primary { background: var(--accent); color: #000; }
.btn-secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-small { padding: 0.4rem 0.75rem; font-size: 0.8rem; }
.btn-danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
.header-actions { display: flex; gap: 0.75rem; }

.login-card {
  max-width: 400px; margin: 4rem auto;
  background: var(--surface); padding: 2.5rem;
  border-radius: var(--radius); border: 1px solid var(--border);
  text-align: center;
}
.login-card h1 { margin-bottom: 0.5rem; }
.login-card input {
  width: 100%; padding: 0.75rem; margin: 1rem 0;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text);
}
.login-card label { display: block; text-align: left; color: var(--muted); font-size: 0.85rem; }
.login-card .btn { width: 100%; margin-top: 0.5rem; }

.flash { padding: 0.75rem 1rem; border-radius: 8px; margin-bottom: 1rem; }
.flash-error { background: #3a1a1a; color: var(--danger); }
.flash-success { background: #1a3a2a; color: var(--success); }

.empty-state { text-align: center; padding: 4rem; color: var(--muted); }
.empty-state .btn { margin-top: 1rem; }

.section { margin-bottom: 2.5rem; }
.times-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 1rem; }
.time-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.25rem;
}
.time-score { font-size: 1.5rem; font-weight: 700; color: var(--accent); }
.time-slot { font-weight: 600; margin: 0.25rem 0; }
.time-label { color: var(--muted); font-size: 0.85rem; margin-bottom: 0.5rem; }
.time-card p { font-size: 0.85rem; color: var(--muted); }

.hashtag-cloud { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 1rem 0; }
.hashtag {
  background: var(--surface2); padding: 0.35rem 0.75rem;
  border-radius: 20px; font-size: 0.85rem; cursor: pointer;
  border: 1px solid var(--border);
}
.hashtag:hover { border-color: var(--accent); color: var(--accent); }

.tips-list { list-style: none; }
.tips-list li {
  padding: 0.75rem 0; border-bottom: 1px solid var(--border);
  font-size: 0.95rem;
}
.tips-list li::before { content: "→ "; color: var(--accent); }

.milestone {
  padding: 0.75rem 1rem; background: var(--surface);
  border-radius: 8px; margin-bottom: 0.5rem; border: 1px solid var(--border);
}

.settings-form label { display: block; margin: 1rem 0 0.5rem; color: var(--muted); font-size: 0.9rem; }
.settings-form input, .settings-form textarea {
  width: 100%; max-width: 500px; padding: 0.75rem;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text);
}

.toast {
  position: fixed; bottom: 2rem; right: 2rem;
  background: var(--accent); color: #000;
  padding: 0.75rem 1.25rem; border-radius: 8px;
  font-weight: 500; z-index: 999; animation: fadeIn 0.2s;
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

@media (max-width: 768px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .container { padding: 1rem; }
  .nav { padding: 1rem; }
}
