/* ── Analytics Dashboard ──────────────────────────────────────────────────── */

:root {
    --an-radius:  8px;
    --an-accent:  #1a6bb5;
    --an-border:  #e2e6ea;
    --an-bg:      #f8f9fa;
    --an-card:    #ffffff;
    --an-text:    #212529;
    --an-muted:   #6c757d;
    --an-green:   #1a6b35;
    --an-orange:  #7a5f00;
    --an-bar:     #a8c8f0;
    --an-bar-hi:  #1a6bb5;
}

#analytics-dashboard {
    font-family: inherit;
    color: var(--an-text);
}

.an-shell {
    background: var(--an-card);
    border: 1px solid var(--an-border);
    border-radius: var(--an-radius);
    overflow: hidden;
}

/* ── Header ───────────────────────────────────────────────────────────────── */

.an-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    padding: 16px 20px 14px;
    border-bottom: 1px solid var(--an-border);
    gap: 12px;
    flex-wrap: wrap;
}

.an-title {
    font-weight: 700;
    font-size: 1.05rem;
    display: flex;
    align-items: center;
    gap: 8px;
}

.an-generated {
    font-size: .78rem;
    color: var(--an-muted);
}

/* ── Tabs ─────────────────────────────────────────────────────────────────── */

.an-tabs {
    display: flex;
    gap: 0;
    border-bottom: 1px solid var(--an-border);
    background: var(--an-bg);
    padding: 0 20px;
    overflow-x: auto;
}

.an-tab {
    background: none;
    border: none;
    border-bottom: 3px solid transparent;
    padding: 11px 18px;
    font-size: .875rem;
    font-weight: 500;
    color: var(--an-muted);
    cursor: pointer;
    white-space: nowrap;
    transition: color .12s, border-color .12s;
    margin-bottom: -1px;
}

.an-tab:hover { color: var(--an-text); }

.an-tab.active {
    color: var(--an-accent);
    border-bottom-color: var(--an-accent);
    background: var(--an-card);
}

/* ── Tab panel ────────────────────────────────────────────────────────────── */

.an-panel { display: none; padding: 20px; }
.an-panel.active { display: block; }

/* ── Stat cards ───────────────────────────────────────────────────────────── */

.an-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 12px;
    margin-bottom: 24px;
}

.an-card {
    background: var(--an-bg);
    border: 1px solid var(--an-border);
    border-radius: var(--an-radius);
    padding: 14px 16px;
    text-align: center;
}

.an-card-value {
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--an-accent);
    line-height: 1.1;
}

.an-card-label {
    font-size: .75rem;
    color: var(--an-muted);
    margin-top: 4px;
    text-transform: uppercase;
    letter-spacing: .04em;
}

.an-card-sub {
    font-size: .75rem;
    color: var(--an-muted);
    margin-top: 2px;
}

/* ── Section title ────────────────────────────────────────────────────────── */

.an-section-title {
    font-size: .78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--an-muted);
    margin-bottom: 10px;
}

/* ── History chart ────────────────────────────────────────────────────────── */

.an-chart-wrap {
    margin-bottom: 24px;
}

.an-chart {
    display: flex;
    align-items: flex-end;
    gap: 3px;
    height: 80px;
    padding-bottom: 22px;
    position: relative;
}

.an-chart-bar-wrap {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    height: 100%;
    gap: 3px;
    cursor: default;
    position: relative;
}

.an-chart-bar {
    width: 100%;
    min-width: 4px;
    background: var(--an-bar);
    border-radius: 3px 3px 0 0;
    transition: background .1s;
    min-height: 2px;
}

.an-chart-bar-wrap:hover .an-chart-bar { background: var(--an-bar-hi); }

.an-chart-date {
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    font-size: .62rem;
    color: var(--an-muted);
    white-space: nowrap;
    pointer-events: none;
}

