:root {
    color-scheme: dark;
    --panel-soft: var(--surface-floating);
    --muted: var(--text-muted);
    --chart-primary: #a8b89e;
    --chart-secondary: #c2a36d;
    --chart-tertiary: #b47766;
    --chart-muted: #5d5b58;
    --purple: #97889d;
    --pink: #ad7f88;
    --orange: #b98a62;
    --green: #829a87;
}

* {
    box-sizing: border-box;
}

button,
input,
select {
    font: inherit;
}

.usage-app .main-shell {
    overflow: hidden;
}

.usage-app .tab-panel .usage-stage {
    display: flex;
    flex-direction: column;
    min-height: 100%;
    height: 100%;
    overflow: auto;
    padding: 16px 18px;
}

.usage-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    padding: 6px 0 16px;
}

.kicker {
    margin: 0;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.11em;
    font-size: 11px;
    font-weight: 600;
}

.usage-head h1 {
    margin: 6px 0 0;
    font-size: 28px;
    line-height: 1.05;
    font-weight: 650;
    letter-spacing: -0.03em;
    text-wrap: balance;
}

.usage-filters {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 8px;
}

.usage-filters .usage-hidden-control {
    display: none;
}

.project-filter {
    position: relative;
}

.project-trigger {
    display: inline-flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    min-height: 40px;
    border: 0;
    padding: 0 12px;
    border-radius: 12px;
    color: var(--text);
    background: var(--surface-raised);
    box-shadow: var(--shadow-border);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition:
        background 160ms ease,
        color 160ms ease,
        box-shadow 160ms ease,
        transform 160ms ease;
}

.project-trigger:hover {
    box-shadow: var(--shadow-border-hover);
}

.project-trigger:active {
    transform: scale(0.96);
}

.project-popover {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    z-index: 31;
    width: 190px;
    padding: 6px;
    border: 0;
    border-radius: 14px;
    background: var(--surface-floating);
    box-shadow: var(--shadow-border), 0 20px 44px rgba(0, 0, 0, 0.36);
}

.project-popover[hidden] {
    display: none;
}

.project-popover button {
    width: 100%;
    min-height: 40px;
    border: 0;
    border-radius: 9px;
    padding: 0 10px;
    color: var(--text);
    background: transparent;
    text-align: left;
    cursor: pointer;
    transition:
        background 160ms ease,
        color 160ms ease,
        transform 160ms ease;
}

.project-popover button:hover,
.project-popover button.is-active {
    background: rgba(255, 255, 255, 0.12);
}

.project-popover button:active {
    transform: scale(0.96);
}

.period-trigger {
    display: inline-flex;
    align-items: center;
    gap: 9px;
    min-height: 40px;
    width: auto;
    border: 0;
    border-radius: 12px;
    background: var(--surface-raised);
    box-shadow: var(--shadow-border);
    color: var(--text);
    padding: 0 12px;
    cursor: pointer;
    transition: background 160ms ease, color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

.period-trigger svg {
    width: 16px;
    height: 16px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
}

.period-chevron {
    display: inline-block;
    width: 7px;
    height: 7px;
    border-right: 1.5px solid currentColor;
    border-bottom: 1.5px solid currentColor;
    color: var(--muted);
    font-size: 0;
    line-height: 0;
    transform: translateY(-2px) rotate(45deg);
}

.group-filter {
    position: relative;
}

.group-trigger {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    min-height: 40px;
    width: auto;
    border: 0;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.065);
    color: var(--muted);
    padding: 0 10px;
    cursor: pointer;
    transition: background 160ms ease, color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

.period-trigger:hover,
.group-trigger:hover {
    box-shadow: var(--shadow-border-hover);
}

.period-trigger:active,
.group-trigger:active,
.period-presets button:active,
.group-popover button:active,
.calendar-nav:active,
.calendar-day:active,
.usage-tab:active {
    transform: scale(0.96);
}

.group-trigger.has-group {
    color: var(--text);
}

.group-clear {
    display: none;
    color: var(--muted);
    font-size: 16px;
    line-height: 1;
    text-align: center;
}

.group-trigger.has-group .group-clear {
    display: inline-block;
}

.group-popover {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    z-index: 31;
    width: 190px;
    padding: 6px;
    border: 0;
    border-radius: 14px;
    background: var(--surface-floating);
    box-shadow: var(--shadow-border), 0 20px 44px rgba(0, 0, 0, 0.36);
}

.group-popover[hidden] {
    display: none;
}

.group-popover button {
    width: 100%;
    min-height: 40px;
    border: 0;
    border-radius: 9px;
    background: transparent;
    color: var(--text);
    padding: 0 10px;
    text-align: left;
    cursor: pointer;
    transition: background 160ms ease, color 160ms ease, transform 160ms ease;
}

.group-popover button.is-active,
.group-popover button:hover {
    background: rgba(255, 255, 255, 0.12);
}

.period-popover {
    position: absolute;
    top: calc(100% + 10px);
    right: 0;
    z-index: 30;
    display: grid;
    grid-template-columns: 190px minmax(0, 1fr);
    width: min(800px, calc(100vw - 260px));
    min-width: 720px;
    border: 0;
    border-radius: 16px;
    background: var(--surface-floating);
    box-shadow: var(--shadow-border), 0 24px 54px rgba(0, 0, 0, 0.38);
    overflow: hidden;
}

.period-popover[hidden] {
    display: none;
}

.period-presets {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 10px;
    border-right: 1px solid var(--line);
}

.period-presets button,
.calendar-day {
    border: 0;
    background: transparent;
    color: var(--text);
    cursor: pointer;
}

.period-presets button {
    min-height: 40px;
    border-radius: 9px;
    padding: 0 10px;
    text-align: left;
    white-space: nowrap;
    transition: background 160ms ease, color 160ms ease, transform 160ms ease;
}

.period-presets button.is-active,
.period-presets button:hover {
    background: rgba(255, 255, 255, 0.12);
}

.period-calendars {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px;
    padding: 14px 16px 18px;
}

.calendar-title {
    display: grid;
    grid-template-columns: 40px 1fr 40px;
    align-items: center;
    margin-bottom: 14px;
    text-align: center;
    color: var(--text);
    font-size: 13px;
    font-weight: 650;
}

.calendar-title span {
    white-space: nowrap;
}

.calendar-nav {
    width: 40px;
    height: 40px;
    border: 0;
    background: transparent;
    color: var(--muted);
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    transition: color 160ms ease, transform 160ms ease;
}

.calendar-nav-spacer {
    width: 40px;
    height: 40px;
}

.calendar-nav:hover {
    color: var(--text);
}

.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 32px);
    gap: 3px;
    justify-content: center;
}

