@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,400;0,9..40,500;0,9..40,600;0,9..40,700;1,9..40,400&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
    --bg-deep:       #faf8f5;
    --bg-surface:    #ffffff;
    --bg-card:       #ffffff;
    --bg-card-hover: #f5f3f0;
    --bg-input:      #f3f1ed;
    --border:        rgba(60,50,40,0.1);
    --border-focus:  rgba(190,58,58,0.45);
    --text-primary:   #2c2420;
    --text-secondary: #6b6560;
    --text-muted:     #a09a94;
    --accent:         #c83c3c;
    --accent-dim:     rgba(200,60,60,0.08);
    --shadow-card:   0 1px 4px rgba(60,50,40,0.06), 0 0 1px rgba(60,50,40,0.04);
    --chart-tick:     #6b6560;
    --chart-grid:     rgba(0,0,0,0.05);
    --chart-legend:   #4a4540;
    --sidebar-w:     240px;
    --radius:        10px;
    --radius-sm:     6px;
    --font-body:     'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono:     'JetBrains Mono', 'Fira Code', monospace;
}

[data-theme="dark"] {
    --bg-deep:       #0c0c14;
    --bg-surface:    #12121f;
    --bg-card:       #17172a;
    --bg-card-hover: #1e1e35;
    --bg-input:      #1b1b30;
    --border:        rgba(255,255,255,0.07);
    --border-focus:  rgba(233,69,96,0.5);
    --text-primary:   #e8e9ed;
    --text-secondary: #7a7f8a;
    --text-muted:     #4e5260;
    --accent:         #e94560;
    --accent-dim:     rgba(233,69,96,0.14);
    --shadow-card:   0 2px 12px rgba(0,0,0,0.3);
    --chart-tick:     #7a7f8a;
    --chart-grid:     rgba(255,255,255,0.04);
    --chart-legend:   #c4c7ce;
}

/* ── RESET ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html {
    font-size: 15px;
    -webkit-font-smoothing: antialiased;
    -webkit-text-size-adjust: 100%;
}
body {
    font-family: var(--font-body);
    background: var(--bg-deep);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    overflow-x: hidden;
    transition: background-color 0.3s, color 0.3s;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ══════════════════════
   FORMS — 16px prevents iOS zoom
   ══════════════════════ */
input[type="text"], input[type="password"], input[type="email"], select, textarea {
    width: 100%;
    padding: 0.65rem 0.9rem;
    font-family: var(--font-body);
    font-size: 16px;
    color: var(--text-primary);
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    outline: none;
    -webkit-appearance: none;
    appearance: none;
    transition: border-color 0.2s, box-shadow 0.2s, background-color 0.3s, color 0.3s;
}
input:focus, select:focus { border-color: var(--border-focus); box-shadow: 0 0 0 3px var(--accent-dim); }
input::placeholder { color: var(--text-muted); }
.form-group { margin-bottom: 1.1rem; text-align: left; }
.form-group label {
    display: block; font-size: 0.83rem; font-weight: 500;
    color: var(--text-secondary); margin-bottom: 0.35rem;
}

/* ══════════════════════
   LOGIN PAGE
   ══════════════════════ */
.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    min-height: -webkit-fill-available;
    padding: 1rem;
    background: var(--bg-deep);
}
.login-card {
    width: 100%;
    max-width: 440px;
    padding: 2.75rem 2.5rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-card);
    text-align: center;
    transition: background-color 0.3s, border-color 0.3s, box-shadow 0.3s;
}
.login-logo {
    margin-bottom: 1.25rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 50px; height: 50px;
    border-radius: 13px;
    background: var(--accent);
}
.login-card h1 { font-size: 1.45rem; font-weight: 700; margin-bottom: 0.25rem; }
.login-subtitle { color: var(--text-secondary); font-size: 0.9rem; margin-bottom: 1.75rem; }
.login-footer-row {
    margin-top: 1.75rem;
    display: flex; justify-content: center; align-items: center; gap: 0.75rem;
}
.login-footer-row span { font-size: 0.8rem; color: var(--text-muted); }