/* Tooltip on hover */
.an-chart-bar-wrap::after {
    content: attr(data-tip);
    position: absolute;
    bottom: calc(100% - 18px);
    left: 50%;
    transform: translateX(-50%);
    background: #2d3748;
    color: #fff;
    font-size: .72rem;
    padding: 4px 8px;
    border-radius: 5px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity .12s;
    z-index: 10;
}

.an-chart-bar-wrap:hover::after { opacity: 1; }

.an-chart-empty {
    color: var(--an-muted);
    font-size: .85rem;
    font-style: italic;
    padding: 16px 0;
}

/* ── Split layout for tables ──────────────────────────────────────────────── */

.an-split {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

@media (max-width: 680px) {
    .an-split { grid-template-columns: 1fr; }
}

/* ── Data table ───────────────────────────────────────────────────────────── */

.an-table-wrap { overflow-x: auto; }

.an-table {
    width: 100%;
    border-collapse: collapse;
    font-size: .82rem;
}

.an-table th {
    padding: 8px 10px;
    text-align: left;
    font-size: .72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--an-muted);
    background: var(--an-bg);
    border-bottom: 1px solid var(--an-border);
    white-space: nowrap;
    cursor: pointer;
    user-select: none;
}

.an-table th:hover { color: var(--an-text); }
.an-table th.sort-asc::after  { content: ' ▲'; font-size: .65rem; }
.an-table th.sort-desc::after { content: ' ▼'; font-size: .65rem; }

.an-table td {
    padding: 8px 10px;
    border-bottom: 1px solid var(--an-border);
    vertical-align: middle;
    color: var(--an-text);
}

.an-table tr:last-child td { border-bottom: none; }
.an-table tr:hover td { background: #fafbfc; }

.an-table td.an-num {
    text-align: right;
    font-variant-numeric: tabular-nums;
    color: var(--an-muted);
}

.an-table td.an-slug {
    font-family: monospace;
    font-size: .8rem;
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.an-rank {
    color: var(--an-muted);
    font-size: .75rem;
    min-width: 18px;
    display: inline-block;
    text-align: right;
}

/* ── Empty state ──────────────────────────────────────────────────────────── */

.an-empty {
    color: var(--an-muted);
    font-size: .85rem;
    font-style: italic;
    padding: 10px 0;
}

/* ── Event counters row ───────────────────────────────────────────────────── */

.an-events {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 24px;
}

.an-event-badge {
    display: flex;
    flex-direction: column;
    align-items: center;
    background: var(--an-bg);
    border: 1px solid var(--an-border);
    border-radius: var(--an-radius);
    padding: 10px 16px;
    min-width: 110px;
    text-align: center;
}

.an-event-total {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--an-accent);
}

.an-event-label {
    font-size: .72rem;
    color: var(--an-muted);
    text-transform: uppercase;
    letter-spacing: .04em;
    margin-top: 2px;
}

.an-event-today {
    font-size: .72rem;
    color: var(--an-green);
    margin-top: 3px;
}

/* ── Triple split (time / search / today) ─────────────────────────────────── */

.an-triple {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 20px;
    margin-top: 20px;
}

@media (max-width: 900px) {
    .an-triple { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 600px) {
    .an-triple { grid-template-columns: 1fr; }
}

/* ── Time badge inside table ──────────────────────────────────────────────── */

.an-time-badge {
    display: inline-block;
    background: #e8f0fb;
    color: var(--an-accent);
    border-radius: 4px;
    padding: 1px 6px;
    font-size: .78rem;
    font-variant-numeric: tabular-nums;
}

/* ── File downloads section ───────────────────────────────────────────────── */

.an-global {
    border-top: 1px solid var(--an-border);
    padding: 20px;
}

.an-global-title {
    font-weight: 600;
    font-size: .95rem;
    margin-bottom: 14px;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* ── "No data" full panel ─────────────────────────────────────────────────── */

.an-no-data {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 40px 20px;
    color: var(--an-muted);
    font-size: .9rem;
}

.an-no-data-icon { font-size: 2rem; opacity: .35; }
