:root {
    --bg: #f5f5f7;
    --card-bg: #ffffff;
    --text: #1a1a2e;
    --text-muted: #6b7280;
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --primary-light: #eef2ff;
    --success: #10b981;
    --success-light: #d1fae5;
    --warning: #f59e0b;
    --warning-light: #fef3c7;
    --danger: #ef4444;
    --danger-light: #fee2e2;
    --info: #3b82f6;
    --border: #e5e7eb;
    --border-focus: #a5b4fc;
    --radius: 10px;
    --radius-sm: 6px;
    --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.1);
    --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

/* Layout */
.container { max-width: 1100px; margin: 0 auto; padding: 24px; }
.container-wide { max-width: 1400px; margin: 0 auto; padding: 24px 32px; }

/* Header */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 0;
    border-bottom: 1px solid var(--border);
    margin-bottom: 24px;
}
.header h1 { font-size: 1.4rem; font-weight: 700; letter-spacing: -0.3px; }
.header .user-info {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.85rem;
    color: var(--text-muted);
}
.header .user-info img { width: 32px; height: 32px; border-radius: 50%; }
.header a { color: var(--primary); text-decoration: none; font-weight: 500; }
.header a:hover { text-decoration: underline; }

/* Cards */
.card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 16px;
    box-shadow: var(--shadow);
    transition: box-shadow var(--transition), transform var(--transition);
}
.card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.card h2 { font-size: 1.15rem; margin-bottom: 4px; font-weight: 600; }
.card .meta { color: var(--text-muted); font-size: 0.83rem; }

/* Status badges */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 12px;
    border-radius: 99px;
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.3px;
    text-transform: uppercase;
}
.badge-draft { background: #f3f4f6; color: #4b5563; }
.badge-approved { background: var(--warning-light); color: #92400e; }
.badge-published { background: var(--success-light); color: #065f46; }
.badge-archived { background: var(--danger-light); color: #991b1b; }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 18px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    transition: all var(--transition);
    white-space: nowrap;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); box-shadow: 0 2px 8px rgba(99,102,241,0.35); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { box-shadow: 0 2px 8px rgba(16,185,129,0.35); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { box-shadow: 0 2px 8px rgba(239,68,68,0.35); }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-outline:hover { background: var(--bg); border-color: #c5c7cc; }
.btn-sm { padding: 5px 12px; font-size: 0.78rem; }
.btn-lg { padding: 12px 28px; font-size: 0.95rem; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; pointer-events: none; }

/* Forms */
.form-group { margin-bottom: 14px; }
.form-group label {
    display: block;
    font-weight: 500;
    margin-bottom: 4px;
    font-size: 0.83rem;
    color: #374151;
}
.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    background: #fff;
    transition: border-color var(--transition), box-shadow var(--transition);
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(99,102,241,0.12);
}
.form-group textarea { resize: vertical; min-height: 80px; }
.form-group input[type="color"] {
    width: 44px;
    height: 34px;
    padding: 2px;
    cursor: pointer;
    border-radius: var(--radius-sm);
}
.form-group input[type="checkbox"] {
    width: auto;
    accent-color: var(--primary);
}
.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

/* Toolbar */
.toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    gap: 12px;
}
.toolbar .filters { display: flex; gap: 8px; align-items: center; }
.toolbar select, .toolbar input {
    padding: 7px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.83rem;
    background: #fff;
}

/* Popup list item */
.popup-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    text-decoration: none;
    color: inherit;
    transition: background var(--transition);
}
.popup-item:last-child { border-bottom: none; }
.popup-item:hover { background: var(--primary-light); }
.popup-info h3 { font-size: 0.95rem; font-weight: 600; }
.popup-info .store { color: var(--text-muted); font-size: 0.83rem; }
.popup-actions { display: flex; gap: 8px; align-items: center; }

/* Editor layout */
.editor-layout {
    display: grid;
    grid-template-columns: 500px 1fr;
    gap: 24px;
    min-height: calc(100vh - 120px);
}
.editor-form {
    overflow-y: auto;
    max-height: calc(100vh - 120px);
    padding-right: 12px;
    scrollbar-width: thin;
    scrollbar-color: #d1d5db transparent;
}
.editor-form::-webkit-scrollbar { width: 5px; }
.editor-form::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 99px; }
.editor-preview {
    position: sticky;
    top: 24px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow);
}
.editor-preview .preview-header {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    font-size: 0.83rem;
    color: var(--text-muted);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #fafbfc;
}
.editor-preview iframe {
    width: 100%;
    flex: 1;
    border: none;
    min-height: 500px;
}

