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

:root {
  --bg:           #ffffff;
  --bg-secondary: #f7f7f6;
  --bg-tertiary:  #f0efed;
  --text:         #1a1a18;
  --text-secondary: #5a5956;
  --text-muted:   #9a9894;
  --border:       rgba(0,0,0,0.10);
  --border-md:    rgba(0,0,0,0.18);
  --purple:       #7F77DD;
  --purple-light: #EEEDFE;
  --purple-mid:   #AFA9EC;
  --purple-dark:  #534AB7;
  --purple-deep:  #3C3489;
  --red:          #E24B4A;
  --green:        #639922;
  --radius-sm:    6px;
  --radius-md:    8px;
  --radius-lg:    12px;
  --font:         'Inter', system-ui, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:           #1a1917;
    --bg-secondary: #211f1d;
    --bg-tertiary:  #2a2825;
    --text:         #f0ece6;
    --text-secondary: #a09c96;
    --text-muted:   #6a6660;
    --border:       rgba(255,255,255,0.09);
    --border-md:    rgba(255,255,255,0.16);
    --purple-light: #2a2650;
    --purple-mid:   #534AB7;
    --purple-dark:  #AFA9EC;
    --purple-deep:  #CECBF6;
  }
}

body {
  font-family: var(--font);
  background: var(--bg-tertiary);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
}

/* ─── Header ────────────────────────────────────────────── */
.header {
  background: var(--bg);
  border-bottom: 0.5px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}
.header-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 1.5rem;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: 15px;
  color: var(--text);
}
.header-badge {
  font-size: 11px;
  color: var(--text-muted);
  background: var(--bg-secondary);
  border: 0.5px solid var(--border);
  border-radius: 20px;
  padding: 3px 10px;
}

/* ─── Layout ────────────────────────────────────────────── */
.main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.5rem;
}
.app-grid {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 1rem;
  align-items: start;
}
@media (max-width: 760px) {
  .app-grid { grid-template-columns: 1fr; }
  .panel-right { order: -1; }
}
.panel {
  background: var(--bg);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.panel-right {
  background: var(--bg-secondary);
  position: sticky;
  top: 68px;
}

/* ─── Typography ────────────────────────────────────────── */
.label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 5px;
  display: block;
}
.section-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
}
.label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 5px;
}
.label-row .label { margin: 0; }
.row-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.link-small {
  font-size: 11px;
  color: var(--purple-dark);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  margin-top: 5px;
}
.link-small:hover { text-decoration: underline; }
.link-purple { color: var(--purple-dark); text-decoration: none; }
.link-purple:hover { text-decoration: underline; }

