/* ─── Reset & Base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --blue:        #1565C0;
    --blue-light:  #1976D2;
    --orange:      #F57C00;
    --dark-blue:   #0D47A1;
    --green:       #2E7D32;
    --green-light: #43A047;
    --red:         #C62828;
    --gray-50:     #F8F9FA;
    --gray-100:    #F1F3F4;
    --gray-200:    #E8EAED;
    --gray-400:    #9AA0A6;
    --gray-600:    #5F6368;
    --gray-800:    #3C4043;
    --gray-900:    #202124;
    --white:       #FFFFFF;
    --admin-accent:#6200EA;
    --shadow-sm:   0 1px 3px rgba(0,0,0,.12), 0 1px 2px rgba(0,0,0,.08);
    --shadow-md:   0 4px 12px rgba(0,0,0,.12);
    --shadow-lg:   0 8px 24px rgba(0,0,0,.14);
    --radius:      12px;
    --radius-sm:   8px;
    --transition:  0.2s ease;

    /* Surface tokens — overridden in dark mode */
    --surface-bg:      var(--gray-100);
    --surface-card:    var(--white);
    --surface-border:  var(--gray-200);
    --surface-hover:   var(--gray-50);
    --text-primary:    var(--gray-900);
    --text-secondary:  var(--gray-600);
    --text-muted:      var(--gray-400);
    --input-bg:        var(--white);
    --filter-bar-bg:   var(--white);
    --footer-bg:       var(--white);
}

/* ─── Dark Mode ────────────────────────────────────────────────────────────── */
[data-theme="dark"] {
    --surface-bg:     #0F1117;
    --surface-card:   #1A1D27;
    --surface-border: #2A2D3A;
    --surface-hover:  #22253A;
    --text-primary:   #E8EAED;
    --text-secondary: #9AA0A6;
    --text-muted:     #5F6368;
    --input-bg:       #22253A;
    --filter-bar-bg:  #1A1D27;
    --footer-bg:      #1A1D27;
    --shadow-sm:      0 1px 3px rgba(0,0,0,.4), 0 1px 2px rgba(0,0,0,.3);
    --shadow-md:      0 4px 12px rgba(0,0,0,.4);
    --shadow-lg:      0 8px 24px rgba(0,0,0,.5);
}

html { font-size: 16px; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--surface-bg);
    color: var(--text-primary);
    line-height: 1.5;
    min-height: 100vh;
    transition: background 0.3s ease, color 0.3s ease;
}

/* ─── Theme Toggle Button ──────────────────────────────────────────────────── */
.theme-toggle {
    background: rgba(255,255,255,.1);
    border: 1.5px solid rgba(255,255,255,.2);
    color: #fff;
    border-radius: 8px;
    width: 32px;
    height: 32px;
    font-size: 14px;
    font-family: inherit;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition);
}
.theme-toggle:hover { background: rgba(255,255,255,.22); }
.theme-toggle .toggle-icon { font-size: 14px; line-height: 1; }

/* ─── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: background var(--transition), opacity var(--transition), transform var(--transition);
    white-space: nowrap;
}
.btn:active { transform: scale(.98); }
.btn-primary  { background: var(--blue); color: #fff; }
.btn-primary:hover  { background: var(--blue-light); }
.btn-outline  { background: transparent; color: var(--blue); border: 2px solid var(--blue); }
.btn-outline:hover  { background: var(--blue); color: #fff; }
.btn-outline-light { background: transparent; color: #fff; border: 1.5px solid rgba(255,255,255,.5); }
.btn-outline-light:hover { background: rgba(255,255,255,.15); }
.btn-ghost    { background: transparent; color: var(--text-secondary); }
.btn-ghost:hover    { background: var(--surface-border); }

/* Header-specific buttons — always white on dark header, never theme-affected */
.site-header .btn-outline {
    color: #fff;
    border-color: rgba(255,255,255,.6);
    background: transparent;
}
.site-header .btn-outline:hover {
    background: rgba(255,255,255,.18);
    border-color: #fff;
    color: #fff;
}
.site-header .btn-ghost {
    color: rgba(255,255,255,.85);
    background: transparent;
}
.site-header .btn-ghost:hover {
    background: rgba(255,255,255,.15);
    color: #fff;
}
.btn-full     { width: 100%; justify-content: center; }
.btn-sm       { padding: 7px 14px; font-size: 13px; }
.btn-xs       { padding: 4px 10px; font-size: 12px; }

