/* =============================================
   Usage History — Premium SaaS Design (uh-*)
   ============================================= */

/* ── CSS Custom Properties ───────────────────────────────────────────────── */
#uh-container {
    --uh-radius: 14px;
    --uh-border: rgba(223, 223, 223, 1);
}
.dark #uh-container {
    --uh-border: #474746;
}

/* ── DRP overrides for user panel ───────────────────────────────────────── */
#uh-container .drp-trigger {
    height: 44px;
    border-radius: 12px;
    border-color: rgba(223, 223, 223, 1);
    background: #fff;
    box-shadow: 0 1px 0 rgba(16, 24, 40, .02);
}
.dark #uh-container .drp-trigger {
    background: #292929;
    border-color: #474746;
}

#uh-container .drp-panel {
    border-radius: 14px;
    border-color: rgba(223, 223, 223, 1);
    overflow: hidden;
    min-width: 560px;
    max-width: 92vw;
}
.dark #uh-container .drp-panel {
    background: #292929;
    border-color: #474746;
    color: #fff;
}

#uh-container .drp-sidebar { background: #f7f7f7; }
.dark #uh-container .drp-sidebar { background: #333332; border-right-color: #474746; }
.dark #uh-container .drp-sidebar-item { color: rgba(255, 255, 255, .8); }
.dark #uh-container .drp-sidebar-item:hover { background: rgba(255, 255, 255, .06); }

#uh-container .drp-sidebar-item.active { background: #141414; color: #fff; }
.dark #uh-container .drp-sidebar-item.active { background: #ffffff; color: #141414; }

#uh-container .drp-btn-apply { background: #141414; border-color: #141414; }
.dark #uh-container .drp-btn-apply { background: #ffffff; border-color: #ffffff; color: #141414; }

#uh-container .drp-day.drp-selected { background: #141414 !important; }
.dark #uh-container .drp-day.drp-selected { background: #ffffff !important; color: #141414 !important; }

.dark #uh-container .drp-cal-title,
.dark #uh-container .drp-day-label,
.dark #uh-container .drp-range-display { color: rgba(255, 255, 255, .75); }
.dark #uh-container .drp-day { color: rgba(255, 255, 255, .85); }
.dark #uh-container .drp-day:hover:not(.drp-empty) { background: rgba(255, 255, 255, .06); }
.dark #uh-container .drp-day.drp-in-range { background: rgba(255, 255, 255, .08); }
.dark #uh-container .drp-footer { border-top-color: #474746; }
.dark #uh-container .drp-btn-cancel { background: transparent; border-color: #474746; color: rgba(255, 255, 255, .8); }

