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

:root {
  --bg:        #f8f8f6;
  --surface:   #ffffff;
  --border:    #e2e2de;
  --text:      #1a1a18;
  --muted:     #6b6b65;
  --accent:    #1a56db;
  --accent-h:  #1648c0;
  --success:   #0a7c3e;
  --error:     #c0392b;
  --warn:      #b45309;
  --radius:    8px;
  --shadow:    0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:      #111110;
    --surface: #1c1c1a;
    --border:  #2e2e2b;
    --text:    #ededea;
    --muted:   #8a8a82;
  }
}

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

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

/* ── Nav ────────────────────────────────────────────────────────────────────── */
nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: 52px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.nav-brand { font-weight: 700; font-size: 16px; color: var(--text); }
.nav-links { display: flex; align-items: center; gap: 20px; font-size: 14px; }
.nav-email { color: var(--muted); }

/* ── Nav dropdown ───────────────────────────────────────────────────────────── */
.nav-dropdown { position: relative; }
.nav-dropdown-btn {
  background: none; border: none; cursor: pointer;
  font-size: 14px; color: var(--muted); padding: 4px 8px;
  border-radius: var(--radius);
}
.nav-dropdown-btn:hover { background: var(--bg); color: var(--text); }
.nav-dropdown-menu {
  display: none; position: absolute; right: 0; top: calc(100% + 6px);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  min-width: 140px; z-index: 100; overflow: hidden;
}
.nav-dropdown.open .nav-dropdown-menu { display: block; }
.nav-dropdown-menu a {
  display: block; padding: 10px 16px; font-size: 14px; color: var(--text);
}
.nav-dropdown-menu a:hover { background: var(--bg); text-decoration: none; }

/* ── Main ───────────────────────────────────────────────────────────────────── */
main { max-width: 860px; margin: 0 auto; padding: 40px 24px 80px; }

/* ── Buttons ─────────────────────────────────────────────────────────────────*/
.btn-primary, .btn-secondary, .btn-copy {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: background .15s, opacity .15s;
}
.btn-primary  { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-h); text-decoration: none; }
.btn-primary:disabled { opacity: .55; cursor: not-allowed; }
.btn-secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--bg); text-decoration: none; }
.btn-copy { background: var(--bg); color: var(--muted); border: 1px solid var(--border);
            font-size: 13px; padding: 5px 12px; }
.btn-copy.copied { background: #dcfce7; color: var(--success); border-color: #bbf7d0; }
.btn-run { font-size: 15px; padding: 10px 22px; }

/* ── Forms ───────────────────────────────────────────────────────────────────*/
label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 16px;
}
input[type="text"], input[type="email"], input[type="password"], textarea {
  width: 100%;
  padding: 9px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color .15s;
}
input:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: vertical; line-height: 1.5; }
.help { font-size: 13px; color: var(--muted); margin-bottom: 10px; }
code { font-size: 12px; background: var(--bg); padding: 1px 5px;
       border-radius: 4px; border: 1px solid var(--border); }
.optional { font-size: 12px; font-weight: 400; color: var(--muted); }