/* ─── Alerts ───────────────────────────────────────────────────────────────── */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 16px;
}
.alert-error   { background: #FFEBEE; color: var(--red); border-left: 4px solid var(--red); }
.alert-success { background: #E8F5E9; color: var(--green); border-left: 4px solid var(--green); }
.alert-warning { background: #FFF8E1; color: #F57F17; border-left: 4px solid #F9A825; }

/* ─── Forms ────────────────────────────────────────────────────────────────── */
.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 16px;
}
.form-group label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
}
.form-group input[type="text"],
.form-group input[type="password"],
.form-group input[type="url"],
.form-group input[type="date"] {
    padding: 11px 14px;
    border: 1.5px solid var(--surface-border);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 14px;
    color: var(--text-primary);
    background: var(--input-bg);
    transition: border-color var(--transition), box-shadow var(--transition);
    outline: none;
}
.form-group input:focus {
    border-color: var(--blue);
    box-shadow: 0 0 0 3px rgba(21,101,192,.12);
}
.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}
.label-hint {
    font-weight: 400;
    color: var(--gray-400);
    font-size: 12px;
}

/* ─── Login Page ───────────────────────────────────────────────────────────── */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #0D47A1 0%, #1565C0 50%, #1976D2 100%);
    padding: 24px;
}
.login-admin {
    background: linear-gradient(135deg, #4A148C 0%, #6200EA 50%, #7C4DFF 100%);
}
.login-card {
    background: var(--surface-card);
    border-radius: var(--radius);
    padding: 48px 40px;
    width: 100%;
    max-width: 420px;
    box-shadow: var(--shadow-lg);
}
.login-logo {
    text-align: center;
    margin-bottom: 28px;
}
.login-logo .logo-icon {
    font-size: 40px;
    margin-bottom: 8px;
    line-height: 1;
}
.login-logo h1 {
    font-size: 22px;
    font-weight: 800;
    color: var(--text-primary);
}
.login-logo p {
    font-size: 12px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .05em;
    margin-top: 2px;
}
.login-card h2 {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 4px;
    color: var(--text-primary);
}
.login-subtitle {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 24px;
}
.login-footer {
    text-align: center;
    margin-top: 20px;
    font-size: 13px;
}
.login-footer a {
    color: var(--blue);
    text-decoration: none;
    font-weight: 500;
}
.login-footer a:hover { text-decoration: underline; }

/* ─── Site Header ──────────────────────────────────────────────────────────── */
.site-header {
    background: var(--blue);
    color: var(--white);
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow-md);
}
.admin-header { background: #3b0d82; }

.header-inner {
    max-width: 1400px;
    margin: 0 auto;
    padding: 12px 24px;
    display: flex;
    align-items: center;
    gap: 20px;
}
.header-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
}
.brand-icon { font-size: 24px; line-height: 1; }
.brand-name {
    font-size: 14px;
    font-weight: 800;
    color: var(--white);
    line-height: 1.2;
}
.brand-sub {
    font-size: 10px;
    color: rgba(255,255,255,.6);
    text-transform: uppercase;
    letter-spacing: .07em;
    font-weight: 500;
}
.header-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 0 0 auto;
}
.header-divider {
    width: 1px;
    height: 20px;
    background: rgba(255,255,255,.2);
    margin: 0 4px;
}
.admin-badge {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    font-weight: 600;
    color: rgba(255,255,255,.9);
    background: rgba(255,255,255,.12);
    padding: 5px 12px;
    border-radius: 20px;
}
.btn-danger-ghost {
    color: rgba(255,150,150,.9);
    background: transparent;
    border: 1.5px solid rgba(255,150,150,.35);
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 500;
    padding: 5px 12px;
    cursor: pointer;
    text-decoration: none;
    transition: all var(--transition);
    font-family: inherit;
}
.btn-danger-ghost:hover {
    background: rgba(255,100,100,.15);
    border-color: rgba(255,150,150,.6);
    color: #fff;
}
/* ─── Admin Notice Bar ─────────────────────────────────────────────────────── */
.admin-notice-bar {
    background: rgba(49,27,146,.08);
    border-bottom: 1px solid rgba(49,27,146,.15);
    font-size: 13px;
}
[data-theme="dark"] .admin-notice-bar {
    background: rgba(100,60,220,.12);
    border-bottom-color: rgba(100,60,220,.25);
}
.admin-notice-inner {
    max-width: 1400px;
    margin: 0 auto;
    padding: 8px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}
