/* FB Page Manager — design system.
   Loaded after Bootstrap 5.1 (the views are written in Bootstrap markup) and restyles
   every component they use. Tokens live on :root; the shell is a fixed left rail plus a
   sticky top bar whose page switcher is the one control everything else hangs off. */

@import url('https://fonts.googleapis.com/css2?family=Manrope:wght@400;500;600;700;800&display=swap');

:root {
    --ink: #171a21;
    --ink-2: #4b5262;
    --ink-3: #7a8194;
    --paper: #f4f5f8;
    --panel: #ffffff;
    --line: #e1e4ea;
    --line-2: #cbd1db;

    --brand: #1b5cff;
    --brand-ink: #0f3fc2;
    --brand-soft: #e9efff;
    --amber: #f5a524;
    --amber-ink: #8a5a00;
    --amber-soft: #fff4dc;
    --ok: #16a34a;
    --ok-soft: #e6f6ec;
    --bad: #dc2626;
    --bad-soft: #fdeaea;
    --warn: #d97706;
    --warn-soft: #fff3e0;

    --r-ctl: 6px;
    --r-panel: 10px;
    --sidebar: 236px;
    --topbar: 56px;
    --font: "Manrope", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

    --bs-body-font-family: var(--font);
    --bs-primary: var(--brand);
    --bs-primary-rgb: 27, 92, 255;
    --bs-body-color: var(--ink);
    --bs-body-bg: var(--panel);
    --bs-link-color: var(--brand-ink);
    --bs-link-hover-color: var(--brand);
    --bs-border-color: var(--line);
}

* { box-sizing: border-box; }

html { font-size: 14px; scroll-behavior: smooth; }

body {
    margin: 0;
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.5;
    color: var(--ink);
    background: var(--panel);
    -webkit-font-smoothing: antialiased;
    font-feature-settings: "tnum" 1, "cv11" 1;
}

a { color: var(--brand-ink); text-decoration: none; }
a:hover { color: var(--brand); text-decoration: underline; }

:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- app shell ---------- */

.shell { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: 100vh; }

.rail {
    position: sticky; top: 0; height: 100vh;
    background: var(--paper);
    border-right: 1px solid var(--line);
    display: flex; flex-direction: column;
    padding: 18px 14px;
    overflow-y: auto;
}

.rail .brand {
    display: flex; align-items: center; gap: 10px;
    padding: 4px 8px 18px;
    color: var(--ink); font-weight: 800; font-size: 15px; letter-spacing: -0.01em;
}
.rail .brand:hover { text-decoration: none; }
.rail .brand .mark {
    width: 30px; height: 30px; border-radius: 8px;
    background: var(--brand); color: #fff;
    display: grid; place-items: center; font-weight: 800; font-size: 13px;
}
.rail .brand small { display: block; font-weight: 500; font-size: 11.5px; color: var(--ink-3); letter-spacing: 0; }

.rail .group { margin-top: 14px; }
.rail .group-title {
    font-size: 11.5px; font-weight: 600; color: var(--ink-3);
    padding: 0 10px 6px;
}
.rail .nav-item {
    display: flex; align-items: center; gap: 10px;
    padding: 7px 10px; margin-bottom: 2px;
    border-radius: var(--r-ctl);
    color: var(--ink-2); font-weight: 500; font-size: 13.5px;
}
.rail .nav-item svg { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; opacity: .85; }
.rail .nav-item:hover { background: #eaecf1; color: var(--ink); text-decoration: none; }
.rail .nav-item.active { background: var(--brand-soft); color: var(--brand-ink); font-weight: 700; }
.rail .nav-item.active svg { opacity: 1; }

.rail .rail-foot { margin-top: auto; padding: 14px 8px 0; font-size: 12px; color: var(--ink-3); }

.rail-toggle { display: none; }

.stage { min-width: 0; display: flex; flex-direction: column; }

.topbar {
    position: sticky; top: 0; z-index: 20;
    height: var(--topbar);
    display: flex; align-items: center; gap: 14px;
    padding: 0 28px;
    background: rgba(255,255,255,.92); backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--line);
}
.topbar .spacer { flex: 1; }

/* The page switcher: one pill, always visible, remembered across screens. A searchable
   combobox (site.js) drawn over a hidden native <select> that remains the data source. */
