*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

/* СВІТЛА ТЕМА (За замовчуванням) */
:root {
    --bg-dark: #f4f5f7;
    --bg-card: #ffffff;
    --bg-card-hover: #f8f9fa;
    --bg-sidebar: #ffffff;
    --border: #e2e8f0;
    --text-primary: #1e293b;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    --accent: #6c5ce7;
    --accent-hover: #5a4bcf;
    --accent-light: rgba(108,92,231,0.1);
    --green: #10b981;
    --green-bg: rgba(16,185,129,0.1);
    --red: #ef4444;
    --red-bg: rgba(239,68,68,0.1);
    --yellow: #f59e0b;
    --yellow-bg: rgba(245,158,11,0.1);
    --blue: #3b82f6;
    --blue-bg: rgba(59,130,246,0.1);
    --orange: #f97316;
    --sidebar-w: 260px;
    --header-h: 64px;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 4px 12px rgba(0,0,0,0.05);
}

/* ТЕМНА ТЕМА */
[data-theme="dark"] {
    --bg-dark: #0f1117;
    --bg-card: #1a1d27;
    --bg-card-hover: #222632;
    --bg-sidebar: #13151d;
    --border: #2a2d3a;
    --text-primary: #e8eaed;
    --text-secondary: #8b8fa3;
    --text-muted: #5f6377;
    --shadow: 0 4px 24px rgba(0,0,0,0.3);
}

body { font-family: 'Inter', -apple-system, sans-serif; background: var(--bg-dark); color: var(--text-primary); min-height: 100vh; overflow-x: hidden; transition: background 0.3s, color 0.3s; }
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

.sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: var(--sidebar-w); background: var(--bg-sidebar); border-right: 1px solid var(--border); display: flex; flex-direction: column; z-index: 100; transition: transform 0.3s, background 0.3s; }
.sidebar-logo { padding: 20px 24px; display: flex; align-items: center; gap: 12px; border-bottom: 1px solid var(--border); height: var(--header-h); }
.logo-icon { width: 36px; height: 36px; background: linear-gradient(135deg, var(--accent), #a78bfa); border-radius: 10px; display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 16px; color: #fff; }
.logo-text { font-weight: 700; font-size: 17px; color: var(--text-primary); }
.sidebar-nav { flex: 1; padding: 16px 12px; overflow-y: auto; }
.nav-section { margin-bottom: 24px; }
.nav-section-title { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 1.2px; color: var(--text-muted); padding: 0 12px; margin-bottom: 8px; }
.nav-item { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: var(--radius-sm); cursor: pointer; transition: all 0.2s; color: var(--text-secondary); font-size: 14px; font-weight: 500; margin-bottom: 2px; position: relative; }
.nav-item:hover { background: var(--bg-card-hover); color: var(--text-primary); }
.nav-item.active { background: var(--accent-light); color: var(--accent); }
.nav-item.active::before { content: ''; position: absolute; left: -12px; top: 50%; transform: translateY(-50%); width: 3px; height: 20px; background: var(--accent); border-radius: 0 3px 3px 0; }
.nav-item svg { width: 20px; height: 20px; flex-shrink: 0; }
.nav-item .badge { margin-left: auto; background: var(--accent); color: #fff; font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 10px; min-width: 24px; text-align: center; }
.sidebar-footer { padding: 16px; border-top: 1px solid var(--border); }
.user-card { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: var(--radius-sm); background: var(--bg-card-hover); }
.user-avatar { width: 36px; height: 36px; border-radius: 50%; background: linear-gradient(135deg, var(--accent), #e040fb); display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 14px; color: #fff; text-transform: uppercase; }
.user-info { flex: 1; min-width: 0; }
.user-name { font-size: 13px; font-weight: 600; }
.user-plan { font-size: 11px; color: var(--text-muted); }

.main { margin-left: var(--sidebar-w); min-height: 100vh; }
.header { height: var(--header-h); border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; padding: 0 32px; background: var(--bg-sidebar); position: sticky; top: 0; z-index: 50; }
.header-left { display: flex; align-items: center; gap: 16px; }
.header-title { font-size: 18px; font-weight: 700; }
.header-subtitle { font-size: 13px; color: var(--text-muted); }
.header-right { display: flex; align-items: center; gap: 12px; }
.header-btn { display: flex; align-items: center; justify-content: center; gap: 8px; padding: 8px 16px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--bg-card); color: var(--text-secondary); font-size: 13px; font-weight: 500; cursor: pointer; transition: all 0.2s; }
.header-btn:hover { border-color: var(--accent); color: var(--text-primary); }
.header-btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.header-btn.primary:hover { background: var(--accent-hover); }
.header-btn svg { width: 16px; height: 16px; }
.header-btn.icon-only { padding: 8px; }

.content { padding: 28px 32px; }
.page { display: none; }
.page.active { display: block; }

.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 28px; }
.stat-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px 24px; transition: all 0.2s; position: relative; overflow: hidden; box-shadow: var(--shadow); }
.stat-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.stat-icon { width: 40px; height: 40px; border-radius: 10px; display: flex; align-items: center; justify-content: center; margin-bottom: 14px; }
.stat-icon svg { width: 20px; height: 20px; }
.stat-label { font-size: 13px; color: var(--text-secondary); margin-bottom: 6px; }
.stat-value { font-size: 28px; font-weight: 800; margin-bottom: 6px; }
.stat-change { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 6px; }
.stat-change.up { color: var(--green); background: var(--green-bg); }
.stat-change.down { color: var(--red); background: var(--red-bg); }
.stat-change.neutral { color: var(--yellow); background: var(--yellow-bg); }

.card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.card-header { padding: 18px 24px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.card-title { font-size: 15px; font-weight: 700; }
.card-body { padding: 24px; }
.card-body.no-pad { padding: 0; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 28px; }
.grid-3-1 { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; margin-bottom: 28px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
thead th { padding: 12px 16px; text-align: left; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.8px; color: var(--text-muted); background: var(--bg-card-hover); border-bottom: 1px solid var(--border); cursor: pointer; user-select: none; white-space: nowrap; position: sticky; top: 0; }
thead th:hover { color: var(--text-secondary); }
thead th .sort-icon { display: inline-block; margin-left: 4px; opacity: 0.4; }
tbody tr { border-bottom: 1px solid var(--border); transition: background 0.15s; }
tbody tr:hover { background: var(--bg-card-hover); }
tbody td { padding: 12px 16px; font-size: 13px; white-space: nowrap; }
.td-keyword { font-weight: 500; color: var(--text-primary); max-width: 300px; overflow: hidden; text-overflow: ellipsis; }
.td-url { color: var(--text-secondary); max-width: 200px; overflow: hidden; text-overflow: ellipsis; }

.pos-badge { display: inline-flex; align-items: center; justify-content: center; min-width: 36px; padding: 4px 10px; border-radius: 6px; font-size: 13px; font-weight: 700; }
.pos-top3 { background: var(--green-bg); color: var(--green); }
.pos-top10 { background: var(--blue-bg); color: var(--blue); }
.pos-top30 { background: var(--yellow-bg); color: var(--yellow); }
.pos-top100 { background: var(--red-bg); color: var(--red); }
.pos-none { background: var(--bg-card-hover); color: var(--text-muted); }

.change-indicator { display: inline-flex; align-items: center; gap: 3px; font-size: 12px; font-weight: 600; }
.change-indicator.up { color: var(--green); }
.change-indicator.down { color: var(--red); }
.change-indicator.same { color: var(--text-muted); }
.change-indicator svg { width: 14px; height: 14px; }

.se-tabs { display: flex; gap: 4px; margin-bottom: 20px; }
.se-tab { padding: 8px 20px; border-radius: var(--radius-sm); font-size: 13px; font-weight: 600; cursor: pointer; border: 1px solid transparent; color: var(--text-secondary); background: transparent; transition: all 0.2s; }
.se-tab:hover { background: var(--bg-card-hover); }
.se-tab.active { background: var(--accent-light); color: var(--accent); border-color: var(--accent); }

.filters-bar { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.search-input { flex: 1; min-width: 200px; padding: 10px 16px 10px 40px; background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-sm); color: var(--text-primary); font-size: 13px; outline: none; transition: border-color 0.2s; font-family: inherit; }
.search-input:focus { border-color: var(--accent); }
.search-wrap { position: relative; flex: 1; min-width: 200px; }
.search-wrap svg { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--text-muted); }
.filter-select { padding: 10px 36px 10px 14px; background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-sm); color: var(--text-secondary); font-size: 13px; outline: none; cursor: pointer; font-family: inherit; appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%235f6377' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; }
.filter-select:focus { border-color: var(--accent); }

.chart-container { position: relative; height: 300px; width: 100%; }

.projects-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 16px; }
.project-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; cursor: pointer; transition: all 0.2s; box-shadow: var(--shadow); }
.project-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.project-domain { font-size: 16px; font-weight: 700; margin-bottom: 4px; display: flex; align-items: center; gap: 8px; }
.project-domain .favicon { width: 20px; height: 20px; border-radius: 4px; background: var(--accent-light); display: flex; align-items: center; justify-content: center; font-size: 10px; font-weight: 700; color: var(--accent); }
.project-url { font-size: 12px; color: var(--text-muted); margin-bottom: 16px; }
.project-stats { display: flex; gap: 20px; }
.project-stat-label { font-size: 11px; color: var(--text-muted); margin-bottom: 2px; }
.project-stat-value { font-size: 18px; font-weight: 700; }

.modal-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.6); backdrop-filter: blur(4px); z-index: 200; align-items: center; justify-content: center; }
.modal-overlay.show { display: flex; }
.modal { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); width: 90%; max-width: 560px; max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow); }
.modal-header { padding: 20px 24px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.modal-header h3 { font-size: 16px; font-weight: 700; }
.modal-close { width: 32px; height: 32px; border-radius: 8px; border: none; background: transparent; color: var(--text-muted); cursor: pointer; display: flex; align-items: center; justify-content: center; font-size: 20px; transition: all 0.2s; }
.modal-close:hover { background: var(--bg-card-hover); color: var(--text-primary); }
.modal-body { padding: 24px; }
.form-group { margin-bottom: 18px; }
.form-label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--text-secondary); }
.form-input { width: 100%; padding: 10px 14px; background: var(--bg-dark); border: 1px solid var(--border); border-radius: var(--radius-sm); color: var(--text-primary); font-size: 13px; outline: none; font-family: inherit; }
.form-input:focus { border-color: var(--accent); }
textarea.form-input { resize: vertical; min-height: 100px; }
.modal-footer { padding: 16px 24px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }

