/* components.css — buttons, cards, tables, inputs, badges, modals, toasts. */

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  border: 1px solid transparent;
  border-radius: var(--radius-input);
  padding: var(--space-2) var(--space-4);
  font-weight: 500;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
  white-space: nowrap;
}
.btn-primary   { background: var(--gold); color: white; }
.btn-primary:hover   { background: #a07e28; }
.btn-secondary { background: var(--surface); border-color: var(--border-strong); color: var(--ink); }
.btn-secondary:hover { background: var(--hover-bg); }
.btn-danger    { background: var(--danger-soft); color: var(--danger); border-color: var(--danger); }
.btn-danger:hover    { background: #f0cab8; }
.btn-ghost     { background: transparent; color: var(--ink); }
.btn-ghost:hover     { background: var(--hover-bg); }
.btn:disabled  { opacity: 0.5; cursor: not-allowed; }
.btn-block     { width: 100%; }

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: var(--space-5);
}
.card + .card { margin-top: var(--space-4); }

.card-tight { padding: var(--space-3) var(--space-4); }

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-3);
}
.card-title { font-size: 13px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--ink-muted); margin: 0; font-weight: 600; }

/* Tables */
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.table th, .table td {
  text-align: left;
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.table th {
  background: var(--surface-2);
  font-weight: 600;
  color: var(--ink-muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.table tbody tr:hover { background: var(--hover-bg); }

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  min-width: 18px;
  height: 18px;
  padding: 0 6px;
  border-radius: 9px;
  background: var(--gold-soft);
  color: var(--ink);
  font-size: 11px;
  font-weight: 600;
  font-family: var(--font-mono);
  line-height: 1;
}
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-warn    { background: var(--warn-soft);    color: var(--warn);    }
.badge-danger  { background: var(--danger-soft);  color: var(--danger);  }
.badge-info    { background: var(--info-soft);    color: var(--info);    }

/* Toasts */
#toast-region {
  position: fixed;
  bottom: var(--space-4);
  right: var(--space-4);
  display: flex;
  flex-direction: column-reverse;
  gap: var(--space-2);
  z-index: 9999;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-card);
  padding: var(--space-3) var(--space-4);
  min-width: 240px;
  max-width: 380px;
  box-shadow: 0 8px 24px rgba(28,24,20,0.10);
  animation: toast-in 140ms ease-out;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}
.toast-success { border-color: var(--success); }
.toast-error   { border-color: var(--danger);  }
.toast-warn    { border-color: var(--warn);    }
.toast-info    { border-color: var(--info);    }
.toast-action {
  background: transparent;
  border: 0;
  color: var(--gold);
  font-weight: 600;
  padding: 0;
  cursor: pointer;
}
@keyframes toast-in {
  from { transform: translateY(8px); opacity: 0; }
  to   { transform: translateY(0);   opacity: 1; }
}

/* Modal */
#modal-root:empty { display: none; }
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(28,24,20,0.40);
  display: flex; align-items: center; justify-content: center;
  z-index: 9000;
  padding: var(--space-4);
}
.modal {
  background: var(--surface);
  border-radius: var(--radius-card);
  border: 1px solid var(--border-strong);
  max-width: 560px;
  width: 100%;
  max-height: 85vh;
  overflow: auto;
  box-shadow: 0 12px 40px rgba(28,24,20,0.20);
}
.modal-header { padding: var(--space-4) var(--space-5); border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.modal-body   { padding: var(--space-5); }
.modal-footer { padding: var(--space-4) var(--space-5); border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: var(--space-3); background: var(--surface-2); }

/* Skeleton */
.skeleton {
  background: linear-gradient(90deg, var(--surface-2) 0%, var(--surface-3) 50%, var(--surface-2) 100%);
  background-size: 200% 100%;
  animation: skeleton-shimmer 1200ms ease-in-out infinite;
  border-radius: var(--radius-input);
  display: block;
}
@keyframes skeleton-shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Copy-to-clipboard hover affordance */
.copyable {
  position: relative; cursor: pointer;
  border-bottom: 1px dashed transparent;
  transition: border-color 0.12s, background 0.12s;
}
.copyable:hover {
  border-bottom-color: var(--ink-subtle);
  background: var(--hover-bg);
}
.copyable::after {
  content: '⧉';
  display: inline-block;
  margin-left: 6px;
  opacity: 0;
  font-size: 0.85em;
  color: var(--ink-subtle);
  transition: opacity 0.12s;
}
.copyable:hover::after,
.copyable:focus::after { opacity: 0.8; }
.copyable:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* Login card */
.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-5);
  background: var(--paper);
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: var(--space-6);
  width: 100%;
  max-width: 380px;
  box-shadow: 0 4px 18px rgba(28,24,20,0.06);
}
.login-card h1 {
  font-family: var(--font-display);
  font-size: 24px;
  margin-bottom: var(--space-2);
  text-align: center;
}
.login-card .login-subtitle {
  text-align: center;
  color: var(--ink-muted);
  font-size: 13px;
  margin-bottom: var(--space-5);
}
.login-card label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-muted);
  margin-bottom: var(--space-2);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.login-card .form-row + .form-row { margin-top: var(--space-4); }
