/* ══════════════════════════════════════════════════════════
   RankTrack App — Stylesheet
   ══════════════════════════════════════════════════════════ */

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

:root {
    --color-primary: #0D9488;
    --color-primary-dark: #0F766E;
    --color-primary-light: #14B8A6;
    --color-primary-50: #F0FDFA;
    --color-primary-100: #CCFBF1;
    --color-accent: #F97316;
    --color-accent-dark: #EA580C;
    --color-success: #16A34A;
    --color-success-light: #DCFCE7;
    --color-warning: #D97706;
    --color-warning-light: #FEF3C7;
    --color-error: #DC2626;
    --color-error-light: #FEE2E2;
    --color-text: #1E293B;
    --color-text-light: #64748B;
    --color-text-muted: #94A3B8;
    --color-bg: #F8FAFC;
    --color-bg-white: #FFFFFF;
    --color-bg-dark: #0F172A;
    --color-border: #E2E8F0;
    --color-border-light: #F1F5F9;
    --font-family: 'Inter', system-ui, -apple-system, sans-serif;
    --sidebar-width: 260px;
    --header-height: 64px;
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.07), 0 2px 4px -2px rgba(0,0,0,0.05);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.08), 0 4px 6px -4px rgba(0,0,0,0.04);
    --transition: 0.2s ease;
}

html { -webkit-text-size-adjust: 100%; }
body { font-family: var(--font-family); font-size: 14px; line-height: 1.5; color: var(--color-text); background: var(--color-bg); -webkit-font-smoothing: antialiased; }
a { color: var(--color-primary); text-decoration: none; transition: color var(--transition); }
a:hover { color: var(--color-primary-dark); }
h1, h2, h3, h4 { line-height: 1.3; font-weight: 600; }
img { max-width: 100%; display: block; }

