/* =============================================
   RankTracker V1 — Main Stylesheet
   Modern, light SaaS design
   ============================================= */

:root {
    --primary: #2563eb;
    --primary-light: #3b82f6;
    --primary-dark: #1d4ed8;
    --primary-bg: #eff6ff;
    --success: #16a34a;
    --success-bg: #f0fdf4;
    --danger: #dc2626;
    --danger-bg: #fef2f2;
    --warning: #d97706;
    --warning-bg: #fffbeb;
    --info: #0891b2;
    --info-bg: #ecfeff;
    --gray-50: #f8fafc;
    --gray-100: #f1f5f9;
    --gray-200: #e2e8f0;
    --gray-300: #cbd5e1;
    --gray-400: #94a3b8;
    --gray-500: #64748b;
    --gray-600: #475569;
    --gray-700: #334155;
    --gray-800: #1e293b;
    --gray-900: #0f172a;
    --sidebar-width: 250px;
    --header-height: 60px;
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --radius: 8px;
    --radius-sm: 6px;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -2px rgba(0,0,0,0.1);
}

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

body {
    font-family: var(--font-sans);
    background: var(--gray-50);
    color: var(--gray-800);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* ---- Sidebar ---- */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: #fff;
    border-right: 1px solid var(--gray-200);
    z-index: 100;
    display: flex;
    flex-direction: column;
    transition: transform 0.2s ease;
}

.sidebar-brand {
    height: var(--header-height);
    display: flex;
    align-items: center;
    padding: 0 20px;
    border-bottom: 1px solid var(--gray-200);
    gap: 10px;
    text-decoration: none;
    color: var(--gray-900);
}

.sidebar-brand .brand-icon {
    width: 32px;
    height: 32px;
    background: var(--primary);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 700;
    font-size: 14px;
}

.sidebar-brand .brand-text {
    font-weight: 700;
    font-size: 16px;
    letter-spacing: -0.3px;
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 16px 12px;
}

.nav-section {
    margin-bottom: 24px;
}

.nav-section-title {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--gray-400);
    padding: 0 8px;
    margin-bottom: 8px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border-radius: var(--radius-sm);
    color: var(--gray-600);
    text-decoration: none;
    font-size: 13.5px;
    font-weight: 500;
    transition: all 0.15s ease;
    margin-bottom: 2px;
}

.nav-item:hover {
    background: var(--gray-100);
    color: var(--gray-800);
}

.nav-item.active {
    background: var(--primary-bg);
    color: var(--primary);
}

.nav-item i {
    font-size: 16px;
    width: 20px;
    text-align: center;
}

.sidebar-footer {
    padding: 12px;
    border-top: 1px solid var(--gray-200);
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    border-radius: var(--radius-sm);
    text-decoration: none;
    color: var(--gray-700);
    transition: background 0.15s ease;
}

.sidebar-user:hover {
    background: var(--gray-100);
}

.user-avatar {
    width: 32px;
    height: 32px;
    background: var(--primary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 600;
    font-size: 12px;
}

.user-info { flex: 1; min-width: 0; }
.user-info .name { font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-info .role { font-size: 11px; color: var(--gray-400); }

/* ---- Main Content ---- */
.main-content {
    margin-left: var(--sidebar-width);
    min-height: 100vh;
}

.top-bar {
    height: var(--header-height);
    background: #fff;
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 28px;
    position: sticky;
    top: 0;
    z-index: 50;
}

.top-bar h1 {
    font-size: 18px;
    font-weight: 700;
    color: var(--gray-900);
    letter-spacing: -0.3px;
}

.top-bar-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.content-area {
    padding: 28px;
}

/* ---- Cards ---- */
.card {
    background: #fff;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}

.card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--gray-100);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-header h3 {
    font-size: 14px;
    font-weight: 600;
    color: var(--gray-800);
}

.card-body {
    padding: 20px;
}

/* ---- Stat Cards ---- */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: #fff;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    padding: 18px 20px;
    box-shadow: var(--shadow-sm);
    transition: box-shadow 0.15s;
}

.stat-card:hover {
    box-shadow: var(--shadow-md);
}

.stat-card .stat-label {
    font-size: 12px;
    font-weight: 500;
    color: var(--gray-500);
    text-transform: uppercase;
    letter-spacing: 0.3px;
    margin-bottom: 6px;
}

.stat-card .stat-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--gray-900);
    letter-spacing: -0.5px;
    line-height: 1.2;
}