.login-card .login-error {
  margin-top: var(--space-3);
  color: var(--danger);
  font-size: 13px;
  min-height: 1em;
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: var(--space-7) var(--space-5);
  color: var(--ink-muted);
}
.empty-state h2 { color: var(--ink); }

/* Sandbox toggle */
.sandbox-toggle {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--ink-muted); cursor: pointer;
  user-select: none;
}
.sandbox-toggle input { display: none; }
.sandbox-dot {
  width: 28px; height: 16px; border-radius: 8px; background: var(--surface-3);
  position: relative; transition: background 120ms;
}
.sandbox-dot::after {
  content: ''; position: absolute; top: 2px; left: 2px;
  width: 12px; height: 12px; border-radius: 50%;
  background: white; transition: transform 120ms;
  box-shadow: 0 1px 2px rgba(0,0,0,0.15);
}
.sandbox-toggle input:checked + .sandbox-dot { background: var(--sandbox); }
.sandbox-toggle input:checked + .sandbox-dot::after { transform: translateX(12px); }
body[data-mode="sandbox"] .sandbox-label { color: var(--sandbox); font-weight: 600; }

/* User menu (popover) */
.user-menu {
  position: fixed; top: calc(var(--topbar-h) - 4px); right: var(--space-4);
  width: 240px; background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: var(--radius-card);
  box-shadow: 0 10px 32px rgba(28,24,20,0.16);
  z-index: 200; overflow: hidden;
}
.user-menu-head {
  padding: var(--space-4); display: flex; flex-direction: column; gap: var(--space-1);
  border-bottom: 1px solid var(--border);
}
.user-menu-item {
  display: block; width: 100%; text-align: left;
  background: transparent; border: 0;
  padding: var(--space-3) var(--space-4);
  font-size: 13px; color: var(--ink); cursor: pointer;
}
.user-menu-item:hover { background: var(--hover-bg); }

/* Health strip in topbar */
#health-strip {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--ink-muted);
  padding: 4px 10px; border-radius: 12px; background: var(--surface-2);
  white-space: nowrap; max-width: 360px; overflow: hidden; text-overflow: ellipsis;
}
.health-dot {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%;
}
.health-success { background: var(--success); }
.health-info    { background: var(--info); }
.health-warn    { background: var(--warn); }
.health-danger  { background: var(--danger); }

/* Inbox cards: lift on hover */
.inbox-card { color: var(--ink) !important; }
.inbox-card:hover { transform: translateY(-1px); border-color: var(--gold-soft); }

