/* Comptes Claude - dark theme, no framework. */

:root {
  color-scheme: dark;
  --bg: #0d1017;
  --surface: #151a23;
  --surface-2: #1c2230;
  --border: #283040;
  --border-strong: #36405a;
  --text: #e7eaf0;
  --muted: #98a2b6;
  --accent: #8ab4ff;
  --accent-strong: #5b8cff;
  --free: #3fb950;
  --in-use: #f0a03c;
  --exhausted: #f85149;
  --neutral: #8b949e;
  --level-low: #3fb950;
  --level-mid: #d6b23a;
  --level-high: #f0883e;
  --level-full: #f85149;
  --info: #58a6ff;
  --warning: #e3b341;
  --radius: 12px;
  --radius-sm: 8px;
  --gap: 16px;
  --gutter: 24px;
  --topbar-clearance: 96px;
  --mono: ui-monospace, "Cascadia Mono", Consolas, "Liberation Mono", monospace;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; line-height: 1.2; }
.muted { color: var(--muted); }

/* ---------- Top bar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px 24px;
  padding: 14px var(--gutter);
  background: rgba(13, 16, 23, 0.94);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(8px);
}
.topbar h1 { font-size: 20px; font-weight: 700; }
.summary { margin: 4px 0 0; color: var(--muted); font-weight: 600; }
.summary .count-free { color: var(--free); }
.summary .count-in_use { color: var(--in-use); }
.summary .count-exhausted { color: var(--exhausted); }
.summary .count-problem { color: var(--neutral); }
.summary .sep { color: var(--border-strong); margin: 0 6px; }
.topbar-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.last-refresh { color: var(--muted); font-size: 13px; margin-right: 4px; }

/* ---------- Buttons ---------- */

