:root {
    --bg: #0f1115;
    --card: #171a21;
    --card2: #1d212b;
    --line: #262b36;
    --text: #e6e8ec;
    --muted: #8b909a;
    --fb: #1877f2;
    --ig: #e1306c;
    --green: #2ecc71;
    --amber: #f5a623;
    --red: #ff6b6b;
    --danger: #ff6b6b;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
}

/* ===== App shell (sidebar + content) ===== */
body.app { display: grid; grid-template-columns: 232px 1fr; }

.sidebar {
    background: #12141a;
    border-right: 1px solid var(--line);
    padding: 1.25rem 0.9rem;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    min-height: 100vh;
    position: sticky;
    top: 0;
}
.sidebar .brand {
    font-weight: 800;
    font-size: 1.1rem;
    padding: 0.4rem 0.7rem 1rem;
    letter-spacing: 0.01em;
}
.sidebar nav { display: flex; flex-direction: column; gap: 0.2rem; flex: 1; }
.nav-item {
    display: flex; align-items: center; gap: 0.65rem;
    padding: 0.6rem 0.75rem;
    border-radius: 9px;
    color: var(--muted);
    text-decoration: none;
    font-size: 0.92rem;
    font-weight: 600;
}
.nav-item .ico { width: 1.1rem; text-align: center; opacity: 0.9; }
.nav-item:hover { background: var(--card2); color: var(--text); }
.nav-item.active { background: rgba(24,119,242,0.15); color: #7aa7ff; }
.nav-item.logout { color: var(--muted); margin-top: auto; }
.nav-item.logout:hover { background: rgba(255,107,107,0.12); color: var(--red); }

.content { min-width: 0; }
.topbar {
    display: flex; justify-content: space-between; align-items: center;
    padding: 1.4rem 2rem;
    border-bottom: 1px solid var(--line);
    gap: 1rem;
}
.topbar h1 { font-size: 1.4rem; }
.topbar-right { display: flex; align-items: center; gap: 0.9rem; white-space: nowrap; }
.topbar-right .who {
    background: var(--card2); border: 1px solid var(--line);
    padding: 0.35rem 0.8rem; border-radius: 20px; font-size: 0.85rem; font-weight: 600;
}
.page-body { padding: 1.75rem 2rem; }
.mt { margin-top: 1.25rem; }

/* ===== Auth ===== */
body.auth-body { display: grid; place-items: center; padding: 2rem; }
.auth-card {
    background: var(--card);
    border: 1px solid var(--line);
    padding: 2.5rem;
    border-radius: 16px;
    width: 100%;
    max-width: 360px;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}
.auth-card h1 { font-size: 1.5rem; }
.auth-card label { display: flex; flex-direction: column; gap: 0.35rem; font-size: 0.85rem; color: var(--muted); margin-top: 1rem; }
.auth-card input {
    background: #0b0d11; border: 1px solid var(--line); color: var(--text);
    padding: 0.7rem 0.85rem; border-radius: 9px; font-size: 0.95rem;
}
.auth-card input:focus { outline: none; border-color: var(--fb); }
.auth-error {
    margin-top: 0.9rem; padding: 0.6rem 0.85rem;
    background: rgba(255,107,107,0.1); border: 1px solid var(--red);
    color: #ffb3b3; border-radius: 8px; font-size: 0.85rem;
}
.btn-primary {
    margin-top: 1.4rem; background: var(--fb); color: #fff; border: none;
    padding: 0.75rem; border-radius: 9px; font-size: 0.95rem; font-weight: 700; cursor: pointer;
}
.btn-primary:hover { filter: brightness(1.1); }

/* ===== Dashboard stat cards ===== */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; }
.stat-card {
    background: var(--card); border: 1px solid var(--line);
    border-radius: 14px; padding: 1.4rem 1.5rem;
    text-decoration: none; color: inherit; display: block;
    transition: border-color 0.15s;
}
.stat-card:hover:not(.static) { border-color: var(--fb); }
.stat-label { color: var(--muted); font-size: 0.85rem; font-weight: 600; }
.stat-num { font-size: 2.4rem; font-weight: 800; line-height: 1.1; margin: 0.3rem 0; }
.stat-sub { font-size: 0.8rem; }

