/* ============================================================
   Analytics pages - layout primitives
   Panels, grids, meters, lists and pills used by the pages under
   /analytics. Built only on the --pm-* tokens from app.css, so
   light/dark mode comes for free.
   ============================================================ */

/* Tone variables: .tone-* on any element exposes --tone / --tone-tint */
.tone-primary { --tone: var(--pm-primary); --tone-tint: var(--pm-primary-tint); }
.tone-success { --tone: var(--pm-success); --tone-tint: var(--pm-success-tint); }
.tone-info    { --tone: var(--pm-info);    --tone-tint: var(--pm-info-tint); }
.tone-warning, .tone-amber { --tone: var(--pm-warning); --tone-tint: var(--pm-warning-tint); }
.tone-danger  { --tone: var(--pm-danger);  --tone-tint: var(--pm-danger-tint); }
.tone-violet  { --tone: var(--pm-violet);  --tone-tint: var(--pm-violet-tint); }
.tone-neutral { --tone: var(--pm-neutral); --tone-tint: var(--pm-neutral-tint); }

/* ── Page shell ───────────────────────────────────────────── */
.analytics-page {
    padding-block: 1.5rem 2.5rem;
}

.analytics-head {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.25rem;
}

.analytics-head h1 {
    font-family: var(--app-font-display);
    font-size: 1.6rem;
    font-weight: 800;
    margin: 0;
    color: var(--pm-text);
    text-wrap: balance;
}

.analytics-head p {
    margin: 0.25rem 0 0;
    color: var(--pm-text-muted);
    max-width: 62ch;
}

.analytics-head .head-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
}

/* Sub-navigation between the analytics pages */
.analytics-nav {
    display: flex;
    gap: 0.25rem;
    padding: 0.3rem;
    margin-bottom: 1.5rem;
    background: var(--pm-surface);
    border: 1px solid var(--pm-border);
    border-radius: var(--pm-radius-lg);
    overflow-x: auto;
    scrollbar-width: none;
}

.analytics-nav::-webkit-scrollbar { display: none; }

.analytics-nav a {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.55rem 0.9rem;
    border-radius: calc(var(--pm-radius-lg) - 5px);
    color: var(--pm-text-muted);
    font-weight: 600;
    font-size: 0.875rem;
    white-space: nowrap;
    text-decoration: none;
    transition: background 0.15s, color 0.15s;
}

.analytics-nav a:hover {
    background: var(--pm-surface-2);
    color: var(--pm-text);
}

.analytics-nav a.active {
    background: var(--pm-primary);
    color: #ffffff;
}

.analytics-nav a i { font-size: 0.85rem; }

/* Plain-English headline under the page title */
.headline {
    display: flex;
    gap: 0.9rem;
    align-items: flex-start;
    padding: 1rem 1.25rem;
    margin-bottom: 1.5rem;
    background: var(--tone-tint, var(--pm-primary-tint));
    border-radius: var(--pm-radius-lg);
    color: var(--pm-text);
    line-height: 1.55;
}

.headline > i {
    color: var(--tone, var(--pm-primary));
    font-size: 1.1rem;
    margin-top: 0.15rem;
}

.headline strong { font-weight: 700; }

/* ── Stat cards (extends .stat from shared-components.css) ── */
.stat-grid {
    display: grid;
    gap: 1rem;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    margin-bottom: 1.5rem;
}

a.stat { text-decoration: none !important; color: inherit; }

.stat.stat-static { cursor: default; }
.stat.stat-static:hover {
    transform: none;
    border-color: var(--pm-border);
    box-shadow: var(--pm-shadow-sm);
}

.stat-value small {
    font-family: var(--app-font-family);
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--pm-text-muted);
    margin-right: 0.2rem;
    letter-spacing: 0;
}

/* ── Panels ────────────────────────────────────────────────── */
.panel {
    background: var(--pm-surface);
    border: 1px solid var(--pm-border);
    border-radius: var(--pm-radius-lg);
    box-shadow: var(--pm-shadow-sm);
    min-width: 0;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem 1rem;
    flex-wrap: wrap;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--pm-border);
}

.panel-title {
    font-family: var(--app-font-display);
    font-size: 1rem;
    font-weight: 700;
    margin: 0;
    color: var(--pm-text);
}

.panel-subtitle {
    font-size: 0.8125rem;
    color: var(--pm-text-muted);
    margin: 0.15rem 0 0;
}

.panel-body { padding: 1.25rem; }
.panel-body.flush { padding: 0; }

.panel-footer {
    padding: 0.8rem 1.25rem;
    border-top: 1px solid var(--pm-border);
    background: var(--pm-surface-2);
    border-radius: 0 0 var(--pm-radius-lg) var(--pm-radius-lg);
    font-size: 0.8125rem;
    color: var(--pm-text-muted);
}

.panel-footer a { color: var(--pm-primary); font-weight: 600; text-decoration: none; }

.panel-link {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--pm-primary);
    text-decoration: none;
    white-space: nowrap;
}

/* ── Grids ─────────────────────────────────────────────────── */
.grid-2, .grid-3, .grid-main-side {
    display: grid;
    gap: 1.25rem;
    margin-bottom: 1.25rem;
}

.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); align-items: start; }
.grid-main-side { grid-template-columns: minmax(0, 1fr) 380px; align-items: start; }

.stack { display: flex; flex-direction: column; gap: 1rem; }