.notice-left {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #4a1a9e;
    font-weight: 500;
}
[data-theme="dark"] .notice-left { color: #a78bfa; }
.notice-icon {
    display: flex;
    align-items: center;
    opacity: .8;
}
.notice-text { font-size: 13px; }
.btn-notice {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    font-size: 12px;
    font-weight: 500;
    background: transparent;
    border: 1.5px solid rgba(74,26,158,.3);
    color: #4a1a9e;
    border-radius: 6px;
    cursor: pointer;
    font-family: inherit;
    transition: all var(--transition);
    white-space: nowrap;
}
.btn-notice:hover {
    background: rgba(74,26,158,.08);
    border-color: rgba(74,26,158,.5);
}
[data-theme="dark"] .btn-notice {
    border-color: rgba(167,139,250,.3);
    color: #a78bfa;
}
[data-theme="dark"] .btn-notice:hover {
    background: rgba(167,139,250,.1);
    border-color: rgba(167,139,250,.5);
}

/* ─── Filter Bar ───────────────────────────────────────────────────────────── */
.filter-bar {
    background: var(--filter-bar-bg);
    border-bottom: 1px solid var(--surface-border);
    position: sticky;
    top: 49px;
    z-index: 90;
    box-shadow: 0 1px 3px rgba(0,0,0,.06);
}
.filter-inner {
    max-width: 1400px;
    margin: 0 auto;
    padding: 10px 24px;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}
.filter-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .06em;
    white-space: nowrap;
}
.filter-presets { display: flex; gap: 4px; }
.preset-btn {
    padding: 5px 12px;
    border: 1.5px solid var(--surface-border);
    border-radius: 6px;
    background: transparent;
    font-family: inherit;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition);
}
.preset-btn:hover {
    border-color: var(--blue);
    color: var(--blue);
    background: rgba(21,101,192,.05);
}
.preset-btn.active {
    border-color: var(--blue);
    color: var(--white);
    background: var(--blue);
}
.filter-divider {
    width: 1px;
    height: 22px;
    background: var(--surface-border);
    margin: 0 4px;
}
.filter-custom {
    display: flex;
    align-items: center;
    gap: 6px;
}
.filter-to {
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 500;
}
.date-input {
    padding: 6px 10px;
    border: 1.5px solid var(--surface-border);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 13px;
    color: var(--text-primary);
    background: var(--input-bg);
    outline: none;
}
.date-input:focus { border-color: var(--blue); }

/* ─── Main Content ─────────────────────────────────────────────────────────── */
.main-content {
    max-width: 1400px;
    margin: 0 auto;
    padding: 28px 24px 60px;
}