.calendar-weekday {
    color: var(--muted);
    font-size: 11px;
    text-align: center;
}

.calendar-day {
    min-height: 32px;
    border-radius: 8px;
    font-size: 13px;
    transition: background 160ms ease, color 160ms ease, transform 160ms ease;
}

.calendar-day:hover,
.calendar-day.is-in-range {
    background: rgba(255, 255, 255, 0.09);
}

.calendar-day.is-edge {
    background: var(--chart-primary);
    color: var(--accent-ink);
}

.calendar-day.is-muted {
    color: #777;
}

.usage-layout {
    flex: 1;
    min-height: 0;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 320px;
    overflow: hidden;
}

.usage-main {
    min-width: 0;
    padding: 22px 22px 0 0;
}

.usage-side {
    min-width: 0;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 22px 0 0 18px;
}

.spend-panel {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    gap: 20px;
    min-height: 540px;
    padding: 20px;
    border-radius: 20px;
    background: var(--surface);
    box-shadow: var(--shadow-border), var(--shadow-soft);
}

.spend-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
}

.metric-head {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin: 0 0 2px;
}

.metric-head span,
.side-label {
    color: var(--muted);
    font-size: 13px;
    text-wrap: pretty;
}

.metric-head strong {
    font-size: 24px;
    line-height: 1;
}

.metric-head strong {
    font-size: 34px;
    font-variant-numeric: tabular-nums;
}

.side-card > strong {
    font-size: 26px;
    line-height: 1;
    font-variant-numeric: tabular-nums;
}

.bar-chart,
.mini-chart,
.sparkline {
    position: relative;
    width: 100%;
    min-width: 0;
    overflow: hidden;
}

.bar-chart {
    height: 390px;
    padding-top: 4px;
}

.chart-svg {
    display: block;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

.axis-text {
    fill: #8b8b91;
    font-size: 12px;
}

.grid-line {
    stroke: rgba(255, 255, 255, 0.085);
    stroke-dasharray: 3 4;
}

.usage-bar {
    opacity: 0.88;
    transition: opacity 160ms ease, filter 160ms ease;
}

.usage-bar:hover,
.usage-bar:focus-visible {
    opacity: 1;
    filter: brightness(1.14);
}

.bar {
    fill: var(--chart-primary);
    opacity: 0.92;
}

.bar:hover {
    opacity: 1;
}

.side-card {
    box-shadow: var(--shadow-border);
    background: var(--surface);
}

.mini-chart {
    height: 155px;
}

.mini-chart.small {
    height: 72px;
    margin-top: 14px;
}

.sparkline {
    height: 74px;
    margin-top: 14px;
}

.token-canvas {
    display: block;
    width: 100%;
    height: 100%;
}

.thread-canvas {
    display: block;
    width: 100%;
    height: 100%;
}

.usage-side .side-card {
    min-width: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 22px 18px;
    border-radius: 16px;
    box-shadow: var(--shadow-border);
}

.usage-side .side-card:nth-child(1),
.usage-side .side-card:nth-child(2) {
    flex: 0 0 196px;
}

.usage-side .side-card:nth-child(3) {
    flex: 1 1 0;
    min-height: 0;
}

.usage-side .side-card:first-child {
    background:
        linear-gradient(135deg, rgba(255, 255, 255, 0.045), transparent 58%),
        var(--surface);
}

.usage-side .side-card:nth-child(2) {
    background:
        linear-gradient(135deg, rgba(255, 255, 255, 0.025), transparent 58%),
        var(--surface);
}

.rank-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 12px;
}