/* ── Sidebar ──────────────────────────────────────────── */
.sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; width: var(--sidebar-width);
    background: var(--color-bg-dark); color: #CBD5E1; display: flex; flex-direction: column;
    z-index: 50; transition: transform 0.3s ease;
}
.sidebar-header { padding: 20px 20px 16px; border-bottom: 1px solid #1E293B; }
.sidebar-logo { display: flex; align-items: center; gap: 10px; color: #fff; font-size: 18px; font-weight: 700; }
.sidebar-nav { flex: 1; padding: 12px 12px; overflow-y: auto; }
.sidebar-link {
    display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: var(--radius-md);
    color: #94A3B8; font-size: 14px; font-weight: 500; transition: all var(--transition); margin-bottom: 2px;
}
.sidebar-link:hover { color: #fff; background: #1E293B; }
.sidebar-link.active { color: #fff; background: var(--color-primary); }
.sidebar-link svg { flex-shrink: 0; }
.sidebar-divider { height: 1px; background: #1E293B; margin: 12px 0; }
.sidebar-label { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: #475569; padding: 8px 12px; font-weight: 600; }
.sidebar-footer { padding: 16px; border-top: 1px solid #1E293B; }
.sidebar-user { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.sidebar-user-avatar {
    width: 36px; height: 36px; border-radius: 50%; background: var(--color-primary);
    display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 600; font-size: 14px; flex-shrink: 0;
}
.sidebar-user-name { font-size: 13px; font-weight: 600; color: #E2E8F0; }
.sidebar-user-plan { font-size: 12px; color: #64748B; }
.sidebar-logout { font-size: 13px; }

/* ── App Main ─────────────────────────────────────────── */
.app-body { background: var(--color-bg); }
.app-main { margin-left: var(--sidebar-width); min-height: 100vh; }
.app-header {
    position: sticky; top: 0; height: var(--header-height); background: var(--color-bg-white);
    border-bottom: 1px solid var(--color-border); display: flex; align-items: center;
    padding: 0 32px; gap: 16px; z-index: 40;
}
.app-header-title { font-size: 18px; font-weight: 700; flex: 1; }
.app-header-actions { display: flex; align-items: center; gap: 8px; }
.app-content { padding: 32px; max-width: 1200px; }
.sidebar-toggle { display: none; background: none; border: none; cursor: pointer; padding: 8px; }
.sidebar-toggle span { display: block; width: 20px; height: 2px; background: var(--color-text); margin: 4px 0; border-radius: 2px; }

/* ── Auth Layout ──────────────────────────────────────── */
.auth-body { background: var(--color-bg); display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 24px; }
.auth-container { width: 100%; max-width: 440px; }
.auth-card { background: var(--color-bg-white); border: 1px solid var(--color-border); border-radius: var(--radius-xl); padding: 40px; box-shadow: var(--shadow-md); }
.auth-logo { text-align: center; margin-bottom: 28px; }
.auth-logo h1 { font-size: 22px; margin-top: 16px; }
.auth-logo p { color: var(--color-text-light); font-size: 14px; margin-top: 4px; }
.auth-footer-text { text-align: center; margin-top: 24px; font-size: 13px; color: var(--color-text-muted); }
.auth-links { display: flex; justify-content: space-between; align-items: center; margin-top: 20px; font-size: 14px; }

/* ── Buttons ──────────────────────────────────────────── */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 10px 20px; border-radius: var(--radius-md); font-size: 14px; font-weight: 600;
    border: none; cursor: pointer; transition: all var(--transition); text-decoration: none; line-height: 1.4;
    font-family: var(--font-family);
}
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-primary { background: var(--color-primary); color: #fff; }
.btn-primary:hover { background: var(--color-primary-dark); color: #fff; }
.btn-accent { background: var(--color-accent); color: #fff; }
.btn-accent:hover { background: var(--color-accent-dark); color: #fff; }
.btn-ghost { background: transparent; color: var(--color-text); border: 1px solid var(--color-border); }
.btn-ghost:hover { background: var(--color-bg); border-color: var(--color-text-muted); }
.btn-danger { background: var(--color-error); color: #fff; }
.btn-danger:hover { background: #B91C1C; color: #fff; }
.btn-sm { padding: 6px 14px; font-size: 13px; }
.btn-lg { padding: 14px 28px; font-size: 16px; }
.btn-block { width: 100%; }

/* ── Forms ────────────────────────────────────────────── */
.form-group { margin-bottom: 18px; }
.form-group label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 5px; color: var(--color-text); }
.form-control {
    width: 100%; padding: 10px 14px; border: 1px solid var(--color-border); border-radius: var(--radius-md);
    font-size: 14px; font-family: var(--font-family); transition: border-color var(--transition); background: var(--color-bg-white);
    color: var(--color-text);
}
.form-control:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 3px rgba(13,148,136,0.1); }
.form-control::placeholder { color: var(--color-text-muted); }
textarea.form-control { min-height: 100px; resize: vertical; }
select.form-control { appearance: auto; }
.form-hint { font-size: 12px; color: var(--color-text-muted); margin-top: 4px; }
.form-error-msg { color: var(--color-error); font-size: 12px; margin-top: 4px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

/* ── Cards ────────────────────────────────────────────── */
.card { background: var(--color-bg-white); border: 1px solid var(--color-border); border-radius: var(--radius-lg); padding: 24px; }
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.card-header h3 { font-size: 16px; }
.card-grid { display: grid; gap: 16px; }
.card-grid-2 { grid-template-columns: repeat(2, 1fr); }
.card-grid-3 { grid-template-columns: repeat(3, 1fr); }
.card-grid-4 { grid-template-columns: repeat(4, 1fr); }

/* ── Stat Cards ───────────────────────────────────────── */
.stat-card { text-align: center; }
.stat-card .stat-value { font-size: 28px; font-weight: 700; color: var(--color-text); line-height: 1.2; }
.stat-card .stat-label { font-size: 13px; color: var(--color-text-muted); margin-top: 4px; }
.stat-card .stat-change { font-size: 12px; font-weight: 600; margin-top: 2px; }

/* ── Tables ───────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table.data-table { width: 100%; border-collapse: collapse; }
table.data-table th {
    text-align: left; padding: 10px 14px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px;
    color: var(--color-text-muted); font-weight: 600; border-bottom: 2px solid var(--color-border); background: var(--color-bg);
}
table.data-table td { padding: 12px 14px; border-bottom: 1px solid var(--color-border-light); font-size: 14px; }
table.data-table tr:hover td { background: var(--color-bg); }
table.data-table .text-center { text-align: center; }
table.data-table .text-right { text-align: right; }

/* ── Rank badges ──────────────────────────────────────── */
.rank-badge { display: inline-flex; align-items: center; justify-content: center; min-width: 32px; padding: 2px 8px; border-radius: 20px; font-size: 13px; font-weight: 700; }
.rank-top3 { background: #FEF3C7; color: #92400E; }
.rank-top10 { background: var(--color-success-light); color: #166534; }
.rank-top20 { background: var(--color-primary-50); color: var(--color-primary-dark); }
.rank-other { background: var(--color-bg); color: var(--color-text-light); }
.rank-none { background: var(--color-error-light); color: #991B1B; }
.rank-up { color: var(--color-success); font-weight: 600; font-size: 13px; }
.rank-down { color: var(--color-error); font-weight: 600; font-size: 13px; }
.rank-unchanged { color: var(--color-text-muted); }

/* ── Alerts ───────────────────────────────────────────── */
.alert { padding: 12px 18px; border-radius: var(--radius-md); margin-bottom: 20px; font-size: 14px; line-height: 1.5; }
.alert-success { background: var(--color-success-light); color: #166534; border: 1px solid #BBF7D0; }
.alert-error { background: var(--color-error-light); color: #991B1B; border: 1px solid #FECACA; }
.alert-warning { background: var(--color-warning-light); color: #92400E; border: 1px solid #FDE68A; }
.alert-info { background: #DBEAFE; color: #1E40AF; border: 1px solid #93C5FD; }

/* ── Project Cards ────────────────────────────────────── */
.project-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 20px; }
.project-card { transition: all var(--transition); }
.project-card:hover { box-shadow: var(--shadow-md); border-color: var(--color-primary-light); }
.project-domain { font-size: 16px; font-weight: 700; margin-bottom: 4px; }
.project-domain a { color: var(--color-text); }
.project-domain a:hover { color: var(--color-primary); }
.project-label { font-size: 13px; color: var(--color-text-muted); margin-bottom: 16px; }
.project-stats { display: flex; gap: 24px; }
.project-stat { text-align: center; }
.project-stat .num { font-size: 20px; font-weight: 700; color: var(--color-text); }
.project-stat .label { font-size: 11px; color: var(--color-text-muted); text-transform: uppercase; letter-spacing: 0.5px; }

/* ── Empty State ──────────────────────────────────────── */
.empty-state { text-align: center; padding: 48px 24px; }
.empty-state-icon { font-size: 48px; margin-bottom: 16px; opacity: 0.4; }
.empty-state h3 { margin-bottom: 8px; color: var(--color-text); }
.empty-state p { color: var(--color-text-light); margin-bottom: 20px; max-width: 400px; margin-left: auto; margin-right: auto; }

/* ── Pagination ───────────────────────────────────────── */
.pagination { display: flex; align-items: center; justify-content: center; gap: 4px; margin-top: 24px; }
.pagination a, .pagination span {
    display: inline-flex; align-items: center; justify-content: center; min-width: 36px; height: 36px;
    padding: 0 8px; border-radius: var(--radius-md); font-size: 13px; font-weight: 500;
    border: 1px solid var(--color-border); color: var(--color-text-light); transition: all var(--transition);
}
.pagination a:hover { background: var(--color-bg); border-color: var(--color-primary); color: var(--color-primary); }
.pagination .active { background: var(--color-primary); border-color: var(--color-primary); color: #fff; }

/* ── Modal ────────────────────────────────────────────── */
.modal-overlay {
    display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 100;
    align-items: center; justify-content: center; padding: 24px;
}
.modal-overlay.open { display: flex; }
.modal { background: var(--color-bg-white); border-radius: var(--radius-xl); padding: 32px; max-width: 480px; width: 100%; box-shadow: var(--shadow-lg); }
.modal h3 { margin-bottom: 12px; }
.modal p { color: var(--color-text-light); margin-bottom: 20px; font-size: 14px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; }

/* ── Toast ────────────────────────────────────────────── */
.toast-container { position: fixed; top: 80px; right: 24px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast {
    background: var(--color-bg-white); border: 1px solid var(--color-border); border-radius: var(--radius-md);
    padding: 14px 20px; box-shadow: var(--shadow-lg); font-size: 14px; min-width: 280px; max-width: 400px;
    animation: slideIn 0.3s ease; display: flex; align-items: center; gap: 10px;
}
.toast-success { border-left: 4px solid var(--color-success); }
.toast-error { border-left: 4px solid var(--color-error); }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ── Spinner ──────────────────────────────────────────── */
.spinner { display: inline-block; width: 16px; height: 16px; border: 2px solid var(--color-border); border-top-color: var(--color-primary); border-radius: 50%; animation: spin 0.6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.spinner-lg { width: 32px; height: 32px; border-width: 3px; }

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

/* ── Toolbar ──────────────────────────────────────────── */
.toolbar { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.toolbar .form-control { max-width: 240px; }

/* ── Keyword bulk add ─────────────────────────────────── */
.keyword-count { font-size: 13px; color: var(--color-text-muted); margin-top: 6px; }
.keyword-count .over-limit { color: var(--color-error); font-weight: 600; }

/* ── Welcome banner ───────────────────────────────────── */
.welcome-banner {
    background: linear-gradient(135deg, var(--color-primary) 0%, #0E7490 100%);
    border-radius: var(--radius-lg); padding: 28px; color: #fff; margin-bottom: 24px;
}
.welcome-banner h2 { color: #fff; font-size: 20px; margin-bottom: 4px; }
.welcome-banner p { color: rgba(255,255,255,0.85); margin: 0; font-size: 14px; }

/* ── Responsive ───────────────────────────────────────── */
@media (max-width: 1024px) {
    .card-grid-4 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .sidebar-toggle { display: block; }
    .app-main { margin-left: 0; }
    .app-content { padding: 20px 16px; }
    .app-header { padding: 0 16px; }
    .card-grid-2, .card-grid-3, .card-grid-4 { grid-template-columns: 1fr; }
    [style*="grid-template-columns:repeat(5"] { grid-template-columns: repeat(2, 1fr) !important; }
    .project-grid { grid-template-columns: 1fr; }
    .form-row { grid-template-columns: 1fr; }
    .toolbar { flex-direction: column; align-items: stretch; }
    .toolbar .form-control { max-width: 100%; }
}
