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

:root {
  --sidebar-bg:    #0f172a;
  --sidebar-text:  #cbd5e1;
  --sidebar-muted: #64748b;
  --sidebar-active-bg: rgba(255,255,255,.08);
  --sidebar-active: #f1f5f9;
  --accent:        #d4a017;
  --accent-hover:  #b8860b;

  --bg:            #f1f5f9;
  --card:          #ffffff;
  --border:        #e2e8f0;
  --text:          #0f172a;
  --muted:         #64748b;
  --label:         #334155;

  --green:  #16a34a;
  --red:    #dc2626;
  --blue:   #2563eb;
  --amber:  #d97706;

  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
}

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

/* ── layout ─────────────────────────────────────────────────────────────── */
.shell {
  display: grid;
  grid-template-columns: 220px 1fr 280px;
  min-height: 100vh;
}

/* ── sidebar ─────────────────────────────────────────────────────────────── */
.sidebar {
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-brand {
  padding: 20px 16px 16px;
  border-bottom: 1px solid rgba(255,255,255,.06);
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.brand-icon {
  font-size: 22px;
  color: var(--accent);
  line-height: 1;
}
.brand-name {
  font-size: 17px;
  font-weight: 700;
  color: #f8fafc;
  letter-spacing: -.3px;
}
.brand-sub {
  font-size: 11px;
  color: var(--sidebar-muted);
  text-transform: uppercase;
  letter-spacing: .8px;
}

.sidebar-section {
  padding: 20px 10px 6px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--sidebar-muted);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  margin: 1px 6px;
  border-radius: 6px;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background .12s, color .12s;
}
.nav-item:hover { background: rgba(255,255,255,.06); color: #f8fafc; }
.nav-item.active { background: var(--sidebar-active-bg); color: var(--sidebar-active); }
.nav-item svg { flex-shrink: 0; opacity: .8; }
.nav-item .nav-badge {
  margin-left: auto;
  background: var(--accent);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 10px;
}

.sidebar-footer {
  margin-top: auto;
  padding: 12px 16px;
  border-top: 1px solid rgba(255,255,255,.06);
  font-size: 11px;
  color: var(--sidebar-muted);
}

/* ── main ────────────────────────────────────────────────────────────────── */
.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.page { display: none; flex-direction: column; flex: 1; }
.page.active { display: flex; }

.page-header {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 11px 20px;
}
.page-header h1 {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -.3px;
}
.page-header p {
  font-size: 12px;
  color: var(--muted);
  margin-top: 1px;
}

.page-body {
  padding: 14px 20px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ── cards / sections ────────────────────────────────────────────────────── */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.card-header {
  padding: 9px 14px 8px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 7px;
}
.card-header h2 {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}
.card-header .card-icon {
  width: 22px;
  height: 22px;
  border-radius: 5px;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
}
.card-body { padding: 11px 14px; }

/* ── form elements ───────────────────────────────────────────────────────── */
.field { margin-bottom: 9px; }
.field:last-child { margin-bottom: 0; }

label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--label);
  margin-bottom: 3px;
  text-transform: uppercase;
  letter-spacing: .4px;
}
label .req { color: var(--red); margin-left: 2px; }
label .opt { color: var(--muted); font-weight: 400; text-transform: none; letter-spacing: 0; font-size: 11px; }

input[type="text"],
input[type="url"],
textarea,
select {
  width: 100%;
  padding: 6px 9px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 12px;
  font-family: inherit;
  color: var(--text);
  background: #fff;
  transition: border-color .15s, box-shadow .15s;
  appearance: none;
}
input[type="text"]:focus,
input[type="url"]:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(37,99,235,.1);
}
textarea { resize: vertical; min-height: 80px; }
select { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' fill='none'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%2364748b' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 28px; }

