:root {
    --bg: #101318;
    --surface: #171b22;
    --surface-2: #1f252e;
    --panel: #151920;
    --border: #2b3440;
    --text: #eef2f6;
    --muted: #9aa7b5;
    --faint: #687584;
    --accent: #3fb7a3;
    --accent-2: #78a6ff;
    --danger: #ef6f73;
    --warning: #f2bc57;
    --success: #4cc38a;
    --radius: 8px;
    --sidebar: 248px;
    --font: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 14px;
}

button, input, select, textarea { font: inherit; }
a { color: inherit; }

.login-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
    background: radial-gradient(circle at top left, rgba(63, 183, 163, .13), transparent 30%), var(--bg);
}

.login-card {
    width: min(420px, 100%);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 28px;
    box-shadow: 0 18px 60px rgba(0,0,0,.34);
}

.login-card h1 { margin: 0 0 4px; font-size: 26px; letter-spacing: 0; }
.login-card p { margin: 0 0 22px; color: var(--muted); }

.layout { display: flex; min-height: 100vh; }
.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: var(--sidebar);
    background: #0d1015;
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 20;
}

.brand {
    padding: 20px;
    border-bottom: 1px solid var(--border);
}
.brand strong { display: block; font-size: 18px; }
.brand span { color: var(--muted); font-size: 12px; }

.nav { padding: 12px; display: grid; gap: 4px; }
.nav button {
    border: 0;
    background: transparent;
    color: var(--muted);
    text-align: left;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 11px 12px;
    border-radius: var(--radius);
    cursor: pointer;
}
.nav button:hover { background: var(--surface); color: var(--text); }
.nav button.active { background: rgba(63,183,163,.12); color: var(--accent); }
.nav .material-symbols-rounded { font-size: 20px; }

.sidebar-footer {
    margin-top: auto;
    padding: 16px;
    border-top: 1px solid var(--border);
    color: var(--muted);
    display: grid;
    gap: 10px;
}