/* Section headers in editor */
.section-header {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--primary);
    margin: 20px 0 10px;
    padding-bottom: 6px;
    border-bottom: 2px solid var(--primary-light);
}
.section-header:first-child { margin-top: 0; }

/* Color field with preview */
.color-field {
    display: flex;
    align-items: center;
    gap: 8px;
}
.color-field input[type="text"] { flex: 1; }

/* Login page */
.login-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #eef2ff 0%, #f5f5f7 50%, #e0e7ff 100%);
}
.login-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 48px 40px;
    text-align: center;
    max-width: 400px;
    width: 100%;
    box-shadow: var(--shadow-lg);
}
.login-card h1 { margin-bottom: 8px; font-weight: 700; }
.login-card p { color: var(--text-muted); margin-bottom: 28px; }

.google-btn {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 12px 28px;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    color: var(--text);
    transition: all var(--transition);
}
.google-btn:hover { box-shadow: var(--shadow-md); border-color: #c5c7cc; }

/* Empty state */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}
.empty-state h2 { margin-bottom: 8px; }

/* Modal */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.45);
    backdrop-filter: blur(4px);
    z-index: 100;
    align-items: center;
    justify-content: center;
}
.modal-overlay.active { display: flex; }
.modal {
    background: var(--card-bg);
    border-radius: 14px;
    padding: 28px;
    max-width: 500px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
}
.modal h2 { margin-bottom: 16px; font-weight: 700; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 20px; }

/* Toast notification */
.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    padding: 12px 20px;
    border-radius: var(--radius);
    color: #fff;
    font-size: 0.85rem;
    font-weight: 500;
    z-index: 200;
    opacity: 0;
    transform: translateY(10px);
    transition: all 0.3s;
    box-shadow: var(--shadow-md);
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }

/* Template type tabs */
.tab-group {
    display: flex;
    gap: 4px;
    background: #f3f4f6;
    padding: 4px;
    border-radius: var(--radius);
}
.tab-btn {
    flex: 1;
    padding: 7px 14px;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    color: var(--text-muted);
    transition: all var(--transition);
}
.tab-btn.active {
    background: var(--card-bg);
    color: var(--primary);
    font-weight: 600;
    box-shadow: var(--shadow);
}
.tab-btn:hover:not(.active) { color: var(--text); }

/* Subsection header in forms */
.subsection {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    color: var(--text-muted);
    margin: 12px 0 8px;
    padding-top: 8px;
    border-top: 1px dashed var(--border);
}

/* URL rule rows */
.url-rule-row {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-bottom: 8px;
}
.url-rule-row select { width: 120px; flex-shrink: 0; }
.url-rule-row input { flex: 1; }

/* 3-column form row */
.form-row { grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); }

/* Accordion sections */
.accordion-section summary {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--primary);
    padding: 8px 0 6px;
    border-bottom: 2px solid var(--primary-light);
    cursor: pointer;
    user-select: none;
    list-style: none;
    display: flex;
    align-items: center;
    gap: 6px;
}
.accordion-section summary::before {
    content: "▸";
    font-size: 0.8rem;
    transition: transform var(--transition);
}
.accordion-section[open] summary::before {
    transform: rotate(90deg);
}
.accordion-section summary::-webkit-details-marker { display: none; }

/* GTM section toggle */
.gtm-hidden { display: none !important; }

