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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #f0f2f5;
    color: #1a1a2e;
    line-height: 1.5;
}

.navbar {
    background: #1a1a2e;
    padding: 0 24px;
    display: flex;
    align-items: center;
    height: 56px;
    gap: 32px;
}

.navbar .logo {
    color: #fff;
    font-size: 18px;
    font-weight: 700;
    text-decoration: none;
}

.navbar a {
    color: #a0a0c0;
    text-decoration: none;
    font-size: 14px;
    padding: 16px 0;
    border-bottom: 3px solid transparent;
    transition: all .2s;
}

.navbar a:hover, .navbar a.active {
    color: #fff;
    border-bottom-color: #4361ee;
}

.nav-account-group {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 8px;
}

.nav-account {
    color: #a0a0c0;
    font-size: 13px;
}

.btn-switch {
    background: transparent;
    border: 1px solid #3a3a5c;
    color: #a0a0c0;
    border-radius: 5px;
    padding: 3px 10px;
    font-size: 12px;
    cursor: pointer;
    transition: all .2s;
    white-space: nowrap;
}
.btn-switch:hover { border-color: #4361ee; color: #fff; }

/* Account switcher dropdown */
.account-switcher-wrap {
    position: relative;
}

.account-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0,0,0,.12);
    min-width: 240px;
    z-index: 1000;
    overflow: hidden;
}

.account-dropdown-header {
    padding: 10px 14px;
    font-size: 11px;
    font-weight: 600;
    color: #888;
    text-transform: uppercase;
    letter-spacing: .5px;
    border-bottom: 1px solid #f0f0f0;
}

