/* Cost Dashboard Styles */

/* ── Sort & Filter ──────────────────────────────────────── */

.cost-th-sort {
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
    position: relative;
}

.cost-th-sort:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}

/* The label of a sortable header is a button (#5042): it looks as the header text did and shows a focus ring. */
.cost-sort-btn {
    font: inherit;
    color: inherit;
    letter-spacing: inherit;
    text-transform: inherit;
    text-align: inherit;
    background: none;
    border: 0;
    padding: 0;
    cursor: pointer;
}

.cost-sort-btn:focus-visible,
.cost-col-filter:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: var(--radius-xs);
}

/* Filter icon inside column header */
.cost-col-filter {
    display: inline-flex;
    align-items: center;
    margin-left: 3px;
    padding: 1px;
    border-radius: var(--radius-xs);
    vertical-align: middle;
    cursor: pointer;
    color: inherit;
    background: none;
    border: 0;
    opacity: 0.4;
    transition: opacity 0.15s;
}

.cost-col-filter:hover {
    opacity: 1;
    background: var(--bg-hover);
}

.cost-col-filter.cost-filter-active {
    opacity: 1;
    color: var(--accent);
}

/* On a touch screen the header's two controls are 44 px (#5053): the label button fills the header's height, and the filter icon is a 44 px button with the glyph centred.
 * The header row grows from 33 to 44 px; a fine pointer keeps the compact sizes above. */
@media (pointer: coarse) {
    .cost-table thead th.cost-th-sort { padding-top: 0; padding-bottom: 0; } /* the buttons carry the height: the cell's own padding would add 18 px to them */
    .cost-sort-btn { min-width: 44px; min-height: 44px; vertical-align: middle; white-space: normal; max-width: 6em; } /* a long heading ("Thinking level") takes two lines inside the button, the filter stays beside it (#5056); in em so it grows with large text: 72 px was narrower than "Provider" at 200% (#5058) */
    .cost-col-filter { min-width: 44px; min-height: 44px; justify-content: center; margin: 0 -8px; } /* its 44 px hit area overlaps the label's end and the cell's padding, so the column is no wider than before and Cost stays on screen (#5056) */
}

/* On a phone the columns sit closer, so more of them fit before the card scrolls (#5056). */
@media (max-width: 767px) {
    .cost-table thead th, .cost-table tbody td { padding-left: 4px; padding-right: 4px; }
}

/* Filter dropdown */
.cost-filter-dropdown {
    z-index: 1000;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    width: 200px;
    max-height: 320px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.cost-filter-search {
    padding: 8px 10px;
    font-size: var(--fs-md);
    color: var(--text-primary);
    background: var(--bg-secondary);
    border: none;
    border-bottom: 1px solid var(--border);
    outline: none;
    font-family: var(--font-sans);
}

.cost-filter-search::placeholder {
    color: var(--text-muted);
}

.cost-filter-actions {
    display: flex;
    gap: 4px;
    padding: 4px 8px;
    border-bottom: 1px solid var(--border);
}

.cost-filter-action-btn {
    font-size: var(--fs-md);
    color: var(--accent);
    background: none;
    border: none;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: var(--radius-xs);
}

.cost-filter-action-btn:hover {
    background: var(--bg-hover);
}

.cost-filter-items {
    overflow-y: auto;
    max-height: 240px;
    padding: 4px 0;
}

.cost-filter-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    font-size: var(--fs-base);
    color: var(--text-primary);
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.cost-filter-item:hover {
    background: var(--bg-hover);
}

.cost-filter-item input[type="checkbox"] {
    flex-shrink: 0;
    accent-color: var(--accent);
}

.cost-dashboard-view {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    padding: 24px 32px;
}

.cost-header {
    display: flex;
    flex-wrap: wrap; /* #4344: at large text the title and the controls wrap instead of the select running off the right edge */
    gap: 8px;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    flex-shrink: 0;
}

.cost-header h2 {
    font-size: var(--type-page-size);
    font-weight: 600;
    margin: 0;
}

.cost-header-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    min-width: 0;
    max-width: 100%;
}

.cost-time-select {
    min-height: var(--control-compact-height);
    font-family: var(--font-sans);
    background: var(--bg-secondary);
    border: 1px solid var(--control-border);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    padding: 4px 8px;
    font-size: var(--fs-md);
    cursor: pointer;
}

/* Summary Cards */
.cost-summary-cards {
    display: flex;
    gap: 12px;
    margin-bottom: 24px;
    flex-wrap: wrap;
    flex-shrink: 0;
}

