/* AIVISOR — GEO Tracking Tool Styles */

:root {
    --color-primary: #4f46e5;
    --color-primary-hover: #4338ca;
    --color-primary-light: #eef2ff;
    --color-success: #16a34a;
    --color-warning: #d97706;
    --color-danger: #dc2626;
    --color-info: #0891b2;
    --color-bg: #f4f5f9;
    --color-surface: #ffffff;
    --color-text: #1a1a2e;
    --color-text-muted: #6b7280;
    --color-border: #e5e7eb;
    --sidebar-width: 260px;
    --topbar-height: 60px;
    --radius: 10px;
    --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
    --shadow-lg: 0 10px 25px rgba(0,0,0,.1);
    --transition: .2s ease;
}

[data-theme="dark"] {
    --color-bg: #0f1117;
    --color-surface: #1a1d27;
    --color-text: #e5e7eb;
    --color-text-muted: #9ca3af;
    --color-border: #2d3142;
    --color-primary-light: #1e1b4b;
    --shadow: 0 1px 3px rgba(0,0,0,.3);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
    line-height: 1.6;
    font-size: 14px;
}

a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Layout */
.app-layout { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-width);
    background: var(--color-surface);
    border-right: 1px solid var(--color-border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 100;
    transition: transform var(--transition);
}

.sidebar-header {
    padding: 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--color-border);
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    font-size: 18px;
    color: var(--color-primary);
    text-decoration: none;
}
.logo svg { width: 24px; height: 24px; }

.sidebar-close { display: none; background: none; border: none; cursor: pointer; color: var(--color-text); }

.sidebar-nav { flex: 1; padding: 12px; overflow-y: auto; }

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    border-radius: 8px;
    color: var(--color-text-muted);
    text-decoration: none;
    font-weight: 500;
    transition: all var(--transition);
    margin-bottom: 2px;
}
.nav-item svg { width: 18px; height: 18px; }
.nav-item:hover { background: var(--color-primary-light); color: var(--color-primary); text-decoration: none; }
.nav-item.active { background: var(--color-primary-light); color: var(--color-primary); }

.sidebar-footer {
    padding: 12px;
    border-top: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    gap: 8px;
}

.theme-toggle {
    background: none; border: 1px solid var(--color-border);
    border-radius: 8px; padding: 8px; cursor: pointer;
    color: var(--color-text-muted); display: flex;
}
.theme-toggle svg { width: 18px; height: 18px; }

.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    min-height: 100vh;
}

.topbar {
    height: var(--topbar-height);
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    padding: 0 24px;
    gap: 16px;
    position: sticky;
    top: 0;
    z-index: 50;
}

.menu-toggle {
    display: none;
    background: none; border: none; cursor: pointer;
    color: var(--color-text); padding: 8px;
}
.menu-toggle svg { width: 22px; height: 22px; }

.topbar-selectors { flex: 1; }
.selector-form { display: flex; gap: 8px; flex-wrap: wrap; }
.selector-select {
    padding: 6px 12px;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    background: var(--color-bg);
    color: var(--color-text);
    font-size: 13px;
    min-width: 160px;
}

.topbar-user { font-weight: 500; font-size: 13px; color: var(--color-text-muted); }

.page-content { padding: 24px; max-width: 1400px; }

/* Page header */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 24px;
    flex-wrap: wrap;
    gap: 16px;
}
.page-header h1 { font-size: 24px; font-weight: 700; }
.page-subtitle { color: var(--color-text-muted); font-size: 14px; margin-top: 4px; }
.page-actions { display: flex; gap: 8px; align-items: center; }

/* Cards */
.card {
    background: var(--color-surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: 1px solid var(--color-border);
    overflow: hidden;
}
.card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--color-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.card-header h3 { font-size: 16px; font-weight: 600; }
.card-body { padding: 20px; }
.card-footer {
    padding: 12px 20px;
    border-top: 1px solid var(--color-border);
    display: flex;
    gap: 8px;
}
.form-card { padding: 24px; }

/* Dashboard */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    gap: 20px;
}
.dashboard-card .card-body { padding: 20px; }
.card-title { font-size: 16px; font-weight: 600; }
.card-subtitle { font-size: 12px; color: var(--color-text-muted); }