.account-dropdown-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    cursor: pointer;
    transition: background .15s;
    border: none;
    background: transparent;
    width: 100%;
    text-align: left;
}
.account-dropdown-item:hover { background: #f5f7ff; }
.account-dropdown-item.active-acc { background: #eef1ff; }

.acc-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: #4361ee;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 700;
    flex-shrink: 0;
}
.acc-avatar.active-acc { background: #22c55e; }

.acc-info { flex: 1; min-width: 0; }
.acc-name { font-size: 13px; font-weight: 600; color: #1a1a2e; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.acc-login { font-size: 11px; color: #999; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.acc-active-mark { font-size: 11px; color: #22c55e; font-weight: 600; }

.account-dropdown-footer {
    border-top: 1px solid #f0f0f0;
    padding: 8px 14px;
}
.account-dropdown-footer a {
    display: block;
    text-align: center;
    font-size: 12px;
    color: #4361ee;
    text-decoration: none;
    padding: 4px 0;
}
.account-dropdown-footer a:hover { text-decoration: underline; }

/* Accounts list on settings page */
.accounts-list {
    display: flex;
    flex-direction: column;
    gap: 0;
    border: 1px solid #e9ecef;
    border-radius: 8px;
    overflow: hidden;
    margin-bottom: 16px;
}

.account-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    border-bottom: 1px solid #f0f0f0;
    background: #fff;
    transition: background .15s;
}
.account-item:last-child { border-bottom: none; }
.account-item.is-active { background: #f5f7ff; }

.account-item-info { flex: 1; min-width: 0; }
.account-item-name { font-size: 14px; font-weight: 600; color: #1a1a2e; }
.account-item-login { font-size: 12px; color: #888; margin-top: 2px; }

.account-item-actions { display: flex; gap: 8px; align-items: center; }

.badge-active {
    display: inline-block;
    background: #d4edda;
    color: #155724;
    font-size: 11px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 10px;
}

/* Add account form */
.add-account-form {
    background: #f8f9fa;
    border: 1px dashed #c0c8e0;
    border-radius: 8px;
    padding: 16px;
    margin-top: 8px;
}

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

.header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.header-row h1 { font-size: 24px; font-weight: 600; }

.meta {
    display: flex;
    gap: 16px;
    align-items: center;
    font-size: 13px;
    color: #666;
}

.btn {
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: all .2s;
}

.btn-primary { background: #4361ee; color: #fff; }
.btn-primary:hover { background: #3a56d4; }
.btn-secondary { background: #6c757d; color: #fff; }
.btn-secondary:hover { background: #5a6268; }
.btn-danger { background: #e63946; color: #fff; }
.btn-danger:hover { background: #c5303c; }
.btn-success { background: #22c55e; color: #fff; }
.btn-success:hover { background: #16a34a; }

/* Bulk action bar */
.bulk-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    background: #fff;
    border: 1px solid #4361ee;
    border-radius: 8px;
    padding: 10px 16px;
    margin-bottom: 12px;
}
.bulk-count { font-size: 14px; font-weight: 600; color: #4361ee; margin-right: 4px; }

/* Checkbox column */
.col-check { width: 36px; text-align: center; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-outline {
    background: transparent;
    border: 1px solid #ccc;
    color: #333;
}
.btn-outline:hover { background: #eee; }

/* Summary cards */
.summary-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
    margin-bottom: 24px;
}

.summary-card {
    background: #fff;
    border-radius: 10px;
    padding: 16px;
    box-shadow: 0 1px 3px rgba(0,0,0,.08);
}

.summary-card .label { font-size: 12px; color: #888; text-transform: uppercase; letter-spacing: .5px; }
.summary-card .value { font-size: 24px; font-weight: 700; margin-top: 4px; }

/* Filters */
.filters {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
    flex-wrap: wrap;
    align-items: center;
}

.filters input, .filters select {
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 13px;
    background: #fff;
}

.filters input[type="text"] { width: 280px; }

.filter-checkbox {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    color: #444;
    cursor: pointer;
    white-space: nowrap;
}
.filter-checkbox input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
}

/* Ads table */
.table-wrap {
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 1px 3px rgba(0,0,0,.08);
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

thead th {
    background: #f8f9fa;
    padding: 10px 12px;
    text-align: left;
    font-weight: 600;
    white-space: nowrap;
    border-bottom: 2px solid #e9ecef;
    position: sticky;
    top: 0;
    user-select: none;
}

thead th.sortable {
    cursor: pointer;
}

thead th.sortable:hover {
    background: #eef0f4;
}

thead th.sort-asc::after  { content: ' ↑'; color: #4361ee; font-size: 11px; }
thead th.sort-desc::after { content: ' ↓'; color: #4361ee; font-size: 11px; }

/* Pagination */
.pagination-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 16px;
    background: #fff;
    border-top: 1px solid #e9ecef;
    border-radius: 0 0 10px 10px;
    flex-wrap: wrap;
    gap: 10px;
}

.pagination-pages {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.page-info {
    font-size: 13px;
    color: #666;
    margin-right: 6px;
}

.page-btns {
    display: flex;
    align-items: center;
    gap: 4px;
}

.page-btn {
    min-width: 32px;
    height: 32px;
    padding: 0 8px;
    border: 1px solid #ddd;
    border-radius: 6px;
    background: #fff;
    font-size: 13px;
    cursor: pointer;
    transition: all .15s;
    color: #333;
}

.page-btn:hover:not(:disabled) { background: #f0f2f5; border-color: #bbb; }
.page-btn.active { background: #4361ee; color: #fff; border-color: #4361ee; font-weight: 600; }
.page-btn:disabled { opacity: .4; cursor: default; }
.page-ellipsis { font-size: 13px; color: #999; padding: 0 4px; }

.pagination-size {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: #666;
}

.page-size-btn {
    padding: 5px 10px;
    border: 1px solid #ddd;
    border-radius: 6px;
    background: #fff;
    font-size: 13px;
    cursor: pointer;
    transition: all .15s;
    color: #333;
}

.page-size-btn:hover { background: #f0f2f5; }
.page-size-btn.active { background: #4361ee; color: #fff; border-color: #4361ee; font-weight: 600; }

tbody td {
    padding: 10px 12px;
    border-bottom: 1px solid #f0f0f0;
    vertical-align: middle;
}

tbody tr:hover { background: #f8f9ff; }

.ad-title-cell {
    display: flex;
    gap: 10px;
    align-items: center;
    min-width: 300px;
}

.ad-thumb {
    width: 50px;
    height: 50px;
    border-radius: 6px;
    object-fit: cover;
    flex-shrink: 0;
}

.ad-title { font-weight: 500; }
.ad-subtitle { font-size: 12px; color: #666; margin-top: 1px; font-style: italic; }
.ad-category { font-size: 11px; color: #888; margin-top: 2px; }

.status-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
}

.status-active { background: #d4edda; color: #155724; }
.status-inactive { background: #f8d7da; color: #721c24; }
.status-moderation { background: #fff3cd; color: #856404; }

/* Moderation status badge in table rows */
.mod-badge {
    display: inline-block;
    margin-top: 3px;
    padding: 1px 6px;
    border-radius: 8px;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: .2px;
    text-transform: uppercase;
    white-space: nowrap;
}
.mod-badge-ban     { background: #fde8e8; color: #b91c1c; }
.mod-badge-reject  { background: #fef3c7; color: #92400e; }
.mod-badge-wait    { background: #dbeafe; color: #1e40af; }
.mod-badge-new     { background: #f3f4f6; color: #374151; }

.btn-edit-teaser {
    display: inline-block;
    margin-top: 5px;
    padding: 2px 10px;
    font-size: 11px;
    font-weight: 600;
    color: #fff;
    background: #ef4444;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    line-height: 1.6;
}
.btn-edit-teaser:hover { background: #dc2626; }

/* Edit teaser modal */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.45);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}
.modal-overlay.open { display: flex; }
.modal-box {
    background: #fff;
    border-radius: 12px;
    padding: 28px 32px;
    width: 520px;
    max-width: 95vw;
    box-shadow: 0 8px 32px rgba(0,0,0,.18);
}
.modal-box h3 { margin: 0 0 4px; font-size: 16px; }
.modal-box .modal-subtitle { font-size: 12px; color: #888; margin-bottom: 18px; }
.modal-field { margin-bottom: 14px; }
.modal-field label { display: block; font-size: 12px; font-weight: 600; color: #555; margin-bottom: 4px; }
.modal-field input,
.modal-field textarea {
    width: 100%;
    box-sizing: border-box;
    padding: 8px 10px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 13px;
    font-family: inherit;
    resize: vertical;
}
.modal-field input:focus,
.modal-field textarea:focus { outline: none; border-color: #4361ee; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; }
.btn-modal-cancel {
    padding: 7px 18px; border: 1px solid #d1d5db; border-radius: 6px;
    background: #fff; font-size: 13px; cursor: pointer;
}
.btn-modal-cancel:hover { background: #f3f4f6; }
.btn-modal-submit {
    padding: 7px 18px; border: none; border-radius: 6px;
    background: #4361ee; color: #fff; font-size: 13px;
    font-weight: 600; cursor: pointer;
}
.btn-modal-submit:hover { background: #3451d1; }
.btn-modal-submit:disabled { background: #a5b4fc; cursor: default; }
.modal-error { color: #b91c1c; font-size: 12px; margin-top: 8px; }

.status-dot {
    display: inline-block;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    margin-right: 5px;
    vertical-align: middle;
    flex-shrink: 0;
}
.dot-active   { background: #22c55e; }
.dot-inactive { background: #d1d5db; }

.num-right { text-align: right; font-variant-numeric: tabular-nums; }
.sub { font-size: 11px; color: #999; }

/* Loading */
.loading {
    text-align: center;
    padding: 60px;
    color: #888;
}

.spinner {
    display: inline-block;
    width: 24px;
    height: 24px;
    border: 3px solid #e0e0e0;
    border-top-color: #4361ee;
    border-radius: 50%;
    animation: spin .8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* Rules page */
.rule-form, .settings-card {
    background: #fff;
    border-radius: 10px;
    padding: 20px;
    margin-bottom: 24px;
    box-shadow: 0 1px 3px rgba(0,0,0,.08);
}

.rule-form h3, .settings-card h3 { margin-bottom: 16px; }

.form-row {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    align-items: end;
    margin-bottom: 12px;
}

.form-group { display: flex; flex-direction: column; gap: 4px; }
.form-group label { font-size: 12px; color: #666; font-weight: 500; }
.form-group input, .form-group select {
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 13px;
}

.rules-list {
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 1px 3px rgba(0,0,0,.08);
}

.rule-item {
    display: flex;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid #f0f0f0;
    gap: 16px;
}

.rule-item:last-child { border-bottom: none; }

.rule-info { flex: 1; }
.rule-name { font-weight: 600; margin-bottom: 4px; }
.rule-desc { font-size: 13px; color: #666; }

.cond-and-badge {
    display: inline-flex;
    align-items: center;
    padding: 1px 7px;
    background: #e8f0fe;
    color: #3b5bdb;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin: 0 4px;
}

.cond-row {
    align-items: flex-end;
    gap: 8px;
}

.cond-row .cond-and-badge {
    margin-bottom: 8px;
}

.cond-remove {
    margin-bottom: 6px;
    padding: 4px 8px;
    line-height: 1;
}

.toggle {
    position: relative;
    width: 44px;
    height: 24px;
    cursor: pointer;
}

.toggle input { display: none; }
.toggle .slider {
    position: absolute;
    inset: 0;
    background: #ccc;
    border-radius: 12px;
    transition: .3s;
}

.toggle .slider::before {
    content: '';
    position: absolute;
    width: 18px;
    height: 18px;
    background: #fff;
    border-radius: 50%;
    left: 3px;
    top: 3px;
    transition: .3s;
}

.toggle input:checked + .slider { background: #4361ee; }
.toggle input:checked + .slider::before { transform: translateX(20px); }

.empty-state {
    text-align: center;
    padding: 40px;
    color: #888;
}

.action-stop { color: #e63946; }

/* Keitaro columns */
.col-keitaro { min-width: 90px; }
.keitaro-good { color: #22c55e; }
.keitaro-mid  { color: #f59e0b; }
.keitaro-bad  { color: #e63946; }

/* CTR color coding */
.ctr-good { color: #22c55e; }
.ctr-mid  { color: #f59e0b; }
.ctr-bad  { color: #e63946; }

/* Campaign mappings */
.mapping-table { display: flex; flex-direction: column; gap: 0; }
.mapping-header {
    display: grid;
    grid-template-columns: 1fr 280px;
    gap: 12px;
    padding: 8px 12px;
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 6px 6px 0 0;
    font-size: 12px;
    font-weight: 600;
    color: #666;
    text-transform: uppercase;
    letter-spacing: .4px;
}
.mapping-row {
    display: grid;
    grid-template-columns: 1fr 280px;
    gap: 12px;
    padding: 10px 12px;
    border: 1px solid #e9ecef;
    border-top: none;
    align-items: center;
    background: #fff;
    transition: background .15s;
}
.mapping-row:last-child { border-radius: 0 0 6px 6px; }
.mapping-row:hover { background: #f8f9ff; }
.mapping-site { font-size: 13px; font-weight: 500; word-break: break-all; }
.mapping-control-wrap {
    display: flex;
    align-items: center;
    gap: 6px;
}
.mapping-select {
    flex: 1;
    min-width: 0;
    padding: 6px 10px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 13px;
    background: #fff;
}
.mapping-select-auto {
    border-color: #66bb6a;
    background: #f1faf2;
}
.badge-auto {
    flex-shrink: 0;
    display: inline-block;
    padding: 2px 7px;
    border-radius: 10px;
    background: #e8f5e9;
    color: #388e3c;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: .3px;
    text-transform: uppercase;
    white-space: nowrap;
}