.context { position: relative; }
.context-btn {
    display: inline-flex; align-items: center; gap: 10px;
    height: 38px; padding: 0 10px 0 4px; min-width: 300px; max-width: min(460px, 60vw);
    border: 1px solid var(--line-2); border-radius: 999px;
    background: var(--panel); color: var(--ink); font: inherit; text-align: left; cursor: pointer;
}
.context-btn:hover { border-color: var(--ink-3); }
.context-btn:focus-visible, .context.open .context-btn { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.context .avatar {
    width: 28px; height: 28px; border-radius: 50%; flex: none;
    background: var(--brand); color: #fff;
    display: grid; place-items: center; font-size: 11.5px; font-weight: 800;
}
.context .avatar.all { background: var(--ink-2); }
.context-text { display: flex; flex-direction: column; min-width: 0; flex: 1; line-height: 1.15; }
.context-label { font-size: 11px; color: var(--ink-3); }
.context-name { font-weight: 700; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.context-chev { width: 16px; height: 16px; stroke: var(--ink-2); fill: none; stroke-width: 2.4; flex: none; transition: transform .15s; }
.context.open .context-chev { transform: rotate(180deg); }

.context-pop {
    position: absolute; left: 0; top: calc(100% + 6px); z-index: 60;
    width: 480px; max-width: calc(100vw - 32px);
    background: var(--panel); border: 1px solid var(--line-2); border-radius: var(--r-panel);
    box-shadow: 0 16px 40px rgba(23,26,33,.16); padding: 8px; display: flex; flex-direction: column; gap: 6px;
}
.context-search {
    width: 100%; height: 36px; padding: 0 12px 0 34px; border-radius: var(--r-ctl);
    border: 1px solid var(--line-2); font: inherit; font-size: 13.5px; color: var(--ink); background: var(--panel);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%237a8194' stroke-width='2'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='M20 20l-4-4'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: 11px center;
}
.context-search:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.context-search::-webkit-search-cancel-button { -webkit-appearance: none; }
.context-list { list-style: none; margin: 0; padding: 0; max-height: min(60vh, 520px); overflow-y: auto; overscroll-behavior: contain; }
.context-item {
    display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: var(--r-ctl);
    cursor: pointer; color: var(--ink); font-size: 13.5px; line-height: 1.3;
}
.context-item .av { width: 26px; height: 26px; border-radius: 50%; flex: none; background: var(--brand-soft); color: var(--brand-ink); display: grid; place-items: center; font-size: 10.5px; font-weight: 800; }
.context-item.all .av { background: var(--paper); color: var(--ink-2); }
.context-item .nm { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.context-item .nm mark { background: var(--amber-soft); color: inherit; padding: 0; border-radius: 2px; }
.context-item .tick { width: 16px; height: 16px; stroke: var(--brand); fill: none; stroke-width: 2.5; flex: none; visibility: hidden; }
.context-item.selected { font-weight: 700; }
.context-item.selected .tick { visibility: visible; }
.context-item:hover, .context-item.active { background: var(--paper); }
.context-item.active { box-shadow: inset 0 0 0 1px var(--line-2); }
.context-empty { padding: 12px; color: var(--ink-3); font-size: 13px; text-align: center; }
.context-count { padding: 2px 10px 4px; font-size: 11.5px; color: var(--ink-3); }

.chip {
    display: inline-flex; align-items: center; gap: 6px;
    height: 30px; padding: 0 10px; border-radius: 999px;
    font-size: 12.5px; font-weight: 600; white-space: nowrap;
}
.chip svg { width: 15px; height: 15px; stroke: currentColor; fill: none; stroke-width: 2; }
.chip.ai { background: var(--amber-soft); color: var(--amber-ink); }
.chip.ai.empty { background: var(--bad-soft); color: var(--bad); }
.chip.user { background: var(--paper); color: var(--ink-2); }
/* The user chip is a link to your own account, so it needs link resets + a hover affordance. */
a.chip.user { text-decoration: none; transition: background .12s, border-color .12s; }
a.chip.user:hover { background: var(--brand-soft); color: var(--ink); }
.chip.user b { color: var(--ink); font-weight: 700; }
.chip.user .role { font-size: 11px; padding: 1px 6px; border-radius: 4px; background: var(--line); color: var(--ink-2); }
.chip.user .role.admin { background: var(--brand-soft); color: var(--brand-ink); }

.btn-quiet {
    border: 1px solid var(--line-2); background: var(--panel); color: var(--ink-2);
    height: 30px; padding: 0 10px; border-radius: var(--r-ctl);
    font: inherit; font-size: 12.5px; font-weight: 600; cursor: pointer;
}
.btn-quiet:hover { border-color: var(--ink-3); color: var(--ink); }

/* Full width: every screen stretches to the right edge on wide monitors. */
main.content { padding: 26px 28px 60px; width: 100%; }

/* ---------- typography ---------- */

h1, .h1 { font-size: 22px; font-weight: 800; letter-spacing: -0.02em; line-height: 1.2; margin: 0 0 6px; }
h2, .h2 { font-size: 18px; font-weight: 700; letter-spacing: -0.01em; }
h3, .h3 { font-size: 16px; font-weight: 700; }
h4, .h4, h5, .h5, h6, .h6 { font-weight: 700; }
.h5 { font-size: 14.5px; }
.display-6 { font-size: 26px; font-weight: 800; letter-spacing: -0.02em; }
.text-muted { color: var(--ink-3) !important; }
.small, small { font-size: 12.5px; }
code { color: var(--brand-ink); background: var(--brand-soft); padding: 1px 5px; border-radius: 4px; font-size: 12px; }
hr { border-color: var(--line); opacity: 1; }

/* Page header patterns the views already use. */
main.content > h1 { margin-bottom: 20px; }
main.content > h1 + p.text-muted { margin-top: -12px; margin-bottom: 20px; }
main.content > .d-flex > h1 { margin-bottom: 0; }

/* ---------- panels, tables, lists ---------- */

.card { border: 1px solid var(--line); border-radius: var(--r-panel); background: var(--panel); box-shadow: none; }
.card-header {
    background: transparent; border-bottom: 1px solid var(--line);
    padding: 10px 16px; font-weight: 700; font-size: 13.5px; color: var(--ink);
}
.card-header.bg-light { background: transparent !important; }
.card-body { padding: 16px; }
.card.border-info, .card.border-primary { border-color: var(--line) !important; }

.card.text-center.p-3 { padding: 14px 12px !important; }
.card.text-center.p-3 .h2, .card.text-center.p-3 .h3 { font-size: 24px; font-weight: 800; letter-spacing: -0.02em; }
.card.text-center.p-3 .text-muted { font-size: 12.5px; }

.table { color: var(--ink); font-size: 13.5px; border-color: var(--line); margin-bottom: 20px; }
.table > :not(caption) > * > * { padding: 10px 12px; border-bottom-width: 1px; background: transparent; box-shadow: none; }
.table thead th, .table > thead > tr > th {
    font-size: 12px; font-weight: 600; color: var(--ink-3);
    border-bottom: 1px solid var(--line-2); white-space: nowrap;
}
.table-hover > tbody > tr:hover > * { background: var(--paper); color: inherit; }
.table-sm > :not(caption) > * > * { padding: 7px 10px; }
.table-striped > tbody > tr:nth-of-type(odd) > * { background: transparent; }

.list-group-item { border-color: var(--line); padding: 10px 14px; font-size: 13.5px; }
.list-group-item.active { background: var(--brand-soft); color: var(--brand-ink); border-color: var(--line); }

dl.row dt { font-weight: 600; color: var(--ink-3); font-size: 12.5px; }

/* ---------- controls ---------- */

.btn {
    font-weight: 600; font-size: 13.5px; border-radius: var(--r-ctl);
    padding: 7px 14px; line-height: 1.4; box-shadow: none !important;
}
.btn-sm { font-size: 12.5px; padding: 5px 10px; }
.btn-primary { background: var(--brand); border-color: var(--brand); }
.btn-primary:hover, .btn-primary:focus, .btn-primary:active { background: var(--brand-ink) !important; border-color: var(--brand-ink) !important; }
.btn-outline-primary { color: var(--brand-ink); border-color: var(--line-2); }
.btn-outline-primary:hover { background: var(--brand-soft); color: var(--brand-ink); border-color: var(--brand); }
.btn-outline-secondary { color: var(--ink-2); border-color: var(--line-2); }
.btn-outline-secondary:hover { background: var(--paper); color: var(--ink); border-color: var(--ink-3); }
.btn-outline-danger { color: var(--bad); border-color: var(--line-2); }
.btn-outline-danger:hover { background: var(--bad-soft); color: var(--bad); border-color: var(--bad); }
.btn-success { background: var(--ok); border-color: var(--ok); }
.btn-danger { background: var(--bad); border-color: var(--bad); }
.btn-warning { background: var(--amber); border-color: var(--amber); color: #2b1d00; }
.btn-dark { background: var(--ink); border-color: var(--ink); }
.btn-secondary { background: var(--ink-2); border-color: var(--ink-2); }
.btn-light { background: var(--paper); border-color: var(--line); color: var(--ink); }
.btn-link { font-weight: 600; }

.form-label { font-size: 12.5px; font-weight: 600; color: var(--ink-2); margin-bottom: 4px; }
.form-control, .form-select {
    font-size: 13.5px; border-radius: var(--r-ctl); border-color: var(--line-2);
    padding: 7px 10px; color: var(--ink); background-color: var(--panel);
}
.form-control-sm, .form-select-sm { font-size: 12.5px; padding: 4px 8px; }
.form-control:focus, .form-select:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.form-control::placeholder { color: #a3a9b6; }
.input-group-text { font-size: 13px; border-color: var(--line-2); background: var(--paper); color: var(--ink-2); }
.form-check-input:checked { background-color: var(--brand); border-color: var(--brand); }
.form-range::-webkit-slider-thumb { background: var(--brand); }
.form-control-color { padding: 2px; }

/* ---------- badges & alerts ---------- */

.badge { font-weight: 600; font-size: 11.5px; border-radius: 4px; padding: 3px 7px; letter-spacing: 0; }
.badge.bg-success { background: var(--ok-soft) !important; color: var(--ok) !important; }
.badge.bg-danger { background: var(--bad-soft) !important; color: var(--bad) !important; }
.badge.bg-warning { background: var(--amber-soft) !important; color: var(--amber-ink) !important; }
.badge.bg-primary { background: var(--brand-soft) !important; color: var(--brand-ink) !important; }
.badge.bg-info { background: #e3f3ff !important; color: #0b5e8f !important; }
.badge.bg-secondary { background: var(--paper) !important; color: var(--ink-2) !important; border: 1px solid var(--line); }
.badge.bg-light { background: var(--paper) !important; color: var(--ink-2) !important; }
.badge.bg-dark { background: var(--ink) !important; }

.alert { border: 0; border-left: 3px solid; border-radius: var(--r-ctl); padding: 10px 14px; font-size: 13.5px; }
.alert-success { background: var(--ok-soft); color: #14532d; border-color: var(--ok); }
.alert-danger { background: var(--bad-soft); color: #7f1d1d; border-color: var(--bad); }
.alert-warning { background: var(--warn-soft); color: #78350f; border-color: var(--warn); }
.alert-info { background: var(--brand-soft); color: var(--brand-ink); border-color: var(--brand); }
.alert a { font-weight: 600; }

.progress { height: 8px; border-radius: 999px; background: var(--paper); font-size: 0; }
.progress-bar { background: var(--brand); }
.progress-bar.bg-success { background: var(--ok) !important; }

.modal-content { border: 1px solid var(--line); border-radius: var(--r-panel); box-shadow: 0 24px 60px rgba(23,26,33,.18); }
.modal-header { border-bottom: 1px solid var(--line); padding: 14px 18px; }
.modal-title { font-weight: 700; font-size: 15px; }
.modal-body { padding: 18px; }
.modal-footer { border-top: 1px solid var(--line); }

.bg-light { background: var(--paper) !important; }
.border { border-color: var(--line) !important; }
.rounded { border-radius: var(--r-ctl) !important; }
.text-primary { color: var(--brand-ink) !important; }

.dropdown-menu { border: 1px solid var(--line); border-radius: var(--r-panel); box-shadow: 0 12px 32px rgba(23,26,33,.12); font-size: 13.5px; }

.pagination .page-link { color: var(--ink-2); border-color: var(--line); font-size: 13px; }
.pagination .page-item.active .page-link { background: var(--brand); border-color: var(--brand); }

/* ---------- notices (TempData) ---------- */
.notice { display: flex; gap: 10px; align-items: flex-start; margin-bottom: 18px; }

/* ---------- auth pages ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; background: var(--paper); padding: 24px; }
.auth-card {
    width: 100%; max-width: 380px; background: var(--panel);
    border: 1px solid var(--line); border-radius: 14px; padding: 30px 30px 26px;
}
.auth-card .brand { display: flex; align-items: center; gap: 10px; margin-bottom: 22px; font-weight: 800; font-size: 16px; color: var(--ink); }
.auth-card .brand .mark { width: 34px; height: 34px; border-radius: 9px; background: var(--brand); color: #fff; display: grid; place-items: center; font-size: 13px; font-weight: 800; }
.auth-card h1 { font-size: 20px; margin-bottom: 4px; }
.auth-card .lede { color: var(--ink-3); font-size: 13px; margin-bottom: 20px; }
.auth-card .form-control { padding: 9px 11px; font-size: 14px; }
.auth-card .btn { padding: 9px 14px; font-size: 14px; }
.auth-foot { margin-top: 18px; font-size: 12px; color: var(--ink-3); text-align: center; }

/* ---------- dashboard ---------- */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); border: 1px solid var(--line); border-radius: var(--r-panel); overflow: hidden; margin-bottom: 22px; }
.stats > a, .stats > div { padding: 16px 18px; border-right: 1px solid var(--line); color: inherit; display: block; }
.stats > a:hover { background: var(--paper); text-decoration: none; }
.stats > :last-child { border-right: 0; }
.stats .n { font-size: 26px; font-weight: 800; letter-spacing: -0.02em; line-height: 1.1; }
.stats .l { font-size: 12.5px; color: var(--ink-3); margin-top: 2px; }

.pagegrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; }
.pagecard { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--r-panel); color: inherit; }
.pagecard:hover { background: var(--paper); text-decoration: none; color: inherit; }
.pagecard .av { width: 32px; height: 32px; border-radius: 8px; background: var(--brand-soft); color: var(--brand-ink); display: grid; place-items: center; font-weight: 800; font-size: 12px; flex: none; }
.pagecard .nm { font-weight: 600; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pagecard .st { font-size: 11.5px; color: var(--ink-3); }
.pagecard .st.on { color: var(--ok); }

/* ---------- posts ---------- */
.compose { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 20px; align-items: start; }
.compose textarea { resize: vertical; }
.compose .idea { border: 1px dashed var(--line-2); border-radius: var(--r-panel); padding: 12px 14px; background: var(--paper); }
.compose .idea .form-label { color: var(--ink-2); }
.designs { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 8px; }
.designs a { display: block; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--paper); color: inherit; }
.designs a:hover { border-color: var(--brand); text-decoration: none; }
.designs img { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; }
.designs .cap { font-size: 11px; padding: 4px 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--ink-2); }
.studio-cta {
    display: flex; align-items: center; gap: 12px; padding: 12px 14px;
    border-radius: var(--r-panel); background: #1e1e1e; color: #e6e6e6;
}
.studio-cta:hover { color: #fff; text-decoration: none; background: #262626; }
.studio-cta .ic { width: 34px; height: 34px; border-radius: 8px; background: #0d99ff; display: grid; place-items: center; flex: none; }
.studio-cta .ic svg { width: 18px; height: 18px; stroke: #fff; fill: none; stroke-width: 2; }
.studio-cta b { display: block; font-size: 13.5px; }
.studio-cta span { font-size: 12px; color: #a0a0a0; }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
    .compose { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
    .shell { grid-template-columns: 1fr; }
    .rail { position: fixed; z-index: 40; left: 0; top: 0; width: var(--sidebar); transform: translateX(-100%); transition: transform .18s ease; box-shadow: 0 0 0 100vw rgba(23,26,33,0); }
    .rail.open { transform: none; box-shadow: 0 0 0 100vw rgba(23,26,33,.35); }
    .rail-toggle { display: inline-grid; place-items: center; width: 34px; height: 34px; border: 1px solid var(--line-2); background: var(--panel); border-radius: var(--r-ctl); cursor: pointer; }
    .rail-toggle svg { width: 18px; height: 18px; stroke: var(--ink); fill: none; stroke-width: 2; }
    .topbar { padding: 0 16px; gap: 10px; }
    .context-btn { min-width: 0; max-width: 56vw; }
    .context-pop { position: fixed; left: 12px; right: 12px; top: 58px; width: auto; max-width: none; }
    .chip.user b { display: none; }
    main.content { padding: 18px 16px 40px; }
    .stats { grid-template-columns: repeat(2, 1fr); }
    .stats > :nth-child(2) { border-right: 0; }
    .stats > :nth-child(-n+2) { border-bottom: 1px solid var(--line); }
}