.stat-card .stat-sub {
    font-size: 12px;
    color: var(--gray-500);
    margin-top: 4px;
}

.stat-card.stat-success { border-left: 3px solid var(--success); }
.stat-card.stat-danger { border-left: 3px solid var(--danger); }
.stat-card.stat-primary { border-left: 3px solid var(--primary); }
.stat-card.stat-warning { border-left: 3px solid var(--warning); }
.stat-card.stat-info { border-left: 3px solid var(--info); }

/* ---- Tables ---- */
.table-wrapper {
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th {
    background: var(--gray-50);
    padding: 10px 14px;
    text-align: left;
    font-size: 11.5px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: var(--gray-500);
    border-bottom: 2px solid var(--gray-200);
    white-space: nowrap;
}

.data-table th a {
    color: var(--gray-500);
    text-decoration: none;
}

.data-table th a:hover { color: var(--primary); }

.data-table td {
    padding: 11px 14px;
    border-bottom: 1px solid var(--gray-100);
    font-size: 13.5px;
    vertical-align: middle;
}

.data-table tr:hover {
    background: var(--gray-50);
}

.data-table .keyword-cell {
    font-weight: 500;
    color: var(--gray-800);
}

.data-table .keyword-cell a {
    color: var(--gray-800);
    text-decoration: none;
}

.data-table .keyword-cell a:hover {
    color: var(--primary);
}

/* ---- Badges ---- */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
    line-height: 1.5;
}

.badge.bg-success { background: var(--success-bg); color: var(--success); }
.badge.bg-danger { background: var(--danger-bg); color: var(--danger); }
.badge.bg-primary { background: var(--primary-bg); color: var(--primary); }
.badge.bg-warning { background: var(--warning-bg); color: var(--warning); }
.badge.bg-info { background: var(--info-bg); color: var(--info); }
.badge.bg-secondary { background: var(--gray-100); color: var(--gray-500); }

.text-success { color: var(--success) !important; }
.text-danger { color: var(--danger) !important; }
.text-muted { color: var(--gray-400) !important; }

/* ---- Buttons ---- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 500;
    border: 1px solid transparent;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.15s ease;
    font-family: var(--font-sans);
    line-height: 1.5;
}

.btn-primary {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}
.btn-primary:hover { background: var(--primary-dark); color: #fff; }

.btn-outline {
    background: #fff;
    color: var(--gray-700);
    border-color: var(--gray-300);
}
.btn-outline:hover { background: var(--gray-50); border-color: var(--gray-400); color: var(--gray-700); }

.btn-danger {
    background: var(--danger);
    color: #fff;
    border-color: var(--danger);
}
.btn-danger:hover { background: #b91c1c; color: #fff; }

.btn-success {
    background: var(--success);
    color: #fff;
    border-color: var(--success);
}

.btn-sm {
    padding: 5px 10px;
    font-size: 12px;
}

.btn-xs {
    padding: 3px 8px;
    font-size: 11px;
}

/* ---- Forms ---- */
.form-group {
    margin-bottom: 16px;
}

.form-label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--gray-700);
    margin-bottom: 5px;
}

.form-control {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-family: var(--font-sans);
    color: var(--gray-800);
    background: #fff;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

select.form-control {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2364748b' d='M6 8.825a.5.5 0 01-.354-.146l-3.5-3.5a.5.5 0 01.708-.708L6 7.618l3.146-3.147a.5.5 0 01.708.708l-3.5 3.5A.5.5 0 016 8.825z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 32px;
}

textarea.form-control { resize: vertical; min-height: 80px; }

/* ---- Alerts ---- */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.alert-success { background: var(--success-bg); color: var(--success); border: 1px solid #bbf7d0; }
.alert-danger { background: var(--danger-bg); color: var(--danger); border: 1px solid #fecaca; }
.alert-warning { background: var(--warning-bg); color: var(--warning); border: 1px solid #fde68a; }
.alert-info { background: var(--info-bg); color: var(--info); border: 1px solid #a5f3fc; }

/* ---- Tag Pills ---- */
.tag-pill {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 500;
    margin-right: 4px;
    margin-bottom: 2px;
}

/* ---- Filter Bar ---- */
.filter-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 16px;
}

.filter-bar .form-control {
    width: auto;
    min-width: 140px;
    padding: 7px 10px;
    font-size: 13px;
}

.filter-bar input[type="search"] {
    min-width: 200px;
}

/* ---- Pagination ---- */
.pagination {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-top: 16px;
    justify-content: center;
}

.pagination a, .pagination span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 34px;
    height: 34px;
    padding: 0 8px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    text-decoration: none;
    color: var(--gray-600);
    border: 1px solid var(--gray-200);
    background: #fff;
    transition: all 0.15s;
}

.pagination a:hover { background: var(--gray-100); }
.pagination span.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ---- Modals ---- */
.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.4);
    z-index: 200;
    display: none;
    align-items: center;
    justify-content: center;
}

.modal-backdrop.show { display: flex; }

.modal-box {
    background: #fff;
    border-radius: var(--radius);
    width: 90%;
    max-width: 500px;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0,0,0,0.15);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--gray-200);
}