/* URL list */
.url-list { display: flex; flex-direction: column; gap: 6px; }
.url-row { display: flex; gap: 6px; align-items: center; }
.url-row input { flex: 1; }
.btn-icon {
  flex-shrink: 0;
  width: 30px;
  height: 30px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  color: var(--muted);
  transition: background .12s, color .12s, border-color .12s;
}
.btn-icon:hover { background: var(--bg); color: var(--text); border-color: #bdc5d0; }
.btn-icon.remove:hover { color: var(--red); border-color: var(--red); }
.btn-add-url {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  border: 1px dashed var(--border);
  border-radius: 6px;
  background: none;
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
  margin-top: 4px;
  transition: color .12s, border-color .12s;
}
.btn-add-url:hover { color: var(--blue); border-color: var(--blue); }

/* type radio */
.type-picker {
  display: flex;
  gap: 8px;
}
.type-option {
  flex: 1;
  position: relative;
}
.type-option input[type="radio"] {
  position: absolute;
  opacity: 0;
  width: 0; height: 0;
}
.type-option label {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 7px 6px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  margin: 0;
  text-transform: none;
  letter-spacing: 0;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  transition: border-color .15s, color .15s, background .15s;
}
.type-option label .type-icon { font-size: 17px; }
.type-option input:checked + label {
  border-color: var(--blue);
  color: var(--blue);
  background: rgba(37,99,235,.05);
}

/* ── image section ───────────────────────────────────────────────────────── */
.upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 12px;
  text-align: center;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.upload-zone:hover,
.upload-zone.drag-over {
  border-color: var(--blue);
  background: rgba(37,99,235,.03);
}
.upload-zone input[type="file"] { display: none; }
.upload-zone .upload-icon { font-size: 20px; margin-bottom: 3px; }
.upload-zone p { font-size: 12px; color: var(--muted); }
.upload-zone strong { color: var(--blue); }

.image-previews {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}
.img-thumb {
  position: relative;
  width: 80px;
  height: 60px;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.img-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.img-thumb .remove-img {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: rgba(0,0,0,.6);
  color: #fff;
  border: none;
  font-size: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

/* ── mode picker (segmented control) ─────────────────────────────────────── */
.mode-picker {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 8px;
}
.mode-opt { position: relative; }
.mode-opt input { position: absolute; opacity: 0; width: 0; height: 0; pointer-events: none; }
.mode-opt label {
  display: block;
  padding: 5px 13px;
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  color: var(--muted);
  background: transparent;
  border-right: 1px solid var(--border);
  margin: 0;
  text-transform: none;
  letter-spacing: 0;
  white-space: nowrap;
  transition: background .1s, color .1s;
}
.mode-opt:last-child label { border-right: none; }
.mode-opt input:checked + label {
  background: var(--accent);
  color: #fff;
}

/* layout picker */
.layout-picker {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}
.layout-opt {
  position: relative;
}
.layout-opt input { position: absolute; opacity: 0; width: 0; height: 0; }
.layout-opt label {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  padding: 6px 8px;
  border: 2px solid var(--border);
  border-radius: 6px;
  margin: 0;
  text-transform: none;
  letter-spacing: 0;
  font-size: 11px;
  color: var(--muted);
  transition: border-color .15s, color .15s;
}
.layout-opt input:checked + label { border-color: var(--accent); color: var(--accent); }
.layout-thumb {
  width: 52px;
  height: 34px;
  display: flex;
  gap: 2px;
}
.lt-cell {
  background: var(--border);
  border-radius: 2px;
  transition: background .15s;
}
.layout-opt input:checked + label .lt-cell { background: var(--accent); opacity: .7; }
.layout-thumb-auto {
  align-items: center;
  justify-content: center;
}
.layout-thumb-auto span {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .5px;
  color: var(--muted);
}
.layout-opt input:checked + label .layout-thumb-auto span { color: var(--accent); }
.border-ctrl-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
}
.border-ctrl-label {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  flex: 1;
}
#border-color {
  width: 32px;
  height: 26px;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  background: none;
}
.border-width-input {
  width: 48px;
  padding: 4px 6px;
  font-size: 12px;
  text-align: center;
}
.border-unit {
  font-size: 11px;
  color: var(--muted);
}

/* collage preview */
#collage-preview-wrap {
  margin-top: 14px;
  display: none;
}
#collage-preview-wrap.visible { display: block; }
#collage-preview-wrap label { margin-bottom: 6px; }
#collage-canvas {
  width: 100%;
  max-width: 540px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  display: block;
}