/* ─── KPI Cards ────────────────────────────────────────────────────────────── */
.kpi-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
    margin-bottom: 28px;
}
.kpi-card {
    border-radius: var(--radius);
    padding: 24px 28px;
    color: var(--white);
    box-shadow: var(--shadow-sm);
    position: relative;
    overflow: hidden;
}
.kpi-card::after {
    content: '';
    position: absolute;
    top: -20px; right: -20px;
    width: 100px; height: 100px;
    border-radius: 50%;
    background: rgba(255,255,255,.08);
}
.kpi-blue      { background: var(--blue); }
.kpi-orange    { background: var(--orange); }
.kpi-dark-blue { background: var(--dark-blue); }
.kpi-green     { background: var(--green); }

.kpi-label {
    font-size: 13px;
    font-weight: 600;
    opacity: .85;
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: .04em;
}
.kpi-value {
    font-size: 48px;
    font-weight: 800;
    line-height: 1;
    letter-spacing: -.02em;
}
.kpi-trend {
    font-size: 13px;
    font-weight: 600;
    opacity: .9;
    margin-top: 8px;
}
.kpi-desc {
    font-size: 11px;
    opacity: .7;
    margin-top: 6px;
    line-height: 1.4;
}
.trend-up   { color: #A5D6A7; }
.trend-down { color: #FFCDD2; }
.trend-flat { color: rgba(255,255,255,.6); }

/* ─── Section Blocks ───────────────────────────────────────────────────────── */
.section-block {
    background: var(--surface-card);
    border-radius: var(--radius);
    padding: 24px;
    margin-bottom: 20px;
    box-shadow: var(--shadow-sm);
}
.section-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 4px;
}
.section-desc {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 16px;
    line-height: 1.5;
}
.section-header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}
.section-header-row .section-title { margin-bottom: 0; }


/* ─── Charts ───────────────────────────────────────────────────────────────── */
.charts-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 20px;
}
.chart-card {
    background: var(--surface-card);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow-sm);
}
.chart-card.chart-wide {
    grid-column: 1 / -1;
}
.chart-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 4px;
}
.chart-desc {
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 14px;
    line-height: 1.5;
}
.chart-wrap {
    position: relative;
    height: 280px;
}
.chart-wrap-bar {
    height: 320px;
}

/* ─── Tables ───────────────────────────────────────────────────────────────── */
.table-wrap {
    overflow-x: auto;
    border-radius: var(--radius-sm);
    border: 1px solid var(--surface-border);
}
.table-scrollable { max-height: 400px; overflow-y: auto; }

.ranking-table,
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}
.ranking-table th,
.data-table th {
    background: var(--surface-bg);
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
    padding: 10px 16px;
    text-align: left;
    border-bottom: 1px solid var(--surface-border);
    white-space: nowrap;
}
.ranking-table td,
.data-table td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--surface-border);
    color: var(--text-primary);
}
.ranking-table tr:last-child td,
.data-table tr:last-child td { border-bottom: none; }
.ranking-table tr:hover td,
.data-table tr:hover td { background: var(--surface-hover); }
.table-loading { text-align: center; color: var(--text-muted); padding: 24px; }

