/* ============================================
   Usage Tab — Refined Design System
   ============================================ */

/* ---- Toolbar ---- */
.usage-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 18px;
}

.usage-toolbar-title {
    font-size: var(--font-size-title);
    font-weight: var(--font-weight-title);
    color: var(--color-text-primary);
    letter-spacing: -0.01em;
}

.usage-range-group {
    display: flex;
    gap: 4px;
    padding: 3px;
    border-radius: var(--radius-md);
    background: var(--color-surface-alt);
    border: 1px solid var(--color-border-soft);
}

.usage-range-btn {
    border: none;
    background: transparent;
    color: var(--color-text-tertiary);
    padding: 5px 11px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    font-family: var(--font-family);
    white-space: nowrap;
    transition: all 120ms var(--ease-spring);
    outline: none;
    -webkit-tap-highlight-color: transparent;
}

.usage-range-btn:hover:not(:disabled) {
    color: var(--color-text-secondary);
    background: var(--color-surface);
}

.usage-range-btn:active:not(:disabled) {
    transform: scale(0.97);
}

.usage-range-btn.active {
    color: #fff;
    background: var(--color-brand);
    box-shadow: 0 1px 3px rgba(200, 121, 99, 0.35);
}

.usage-range-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.usage-range-btn-icon {
    padding: 5px 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.usage-range-btn-icon svg {
    width: 14px;
    height: 14px;
}

/* ---- Current session bar ---- */
.usage-current-session-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    padding: 8px 14px;
    margin-bottom: 16px;
    border-radius: var(--radius-md);
    background: var(--color-surface-alt);
    font-size: 12px;
    color: var(--color-text-secondary);
}

.usage-current-session-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--color-success);
    flex-shrink: 0;
    animation: usage-pulse 2s ease-in-out infinite;
}

@keyframes usage-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

.usage-current-session-label {
    font-weight: 700;
    color: var(--color-text-primary);
}

.usage-current-session-stat {
    color: var(--color-text-tertiary);
}

.usage-current-session-stat::before {
    content: '·';
    margin-right: 10px;
    color: var(--color-border-strong);
}

/* ---- Summary cards ---- */
.usage-summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    gap: 10px;
    margin-bottom: 18px;
}

.usage-summary-card {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 2px;
    padding: 14px 16px;
    border-radius: var(--radius-md);
    background: var(--color-surface);
    border: 1px solid var(--color-border-soft);
    transition: all 120ms var(--ease-spring);
    min-height: 72px;
}

.usage-summary-card-value {
    font-size: 26px;
    font-weight: 700;
    color: var(--color-text-primary);
    line-height: 1.1;
    letter-spacing: -0.02em;
    font-variant-numeric: tabular-nums;
}