/* ── grid row ────────────────────────────────────────────────────────────── */
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

/* ── toggle row ──────────────────────────────────────────────────────────── */
.toggle-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
}
.toggle-row:last-child { border-bottom: none; margin-bottom: 0; }
.toggle-row .toggle-label {
  flex: 1;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
}
.toggle-row .toggle-desc {
  font-size: 11px;
  color: var(--muted);
  display: block;
  margin-top: 1px;
}
/* checkbox toggle */
.switch {
  position: relative;
  display: inline-flex;
  width: 36px;
  height: 20px;
  flex-shrink: 0;
}
.switch input { opacity: 0; width: 0; height: 0; }
.switch-track {
  position: absolute;
  inset: 0;
  border-radius: 20px;
  background: var(--border);
  cursor: pointer;
  transition: background .2s;
}
.switch input:checked + .switch-track { background: var(--blue); }
.switch-track::after {
  content: '';
  position: absolute;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #fff;
  top: 3px;
  left: 3px;
  transition: transform .2s;
  box-shadow: 0 1px 2px rgba(0,0,0,.2);
}
.switch input:checked + .switch-track::after { transform: translateX(16px); }

/* ── generate button + progress ──────────────────────────────────────────── */
.generate-bar {
  background: var(--card);
  border-top: 1px solid var(--border);
  padding: 16px 28px;
  display: flex;
  align-items: center;
  gap: 16px;
  position: sticky;
  bottom: 0;
}

.btn-generate {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 22px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, opacity .15s;
  white-space: nowrap;
}
.btn-generate:hover { background: var(--accent-hover); }
.btn-generate:disabled { opacity: .55; cursor: not-allowed; }
.btn-generate svg { animation: none; }
.btn-generate.loading svg { animation: spin .9s linear infinite; }

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

.progress-area { flex: 1; display: none; }
.progress-area.visible { display: block; }

.progress-steps { display: flex; flex-direction: column; gap: 2px; }
.progress-step {
  font-size: 12px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 6px;
}
.progress-step.active { color: var(--blue); font-weight: 500; }
.progress-step.done { color: var(--green); }
.progress-step.error { color: var(--red); }
.step-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}
.progress-step.active .step-dot { animation: pulse .8s ease-in-out infinite; }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.3} }

/* ── result card ─────────────────────────────────────────────────────────── */
#result-card {
  display: none;
  background: var(--card);
  border: 2px solid var(--green);
  border-radius: var(--radius);
  padding: 16px 18px;
  animation: fadeIn .3s ease;
}
#result-card.visible { display: block; }
@keyframes fadeIn { from{opacity:0;transform:translateY(6px)} to{opacity:1;transform:none} }

.result-header {
  font-size: 14px;
  font-weight: 600;
  color: var(--green);
  margin-bottom: 10px;
}
.result-links {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.result-link {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  text-decoration: none;
  border: 1px solid;
  transition: background .12s;
}
.result-link.edit { border-color: var(--blue); color: var(--blue); }
.result-link.edit:hover { background: rgba(37,99,235,.07); }
.result-link.preview { border-color: var(--border); color: var(--text); }
.result-link.preview:hover { background: var(--bg); }

/* error banner */
#error-banner {
  display: none;
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: var(--radius);
  padding: 12px 14px;
  font-size: 13px;
  color: var(--red);
  margin-bottom: 12px;
}
#error-banner.visible { display: block; }

/* ── schedule row ────────────────────────────────────────────────────────── */
.schedule-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.schedule-row input[type="datetime-local"] {
  flex: 1;
  max-width: 280px;
}
.sast-badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  background: rgba(212,160,23,.12);
  color: var(--accent-hover);
  border: 1px solid rgba(212,160,23,.3);
  white-space: nowrap;
  letter-spacing: .3px;
}