.main {
    margin-left: var(--sidebar);
    width: calc(100% - var(--sidebar));
    padding: 28px;
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
    margin-bottom: 22px;
}
.page-header h1 { margin: 0; font-size: 25px; letter-spacing: 0; }
.page-header p { margin: 4px 0 0; color: var(--muted); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

.grid { display: grid; gap: 14px; }
.stats-grid { grid-template-columns: repeat(5, minmax(150px, 1fr)); }
.two-col { grid-template-columns: minmax(0, 1fr) 380px; align-items: start; }

.card, .stat-card, .panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.card, .panel { padding: 16px; }
.stat-card { padding: 16px; display: grid; gap: 8px; min-height: 104px; }
.stat-card span { color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; }
.stat-card strong { font-size: 30px; line-height: 1; }
.stat-card.ready { border-color: rgba(239,111,115,.5); }
.stat-card.near { border-color: rgba(242,188,87,.45); }

.sync-run-list { display: grid; gap: 10px; }
.sync-run-item {
    min-height: 58px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 12px;
    background: #12161c;
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.sync-run-count {
    min-width: 74px;
    text-align: right;
}
.sync-run-count strong {
    display: block;
    font-size: 20px;
    line-height: 1;
}
.sync-run-count span {
    display: block;
    color: var(--muted);
    font-size: 11px;
    margin-top: 3px;
}

.filters {
    display: grid;
    grid-template-columns: 2fr repeat(5, minmax(120px, 1fr));
    gap: 8px;
    margin-bottom: 12px;
}

.field { display: grid; gap: 6px; margin-bottom: 12px; }
.field label { color: var(--muted); font-size: 12px; font-weight: 700; }
.input, input, select, textarea {
    width: 100%;
    background: #0f1319;
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 11px;
    outline: none;
}
textarea { min-height: 96px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: rgba(63,183,163,.75); }

.check-row { display: flex; gap: 14px; flex-wrap: wrap; }
.check-row label {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    color: var(--text);
    background: var(--surface-2);
    border: 1px solid var(--border);
    padding: 8px 10px;
    border-radius: var(--radius);
}
.check-row input { width: auto; }

.btn, button.btn {
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
    border-radius: var(--radius);
    min-height: 38px;
    padding: 8px 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    cursor: pointer;
}
.btn:hover { border-color: #405060; }
.btn.primary { background: var(--accent); color: #08110f; border-color: var(--accent); font-weight: 800; }
.btn.danger { background: rgba(239,111,115,.14); color: #ffb1b4; border-color: rgba(239,111,115,.35); }
.btn.ghost { background: transparent; }
.btn.sm { min-height: 31px; padding: 5px 9px; font-size: 12px; }
.plugin-download-btn {
    text-decoration: none;
    border-color: rgba(120,166,255,.45);
    background: linear-gradient(180deg, rgba(120,166,255,.16), rgba(120,166,255,.07));
    color: #d9e6ff;
    font-weight: 800;
}
.plugin-download-btn:hover { border-color: rgba(120,166,255,.8); color: #fff; }
.plugin-install-panel {
    display: grid;
    grid-template-columns: minmax(220px, .65fr) minmax(0, 1.35fr);
    gap: 18px;
    align-items: center;
    margin: -4px 0 14px;
    border-color: rgba(120,166,255,.28);
    background:
        linear-gradient(135deg, rgba(120,166,255,.12), transparent 38%),
        var(--surface);
}
.plugin-install-copy h2 { margin: 0 0 6px; font-size: 18px; }
.plugin-install-copy p { margin: 0; color: var(--muted); line-height: 1.45; }
.plugin-install-fields { display: grid; gap: 10px; }
.plugin-install-fields label {
    display: grid;
    grid-template-columns: 132px minmax(0, 1fr) auto;
    align-items: center;
    gap: 10px;
    margin: 0;
}
.plugin-install-fields span {
    color: #b8c7d9;
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
}
.plugin-install-fields code {
    min-height: 38px;
    display: flex;
    align-items: center;
    overflow: auto;
    white-space: nowrap;
    padding: 8px 10px;
    border: 1px solid rgba(120,166,255,.28);
    border-radius: var(--radius);
    background: #0b1020;
    color: #7ee787;
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
    font-size: 13px;
}
.plugin-install-fields .token-code { color: #f5d97a; }
.icon-btn {
    width: 34px;
    height: 34px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
    cursor: pointer;
}

.table-wrap { overflow: auto; border: 1px solid var(--border); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; min-width: 880px; }
th, td {
    text-align: left;
    padding: 10px 11px;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}
th {
    color: var(--muted);
    background: #12161c;
    font-size: 12px;
    position: sticky;
    top: 0;
}
tr:hover td { background: rgba(255,255,255,.015); }
.url { font-weight: 700; }
.sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.nowrap { white-space: nowrap; }
.ads-filters { grid-template-columns: minmax(220px, 1fr) 220px; }
.ads-overview-toolbar { margin-bottom: 14px; max-width: 680px; }
.ad-site-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 12px;
    margin-bottom: 14px;
}
.ad-site-card {
    min-height: 138px;
    text-align: left;
    display: grid;
    align-content: start;
    gap: 7px;
    padding: 16px;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
}
.ad-site-card:hover {
    border-color: rgba(63,183,163,.7);
    background: #1a2028;
}
.ad-site-card-top {
    display: flex;
    justify-content: flex-start;
    align-items: center;
}
.ad-site-name {
    font-size: 16px;
    font-weight: 800;
    overflow-wrap: anywhere;
}
.ad-site-sub, .ad-site-zones, .ad-site-plugin-note {
    color: var(--muted);
    font-size: 12px;
    overflow-wrap: anywhere;
}
.plugin-badge {
    width: fit-content;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 9px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
}
.plugin-badge span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: currentColor;
}
.plugin-badge.online { color: #87e7b2; background: rgba(76,195,138,.12); border-color: rgba(76,195,138,.32); }
.plugin-badge.stale { color: #ffd17f; background: rgba(242,188,87,.12); border-color: rgba(242,188,87,.32); }
.plugin-badge.offline { color: #ffadaf; background: rgba(239,111,115,.13); border-color: rgba(239,111,115,.34); }
.plugin-badge.not_installed { color: #9aa7b5; background: rgba(154,167,181,.08); }
.ad-site-meta {
    width: fit-content;
    color: var(--accent);
    background: rgba(63,183,163,.12);
    border: 1px solid rgba(63,183,163,.28);
    border-radius: 999px;
    padding: 4px 8px;
    font-size: 12px;
    font-weight: 800;
}
.ad-detail-title {
    margin-top: 10px !important;
    overflow-wrap: anywhere;
}
.ad-layout-workbench {
    display: grid;
    grid-template-columns: 1fr;
    gap: 14px;
    align-items: start;
}
.ad-connection-panel {
    display: grid;
    grid-template-columns: minmax(240px, 1fr) minmax(360px, 1.2fr);
    gap: 14px;
    padding: 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.ad-connection-heading {
    display: flex;
    align-items: center;
    gap: 9px;
    margin-bottom: 5px;
}
.ad-connection-heading .material-symbols-rounded { color: var(--accent); }
.ad-connection-panel p {
    margin: 0;
    color: var(--muted);
}
.connection-metrics {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
}
.connection-metrics div {
    min-height: 58px;
    display: grid;
    align-content: center;
    gap: 4px;
    padding: 10px;
    background: #11161d;
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.connection-metrics span, .connection-zone-counts {
    color: var(--muted);
    font-size: 12px;
}
.connection-metrics strong {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.connection-zone-counts {
    grid-column: 1 / -1;
}
.connection-error {
    grid-column: 1 / -1;
    padding: 10px 12px;
    border: 1px solid rgba(239,111,115,.34);
    border-radius: var(--radius);
    background: rgba(239,111,115,.12);
    color: #ffadaf;
}
.ad-preview-note {
    padding: 12px 14px;
    background: rgba(63,183,163,.1);
    border: 1px solid rgba(63,183,163,.32);
    border-radius: var(--radius);
    color: #bce9df;
    line-height: 1.45;
}
.ad-post-preview {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.ad-post-preview {
    position: relative;
    overflow: hidden;
}
.mock-page-stage {
    position: relative;
    min-height: 760px;
    padding: 14px 142px 24px;
}
.mock-post-column {
    width: min(900px, 100%);
    margin: 0 auto;
}
.mock-floating-rails {
    pointer-events: none;
    position: absolute;
    inset: 0;
    top: 50vh;
    z-index: 8;
    height: 0;
}
.mock-floating-ad {
    position: absolute;
    top: 280px;
    display: grid;
    place-items: center;
    overflow: hidden;
    background: #0f1319;
    border: 1px solid rgba(63,183,163,.36);
    border-radius: var(--radius);
    color: var(--muted);
    font-size: 12px;
    text-align: center;
}
.mock-floating-side {
    width: 114px;
    min-height: 170px;
}
.mock-floating-ad img {
    width: 100%;
    height: auto;
    display: block;
}
.mock-floating-ad b {
    width: 100%;
    display: block;
    padding: 4px 2px;
    background: #555;
    color: #fff;
    font-size: 18px;
    line-height: 1;
}
.mock-floating-left { left: 16px; }
.mock-floating-right { right: 16px; }
.mock-floating-bottom-preview {
    width: min(760px, 100%);
    margin: 14px auto;
    padding: 14px 18px;
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    background: rgba(11,15,20,.46);
}
.mock-floating-bottom-frame {
    position: relative;
    width: min(504px, 92%);
    min-height: 44px;
    margin: 0 auto;
    display: grid;
    place-items: center;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.2;
    text-align: center;
}
.mock-floating-bottom-frame.is-empty {
    border: 1px dashed rgba(120,166,255,.28);
    border-radius: var(--radius);
    background: #0f1319;
}
.mock-floating-bottom-frame img {
    width: 100%;
    height: auto;
    display: block;
}
.mock-floating-bottom-frame b {
    position: absolute;
    top: -12px;
    right: -12px;
    width: 24px;
    height: 24px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: #e53935;
    color: #fff;
    font-size: 15px;
    line-height: 1;
    box-shadow: 0 2px 6px rgba(0,0,0,.4);
}
.mock-browser-bar {
    min-height: 44px;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 14px;
    background: #11161d;
    border-bottom: 1px solid var(--border);
}
.mock-browser-bar span {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--faint);
}
.mock-browser-bar strong { margin-left: 8px; color: var(--muted); font-size: 12px; }
.mock-post-title, .mock-video, .mock-content {
    margin: 14px auto;
    width: min(760px, 100%);
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    color: var(--muted);
    text-align: center;
}
.mock-post-title { padding: 22px; font-size: 22px; font-weight: 800; color: var(--text); }
.mock-video { min-height: 220px; display: grid; place-items: center; background: #0b0f14; }
.mock-content { min-height: 120px; padding: 28px; }
.ad-zone-board {
    width: 100%;
    margin: 14px auto;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: #12161c;
}
.ad-zone-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
}
.ad-zone-head h2 { margin: 0; font-size: 15px; }
.ad-zone-head span { display: block; margin-top: 2px; color: var(--muted); font-size: 12px; }
.ad-dropzone {
    min-height: 82px;
    display: grid;
    gap: 10px;
    padding: 12px;
    transition: background .16s ease, border-color .16s ease;
}
.ad-dropzone.is-invalid {
    background: rgba(239,111,115,.08);
    outline: 1px solid rgba(239,111,115,.42);
    outline-offset: -1px;
}
.ad-empty-slot {
    min-height: 58px;
    display: grid;
    place-items: center;
    color: var(--muted);
    border: 1px dashed var(--border);
    border-radius: var(--radius);
}
.ad-drag-card {
    display: grid;
    grid-template-columns: 32px 178px minmax(0, 1fr) auto;
    gap: 12px;
    align-items: center;
    padding: 10px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: grab;
    box-shadow: 0 8px 20px rgba(0,0,0,.12);
}
.ad-drag-card:active { cursor: grabbing; }
.ad-drag-card.dragging {
    opacity: .55;
    border-color: var(--accent);
}
.ad-drag-card.is-disabled { opacity: .72; }
.drag-handle {
    color: var(--muted);
    display: grid;
    place-items: center;
}
.ad-drag-card img {
    width: 178px;
    max-height: 76px;
    object-fit: contain;
    background: #0f1319;
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.ad-drag-meta {
    display: grid;
    gap: 3px;
    min-width: 0;
}
.ad-drag-meta strong, .ad-drag-meta span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.ad-drag-meta span {
    color: var(--muted);
    font-size: 12px;
}
.ad-drag-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;
}
.ad-thumb {
    width: 160px;
    max-height: 76px;
    object-fit: contain;
    display: block;
    background: #0f1319;
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.ad-preview {
    width: min(420px, 100%);
    max-height: 180px;
    object-fit: contain;
    background: #0f1319;
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.embed-panel { margin-top: 14px; }
.embed-panel h2 { margin: 0 0 10px; font-size: 18px; }
.embed-panel pre {
    overflow: auto;
    margin: 0;
    padding: 12px;
    background: #0f1319;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
}

.badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 8px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 800;
    background: var(--surface-2);
    color: var(--muted);
}
.badge.blocked { color: #ffcf8a; background: rgba(242,188,87,.12); }
.badge.redirect_ready { color: #ffadaf; background: rgba(239,111,115,.15); }
.badge.redirected, .badge.resolved, .badge.approved { color: #99e8bd; background: rgba(76,195,138,.12); }
.badge.pending { color: #9dc0ff; background: rgba(120,166,255,.12); }
.badge.rejected { color: #f3a0a3; background: rgba(239,111,115,.12); }

.isp-list { display: flex; gap: 5px; flex-wrap: wrap; }
.isp { border: 1px solid var(--border); border-radius: 5px; padding: 2px 6px; color: var(--muted); font-size: 12px; }
.isp.on { color: var(--text); border-color: rgba(63,183,163,.55); background: rgba(63,183,163,.1); }

.empty { padding: 26px; text-align: center; color: var(--muted); }
.toast {
    background: var(--surface);
    border: 1px solid var(--border);
    border-left: 4px solid var(--accent);
    color: var(--text);
    border-radius: var(--radius);
    padding: 12px 14px;
    box-shadow: 0 12px 30px rgba(0,0,0,.32);
}
#toast-container {
    position: fixed;
    right: 18px;
    bottom: 18px;
    display: grid;
    gap: 8px;
    z-index: 80;
}

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.58);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 18px;
    z-index: 70;
}
.modal {
    width: min(720px, 100%);
    max-height: 90vh;
    overflow: auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.modal-header, .modal-footer {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}
.modal-footer { border-bottom: 0; border-top: 1px solid var(--border); justify-content: flex-end; }
.modal-header h3 { margin: 0; }
.modal-body { padding: 16px; }

@media (max-width: 980px) {
    .sidebar { position: static; width: 100%; height: auto; }
    .layout { display: block; }
    .main { margin-left: 0; width: 100%; padding: 18px; }
    .nav { grid-template-columns: repeat(2, 1fr); }
    .stats-grid, .two-col, .filters, .ad-layout-workbench, .ad-connection-panel, .connection-metrics, .plugin-install-panel, .plugin-install-fields label { grid-template-columns: 1fr; }
    .page-header { display: grid; }
    .mock-page-stage { padding: 14px; }
    .mock-floating-rails { display: none; }
    .ad-drag-card { grid-template-columns: 28px 96px minmax(0, 1fr); }
    .ad-drag-card img { width: 96px; }
    .ad-drag-actions { grid-column: 2 / -1; justify-content: flex-start; }
}
