/* AI credits widget + Settings → AI Usage pane. Widget is hidden by default;
   credits.js shows it after a successful sign-in in SaaS mode. */

/* Credits widget — a small gauge, not a status badge.
   Communicates "how much AI you have left tonight" without a click. */
.credits-widget {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  padding: 0 12px;
  margin-left: 8px;
  background: var(--s2);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  overflow: hidden;
  transition: background-color 0.15s, border-color 0.15s;
}
.credits-widget::before {
  /* Fill bar — width set by state class. */
  content: '';
  position: absolute; left: 0; top: 0; bottom: 0;
  width: var(--credits-fill, 100%);
  background: linear-gradient(90deg, rgba(34,197,94,.22), rgba(34,197,94,.08));
  pointer-events: none;
  transition: width .3s ease, background .15s;
}
.credits-widget > * { position: relative; z-index: 1; }
.credits-widget:hover {
  background: var(--s1);
  border-color: var(--accent);
}
.credits-widget.hidden { display: none; }

.credits-widget.warn { --credits-fill: 55%; }
.credits-widget.low  { --credits-fill: 22%; }
.credits-widget.zero { --credits-fill: 0%; color: var(--muted); }
.credits-widget.warn::before { background: linear-gradient(90deg, rgba(245,158,11,.30), rgba(245,158,11,.10)); }
.credits-widget.low::before  { background: linear-gradient(90deg, rgba(239,68,68,.32), rgba(239,68,68,.10)); }

/* Legacy dot — hidden now that the fill bar carries the state. */
.credits-dot { display: none; }

.credits-value {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.credits-label {
  font-size: 10px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-weight: 600;
}

/* Subtle pulse when balance just changed (set by credits.js after each call). */
@keyframes credits-tick {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.04); }
  100% { transform: scale(1); }
}
.credits-widget.ticked .credits-value { animation: credits-tick 0.45s ease-out; }

/* ── Settings → AI Usage pane ─────────────────────────────────────────── */

.usage-pane {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.usage-empty {
  font-size: 12px;
  color: var(--muted);
  padding: 16px;
  text-align: center;
  background: var(--s2);
  border: 1px dashed var(--border);
  border-radius: 8px;
}

/* Summary card at the top: balance + totals across loaded history. */
.usage-summary-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 14px 18px;
  background: var(--s2);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.usage-summary-left {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.usage-summary-balance {
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.usage-balance-value {
  font-size: 26px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  letter-spacing: 0.01em;
}
.usage-balance-unit {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
}
.usage-summary-meta {
  font-size: 12px;
  color: var(--muted);
}
.usage-summary-right {
  display: flex;
  gap: 18px;
}
.usage-stat {
  text-align: right;
  min-width: 70px;
}
.usage-stat-num {
  font-size: 18px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}
.usage-stat-lbl {
  font-size: 10px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
}

/* Section wrapper — title + content. */
.usage-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.usage-section-hd {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.usage-section-hd h4,
.usage-section-hd-solo {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
}

/* Day/Week/Month segmented toggle. */
.usage-grouping {
  display: inline-flex;
  background: var(--s2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 2px;
  gap: 2px;
}
.usage-grouping-btn {
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 12px;
  font-weight: 500;
  padding: 4px 12px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}
.usage-grouping-btn:hover { color: var(--text); }
.usage-grouping-btn.on {
  background: rgba(255,255,255,.08);
  color: var(--text);
}

/* Group list — expandable rows. Settings pane handles outer scrolling. */
.usage-groups {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.usage-group {
  background: var(--s2);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  transition: border-color 0.12s;
}
.usage-group.open { border-color: rgba(255,255,255,.15); }
.usage-group-hd {
  display: grid;
  grid-template-columns: 16px 1fr auto auto auto;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 10px 14px;
  background: transparent;
  border: 0;
  color: var(--text);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  text-align: left;
  transition: background 0.12s;
}
.usage-group-hd:hover { background: rgba(255,255,255,.03); }
.usage-group-caret {
  font-size: 10px;
  color: var(--muted);
  transition: transform 0.15s;
  display: inline-block;
  width: 12px;
}
.usage-group.open .usage-group-caret { transform: rotate(90deg); }
.usage-group-label {
  font-weight: 600;
  letter-spacing: 0.01em;
}
.usage-group-sub {
  font-size: 11px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.usage-group-tokens {
  font-size: 11px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.usage-group-cache { color: #86efac; }
.usage-group-cu {
  font-size: 13px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  min-width: 56px;
  text-align: right;
}
.usage-group-body {
  border-top: 1px solid var(--border);
  background: rgba(0,0,0,.18);
  padding: 8px 14px 12px;
}

/* Drilled-down per-call table. */
.usage-call-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.usage-call-table th, .usage-call-table td {
  text-align: left;
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
}
.usage-call-table tr:last-child td { border-bottom: 0; }
.usage-call-table th {
  font-weight: 500;
  color: var(--muted);
  text-transform: uppercase;
  font-size: 10px;
  letter-spacing: 0.06em;
}
.usage-call-table td.num,
.usage-call-table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.usage-call-table td.muted { color: var(--muted); }
.usage-call-table td.strong { font-weight: 600; }
.usage-call-table td.cached { color: #86efac; }
.usage-call-table td.cached .cached-pct {
  color: #4ade80;
  opacity: .6;
  font-size: 11px;
  margin-left: 4px;
}

/* Footer: row count + Load more. */
.usage-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-top: 4px;
}
.usage-footer-msg {
  font-size: 11px;
  color: var(--muted);
}
.usage-footer-msg.muted { opacity: .7; }

/* Active sessions list. */
.usage-sessions {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.usage-session-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--s2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 12px;
}
.usage-session-row.current { border-color: var(--accent); }
.usage-session-meta {
  color: var(--muted);
  margin-left: 6px;
  font-size: 11px;
}

/* 402 banner that replaces the Copilot input when balance hits zero. */
.copilot-credits-empty {
  background: rgba(239, 68, 68, 0.08);
  border-top: 1px solid rgba(239, 68, 68, 0.4);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.copilot-credits-empty .ce-title {
  font-size: 13px;
  font-weight: 600;
  color: #fca5a5;
}
.copilot-credits-empty .ce-body {
  font-size: 12px;
  color: var(--muted);
}
.copilot-credits-empty .ce-actions {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}

/* Small button variant used for the Load more action in the usage pane. */
.btn.btn-sm {
  padding: 4px 10px;
  font-size: 11px;
  height: auto;
}
