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

:root {
  --bg:        #0f1117;
  --surface:   #1a1d27;
  --surface2:  #22263a;
  --border:    #2e3250;
  --primary:   #6366f1;
  --primary-h: #818cf8;
  --green:     #22c55e;
  --yellow:    #f59e0b;
  --red:       #ef4444;
  --blue:      #3b82f6;
  --text:      #e2e8f0;
  --muted:     #94a3b8;
  --radius:    12px;
  --shadow:    0 4px 24px rgba(0,0,0,.4);
}

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

/* ── Header ───────────────────────────────────────────────────────────────── */
header {
  border-bottom: 1px solid var(--border);
  padding: 0 1.5rem;
  position: sticky;
  top: 0;
  background: rgba(15,17,23,.85);
  backdrop-filter: blur(12px);
  z-index: 100;
}
.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 60px;
}
.logo {
  display: flex;
  align-items: center;
  gap: .6rem;
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--text);
}

/* ── Main Layout ──────────────────────────────────────────────────────────── */
main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem 1.5rem 4rem;
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

/* ── Hero Card ────────────────────────────────────────────────────────────── */
.hero-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2.5rem;
  text-align: center;
  box-shadow: var(--shadow);
}
.hero-card h1 {
  font-size: 2rem;
  font-weight: 800;
  background: linear-gradient(135deg, #818cf8 0%, #c084fc 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: .6rem;
}
.subtitle { color: var(--muted); max-width: 560px; margin: 0 auto 2rem; }
.input-row {
  display: flex;
  gap: .75rem;
  max-width: 700px;
  margin: 0 auto;
}
.input-row input {
  flex: 1;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .75rem 1rem;
  font-size: 1rem;
  color: var(--text);
  outline: none;
  transition: border-color .2s;
}
.input-row input:focus { border-color: var(--primary); }
.input-row input::placeholder { color: var(--muted); }

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn-primary {
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: .75rem 1.5rem;
  font-size: .95rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: .5rem;
  transition: background .2s, transform .1s;
  white-space: nowrap;
}
.btn-primary:hover { background: var(--primary-h); }
.btn-primary:active { transform: scale(.97); }

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 8px;
  padding: .5rem 1rem;
  font-size: .875rem;
  cursor: pointer;
  transition: border-color .2s, color .2s;
}
.btn-ghost:hover { border-color: var(--primary); color: var(--primary); }

.btn-approve {
  background: #16a34a;
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: .6rem 1.2rem;
  font-size: .875rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: .4rem;
  transition: background .2s;
  white-space: nowrap;
}
.btn-approve:hover { background: #15803d; }
.btn-approve:disabled { background: #1e3a2a; color: #4ade80; cursor: default; }

.btn-revise {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .6rem 1rem;
  font-size: .875rem;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color .2s;
}
.btn-revise:hover { border-color: var(--primary); }

/* ── Progress Bar ─────────────────────────────────────────────────────────── */
.progress-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  padding: 1.25rem 1.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.step {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .35rem;
  min-width: 90px;
}
.step-dot {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--surface2);
  transition: all .3s;
}
.step span { font-size: .75rem; color: var(--muted); font-weight: 500; }
.step-line { flex: 1; height: 2px; background: var(--border); margin: 0 4px; max-width: 80px; transition: background .3s; }

.step.active .step-dot   { border-color: var(--primary); background: var(--primary); box-shadow: 0 0 12px rgba(99,102,241,.5); }
.step.active span        { color: var(--primary); }
.step.done .step-dot     { border-color: var(--green); background: var(--green); }
.step.done span          { color: var(--green); }
.step.done ~ .step-line  { background: var(--green); }
.step.active ~ .step-line { background: var(--border); }

/* ── Status Strip ─────────────────────────────────────────────────────────── */
#status-strip {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .75rem 1.25rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: .875rem;
  color: var(--muted);
}

/* ── Stop Button ──────────────────────────────────────────────────────────── */
.btn-stop {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  padding: .4rem .85rem;
  background: transparent;
  color: var(--red);
  border: 1px solid var(--red);
  border-radius: 6px;
  font-size: .8rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, color .15s;
  white-space: nowrap;
}
.btn-stop:hover {
  background: var(--red);
  color: #fff;
}
.btn-stop:disabled {
  opacity: .5;
  cursor: not-allowed;
}

/* ── Error Banner ─────────────────────────────────────────────────────────── */
#error-banner {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .875rem 1.25rem;
  background: #2d1b1b;
  border: 1px solid var(--red);
  border-radius: 8px;
  color: #fca5a5;
  font-size: .875rem;
}

/* ── Section titles ───────────────────────────────────────────────────────── */
.section-title { font-size: 1.25rem; font-weight: 700; }
.section-sub   { color: var(--muted); font-size: .875rem; margin-top: .25rem; }

/* ── Posts Grid ───────────────────────────────────────────────────────────── */
.posts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 1.25rem;
  margin-top: 1rem;
}