.btn {
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 7px 14px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.btn:hover:not(:disabled) { background: #252c3d; border-color: #46516d; }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn:focus-visible, input:focus-visible, summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.btn-primary { background: var(--accent-strong); border-color: var(--accent-strong); color: #fff; }
.btn-primary:hover:not(:disabled) { background: #4a7af0; border-color: #4a7af0; }
.btn-ghost { background: transparent; border-color: var(--border); }
.btn-danger { background: var(--exhausted); border-color: var(--exhausted); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #e5403a; border-color: #e5403a; }
.btn-sm { font-size: 13px; padding: 4px 10px; }
.btn-link-danger { color: #ff8f88; }

/* ---------- Layout ---------- */

.container { max-width: 1320px; margin: 0 auto; padding: 20px var(--gutter) 48px; }

.banner {
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  margin-bottom: var(--gap);
  border: 1px solid;
}
.banner-error { background: rgba(248, 81, 73, 0.1); border-color: rgba(248, 81, 73, 0.45); }

/* ---------- Add panel ---------- */

.panel {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: var(--gap);
  /* Panels are scrolled into view: keep them clear of the sticky top bar. */
  scroll-margin-top: var(--topbar-clearance);
}
.add-form h2 { font-size: 17px; margin-bottom: 14px; }
.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 13px; font-weight: 600; }
.field-wide { grid-column: 1 / -1; }
.field-help { margin: 0; font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
input[type="text"], input[type="email"], input[type="password"] {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  width: 100%;
}
.help { margin-top: 14px; font-size: 14px; color: var(--muted); }
.help p { margin: 0 0 8px; }
.help-warning {
  color: var(--text);
  background: rgba(227, 179, 65, 0.1);
  border-left: 3px solid var(--warning);
  padding: 8px 10px;
  border-radius: 4px;
}
.form-error { color: #ff8f88; margin: 8px 0 0; }
.form-actions { display: flex; gap: 8px; margin-top: 14px; }

/* ---------- Legend ---------- */

.legend {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 16px;
  margin-bottom: var(--gap);
  font-size: 14px;
}
.legend summary { cursor: pointer; color: var(--muted); font-weight: 600; }
.legend ul { margin: 12px 0 8px; padding: 0; list-style: none; display: grid; gap: 8px; }
.legend li .badge { margin-right: 6px; }
.legend p { margin: 4px 0 4px; }

/* ---------- Status colours ---------- */

.status-free { --status-color: var(--free); }
.status-in_use { --status-color: var(--in-use); }
.status-exhausted { --status-color: var(--exhausted); }
.status-reauth, .status-error, .status-pending, .status-loading { --status-color: var(--neutral); }

/* Small pulsing dot while the server fetches this account. */
.refreshing {
  width: 8px;
  height: 8px;
  margin-left: auto;
  margin-right: 8px;
  border-radius: 50%;
  background: var(--accent);
  animation: refreshing-pulse 1.2s ease-in-out infinite;
  flex: none;
  align-self: center;
}
@keyframes refreshing-pulse {
  0%, 100% { opacity: 0.25; }
  50% { opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  .refreshing { animation: none; opacity: 0.7; }
}

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.04em;
  white-space: nowrap;
  color: #0d1017;
  background: var(--status-color, var(--neutral));
}

/* ---------- Cards ---------- */

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(330px, 1fr));
  gap: var(--gap);
}
.empty {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--muted);
  padding: 40px 16px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
}

.card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: 4px solid var(--status-color, var(--neutral));
  border-radius: var(--radius);
  padding: 14px 16px 12px;
}
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.card-title { font-size: 17px; font-weight: 700; overflow-wrap: anywhere; }

.identity { display: flex; flex-direction: column; gap: 6px; margin-top: -4px; }
.email { color: var(--muted); font-size: 14px; overflow-wrap: anywhere; }
.org-line { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; font-size: 13px; }
.plan-badge {
  font-weight: 700;
  color: var(--accent);
  background: rgba(138, 180, 255, 0.12);
  border: 1px solid rgba(138, 180, 255, 0.35);
  border-radius: 6px;
  padding: 1px 8px;
}
.plan-tier { color: var(--text); font-weight: 600; }
.org-name { color: var(--muted); overflow-wrap: anywhere; }

.status-detail { font-size: 14px; }
.available { font-size: 15px; color: var(--text); }
.available strong { color: var(--status-color); }
.reason { color: var(--muted); font-size: 13px; }

.notice {
  font-size: 13px;
  border-radius: 6px;
  padding: 7px 10px;
  border-left: 3px solid;
}
.notice-info { background: rgba(88, 166, 255, 0.08); border-color: var(--info); }
.notice-warning { background: rgba(227, 179, 65, 0.08); border-color: var(--warning); }
.notice-error { background: rgba(139, 148, 158, 0.1); border-color: var(--neutral); }

/* ---------- Meters ---------- */

.usage { display: flex; flex-direction: column; gap: 10px; }
.meter-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.meter-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.meter-value { font-size: 15px; font-weight: 700; font-variant-numeric: tabular-nums; }
.meter-track {
  height: 8px;
  margin: 5px 0 4px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
}
.meter-fill { height: 100%; width: 0; border-radius: 999px; transition: width 0.4s ease; }
.meter-detail { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.meter-idle .meter-value, .meter-idle .meter-detail { color: var(--muted); }

.level-low { background: var(--level-low); }
.level-mid { background: var(--level-mid); }
.level-high { background: var(--level-high); }
.level-full { background: var(--level-full); }
.level-none { background: transparent; }

.scoped { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.scoped-item {
  font-size: 12px;
  color: var(--muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 2px 8px;
  font-variant-numeric: tabular-nums;
}
.scoped-item .dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  margin-right: 5px;
  vertical-align: 1px;
}
.scoped-item strong { color: var(--text); }

/* ---------- Group filter chips ---------- */

.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: var(--gap); }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 12px;
  cursor: pointer;
}
.chip:hover { border-color: var(--border-strong); color: var(--text); }
.chip[aria-pressed="true"] {
  color: var(--text);
  background: var(--surface-2);
  border-color: var(--accent-strong);
}
.chip-count {
  font-size: 11px;
  color: var(--muted);
  background: var(--bg);
  border-radius: 999px;
  padding: 0 7px;
}
.chip:focus-visible, .group-toggle:focus-visible, select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- Group sections ---------- */

.sections { display: flex; flex-direction: column; gap: 22px; }
.group-section { --group-color: var(--neutral); }
.group-head-wrap { margin-bottom: 12px; }
.group-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 14px;
  padding: 6px 0 8px;
  margin-bottom: 12px;
  border-bottom: 2px solid var(--group-color);
}
.group-head-wrap .group-head { margin-bottom: 0; }
.group-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font: inherit;
  color: var(--text);
  background: none;
  border: 0;
  padding: 2px 4px 2px 0;
  cursor: pointer;
  min-width: 0;
}
.chevron { color: var(--muted); width: 12px; font-size: 13px; }
.group-dot {
  flex: none;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--group-color, var(--neutral));
}
.group-name { font-size: 17px; font-weight: 700; overflow-wrap: anywhere; text-align: left; }
.group-summary { color: var(--muted); font-size: 14px; font-variant-numeric: tabular-nums; }
.group-actions { display: flex; flex-wrap: wrap; gap: 4px; margin-left: auto; }
.btn-icon { min-width: 30px; padding-left: 8px; padding-right: 8px; }
.group-confirm {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  padding: 8px 12px;
  font-size: 14px;
  color: #ffb3ae;
  background: rgba(248, 81, 73, 0.08);
  border-left: 3px solid var(--exhausted);
  border-radius: 6px;
}
.group-confirm span { flex: 1 1 260px; }
.group-edit-form { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; width: 100%; }
.group-edit-form input[type="text"] { flex: 1 1 200px; min-width: 0; padding: 5px 8px; }
.section-empty {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  padding: 14px 16px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
}