/* ===== A/B Testing ===== */
.ab-variant-tabs {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-bottom: 14px;
}
.ab-variant-tab {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    border: 1.5px solid var(--border);
    border-radius: 99px;
    background: var(--card-bg);
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    color: var(--text-muted);
    transition: all var(--transition);
}
.ab-variant-tab:hover { border-color: #a5b4fc; color: var(--text); }
.ab-variant-tab.active {
    border-color: var(--primary);
    background: var(--primary-light);
    color: var(--primary);
    font-weight: 600;
    box-shadow: 0 0 0 2px rgba(99,102,241,0.1);
}
.ab-variant-tab .variant-letter {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: #e5e7eb;
    color: #6b7280;
    font-weight: 700;
    font-size: 0.7rem;
    flex-shrink: 0;
}
.ab-variant-tab.active .variant-letter {
    background: var(--primary);
    color: #fff;
}
.ab-variant-tab .variant-traffic {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-left: 2px;
}
.ab-variant-tab.active .variant-traffic { color: var(--primary); }

/* Traffic allocation bar */
.traffic-bar-container {
    padding: 14px;
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 14px;
}
.traffic-bar-label {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    font-size: 0.78rem;
    font-weight: 500;
    color: #475569;
}
.traffic-bar {
    display: flex;
    height: 28px;
    border-radius: 99px;
    overflow: hidden;
    background: #e5e7eb;
}
.traffic-bar-segment {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: 600;
    color: #fff;
    transition: width 0.3s ease;
    min-width: 0;
    overflow: hidden;
    white-space: nowrap;
}
.traffic-bar-legend {
    display: flex;
    gap: 14px;
    margin-top: 8px;
    flex-wrap: wrap;
}
.traffic-bar-legend-item {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 0.72rem;
    color: #64748b;
}
.traffic-bar-legend-item .swatch {
    width: 10px;
    height: 10px;
    border-radius: 2px;
    flex-shrink: 0;
}

/* A/B hint box */
.ab-hint {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 10px 14px;
    background: #f0f4ff;
    border: 1px solid #c7d2fe;
    border-radius: var(--radius-sm);
    font-size: 0.78rem;
    line-height: 1.5;
    color: #4338ca;
    margin-bottom: 14px;
}
.ab-hint-icon {
    font-size: 1rem;
    flex-shrink: 0;
    line-height: 1;
    margin-top: 1px;
}

/* Auto-winner section */
.auto-winner-section {
    margin-top: 16px;
    padding: 14px;
    background: #fafbfc;
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.auto-winner-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
    font-size: 0.78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #64748b;
}
.stats-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 0.8rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
}
.stats-table th {
    text-align: left;
    padding: 8px 12px;
    font-weight: 600;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: #64748b;
    background: #f1f5f9;
    border-bottom: 1px solid var(--border);
}
.stats-table th:not(:first-child) { text-align: right; }
.stats-table td {
    padding: 8px 12px;
    border-bottom: 1px solid #f1f5f9;
}
.stats-table td:not(:first-child) { text-align: right; font-variant-numeric: tabular-nums; }
.stats-table tr:last-child td { border-bottom: none; }
.stats-table tr.winner-row { background: #ecfdf5; }
.stats-table .winner-badge {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding: 1px 8px;
    background: var(--success);
    color: #fff;
    border-radius: 99px;
    font-size: 0.68rem;
    font-weight: 600;
    margin-left: 6px;
}

/* ===== Suppression Rules ===== */
.suppression-rule {
    display: flex;
    gap: 10px;
    padding: 12px 14px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 8px;
    transition: border-color var(--transition), box-shadow var(--transition);
}
.suppression-rule:hover {
    border-color: #c5c7cc;
    box-shadow: var(--shadow);
}
.suppression-rule-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    flex-shrink: 0;
    font-size: 1.1rem;
}
.suppression-rule-icon.close_count { background: #fef2f2; }
.suppression-rule-icon.page_type { background: #eff6ff; }
.suppression-rule-icon.conversion { background: #ecfdf5; }
.suppression-rule-icon.custom_event { background: #faf5ff; }
.suppression-rule-body { flex: 1; min-width: 0; }
.suppression-rule-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 6px;
}
.suppression-rule-type {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text);
}
.suppression-rule-params {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}
.suppression-rule-params label {
    font-size: 0.78rem;
    color: #64748b;
    white-space: nowrap;
}
.suppression-rule-params input,
.suppression-rule-params select {
    padding: 4px 8px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 0.8rem;
    background: #fff;
}
.suppression-rule-params input[type="number"] { width: 56px; }
.suppression-rule-params textarea {
    width: 100%;
    padding: 6px 8px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 0.8rem;
    resize: vertical;
    min-height: 48px;
    margin-top: 4px;
}
.suppression-rule-desc {
    font-size: 0.76rem;
    color: #94a3b8;
    line-height: 1.4;
}

/* Responsive */
@media (max-width: 900px) {
    .editor-layout {
        grid-template-columns: 1fr;
    }
    .editor-preview {
        position: static;
        min-height: 400px;
    }
}
@media (max-width: 600px) {
    .container, .container-wide { padding: 16px; }
    .header { flex-direction: column; gap: 8px; }
    .form-row { grid-template-columns: 1fr; }
}

/* --- Popup Banner Manager Loading Animation (indigo) --- */
.loading-overlay{position:fixed;inset:0;z-index:9999;background:#0c0a1a;display:flex;align-items:center;justify-content:center;transition:opacity .5s}
.loading-overlay.fade-out{opacity:0;pointer-events:none}
.loading-text{font-family:'SF Mono','Fira Code',monospace;font-size:1.5rem;color:#a5b4fc;letter-spacing:.15em}
.loading-text .cursor{display:inline-block;width:2px;height:1.2em;background:#a5b4fc;vertical-align:text-bottom;animation:cursor-blink .7s step-end infinite;margin-left:2px}
@keyframes cursor-blink{0%,100%{opacity:1}50%{opacity:0}}