.rank-num {
    font-weight: 700;
    color: var(--gray-400);
    font-size: 13px;
}
.rank-1 .rank-num { color: #F57C00; }
.rank-2 .rank-num { color: var(--gray-600); }
.rank-3 .rank-num { color: #8D6E63; }

.share-bar-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
}
.share-bar {
    height: 6px;
    border-radius: 3px;
    background: var(--blue);
    min-width: 2px;
}
.share-pct { font-size: 12px; color: var(--gray-600); white-space: nowrap; }

.trend-arrow { font-size: 16px; }
.trend-arrow.up   { color: var(--green); }
.trend-arrow.down { color: var(--red); }
.trend-arrow.flat { color: var(--gray-400); }

.type-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
}
.type-website  { background: #FFF3E0; color: #E65100; }
.type-external { background: #E3F2FD; color: #1565C0; }

/* ─── Social Grid ──────────────────────────────────────────────────────────── */
.social-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 12px;
}
.social-card {
    background: var(--surface-bg);
    border: 1px solid var(--surface-border);
    border-radius: var(--radius-sm);
    padding: 16px;
    text-align: center;
}
.social-icon { font-size: 24px; margin-bottom: 6px; }
.social-platform {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: .04em;
    margin-bottom: 4px;
}
.social-count {
    font-size: 24px;
    font-weight: 800;
    color: var(--text-primary);
}

/* ─── Date Range Badge ─────────────────────────────────────────────────────── */
.date-range-badge {
    background: rgba(255,255,255,.15);
    color: rgba(255,255,255,.9);
    border-radius: 6px;
    padding: 5px 12px;
    font-size: 12px;
    font-weight: 500;
    white-space: nowrap;
    border: 1.5px solid rgba(255,255,255,.2);
}
.date-range-badge:empty { display: none; }

/* ─── Site Footer ──────────────────────────────────────────────────────────── */
.site-footer {
    text-align: center;
    padding: 24px;
    font-size: 12px;
    color: var(--text-muted);
    border-top: 1px solid var(--surface-border);
    background: var(--footer-bg);
}

/* ─── Settings Page ────────────────────────────────────────────────────────── */
.settings-main {
    max-width: 760px;
    margin: 40px auto;
    padding: 0 24px 60px;
}
.settings-card {
    background: var(--surface-card);
    border-radius: var(--radius);
    padding: 28px;
    margin-bottom: 20px;
    box-shadow: var(--shadow-sm);
}
.settings-card h2 {
    font-size: 17px;
    font-weight: 700;
    margin-bottom: 8px;
    color: var(--text-primary);
}
.settings-desc {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 20px;
    line-height: 1.6;
}

.status-badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
}
.status-active {
    background: #E8F5E9;
    color: var(--green);
}
[data-theme="dark"] .status-active {
    background: rgba(46,125,50,.2);
    color: #81C784;
}
.status-error {
    background: #FFEBEE;
    color: var(--red);
}
[data-theme="dark"] .status-error {
    background: rgba(198,40,40,.2);
    color: #EF9A9A;
}
.settings-hr {
    border: none;
    border-top: 1px solid var(--surface-border);
    margin: 20px 0;
}
.settings-replace-label {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 14px;
}
.btn-danger-outline {
    background: transparent;
    color: var(--red);
    border: 1.5px solid rgba(198,40,40,.35);
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 500;
    padding: 5px 12px;
    cursor: pointer;
    font-family: inherit;
    transition: all var(--transition);
}
.btn-danger-outline:hover {
    background: #FFEBEE;
    border-color: var(--red);
}
[data-theme="dark"] .btn-danger-outline:hover { background: rgba(198,40,40,.12); }
.file-input {
    display: block;
    width: 100%;
    padding: 10px 12px;
    border: 1.5px dashed var(--surface-border);
    border-radius: var(--radius-sm);
    background: var(--surface-bg);
    font-family: inherit;
    font-size: 13px;
    color: var(--text-primary);
    cursor: pointer;
    transition: border-color var(--transition);
}
.file-input:hover { border-color: var(--blue); }

/* ─── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
    .charts-row { grid-template-columns: 1fr; }
    .chart-card.chart-wide { grid-column: auto; }
    .kpi-value { font-size: 36px; }
}
@media (max-width: 640px) {
    .header-inner { padding: 10px 16px; gap: 8px; }
    .main-content { padding: 16px 16px 40px; }
    .filter-inner { padding: 8px 16px; gap: 6px; }
    .filter-divider { display: none; }
    .filter-custom { flex-wrap: wrap; }
    .admin-notice-inner { padding: 8px 16px; flex-direction: column; align-items: flex-start; gap: 8px; }
    .form-row { grid-template-columns: 1fr; }
    .login-card { padding: 32px 24px; }
    .kpi-value { font-size: 32px; }
}

/* ─── Loading Spinner ──────────────────────────────────────────────────────── */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(255,255,255,.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 999;
    backdrop-filter: blur(2px);
}
.spinner {
    width: 40px; height: 40px;
    border: 4px solid var(--gray-200);
    border-top-color: var(--blue);
    border-radius: 50%;
    animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
