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

:root {
    --bg:      #0f1117;
    --surface: #1a1d27;
    --border:  #2a2d3a;
    --accent:  #4f7cff;
    --green:   #22c55e;
    --red:     #ef4444;
    --yellow:  #f59e0b;
    --text:    #e2e8f0;
    --muted:   #64748b;
    --radius:  10px;
    --shadow:  0 4px 24px rgba(0,0,0,.4);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Inter', sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    font-size: 14px;
    line-height: 1.5;
}

/* ── Layout ── */
.navbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    height: 56px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}
.navbar .logo { font-weight: 700; font-size: 16px; letter-spacing: .5px; }
.navbar .logo span { color: var(--accent); }
.nav-right { display: flex; align-items: center; gap: 16px; }
.nav-user { color: var(--muted); font-size: 13px; }

.container { max-width: 1280px; margin: 0 auto; padding: 32px 24px; }

.page { display: none; }
.page.active { display: block; }

/* ── Cards ── */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    margin-bottom: 16px;
}
.card-title {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

/* ── Forms ── */
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; text-transform: uppercase; letter-spacing: .5px; }
.form-group input {
    width: 100%;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 9px 12px;
    color: var(--text);
    font-size: 14px;
    outline: none;
    transition: border-color .15s;
}
.form-group input:focus { border-color: var(--accent); }

/* ── Buttons ── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: 6px;
    border: none;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: opacity .15s, transform .1s;
}
.btn:hover { opacity: .85; }
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-ghost   { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.btn-danger  { background: var(--red); color: #fff; }
.btn-sm { padding: 5px 10px; font-size: 12px; }

/* ── Pixel cards ── */
.pixels-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
    gap: 14px;
}

.pixel-card {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    position: relative;
}
.pixel-card .pname { font-weight: 600; font-size: 14px; margin-bottom: 4px; }
.pixel-card .pid { font-family: monospace; color: var(--muted); font-size: 12px; margin-bottom: 10px; }
.pixel-card .token-row {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--muted);
    margin-bottom: 10px;
}
.pixel-card .token-val {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-family: monospace;
    color: var(--text);
    opacity: .5;
}
.pixel-card .actions { display: flex; gap: 6px; margin-top: 10px; }
.pixel-card-err  { border-color: rgba(239,68,68,.5); background: rgba(239,68,68,.04); }
.pixel-card-warn { border-color: rgba(245,158,11,.4); background: rgba(245,158,11,.03); }

/* ── Badge ── */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    position: absolute;
    top: 14px;
    right: 14px;
}
.badge.valid   { background: rgba(34,197,94,.15);  color: var(--green); }
.badge.invalid { background: rgba(239,68,68,.15);   color: var(--red); }
.badge.unknown { background: rgba(100,116,139,.15); color: var(--muted); }

/* ── Table ── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); color: var(--muted); font-weight: 500; text-transform: uppercase; font-size: 11px; letter-spacing: .5px; }
td { padding: 10px 12px; border-bottom: 1px solid var(--border); }
tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(255,255,255,.02); }

/* ── Tabs ── */
.tabs { display: flex; gap: 4px; margin-bottom: 20px; }
.tab-btn {
    padding: 8px 16px;
    border-radius: 6px;
    border: none;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
}
.tab-btn.active { background: var(--surface); color: var(--text); border: 1px solid var(--border); }

/* ── Auth page ── */
.auth-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 16px;
}
.auth-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 32px;
    width: 100%;
    max-width: 380px;
    box-shadow: var(--shadow);
}
.auth-card h1 { font-size: 20px; font-weight: 700; margin-bottom: 6px; }
.auth-card p  { color: var(--muted); margin-bottom: 24px; font-size: 13px; }

/* ── Invite list ── */
.invite-token {
    font-family: monospace;
    background: var(--bg);
    padding: 3px 8px;
    border-radius: 4px;
    font-size: 12px;
    user-select: all;
}

/* ── Modal ── */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.6);
    z-index: 200;
    align-items: center;
    justify-content: center;
}
.modal-overlay.open { display: flex; }
.modal {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 28px;
    width: 100%;
    max-width: 420px;
    box-shadow: var(--shadow);
}
.modal h2 { font-size: 16px; font-weight: 600; margin-bottom: 18px; }

/* ── Toast ── */
#toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    padding: 12px 18px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    z-index: 999;
    opacity: 0;
    transform: translateY(8px);
    transition: opacity .2s, transform .2s;
    pointer-events: none;
}
#toast.show { opacity: 1; transform: translateY(0); }
#toast.ok  { background: var(--green); color: #fff; }
#toast.err { background: var(--red);   color: #fff; }

/* ── Help ── */
.help-content h3 { font-size: 14px; font-weight: 600; margin: 20px 0 8px; color: var(--accent); }
.help-content h3:first-child { margin-top: 0; }
.help-content p { font-size: 13px; color: var(--text); line-height: 1.6; margin-bottom: 8px; }
.help-content ul, .help-content ol { font-size: 13px; margin: 6px 0 12px 20px; color: var(--text); line-height: 1.7; }
.help-content li { margin-bottom: 4px; }