/* Cmd+K palette */
.cmdk-backdrop {
  position: fixed; inset: 0;
  background: rgba(28,24,20,0.30);
  display: flex; align-items: flex-start; justify-content: center;
  padding-top: 12vh; z-index: 9500;
}
.cmdk-panel {
  width: min(640px, 92vw);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  box-shadow: 0 20px 60px rgba(28,24,20,0.25);
  display: flex; flex-direction: column; max-height: 70vh; overflow: hidden;
}
.cmdk-input-wrap {
  display: flex; align-items: center; gap: 8px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
.cmdk-hint {
  font-family: var(--font-mono); font-size: 11px;
  background: var(--surface-3); color: var(--ink-muted);
  padding: 2px 6px; border-radius: 3px;
}
.cmdk-input {
  flex: 1; border: 0; outline: none;
  font-size: 16px; background: transparent;
  padding: 0; height: 24px;
}
.cmdk-input:focus { outline: none; }
.cmdk-list {
  flex: 1; overflow-y: auto; padding: 4px 0;
}
.cmdk-section-head {
  padding: 8px 18px 4px;
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--ink-subtle); font-weight: 600;
}
.cmdk-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 18px; cursor: pointer; gap: 12px;
  border-left: 3px solid transparent;
}
.cmdk-row:hover { background: var(--hover-bg); }
.cmdk-row.active {
  background: var(--surface-2);
  border-left-color: var(--gold);
}
.cmdk-left { display: flex; align-items: center; min-width: 0; flex: 1 1 auto; }
.cmdk-left > span:last-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cmdk-right { font-size: 12px; flex: 0 0 auto; max-width: 40%;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cmdk-empty { padding: 16px 18px; text-align: center; }
.cmdk-meta { padding: 8px 18px; font-size: 11px; text-align: right; }
.cmdk-footer {
  padding: 8px 18px;
  border-top: 1px solid var(--border);
  font-size: 11px; color: var(--ink-subtle);
}
.cmdk-footer .mono { background: var(--surface-3); padding: 1px 5px; border-radius: 3px; }

/* Cheatsheet kbd styling */
kbd.cheatsheet-key {
  font-family: var(--font-mono); font-size: 11px;
  background: var(--surface-3); color: var(--ink);
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: 3px; padding: 1px 5px;
}

.topbar-icon {
  background: transparent; border: 0; padding: 6px; border-radius: 4px;
  color: var(--ink-muted); cursor: pointer;
}
.topbar-icon:hover { background: var(--hover-bg); color: var(--ink); }
#last-updated { white-space: nowrap; }

/* Saved views section in sidebar */
.sidebar-saved-views {
  padding: var(--space-3) 0; border-top: 1px solid var(--border);
  margin-top: var(--space-3);
}
.sidebar-section-head {
  padding: 0 var(--space-5) var(--space-2);
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--ink-subtle); font-weight: 600;
}
.saved-view-link {
  display: flex; align-items: center; justify-content: space-between;
  padding: 4px var(--space-5); font-size: 12px;
  color: var(--ink-muted); border-left: 2px solid transparent;
}
.saved-view-link:hover { background: var(--hover-bg); color: var(--ink); }
.saved-view-del {
  background: transparent; border: 0; color: var(--ink-subtle);
  font-size: 14px; cursor: pointer; padding: 0 4px; opacity: 0;
  transition: opacity 0.12s;
}
.saved-view-link:hover .saved-view-del { opacity: 1; }
.saved-view-del:hover { color: var(--danger); }

/* Pagination */
.pagination { display: inline-flex; gap: var(--space-2); align-items: center; }
.pagination .page-info { font-size: 13px; color: var(--ink-muted); }

/* Filter bar */
.filter-bar {
  display: flex; gap: var(--space-3); align-items: center; flex-wrap: wrap;
  margin-bottom: var(--space-4);
}
.filter-bar input, .filter-bar select { width: auto; min-width: 140px; }

/* ── Token balance pill (topbar) ─────────────────────────────────────── */
.token-pill {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--ink-muted);
  padding: 4px 10px; border-radius: 12px; background: var(--surface-2);
  border: 1px solid var(--border);
  text-decoration: none;
  white-space: nowrap;
}
.token-pill:hover { color: var(--ink); border-color: var(--border-strong); }
.token-pill-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; }
.token-pill-dot-active   { background: var(--success); }
.token-pill-dot-grace    { background: var(--warn);    }
.token-pill-dot-blackout { background: var(--danger);  }
.token-pill-grace    { color: var(--warn);   border-color: var(--warn-soft);   background: var(--warn-soft); }
.token-pill-blackout { color: var(--danger); border-color: var(--danger-soft); background: var(--danger-soft); }

/* ── KPI strip ───────────────────────────────────────────────────────── */
.kpi-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: var(--space-3);
}
.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: var(--space-4);
}
.kpi-label {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--ink-muted); font-weight: 600;
}
.kpi-value {
  font-family: var(--font-mono);
  font-size: 22px; font-weight: 600;
  color: var(--ink);
  margin: 6px 0;
}
.kpi-spark { color: var(--gold); }
.kpi-meta { color: var(--ink-subtle); }
