/* ── Shared components ───────────────────────────────────────────────
   The one definition of each component every page uses: buttons, badges,
   form fields, notices, the modal shell, the focus ring and the skip link.
   Needs tokens.css before it. Linked by the app (index.html), the API docs,
   and the standalone app pages (team, integrations, file viewer) — never
   copy one of these rules into a page's own <style> block; link this file. */

/* ── Keyboard focus ──────────────────────────────────────────────── */
/* One visible focus ring for every control. !important because many
   components reset `outline: none` on their base class. */
:focus-visible { outline: 2px solid var(--blue) !important; outline-offset: 2px; }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline-offset: 1px; }
/* Dialog panels receive programmatic focus only as a fallback; no ring. */
[tabindex="-1"]:focus-visible { outline: none !important; }

/* ── Skip link ───────────────────────────────────────────────────── */
/* First focusable element on the page; off-screen until it has focus. */
.skip-link {
  position: fixed; top: 0.5rem; left: 0.5rem; z-index: 10001;
  padding: 0.55rem 0.9rem; border-radius: var(--r-sm);
  background: var(--surface-s); color: var(--blue-ink);
  border: 1px solid var(--border-hi); box-shadow: var(--sh);
  font-size: 0.875rem; font-weight: 700; text-decoration: none;
  transform: translateY(-200%);
}
.skip-link:focus { transform: translateY(0); }

/* ── Buttons ─────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 0.55rem 1.15rem;
  border: none; border-radius: var(--r-sm);
  cursor: pointer; font-family: var(--font);
  font-size: 0.875rem; font-weight: 700;
  transition: all 0.16s ease; white-space: nowrap;
  line-height: 1; text-decoration: none;
}
.btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none !important; box-shadow: none !important; }

/* Primary: white on --grad (at least 4.9:1 across the gradient). */
.btn-primary {
  background: var(--grad);
  color: #fff;
  box-shadow: 0 2px 12px rgba(37,99,235,0.28);
}
.btn-primary:hover:not(:disabled) {
  background: var(--grad-hover);
  box-shadow: 0 4px 20px rgba(37,99,235,0.36);
  transform: translateY(-1px);
}
.btn-primary:active { transform: translateY(0); box-shadow: 0 2px 8px rgba(37,99,235,0.22); }

