:root {
  --bg: #f6f7f5;
  --surface: #ffffff;
  --surface-2: #f0f2ef;
  --text: #1c2321;
  --muted: #5d6865;
  --border: #dde2de;
  --brand: #0f6e64;
  --brand-ink: #ffffff;
  --brand-soft: #e2f1ee;
  --ok: #1d7a45;
  --ok-soft: #e3f3e8;
  --warn: #8a5a00;
  --warn-soft: #fbf0d9;
  --bad: #b3261e;
  --bad-soft: #fbe5e3;
  --info: #1f5fa8;
  --info-soft: #e4eefa;
  --radius: 10px;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.05), 0 2px 8px rgb(0 0 0 / 0.04);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121615;
    --surface: #1a201e;
    --surface-2: #222a28;
    --text: #e6ebe9;
    --muted: #9aa6a2;
    --border: #2f3936;
    --brand: #3fb3a4;
    --brand-ink: #06201d;
    --brand-soft: #18322e;
    --ok: #5cc98a;
    --ok-soft: #173024;
    --warn: #e6b450;
    --warn-soft: #33290f;
    --bad: #f08a80;
    --bad-soft: #3a1c19;
    --info: #7fb2f0;
    --info-soft: #172840;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--brand); }
img { max-width: 100%; display: block; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 0.5rem; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.1rem; }
p { margin: 0 0 0.75rem; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
[hidden] { display: none !important; }

/* ---- Top bar ---- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 1.5rem;
  padding: 0.6rem 1.25rem;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 0.5rem; font-weight: 650; color: var(--text); text-decoration: none; }
.brand-mark {
  display: grid; place-items: center; width: 30px; height: 30px; border-radius: 8px;
  background: var(--brand); color: var(--brand-ink); font-size: 0.8rem; letter-spacing: 0.02em;
}
.nav { display: flex; gap: 0.25rem; }
.nav a { padding: 0.4rem 0.75rem; border-radius: 8px; color: var(--muted); text-decoration: none; font-weight: 550; }
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { background: var(--brand-soft); color: var(--brand); }
.who { margin-left: auto; display: flex; align-items: center; gap: 0.75rem; color: var(--muted); font-size: 0.9rem; }

/* ---- Layout ---- */
.view { max-width: 1080px; margin: 0 auto; padding: 1.5rem 1.25rem 4rem; outline: none; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.page-head p { margin: 0; }
.grid-compose { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 1.25rem; align-items: start; }
.stack > * + * { margin-top: 1rem; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 1.1rem 1.2rem;
}
.card h2 { margin-bottom: 0.75rem; }
.sticky { position: sticky; top: 4.5rem; }

/* ---- Forms ---- */
label { display: block; font-weight: 600; margin-bottom: 0.35rem; }
.hint { font-weight: 400; color: var(--muted); font-size: 0.85rem; }
input[type="text"], input[type="email"], input[type="password"], input[type="url"], textarea {
  width: 100%; padding: 0.6rem 0.7rem; font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
}
textarea { min-height: 9rem; resize: vertical; }
input:focus-visible, textarea:focus-visible, button:focus-visible, a:focus-visible, .switch input:focus-visible + span {
  outline: 2px solid var(--brand); outline-offset: 2px;
}
.field + .field { margin-top: 1rem; }
.counter { display: flex; justify-content: space-between; gap: 1rem; margin-top: 0.3rem; font-size: 0.85rem; color: var(--muted); }
.counter .over { color: var(--bad); font-weight: 600; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  padding: 0.55rem 1rem; font: inherit; font-weight: 600; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); text-decoration: none;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn-primary:hover { background: var(--brand); filter: brightness(1.08); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-sm { padding: 0.3rem 0.65rem; font-size: 0.85rem; }
.btn-block { width: 100%; padding: 0.75rem 1rem; }
.btn-row { display: flex; gap: 0.5rem; flex-wrap: wrap; }

/* ---- Image picker ---- */
.dropzone {
  display: grid; place-items: center; gap: 0.4rem; text-align: center; min-height: 170px; padding: 1.25rem;
  border: 2px dashed var(--border); border-radius: var(--radius); background: var(--surface-2); color: var(--muted); cursor: pointer;
}
.dropzone:hover, .dropzone.drag { border-color: var(--brand); color: var(--text); }
.dropzone strong { color: var(--text); }
.preview { position: relative; border-radius: var(--radius); overflow: hidden; background: var(--surface-2); border: 1px solid var(--border); }
.preview img { width: 100%; max-height: 420px; object-fit: contain; }
.preview-meta { display: flex; justify-content: space-between; align-items: center; gap: 0.75rem; padding: 0.55rem 0.75rem; font-size: 0.85rem; color: var(--muted); border-top: 1px solid var(--border); background: var(--surface); flex-wrap: wrap; }

/* ---- Notices ---- */
.notice { padding: 0.7rem 0.85rem; border-radius: 8px; font-size: 0.9rem; border: 1px solid transparent; }
.notice p:last-child, .notice ul:last-child { margin-bottom: 0; }
.notice ul { margin: 0.25rem 0 0; padding-left: 1.1rem; }
.notice-warn { background: var(--warn-soft); color: var(--warn); }
.notice-bad { background: var(--bad-soft); color: var(--bad); }
.notice-info { background: var(--info-soft); color: var(--info); }
.notice .btn-row { margin-top: 0.55rem; }

/* ---- Target picker ---- */
.targets { list-style: none; margin: 0; padding: 0; }
.targets li { padding: 0.65rem 0; border-top: 1px solid var(--border); }
.targets li:first-child { border-top: 0; padding-top: 0; }
.target-row { display: flex; align-items: center; gap: 0.65rem; }
.target-row input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--brand); flex: none; }
.target-row label { margin: 0; font-weight: 550; flex: 1; min-width: 0; cursor: pointer; }
.target-reason { margin: 0.25rem 0 0 1.8rem; font-size: 0.82rem; color: var(--muted); }
.override { margin: 0.5rem 0 0 1.8rem; }
.override textarea { min-height: 5rem; }
.linkish { background: none; border: 0; padding: 0; font: inherit; color: var(--brand); cursor: pointer; font-size: 0.82rem; }

/* ---- Badges ---- */
.badge {
  display: inline-flex; align-items: center; gap: 0.3rem; padding: 0.1rem 0.5rem; border-radius: 999px;
  font-size: 0.75rem; font-weight: 650; white-space: nowrap; background: var(--surface-2); color: var(--muted);
}
.badge-fb { background: var(--info-soft); color: var(--info); }
.badge-ig { background: #f7e6f1; color: #9b2a6f; }
@media (prefers-color-scheme: dark) { .badge-ig { background: #3a1830; color: #f0a2d0; } }
.status-published { background: var(--ok-soft); color: var(--ok); }
.status-partial { background: var(--warn-soft); color: var(--warn); }
.status-failed { background: var(--bad-soft); color: var(--bad); }
.status-publishing, .status-pending { background: var(--info-soft); color: var(--info); }
.spin { width: 0.7em; height: 0.7em; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spin { animation: none; } }

/* ---- History ---- */
.post-list { display: grid; gap: 0.75rem; }
.post-item {
  display: grid; grid-template-columns: 88px minmax(0, 1fr) auto; gap: 1rem; align-items: center;
  padding: 0.75rem; color: inherit; text-decoration: none;
}
.post-item:hover { border-color: var(--brand); }
.thumb { width: 88px; height: 88px; border-radius: 8px; object-fit: cover; background: var(--surface-2); }
.thumb-empty { display: grid; place-items: center; color: var(--muted); font-size: 0.75rem; }
.post-caption { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; margin: 0 0 0.35rem; }
.chips { display: flex; flex-wrap: wrap; gap: 0.3rem; }
.empty { text-align: center; padding: 2.5rem 1rem; color: var(--muted); }

.detail { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.3fr); gap: 1.25rem; align-items: start; }
.caption-full { white-space: pre-wrap; word-break: break-word; }
.result-list { list-style: none; margin: 0; padding: 0; }
.result-list li { padding: 0.8rem 0; border-top: 1px solid var(--border); }
.result-list li:first-child { border-top: 0; padding-top: 0; }
.result-head { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.result-head strong { flex: 1; min-width: 8rem; }
.result-error { margin: 0.4rem 0 0; font-size: 0.85rem; color: var(--bad); word-break: break-word; }
.result-note { margin: 0.4rem 0 0; font-size: 0.85rem; color: var(--muted); }

/* ---- Targets table ---- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
th, td { text-align: left; padding: 0.6rem 0.5rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); font-weight: 650; }
tr:last-child td { border-bottom: 0; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.82rem; color: var(--muted); }
.switch { position: relative; display: inline-flex; align-items: center; gap: 0.5rem; margin: 0; font-weight: 500; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch span { width: 38px; height: 22px; border-radius: 999px; background: var(--border); position: relative; transition: background 0.15s; flex: none; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform 0.15s; box-shadow: 0 1px 2px rgb(0 0 0 / 0.3); }
.switch input:checked + span { background: var(--brand); }
.switch input:checked + span::after { transform: translateX(16px); }

/* ---- Login ---- */
.login { max-width: 380px; margin: 8vh auto 0; }
.login .brand { margin-bottom: 1.25rem; font-size: 1.1rem; }

/* ---- Toast ---- */
.toast {
  position: fixed; left: 50%; bottom: 1.25rem; transform: translateX(-50%); z-index: 20;
  max-width: min(92vw, 520px); padding: 0.7rem 1rem; border-radius: 10px;
  background: var(--text); color: var(--bg); box-shadow: 0 6px 24px rgb(0 0 0 / 0.2); font-size: 0.92rem;
}
.toast.bad { background: var(--bad); color: #fff; }

/* ---- Small screens ---- */
@media (max-width: 820px) {
  .grid-compose, .detail { grid-template-columns: 1fr; }
  .sticky { position: static; }
}
@media (max-width: 640px) {
  .topbar { flex-wrap: wrap; gap: 0.5rem 1rem; padding: 0.6rem 1rem; }
  .nav { order: 3; width: 100%; }
  .nav a { flex: 1; text-align: center; }
  .who #who-email { display: none; }
  .view { padding: 1.1rem 1rem 3rem; }
  .post-item { grid-template-columns: 64px minmax(0, 1fr); }
  .post-item .thumb { width: 64px; height: 64px; }
  .post-item > :last-child { grid-column: 1 / -1; }
}