/* ---------- Group picker on cards, selects, colour inputs ---------- */

select {
  font: inherit;
  font-size: 13px;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 5px 8px;
  max-width: 100%;
}
.field select { font-size: 15px; padding: 8px 10px; }
.group-picker {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
}
.group-picker select { flex: 1 1 auto; min-width: 0; }
input[type="color"] {
  width: 44px;
  height: 34px;
  padding: 2px;
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.fields-group { grid-template-columns: minmax(200px, 1fr) auto; }
.field-color input[type="color"] { width: 64px; height: 38px; }

/* ---------- Card actions ---------- */

.actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-top: auto;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}
.actions.confirm { font-size: 13px; }
.actions.confirm span { flex-basis: 100%; color: #ffb3ae; }

.rename-form { display: flex; flex-wrap: wrap; gap: 6px; flex: 1; min-width: 0; }
.rename-form input { flex: 1 1 160px; min-width: 0; padding: 5px 8px; }

/* Non-destructive confirmations (switch, import, restore): neutral question text. */
.actions.confirm-neutral span { color: var(--text); }
.confirm-option {
  flex-basis: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  cursor: pointer;
}
input[type="checkbox"] {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--accent-strong);
  cursor: pointer;
}
.adopt-form input[type="text"] { flex: 1 1 180px; min-width: 0; padding: 5px 8px; }

/* ---------- Command output and manual login command ---------- */

.command-output, .command-block {
  margin: 0;
  font-family: var(--mono);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
}
.command-output { font-size: 12px; color: var(--muted); max-height: 220px; overflow: auto; }
.command-block { font-size: 14px; color: var(--text); margin-top: 12px; user-select: all; }
.command-block:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.command-result { display: flex; flex-direction: column; gap: 6px; }
.command-result-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.manual-login h2 { font-size: 17px; margin-bottom: 4px; }
.manual-login > .muted { margin: 0; font-size: 14px; }

/* ---------- Targets (Cibles) ---------- */

.targets-section { margin-top: 32px; }
.targets-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 14px;
  padding: 6px 0 8px;
  margin-bottom: 12px;
  border-bottom: 2px solid var(--border-strong);
}
.targets-head h2 { font-size: 17px; font-weight: 700; }
.targets-head .btn { margin-left: auto; }
.targets-error { margin: 0 0 12px; font-size: 14px; }
.target-address { font-family: var(--mono); color: var(--text); }
.target-card .reason { overflow-wrap: anywhere; }

.sync-ok { --status-color: var(--free); }
.sync-pending { --status-color: var(--accent); }
.sync-error { --status-color: var(--exhausted); }
.sync-foreign, .sync-drift { --status-color: var(--warning); }
.sync-unassigned { --status-color: var(--neutral); }

/* ---------- Hidden accounts ---------- */

.hidden-section { margin-top: 28px; }
.hidden-section h2 { font-size: 14px; color: var(--muted); margin-bottom: 8px; }
.hidden-list { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.hidden-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 5px 6px 5px 12px;
  font-size: 14px;
}

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  max-width: min(560px, calc(100vw - 32px));
  background: #232a3a;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  z-index: 20;
}
.toast-error { border-color: rgba(248, 81, 73, 0.6); }

/* ---------- Login page (server mode) ---------- */

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: var(--gutter);
}
.login-card {
  width: min(380px, 100%);
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.login-head { display: flex; align-items: center; gap: 12px; }
.login-logo { width: 36px; height: 36px; flex: none; }
.login-card h1 { font-size: 20px; font-weight: 700; }
.login-intro { margin: 0; font-size: 14px; }
.login-card .form-error { margin: 0; }
.login-card .form-actions { margin-top: 0; }
.login-card .form-actions .btn { width: 100%; }

/* ---------- Small screens ---------- */

@media (max-width: 640px) {
  :root { --gutter: 16px; }
  .topbar { position: static; }
  .topbar-actions { width: 100%; }
  .last-refresh { flex-basis: 100%; }
  .cards { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  .meter-fill, .btn { transition: none; }
}