.usage-summary-card-label {
    font-size: 11px;
    font-weight: 500;
    color: var(--color-text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.usage-copyable {
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.usage-copyable:hover {
    border-color: var(--color-brand);
    background: var(--color-surface-alt);
}

.usage-copyable:active {
    transform: scale(0.98);
}

.usage-copyable:focus-visible {
    outline: 2px solid var(--color-brand-light);
    outline-offset: 2px;
}

/* ---- Content area ---- */
.usage-content {
    position: relative;
}

.usage-content-loading {
    opacity: 0.7;
    pointer-events: none;
}

.usage-content-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: flex-start;
    justify-content: flex-end;
    padding: 12px;
    z-index: 1;
}

.usage-spinner {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 2px solid var(--color-border-soft);
    border-top-color: var(--color-brand);
    animation: usage-spin 0.8s linear infinite;
}

@keyframes usage-spin {
    to { transform: rotate(360deg); }
}

/* ---- Cards ---- */
.usage-card {
    padding: 18px;
    border-radius: var(--radius-md);
    background: var(--color-surface);
    border: 1px solid var(--color-border-soft);
    margin-bottom: 12px;
}

.usage-card-head {
    margin-bottom: 14px;
}

.usage-card-title {
    font-size: 14px;
    font-weight: 700;
    color: var(--color-text-primary);
    margin-bottom: 2px;
}

.usage-card-subtitle {
    font-size: 11px;
    color: var(--color-text-muted);
}

/* ---- Chart grid ---- */
.usage-chart-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}

.usage-card-wide {
    grid-column: 1 / -1;
}

/* ---- Daily chart ---- */
.usage-daily-chart {
    display: flex;
    align-items: flex-end;
    gap: 4px;
    height: 140px;
    padding: 0 2px;
}

.usage-daily-bar-group {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    min-width: 0;
    -webkit-tap-highlight-color: transparent;
}

.usage-daily-bar-stack {
    width: 100%;
    max-width: 32px;
    height: 100px;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    position: relative;
    border-radius: 4px 4px 0 0;
    overflow: hidden;
    background: var(--color-surface-alt);
}

.usage-daily-bar-fill {
    width: 100%;
    border-radius: 4px 4px 0 0;
    background: var(--color-brand);
    transition: height 200ms var(--ease-spring);
    min-height: 2px;
}

.usage-daily-bar-prev {
    width: 100%;
    background: var(--color-text-muted);
    opacity: 0.35;
    border-radius: 4px 4px 0 0;
}

.usage-daily-bar-group.active .usage-daily-bar-fill {
    background: var(--color-brand-dark);
    box-shadow: 0 0 8px rgba(200, 121, 99, 0.3);
}

.usage-daily-bar-group:hover .usage-daily-bar-fill {
    filter: brightness(1.1);
}

.usage-daily-bar-label {
    font-size: 10px;
    color: var(--color-text-muted);
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

.usage-daily-bar-group.active .usage-daily-bar-label {
    color: var(--color-brand-dark);
    font-weight: 700;
}

/* ---- Daily legend ---- */
.usage-daily-legend {
    display: flex;
    gap: 16px;
    margin-top: 10px;
    font-size: 11px;
    color: var(--color-text-muted);
}

.usage-daily-legend-item {
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

.usage-daily-legend-swatch {
    width: 10px;
    height: 10px;
    border-radius: 2px;
}

.usage-daily-legend-swatch.current {
    background: var(--color-brand);
}

.usage-daily-legend-swatch.prev {
    background: var(--color-text-muted);
    opacity: 0.35;
}

/* ---- Day detail ---- */
.usage-daydetail {
    margin-top: 12px;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    background: var(--color-surface-alt);
}

.usage-daydetail-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
}

.usage-daydetail-date {
    font-weight: 700;
    font-size: 13px;
    color: var(--color-text-primary);
}

.usage-daydetail-stats {
    font-size: 12px;
    color: var(--color-text-secondary);
}

.usage-daydetail-compare {
    margin-top: 4px;
    font-size: 11px;
    color: var(--color-text-muted);
}

/* ---- Lists ---- */
.usage-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.usage-list-row {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    gap: 8px 12px;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    background: var(--color-surface-alt);
    transition: background 120ms var(--ease-spring);
}

.usage-list-row:hover {
    background: var(--color-surface-elevated);
}

.usage-list-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--color-text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.usage-list-path {
    font-size: 12px;
    color: var(--color-text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-family: var(--font-family-mono);
    font-size: 11px;
}

.usage-list-stat {
    font-size: 13px;
    font-weight: 700;
    color: var(--color-text-primary);
    font-variant-numeric: tabular-nums;
    text-align: right;
}

.usage-list-meta {
    grid-column: 1 / -1;
    font-size: 11px;
    color: var(--color-text-muted);
}

.usage-list-value {
    font-size: 12px;
    color: var(--color-text-secondary);
    padding: 8px 0;
}

.usage-progress {
    height: 3px;
    border-radius: 2px;
    background: var(--color-surface-alt);
    overflow: hidden;
}

.usage-progress-fill {
    height: 100%;
    border-radius: 2px;
    background: var(--color-brand);
    transition: width 300ms var(--ease-spring);
}

/* ---- Hourly heatmap ---- */
.usage-card-hourly-heatmap {
    overflow-x: auto;
}

.hourly-heatmap-wrapper {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin-top: 10px;
    min-width: 480px;
}

.hourly-heatmap-header {
    display: flex;
    gap: 2px;
    align-items: flex-end;
}

.hourly-heatmap-corner {
    width: 32px;
    flex-shrink: 0;
}

.hourly-heatmap-hour-label {
    flex: 1;
    min-width: 0;
    font-size: 9px;
    color: var(--color-text-muted);
    text-align: center;
    line-height: 14px;
}

.hourly-heatmap-row {
    display: flex;
    gap: 2px;
    align-items: center;
}

.hourly-heatmap-weekday-label {
    width: 32px;
    flex-shrink: 0;
    font-size: 10px;
    color: var(--color-text-secondary);
    text-align: right;
    padding-right: 4px;
}

.hourly-heatmap-cell {
    flex: 1;
    min-width: 0;
    aspect-ratio: 1;
    border-radius: 3px;
}

.hourly-heatmap-cell.level-0 { background: var(--color-surface-alt); }
.hourly-heatmap-cell.level-1 { background: var(--color-heatmap-1); }
.hourly-heatmap-cell.level-2 { background: var(--color-heatmap-2); }
.hourly-heatmap-cell.level-3 { background: var(--color-heatmap-3); }
.hourly-heatmap-cell.level-4 { background: var(--color-heatmap-4); }

.hourly-heatmap-legend {
    display: flex;
    align-items: center;
    gap: 3px;
    justify-content: flex-end;
    margin-top: 8px;
    font-size: 10px;
    color: var(--color-text-muted);
}

.hourly-heatmap-legend .hourly-heatmap-cell {
    width: 11px;
    height: 11px;
    aspect-ratio: auto;
}

.hourly-heatmap-legend-label {
    margin: 0 2px;
}

/* ---- Empty state ---- */
.usage-empty {
    padding: 32px 16px;
    border-radius: var(--radius-md);
    background: var(--color-surface-alt);
    border: 1px dashed var(--color-border);
    color: var(--color-text-secondary);
    text-align: center;
    font-size: 13px;
}

/* ---- Responsive ---- */
@media (max-width: 960px) {
    .usage-chart-grid {
        grid-template-columns: 1fr;
    }

    .usage-summary-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 640px) {
    .usage-toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    .usage-range-group {
        justify-content: center;
        flex-wrap: wrap;
    }

    .usage-summary-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .usage-summary-card-value {
        font-size: 22px;
    }

    .usage-daily-chart {
        height: 100px;
    }

    .usage-daily-bar-stack {
        max-width: 24px;
        height: 70px;
    }
}