/* ─── Form elements ─────────────────────────────────────── */
textarea,
select,
input[type="password"],
input[type="text"] {
  width: 100%;
  font-family: var(--font);
  font-size: 13px;
  color: var(--text);
  background: var(--bg);
  border: 0.5px solid var(--border-md);
  border-radius: var(--radius-md);
  padding: 8px 11px;
  transition: border-color .15s;
  outline: none;
}
textarea { resize: none; line-height: 1.6; }
textarea:focus, select:focus, input:focus { border-color: var(--purple); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ─── Buttons ────────────────────────────────────────────── */
.btn-primary {
  width: 100%;
  padding: 11px;
  font-size: 13px;
  font-weight: 500;
  font-family: var(--font);
  border: none;
  border-radius: var(--radius-md);
  background: var(--purple);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  transition: opacity .15s;
}
.btn-primary:hover { opacity: .88; }
.btn-primary:disabled { opacity: .4; cursor: not-allowed; }

.btn-sm {
  padding: 5px 10px;
  font-size: 12px;
  font-family: var(--font);
  border: 0.5px solid var(--border-md);
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: background .15s;
}
.btn-sm:hover { background: var(--bg-secondary); }

.enhance-btn {
  padding: 6px 11px;
  font-size: 11px;
  font-family: var(--font);
  border: 0.5px solid var(--purple-mid);
  border-radius: var(--radius-md);
  background: var(--purple-light);
  color: var(--purple-deep);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
  transition: background .15s;
}
.enhance-btn:hover { background: #CECBF6; }
.enhance-btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-post {
  width: 100%;
  padding: 10px;
  font-size: 13px;
  font-weight: 500;
  font-family: var(--font);
  border: 0.5px solid var(--border-md);
  border-radius: var(--radius-md);
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  cursor: not-allowed;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  opacity: .5;
  transition: opacity .15s, background .15s;
}
.btn-post.enabled {
  background: var(--purple);
  color: #fff;
  border-color: transparent;
  cursor: pointer;
  opacity: 1;
}
.btn-post.enabled:hover { opacity: .88; }

/* ─── Platform buttons ───────────────────────────────────── */
.platform-btns { display: flex; gap: 5px; }
.platform-btn {
  flex: 1;
  padding: 7px 4px;
  font-size: 11px;
  font-family: var(--font);
  border: 0.5px solid var(--border-md);
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  transition: background .15s, border-color .15s, color .15s;
}
.platform-btn i { font-size: 15px; }
.platform-btn.active {
  border-color: var(--purple);
  color: var(--purple-dark);
  background: var(--purple-light);
}

/* ─── Tab bar ────────────────────────────────────────────── */
.tab-bar {
  display: flex;
  border: 0.5px solid var(--border-md);
  border-radius: var(--radius-md);
  overflow: hidden;
}
.tab {
  flex: 1;
  padding: 8px 6px;
  font-size: 12px;
  font-weight: 500;
  font-family: var(--font);
  text-align: center;
  cursor: pointer;
  background: transparent;
  color: var(--text-secondary);
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  transition: background .15s, color .15s;
}
.tab:not(:last-child) { border-right: 0.5px solid var(--border-md); }
.tab.active {
  background: var(--bg-tertiary);
  color: var(--text);
}

/* ─── Segmented control ──────────────────────────────────── */
.seg-group {
  display: flex;
  border: 0.5px solid var(--border-md);
  border-radius: var(--radius-md);
  overflow: hidden;
}
.seg {
  flex: 1;
  padding: 6px 3px;
  font-size: 11px;
  font-family: var(--font);
  text-align: center;
  cursor: pointer;
  background: transparent;
  color: var(--text-secondary);
  border: none;
  transition: background .15s;
}
.seg:not(:last-child) { border-right: 0.5px solid var(--border-md); }
.seg.active {
  background: var(--bg-tertiary);
  color: var(--text);
  font-weight: 500;
}

/* ─── Key row ────────────────────────────────────────────── */
.key-row {
  display: flex;
  gap: 7px;
  align-items: center;
}
.key-row input { flex: 1; }

/* ─── Status notices ─────────────────────────────────────── */
.notice {
  margin-top: 5px;
  padding: 7px 10px;
  border-radius: var(--radius-md);
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 7px;
}
.notice-success {
  background: #eaf3de;
  border: 0.5px solid #C0DD97;
  color: #3B6D11;
}
.notice-error {
  background: #FCEBEB;
  border: 0.5px solid #F7C1C1;
  color: #A32D2D;
}

/* ─── Drop zone ──────────────────────────────────────────── */
.drop-zone {
  border: 1.5px dashed var(--border-md);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  cursor: pointer;
  text-align: center;
  transition: border-color .2s, background .2s;
}
.drop-zone:hover, .drop-zone.drag-over {
  border-color: var(--purple);
  background: var(--purple-light);
}
.drop-icon { font-size: 24px; color: var(--text-muted); }
.drop-title { font-size: 13px; color: var(--text-secondary); }
.drop-sub { font-size: 11px; color: var(--text-muted); }
.drop-zone img {
  max-height: 180px;
  max-width: 100%;
  border-radius: var(--radius-md);
  object-fit: cover;
}

/* ─── Video preview ──────────────────────────────────────── */
.video-preview {
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-secondary);
  min-height: 260px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  overflow: hidden;
  transition: border-color .2s;
}
.video-preview.active-gen { border-color: var(--purple); }
.preview-icon { font-size: 28px; color: var(--text-muted); }
.preview-text { font-size: 13px; color: var(--text-muted); text-align: center; padding: 0 1.5rem; }
.preview-video { width: 100%; display: block; border-radius: var(--radius-md); }
.preview-actions { padding: 6px 0 2px; display: flex; gap: 7px; }

/* ─── Progress ───────────────────────────────────────────── */
.progress-bar {
  width: 75%;
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: var(--purple);
  border-radius: 2px;
  transition: width .5s ease;
}
.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top: 2px solid var(--purple);
  border-radius: 50%;
  animation: spin .8s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Caption ────────────────────────────────────────────── */
.caption-box {
  background: var(--bg);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-md);
  padding: 9px 11px;
  font-size: 13px;
  line-height: 1.65;
  min-height: 54px;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ─── Tags ───────────────────────────────────────────────── */
.tags-box { display: flex; flex-wrap: wrap; gap: 5px; min-height: 26px; }
.tag {
  padding: 3px 9px;
  background: var(--purple-light);
  color: var(--purple-deep);
  border-radius: 20px;
  font-size: 11px;
}
.tags-empty { font-size: 12px; color: var(--text-muted); }

/* ─── Gallery ────────────────────────────────────────────── */
.gallery-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.gallery-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.gallery-card {
  border: 0.5px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--bg);
  cursor: pointer;
  transition: border-color .2s;
}
.gallery-card:hover { border-color: var(--purple-mid); }
.gallery-card video,
.gallery-card .card-placeholder {
  width: 100%;
  aspect-ratio: 9/16;
  object-fit: cover;
  display: block;
  background: var(--bg-secondary);
}
.card-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 11px;
}
.card-meta { padding: 6px 8px; }
.card-prompt {
  font-size: 11px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card-date { font-size: 10px; color: var(--text-muted); margin-top: 2px; }
.gallery-empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: 2rem 1rem;
  color: var(--text-muted);
  font-size: 13px;
}
.gallery-empty i { font-size: 24px; display: block; margin-bottom: 8px; }

/* ─── Usage bar ──────────────────────────────────────────── */
.generate-footer { display: flex; flex-direction: column; gap: 6px; margin-top: auto; padding-top: .5rem; }
.usage-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.usage-label { font-size: 12px; color: var(--text-secondary); }
.usage-bar-wrap {
  background: var(--border);
  border-radius: 4px;
  height: 4px;
  overflow: hidden;
}
.usage-bar-fill {
  height: 100%;
  background: var(--purple);
  border-radius: 4px;
  transition: width .4s;
}
.usage-note { font-size: 10px; color: var(--text-muted); }

/* ─── Divider ────────────────────────────────────────────── */
.divider { height: 0.5px; background: var(--border); flex-shrink: 0; }

/* ─── Post note ──────────────────────────────────────────── */
.post-note { font-size: 11px; color: var(--text-muted); margin-top: 5px; text-align: center; }

/* ─── Section spacing ────────────────────────────────────── */
.section { display: flex; flex-direction: column; gap: 0; }

/* ─── Focus ring ─────────────────────────────────────────── */
:focus-visible { outline: 2px solid var(--purple); outline-offset: 2px; }

/* ─── Reduced motion ─────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .spinner { animation: none; border-top-color: var(--purple); opacity: .6; }
  .progress-fill { transition: none; }
}
