/* ── Analytics dashboard ── */

/* ── Header ── */
.analytics-header {
    margin-bottom: 2rem;
}

.analytics-header-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.analytics-subtitle {
    margin: 0.3rem 0 0;
    color: var(--text-muted);
    font-size: 0.875rem;
}

.analytics-subtitle strong {
    color: var(--text-secondary);
    font-weight: 600;
}

/* Live badge — now a genuine "active now" indicator (polled, see the
   inline script), not a decorative always-on label. :not([hidden]) so the
   idle variant's hidden attribute actually hides it (same lesson learned
   repeatedly elsewhere in this codebase: an unconditional display here
   would beat the browser's [hidden] rule on the specificity tie). */
.analytics-live-badge:not([hidden]) {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.2rem 0.6rem;
    border-radius: 99px;
    background: rgba(16, 185, 129, 0.1);
    border: 1px solid rgba(16, 185, 129, 0.25);
    color: #10b981;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

/* ── Summary cards ── */
.analytics-summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(168px, 1fr));
    gap: 0.85rem;
    margin-bottom: 1.25rem;
}

.analytics-card {
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 1.1rem 1.25rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 0;
    position: relative;
    overflow: hidden;
}

.analytics-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    border-radius: 14px 14px 0 0;
}

.analytics-card--purple::before { background: #8b5cf6; }
.analytics-card--blue::before   { background: #3b82f6; }
.analytics-card--green::before  { background: #10b981; }
.analytics-card--amber::before  { background: #f59e0b; }
.analytics-card--teal::before   { background: #14b8a6; }
.analytics-card--pink::before   { background: #ec4899; }

.analytics-card-top {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.65rem;
}

.analytics-card-icon {
    display: flex;
    align-items: center;
    width: 1.6rem;
    height: 1.6rem;
    border-radius: 8px;
    justify-content: center;
    font-size: 0.9rem;
    flex-shrink: 0;
}

.analytics-card--purple .analytics-card-icon { background: rgba(139, 92, 246, 0.12); color: #8b5cf6; }
.analytics-card--blue   .analytics-card-icon { background: rgba(59, 130, 246, 0.12);  color: #3b82f6; }
.analytics-card--green  .analytics-card-icon { background: rgba(16, 185, 129, 0.12); color: #10b981; }
.analytics-card--amber  .analytics-card-icon { background: rgba(245, 158, 11, 0.12); color: #f59e0b; }
.analytics-card--teal   .analytics-card-icon { background: rgba(20, 184, 166, 0.12); color: #14b8a6; }
.analytics-card--pink   .analytics-card-icon { background: rgba(236, 72, 153, 0.12); color: #ec4899; }

.analytics-card-label {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    line-height: 1.2;
}

.analytics-card-value {
    font-size: 2.1rem;
    font-weight: 800;
    color: var(--text);
    line-height: 1.1;
    letter-spacing: -0.04em;
    margin-bottom: 0.5rem;
}

.analytics-card-bottom {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    flex-wrap: wrap;
    margin-top: auto;
}

.analytics-card-sub {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* Trend indicator */
.analytics-trend {
    display: inline-flex;
    align-items: center;
    gap: 0.2rem;
    font-size: 0.75rem;
    font-weight: 700;
    padding: 0.15rem 0.4rem;
    border-radius: 6px;
}

.analytics-trend--up {
    color: #10b981;
    background: rgba(16, 185, 129, 0.1);
}

.analytics-trend--down {
    color: #ef4444;
    background: rgba(239, 68, 68, 0.1);
}

/* ── Sections ── */
.analytics-section {
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 1.25rem 1.4rem;
    margin-bottom: 1.1rem;
}

.analytics-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.1rem;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.analytics-section-title {
    font-size: 0.82rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin: 0;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.analytics-section-meta {
    font-size: 0.72rem;
    color: var(--text-muted);
}

/* Empty state */
.analytics-empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    padding: 1.5rem 0;
    color: var(--text-muted);
    text-align: center;
}

.analytics-empty-state p {
    font-size: 0.875rem;
    margin: 0;
}

/* ── Bar chart ── */
.analytics-chart-wrap {
    overflow-x: auto;
    position: relative;
}

.analytics-chart-container {
    display: flex;
    gap: 0.4rem;
    align-items: stretch;
    min-width: 520px;
}

/* On phones, shrink to fit instead of forcing horizontal scroll on the
   page's main chart — bars just get proportionally thinner (still tap-
   able, and only ~6 day-labels ever render regardless of width, so
   nothing collides). */
@media (max-width: 600px) {
    .analytics-chart-container {
        min-width: 0;
    }
}

.analytics-chart-yaxis {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: flex-end;
    padding-bottom: 26px;
    min-width: 2rem;
    flex-shrink: 0;
}

.analytics-chart-yaxis span {
    font-size: 0.62rem;
    color: var(--text-muted);
    line-height: 1;
    font-variant-numeric: tabular-nums;
}

.analytics-chart-inner {
    flex: 1;
    min-width: 0;
    position: relative;
}

/* Gridlines */
.analytics-chart-gridlines {
    position: absolute;
    inset: 0 0 26px 0;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    pointer-events: none;
    z-index: 0;
}

.analytics-gridline {
    border-top: 1px dashed var(--border);
    width: 100%;
}

.analytics-bar-chart {
    display: flex;
    align-items: flex-end;
    gap: 3px;
    height: 200px;
    padding-bottom: 26px;
    position: relative;
    z-index: 1;
}

.analytics-bar-col {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    height: 100%;
    position: relative;
    cursor: default;
}

.analytics-bar-fill {
    width: 100%;
    background: var(--primary);
    border-radius: 3px 3px 0 0;
    min-height: 2px;
    opacity: 0.65;
    transition: opacity 0.15s, height 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.analytics-bar-col.is-today .analytics-bar-fill {
    background: #a78bfa;
    opacity: 1;
    box-shadow: 0 0 8px rgba(167, 139, 250, 0.4);
}

.analytics-bar-col:hover .analytics-bar-fill {
    opacity: 1;
}

.analytics-bar-label {
    position: absolute;
    left: 0;
    bottom: 0;
    font-size: 0.59rem;
    color: var(--text-muted);
    white-space: nowrap;
    line-height: 1;
}

/* The last column's label would otherwise bleed past the chart's right
   edge once columns get very narrow (many days in a small viewport). */
.analytics-bar-label--end {
    left: auto;
    right: 0;
}

.analytics-bar-col.is-today .analytics-bar-label {
    color: #a78bfa;
    font-weight: 700;
}

/* Tooltip */
.analytics-chart-tooltip {
    position: absolute;
    background: var(--bg-elevated);
    border: 1px solid var(--border-strong);
    border-radius: 8px;
    padding: 0.35rem 0.65rem;
    font-size: 0.78rem;
    color: var(--text);
    font-weight: 500;
    pointer-events: none;
    white-space: nowrap;
    opacity: 0;
    transition: opacity 0.1s;
    z-index: 20;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.analytics-chart-tooltip.is-visible {
    opacity: 1;
}

/* ── Two-column layout ── */
.analytics-two-col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.1rem;
    margin-bottom: 1.1rem;
}

@media (max-width: 760px) {
    .analytics-two-col {
        grid-template-columns: 1fr;
    }
}

/* ── Shared rows list (pages + referrers) ── */
.analytics-rows-list {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.analytics-row-item {
    display: grid;
    grid-template-columns: 1.5rem 1fr auto;
    gap: 0.6rem;
    align-items: center;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border);
}

.analytics-row-item:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.analytics-row-item:first-child {
    padding-top: 0;
}

.analytics-row-rank {
    font-size: 0.68rem;
    font-weight: 700;
    color: var(--text-muted);
    text-align: center;
    font-variant-numeric: tabular-nums;
}

.analytics-row-info {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    min-width: 0;
    overflow: hidden;
}

.analytics-row-bar-wrap {
    background: var(--bg-secondary);
    border-radius: 4px;
    height: 4px;
    overflow: hidden;
}

.analytics-row-bar {
    height: 100%;
    border-radius: 4px;
    min-width: 2px;
    transition: width 0.35s ease;
}

.analytics-row-bar--page     { background: var(--primary); opacity: 0.7; }
.analytics-row-bar--referrer { background: #10b981; opacity: 0.7; }

.analytics-row-stats {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.15rem;
    flex-shrink: 0;
}

.analytics-row-count {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--text);
    font-variant-numeric: tabular-nums;
}

.analytics-row-share {
    font-size: 0.68rem;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}

/* Pages */
.analytics-page-link {
    color: var(--text);
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: block;
}

.analytics-page-link:hover {
    color: var(--primary);
}

/* Referrers */
.analytics-referrer-host {
    font-family: 'Menlo', 'Consolas', monospace;
    font-size: 0.78rem;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: block;
}

/* ── Device breakdown ── */
.analytics-device-total-bar {
    display: flex;
    height: 8px;
    border-radius: 6px;
    overflow: hidden;
    margin-bottom: 1.1rem;
    gap: 2px;
}

.analytics-device-segment {
    height: 100%;
    border-radius: 2px;
    transition: opacity 0.15s;
}

.analytics-device-segment:hover {
    opacity: 0.8;
}

.analytics-device-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.analytics-device-row {
    display: grid;
    grid-template-columns: 8px 18px 68px 1fr 38px 36px;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
}

/* Browser/OS rows have no icon column. */
.analytics-device-row--simple {
    grid-template-columns: 8px 68px 1fr 38px 36px;
}

/* Narrow screens: the fixed columns (dot+icon+label+pct+count) leave the
   actual proportion bar very little room. Drop the icon and tighten the
   label/pct/count widths so the bar — the meaningful part — gets space. */
@media (max-width: 480px) {
    .analytics-device-row {
        grid-template-columns: 6px 56px 1fr 32px;
        gap: 0.4rem;
    }
    .analytics-device-row--simple {
        grid-template-columns: 6px 56px 1fr 32px;
    }
    .analytics-device-icon {
        display: none;
    }
    .analytics-device-label {
        font-size: 0.76rem;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    .analytics-device-count {
        display: none;
    }
}

.analytics-device-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.analytics-device-icon {
    color: var(--text-muted);
    display: flex;
    align-items: center;
    font-size: 1rem;
}

.analytics-device-label {
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.82rem;
}

.analytics-device-bar-wrap {
    background: var(--bg-secondary);
    border-radius: 4px;
    height: 6px;
    overflow: hidden;
}

.analytics-device-bar {
    height: 100%;
    border-radius: 4px;
    opacity: 0.75;
    transition: width 0.35s ease;
}

.analytics-device-pct {
    text-align: right;
    font-variant-numeric: tabular-nums;
    font-weight: 700;
    font-size: 0.8rem;
    color: var(--text);
}

.analytics-device-count {
    color: var(--text-muted);
    font-size: 0.72rem;
    font-variant-numeric: tabular-nums;
}

/* Per-website table */
.analytics-website-table-wrap {
    overflow-x: auto;
}

.analytics-website-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.analytics-website-table thead th {
    text-align: left;
    padding: 0.55rem 0.9rem;
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.analytics-website-table tbody tr {
    border-bottom: 1px solid var(--border);
    transition: background 0.12s;
}

.analytics-website-table tbody tr:last-child {
    border-bottom: none;
}

.analytics-website-table tbody tr:hover {
    background: var(--bg-hover);
}

.analytics-website-table td {
    padding: 0.75rem 0.9rem;
    vertical-align: middle;
}

.analytics-col-num {
    text-align: right;
    width: 90px;
    font-variant-numeric: tabular-nums;
    color: var(--text-secondary);
}

.analytics-col-action {
    text-align: right;
    width: 100px;
}

.analytics-website-name-cell {
    min-width: 180px;
}

.analytics-website-name-wrap {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.analytics-website-name {
    font-weight: 500;
    color: var(--text);
}

.analytics-website-domain {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.1rem;
}

.analytics-site-badge {
    font-size: 0.68rem;
    font-weight: 600;
    padding: 0.15rem 0.45rem;
    border-radius: 99px;
    letter-spacing: 0.02em;
}

.analytics-site-badge--live {
    background: rgba(16,185,129,.15);
    color: #10b981;
    border: 1px solid rgba(16,185,129,.25);
}

.analytics-site-badge--concept {
    background: var(--bg-hover);
    color: var(--text-muted);
    border: 1px solid var(--border);
}

.analytics-table-num--active {
    color: #8b5cf6;
    font-weight: 600;
}

/* Site-status badge reused inline next to the page title on the per-website page. */
.dashboard-page-title .analytics-site-badge {
    vertical-align: middle;
    margin-left: 0.5rem;
}

/* ── Sortable table headers ── */
.analytics-sort-link {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    color: inherit;
    text-decoration: none;
}

.analytics-sort-link:hover,
.analytics-sort-link.is-active {
    color: var(--text);
}

/* ── Date-range picker + export ── */
.analytics-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-bottom: 1.1rem;
}

.analytics-range-pills {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    flex-wrap: wrap;
}

.analytics-range-pill {
    display: inline-flex;
    padding: 0.35rem 0.8rem;
    border-radius: 20px;
    font-size: var(--fs-sm);
    font-weight: 500;
    color: var(--text-secondary);
    background: var(--bg-primary);
    border: 1px solid var(--border);
    text-decoration: none;
    cursor: pointer;
    list-style: none;
    transition: background 0.12s, border-color 0.12s, color 0.12s;
}

.analytics-range-pill::-webkit-details-marker,
.analytics-range-pill::marker {
    display: none;
    content: '';
}

.analytics-range-pill:hover {
    background: var(--bg-hover);
    color: var(--text);
}

.analytics-range-pill.is-active {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

.analytics-range-custom {
    position: relative;
}

.analytics-range-form {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    z-index: 30;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    padding: 0.85rem;
    background: var(--bg-elevated);
    border: 1px solid var(--border-strong);
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
    width: max-content;
}

.analytics-range-form-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text);
}

.analytics-range-form-close {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    transition: background 0.12s, color 0.12s;
}

.analytics-range-form-close:hover {
    background: var(--bg-hover);
    color: var(--text);
}

.analytics-range-form label {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.analytics-range-form input[type="date"] {
    padding: 0.4rem 0.5rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg-primary);
    color: var(--text);
    font-size: 0.82rem;
}

.analytics-export-link {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: var(--fs-sm);
    font-weight: 500;
    color: var(--text-secondary);
    text-decoration: none;
    padding: 0.35rem 0.8rem;
    border: 1px solid var(--border);
    border-radius: 20px;
    transition: background 0.12s, color 0.12s;
}

.analytics-export-link:hover {
    background: var(--bg-hover);
    color: var(--text);
}

@media (max-width: 560px) {
    .analytics-toolbar {
        flex-direction: column;
        align-items: stretch;
    }
    .analytics-export-link {
        justify-content: center;
    }
    .analytics-range-form {
        position: fixed;
        left: 1rem;
        right: 1rem;
        top: 8rem;
        width: auto;
    }
}