.metric-row { margin-bottom: 16px; }
.metric-label { font-size: 12px; color: var(--color-text-muted); text-transform: uppercase; letter-spacing: .5px; }
.metric-value { font-size: 28px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.metric-hint { font-size: 12px; color: var(--color-text-muted); }

.delta { font-size: 14px; font-weight: 600; }
.delta-up { color: var(--color-success); }
.delta-down { color: var(--color-danger); }

.stats-grid { display: grid; grid-template-columns: 1fr; gap: 12px; }
.stat-item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 12px;
    background: var(--color-bg);
    border-radius: 8px;
}
.stat-item svg { width: 18px; height: 18px; color: var(--color-primary); margin-top: 2px; flex-shrink: 0; }
.stat-label { font-size: 11px; color: var(--color-text-muted); display: block; }
.stat-value { font-size: 14px; font-weight: 600; display: block; }
.stat-badge { font-size: 11px; margin-top: 2px; display: inline-block; }
.stat-warning { background: #fef3c7; }
[data-theme="dark"] .stat-warning { background: #422006; }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    border: none;
    cursor: pointer;
    text-decoration: none;
    transition: all var(--transition);
    white-space: nowrap;
}
.btn svg { width: 16px; height: 16px; }
.btn-primary { background: var(--color-primary); color: white; }
.btn-primary:hover { background: var(--color-primary-hover); color: white; text-decoration: none; }
.btn-success { background: var(--color-success); color: white; }
.btn-success:hover { background: #15803d; color: white; }
.btn-danger { background: var(--color-danger); color: white; }
.btn-danger:hover { background: #b91c1c; color: white; }
.btn-outline { background: transparent; border: 1px solid var(--color-border); color: var(--color-text); }
.btn-outline:hover { background: var(--color-bg); text-decoration: none; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-sm svg { width: 14px; height: 14px; }
.btn-block { width: 100%; justify-content: center; }

/* Badges */
.badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .3px;
}
.badge-success { background: #dcfce7; color: #166534; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-danger { background: #fee2e2; color: #991b1b; }
.badge-info { background: #e0f2fe; color: #075985; }
.badge-muted { background: #f3f4f6; color: #6b7280; }
[data-theme="dark"] .badge-success { background: #14532d; color: #86efac; }
[data-theme="dark"] .badge-warning { background: #422006; color: #fcd34d; }

.visibility-badge {
    background: var(--color-primary-light);
    color: var(--color-primary);
    padding: 4px 12px;
    border-radius: 20px;
    font-weight: 700;
    font-size: 14px;
}

/* Tables */
.table-responsive { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
    text-align: left;
    padding: 12px 16px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: var(--color-text-muted);
    border-bottom: 2px solid var(--color-border);
    white-space: nowrap;
}
.data-table td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--color-border);
    vertical-align: middle;
}
.data-table tr:hover { background: var(--color-bg); }
.actions { display: flex; gap: 6px; align-items: center; }
.inline-form { display: inline; }
.row-pending { background: #fffbeb !important; }
[data-theme="dark"] .row-pending { background: #422006 !important; }

/* Forms */
.form-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
}
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group.full-width { grid-column: 1 / -1; }
.form-group label { font-size: 13px; font-weight: 500; }
.form-group input, .form-group select, .form-group textarea {
    padding: 10px 12px;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    background: var(--color-bg);
    color: var(--color-text);
    font-size: 14px;
    font-family: inherit;
    transition: border-color var(--transition);
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(79,70,229,.15);
}
.form-hint { font-size: 12px; color: var(--color-text-muted); }
.checkbox-label { display: flex; align-items: center; gap: 8px; cursor: pointer; font-size: 14px; }
.form-actions { display: flex; gap: 12px; justify-content: flex-end; margin-top: 24px; padding-top: 20px; border-top: 1px solid var(--color-border); }

/* Filters */
.filters-bar { margin-bottom: 20px; }
.filters-form { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.filters-form select, .filters-form input[type="month"] {
    padding: 8px 12px;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    background: var(--color-surface);
    color: var(--color-text);
    font-size: 13px;
}

/* Alerts */
.alert {
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 14px;
}
.alert svg { width: 18px; height: 18px; flex-shrink: 0; }
.alert-warning { background: #fef3c7; color: #92400e; border: 1px solid #fcd34d; }
.alert-error { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }
[data-theme="dark"] .alert-warning { background: #422006; color: #fcd34d; }

.info-box {
    display: flex;
    gap: 12px;
    padding: 14px;
    background: var(--color-primary-light);
    border-radius: 8px;
    margin-top: 16px;
    font-size: 13px;
}
.info-box svg { width: 18px; height: 18px; color: var(--color-primary); flex-shrink: 0; }

/* Empty state */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--color-text-muted);
}
.empty-state svg { width: 48px; height: 48px; margin-bottom: 16px; opacity: .5; }
.empty-state h3 { font-size: 18px; color: var(--color-text); margin-bottom: 8px; }
.empty-state p { margin-bottom: 20px; }

/* Toast */
.toast-container { position: fixed; top: 80px; right: 24px; z-index: 9999; display: flex; flex-direction: column; gap: 8px; }
.toast {
    padding: 12px 20px;
    border-radius: 8px;
    box-shadow: var(--shadow-lg);
    font-size: 14px;
    animation: slideIn .3s ease;
    max-width: 360px;
}
.toast-success { background: #dcfce7; color: #166534; border-left: 4px solid var(--color-success); }
.toast-error { background: #fee2e2; color: #991b1b; border-left: 4px solid var(--color-danger); }

@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* Test grid */
.stats-panel {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 12px;
    margin-bottom: 20px;
}
.stat-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 16px;
    text-align: center;
}
.stat-big { font-size: 24px; font-weight: 700; color: var(--color-primary); display: block; }
.stat-detail { font-size: 11px; color: var(--color-text-muted); }

.test-grid-container {
    background: var(--color-surface);
    border-radius: var(--radius);
    border: 1px solid var(--color-border);
    overflow: hidden;
}
.test-grid-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.test-grid { width: 100%; border-collapse: collapse; font-size: 12px; }
.test-grid th {
    background: var(--color-primary);
    color: white;
    padding: 10px 8px;
    text-align: center;
    font-size: 11px;
    white-space: nowrap;
    position: sticky;
    top: 0;
    z-index: 2;
}
.test-grid .sticky-col {
    position: sticky;
    left: 0;
    z-index: 3;
    background: var(--color-surface);
    min-width: 200px;
    max-width: 280px;
}
.test-grid th.sticky-col { background: #3730a3; z-index: 4; }
.query-cell { padding: 8px 12px !important; vertical-align: top; border-right: 2px solid var(--color-border); }
.query-text { font-weight: 500; display: block; font-size: 12px; }
.query-cat { font-size: 10px; color: var(--color-text-muted); }
.platform-cell { padding: 6px !important; vertical-align: top; min-width: 160px; border-bottom: 1px solid var(--color-border); }
.cell-inputs { display: flex; flex-direction: column; gap: 4px; }
.appeared-check {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 4px;
    background: var(--color-bg);
}
.appeared-check input { width: 16px; height: 16px; cursor: pointer; }
.appeared-check:has(input:checked) { background: #dcfce7; color: #166534; }
.cell-inputs input[type="text"] {
    padding: 5px 8px;
    border: 1px solid var(--color-border);
    border-radius: 4px;
    font-size: 11px;
    background: var(--color-bg);
    color: var(--color-text);
    width: 100%;
}
.cell-inputs input:focus { outline: none; border-color: var(--color-primary); }

.save-status { font-size: 12px; color: var(--color-text-muted); }
.save-status.saving { color: var(--color-warning); }
.save-status.saved { color: var(--color-success); }

.competitors-list { display: flex; flex-direction: column; gap: 8px; }
.competitor-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 12px;
    background: var(--color-bg);
    border-radius: 6px;
}
.competitor-item .rank { font-weight: 700; color: var(--color-primary); min-width: 30px; }
.competitor-item .name { flex: 1; font-weight: 500; }
.competitor-item .mentions { font-size: 12px; color: var(--color-text-muted); }

/* Analytics */
.analytics-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 20px;
}
.chart-card .card-body { padding: 20px; min-height: 350px; }

/* Login */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
}
.login-container { width: 100%; max-width: 420px; padding: 20px; }
.login-card {
    background: white;
    border-radius: 16px;
    padding: 40px 32px;
    box-shadow: var(--shadow-lg);
}
.login-header { text-align: center; margin-bottom: 32px; }
.logo-large {
    width: 56px; height: 56px;
    background: #eef2ff;
    border-radius: 14px;
    display: flex; align-items: center; justify-content: center;
    margin: 0 auto 16px;
    color: #4f46e5;
}
.logo-large svg { width: 28px; height: 28px; }
.login-header h1 { font-size: 28px; color: #1a1a2e; }
.subtitle { color: #6b7280; font-size: 14px; margin-top: 4px; }
.login-form .form-group { margin-bottom: 16px; }
.login-form label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 6px; color: #374151; }
.login-form input {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font-size: 14px;
}
.login-form input:focus { outline: none; border-color: #4f46e5; box-shadow: 0 0 0 3px rgba(79,70,229,.15); }
.login-footer { text-align: center; color: rgba(255,255,255,.7); font-size: 12px; margin-top: 20px; }

/* Utilities */
.text-muted { color: var(--color-text-muted); }
.text-warning { color: var(--color-warning); }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.mb-4 { margin-bottom: 16px; }

/* Sidebar overlay */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.5);
    z-index: 99;
}

/* Responsive */
@media (max-width: 1024px) {
    .form-grid { grid-template-columns: 1fr; }
    .analytics-grid { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .sidebar-close { display: block; }
    .sidebar-overlay.active { display: block; }
    .main-content { margin-left: 0; }
    .menu-toggle { display: flex; }
    .page-content { padding: 16px; }
    .page-header { flex-direction: column; }
    .dashboard-grid { grid-template-columns: 1fr; }
    .topbar-selectors { order: 3; width: 100%; }
    .selector-form { width: 100%; }
    .selector-select { flex: 1; min-width: 0; }
    .stats-panel { grid-template-columns: repeat(2, 1fr); }
    .toast-container { left: 16px; right: 16px; }
}

@media (min-width: 1024px) {
    .analytics-grid { grid-template-columns: 1fr 1fr; }
}

@media print {
    .sidebar, .topbar, .report-actions, .page-actions { display: none !important; }
    .main-content { margin-left: 0; }
}
