* { box-sizing: border-box; }

:root {
  --bg: #f6f4ef;
  --card: #ffffff;
  --ink: #21201c;
  --muted: #6f6a5e;
  --line: #e3ddd0;
  --accent: #28323c;
  --accent-ink: #ffffff;
  --gold: #9f9070;
  --danger: #a13a2c;
  --ok: #3d6b45;
}

body {
  margin: 0;
  font-family: -apple-system, "Helvetica Neue", Segoe UI, sans-serif;
  background: var(--bg);
  color: var(--ink);
}

header { background: var(--accent); color: var(--accent-ink); }
.header-inner { max-width: 1200px; margin: 0 auto; padding: 22px 24px; }
h1 { margin: 0; font-size: 24px; font-weight: 650; letter-spacing: 0.2px; }
.subtitle { margin: 6px 0 0; opacity: 0.85; font-size: 14px; }

.banner {
  max-width: 1200px; margin: 16px auto 0; padding: 12px 16px;
  background: #fdf3d7; border: 1px solid #e8d9a0; border-radius: 10px;
  font-size: 14px;
}
.banner code { background: #f3e9c8; padding: 1px 5px; border-radius: 4px; }
.banner p { margin: 0 0 8px; }
.banner-title { font-weight: 650; }
.banner a { color: inherit; }
#apikey-form { display: flex; gap: 8px; }
#apikey-input {
  flex: 1; font: inherit; font-size: 13.5px; padding: 8px 10px;
  border: 1px solid #d8c98f; border-radius: 8px; background: #fffdf5;
}
.banner-error { color: var(--danger); font-size: 13px; margin-top: 8px !important; }

.toolbar {
  max-width: 1200px; margin: 18px auto 0; padding: 0 24px;
  display: flex; flex-wrap: wrap; gap: 12px; align-items: center;
}
.tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.tab {
  border: 1px solid var(--line); background: var(--card); color: var(--ink);
  border-radius: 999px; padding: 7px 14px; font-size: 13.5px; cursor: pointer;
}
.tab.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.tab .count { opacity: 0.65; margin-left: 4px; font-size: 12px; }

.actions { margin-left: auto; display: flex; gap: 8px; }
button {
  font: inherit; font-size: 13.5px; border-radius: 9px; padding: 8px 15px;
  cursor: pointer; border: 1px solid transparent;
}
button.primary { background: var(--accent); color: var(--accent-ink); }
button.primary:hover { background: #37434f; }
button.secondary { background: var(--card); border-color: var(--line); color: var(--ink); }
button.secondary:hover { border-color: var(--gold); }
button:disabled { opacity: 0.45; cursor: default; }

.progress {
  max-width: 1200px; margin: 14px auto 0; padding: 10px 16px;
  background: #e9f0e7; border: 1px solid #c7d8c4; border-radius: 10px;
  font-size: 14px;
}

.drop-overlay {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  background: rgba(33, 32, 28, 0.55); backdrop-filter: blur(2px);
  pointer-events: none;
}
.drop-inner {
  border: 3px dashed var(--accent-ink); border-radius: 18px;
  padding: 48px 72px; text-align: center; color: var(--accent-ink);
}
.drop-title { font-size: 24px; font-weight: 650; }
.drop-brand { margin-top: 8px; font-size: 15px; opacity: 0.85; }

.publish-panel { margin-top: 12px; border-top: 1px solid var(--line); padding-top: 10px; }
.pub-title { font-size: 12px; font-weight: 650; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 6px; }
.pub-row { display: flex; flex-wrap: wrap; gap: 8px; }
.pub-chip {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--line); border-radius: 8px; padding: 4px 8px; font-size: 13px;
}
.pub-plat { font-weight: 600; }
.pub-info { color: var(--muted); }
.pub-ok { color: var(--ok); font-weight: 600; text-decoration: none; }
.pub-scheduled { color: var(--gold); font-weight: 600; }
.pub-fail { color: var(--danger); font-weight: 600; cursor: help; }
.pub-btn { padding: 3px 10px !important; font-size: 12px !important; }