/* ── status badges ───────────────────────────────────────────────────────── */
.status-badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .4px;
  text-transform: uppercase;
  white-space: nowrap;
  vertical-align: middle;
}
.status-badge.submitted {
  background: rgba(99,102,241,.15);
  color: #818cf8;
  border: 1px solid rgba(99,102,241,.3);
}
.status-badge.scheduled {
  background: rgba(34,197,94,.15);
  color: #4ade80;
  border: 1px solid rgba(34,197,94,.3);
}
.status-badge.error {
  background: rgba(239,68,68,.15);
  color: #f87171;
  border: 1px solid rgba(239,68,68,.3);
}

/* ── submissions table ───────────────────────────────────────────────────── */
.sub-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.sub-table th {
  text-align: left;
  padding: 10px 16px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .6px;
  text-transform: uppercase;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
}
.sub-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  vertical-align: middle;
}
.sub-table tr:last-child td { border-bottom: none; }
.sub-table tr:hover td { background: rgba(255,255,255,.025); }
.sub-date { font-size: 12px; white-space: nowrap; color: var(--muted); }
.sub-title-link { color: var(--text); text-decoration: none; }
.sub-title-link:hover { color: var(--accent); text-decoration: underline; }
.sub-action {
  font-size: 12px;
  color: var(--accent);
  text-decoration: none;
  white-space: nowrap;
}
.sub-action:hover { color: var(--accent-hover); }

/* ── right panel ──────────────────────────────────────────────────────────── */
.right-panel {
  background: var(--card);
  border-left: 1px solid var(--border);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}
.rp-section { padding: 16px; }
.rp-heading {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .8px;
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}
.rp-heading svg { flex-shrink: 0; }
.rp-heading-icon { font-size: 13px; }
.rp-heading.done  { color: var(--green); }
.rp-heading.error { color: var(--red); }
.rp-heading.done .rp-heading-icon,
.rp-heading.error .rp-heading-icon { font-style: normal; }

/* how-to list */
.howto-list {
  list-style: none;
  padding: 0; margin: 0;
  display: flex;
  flex-direction: column;
  gap: 13px;
}
.howto-step { display: flex; gap: 10px; align-items: flex-start; }
.howto-num {
  flex-shrink: 0;
  width: 19px; height: 19px;
  border-radius: 50%;
  background: var(--border);
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 1px;
  transition: background .2s, color .2s;
}
.howto-num.done {
  background: var(--green);
  color: #fff;
}
.howto-body strong {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  display: block;
  margin-bottom: 2px;
}
.howto-body p {
  font-size: 11px;
  color: var(--muted);
  line-height: 1.5;
  margin: 0;
}
.howto-tip {
  margin-top: 16px;
  padding: 9px 11px;
  background: var(--bg);
  border-radius: var(--radius);
  font-size: 11px;
  color: var(--muted);
  line-height: 1.5;
}
.howto-tip strong { color: var(--accent); }

/* progress steps override size in right panel */
.rp-steps .progress-step { font-size: 12px; gap: 8px; padding: 4px 0; }

/* result in right panel */
.rp-result {
  margin-top: 14px;
  padding: 12px;
  background: var(--bg);
  border-radius: var(--radius);
  border: 1px solid var(--green);
  animation: fadeIn .25s ease;
}
.rp-result.error-state { border-color: var(--red); }
.rp-result-status {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}
.rp-post-id { font-size: 11px; color: var(--muted); }
.rp-result-links { display: flex; flex-direction: column; gap: 6px; }
.rp-link {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 10px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 12px;
  font-weight: 500;
  color: var(--text);
  text-decoration: none;
  transition: border-color .12s, color .12s;
}
.rp-link:hover { border-color: var(--accent); color: var(--accent); }
.rp-audit-note {
  font-size: 11px;
  color: var(--muted);
  margin-top: 8px;
  line-height: 1.4;
}
.rp-error { font-size: 12px; color: var(--red); line-height: 1.5; margin: 0; }
.rp-back-btn {
  display: block;
  width: 100%;
  margin-top: 14px;
  padding: 7px;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 11px;
  color: var(--muted);
  cursor: pointer;
  text-align: center;
  transition: background .12s, color .12s;
}
.rp-back-btn:hover { background: var(--bg); color: var(--text); }

/* ── utility ─────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }
.text-muted { color: var(--muted); font-size: 11px; margin-top: 4px; }