.modal-header h3 { font-size: 16px; font-weight: 600; }

.modal-close {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    color: var(--gray-400);
    padding: 4px;
}

.modal-body { padding: 20px; }
.modal-footer { padding: 12px 20px; border-top: 1px solid var(--gray-100); text-align: right; }

/* ---- Auth Pages ---- */
.auth-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #eff6ff 0%, #f8fafc 50%, #ecfeff 100%);
    padding: 20px;
}

.auth-card {
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 4px 24px rgba(0,0,0,0.08);
    width: 100%;
    max-width: 420px;
    padding: 40px 36px;
}

.auth-card .brand {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 28px;
    justify-content: center;
}

.auth-card .brand .brand-icon {
    width: 36px;
    height: 36px;
    background: var(--primary);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 700;
    font-size: 16px;
}

.auth-card .brand .brand-text {
    font-size: 20px;
    font-weight: 700;
    color: var(--gray-900);
}

.auth-card h2 {
    text-align: center;
    font-size: 20px;
    margin-bottom: 6px;
    color: var(--gray-900);
}

.auth-card .subtitle {
    text-align: center;
    color: var(--gray-500);
    font-size: 14px;
    margin-bottom: 24px;
}

.auth-card .form-control {
    padding: 11px 14px;
}

.auth-card .btn-primary {
    width: 100%;
    padding: 11px;
    font-size: 14px;
    justify-content: center;
    margin-top: 8px;
}

.auth-card .auth-footer {
    text-align: center;
    margin-top: 20px;
    font-size: 13px;
    color: var(--gray-500);
}

.auth-card .auth-footer a {
    color: var(--primary);
    text-decoration: none;
    font-weight: 500;
}

/* ---- Mobile ---- */
.mobile-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 22px;
    cursor: pointer;
    padding: 4px;
    color: var(--gray-700);
}

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }
    .sidebar.open {
        transform: translateX(0);
    }
    .main-content {
        margin-left: 0;
    }
    .mobile-toggle {
        display: block;
    }
    .stat-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    .filter-bar {
        flex-direction: column;
        align-items: stretch;
    }
    .filter-bar .form-control {
        width: 100%;
    }
    .content-area {
        padding: 16px;
    }
}

/* ---- Utilities ---- */
.fw-semibold { font-weight: 600; }
.text-sm { font-size: 13px; }
.text-xs { font-size: 12px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 16px; }
.mt-4 { margin-top: 24px; }
.mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 16px; }
.mb-4 { margin-bottom: 24px; }
.d-flex { display: flex; }
.align-center { align-items: center; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.flex-1 { flex: 1; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.w-100 { width: 100%; }
.truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 200px; }
.d-none { display: none; }

/* ---- Mover rows ---- */
.mover-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid var(--gray-100);
}

.mover-row:last-child { border-bottom: none; }
.mover-row .kw { font-weight: 500; font-size: 13px; }
.mover-row .project-label { font-size: 11px; color: var(--gray-400); }

/* ---- Empty State ---- */
.empty-state {
    text-align: center;
    padding: 48px 20px;
    color: var(--gray-400);
}

.empty-state i {
    font-size: 48px;
    margin-bottom: 12px;
    display: block;
}

.empty-state p {
    font-size: 15px;
    margin-bottom: 16px;
}

/* ---- Chart Container ---- */
.chart-container {
    position: relative;
    height: 300px;
    width: 100%;
}