.toast-container { position: fixed; top: 80px; right: 32px; z-index: 300; display: flex; flex-direction: column; gap: 8px; }
.toast { padding: 14px 20px; border-radius: var(--radius-sm); background: var(--bg-card); border: 1px solid var(--border); font-size: 13px; font-weight: 500; box-shadow: var(--shadow); animation: slideIn 0.3s ease; display: flex; align-items: center; gap: 10px; }
.toast.success { border-left: 3px solid var(--green); }
.toast.error { border-left: 3px solid var(--red); }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes fadeOut { from { opacity: 1; } to { opacity: 0; transform: translateX(50px); } }

.visibility-graph { display: flex; align-items: flex-end; gap: 2px; height: 40px; }
.visibility-bar { flex: 1; background: var(--accent); border-radius: 2px 2px 0 0; min-width: 4px; transition: height 0.3s; }
.group-tag { padding: 2px 8px; border-radius: 4px; font-size: 11px; font-weight: 600; background: rgba(108,92,231,0.15); color: #a78bfa; }

.pagination { display: flex; align-items: center; justify-content: space-between; padding: 16px 24px; border-top: 1px solid var(--border); }
.pagination-info { font-size: 13px; color: var(--text-muted); }
.pagination-btns { display: flex; gap: 4px; }
.page-btn { width: 36px; height: 36px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: transparent; color: var(--text-secondary); font-size: 13px; font-weight: 500; cursor: pointer; display: flex; align-items: center; justify-content: center; transition: all 0.2s; }
.page-btn:hover { border-color: var(--accent); color: var(--text-primary); }
.page-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.date-range { display: flex; align-items: center; gap: 8px; padding: 8px 14px; background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 13px; color: var(--text-secondary); cursor: pointer; }
.date-range:hover { border-color: var(--accent); }
.date-range svg { width: 16px; height: 16px; }

.sparkline { width: 80px; height: 30px; }
.checkbox { width: 18px; height: 18px; border-radius: 4px; border: 2px solid var(--border); background: transparent; cursor: pointer; display: flex; align-items: center; justify-content: center; transition: all 0.2s; flex-shrink: 0; }
.checkbox.checked { background: var(--accent); border-color: var(--accent); }
.checkbox.checked::after { content: '✓'; color: #fff; font-size: 12px; font-weight: 700; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.status-dot.active { background: var(--green); box-shadow: 0 0 8px var(--green); }
.status-dot.paused { background: var(--yellow); }
.fade-in { animation: fadeIn 0.4s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

.dist-row { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.dist-label { width: 80px; font-size: 12px; color: var(--text-secondary); font-weight: 500; }
.dist-bar-wrap { flex: 1; height: 8px; background: rgba(128,128,128,0.2); border-radius: 4px; overflow: hidden; }
.dist-bar { height: 100%; border-radius: 4px; transition: width 0.6s ease; }
.dist-value { width: 40px; text-align: right; font-size: 13px; font-weight: 700; }

@media (max-width: 1200px) { .stats-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .main { margin-left: 0; }
    .stats-grid { grid-template-columns: 1fr; }
    .grid-2, .grid-3-1 { grid-template-columns: 1fr; }
    .content { padding: 16px; }
    .header { padding: 0 16px; }
}