/* ── Platform Card ────────────────────────────────────────────────────────── */
.platform-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  box-shadow: var(--shadow);
  transition: border-color .3s;
}
.platform-card.status-approved { border-color: #16a34a; }
.platform-card.status-revising { border-color: var(--primary); }

.card-header {
  display: flex;
  align-items: center;
  gap: .75rem;
}
.platform-icon {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 1rem;
  flex-shrink: 0;
}
.linkedin-icon  { background: #0077b5; color: #fff; }
.facebook-icon  { background: #1877f2; color: #fff; }
.instagram-icon { background: linear-gradient(135deg, #f09433 0%, #e6683c 25%, #dc2743 50%, #cc2366 75%, #bc1888 100%); color: #fff; font-size: 1.3rem; }

.platform-meta  { display: flex; flex-direction: column; flex: 1; }
.platform-name  { font-weight: 700; font-size: .9rem; }
.char-count     { font-size: .75rem; color: var(--muted); }

/* ── Badges ───────────────────────────────────────────────────────────────── */
.badge {
  font-size: .7rem;
  font-weight: 700;
  padding: .25rem .6rem;
  border-radius: 99px;
  text-transform: uppercase;
  letter-spacing: .04em;
  white-space: nowrap;
}
.badge-pending  { background: #2d2510; color: var(--yellow); border: 1px solid #5a4010; }
.badge-revising { background: #1e1f3a; color: var(--primary); border: 1px solid #3d3f6b; }
.badge-approved { background: #0f2e1a; color: var(--green);  border: 1px solid #1a5c34; }
.badge-generating { background: #1e1f3a; color: var(--blue); border: 1px solid #2a3a6b; }
.badge-ready    { background: #2d2510; color: var(--yellow); border: 1px solid #5a4010; }

/* ── Post Content ─────────────────────────────────────────────────────────── */
.post-content {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
  font-size: .875rem;
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-word;
  min-height: 80px;
  color: var(--text);
}
.post-content.loading {
  display: flex; align-items: center; gap: .6rem; color: var(--muted);
}

.hashtags {
  display: flex;
  flex-wrap: wrap;
  gap: .4rem;
}
.tag {
  background: #1e1f3a;
  color: var(--primary);
  border: 1px solid #3d3f6b;
  border-radius: 4px;
  padding: .2rem .5rem;
  font-size: .75rem;
  font-weight: 500;
}

/* ── Card Actions ─────────────────────────────────────────────────────────── */
.card-actions {
  display: flex;
  flex-direction: column;
  gap: .75rem;
}
.revise-row {
  display: flex;
  gap: .6rem;
}
.revise-row textarea {
  flex: 1;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .5rem .75rem;
  font-size: .8rem;
  color: var(--text);
  resize: vertical;
  outline: none;
  font-family: inherit;
  transition: border-color .2s;
}
.revise-row textarea:focus { border-color: var(--primary); }
.revise-row textarea::placeholder { color: var(--muted); }

/* ── Image Card ───────────────────────────────────────────────────────────── */
.image-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  margin-top: 1rem;
}
.image-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  min-height: 380px;
  color: var(--muted);
  background: var(--surface2);
}
#image-preview {
  width: 100%;
  max-height: 500px;
  object-fit: cover;
  display: block;
}
.image-actions {
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.image-buttons {
  display: flex;
  flex-direction: column;
  gap: .75rem;
}
.image-buttons .revise-row { align-items: flex-start; }

/* ── Posting Grid ────────────────────────────────────────────────────────── */
.posting-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}
.posting-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  display: flex;
  align-items: center;
  gap: .75rem;
  box-shadow: var(--shadow);
  transition: border-color .3s;
}
.posting-card.posting-success { border-color: var(--green); }
.posting-card.posting-failed  { border-color: var(--red); }
.posting-status {
  margin-left: auto;
  font-size: .85rem;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: .4rem;
}
.posting-status a {
  color: var(--primary);
  text-decoration: underline;
}
.small-spinner { width: 12px; height: 12px; border-width: 1.5px; }
.summary-ok { color: var(--green); font-weight: 600; }
.summary-partial { color: var(--yellow, #eab308); font-weight: 600; }

/* ── Complete Section ─────────────────────────────────────────────────────── */
.complete-card {
  background: linear-gradient(135deg, #0f2e1a 0%, #1a1d27 100%);
  border: 1px solid #22c55e50;
  border-radius: var(--radius);
  padding: 3rem;
  text-align: center;
  box-shadow: var(--shadow);
}
.complete-icon { color: var(--green); margin-bottom: 1rem; }
.complete-card h2 { font-size: 1.75rem; font-weight: 800; margin-bottom: .5rem; }
.complete-card p  { color: var(--muted); margin-bottom: 1.5rem; }
.complete-card .btn-primary { margin: 0 auto; }

/* ── Spinner ──────────────────────────────────────────────────────────────── */
.spinner {
  display: inline-block;
  width: 16px; height: 16px;
  border: 2px solid rgba(255,255,255,.2);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .7s linear infinite;
  flex-shrink: 0;
}
.large-spinner { width: 36px; height: 36px; border-width: 3px; border-top-color: var(--primary); }

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Utilities ────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }

/* ── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  .hero-card { padding: 1.5rem 1rem; }
  .hero-card h1 { font-size: 1.5rem; }
  .input-row { flex-direction: column; }
  .progress-bar { gap: 0; padding: 1rem .5rem; overflow-x: auto; }
  .step { min-width: 60px; }
  .step span { font-size: .65rem; }
  .revise-row { flex-direction: column; }
}