/* ── Export buttons ──────────────────────────────────────────────────────── */
.uh-export-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 36px;
    padding: 0 14px;
    border-radius: 10px;
    border: 1px solid var(--uh-border);
    background: #fff;
    font-size: 13px;
    font-weight: 600;
    color: #141414;
    transition: background .15s, transform .15s, box-shadow .15s;
    text-decoration: none;
    white-space: nowrap;
}
.uh-export-btn:hover {
    background: #F6F3F2;
    transform: translateY(-1px);
    box-shadow: 0 2px 6px rgba(0, 0, 0, .07);
    color: #141414;
    text-decoration: none;
}
.dark .uh-export-btn { background: #3A3A39; border-color: #474746; color: #fff; }
.dark .uh-export-btn:hover { background: #444443; color: #fff; }
.uh-export-btn--active { background: #141414 !important; color: #fff !important; border-color: #141414 !important; }
.dark .uh-export-btn--active { background: #fff !important; color: #141414 !important; border-color: #fff !important; }

/* ── Filter card ─────────────────────────────────────────────────────────── */
.uh-filter-card {
    background: #fff;
    border: 1px solid var(--uh-border);
    border-radius: var(--uh-radius);
    padding: 16px;
}
.dark .uh-filter-card { background: #292929; }

.uh-search-wrap {
    position: relative;
    flex: 1;
    min-width: 0;
}
.uh-search-icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: #898989;
    pointer-events: none;
    width: 16px;
    height: 16px;
}
.dark .uh-search-icon { color: rgba(255, 255, 255, .4); }

.uh-search-input {
    width: 100%;
    height: 44px;
    padding: 0 14px 0 40px;
    border: 1px solid var(--uh-border);
    border-radius: 12px;
    background: #fff;
    font-size: 14px;
    color: #141414;
    outline: none;
    transition: border-color .2s, box-shadow .2s;
}
.uh-search-input:focus {
    border-color: #141414;
    box-shadow: 0 0 0 3px rgba(20, 20, 20, .06);
}
.dark .uh-search-input { background: #292929; color: #fff; border-color: #474746; }
.dark .uh-search-input:focus { border-color: #888; box-shadow: 0 0 0 3px rgba(255, 255, 255, .05); }
.uh-search-input::placeholder { color: #aaa; }
.dark .uh-search-input::placeholder { color: rgba(255, 255, 255, .3); }

.uh-filter-actions {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

.uh-btn-filter {
    height: 44px;
    padding: 0 20px;
    border-radius: 12px;
    background: #141414;
    color: #fff;
    font-size: 14px;
    font-weight: 600;
    border: none;
    cursor: pointer;
    white-space: nowrap;
    transition: background .15s, transform .15s;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.uh-btn-filter:hover { background: #333; transform: translateY(-1px); }
.dark .uh-btn-filter { background: #fff; color: #141414; }
.dark .uh-btn-filter:hover { background: #e5e5e5; }

.uh-btn-reset {
    height: 44px;
    padding: 0 18px;
    border-radius: 12px;
    border: 1px solid var(--uh-border);
    background: #fff;
    color: #141414;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background .15s, transform .15s;
}
.uh-btn-reset:hover { background: #F6F3F2; transform: translateY(-1px); color: #141414; text-decoration: none; }
.dark .uh-btn-reset { background: #3A3A39; border-color: #474746; color: #fff; }
.dark .uh-btn-reset:hover { background: #444443; color: #fff; }

/* ── Table card ──────────────────────────────────────────────────────────── */
.uh-table-card {
    background: #fff;
    border: 1px solid var(--uh-border);
    border-radius: var(--uh-radius);
    overflow: hidden;
}
.dark .uh-table-card { background: #292929; }

.uh-table { width: 100%; border-collapse: collapse; }

.uh-table thead th {
    background: #F6F3F2;
    padding: 10px 16px;
    font-size: 11px;
    font-weight: 700;
    color: #898989;
    text-transform: uppercase;
    letter-spacing: .6px;
    text-align: left;
    white-space: nowrap;
    border-bottom: 1px solid var(--uh-border);
}
.dark .uh-table thead th {
    background: #333332;
    color: rgba(255, 255, 255, .5);
    border-bottom-color: #474746;
}

.uh-table tbody tr {
    border-bottom: 1px solid rgba(223, 223, 223, .6);
    transition: background .15s;
}
.uh-table tbody tr:last-child { border-bottom: none; }
.uh-table tbody tr:hover { background: rgba(246, 243, 242, .7); }
.dark .uh-table tbody tr { border-bottom-color: rgba(71, 71, 70, .6); }
.dark .uh-table tbody tr:hover { background: rgba(255, 255, 255, .04); }

.uh-table td {
    padding: 14px 16px;
    font-size: 14px;
    color: #141414;
    font-family: 'Figtree', sans-serif;
    vertical-align: middle;
}
.dark .uh-table td { color: #fff; }

/* Column min-widths */
.uh-col-date   { min-width: 120px; }
.uh-col-type   { min-width: 130px; }
.uh-col-model  { min-width: 130px; }
.uh-col-usage  { min-width: 110px; }
.uh-col-cost   { min-width: 90px; }
.uh-col-pkg    { min-width: 120px; }
.uh-col-plan   { min-width: 110px; }

/* ── Date cell ───────────────────────────────────────────────────────────── */
.uh-date-primary { font-weight: 600; font-size: 13px; white-space: nowrap; }
.uh-date-time    { font-size: 11px; color: #898989; margin-top: 2px; white-space: nowrap; }
.dark .uh-date-time { color: rgba(255, 255, 255, .45); }

/* ── Type badge ──────────────────────────────────────────────────────────── */
.uh-type-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    border-radius: 8px;
    font-size: 11px;
    font-weight: 700;
    white-space: nowrap;
    border: 1px solid transparent;
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
}
.uh-type-badge-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 140px;
}
.uh-type-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    flex-shrink: 0;
    background: currentColor;
    opacity: .7;
}

.uh-type-teal   { background: #f0fdfa; color: #0d9488; border-color: #99f6e4; }
.uh-type-purple { background: #faf5ff; color: #7c3aed; border-color: #ddd6fe; }
.uh-type-rose   { background: #fff1f2; color: #e11d48; border-color: #fecdd3; }
.uh-type-amber  { background: #fffbeb; color: #d97706; border-color: #fde68a; }
.uh-type-blue   { background: #eff6ff; color: #2563eb; border-color: #bfdbfe; }
.uh-type-indigo { background: #eef2ff; color: #4f46e5; border-color: #c7d2fe; }
.uh-type-green  { background: #f0fdf4; color: #16a34a; border-color: #bbf7d0; }
.uh-type-default{ background: #f8fafc; color: #64748b; border-color: #e2e8f0; }

.dark .uh-type-teal   { background: rgba(13,  148, 136, .12); border-color: rgba(13,  148, 136, .3); }
.dark .uh-type-purple { background: rgba(124, 58,  237, .12); border-color: rgba(124, 58,  237, .3); }
.dark .uh-type-rose   { background: rgba(225, 29,  72,  .12); border-color: rgba(225, 29,  72,  .3); }
.dark .uh-type-amber  { background: rgba(217, 119, 6,   .12); border-color: rgba(217, 119, 6,   .3); }
.dark .uh-type-blue   { background: rgba(37,  99,  235, .12); border-color: rgba(37,  99,  235, .3); }
.dark .uh-type-indigo { background: rgba(79,  70,  229, .12); border-color: rgba(79,  70,  229, .3); }
.dark .uh-type-green  { background: rgba(22,  163, 74,  .12); border-color: rgba(22,  163, 74,  .3); }
.dark .uh-type-default{ background: rgba(100, 116, 139, .1);  border-color: rgba(100, 116, 139, .25); color: rgba(255, 255, 255, .6); }

/* ── Model chip ──────────────────────────────────────────────────────────── */
.uh-model-chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    border-radius: 8px;
    background: #F6F3F2;
    border: 1px solid rgba(223, 223, 223, 1);
    font-size: 11px;
    font-weight: 700;
    color: #141414;
    max-width: 180px;
    overflow: hidden;
}
.uh-model-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dark .uh-model-chip { background: #3A3A39; border-color: #474746; color: rgba(255, 255, 255, .85); }

.uh-model-chip-card { max-width: 130px; }

/* Model icon helpers */
.uh-model-icon { flex-shrink: 0; opacity: .6; }

/* ── Usage cell ──────────────────────────────────────────────────────────── */
.uh-usage-val  { font-weight: 700; font-size: 13px; }
.uh-usage-unit { font-size: 11px; color: #898989; margin-top: 2px; }
.dark .uh-usage-unit { color: rgba(255, 255, 255, .45); }

/* ── Cost cell ───────────────────────────────────────────────────────────── */
.uh-cost-free {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    font-weight: 700;
    color: #16a34a;
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
    padding: 3px 9px;
    border-radius: 7px;
}
.dark .uh-cost-free { background: rgba(22, 163, 74, .1); border-color: rgba(22, 163, 74, .3); color: #4ade80; }

.uh-cost-own-key {
    display: inline-flex;
    align-items: center;
    font-size: 12px;
    font-weight: 700;
    color: #6d28d9;
    background: linear-gradient(135deg, #f5f3ff 0%, #ede9fe 100%);
    border: 1px solid #ddd6fe;
    padding: 4px 10px;
    border-radius: 8px;
    cursor: default;
    white-space: nowrap;
    box-shadow: 0 1px 3px rgba(109, 40, 217, .08);
}
.dark .uh-cost-own-key {
    background: linear-gradient(135deg, rgba(109, 40, 217, .15) 0%, rgba(139, 92, 246, .1) 100%);
    border-color: rgba(139, 92, 246, .35);
    color: #c4b5fd;
    box-shadow: 0 1px 3px rgba(139, 92, 246, .12);
}

.uh-cost-num  { font-weight: 700; font-size: 14px; }
.uh-cost-unit { font-size: 11px; color: #898989; margin-left: 2px; }
.dark .uh-cost-unit { color: rgba(255, 255, 255, .45); }

/* Inline cost group (used in mobile card) */
.uh-cost-group {
    display: flex;
    align-items: baseline;
    gap: 3px;
}

/* ── Package chip ────────────────────────────────────────────────────────── */
.uh-pkg-chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    border-radius: 8px;
    background: #F6F3F2;
    border: 1px solid rgba(223, 223, 223, 1);
    font-size: 12px;
    font-weight: 600;
    color: #141414;
    max-width: 180px;
    overflow: hidden;
}
.uh-pkg-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dark .uh-pkg-chip { background: #3A3A39; border-color: #474746; color: rgba(255, 255, 255, .85); }

/* Plan type (subscription / one-time / included credits) */
.uh-plan-chip {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 8px;
    background: #eef2ff;
    border: 1px solid #c7d2fe;
    font-size: 11px;
    font-weight: 700;
    color: #4338ca;
    max-width: 160px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.dark .uh-plan-chip {
    background: rgba(79, 70, 229, .15);
    border-color: rgba(129, 140, 248, .35);
    color: rgba(199, 210, 254, .95);
}

/* Pkg icon helper */
.uh-pkg-icon { flex-shrink: 0; opacity: .6; }

/* ── Empty state ─────────────────────────────────────────────────────────── */
.uh-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 24px;
    gap: 12px;
}
.uh-empty-icon {
    width: 64px;
    height: 64px;
    border-radius: 18px;
    background: #F6F3F2;
    border: 1px solid rgba(223, 223, 223, 1);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 26px;
    margin-bottom: 4px;
}
.dark .uh-empty-icon { background: #333332; border-color: #474746; }
.uh-empty-title { font-size: 15px; font-weight: 700; color: #141414; }
.dark .uh-empty-title { color: #fff; }
.uh-empty-sub  { font-size: 13px; color: #898989; text-align: center; max-width: 280px; }
.dark .uh-empty-sub { color: rgba(255, 255, 255, .45); }

/* ── Mobile card list ────────────────────────────────────────────────────── */
.uh-card-list { display: none; }

.uh-usage-card {
    background: #fff;
    border: 1px solid var(--uh-border);
    border-radius: 14px;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    transition: box-shadow .2s;
}
.dark .uh-usage-card { background: #292929; }
.uh-usage-card:hover { box-shadow: 0 4px 16px rgba(0, 0, 0, .07); }
.dark .uh-usage-card:hover { box-shadow: 0 4px 16px rgba(0, 0, 0, .25); }

.uh-card-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 8px;
}
.uh-card-body {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}
.uh-card-field { display: flex; flex-direction: column; gap: 3px; }
.uh-card-label {
    font-size: 10px;
    font-weight: 700;
    color: #898989;
    text-transform: uppercase;
    letter-spacing: .5px;
}
.dark .uh-card-label { color: rgba(255, 255, 255, .4); }
.uh-card-value { font-size: 13px; font-weight: 600; color: #141414; }
.dark .uh-card-value { color: #fff; }

.uh-card-pkg-value {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 130px;
}

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
    .uh-table-card .uh-table-wrap { display: none; }
    .uh-card-list { display: flex; flex-direction: column; gap: 10px; }
    .uh-filter-actions { width: 100%; }
    .uh-btn-filter,
    .uh-btn-reset { flex: 1; justify-content: center; }
    .uh-drp-wrap { width: 100%; }
}

@media (min-width: 769px) {
    .uh-export-mobile { display: none !important; }
}

/* ── Responsive DRP ──────────────────────────────────────────────────────── */
@media (max-width: 640px) {
    #uh-container .drp-panel { min-width: 96vw; left: 0; right: 0; }
    #uh-container .drp-right { min-width: 0; }
    #uh-container .drp-calendars { flex-direction: column; }
}

/* =============================================
   Advanced Date Range Picker (drp-*)
   ============================================= */
.drp-wrap    { position: relative; width: 100%; }
.drp-trigger {
    display: inline-flex; align-items: center; gap: 8px; cursor: pointer;
    padding: 0 12px; border: 1px solid #dee2e6; border-radius: 4px;
    background: #fff; font-size: 13px; color: #495057; width: 100%; height: 35px;
    white-space: nowrap; -webkit-user-select: none; user-select: none;
}
.drp-trigger:hover { border-color: #adb5bd; }
.drp-trigger-icon  { color: #6c757d; display: flex; align-items: center; }
.drp-trigger-label { flex: 1; overflow: hidden; text-overflow: ellipsis; font-size: 13px; }
.drp-trigger-caret { color: #6c757d; display: flex; align-items: center; }

.drp-panel {
    display: none; position: absolute; top: calc(100% + 5px); left: 0; z-index: 1001;
    background: #fff; border: 1px solid #dee2e6; border-radius: 4px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, .15); flex-direction: row; min-width: 620px;
}
.drp-panel.open { display: flex; }

/* Sidebar */
.drp-sidebar { width: 150px; flex-shrink: 0; border-right: 1px solid #e9ecef; padding: 8px 0; background: #f8f9fa; }
.drp-sidebar-item {
    display: block; width: 100%; text-align: left; background: none; border: none;
    padding: 8px 16px; font-size: 13px; color: #495057; cursor: pointer; outline: none;
}
.drp-sidebar-item:hover { background: #e9ecef; }
.drp-sidebar-item.active { background: #141414; color: #fff; font-weight: 600; }

/* Calendars */
.drp-right     { display: flex; flex-direction: column; flex: 1; min-width: 470px; }
.drp-calendars { display: flex; padding: 15px; gap: 20px; }
.drp-month     { flex: 1; }
.drp-cal-head  { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.drp-cal-title { font-size: 13px; font-weight: 700; color: #212529; }
.drp-nav { background: none; border: none; cursor: pointer; padding: 2px 8px; color: #6c757d; font-size: 18px; line-height: 1; }
.drp-nav:hover { color: #212529; }
.drp-nav.invisible { visibility: hidden; }

.drp-grid      { display: grid; grid-template-columns: repeat(7, 1fr); text-align: center; }
.drp-day-label { font-size: 10px; font-weight: 700; color: #adb5bd; padding-bottom: 8px; text-transform: uppercase; }
.drp-day {
    padding: 6px 0; font-size: 12px; color: #495057;
    cursor: pointer; border-radius: 4px;
}
.drp-day:hover:not(.drp-empty) { background: #f0f2f5; }
.drp-day.drp-today   { font-weight: 700; color: #141414; }
.drp-day.drp-selected{ background: #141414 !important; color: #fff !important; }
.drp-day.drp-hover   { background: #e9ecef !important; border-radius: 4px; }
.drp-day.drp-in-range{ background: #f1f4f8; border-radius: 0; }
.drp-day.drp-empty   { pointer-events: none; }

/* Footer */
.drp-footer {
    display: flex; align-items: center; border-top: 1px solid #f1f3f5;
    padding: 10px 15px; gap: 10px;
}
.drp-range-display { flex: 1; font-size: 12px; color: #6c757d; }
.drp-range-display b { color: #212529; font-weight: 600; }
.drp-btn {
    padding: 6px 16px; border-radius: 4px; font-size: 13px; font-weight: 600;
    cursor: pointer; border: 1px solid transparent; outline: none;
}
.drp-btn-cancel { background: #fff; border-color: #dee2e6; color: #6c757d; }
.drp-btn-apply  { background: #141414; border-color: #141414; color: #fff; }

@media (max-width: 991px) {
    .drp-panel { min-width: 100%; left: 0; right: 0; }
    .drp-right { min-width: 0; }
    .drp-calendars { flex-direction: column; }
}

/* Token breakdown tooltip (user usage-history page) */
.uh-token-tooltip {
    position: relative;
    display: inline-flex;
    align-items: center;
    outline: none;
}

.uh-token-tooltip .uh-usage-val {
    display: inline-flex;
    align-items: center;
}

.uh-token-tooltip-box {
    /* Positioned via JS using `position: fixed` so it won't be clipped
       by table/container overflow + scrolling. */
    position: fixed;
    left: 0;
    top: 0;
    bottom: auto;
    transform: translateX(-50%) translateY(6px);
    opacity: 0;
    pointer-events: none;
    transition: opacity .12s ease, transform .12s ease;
    z-index: 20;
    min-width: 200px;
    max-width: 220px;
    background: rgba(20, 20, 20, .96);
    color: #fff;
    border-radius: 10px;
    padding: 10px 12px;
    box-shadow: 0 10px 24px rgba(0,0,0,.24);
    border: none;
}

.uh-token-tooltip-box::after {
    content: '';
    position: absolute;
    left: 50%;
    top: -6px;
    transform: translateX(-50%);
    border-width: 6px;
    border-style: solid;
    border-color: rgba(20, 20, 20, .98) transparent transparent transparent;
}

.uh-token-tooltip-title {
    font-size: 12px;
    font-weight: 800;
    color: rgba(255,255,255,.9);
    margin-bottom: 6px;
}

.uh-token-tooltip-row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 10px;
    font-size: 12px;
    font-weight: 700;
}

.uh-token-tooltip-row + .uh-token-tooltip-row { margin-top: 6px; }

.uh-token-tooltip-k {
    color: rgba(255,255,255,.7);
    font-weight: 700;
}

.uh-token-tooltip-v { font-weight: 900; }

.uh-token-tooltip:hover .uh-token-tooltip-box,
.uh-token-tooltip:focus-visible .uh-token-tooltip-box {
    opacity: 1;
    pointer-events: auto;
    transform: translateX(-50%) translateY(0);
}