@media (max-width: 1100px) {
    .grid-main-side, .grid-3 { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 768px) {
    .grid-2 { grid-template-columns: minmax(0, 1fr); }
    .analytics-head h1 { font-size: 1.35rem; }
}

/* ── Meters (labelled share-of-total bars) ─────────────────── */
.meter { display: flex; flex-direction: column; gap: 0.4rem; }

.meter-head {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    font-size: 0.8125rem;
}

.meter-head .label {
    color: var(--pm-text);
    font-weight: 600;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.meter-head .value {
    color: var(--pm-text);
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.meter-head .value small { color: var(--pm-text-muted); font-weight: 500; }

.meter-bar {
    height: 8px;
    border-radius: 999px;
    background: var(--pm-surface-2);
    overflow: hidden;
}

.meter-bar > span {
    display: block;
    height: 100%;
    border-radius: inherit;
    background: var(--tone, var(--pm-primary));
    transition: width 0.6s cubic-bezier(0.2, 0.8, 0.2, 1);
}

/* ── Lists ─────────────────────────────────────────────────── */
.list { list-style: none; margin: 0; padding: 0; }

.list-row {
    display: flex;
    align-items: center;
    gap: 0.875rem;
    padding: 0.8rem 1.25rem;
    border-bottom: 1px solid var(--pm-border);
    min-width: 0;
}

.list-row:last-child { border-bottom: 0; }
.list-row .main { flex: 1; min-width: 0; }

.list-row .title {
    font-weight: 600;
    color: var(--pm-text);
    font-size: 0.9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.list-row .meta {
    color: var(--pm-text-muted);
    font-size: 0.78rem;
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    align-items: center;
}

.list-row .end { text-align: right; flex-shrink: 0; }

.list-row .amount {
    font-family: var(--app-font-mono);
    font-variant-numeric: tabular-nums;
    font-weight: 700;
    color: var(--pm-text);
}

.icon-tile {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    display: grid;
    place-items: center;
    background: var(--tone-tint, var(--pm-neutral-tint));
    color: var(--tone, var(--pm-neutral));
    flex-shrink: 0;
}

/* ── Pills ─────────────────────────────────────────────────── */
.pill {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.12rem 0.55rem;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 700;
    white-space: nowrap;
    background: var(--tone-tint, var(--pm-neutral-tint));
    color: var(--tone, var(--pm-neutral));
}

/* ── Tables inside panels ──────────────────────────────────── */
.table-wrap { overflow-x: auto; }

.table-wrap .table { margin: 0; color: var(--pm-text); }

.table-wrap .table th {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--pm-text-muted);
    background: var(--pm-surface-2);
    border-bottom: 1px solid var(--pm-border);
    padding: 0.65rem 1rem;
    white-space: nowrap;
}

.table-wrap .table td {
    padding: 0.7rem 1rem;
    border-color: var(--pm-border);
    vertical-align: middle;
    background: transparent;
    color: var(--pm-text);
}

.table-wrap .table tfoot td {
    font-weight: 700;
    background: var(--pm-surface-2);
}

.cell-num {
    text-align: right;
    font-family: var(--app-font-mono);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.cell-muted { color: var(--pm-text-muted) !important; }
.cell-strong { font-weight: 700; }

/* ── Profit & loss statement ───────────────────────────────── */
.pnl .pnl-section td {
    background: var(--pm-surface-2);
    color: var(--pm-text-muted);
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.pnl .pnl-subtotal td {
    font-weight: 700;
    border-top: 2px solid var(--pm-border);
}

.pnl .pnl-indent { padding-left: 2rem !important; }

.pnl .pnl-total td {
    font-size: 1.02rem;
    font-weight: 800;
    border-top: 2px solid var(--pm-text-muted);
}

/* ── Controls ──────────────────────────────────────────────── */
.period-picker {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
}

.period-picker .form-select,
.period-picker .form-control {
    width: auto;
    min-width: 150px;
    background-color: var(--pm-surface);
    border-color: var(--pm-border);
    color: var(--pm-text);
}

.segmented {
    display: inline-flex;
    padding: 0.2rem;
    border-radius: 10px;
    background: var(--pm-surface-2);
    border: 1px solid var(--pm-border);
}

.segmented button {
    border: 0;
    background: transparent;
    color: var(--pm-text-muted);
    font-weight: 600;
    font-size: 0.8125rem;
    padding: 0.35rem 0.8rem;
    border-radius: 8px;
}

.segmented button.active {
    background: var(--pm-surface);
    color: var(--pm-text);
    box-shadow: var(--pm-shadow-sm);
}

.btn-quiet {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.45rem 0.85rem;
    border-radius: 10px;
    border: 1px solid var(--pm-border);
    background: var(--pm-surface);
    color: var(--pm-text);
    font-weight: 600;
    font-size: 0.875rem;
}

.btn-quiet:hover:not(:disabled) { border-color: var(--pm-primary); color: var(--pm-primary); }
.btn-quiet:disabled { opacity: 0.55; }

/* ── Empty / loading states ────────────────────────────────── */
.an-empty {
    text-align: center;
    padding: 2.25rem 1.25rem;
    color: var(--pm-text-muted);
}

.an-empty i {
    font-size: 1.6rem;
    color: var(--pm-border);
    margin-bottom: 0.6rem;
    display: block;
}

.an-empty .an-empty-title {
    font-weight: 700;
    color: var(--pm-text);
    margin-bottom: 0.2rem;
}

.an-empty p { margin: 0; font-size: 0.875rem; }

.loading-block {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    padding: 4rem 1rem;
    color: var(--pm-text-muted);
}

.text-danger-soft { color: var(--pm-danger) !important; }
.text-success-soft { color: var(--pm-success) !important; }