/* ── BUTTONS ── */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
    padding: 0.55rem 1.15rem;
    font-family: var(--font-body); font-size: 0.88rem; font-weight: 500;
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    background: var(--bg-card); color: var(--text-primary);
    cursor: pointer; transition: all 0.15s;
}
.btn:hover { background: var(--bg-card-hover); text-decoration: none; }
.btn-primary {
    background: var(--accent); border-color: var(--accent); color: #fff;
    padding: 0.68rem 1.3rem; font-size: 16px; font-weight: 600;
}
.btn-primary:hover { filter: brightness(1.08); }
.btn-danger { color: var(--accent); border-color: rgba(200,60,60,0.2); }
.btn-danger:hover { background: var(--accent-dim); }
.btn-full { width: 100%; }
.btn-sm { padding: 0.38rem 0.8rem; font-size: 0.82rem; }

/* ── ALERTS ── */
.alert { padding: 0.75rem 1rem; border-radius: var(--radius-sm); font-size: 0.88rem; margin-bottom: 1.25rem; text-align: left; }
.alert-error { background: rgba(200,60,60,0.07); border: 1px solid rgba(200,60,60,0.18); color: #a83535; }
[data-theme="dark"] .alert-error { background: rgba(233,69,96,0.12); border-color: rgba(233,69,96,0.25); color: #f07a8e; }
.alert-success { background: rgba(58,143,92,0.07); border: 1px solid rgba(58,143,92,0.18); color: #2d7a4a; }
[data-theme="dark"] .alert-success { background: rgba(39,174,96,0.12); border-color: rgba(39,174,96,0.25); color: #6dd5a0; }

/* ── THEME TOGGLE ── */
.theme-btn {
    display: inline-flex; align-items: center; justify-content: center;
    width: 36px; height: 36px;
    border: 1px solid var(--border); border-radius: 50%;
    background: var(--bg-input); color: var(--text-secondary);
    cursor: pointer; transition: all 0.2s; flex-shrink: 0;
    padding: 0;
}
.theme-btn:hover { background: var(--bg-card-hover); color: var(--text-primary); border-color: var(--accent); }
.theme-btn svg { width: 18px; height: 18px; }
.theme-btn .icon-sun { display: block; }
.theme-btn .icon-moon { display: none; }
[data-theme="dark"] .theme-btn .icon-sun { display: none; }
[data-theme="dark"] .theme-btn .icon-moon { display: block; }

/* ══════════════════════
   DASHBOARD LAYOUT
   ══════════════════════ */
.dashboard-body {
    display: flex;
    min-height: 100vh;
}
.sidebar {
    position: fixed; top: 0; left: 0;
    width: var(--sidebar-w); height: 100vh;
    background: var(--bg-surface); border-right: 1px solid var(--border);
    display: flex; flex-direction: column; padding: 1.25rem 0; z-index: 100;
    transition: background-color 0.3s, border-color 0.3s;
    overflow-y: auto;
}
.sidebar-brand {
    display: flex; align-items: center; gap: 0.65rem;
    padding: 0 1.25rem 1.5rem;
    font-size: 1.05rem; font-weight: 600;
    border-bottom: 1px solid var(--border); margin-bottom: 1rem;
}
.sidebar-nav { flex: 1; display: flex; flex-direction: column; gap: 0.15rem; padding: 0 0.65rem; }
.nav-item {
    display: flex; align-items: center; gap: 0.6rem;
    padding: 0.55rem 0.75rem; border-radius: var(--radius-sm);
    font-size: 0.9rem; color: var(--text-secondary);
    transition: all 0.15s; text-decoration: none;
}
.nav-item:hover { background: var(--accent-dim); color: var(--text-primary); text-decoration: none; }
.nav-item.active { background: var(--accent-dim); color: var(--accent); font-weight: 500; }
.sidebar-footer {
    padding: 0.75rem 0.65rem 0; border-top: 1px solid var(--border);
    margin-top: auto; display: flex; flex-direction: column; gap: 0.35rem;
}
.sidebar-footer-row {
    display: flex; align-items: center; justify-content: space-between;
    padding: 0.3rem 0.75rem;
}
.nav-logout:hover { color: var(--accent); }
.main-content {
    margin-left: var(--sidebar-w); flex: 1;
    padding: 2rem 2.5rem 3rem; max-width: 1200px; width: 100%;
    min-width: 0;
}

/* ── HEADER ── */
.dash-header {
    display: flex; justify-content: space-between; align-items: flex-start;
    gap: 1.5rem; margin-bottom: 2rem; flex-wrap: wrap;
}
.dash-header h1 { font-size: 1.6rem; font-weight: 700; letter-spacing: -0.02em; }
.header-sub { color: var(--text-secondary); font-size: 0.88rem; margin-top: 0.2rem; }
.filter-form { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.filter-form select, .filter-path { width: auto; min-width: 120px; padding: 0.4rem 0.7rem; }
.filter-path { min-width: 140px; }

/* ── KPI ── */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1rem; margin-bottom: 1.75rem; }
.kpi-card {
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 1.25rem 1.5rem; box-shadow: var(--shadow-card);
    transition: background-color 0.3s, border-color 0.3s;
}
.kpi-label { font-size: 0.78rem; font-weight: 500; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 0.35rem; }
.kpi-value { font-size: 1.9rem; font-weight: 700; letter-spacing: -0.02em; line-height: 1.1; }

/* ── CARDS ── */
.card {
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 1.5rem; margin-bottom: 1.5rem;
    box-shadow: var(--shadow-card); transition: background-color 0.3s, border-color 0.3s;
    overflow: hidden;
}
.card h2 { font-size: 1rem; font-weight: 600; margin-bottom: 1.1rem; }
.card h3 { font-size: 0.92rem; font-weight: 600; }
.card-desc { font-size: 0.85rem; color: var(--text-secondary); margin-bottom: 1rem; line-height: 1.5; }
.card-desc code { font-family: var(--font-mono); font-size: 0.82rem; background: var(--bg-input); padding: 0.15em 0.4em; border-radius: 3px; }
.chart-card { padding-bottom: 1rem; }
.chart-container { position: relative; height: 260px; width: 100%; }
.chart-container-sm { position: relative; height: 200px; width: 100%; }
.chart-container canvas, .chart-container-sm canvas { position: absolute; top: 0; left: 0; width: 100% !important; height: 100% !important; }

/* ── EMBED CARD ── */
.card-embed {
    border: 2px solid var(--accent);
    background: var(--bg-card);
    position: relative;
}
.card-embed::before {
    content: ''; position: absolute; inset: 0;
    background: var(--accent); opacity: 0.03;
    border-radius: var(--radius); pointer-events: none;
}
.embed-badge {
    display: inline-block; background: var(--accent); color: #fff;
    font-size: 0.7rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em;
    padding: 0.25rem 0.6rem; border-radius: 4px; margin-bottom: 0.75rem;
}
.embed-steps { margin: 1.25rem 0 0; }
.embed-steps h3 { margin-top: 1.25rem; margin-bottom: 0.35rem; }
.embed-steps ol {
    margin: 0.4rem 0 0 1.25rem; font-size: 0.85rem; color: var(--text-secondary); line-height: 1.7;
}
.embed-steps ol li { margin-bottom: 0.3rem; }
.embed-details { margin-top: 1.25rem; }
.embed-toggle {
    cursor: pointer; font-size: 0.88rem; font-weight: 500; color: var(--accent);
    padding: 0.5rem 0; list-style: none; user-select: none;
}
.embed-toggle::-webkit-details-marker { display: none; }
.embed-toggle::before { content: '▸ '; }
.embed-details[open] .embed-toggle::before { content: '▾ '; }

/* ── GRIDS ── */
.grid-2col { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; margin-bottom: 1.5rem; }
.grid-3col { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 1.5rem; margin-bottom: 1.5rem; }

/* ── TABLES ── */
.data-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.data-table thead th {
    text-align: left; font-weight: 500; color: var(--text-muted);
    text-transform: uppercase; font-size: 0.72rem; letter-spacing: 0.05em;
    padding: 0.6rem 0.75rem; border-bottom: 1px solid var(--border);
}
.data-table tbody td { padding: 0.55rem 0.75rem; border-bottom: 1px solid var(--border); color: var(--text-secondary); }
.data-table tbody tr:hover td { background: var(--accent-dim); color: var(--text-primary); }
.data-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.data-table .truncate { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.data-table .nowrap { white-space: nowrap; }
.data-table .empty-row { text-align: center; color: var(--text-muted); padding: 2rem; }
.data-table-compact { font-size: 0.8rem; }
.data-table-compact td { padding: 0.4rem 0.6rem; }
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* ── BAR LISTS ── */
.bar-list { display: flex; flex-direction: column; gap: 0.65rem; }
.bar-label { display: flex; justify-content: space-between; font-size: 0.82rem; color: var(--text-secondary); margin-bottom: 0.2rem; }
.bar-track { height: 6px; background: var(--accent-dim); border-radius: 3px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--accent); border-radius: 3px; min-width: 2px; transition: width 0.4s; }

/* ── SNIPPET BOX ── */
.snippet-box {
    position: relative; background: var(--bg-input);
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    padding: 1rem 1.25rem; overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    transition: background-color 0.3s;
}
[data-theme="dark"] .snippet-box { background: #0e0e18; }
.snippet-box pre { margin: 0; font-family: var(--font-mono); font-size: 0.78rem; line-height: 1.65; color: var(--text-secondary); white-space: pre-wrap; word-break: break-all; }
.snippet-box-sm { margin-top: 0.5rem; padding: 0.75rem 1rem; }
.snippet-box-sm pre { font-size: 0.74rem; line-height: 1.5; }
.btn-copy { position: absolute; top: 0.6rem; right: 0.6rem; }

/* ── VISITOR BADGES ── */
.badge { font-size: 0.72rem; font-weight: 500; color: var(--text-muted); margin-left: 0.5rem; }
.revisit-badge {
    display: inline-block; background: var(--accent-dim); color: var(--accent);
    font-size: 0.72rem; font-weight: 600; padding: 0.15em 0.5em; border-radius: 4px;
    font-variant-numeric: tabular-nums;
}
.new-badge {
    display: inline-block; background: rgba(58,143,92,0.1); color: #2d7a4a;
    font-size: 0.72rem; font-weight: 600; padding: 0.15em 0.5em; border-radius: 4px;
}
[data-theme="dark"] .new-badge { background: rgba(39,174,96,0.15); color: #6dd5a0; }
.mono-text { font-family: var(--font-mono); font-size: 0.78rem; letter-spacing: -0.02em; }

/* ── SITE SWITCHER ── */
.site-switcher {
    display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap;
    margin-bottom: 1.5rem; padding: 0.75rem 1rem;
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow-card);
    transition: background-color 0.3s, border-color 0.3s;
}
.site-switcher-label {
    font-size: 0.8rem; font-weight: 500; color: var(--text-muted);
    text-transform: uppercase; letter-spacing: 0.04em; margin-right: 0.25rem;
}
.site-tab {
    display: inline-flex; align-items: center; padding: 0.35rem 0.85rem;
    font-size: 0.82rem; font-weight: 500; border-radius: 6px;
    color: var(--text-secondary); background: var(--bg-input);
    border: 1px solid transparent; text-decoration: none;
    transition: all 0.15s; cursor: pointer;
}
.site-tab:hover { background: var(--accent-dim); color: var(--text-primary); text-decoration: none; }
.site-tab.active {
    background: var(--accent); color: #fff;
    border-color: var(--accent); font-weight: 600;
}

.dash-footer { text-align: center; color: var(--text-muted); font-size: 0.78rem; padding-top: 2rem; margin-top: 1rem; border-top: 1px solid var(--border); }

/* ══════════════════════════════════════
   MOBILE — complete rewrite
   ══════════════════════════════════════ */
@media (max-width: 1024px) {
    .grid-3col { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 768px) {
    /* Kill all horizontal overflow at every level */
    html, body, .dashboard-body, .main-content { max-width: 100vw; overflow-x: hidden; }

    /* Sidebar → simple top bar, NOT fixed — avoids all the overlap/margin mess */
    .sidebar {
        position: relative;
        width: 100%; height: auto;
        flex-direction: row; align-items: center;
        padding: 0.5rem; gap: 0.25rem;
        border-right: none; border-bottom: 1px solid var(--border);
        overflow: hidden;
    }
    .sidebar-brand { padding: 0; margin: 0; border-bottom: none; }
    .sidebar-brand span { display: none; }
    .sidebar-brand svg { width: 24px; height: 24px; }
    .sidebar-nav {
        flex: 1; flex-direction: row; padding: 0; gap: 0;
        overflow-x: auto; -webkit-overflow-scrolling: touch;
    }
    .sidebar-nav .nav-item svg { display: none; }
    .nav-item { font-size: 0.72rem; padding: 0.3rem 0.45rem; white-space: nowrap; }
    .sidebar-footer { margin: 0; border-top: none; padding: 0; flex-direction: row; }
    .sidebar-footer-row { padding: 0; gap: 0.25rem; }
    .nav-logout { font-size: 0.72rem; padding: 0.3rem 0.45rem; }
    .nav-logout svg { display: none; }
    .theme-btn { width: 30px; height: 30px; }
    .theme-btn svg { width: 14px; height: 14px; }

    /* Main content — no margin-top needed since sidebar is relative, not fixed */
    .dashboard-body { flex-direction: column; }
    .main-content { margin-left: 0; padding: 0.75rem; }

    /* Header */
    .dash-header { flex-direction: column; gap: 0.5rem; margin-bottom: 1rem; }
    .dash-header h1 { font-size: 1.2rem; }
    .header-sub { font-size: 0.78rem; }

    /* Filters — stack vertically */
    .filter-form { width: 100%; flex-direction: column; gap: 0.35rem; }
    .filter-form select, .filter-path { width: 100%; min-width: 0; }
    .filter-form .btn { width: 100%; }

    /* Grids → single column */
    .grid-2col, .grid-3col { grid-template-columns: 1fr; gap: 0.75rem; }
    .kpi-grid { grid-template-columns: 1fr 1fr; gap: 0.5rem; }
    .kpi-card { padding: 0.75rem; }
    .kpi-value { font-size: 1.3rem; }
    .kpi-label { font-size: 0.68rem; }

    /* Cards */
    .card { padding: 0.75rem; margin-bottom: 0.75rem; }
    .card h2 { font-size: 0.88rem; margin-bottom: 0.6rem; }
    .card-desc { font-size: 0.78rem; }

    /* Tables */
    .data-table { font-size: 0.7rem; }
    .data-table thead th { font-size: 0.6rem; padding: 0.35rem 0.4rem; }
    .data-table tbody td { padding: 0.35rem 0.4rem; }
    .data-table .truncate { max-width: 90px; }
    .data-table-compact { font-size: 0.68rem; }

    /* Charts */
    .chart-container { height: 180px; }
    .chart-container-sm { height: 150px; }

    /* Site switcher */
    .site-switcher { padding: 0.5rem; gap: 0.25rem; flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .site-switcher-label { font-size: 0.68rem; white-space: nowrap; }
    .site-tab { font-size: 0.7rem; padding: 0.25rem 0.5rem; white-space: nowrap; }

    /* Snippet */
    .snippet-box { padding: 0.6rem; }
    .snippet-box pre { font-size: 0.65rem; }
    .btn-copy { font-size: 0.68rem; padding: 0.2rem 0.4rem; top: 0.4rem; right: 0.4rem; }

    /* Embed */
    .card-embed { padding: 0.75rem; }
    .embed-steps ol { font-size: 0.76rem; margin-left: 1rem; }

    /* Badges */
    .mono-text { font-size: 0.65rem; }
    .bar-label { font-size: 0.74rem; }

    /* Login */
    .login-body { padding: 0.75rem; }
    .login-card { max-width: 100%; padding: 1.75rem 1.25rem; }
    .login-card h1 { font-size: 1.25rem; }
    .login-subtitle { font-size: 0.85rem; margin-bottom: 1.25rem; }
    .login-logo { width: 44px; height: 44px; border-radius: 11px; }

    /* Hide less critical columns */
    .hide-mobile { display: none; }
}

@media (max-width: 480px) {
    .kpi-grid { grid-template-columns: 1fr; }
    .dash-header h1 { font-size: 1.05rem; }
    .login-card { padding: 1.5rem 1rem; }
    .login-card h1 { font-size: 1.15rem; }
}