/* ===== Profile ===== */
.profile-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 1rem; }
.panel { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 1.5rem; }
.panel h2 { font-size: 1rem; margin-bottom: 1rem; }
.kv { display: flex; justify-content: space-between; gap: 1rem; padding: 0.5rem 0; border-bottom: 1px solid var(--line); font-size: 0.9rem; }
.kv:last-child { border-bottom: none; }
.kv span { color: var(--muted); }
.fb-profile { display: flex; align-items: center; gap: 1rem; }
.avatar { width: 56px; height: 56px; border-radius: 50%; }
.ok { color: var(--green); }
.warn { color: var(--amber); }
.bad { color: var(--red); }

/* ===== Auto-reply ===== */
.ar-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap; }
.btn-run {
    background: var(--green); color: #06210f; border: none; cursor: pointer;
    padding: 0.6rem 1.1rem; border-radius: 9px; font-size: 0.9rem; font-weight: 700; white-space: nowrap;
}
.btn-run:hover { filter: brightness(1.08); }
.btn-run:disabled { opacity: 0.6; cursor: default; }
.run-status { display: none; margin-top: 1rem; padding: 0.8rem 1rem; border-radius: 9px; background: var(--card2); border: 1px solid var(--line); font-size: 0.88rem; }
.run-status.show { display: block; }
.ar-head-btns { display: flex; gap: 0.6rem; flex: none; }
.btn-save-all { background: var(--card2); border: 1px solid var(--line); color: var(--text); cursor: pointer; padding: 0.6rem 1.1rem; border-radius: 9px; font-size: 0.9rem; font-weight: 700; }
.btn-save-all:hover { border-color: var(--fb); }

