:root {
  --navy: #0d2c41;
  --navy-2: #163b55;
  --teal: #239c98;
  --teal-dark: #1b7d7a;
  --slate: #6f6a67;
  --gold: #ffc665;
  --tan: #b58f64;
  --sky: #739cd1;
  --cream: #f6f3ee;
  --light: #e7e9ec;
  --line: #dfe2e6;
  --white: #ffffff;
  --ink: #142231;
  --muted: #5d6670;
  --ok: #1f8a5b;
  --ok-bg: #e5f4ec;
  --warn: #9a6200;
  --warn-bg: #fff4dc;
  --err: #b3261e;
  --err-bg: #fdeceb;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(13, 44, 65, 0.06), 0 4px 16px rgba(13, 44, 65, 0.06);
  --display: 'Poppins', 'Century Gothic', system-ui, sans-serif;
  --body: 'Open Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--body);
  color: var(--ink);
  background: var(--cream);
  font-size: 15px;
  line-height: 1.5;
}
h1, h2, h3 { font-family: var(--display); color: var(--navy); margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 24px; }
h2 { font-size: 19px; }
h3 { font-size: 16px; }
a { color: var(--teal-dark); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.hidden { display: none !important; }

/* ---------- header ---------- */
.topbar {
  background: var(--navy);
  color: var(--white);
  position: sticky; top: 0; z-index: 20;
}
.topbar-inner {
  max-width: 1180px; margin: 0 auto; padding: 10px 16px;
  display: flex; align-items: center; gap: 24px; flex-wrap: wrap;
}
.topbar-logo { height: 42px; width: auto; display: block; }
.login-logo { width: 230px; display: block; margin: 0 auto 8px; }
.brand-name { font-family: var(--display); font-size: 13px; letter-spacing: 0.18em; text-transform: uppercase; color: #b9d7e0; }
.tabs { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
.tab {
  background: none; border: 0; color: #cfe0e8; font: 600 14px var(--display);
  padding: 8px 14px; border-radius: 999px; cursor: pointer;
}
.tab:hover { color: var(--white); background: rgba(255, 255, 255, 0.08); }
.tab.active { background: var(--teal); color: var(--white); }
.topbar .link-btn { color: #cfe0e8; background: none; border: 0; cursor: pointer; font: 14px var(--body); }

main { max-width: 1180px; margin: 0 auto; padding: 24px 16px 80px; }

/* ---------- common ---------- */
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.stack > * + * { margin-top: 12px; }
.card {
  background: var(--white); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px;
}
.section-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }

.btn {
  display: inline-flex; align-items: center; gap: 6px; justify-content: center;
  border: 1px solid var(--line); background: var(--white); color: var(--navy);
  font: 600 14px var(--display); padding: 8px 14px; border-radius: 8px; cursor: pointer;
  text-decoration: none; white-space: nowrap;
}
.btn:hover { border-color: var(--navy); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn.primary { background: var(--teal); border-color: var(--teal); color: var(--white); }
.btn.primary:hover { background: var(--teal-dark); border-color: var(--teal-dark); }
.btn.navy { background: var(--navy); border-color: var(--navy); color: var(--white); }
.btn.danger { color: var(--err); }
.btn.danger:hover { border-color: var(--err); }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--light); }

label { display: block; font-weight: 600; font-size: 13px; color: var(--navy); margin-bottom: 4px; }
input[type=text], input[type=password], input[type=number], input[type=date], input[type=time], input[type=datetime-local], select, textarea {
  width: 100%; font: 15px var(--body); color: var(--ink);
  padding: 9px 11px; border: 1px solid #cdd3d9; border-radius: 8px; background: var(--white);
}
textarea { resize: vertical; min-height: 90px; line-height: 1.5; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(35, 156, 152, 0.35); border-color: var(--teal); }
.field { margin-bottom: 14px; }
.hint { font-size: 12.5px; color: var(--muted); margin-top: 4px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
@media (max-width: 640px) { .grid2, .grid3 { grid-template-columns: 1fr; } }

.pill {
  display: inline-flex; align-items: center; gap: 5px; font: 600 12px var(--display);
  padding: 3px 9px; border-radius: 999px; background: var(--light); color: var(--navy); white-space: nowrap;
}
.pill.draft { background: var(--light); color: var(--slate); }
.pill.scheduled { background: #e3f2f1; color: var(--teal-dark); }
.pill.publishing { background: #e8effa; color: #2f5d9c; }
.pill.published { background: var(--ok-bg); color: var(--ok); }
.pill.partial { background: var(--warn-bg); color: var(--warn); }
.pill.failed { background: var(--err-bg); color: var(--err); }
.pill.skipped { background: var(--light); color: var(--slate); }
.pill.pending { background: #eef1f4; color: var(--muted); }
.pill.ai { background: #fff4dc; color: #7a5200; }

.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--white); font-size: 13px; cursor: pointer; user-select: none;
}
.chip.on { background: var(--navy); color: var(--white); border-color: var(--navy); }
.platform-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.p-facebook { background: #1877f2; }
.p-instagram { background: #d62976; }
.p-linkedin, .p-linkedin_org { background: #0a66c2; }

.banner { padding: 12px 14px; border-radius: 10px; font-size: 14px; margin-bottom: 16px; border: 1px solid; }
.banner.info { background: #eaf4f4; border-color: #bfe0de; color: #154e4c; }
.banner.warn { background: var(--warn-bg); border-color: #f2d496; color: #6d4a00; }
.banner.err { background: var(--err-bg); border-color: #f2c2bf; color: #7d1c16; }
.banner.ok { background: var(--ok-bg); border-color: #b9e0c9; color: #175d3f; }
.banner ul { margin: 6px 0 0; padding-left: 18px; }

.empty { text-align: center; padding: 48px 16px; color: var(--muted); }
.empty h3 { margin-bottom: 6px; }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: var(--navy); }
.login-card { width: 100%; max-width: 380px; background: var(--white); border-radius: 16px; padding: 28px; box-shadow: 0 20px 50px rgba(0,0,0,0.25); }

.login-card .tag { text-align: center; font: 600 11px var(--display); letter-spacing: 0.3em; color: var(--slate); margin-bottom: 22px; }

/* ---------- queue ---------- */
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.filters select { width: auto; min-width: 200px; }
.day-head { font: 600 13px var(--display); color: var(--slate); text-transform: uppercase; letter-spacing: 0.08em; margin: 22px 0 8px; }
.post {
  display: grid; grid-template-columns: 1fr 180px; gap: 16px;
  background: var(--white); border: 1px solid var(--line); border-left: 4px solid var(--light);
  border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin-bottom: 12px;
}
.post.s-scheduled { border-left-color: var(--teal); }
.post.s-published { border-left-color: var(--ok); }
.post.s-failed { border-left-color: var(--err); }
.post.s-partial { border-left-color: var(--gold); }
.post.s-draft { border-left-color: #c9ced4; }
@media (max-width: 720px) { .post { grid-template-columns: 1fr; } }
.post-meta { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; font-size: 13px; }
.post-meta strong { font-family: var(--display); color: var(--navy); font-size: 14px; }
.post-body { white-space: pre-wrap; word-wrap: break-word; font-size: 14.5px; }
.post-body .footer-line { color: var(--muted); font-size: 12.5px; }
.post-img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 8px; background: var(--light); }
.post-noimg {
  width: 100%; aspect-ratio: 1; border-radius: 8px; border: 1px dashed #c9ced4; display: grid; place-items: center;
  text-align: center; color: var(--muted); font-size: 12.5px; padding: 10px;
}
.targets { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.target { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; padding: 3px 9px; border-radius: 999px; background: #f2f4f6; }
.target.t-published { background: var(--ok-bg); }
.target.t-failed { background: var(--err-bg); }
.target.t-skipped { background: var(--light); color: var(--muted); }
.target-err { font-size: 12.5px; color: var(--err); margin-top: 6px; }
.image-idea { font-size: 12.5px; color: var(--muted); margin-top: 8px; font-style: italic; }
.post-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 12px; }

/* ---------- clients ---------- */
.clients { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 16px; }
@media (max-width: 400px) { .clients { grid-template-columns: 1fr; } }
.client-card h3 { font-size: 17px; }
.linkbox { display: flex; gap: 6px; margin: 10px 0; }
.linkbox input { font-size: 12.5px; background: #f7f8f9; }
.acct { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--light); font-size: 14px; }
.acct .name { flex: 1; min-width: 0; overflow-wrap: anywhere; line-height: 1.35; }
.acct .name .warn-line { font-size: 12.5px; margin-top: 2px; }
.switch { position: relative; width: 36px; height: 20px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: #c9ced4; border-radius: 999px; transition: 0.15s; cursor: pointer; }
.switch span::before { content: ''; position: absolute; width: 16px; height: 16px; left: 2px; top: 2px; background: white; border-radius: 50%; transition: 0.15s; }
.switch input:checked + span { background: var(--teal); }
.switch input:checked + span::before { transform: translateX(16px); }

/* ---------- modal ---------- */
.modal-bg {
  position: fixed; inset: 0; background: rgba(13, 44, 65, 0.55); z-index: 50;
  display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow-y: auto;
}
.modal { background: var(--white); border-radius: 16px; width: 100%; max-width: 680px; padding: 22px; box-shadow: 0 20px 60px rgba(0,0,0,0.3); }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; flex-wrap: wrap; }
.close-x { background: none; border: 0; font-size: 24px; line-height: 1; cursor: pointer; color: var(--slate); }
.counter { font-size: 12px; color: var(--muted); text-align: right; margin-top: 3px; }
.img-preview { display: flex; gap: 12px; align-items: center; margin-top: 8px; }
.img-preview img { width: 84px; height: 84px; object-fit: cover; border-radius: 8px; }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 100;
  background: var(--navy); color: white; padding: 10px 18px; border-radius: 999px; font-size: 14px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.25); max-width: calc(100% - 32px);
}
.toast.err { background: var(--err); }

.activity { font-size: 13.5px; }
.activity div { padding: 8px 0; border-bottom: 1px solid var(--light); display: grid; grid-template-columns: 150px 90px 1fr; gap: 10px; }
@media (max-width: 640px) { .activity div { grid-template-columns: 1fr; gap: 2px; } }
.spinner { width: 16px; height: 16px; border: 2px solid rgba(255,255,255,0.4); border-top-color: white; border-radius: 50%; animation: spin 0.8s linear infinite; display: inline-block; }
.btn:not(.primary):not(.navy) .spinner { border-color: rgba(13,44,65,0.2); border-top-color: var(--navy); }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- autopilot ---------- */
.autopilot-box { margin-top: 12px; padding: 12px; border-radius: 10px; background: #f4f6f8; border: 1px solid var(--line); font-size: 14px; }
.autopilot-box.on { background: #e9f6f5; border-color: #bfe0de; }
.autopilot-box strong { font-family: var(--display); color: var(--navy); }

/* ---------- library ---------- */
.lib-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.lib-card { background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; display: flex; flex-direction: column; }
.lib-card img { width: 100%; aspect-ratio: 1; object-fit: contain; background: #e9edf0; display: block; }
.lib-body { padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 8px; flex: 1; font-size: 13.5px; }
.lib-body .desc { color: var(--ink); }
.flag { background: var(--warn-bg); color: #6d4a00; border-radius: 8px; padding: 6px 8px; font-size: 12.5px; }
.flag strong { text-transform: capitalize; }
.lib-actions { display: flex; align-items: center; gap: 8px; margin-top: auto; padding-top: 6px; border-top: 1px solid var(--light); }
.lib-actions .grow { flex: 1; font-size: 13px; }
.pick-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; max-height: 260px; overflow-y: auto; margin-top: 8px; }
.pick-grid img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 6px; cursor: pointer; border: 2px solid transparent; }
.pick-grid img:hover { border-color: var(--teal); }