.cost-card {
    flex: 1;
    min-width: 120px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 14px 16px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.cost-card-label {
    font-size: var(--fs-base);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: var(--text-secondary);
}

.cost-card-value {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
}

/* Sections */
.cost-section {
    margin-bottom: 24px;
}

.cost-section-title {
    font-size: var(--fs-xl);
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.cost-table-container {
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow-x: auto; /* a wide table scrolls inside its box on a phone instead of being cut off (#4589) */
    overflow-y: hidden;
}

.cost-empty {
    padding: 24px;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.8125rem;
}

/* Tables */
.cost-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.75rem;
}

.cost-table thead th {
    background: var(--bg-secondary);
    padding: 8px 12px;
    text-align: left;
    font-weight: 600;
    font-size: var(--fs-base);
    text-transform: uppercase;
    letter-spacing: 0.3px;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.cost-table tbody td {
    padding: 6px 12px;
    border-bottom: 1px solid var(--border-subtle);
    color: var(--text-primary);
    white-space: nowrap;
}

.cost-table tbody tr:last-child td {
    border-bottom: none;
}

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

.cost-col-right {
    text-align: right !important;
    font-variant-numeric: tabular-nums;
}

.cost-cost-cell {
    font-weight: 600;
    color: var(--accent);
}

.cost-agent-name {
    font-weight: 500;
    max-width: 160px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.cost-agent-link {
    color: var(--accent);
    text-decoration: none;
    cursor: pointer;
}

.cost-agent-link:hover {
    text-decoration: underline;
}

.cost-agent-terminated {
    opacity: 0.7;
}

.cost-agent-ended {
    font-size: var(--fs-sm);
    color: var(--text-muted);
    font-weight: 400;
}

.cost-date {
    color: var(--text-secondary);
    font-size: var(--fs-base);
}

/* Agent type badges */

/* Model name */
.cost-model-name {
    font-family: var(--font-mono, monospace);
    font-size: 0.6875rem;
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Status badges */
.cost-status {
    font-size: var(--fs-base);
    font-weight: 600;
    padding: 1px 6px;
    border-radius: var(--radius-xs);
    text-transform: uppercase;
}

.cost-status-ok {
    background: rgba(var(--fx-green-rgb), 0.15);
    color: var(--success);
}

.cost-status-error {
    background: rgba(var(--fx-red-rgb), 0.15);
    color: var(--error);
}

.cost-status-pending {
    background: rgba(var(--fx-grey-rgb), 0.12);
    color: var(--text-muted);
}

/* ── Live Indicator ──────────────────────────────────────── */

.cost-header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.cost-live-indicator {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: var(--fs-base);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--success);
    opacity: 0.7;
    transition: opacity 0.3s;
}

.cost-live-indicator.cost-live-flash {
    opacity: 1;
}

.cost-live-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--success);
    animation: cost-pulse 2s ease-in-out infinite;
}

@keyframes cost-pulse {
    0%, 100% { opacity: 0.4; transform: scale(1); }
    50% { opacity: 1; transform: scale(1.3); }
}

/* ── Summary Card Enhancements ──────────────────────────── */

.cost-card-sparkline {
    margin-top: 4px;
    height: 24px;
    overflow: hidden;
}

.cost-card-sparkline svg {
    display: block;
}

.cost-card-highlight {
    border-color: var(--accent-dim);
    background: color-mix(in srgb, var(--accent) 8%, var(--bg-secondary));
}

.cost-card-highlight .cost-card-value {
    color: var(--accent);
    font-size: 1.375rem;
}

.cost-card-burn .cost-card-value {
    font-size: 1rem;
    color: var(--warning);
}

/* ── Cumulative Spend Chart ─────────────────────────────── */

.cost-chart-container {
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 12px;
    background: var(--bg-secondary);
    overflow: hidden;
}

.spend-chart-svg {
    display: block;
    width: 100%;
}

.spend-grid {
    stroke: var(--border);
    stroke-width: 0.5;
}

.spend-area {
    fill: rgba(var(--accent-rgb), 0.08);
}

.spend-line {
    fill: none;
    stroke: var(--accent);
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.spend-dot {
    fill: var(--accent);
}

.spend-bar {
    fill: rgba(var(--accent-rgb), 0.15);
}

.spend-label {
    font-size: 0.625rem;
    fill: var(--text-muted);
    font-family: var(--font-mono, monospace);
}

/* ── Team Share Bar ─────────────────────────────────────── */

.cost-share-bar-wrapper {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 80px;
}

.cost-share-bar {
    height: 6px;
    border-radius: var(--radius-xs);
    background: var(--accent);
    transition: width 0.3s ease;
    min-width: 2px;
}

.cost-share-label {
    font-size: var(--fs-base);
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.cost-agent-team {
    color: var(--text-muted);
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.agent-cost-chart-tooltip {
    display: none;
    position: fixed;
    z-index: 1000;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    padding: 12px;
    box-shadow: 0 4px 16px rgba(var(--black-rgb), 0.3);
    pointer-events: none;
}
.agent-cost-chart-tooltip .chart-title {
    font-size: 0.6875rem;
    color: var(--text-muted);
    margin-bottom: 6px;
}
.agent-cost-chart-tooltip svg {
    display: block;
}
.agent-cost-chart-tooltip .chart-axis-label {
    font-size: 0.625rem;
    fill: var(--text-muted);
}
.agent-cost-chart-tooltip .chart-line {
    fill: none;
    stroke: var(--accent);
    stroke-width: 1.5;
}
.agent-cost-chart-tooltip .chart-area {
    fill: rgba(var(--accent-rgb), 0.1);
}
.agent-cost-chart-tooltip .chart-grid {
    stroke: var(--border-light);
    stroke-width: 0.5;
}

/* By Model shows a readable name ("Opus 5.5"), not an id, so it is not set in the code font (#4589). */
#cost-by-model .cost-model-name, #cost-by-thinking .cost-model-name { font-family: inherit; }
}

/* The usage with no thinking level recorded (#4969): not a level, so quieter than the rows that are. */
#cost-by-thinking .cost-table tr.cost-row-unreported td { color: var(--text-muted); }