.autorun-bar { display: flex; align-items: center; gap: 0.7rem; flex-wrap: wrap; margin-top: 1rem; padding: 0.7rem 1rem; background: var(--card); border: 1px solid var(--line); border-radius: 10px; }
.autorun-label { font-size: 0.88rem; display: flex; align-items: center; gap: 0.4rem; }
.autorun-bar select { background: #0b0d11; border: 1px solid var(--line); color: var(--text); border-radius: 7px; padding: 0.25rem 0.4rem; font-size: 0.82rem; }
.autorun-next { margin-left: auto; }
.switch.sm { width: 40px; height: 22px; }
.switch.sm .slider::before { height: 16px; width: 16px; }
.switch.sm input:checked + .slider::before { transform: translateX(18px); }

.ar-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 1rem; margin-top: 1.25rem; }
.ar-card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 1.1rem 1.2rem; display: flex; flex-direction: column; gap: 0.7rem; }
.ar-top { display: flex; justify-content: space-between; align-items: center; gap: 0.75rem; }
.fld { display: flex; flex-direction: column; gap: 0.35rem; font-size: 0.8rem; color: var(--muted); }
.fld input, .fld textarea {
    background: #0b0d11; border: 1px solid var(--line); color: var(--text);
    padding: 0.55rem 0.7rem; border-radius: 8px; font-size: 0.86rem; font-family: inherit; resize: vertical;
}
.fld input:focus, .fld textarea:focus { outline: none; border-color: var(--fb); }
.ar-replyall { display: flex; align-items: center; gap: 0.5rem; font-size: 0.82rem; cursor: pointer; }
.ar-replyall input { width: 15px; height: 15px; accent-color: var(--fb); }
.ar-default-fld { border-left: 2px solid var(--amber); padding-left: 0.6rem; }
.ar-actions { display: flex; align-items: center; gap: 0.8rem; }
.btn-save { background: var(--fb); color: #fff; border: none; cursor: pointer; padding: 0.45rem 1.1rem; border-radius: 8px; font-size: 0.83rem; font-weight: 700; }
.btn-save:hover { filter: brightness(1.1); }
.btn-save:disabled { opacity: 0.6; }

/* Toggle switch */
.switch { position: relative; display: inline-block; width: 46px; height: 26px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; inset: 0; background: #3a3f4b; border-radius: 26px; cursor: pointer; transition: 0.2s; }
.slider::before { content: ""; position: absolute; height: 20px; width: 20px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: 0.2s; }
.switch input:checked + .slider { background: var(--green); }
.switch input:checked + .slider::before { transform: translateX(20px); }

/* ===== Leads ===== */
.leads-bar { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: 0.5rem; }
.lead-stats { display: flex; gap: 0.5rem; }
.lead-actions-top { display: flex; align-items: center; gap: 0.9rem; flex-wrap: wrap; }
.tabs { display: flex; gap: 0.25rem; background: var(--card2); padding: 3px; border-radius: 9px; }
.tab { padding: 0.35rem 0.8rem; border-radius: 7px; text-decoration: none; color: var(--muted); font-size: 0.82rem; font-weight: 600; }
.tab.active { background: var(--fb); color: #fff; }
.btn-download { background: var(--card2); border: 1px solid var(--line); color: var(--text); text-decoration: none; padding: 0.45rem 0.9rem; border-radius: 8px; font-size: 0.83rem; font-weight: 600; }
.btn-download:hover { border-color: var(--green); }

.leads-table .phone strong { font-size: 0.95rem; letter-spacing: 0.02em; }
.leads-table tr.is-copied { opacity: 0.6; }
.lead-badge { font-size: 0.68rem; text-transform: uppercase; font-weight: 700; padding: 2px 7px; border-radius: 20px; letter-spacing: 0.03em; }
.b-new { background: rgba(46,204,113,0.15); color: var(--green); }
.b-copied { background: var(--line); color: var(--muted); }
.btn-copy { background: var(--card2); border: 1px solid var(--line); color: var(--text); cursor: pointer; padding: 0.35rem 0.8rem; border-radius: 7px; font-size: 0.8rem; font-weight: 600; }
.btn-copy:hover { border-color: var(--fb); }

/* Checkboxes + bulk bar */
.chk-col { width: 34px; text-align: center; }
.row-chk, #selAll { width: 16px; height: 16px; cursor: pointer; accent-color: var(--fb); }
.bulk-bar {
    display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
    background: var(--card2); border: 1px solid var(--line); border-radius: 10px;
    padding: 0.6rem 0.9rem; margin: 0.75rem 0;
}
.bulk-check { display: flex; align-items: center; gap: 0.5rem; font-size: 0.85rem; font-weight: 600; cursor: pointer; }
.sel-count { font-size: 0.82rem; }
.bulk-actions { display: flex; gap: 0.5rem; margin-left: auto; }
.btn-copy-sel, .btn-mark-sel {
    background: var(--fb); color: #fff; border: none; cursor: pointer;
    padding: 0.4rem 0.9rem; border-radius: 7px; font-size: 0.8rem; font-weight: 700;
}
.btn-mark-sel { background: var(--card); border: 1px solid var(--line); color: var(--text); }
.btn-copy-sel:hover { filter: brightness(1.1); }
.btn-mark-sel:hover { border-color: var(--fb); }

/* Pagination */
.pager { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin-top: 1.25rem; }
.pager-links { display: flex; gap: 0.3rem; flex-wrap: wrap; }
.pg {
    min-width: 34px; text-align: center; padding: 0.4rem 0.6rem;
    background: var(--card2); border: 1px solid var(--line); border-radius: 7px;
    color: var(--text); text-decoration: none; font-size: 0.83rem; font-weight: 600;
}
.pg:hover { border-color: var(--fb); }
.pg.active { background: var(--fb); color: #fff; border-color: var(--fb); }
.pg.disabled { opacity: 0.4; pointer-events: none; }
.pg-gap { color: var(--muted); padding: 0 0.2rem; align-self: center; }

/* ===== Ad account cards extra ===== */
.ad-top { text-decoration: none; color: inherit; }
a.ad-top:hover .name { color: #7aa7ff; }
.ad-balance { font-size: 0.8rem; margin-top: 0.4rem; }
.ad-card-actions { display: flex; gap: 0.5rem; margin-top: 0.7rem; }
.btn-mini { background: var(--card); border: 1px solid var(--line); color: var(--text); text-decoration: none; padding: 0.3rem 0.7rem; border-radius: 7px; font-size: 0.78rem; font-weight: 600; }
.btn-mini:hover { border-color: var(--fb); }
.btn-mini.fund:hover { border-color: var(--green); }

/* ===== Dayparting bar ===== */
.daypart-bar { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; padding: 0.9rem 1.1rem; border: 1px solid var(--line); border-radius: 12px; background: var(--card); margin-bottom: 1.25rem; }
.daypart-bar.on { border-color: var(--green); background: rgba(46,204,113,0.06); }
.daypart-bar.sub { margin-top: -0.75rem; }
.daypart-bar.sub.on { border-color: var(--amber); background: rgba(245,166,35,0.07); }
.dp-text { flex: 1; min-width: 220px; }
.dp-status { min-width: 120px; }

/* ===== Ad account detail ===== */
.bal-panel { margin-bottom: 1.5rem; }
.bal-main { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; }
.bal-num { font-size: 1.5rem; font-weight: 800; margin: 0.25rem 0; }
.btn-fund { background: var(--green); color: #06210f; text-decoration: none; padding: 0.6rem 1.1rem; border-radius: 9px; font-weight: 700; font-size: 0.9rem; white-space: nowrap; }
.btn-fund:hover { filter: brightness(1.08); }

.row-best { background: rgba(46,204,113,0.08); }
.tag-best { background: rgba(46,204,113,0.2); color: var(--green); font-size: 0.62rem; font-weight: 700; text-transform: uppercase; padding: 1px 6px; border-radius: 10px; margin-left: 0.3rem; }
.minibar { display: inline-block; height: 8px; background: var(--fb); border-radius: 4px; min-width: 2px; vertical-align: middle; }

.hour-bars { display: flex; align-items: flex-end; gap: 3px; height: 120px; margin-top: 1rem; padding: 0.5rem; background: var(--card); border: 1px solid var(--line); border-radius: 10px; overflow-x: auto; }
.hbar { flex: 1; min-width: 18px; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; }
.hbar-fill { width: 60%; background: #3a4150; border-radius: 3px 3px 0 0; min-height: 3px; }
.hbar.best .hbar-fill { background: var(--green); }
.hbar-lbl { font-size: 0.6rem; color: var(--muted); margin-top: 3px; }

.ad-status { font-size: 0.66rem; font-weight: 700; text-transform: uppercase; padding: 2px 7px; border-radius: 10px; letter-spacing: 0.02em; }
.ad-status.s-active { background: rgba(46,204,113,0.15); color: var(--green); }
.ad-status.s-paused { background: rgba(245,166,35,0.15); color: var(--amber); }
.ad-status.s-issue { background: rgba(255,107,107,0.15); color: var(--red); }

.tag-type { font-size: 0.72rem; font-weight: 600; padding: 2px 8px; border-radius: 10px; background: var(--card2); color: var(--muted); white-space: nowrap; }
.type-head { font-size: 1rem; margin: 1.6rem 0 0.5rem; display: flex; align-items: center; gap: 0.5rem; }
.type-head .count { font-size: 0.72rem; }

/* "Ads Manager ↗" link beside an ad name — quiet until hovered. */
.ads-table td a { color: var(--text); text-decoration: none; }
.ads-table td a:hover { text-decoration: underline; }
.open-ext { display: inline-block; margin-left: 8px; font-size: 0.72rem; white-space: nowrap;
    color: var(--muted) !important; opacity: 0.75; }
.open-ext:hover { opacity: 1; color: var(--fb) !important; }

/* Inline "change" affordance on the WhatsApp destination cell. */
.btn-wa-edit { margin-left: 6px; padding: 1px 7px; font-size: 0.7rem; cursor: pointer;
    background: transparent; color: var(--muted); border: 1px solid var(--line);
    border-radius: 9px; opacity: 0.7; }
.btn-wa-edit:hover { opacity: 1; color: var(--text); border-color: var(--muted); }
.btn-wa-edit:disabled { cursor: default; opacity: 0.4; }

/* Quiet-ad filter: hide ads with almost no results AND almost no spend. */
.lowact-toggle { display: inline-flex; align-items: center; gap: 7px; margin: 0 0 0.6rem;
    padding: 5px 11px; border: 1px solid var(--line); border-radius: 999px;
    background: var(--card); font-size: 0.82rem; cursor: pointer; user-select: none; }
.lowact-toggle:hover { border-color: var(--muted); }
.lowact-toggle input { cursor: pointer; }
body.hide-lowact .ads-table tr[data-low="1"],
body.hide-lowact .type-block[data-all-low="1"] { display: none; }

/* Download dropdown (leads) */
.dl-menu { position: relative; display: inline-block; }
.dl-menu > summary { list-style: none; cursor: pointer; user-select: none; }
.dl-menu > summary::-webkit-details-marker { display: none; }
.dl-menu[open] > summary { outline: none; }
.dl-menu-items { position: absolute; right: 0; top: calc(100% + 6px); z-index: 30; min-width: 190px;
    background: var(--card2); border: 1px solid var(--line); border-radius: 9px; padding: 6px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.35); display: flex; flex-direction: column; gap: 2px; }
.dl-menu-items a { display: flex; justify-content: space-between; gap: 12px; padding: 8px 10px;
    border-radius: 6px; font-size: 0.85rem; color: var(--text); text-decoration: none; }
.dl-menu-items a:hover { background: var(--card); }

/* Token / connection warning banner */
.token-banner { padding: 0.7rem 1rem; border-radius: 9px; margin-bottom: 1rem; font-size: 0.9rem; border: 1px solid; }
.token-banner a { font-weight: 700; text-decoration: underline; white-space: nowrap; }
.token-banner.warn { background: rgba(245,166,35,0.12); border-color: rgba(245,166,35,0.4); color: var(--amber); }
.token-banner.err  { background: rgba(255,107,107,0.12); border-color: rgba(255,107,107,0.4); color: var(--red); }
.ad-status.s-deleted, .ad-status.s-archived { background: var(--line); color: var(--muted); }
.btn-adtoggle { background: var(--card2); border: 1px solid var(--line); color: var(--text); cursor: pointer; padding: 0.35rem 0.85rem; border-radius: 7px; font-size: 0.8rem; font-weight: 600; }
.btn-adtoggle:hover { border-color: var(--amber); }

/* ===== Notices ===== */
.notice {
    background: rgba(245,166,35,0.1); border: 1px solid var(--amber);
    color: #f0c987; padding: 0.7rem 1rem; border-radius: 9px;
    font-size: 0.85rem; margin: 1rem 0;
}

/* ===== Data table (Posts) ===== */
.data-table {
    width: 100%; border-collapse: collapse; margin-top: 1rem;
    font-size: 0.88rem;
}
.data-table thead th {
    text-align: left; color: var(--muted); font-weight: 600;
    padding: 0.6rem 0.75rem; border-bottom: 1px solid var(--line);
    font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.03em;
}
.data-table td { padding: 0.7rem 0.75rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.data-table tbody tr:hover { background: var(--card2); }
.data-table .num { text-align: right; white-space: nowrap; }
.data-table .rank { color: var(--muted); }
.data-table .nowrap { white-space: nowrap; }
.post-cell { max-width: 420px; }
.post-cell a { color: #7aa7ff; text-decoration: none; }
.post-cell a:hover { text-decoration: underline; }

/* ===== Comment list ===== */
.comment-list { display: grid; gap: 0.9rem; margin-top: 1rem; }
.comment-post { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 1rem 1.15rem; }
.cp-head { display: flex; align-items: flex-start; gap: 0.8rem; }
.rank-badge {
    flex: none; width: 26px; height: 26px; border-radius: 7px;
    background: var(--card2); color: var(--muted);
    display: grid; place-items: center; font-size: 0.8rem; font-weight: 700;
}
.cp-meta { flex: 1; min-width: 0; }
.cp-title { font-weight: 600; color: var(--text); text-decoration: none; display: block; }
a.cp-title:hover { color: #7aa7ff; }
.cp-count { flex: none; font-size: 0.85rem; color: var(--muted); white-space: nowrap; }
.cp-count strong { color: var(--ig); font-size: 1rem; }
.small { font-size: 0.82rem; }

/* Chat-style comments */
.chat { margin-top: 0.85rem; border-top: 1px solid var(--line); padding-top: 0.85rem; display: flex; flex-direction: column; gap: 0.6rem; }
.chat-thread { display: flex; flex-direction: column; gap: 0.35rem; }
.bubble {
    max-width: 78%; padding: 0.55rem 0.8rem; border-radius: 14px; font-size: 0.86rem;
    background: var(--card2); border: 1px solid var(--line);
}
.bubble.incoming { align-self: flex-start; border-bottom-left-radius: 4px; }
.bubble.incoming.nested { align-self: flex-start; margin-left: 1.5rem; background: #14171e; }
.bubble.outgoing {
    align-self: flex-end; border-bottom-right-radius: 4px;
    background: rgba(24,119,242,0.18); border-color: rgba(24,119,242,0.4);
}
.b-from { font-weight: 700; font-size: 0.78rem; margin-bottom: 0.15rem; }
.bubble.outgoing .b-from { color: #7aa7ff; }
.b-msg { line-height: 1.35; word-break: break-word; }
.b-meta { color: var(--muted); font-size: 0.72rem; margin-top: 0.3rem; display: flex; align-items: center; gap: 0.5rem; }

.c-reply-btn {
    background: none; border: none; color: #7aa7ff; cursor: pointer;
    font-size: 0.75rem; font-weight: 700; padding: 0; white-space: nowrap;
}
.c-reply-btn:hover { text-decoration: underline; }

.cp-actions { margin-top: 0.75rem; display: flex; align-items: center; gap: 0.9rem; flex-wrap: wrap; }
.btn-showall {
    background: var(--card2); border: 1px solid var(--line); color: var(--text);
    padding: 0.45rem 0.9rem; border-radius: 8px; font-size: 0.82rem; font-weight: 600; cursor: pointer;
}
.btn-showall:hover { border-color: var(--fb); }
.btn-showall:disabled { opacity: 0.6; cursor: default; }

.reply-box { margin-top: 0.5rem; margin-left: 0.5rem; display: grid; gap: 0.5rem; }
.reply-text {
    width: 100%; background: #0b0d11; border: 1px solid var(--line); color: var(--text);
    border-radius: 8px; padding: 0.55rem 0.7rem; font-size: 0.86rem; resize: vertical; font-family: inherit;
}
.reply-text:focus { outline: none; border-color: var(--fb); }
.reply-actions { display: flex; align-items: center; gap: 0.8rem; }
.btn-send {
    background: var(--fb); color: #fff; border: none; cursor: pointer;
    padding: 0.45rem 1rem; border-radius: 8px; font-size: 0.82rem; font-weight: 700;
}
.btn-send:hover { filter: brightness(1.1); }
.btn-send:disabled { opacity: 0.6; cursor: default; }
.reply-done { color: var(--green); font-size: 0.84rem; margin-top: 0.4rem; }

@media (max-width: 720px) {
    body.app { grid-template-columns: 1fr; }
    .sidebar { position: static; min-height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; }
    .sidebar nav { flex-direction: row; flex-wrap: wrap; }
    .nav-item.logout { margin-top: 0; }
    .topbar, .page-body { padding-left: 1rem; padding-right: 1rem; }
}

.container {
    background: var(--card);
    padding: 2.5rem;
    border-radius: 16px;
    max-width: 480px;
    width: 100%;
}
.container.wide { max-width: 860px; }

.head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap; }
.refresh { display: flex; align-items: center; gap: 0.6rem; white-space: nowrap; }
.btn-refresh {
    background: var(--card2);
    border: 1px solid var(--line);
    color: var(--text);
    text-decoration: none;
    padding: 0.4rem 0.8rem;
    border-radius: 8px;
    font-size: 0.82rem;
    font-weight: 600;
}
.btn-refresh:hover { border-color: var(--fb); }

h1 { font-size: 1.6rem; margin-bottom: 0.35rem; }
h2 {
    font-size: 1.05rem;
    margin: 1.75rem 0 0.9rem;
    display: flex; align-items: center; gap: 0.5rem;
}
h2 .count {
    font-size: 0.75rem;
    background: var(--card2);
    color: var(--muted);
    padding: 2px 9px;
    border-radius: 20px;
}
.muted { color: var(--muted); font-size: 0.85rem; }
code { background: #0b0d11; padding: 1px 6px; border-radius: 4px; font-size: 0.8rem; }
a { color: inherit; }

.alert {
    margin-top: 1.5rem;
    padding: 1rem 1.25rem;
    border: 1px solid var(--danger);
    border-radius: 10px;
    background: rgba(255, 107, 107, 0.08);
}
.alert p { margin-top: 0.4rem; }

.btn-fb {
    display: inline-block;
    margin-top: 0.9rem;
    background: var(--fb);
    color: #fff;
    text-decoration: none;
    padding: 0.6rem 1.1rem;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.9rem;
}
.btn-fb:hover { filter: brightness(1.1); }

/* --- Ad accounts --- */
.ad-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
    gap: 0.7rem;
}
.ad-card {
    background: var(--card2);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 0.85rem 0.95rem;
}
.ad-top { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; margin-bottom: 0.25rem; }
.ad-top .name { font-weight: 600; font-size: 0.9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.platforms { display: flex; gap: 4px; margin-top: 0.5rem; }
.pf {
    font-size: 0.62rem;
    font-weight: 700;
    letter-spacing: 0.03em;
    padding: 2px 6px;
    border-radius: 5px;
    color: #fff;
}
.pf-fb  { background: var(--fb); }
.pf-ig  { background: var(--ig); }
.pf-an  { background: #5b6270; }
.pf-msg { background: #a333c8; }
.pf-other { background: #5b6270; }

.ad-spend { margin-top: 0.5rem; font-size: 0.95rem; }
.ad-spend strong { font-size: 1.05rem; }

.status {
    flex: none;
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    padding: 2px 7px;
    border-radius: 20px;
    font-weight: 700;
}
.status.s-active   { background: rgba(46,204,113,0.15); color: var(--green); }
.status.s-disabled,
.status.s-closed   { background: rgba(255,107,107,0.15); color: var(--red); }
.status.s-unsettled,
.status.s-grace_period,
.status.s-pending_review { background: rgba(245,166,35,0.15); color: var(--amber); }
.status.s-unknown  { background: var(--line); color: var(--muted); }

/* --- Pages --- */
.page-list { list-style: none; display: grid; gap: 0.75rem; }
.page {
    display: grid;
    grid-template-columns: 1.2fr 1fr;
    gap: 0.75rem 1rem;
    padding: 1rem;
    border: 1px solid var(--line);
    border-radius: 10px;
}
.page-fb, .page-ig { display: flex; align-items: center; gap: 0.65rem; }
.page-posts {
    grid-column: 1 / -1;
    border-top: 1px solid var(--line);
    padding-top: 0.6rem;
    display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 0.75rem;
    font-size: 0.85rem;
}
.name { font-weight: 600; }

.pill {
    background: var(--card2);
    border: 1px solid var(--line);
    padding: 2px 10px;
    border-radius: 20px;
    font-size: 0.8rem;
}
.latest {
    color: var(--muted);
    text-decoration: none;
    border-bottom: 1px dashed var(--line);
}
.latest:hover { color: var(--text); }

.badge {
    flex: none;
    width: 34px; height: 34px;
    border-radius: 8px;
    display: grid; place-items: center;
    font-size: 0.7rem; font-weight: 700; color: #fff;
}
.badge.fb { background: var(--fb); }
.badge.ig { background: var(--ig); }

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