/* ── Lang toggle ── */
/* ── Log filter buttons ── */
.filter-btn {
    background: rgba(255,255,255,.06);
    border: 1px solid var(--border);
    border-radius: 5px;
    padding: 2px 10px;
    font-size: 12px;
    color: var(--muted);
    cursor: pointer;
    transition: background .15s, color .15s;
}
.filter-btn:hover { background: rgba(255,255,255,.1); color: var(--text); }
.filter-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ── Stats bar ── */
.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 18px;
    min-width: 130px;
    flex: 1;
}
.stat-card .stat-val { font-size: 22px; font-weight: 700; line-height: 1.2; }
.stat-card .stat-lbl { font-size: 11px; color: var(--muted); margin-top: 2px; }
.stat-card.green .stat-val { color: var(--green); }
.stat-card.red .stat-val   { color: var(--red); }
.stat-card.blue .stat-val  { color: var(--accent); }

/* ── View switcher ── */
.view-btn {
    background: none;
    border: none;
    border-radius: 6px;
    padding: 4px 8px;
    font-size: 15px;
    cursor: pointer;
    color: var(--muted);
    transition: background .15s, color .15s;
    line-height: 1;
}
.view-btn:hover { background: rgba(255,255,255,.08); color: var(--text); }
.view-btn.active { background: var(--accent); color: #fff; }
#view-switcher { display: none; }

.lang-toggle {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--accent);
    font-size: 11px;
    font-weight: 700;
    padding: 3px 8px;
    cursor: pointer;
    letter-spacing: .5px;
    transition: border-color .15s;
}
.lang-toggle:hover { border-color: var(--accent); }

/* ── Utils ── */
.mt8  { margin-top: 8px; }
.mt16 { margin-top: 16px; }
.flex { display: flex; align-items: center; gap: 8px; }
.text-muted { color: var(--muted); }
.empty-state { text-align: center; padding: 40px 0; color: var(--muted); }

/* ── Mobile ── */
@media (max-width: 640px) {
    .navbar { padding: 0 12px; height: 50px; }
    .navbar .logo { font-size: 14px; }
    .nav-right { gap: 8px; }
    .nav-user { display: none; }

    .container { padding: 16px 10px; }

    .card { padding: 16px; }
    .card-title { font-size: 14px; flex-wrap: wrap; gap: 8px; }

    /* Tabs scroll horizontally */
    .tabs {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        flex-wrap: nowrap;
        padding-bottom: 4px;
    }
    .tabs::-webkit-scrollbar { display: none; }
    .tab-btn { white-space: nowrap; flex-shrink: 0; padding: 7px 12px; font-size: 12px; }

    .pixels-grid { grid-template-columns: 1fr; }

    .pixel-card .actions { flex-wrap: wrap; }

    /* Auth card full-width */
    .auth-card { padding: 24px 16px; }

    /* Modal full-width */
    .modal {
        max-width: 100%;
        margin: 0 12px;
        padding: 20px 16px;
    }
    .modal-overlay { align-items: flex-end; padding-bottom: 0; }
    .modal { border-bottom-left-radius: 0; border-bottom-right-radius: 0; }

    /* Toast bottom-center */
    #toast { left: 12px; right: 12px; bottom: 16px; text-align: center; }

    /* Tables on mobile */
    .table-wrap { -webkit-overflow-scrolling: touch; }
    td, th { padding: 8px 10px; }

    /* Buttons full-width in forms */
    .btn-block-mobile { width: 100%; justify-content: center; }

    .help-content ul, .help-content ol { margin-left: 14px; }
}

/* Modal: fade-in only — no slide/scale (those cause repaint flicker on some Macs) */
.modal-overlay.open { animation: affxFadeIn .15s ease-out; }
@keyframes affxFadeIn { from { opacity: 0 } to { opacity: 1 } }


/* === AFFX Campaigns UI v3 (2026-05-14) — clean rewrite === */

/* Page baseline: solid bg on html so scrollbar zone never shows void */
html { background: var(--bg); min-height: 100vh; }
body { background: var(--bg); min-height: 100vh; }

/* Tables: sticky header, nowrap rows, ellipsis on long names */
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; }
table thead th {
    position: sticky; top: 0;
    background: var(--surface);
    z-index: 2;
}
#tbl-my-campaigns th, #tbl-my-campaigns td,
#tbl-all-campaigns th, #tbl-all-campaigns td {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 360px;
    vertical-align: middle;
}
/* "Название" column gets a bit more */
#tbl-my-campaigns td:nth-child(2),
#tbl-all-campaigns td:nth-child(3) { max-width: 440px; }

/* Zebra rows for readability */
#tbl-my-campaigns tbody tr:nth-child(even),
#tbl-all-campaigns tbody tr:nth-child(even) {
    background: rgba(255,255,255,.02);
}

/* Mobile: horizontal scroll on tables, smaller paddings */
@media (max-width: 768px) {
    .container { padding: 16px 12px; }
    .card { padding: 14px; }
    #tbl-my-campaigns th, #tbl-my-campaigns td,
    #tbl-all-campaigns th, #tbl-all-campaigns td {
        max-width: 220px; font-size: 13px; padding: 8px 6px;
    }
    .modal { margin: 0 8px; }
}