.btn-ghost {
  background: var(--surface); color: var(--text-2);
  border: 1px solid var(--border-md);
  box-shadow: var(--sh-xs);
}
.btn-ghost:hover:not(:disabled) { background: #fff; color: var(--text); border-color: var(--border-hi); box-shadow: var(--sh-sm); }

.btn-danger {
  background: var(--red-dim); color: var(--red-ink);
  border: 1px solid rgba(239,68,68,0.22);
}
.btn-danger:hover:not(:disabled) { background: rgba(239,68,68,0.16); }
/* A ghost button whose action is destructive (Revoke, Remove). */
.btn-ghost.btn-ghost-danger { color: var(--red-ink); border-color: rgba(239,68,68,0.3); }
.btn-ghost.btn-ghost-danger:hover:not(:disabled) { color: var(--red-ink); background: var(--red-dim); border-color: rgba(239,68,68,0.45); }

.btn-icon {
  padding: 0.3rem 0.4rem; background: transparent; color: var(--text-3);
  border-radius: var(--r-sm); line-height: 1; border: none;
}
.btn-icon:hover:not(:disabled) { background: var(--hover); color: var(--text); }

.btn-sm { padding: 0.35rem 0.72rem; font-size: 0.8rem; }
.btn-block { width: 100%; justify-content: center; }

/* ── Badges ──────────────────────────────────────────────────────── */
.badge {
  display: inline-block; padding: 0.18rem 0.55rem;
  border-radius: var(--r-pill); font-size: 0.72rem; font-weight: 700;
  white-space: nowrap;
}
.badge-blue   { background: var(--blue-dim);   color: var(--blue-ink); }
.badge-teal   { background: var(--teal-dim);   color: var(--teal-ink); }
.badge-green  { background: var(--green-dim);  color: var(--green-ink); }
.badge-amber  { background: var(--amber-dim);  color: var(--amber-ink); }
.badge-red    { background: var(--red-dim);    color: var(--red-ink); }
.badge-purple { background: var(--purple-dim); color: var(--purple-ink); }

/* ── Form fields ─────────────────────────────────────────────────── */
.form-row { display: flex; flex-direction: column; gap: 0.25rem; }
.form-label { font-size: 0.78rem; font-weight: 600; color: var(--text-2); }
.form-input, .form-select {
  padding: 0.5rem 0.75rem; font-size: 0.85rem; font-family: var(--font);
  background: rgba(255,255,255,0.92); border: 1.5px solid var(--border-md);
  border-radius: var(--r); color: var(--text); outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.form-input:focus, .form-select:focus {
  border-color: var(--border-hi); box-shadow: 0 0 0 3px var(--blue-glow);
}
.form-input::placeholder { color: var(--text-placeholder); }
/* Compact field for a row inside a drawer or modal (model picker, credit limit). */
.form-input-sm, .form-select-sm { padding: 0.38rem 0.6rem; font-size: 0.82rem; border-width: 1px; border-radius: var(--r-sm); }
.form-input-num { width: 6.5rem; }
/* Label + field (+ unit) on one line. */
.form-inline { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.form-inline .form-label { white-space: nowrap; }
.form-unit { font-size: 0.75rem; color: var(--text-3); }
.form-error { color: var(--red-ink); font-size: 0.82rem; }

/* ── Inline notice (auth errors, failed questions) ───────────────── */
.notice {
  font-size: 0.875rem; line-height: 1.5; color: var(--text); text-align: left;
  padding: 0.55rem 0.75rem; border-radius: var(--r-sm); border-left: 3px solid;
}
.notice-error   { background: var(--red-dim);   border-left-color: var(--red); }
.notice-success { background: var(--green-dim); border-left-color: var(--green); }

/* ── Modal shell ─────────────────────────────────────────────────── */
/* One shell for every modal: <div class="modal-overlay"> > <div class="modal">.
   The overlay gets .open to show it. Width comes from a size modifier
   (default 400px, .modal-md 480px, .modal-lg 720px). */
.modal-overlay {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(30,80,160,0.22);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  display: flex; align-items: center; justify-content: center;
  padding: 1rem;
  opacity: 0; pointer-events: none;
  /* visibility (delayed until the fade ends) keeps the closed modal's controls
     out of the Tab order and the accessibility tree. */
  visibility: hidden; transition: opacity 0.18s ease, visibility 0s linear 0.18s;
}
.modal-overlay.open { opacity: 1; pointer-events: all; visibility: visible; transition: opacity 0.18s ease, visibility 0s; }
/* Confirm / prompt dialogs (js/dialog.js) and the one-time key modal sit above
   drawers and other modals. */
.modal-overlay-top { z-index: 1500; }
.modal {
  display: flex; flex-direction: column; gap: 1rem;
  background: var(--surface-s);
  border: 1px solid var(--border-md);
  border-radius: var(--r-xl); padding: 1.5rem;
  width: 100%; max-width: 400px;
  max-height: calc(100vh - 2rem); max-height: calc(100dvh - 2rem); overflow-y: auto;
  box-shadow: var(--sh-xl);
  transform: scale(0.97) translateY(10px); transition: transform 0.2s ease;
}
/* `none`, not scale(1): a transform would make the modal the containing block
   for position:fixed children (the access picker's results list). */
.modal-overlay.open .modal { transform: none; }
.modal-md { max-width: 480px; }
.modal-lg { max-width: 720px; }
/* Sectioned modal: no padding of its own, each section pads itself. */
.modal-flush { padding: 0; gap: 0; overflow: hidden; }
.modal-header { display: flex; align-items: center; gap: 0.5rem; }
.modal-header-icon { flex-shrink: 0; color: var(--blue-ink); }
.modal-title { font-size: 1.05rem; font-weight: 800; color: var(--text); flex: 1; min-width: 0; overflow-wrap: anywhere; }
.modal-desc, .modal-message { font-size: 0.875rem; color: var(--text-2); line-height: 1.55; overflow-wrap: anywhere; }
/* Confirm messages keep their paragraph breaks. */
.modal-message { white-space: pre-line; }
.modal-close {
  display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0;
  background: none; border: none; cursor: pointer; font-size: 1.3rem;
  color: var(--text-2); line-height: 1; padding: 0.3rem;
  border-radius: var(--r-sm); transition: color 0.15s, background 0.15s;
}
.modal-close:hover { color: var(--text); background: var(--hover); }
.modal-input {
  width: 100%; padding: 0.7rem 0.95rem;
  background: rgba(237,245,255,0.7); border: 1px solid var(--border-md);
  border-radius: var(--r); color: var(--text);
  font-family: var(--font); font-size: 0.92rem; font-weight: 500;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.modal-input:focus {
  border-color: var(--border-hi); background: #fff;
  box-shadow: 0 0 0 3px var(--blue-glow);
}
.modal-input::placeholder { color: var(--text-placeholder); }
.modal-actions { display: flex; gap: 0.55rem; justify-content: flex-end; flex-wrap: wrap; }
.modal-section-title { font-size: 0.78rem; font-weight: 700; color: var(--text); }
/* Confirm dialogs: the message can be long (a file name), never a wide box. */
.modal-confirm .modal-title { font-size: 1rem; line-height: 1.45; }
@media (max-width: 600px) {
  .modal { padding: 1.25rem; }
  /* Full-width actions are easier to hit and never wrap mid-label. */
  .modal-confirm .modal-actions .btn { flex: 1 1 auto; justify-content: center; }
}
@media (prefers-reduced-motion: reduce) {
  .modal-overlay, .modal { transition: none; }
}

/* ── Visually hidden (still read by screen readers) ──────────────── */
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* ── Toggle switch ───────────────────────────────────────────────── */
/* <label class="toggle"><input type="checkbox" role="switch"><span class="toggle-track"></span></label> */
/* display:inline-block matters: a label is inline by default, so the 28×16 box
   only held inside flex parents. In a plain container (e.g. a table cell) the
   box collapsed and the absolutely-positioned track rendered broken. */
.toggle { position: relative; display: inline-block; width: 28px; height: 16px; flex-shrink: 0; vertical-align: middle; }
.toggle input { opacity: 0; width: 0; height: 0; position: absolute; }
.toggle-track {
  position: absolute; inset: 0;
  /* The off state needs 3:1 against the panel to be seen as a control. */
  background: #c9d8ea; border: 1px solid #7f9bb8;
  border-radius: 999px; cursor: pointer; transition: all 0.18s ease;
}
.toggle-track::after {
  content: ''; position: absolute;
  width: 10px; height: 10px;
  background: #fff; border-radius: 50%;
  top: 2px; left: 2px; transition: all 0.18s ease;
  box-shadow: 0 1px 3px rgba(30,90,180,0.18);
}
.toggle input:checked + .toggle-track {
  background: var(--grad);
  border-color: transparent;
}
.toggle input:checked + .toggle-track::after { left: 14px; }
.toggle input:focus-visible + .toggle-track { outline: 2px solid var(--blue); outline-offset: 2px; }
/* A file inside a folder that is switched off: its switch is locked and shows
   off, whatever the file's own setting, because the folder excludes it. */
.toggle input:disabled + .toggle-track { cursor: not-allowed; background: #e3ebf5; border-color: #b9c9dc; }
.toggle input:disabled + .toggle-track::after { left: 2px; box-shadow: none; }

/* ── Back link (standalone app pages: team, integrations, file viewer) ── */
.back-link {
  display: inline-flex; align-items: center; gap: 0.35rem;
  font-size: 0.82rem; font-weight: 700; color: var(--text-2);
  text-decoration: none; padding: 0.38rem 0.8rem; border-radius: var(--r-pill);
  background: none; border: none; cursor: pointer; font-family: var(--font);
  transition: color 0.15s, background 0.15s;
}
.back-link:hover { background: var(--hover); color: var(--text); }