/* ── Alerts ──────────────────────────────────────────────────────────────────*/
.alert { padding: 12px 16px; border-radius: var(--radius); font-size: 14px; margin-bottom: 20px; }
.alert-error   { background: #fef2f2; color: var(--error); border: 1px solid #fecaca; }
.alert-success { background: #f0fdf4; color: var(--success); border: 1px solid #bbf7d0; }
@media (prefers-color-scheme: dark) {
  .alert-error   { background: #2d1515; border-color: #5c2020; }
  .alert-success { background: #0f2d1a; border-color: #1a5c30; }
}

/* ── Auth ────────────────────────────────────────────────────────────────────*/
.auth-card {
  max-width: 380px;
  margin: 80px auto 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 36px 32px;
  box-shadow: var(--shadow);
}
.auth-card h1 { font-size: 22px; margin-bottom: 4px; }
.subtitle { color: var(--muted); font-size: 14px; margin-bottom: 28px; }
.auth-card .btn-primary { width: 100%; justify-content: center; margin-top: 4px; }
.auth-link { font-size: 13px; color: var(--muted); margin-top: 20px; text-align: center; }

/* ── Dashboard ───────────────────────────────────────────────────────────────*/
.dashboard-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 32px;
}
.dashboard-header h1 { font-size: 26px; }

.run-panel { margin-bottom: 32px; }
.run-panel.hidden { display: none; }
.run-status {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  color: var(--muted);
  margin-bottom: 10px;
}
.run-log {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  font-size: 13px;
  color: var(--muted);
  max-height: 180px;
  overflow-y: auto;
  font-family: ui-monospace, monospace;
}
.log-line { margin-bottom: 4px; }
.log-error { color: var(--error); }

/* ── Spinner ─────────────────────────────────────────────────────────────────*/
.spinner {
  width: 16px; height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── History table ───────────────────────────────────────────────────────────*/
.history h2 { font-size: 17px; margin-bottom: 14px; }
.runs-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.runs-table th {
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
  padding: 0 12px 8px 0;
  border-bottom: 1px solid var(--border);
}
.runs-table td { padding: 10px 12px 10px 0; border-bottom: 1px solid var(--border); }
.link-view { font-size: 13px; }
.empty { color: var(--muted); font-size: 14px; padding: 20px 0; }

/* ── Badges ──────────────────────────────────────────────────────────────────*/
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
}
.badge-done    { background: #dcfce7; color: var(--success); }
.badge-running { background: #dbeafe; color: #1d4ed8; }
.badge-pending { background: #fef9c3; color: var(--warn); }
.badge-error   { background: #fee2e2; color: var(--error); }
@media (prefers-color-scheme: dark) {
  .badge-done    { background: #0f2d1a; color: #4ade80; }
  .badge-running { background: #1e2d4a; color: #60a5fa; }
  .badge-pending { background: #2d2510; color: #fbbf24; }
  .badge-error   { background: #2d1515; color: #f87171; }
}

/* ── Setup ───────────────────────────────────────────────────────────────────*/
.setup h1 { font-size: 26px; margin-bottom: 28px; }
.setup-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 20px;
}
.setup-section h2 { font-size: 16px; margin-bottom: 16px; }
.setup-actions { display: flex; gap: 12px; margin-top: 8px; }

/* ── API keys ────────────────────────────────────────────────────────────────*/
.api-keys h1 { font-size: 26px; margin-bottom: 8px; }
.new-key-box { word-break: break-all; }
.key-display {
  display: block; font-size: 13px; background: var(--bg);
  padding: 10px 12px; border-radius: var(--radius);
  border: 1px solid var(--border); margin: 8px 0 10px;
  font-family: ui-monospace, monospace;
}
.btn-revoke {
  background: none; border: 1px solid var(--border); border-radius: var(--radius);
  font-size: 12px; padding: 3px 10px; cursor: pointer; color: var(--error);
}
.btn-revoke:hover { background: #fee2e2; border-color: var(--error); }
.code-block {
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px;
  font-size: 12px; font-family: ui-monospace, monospace;
  white-space: pre; overflow-x: auto; line-height: 1.6;
}

/* ── Run result ──────────────────────────────────────────────────────────────*/
.run-result-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 32px;
}
.run-result-header h1 { font-size: 26px; }
.run-meta { font-size: 13px; color: var(--muted); margin-top: 4px; }

.result-section { margin-bottom: 40px; }
.result-section h2 { font-size: 17px; margin-bottom: 16px; }

/* Stories grid */
.stories-grid { display: grid; gap: 14px; }
.story-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
}
.story-header { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.story-category {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  background: var(--bg);
  padding: 2px 8px;
  border-radius: 4px;
  border: 1px solid var(--border);
}
.story-grade {
  font-size: 12px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 4px;
}
.grade-10, .grade-9 { background: #dcfce7; color: var(--success); }
.grade-8,  .grade-7 { background: #dbeafe; color: #1d4ed8; }
.grade-6,  .grade-5 { background: #fef9c3; color: var(--warn); }
@media (prefers-color-scheme: dark) {
  .grade-10, .grade-9 { background: #0f2d1a; color: #4ade80; }
  .grade-8,  .grade-7 { background: #1e2d4a; color: #60a5fa; }
  .grade-6,  .grade-5 { background: #2d2510; color: #fbbf24; }
}
.story-title   { font-size: 15px; font-weight: 600; margin-bottom: 6px; }
.story-summary { font-size: 14px; color: var(--muted); margin-bottom: 10px; }
.story-link    { font-size: 13px; }

/* Post cards */
.post-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  position: relative;
  margin-bottom: 14px;
}
.tweet-card { max-width: 560px; }
.post-text {
  white-space: pre-wrap;
  font-family: inherit;
  font-size: 14px;
  line-height: 1.65;
  margin-bottom: 12px;
}
.char-count { font-size: 12px; color: var(--muted); margin-right: 10px; }
.copy-source { position: absolute; opacity: 0; pointer-events: none; height: 0; }