.product-search { position: relative; }
.product-results {
  position: absolute; z-index: 30; left: 0; right: 0; top: 100%;
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 8px 24px rgba(33,32,28,0.14); margin-top: 4px;
  max-height: 320px; overflow-y: auto;
}
.pr-item {
  display: flex; align-items: center; gap: 10px; padding: 7px 10px;
  cursor: pointer; border-bottom: 1px solid var(--line); font-size: 13px;
}
.pr-item:last-child { border-bottom: none; }
.pr-item:hover { background: #f3efe6; }
.pr-img { width: 34px; height: 34px; border-radius: 6px; object-fit: cover; background: var(--line); flex: none; }
.pr-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pr-price { color: var(--muted); font-weight: 600; }
.pr-empty { padding: 8px 10px; font-size: 13px; color: var(--muted); }

/* ---------- image library ---------- */
.library-modal { width: min(1120px, 95vw); max-height: 92vh; display: flex; flex-direction: column; }
.lib-head { display: flex; align-items: center; gap: 12px; }
.lib-head h2 { margin: 0; }
.lib-brand-select { padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; font-size: 14px; background: var(--card); color: var(--ink); }
.lib-filters { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
.lib-chip { display: inline-flex; align-items: center; gap: 6px; padding: 5px 11px; border: 1px solid var(--line); border-radius: 999px; background: var(--card); color: var(--ink); font-size: 13px; cursor: pointer; }
.lib-chip:hover { border-color: var(--accent); }
.lib-chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.lib-chip .lib-count { font-variant-numeric: tabular-nums; opacity: 0.7; }
.lib-chip.active .lib-count { opacity: 0.9; }
.lib-selbar { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; gap: 12px; padding: 8px 12px; margin-bottom: 10px; background: var(--card); border: 1px solid var(--accent); border-radius: 10px; }
.lib-selcount { font-weight: 600; }
.lib-warn { color: #b45309; font-size: 13px; }
.link-btn { background: none; border: none; color: var(--accent); cursor: pointer; font-size: 13px; padding: 0; }
.link-btn:hover { text-decoration: underline; }
button.danger { background: #dc2626; border: 1px solid #dc2626; color: #fff; border-radius: 8px; padding: 7px 14px; cursor: pointer; font-size: 14px; }
button.danger:hover { background: #b91c1c; }
.lib-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 12px; overflow-y: auto; padding: 2px; flex: 1; }
.lib-empty { grid-column: 1 / -1; padding: 40px; text-align: center; color: var(--muted); }
.lib-tile { position: relative; aspect-ratio: 4 / 5; border-radius: 10px; overflow: hidden; cursor: pointer; border: 2px solid transparent; background: var(--line); }
.lib-tile.selected { border-color: var(--accent); }
.lib-thumb { width: 100%; height: 100%; object-fit: cover; display: block; }
.lib-check { position: absolute; top: 7px; left: 7px; width: 20px; height: 20px; border-radius: 5px; border: 2px solid #fff; background: rgba(0,0,0,0.35); box-shadow: 0 0 0 1px rgba(0,0,0,0.2); }
.lib-tile.selected .lib-check { background: var(--accent); border-color: #fff; }
.lib-tile.selected .lib-check::after { content: "✓"; position: absolute; inset: 0; color: #fff; font-size: 13px; line-height: 16px; text-align: center; font-weight: 700; }
.lib-badge { position: absolute; bottom: 26px; left: 7px; right: 7px; padding: 3px 7px; border-radius: 6px; font-size: 11px; font-weight: 600; color: #fff; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lib-name { position: absolute; bottom: 0; left: 0; right: 0; padding: 3px 7px; font-size: 10px; color: #fff; background: rgba(0,0,0,0.55); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.b-unused { background: #6b7280; }
.b-review { background: #d97706; }
.b-ready { background: #2563eb; }
.b-scheduled { background: #7c3aed; }
.b-published { background: #16a34a; }
.b-skipped { background: #4b5563; }
.b-generating { background: #d97706; }
.b-error { background: #dc2626; }
#library-modal.lib-dragging .modal { outline: 3px dashed var(--accent); outline-offset: -6px; }

.toggle-row { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.toggle-row input[type="checkbox"] { width: 18px; height: 18px; flex: none; accent-color: var(--accent); cursor: pointer; }
#settings-body select { padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; font-size: 14px; background: var(--card); color: var(--ink); }
#settings-body textarea { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font-size: 14px; font-family: inherit; }

main {
  max-width: 1200px; margin: 20px auto 60px; padding: 0 24px;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(500px, 1fr)); gap: 18px;
}
.empty { color: var(--muted); font-size: 15px; grid-column: 1 / -1; padding: 40px 0; text-align: center; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  overflow: hidden; display: flex; flex-direction: column;
}
.card-media { position: relative; background: #eceae3; height: 300px; overflow: hidden; }
/* The whole photo is always visible (portrait shows tall, landscape wide);
   a blurred copy of itself fills the space around it. */
.thumb-bg {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: cover; filter: blur(22px) brightness(0.85) saturate(1.1);
  transform: scale(1.15);
}
.thumb { position: relative; width: 100%; height: 100%; object-fit: contain; display: block; }
.badges { position: absolute; top: 10px; left: 10px; display: flex; gap: 6px; }
.badge {
  font-size: 11.5px; font-weight: 600; padding: 4px 10px; border-radius: 999px;
  background: rgba(255, 255, 255, 0.92); color: var(--ink);
}
.badge.status[data-status="review"] { background: #fdf3d7; }
.badge.status[data-status="flagged"] { background: #f7ddd7; color: var(--danger); }
.badge.status[data-status="approved"] { background: #dcead9; color: var(--ok); }
.badge.status[data-status="new"] { background: #e4e9ef; }
.badge.status[data-status="error"] { background: var(--danger); color: #fff; }
.badge.status[data-status="generating"] { background: #e4e9ef; }
.badge.status[data-status="skipped"] { background: #eee; color: var(--muted); }

.card-body { padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 10px; }
.analysis-line { margin: 0; font-size: 13px; color: var(--muted); }
.quality-issues { margin: 0; font-size: 13px; color: var(--danger); }
.error-line { margin: 0; font-size: 13px; color: var(--danger); }
.hidden { display: none !important; }

details { border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; }
details + details { margin-top: 8px; }
summary { cursor: pointer; font-weight: 600; font-size: 13.5px; }
textarea, input[type="text"], .f-pin-title {
  width: 100%; margin-top: 8px; font: inherit; font-size: 13.5px;
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px;
  resize: vertical; background: #fdfcf9;
}
textarea:focus, input:focus { outline: 2px solid var(--gold); border-color: transparent; }

.link-row .f-link {
  width: 100%; font: inherit; font-size: 13px; padding: 8px 10px; margin: 0;
  border: 1px dashed var(--line); border-radius: 8px; background: #fdfcf9;
}
.link-row .f-link:not(:placeholder-shown) { border-style: solid; }
.link-note { margin: 6px 2px 0; font-size: 12px; color: var(--muted); }
.link-note.used { color: var(--ok); }

.card-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.save-note { font-size: 12px; color: var(--ok); }

/* --- platform crop previews --- */
.crop-section { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.crop-hint { margin: 0 0 10px; font-size: 12.5px; color: var(--muted); }
.crop-hint strong { color: var(--ink); font-weight: 600; }
.crop-strip { display: flex; gap: 10px; align-items: flex-end; overflow-x: auto; padding-bottom: 4px; }
.crop-item { flex: 0 0 auto; text-align: center; cursor: pointer; border: none; background: none; padding: 0; }
.crop-item img {
  display: block; height: 96px; width: auto; border-radius: 6px;
  border: 1px solid var(--line); background: #eceae3;
}
.crop-item:hover img { outline: 2px solid var(--gold); }
.crop-item .crop-label { display: block; font-size: 11px; margin-top: 4px; color: var(--ink); }
.crop-item .crop-dims { display: block; font-size: 10px; color: var(--muted); }
.crop-item .crop-custom { display: block; font-size: 10px; color: var(--gold); font-weight: 600; }
.crop-item .crop-used { display: block; font-size: 10px; color: var(--accent); font-weight: 600; }

/* --- reframe dialog --- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(20, 20, 16, 0.55);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
.modal {
  background: var(--card); border-radius: 16px; padding: 20px 22px;
  max-width: min(92vw, 720px); max-height: 92vh; overflow: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}
.modal h2 { margin: 0 0 4px; font-size: 17px; }
.modal-hint { margin: 0 0 14px; font-size: 13px; color: var(--muted); }
#crop-viewport {
  position: relative; overflow: hidden; border-radius: 10px; margin: 0 auto;
  background: #eceae3; cursor: grab; touch-action: none;
  outline: 1px solid var(--line);
}
#crop-viewport.dragging { cursor: grabbing; }
#crop-image { position: absolute; top: 0; left: 0; max-width: none; user-select: none; pointer-events: none; }
.modal-actions { display: flex; gap: 8px; margin-top: 14px; align-items: center; }
.modal-actions .spacer { flex: 1; }

/* --- login --- */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-card {
  background: var(--card); border: 1px solid var(--line); border-radius: 16px;
  padding: 32px 34px; width: min(92vw, 400px);
}
.login-card h1 { color: var(--ink); font-size: 22px; margin: 0 0 18px; }
.login-card h2 { font-size: 16px; margin: 0 0 12px; }
.login-card input {
  width: 100%; font: inherit; font-size: 14px; padding: 10px 12px; margin-bottom: 10px;
  border: 1px solid var(--line); border-radius: 9px; background: #fdfcf9;
}
.login-card button { width: 100%; padding: 10px; font-size: 14px; }
.login-hint { font-size: 13px; color: var(--muted); margin: 0 0 12px; }

/* --- header user area --- */
.header-inner { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.user-area { text-align: right; font-size: 13px; opacity: 0.9; white-space: nowrap; }
.user-area a { color: inherit; }

/* --- post previews --- */
.preview-modal { width: min(92vw, 620px); }
#preview-tabs { margin-bottom: 14px; }
#preview-body { display: flex; justify-content: center; }
.pv {
  background: #fff; border: 1px solid #e2e2e2; border-radius: 12px;
  overflow: hidden; font-family: -apple-system, "Helvetica Neue", Segoe UI, sans-serif;
}
.pv img { display: block; width: 100%; }
.pv-avatar {
  width: 34px; height: 34px; border-radius: 50%; background: var(--accent);
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 15px; flex: 0 0 auto;
}
.pv-icons { display: flex; gap: 16px; color: #222; }
.pv-icons svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 1.8; }

/* Instagram */
.pv-instagram { width: 380px; max-width: 100%; }
.pv-instagram .pv-head { display: flex; align-items: center; gap: 10px; padding: 10px 12px; }
.pv-instagram .pv-name { font-weight: 600; font-size: 13.5px; color: #111; }
.pv-instagram .pv-actions { display: flex; justify-content: space-between; padding: 10px 12px 4px; }
.pv-instagram .pv-caption { padding: 2px 12px 14px; font-size: 13.5px; color: #111; line-height: 1.45; }
.pv-instagram .pv-caption b { font-weight: 600; }
.ig-more { color: #8e8e8e; cursor: pointer; }
.ig-tags { color: #00376b; }

/* Facebook */
.pv-facebook { width: 500px; max-width: 100%; }
.pv-facebook .pv-head { display: flex; align-items: center; gap: 10px; padding: 12px 14px 8px; }
.pv-facebook .pv-name { font-weight: 600; font-size: 14.5px; color: #050505; }
.pv-facebook .pv-meta { font-size: 12px; color: #65676b; }
.pv-facebook .pv-text { padding: 2px 14px 12px; font-size: 14.5px; color: #050505; line-height: 1.45; white-space: pre-wrap; }
.pv-facebook .pv-bar {
  display: flex; justify-content: space-around; border-top: 1px solid #e4e6eb;
  padding: 8px 0; color: #65676b; font-size: 13.5px; font-weight: 600;
}
.pv-facebook .pv-bar span { display: flex; align-items: center; gap: 6px; }
.pv-facebook .pv-bar svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 1.8; }

/* Pinterest */
.pv-pinterest { width: 300px; max-width: 100%; border: none; background: none; }
.pv-pinterest img { border-radius: 16px; border: 1px solid #e2e2e2; }
.pv-pinterest .pv-title { font-weight: 600; font-size: 14.5px; color: #111; margin: 10px 2px 4px; }
.pv-pinterest .pv-desc { font-size: 12.5px; color: #5f5f5f; margin: 0 2px 8px; line-height: 1.4; }
.pv-pinterest .pv-head { display: flex; align-items: center; gap: 8px; margin: 0 2px; }
.pv-pinterest .pv-name { font-size: 13px; color: #111; }

/* X */
.pv-x { width: 500px; max-width: 100%; padding: 12px 14px; }
.pv-x .pv-head { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.pv-x .pv-name { font-weight: 700; font-size: 14.5px; color: #0f1419; }
.pv-x .pv-handle { font-size: 13.5px; color: #536471; }
.pv-x .pv-text { font-size: 14.5px; color: #0f1419; line-height: 1.45; margin: 0 0 10px; white-space: pre-wrap; }
.pv-x img { border-radius: 16px; border: 1px solid #e2e2e2; }
.pv-x .pv-icons { justify-content: space-between; margin-top: 10px; color: #536471; max-width: 360px; }
.pv-x .pv-icons svg { width: 18px; height: 18px; }
.pv-count { text-align: center; font-size: 12px; color: var(--muted); margin-top: 10px; }
.pv-count.over { color: var(--danger); font-weight: 600; }

/* --- settings --- */
.settings-modal { width: min(92vw, 720px); }
#settings-tabs { margin-bottom: 12px; }
.settings-brand { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; margin-bottom: 12px; }
.settings-brand h3 { margin: 0 0 10px; font-size: 14.5px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.settings-row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.settings-row label { width: 170px; font-size: 13.5px; flex: 0 0 auto; }
.settings-row select, .settings-row input[type="text"], .settings-row input[type="email"],
.settings-row input[type="password"] {
  font: inherit; font-size: 13.5px; padding: 6px 8px; border: 1px solid var(--line);
  border-radius: 8px; background: #fdfcf9; flex: 1; max-width: 320px; margin: 0;
}
.settings-row input[type="time"] {
  font: inherit; font-size: 13.5px; padding: 5px 8px; border: 1px solid var(--line);
  border-radius: 8px; background: #fdfcf9;
}

/* posting schedule day toggles */
.sched-controls { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.day-toggles { display: inline-flex; gap: 4px; }
.day-toggle {
  width: 30px; height: 30px; padding: 0; border-radius: 50%;
  border: 1px solid var(--line); background: var(--card); font-size: 12px; font-weight: 600;
  color: var(--muted);
}
.day-toggle.on { background: var(--accent); border-color: var(--accent); color: #fff; }

/* connections */
.conn-status {
  font-size: 11.5px; font-weight: 600; padding: 3px 10px; border-radius: 999px;
  background: #eee; color: var(--muted);
}
.conn-status.partial { background: #fdf3d7; color: #7a6420; }
.conn-status.ok { background: #dcead9; color: var(--ok); }
.conn-guide { margin-top: 10px; border: none; padding: 0; }
.conn-guide summary { color: var(--accent); font-size: 13px; }
.conn-guide ol { margin: 8px 0 4px; padding-left: 20px; font-size: 13px; color: var(--ink); }
.conn-guide li { margin-bottom: 6px; line-height: 1.45; }

/* users */
.user-row { justify-content: space-between; }
.user-label { font-size: 13.5px; }
.user-email { color: var(--muted); margin-left: 6px; }
.user-role {
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.4px;
  background: #e4e9ef; border-radius: 999px; padding: 2px 8px; margin-left: 8px;
}

@media (max-width: 560px) {
  main { grid-template-columns: 1fr; }
}