.rank-row span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.bar-track {
    grid-column: 1 / -1;
    height: 8px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.075);
}

.bar-fill {
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, var(--chart-primary), var(--chart-secondary));
}

.usage-tabs {
    display: flex;
    gap: 16px;
    margin-bottom: 16px;
    border-bottom: 1px solid var(--line);
}

.usage-tab {
    border: 0;
    border-bottom: 1px solid transparent;
    background: transparent;
    color: var(--muted);
    min-height: 40px;
    padding: 0 0 12px;
    cursor: pointer;
    transition: color 160ms ease, border-color 160ms ease, transform 160ms ease;
}

.usage-tab.is-active {
    border-color: var(--chart-primary);
    color: var(--text);
    font-weight: 650;
}

.rank-list {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    gap: 8px;
    min-height: 0;
    padding-right: 4px;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-gutter: stable;
}

.rank-row {
    padding: 9px 10px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.045);
}

.rank-row strong {
    font-size: 13px;
    font-variant-numeric: tabular-nums;
}

.tooltip {
    position: fixed;
    z-index: 20;
    display: none;
    max-width: 310px;
    padding: 12px;
    border: 0;
    border-radius: 10px;
    background: var(--surface-floating);
    color: var(--text);
    box-shadow: var(--shadow-border), 0 16px 34px rgba(0, 0, 0, 0.35);
    pointer-events: none;
}

.tooltip.is-visible {
    display: block;
}

.tooltip-title {
    margin-bottom: 10px;
    color: var(--text);
    font-size: 12px;
}

.tooltip-total {
    margin: -2px 0 10px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--line);
    color: var(--text);
    font-size: 15px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.tooltip-row {
    display: grid;
    grid-template-columns: 10px minmax(0, 1fr) auto;
    align-items: center;
    gap: 8px;
    color: var(--muted);
    font-size: 12px;
}

.tooltip-row strong,
.axis-text {
    font-variant-numeric: tabular-nums;
}

.tooltip-dot {
    width: 10px;
    height: 10px;
    border-radius: 3px;
    background: var(--purple);
}

@media (max-width: 1180px) {
    .usage-head {
        padding-right: 0;
    }

    .period-popover {
        width: min(800px, calc(100vw - 76px));
        min-width: 720px;
    }
}

@media (max-width: 860px) {
    .usage-app .main-shell {
        overflow: visible;
    }

    .usage-app .tab-panel .usage-stage {
        height: auto;
        min-height: 100vh;
        overflow: visible;
        padding: 16px;
    }

    .usage-head {
        align-items: flex-start;
        flex-direction: column;
        gap: 14px;
        padding: 0 0 16px;
    }

    .usage-head h1 {
        font-size: 28px;
    }

    .usage-filters {
        width: 100%;
        justify-content: flex-start;
    }

    .period-trigger,
    .project-trigger,
    .group-trigger {
        width: 100%;
        justify-content: space-between;
    }

    .project-filter {
        width: 100%;
    }

    .project-popover {
        width: min(240px, calc(100vw - 32px));
    }

    .period-popover {
        position: fixed;
        top: 86px;
        right: 12px;
        left: 12px;
        grid-template-columns: 1fr;
        width: auto;
        min-width: 0;
        max-height: calc(100dvh - 108px);
        overflow: auto;
    }

    .period-presets {
        border-right: 0;
        border-bottom: 1px solid var(--line);
    }

    .period-calendars {
        grid-template-columns: 1fr;
    }

    .calendar-grid {
        grid-template-columns: repeat(7, minmax(0, 1fr));
    }

    .calendar-day {
        min-height: 40px;
    }

    .group-popover {
        right: auto;
        left: 0;
        width: min(240px, calc(100vw - 32px));
    }

    .usage-layout {
        grid-template-columns: 1fr;
        overflow: visible;
    }

    .usage-main {
        padding: 18px 0 0;
        border-right: 0;
    }

    .usage-side {
        overflow: visible;
        padding: 16px 0 0;
    }

    .usage-side .side-card:nth-child(1),
    .usage-side .side-card:nth-child(2) {
        flex-basis: auto;
        min-height: 190px;
    }

    .usage-side .side-card:nth-child(3) {
        flex: 0 0 auto;
    }

    .rank-list {
        max-height: min(360px, 45dvh);
    }

    .spend-panel {
        min-height: auto;
    }

    .spend-head {
        flex-direction: column;
        align-items: stretch;
    }

    .bar-chart {
        height: 320px;
        overflow-x: auto;
    }

    .chart-svg {
        min-width: 560px;
    }
}

.empty {
    color: var(--muted);
    font-size: 13px;
    text-wrap: pretty;
}
