/* Admin dashboard styles, on top of /assets/site.css (its tokens, light and
   dark themes, buttons, badges, tables, callouts and cards). Copied to
   /admin/assets/admin.css by scripts/build-site.ts.

   Layout: a fixed sidebar (a sheet behind the menu button below 960px), a
   sticky top bar with breadcrumbs and the user menu, and the screen. */

/* ---------- Shell ---------- */

/* Focused fields scroll clear of the sticky top bar and the sticky save bars. */
html { scroll-padding-top: 76px; scroll-padding-bottom: 96px; }

.shell { min-height: 100vh; min-height: 100dvh; }

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 40;
  width: 264px;
  display: flex;
  flex-direction: column;
  background: var(--sidebar);
  border-right: 1px solid var(--border);
}
.sidebar-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; height: 64px; padding: 0 16px 0 20px; }
.sidebar-close { display: none; }
.sidebar-nav { flex: 1; overflow-y: auto; padding: 8px 12px 16px; display: flex; flex-direction: column; gap: 2px; }
.sidebar-nav a, .sidebar-docs {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 40px;
  padding: 0 12px;
  border-radius: var(--radius-md);
  color: var(--muted-foreground);
  font-size: 15px;
  font-weight: 500;
  transition: background-color 0.12s ease, color 0.12s ease;
}
.sidebar-nav a:hover, .sidebar-docs:hover { background: var(--accent); color: var(--foreground); text-decoration: none; }
.sidebar-nav a[aria-current='page'] { background: var(--primary-soft); color: var(--primary-soft-foreground); }
.sidebar-nav a:focus-visible, .sidebar-docs:focus-visible { outline: 2px solid var(--ring); outline-offset: -2px; }
.nav-icon { display: inline-flex; width: 18px; height: 18px; flex: none; }
.nav-trail { display: inline-flex; margin-left: auto; opacity: 0.7; }
.nav-group { margin: 18px 12px 6px; font-size: 13.5px; font-weight: 600; color: var(--foreground); }
.sidebar-foot { padding: 12px; border-top: 1px solid var(--border); }
.sidebar-backdrop { display: none; }

.main-col { margin-left: 264px; min-width: 0; min-height: 100vh; display: flex; flex-direction: column; }

.app-topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 12px;
  height: 64px;
  padding: 0 24px 0 32px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--background) 86%, transparent);
  backdrop-filter: saturate(1.4) blur(8px);
}
.menu-btn { display: none; }
.account { margin-left: auto; display: flex; align-items: center; }

.crumbs { min-width: 0; font-size: 15px; }
.crumbs ol { list-style: none; display: flex; align-items: center; gap: 6px; margin: 0; padding: 0; min-width: 0; }
.crumb { display: inline-flex; align-items: center; gap: 6px; min-width: 0; color: var(--muted-foreground); }
.crumb a { color: var(--muted-foreground); white-space: nowrap; }
.crumb a:hover { color: var(--foreground); text-decoration: none; }
.crumb-current span { color: var(--foreground); font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.crumb-sep { color: var(--muted-foreground); opacity: 0.7; }

.admin { width: 100%; max-width: 1320px; margin: 0 auto; padding: 32px 40px 80px; outline: none; flex: 1; }
.admin > * + * { margin-top: 24px; }
.admin h1:focus, .admin h2:focus, .admin h3:focus { outline: none; }

/* Signed out: only the sign-in screen. Viewers: no controls they can't use;
   admins: no notes meant for viewers. */
body.signed-out .sidebar, body.signed-out .app-topbar, body.signed-out .sidebar-backdrop { display: none; }
body.signed-out .main-col { margin-left: 0; }
body.role-viewer [data-needs-admin] { display: none !important; }
body:not(.role-viewer) [data-viewer-only] { display: none !important; }
body.role-viewer .settings-form .form-bar:not(:has(.form-status:not(:empty))) { display: none; }

/* ---------- Page structure ---------- */

.page-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px 24px; flex-wrap: wrap; }
.page-heading { min-width: 0; flex: 1 1 360px; }
.page-header h1 { margin: 0; font-size: 28px; font-weight: 700; letter-spacing: -0.025em; overflow-wrap: anywhere; }
.page-description { margin: 6px 0 0; max-width: 72ch; color: var(--muted-foreground); font-size: 15.5px; }
.page-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; margin-top: 10px; }
.page-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.page-actions .updated { margin: 0; }

.section > * + * { margin-top: 16px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 8px 16px; flex-wrap: wrap; }
.section-head h2 { margin: 0; font-size: 20px; }
.section-head h3 { margin: 0; font-size: 17px; }
.section-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.section-intro { display: flex; align-items: center; justify-content: space-between; gap: 12px 20px; flex-wrap: wrap; }
.section-intro .hint { margin: 0; flex: 1 1 360px; }
.tab-panel > * + * { margin-top: 20px; }
.loading-box > * + * { margin-top: 24px; }
.usage-summary { display: grid; gap: 20px; }
.usage-summary > * { margin: 0; }

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 460px), 1fr)); gap: 20px; align-items: start; }
.panels { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 460px), 1fr)); gap: 20px; align-items: start; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); gap: 20px; }
.button-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.button-row .hint { margin: 0; }
.back-link { margin: 0; }
.inline-label { font-size: 14px; color: var(--muted-foreground); font-weight: 500; }
.inline-field { display: inline-flex; align-items: center; gap: 8px; }
.nowrap { white-space: nowrap; }
.mono-sm { font-family: var(--mono); font-size: 14px; }

.hint { color: var(--muted-foreground); font-size: 14.5px; margin: 6px 0 0; line-height: 1.55; }
p.hint:first-child { margin-top: 0; }

/* ---------- Cards ---------- */

.card-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px 16px; flex-wrap: wrap; padding: 20px 24px 0; }
.card-header:last-child { padding-bottom: 20px; }
.card-heading { min-width: 0; flex: 1 1 240px; }
.card-title { margin: 0; font-size: 17px; font-weight: 600; letter-spacing: -0.01em; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
h2.card-title { font-size: 18px; }
.card-description { margin: 4px 0 0; color: var(--muted-foreground); font-size: 14.5px; }
.card-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.card-content { padding: 18px 24px 22px; }
.card-content > :first-child { margin-top: 0; }
.card-content > :last-child { margin-bottom: 0; }
.card-content > * + * { margin-top: 14px; }
.card-flush { padding: 16px 0 0; }
.card-flush > .table-wrap { border: 0; border-top: 1px solid var(--border); border-radius: 0 0 var(--radius-xl) var(--radius-xl); margin: 0; background: transparent; }
.card-flush > .loading-box > .table-wrap, .card-flush > div > .table-wrap { border: 0; border-top: 1px solid var(--border); border-radius: 0 0 var(--radius-xl) var(--radius-xl); margin: 0; background: transparent; }
.card-flush > .callout, .card-flush > div > .callout, .card-flush > .empty-state, .card-flush > div > .empty-state, .card-flush > .loading-box > .skeleton-block { margin: 0 24px 20px; }
.card-flush > .form-status { margin: 0 24px 12px; }
.card-footer { display: flex; align-items: center; gap: 8px 12px; flex-wrap: wrap; padding: 14px 24px; border-top: 1px solid var(--border); background: color-mix(in srgb, var(--muted) 50%, transparent); border-radius: 0 0 var(--radius-xl) var(--radius-xl); }
.card-footer .hint { margin: 0; }
.card-danger { border-color: var(--danger-border); }
.provider-card .card-header { flex-wrap: nowrap; align-items: center; }
.provider-card .card-heading { flex: 1 1 auto; }
.card-danger .card-title { color: var(--danger); }
.card-row { display: flex; align-items: center; justify-content: space-between; gap: 8px 12px; flex-wrap: wrap; }
.card-row .hint { margin: 0; }
.results-card { overflow: hidden; }
.results-card > .card-header { padding-bottom: 4px; }
.results-card > .toolbar { padding: 16px 24px 18px; }
.results-card > .loading-box, .results-card > div:not(.toolbar):not(.card-header):not(.results-head):not(.load-more) { margin: 0; }
.results-card .table-wrap { border: 0; border-top: 1px solid var(--border); border-radius: 0; margin: 0; background: transparent; }
.results-card .empty-state, .results-card > .callout, .results-card .loading-box > .skeleton-block { margin: 0 24px 24px; }
.results-head { padding: 14px 24px 12px; }
.results-head .hint { margin: 0; }
.load-more:not(:empty) { display: flex; justify-content: center; padding: 14px 24px; border-top: 1px solid var(--border); }
.toolbar-card { padding: 20px 24px; }
.toolbar-card > .hint { margin-top: 10px; }

/* ---------- Forms ---------- */

.form { max-width: 720px; }
.form-wide { max-width: 880px; }
.form > * + * { margin-top: 18px; }
.form-wide > * + * { margin-top: 20px; }
.form-summary:empty { display: none; }
.form > .form-summary:empty + * { margin-top: 0; }
.form-summary:focus { outline: none; }
.field { margin-left: 0; margin-right: 0; border: 0; padding: 0; min-width: 0; }
.field + .field, .field + .field-grid, .field-grid + .field, .field-grid + .field-grid { margin-top: 18px; }
.card-content > .field + .field, .card-content > .field-grid + .field, .card-content > .field + .field-grid { margin-top: 20px; }
.label, .field > label, .field legend { display: block; font-size: 14.5px; font-weight: 500; line-height: 1.4; color: var(--foreground); margin: 0 0 8px; padding: 0; }
.field-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr)); gap: 18px 20px; align-items: start; }
.field-grid > .field { margin: 0; }
.field-grid-3 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr)); }

.admin input:not([type='checkbox']):not([type='radio']):not(.select-search-input),
.admin textarea {
  width: 100%;
  min-height: 40px;
  padding: 8px 12px;
  font: inherit;
  font-size: 15px;
  line-height: 1.45;
  color: var(--foreground);
  background: var(--background);
  border: 1px solid var(--input);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-xs);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.admin textarea { min-height: 88px; resize: vertical; }
.admin input::placeholder, .admin textarea::placeholder, .select-search-input::placeholder { color: var(--muted-foreground); opacity: 1; }
.admin input:not([type='checkbox']):focus-visible, .admin textarea:focus-visible, .admin input:not([type='checkbox']):focus {
  outline: none;
  border-color: var(--ring);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--ring) 30%, transparent);
}
.admin input:disabled, .admin textarea:disabled { opacity: 0.6; cursor: not-allowed; background: var(--muted); }
.admin input[type='date'] { min-width: 0; }
.admin input[type='number'] { font-variant-numeric: tabular-nums; }
.field textarea { font-family: var(--mono); font-size: 14.5px; line-height: 1.6; }
.field textarea.template { min-height: 260px; }
.playground-form textarea { font-family: var(--font); font-size: 15px; }
.field [aria-invalid='true'], .admin input[aria-invalid='true'] { border-color: var(--danger) !important; }
.field [aria-invalid='true']:focus { box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 25%, transparent) !important; }
fieldset.field[aria-invalid='true'] { border-left: 3px solid var(--danger); padding-left: 12px; }
.field-error { color: var(--danger); font-size: 14px; font-weight: 500; margin: 6px 0 0; }
.form-status { font-size: 14.5px; color: var(--success); }
.form-status:empty { display: none; }
.form-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.form > .form-actions, .form > div > .form-actions { margin-top: 20px; }
.form-bar .form-actions { margin: 0; }
.form-bar { display: flex; align-items: center; gap: 10px 16px; flex-wrap: wrap; }
.settings-form .form-bar, .form-wide > .form-bar { position: sticky; bottom: 0; z-index: 5; padding: 14px 0; background: linear-gradient(to top, var(--background) 70%, transparent); }
fieldset.plain { border: 0; padding: 0; margin: 0; min-width: 0; display: grid; gap: 20px; }

.input-group { position: relative; display: flex; align-items: stretch; }
.input-group input { padding-right: 44px !important; }
.input-addon-btn {
  position: absolute;
  top: 50%;
  right: 4px;
  transform: translateY(-50%);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 32px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted-foreground);
  cursor: pointer;
}
.input-addon-btn:hover { background: var(--accent); color: var(--foreground); }
.input-addon-btn:focus-visible { outline: 2px solid var(--ring); outline-offset: 0; }

.input-icon { position: relative; }
.input-icon > .icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted-foreground); pointer-events: none; }
.input-icon input { padding-left: 38px !important; }

.toolbar { display: flex; flex-wrap: wrap; gap: 12px 16px; align-items: flex-end; }
.toolbar .field { margin: 0; }
.toolbar .field-check { display: flex; align-items: center; min-height: 40px; }
.toolbar .field-search { flex: 1 1 260px; max-width: 420px; }
.toolbar .select-trigger { min-width: 200px; }
.toolbar-end { margin-left: auto; align-self: center; }
.toolbar-end .hint { margin: 0; }
.field-button { align-self: flex-end; }
.field-inline { max-width: 420px; }
.form-row { display: flex; flex-wrap: wrap; gap: 12px 16px; align-items: flex-end; max-width: none; }
.form-row > * + * { margin-top: 0; }
.form-row .field { margin: 0; min-width: 180px; }
.form-row .form-summary { flex-basis: 100%; }
.form-inline { max-width: 520px; }

.filters { max-width: none; }
.filter-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 210px), 1fr)); gap: 16px 18px; }
.filter-grid .field { margin: 0; }
.filter-grid .select-trigger, .filter-grid .combobox { width: 100%; }
.filter-actions { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding-top: 16px; margin-top: 18px; border-top: 1px solid var(--border); }
.filter-actions .field { margin: 0; }
.filter-actions .form-actions { margin: 0; }

/* ---------- Select, combobox, listbox ---------- */

.select { position: relative; display: inline-flex; max-width: 100%; }
.field > .select, .field > .combobox { display: flex; }
.select-trigger {
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  min-width: 160px;
  min-height: 40px;
  padding: 0 10px 0 12px;
  font: inherit;
  font-size: 15px;
  color: var(--foreground);
  text-align: left;
  background: var(--background);
  border: 1px solid var(--input);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-xs);
  cursor: pointer;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.select-trigger:hover { border-color: color-mix(in srgb, var(--input) 60%, var(--foreground)); }
.select-trigger:focus-visible, .select.is-open .select-trigger { outline: none; border-color: var(--ring); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ring) 30%, transparent); }
.select-trigger:disabled { opacity: 0.6; cursor: not-allowed; background: var(--muted); }
.select-trigger[aria-invalid='true'] { border-color: var(--danger); }
.select-sm { min-height: 34px; font-size: 14px; min-width: 120px; border-radius: var(--radius-sm); }
.select-value { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.select-value.is-placeholder { color: var(--muted-foreground); }
.select-chevron { color: var(--muted-foreground); flex: none; }

.popover {
  z-index: 1000;
  background: var(--popover);
  color: var(--popover-foreground);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  animation: pop-in 0.12s ease-out;
}
.popover[data-side='top'] { animation-name: pop-in-top; }
@keyframes pop-in { from { opacity: 0; transform: translateY(-4px) scale(0.98); } to { opacity: 1; transform: none; } }
@keyframes pop-in-top { from { opacity: 0; transform: translateY(4px) scale(0.98); } to { opacity: 1; transform: none; } }
.select-panel { display: flex; flex-direction: column; overflow: hidden; min-width: 180px; }
.select-panel[hidden] { display: none; }
.select-search { display: flex; align-items: center; gap: 8px; padding: 0 12px; border-bottom: 1px solid var(--border); color: var(--muted-foreground); }
.select-search-input { flex: 1; min-width: 0; height: 42px; border: 0; outline: none; background: transparent; color: var(--foreground); font: inherit; font-size: 15px; }
.select-list { overflow-y: auto; padding: 4px; outline: none; overscroll-behavior: contain; }
.select-option {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 8px 10px 8px 6px;
  border-radius: var(--radius-sm);
  font-size: 15px;
  line-height: 1.4;
  cursor: pointer;
  user-select: none;
}
/* The active option: a tint and an inset ring (the tint alone is too faint to see). */
.select-option.is-active { background: var(--primary-soft); color: var(--primary-soft-foreground); box-shadow: inset 0 0 0 1px var(--ring); }
.select-option[aria-disabled='true'] { opacity: 0.5; cursor: not-allowed; }
.select-option[aria-selected='true'] .select-option-label { font-weight: 500; }
.select-check { display: inline-flex; width: 18px; height: 21px; align-items: center; justify-content: center; flex: none; color: var(--primary); }
.select-option-text { display: flex; flex-direction: column; min-width: 0; }
.select-option-label { overflow-wrap: anywhere; }
.select-option-description { font-size: 13.5px; color: var(--muted-foreground); }
.select-empty { padding: 12px; font-size: 14.5px; color: var(--muted-foreground); text-align: center; }

.combobox { position: relative; display: inline-flex; width: 100%; }
.combobox .combobox-input { padding-right: 40px !important; }
.combobox-toggle {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted-foreground);
  cursor: pointer;
}
.combobox-toggle:hover { background: var(--accent); color: var(--foreground); }

/* ---------- Checkbox, switch ---------- */

.checkbox { position: relative; display: inline-flex; width: 18px; height: 18px; flex: none; }
.checkbox-input {
  appearance: none;
  -webkit-appearance: none;
  margin: 0;
  width: 18px;
  height: 18px;
  border: 1.5px solid var(--input);
  border-radius: 5px;
  background: var(--background);
  box-shadow: var(--shadow-xs);
  cursor: pointer;
  transition: background-color 0.12s ease, border-color 0.12s ease;
}
.checkbox-input:hover { border-color: color-mix(in srgb, var(--input) 50%, var(--foreground)); }
.checkbox-input:checked, .checkbox-input:indeterminate { background: var(--primary); border-color: var(--primary); }
.checkbox-input:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--background), 0 0 0 4px var(--ring); }
.checkbox-input:disabled { opacity: 0.55; cursor: not-allowed; }
.checkbox-input[aria-invalid='true'] { border-color: var(--danger); }
.checkbox .icon { position: absolute; top: 2px; left: 2px; color: var(--primary-foreground); pointer-events: none; opacity: 0; transform: scale(0.6); transition: opacity 0.12s ease, transform 0.12s ease; }
.checkbox-input:checked:not(:indeterminate) ~ .checkbox-check, .checkbox-input:indeterminate ~ .checkbox-dash { opacity: 1; transform: none; }

.check { display: inline-flex; align-items: center; gap: 10px; font-size: 15px; cursor: pointer; line-height: 1.4; }
.check-text { color: var(--foreground); }
.check-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 170px), 1fr)); gap: 10px; margin-top: 10px; }
.check-card { padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--background); transition: border-color 0.12s ease, background-color 0.12s ease; }
.check-card:hover { border-color: var(--input); background: var(--accent); }
.check-card:has(.checkbox-input:checked) { border-color: color-mix(in srgb, var(--primary) 55%, var(--border)); background: var(--primary-soft); }
.field > label.check, .field-check > label.check { display: inline-flex; margin: 0; font-size: 15px; font-weight: 500; }
.check-hint { margin-left: 28px; }
fieldset.checks > legend + .hint { margin: -2px 0 0; }

.switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  flex: none;
  width: 44px;
  height: 24px;
  padding: 2px;
  border: 0;
  border-radius: 999px;
  background: var(--input);
  cursor: pointer;
  transition: background-color 0.15s ease;
}
.switch[aria-checked='true'] { background: var(--primary); }
.switch:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--background), 0 0 0 4px var(--ring); }
.switch:disabled { opacity: 0.55; cursor: not-allowed; }
.switch-thumb { display: block; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgb(0 0 0 / 25%); transition: transform 0.15s ease; }
.switch[aria-checked='true'] .switch-thumb { transform: translateX(20px); }
.field-switch { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px 24px; padding: 14px 16px; border: 1px solid var(--border); border-radius: var(--radius-lg); }
.field-switch .label { margin: 0; cursor: pointer; }
.field-switch .hint { margin-top: 4px; }
.switch-text { min-width: 0; }

/* ---------- Segmented control, tabs ---------- */

.segmented { display: inline-flex; align-items: center; gap: 2px; padding: 3px; border-radius: var(--radius-lg); background: var(--muted); border: 1px solid var(--border); max-width: 100%; overflow-x: auto; }
.segment {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 32px;
  padding: 0 12px;
  border: 0;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--muted-foreground);
  font: inherit;
  font-size: 14.5px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 0.12s ease, color 0.12s ease, box-shadow 0.12s ease;
}
.segment:hover { color: var(--foreground); }
.segment[aria-checked='true'] { background: var(--background); color: var(--foreground); box-shadow: var(--shadow-sm); }
.segment:focus-visible { outline: 2px solid var(--ring); outline-offset: 1px; }
.segmented-sm .segment { min-height: 28px; padding: 0 10px; font-size: 14px; }

.tabs { display: flex; gap: 4px; padding: 4px; border-radius: var(--radius-lg); background: var(--muted); border: 1px solid var(--border); overflow-x: auto; scrollbar-width: none; width: fit-content; max-width: 100%; }
.tabs::-webkit-scrollbar { display: none; }
.tabs a {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  padding: 0 14px;
  border-radius: var(--radius-md);
  color: var(--muted-foreground);
  font-size: 15px;
  font-weight: 500;
  white-space: nowrap;
  transition: background-color 0.12s ease, color 0.12s ease;
}
.tabs a:hover { color: var(--foreground); text-decoration: none; }
.tabs a[aria-current='page'] { background: var(--background); color: var(--foreground); box-shadow: var(--shadow-sm); }
.tabs a:focus-visible { outline: 2px solid var(--ring); outline-offset: -2px; }

/* ---------- KPI cards ---------- */

.kpis { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
@media (min-width: 1480px) { .kpis { grid-template-columns: repeat(6, minmax(0, 1fr)); } }
.kpis.kpis-3 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr)); }
.kpi { display: flex; flex-direction: column; gap: 6px; min-width: 0; padding: 18px 20px; }
.kpi-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.kpi-label { font-size: 14.5px; font-weight: 500; color: var(--muted-foreground); }
.kpi-icon { display: inline-flex; color: var(--muted-foreground); }
.kpi-value { font-size: 30px; font-weight: 700; line-height: 1.15; letter-spacing: -0.025em; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.kpi-sub { font-size: 14px; color: var(--muted-foreground); }
.kpi-warn .kpi-icon { color: var(--warning); }
.kpi-bad .kpi-icon { color: var(--danger); }

/* ---------- Chart ---------- */

.chart-box { margin: 0; }
.chart-figure { position: relative; }
.chart { width: 100%; height: auto; display: block; }
.chart-bar { fill: var(--primary); transition: fill 0.12s ease; }
.chart-bar.is-active { fill: var(--primary-hover); }
.chart-hit { fill: transparent; }
.chart-axis { stroke: var(--input); stroke-width: 1; }
.chart-grid { stroke: var(--border); stroke-width: 1; stroke-dasharray: 3 3; }
.chart-text { fill: var(--muted-foreground); font-size: 14px; font-family: var(--font); }
.chart-tip {
  position: absolute;
  top: 0;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 8px 12px;
  font-size: 14px;
  line-height: 1.35;
  white-space: nowrap;
  pointer-events: none;
  background: var(--popover);
  color: var(--popover-foreground);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
}
.chart-tip[hidden] { display: none; }
.chart-tip strong { font-weight: 600; font-variant-numeric: tabular-nums; }
.chart-tip span { color: var(--muted-foreground); font-size: 13.5px; }
.chart-foot { display: flex; justify-content: flex-end; }

/* ---------- Tables ---------- */

.admin td { vertical-align: middle; }
/* A row that gets focus after "Load older" (tabindex -1). */
tbody tr[tabindex]:focus { outline: none; }
tbody tr[tabindex]:focus-visible { outline: 2px solid var(--ring); outline-offset: -2px; }
.table-scroll { max-height: min(70vh, 760px); }
.table-scroll thead th { position: sticky; top: 0; z-index: 1; box-shadow: inset 0 -1px 0 var(--border); border-bottom-color: transparent; }
table.compact th, table.compact td { padding: 9px 14px; }
.cell-stack { display: inline-flex; flex-direction: column; align-items: flex-start; gap: 3px; min-width: 0; }
td.num .cell-stack { align-items: flex-end; }
.cell-title { font-weight: 500; }
a.cell-title { color: var(--foreground); }
a.cell-title:hover { color: var(--primary); }
.badge-row { display: inline-flex; align-items: center; flex-wrap: wrap; gap: 6px; }
.row-actions { display: inline-flex; align-items: center; justify-content: flex-end; gap: 6px; flex-wrap: wrap; width: 100%; }
td:last-child .row-actions { justify-content: flex-end; }
.attempts code { font-size: 14px; }
.vars { display: inline-flex; flex-wrap: wrap; gap: 4px; }
table.calls td, table.alerts td, table.audit td, table.prices td { font-size: 14.5px; }
table.audit td:last-child { min-width: 240px; }
table.prices td:nth-child(6) { min-width: 230px; }
table.prices td:nth-child(7) { min-width: 170px; }

.empty-state { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 6px; padding: 36px 20px; border: 1px dashed var(--border); border-radius: var(--radius-lg); }
.empty-icon { display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px; margin-bottom: 6px; border-radius: 50%; background: var(--muted); color: var(--muted-foreground); }
.empty-title { margin: 0; font-weight: 600; font-size: 16px; }
.empty-description { margin: 0; max-width: 46ch; color: var(--muted-foreground); font-size: 14.5px; }
.empty-action { margin-top: 10px; }
.card > .empty-state, .card-content > .empty-state { border: 0; }

/* ---------- Status chips, meters, detail lists ---------- */

.chips { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; align-items: center; gap: 8px; padding: 5px 12px; font-size: 14.5px; border: 1px solid var(--border); border-radius: 999px; background: var(--background); }
.chip:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }
.chip-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted-foreground); flex: none; }
.chip-ok .chip-dot { background: var(--success); box-shadow: 0 0 0 3px var(--success-soft); }
.chip-bad { border-color: var(--danger-border); background: var(--danger-soft); }
.chip-bad .chip-dot { background: var(--danger); }

.spend { display: inline-flex; flex-direction: column; gap: 6px; min-width: 170px; }
.meter { display: block; height: 6px; border-radius: 999px; background: var(--muted); overflow: hidden; }
.meter-fill { display: block; height: 100%; border-radius: 999px; background: var(--success); }
.meter-warn .meter-fill { background: var(--warning); }
.meter-bad .meter-fill { background: var(--danger); }

dl.details { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 10px 24px; margin: 0; font-size: 15px; }
dl.details dt { color: var(--muted-foreground); }
dl.details dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.alert-fields { margin-top: 6px; }
.alert-fields summary, details.raw summary { cursor: pointer; color: var(--primary); font-size: 14.5px; font-weight: 500; }
.alert-fields dl.details { font-size: 14px; margin-top: 8px; gap: 4px 16px; }
details.raw { margin-top: 16px; }
details.raw pre { margin-top: 10px; }
.detail-id { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.detail-id code { font-size: 14px; }
.telegram-state { gap: 8px; }
.telegram-state .badge, .badge-wrap { white-space: normal; }
.prompt-meta { color: var(--muted-foreground); margin: 0; }
.tips { margin: 0; padding-left: 20px; }
.tips li + li { margin-top: 8px; }
.card-content > pre.snippet-code + .tips { margin-top: 14px; }
/* Settings → Alerts: chats found in the bot's recent messages. */
.chat-list { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 8px; }
.chat-list li { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.chat-list .hint { margin: 0; }

/* ---------- Key reveal ---------- */

.key-reveal { border-color: var(--warning-border); box-shadow: 0 0 0 4px var(--warning-soft), var(--shadow-sm); }
.key-reveal:focus { outline: none; box-shadow: 0 0 0 2px var(--background), 0 0 0 4px var(--ring); }
.key-reveal .card-title .icon { color: var(--warning); }
.secret-row { display: flex; align-items: stretch; gap: 10px; flex-wrap: wrap; }
.secret-key { flex: 1 1 320px; display: block; font-size: 15px; padding: 10px 14px; border-radius: var(--radius-md); overflow-wrap: anywhere; user-select: all; background: var(--muted); }

/* ---------- Integrate snippets, playground ---------- */

.snippets { display: grid; grid-template-columns: minmax(0, 1fr); gap: 20px; }
.card { min-width: 0; }
.playground > *, .panels > *, .cards > *, .grid-2 > * { min-width: 0; }
.snippet .card-content { padding-top: 14px; }
.install-line { display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap; }
pre.snippet-code { margin: 0; max-height: 440px; overflow: auto; }
pre.scroll-pre { margin: 0; max-height: 440px; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; }

.playground { display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); gap: 20px; align-items: start; }
.playground-form { max-width: none; }
.playground-result { position: sticky; top: 84px; }
.playground-result-body > * + * { margin-top: 16px; }
.result-title { margin: 0; font-size: 16px; }
.reply-wrap { position: relative; }
.reply-wrap > .copy-btn { position: absolute; top: 8px; right: 8px; background: var(--background); }
.reply { white-space: pre-wrap; overflow-wrap: anywhere; max-height: 480px; overflow: auto; padding: 14px 48px 14px 16px; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--muted); font-size: 15.5px; line-height: 1.65; }
.waiting { display: flex; align-items: center; gap: 10px; color: var(--muted-foreground); padding: 20px 0; }
.vars-set { padding: 14px 16px; border: 1px solid var(--border); border-radius: var(--radius-lg); }
.vars-set .field + .field { margin-top: 12px; }

.copy-btn.is-copied { color: var(--success); }

/* ---------- Dropdown menu ---------- */

.menu { min-width: 220px; max-width: 320px; padding: 4px; overflow-y: auto; outline: none; }
.menu[hidden] { display: none; }
.menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 38px;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  font-size: 15px;
  cursor: pointer;
  outline: none;
  user-select: none;
}
.menu-item:hover { background: var(--accent); color: var(--accent-foreground); }
/* The focused item: a tint and an inset ring (the tint alone is too faint to see). */
.menu-item:focus { background: var(--primary-soft); color: var(--primary-soft-foreground); box-shadow: inset 0 0 0 1px var(--ring); }
.menu-item[aria-disabled='true'] { opacity: 0.5; cursor: not-allowed; }
.menu-item .icon { color: var(--muted-foreground); }
.menu-item-destructive, .menu-item-destructive .icon { color: var(--danger); }
.menu-item-destructive:focus, .menu-item-destructive:hover { background: var(--danger-soft); color: var(--danger); }
.menu-item-destructive:focus { box-shadow: inset 0 0 0 1px var(--danger); }
.menu-text { display: flex; flex-direction: column; min-width: 0; }
.menu-description { font-size: 13.5px; color: var(--muted-foreground); line-height: 1.35; }
.menu-check { display: inline-flex; width: 16px; justify-content: center; color: var(--primary); }
.menu-separator { height: 1px; margin: 4px -4px; background: var(--border); }
.menu-label { padding: 6px 10px 2px; font-size: 13.5px; font-weight: 600; color: var(--muted-foreground); }
.menu-header { display: flex; align-items: center; gap: 10px; padding: 10px; }
.menu-who { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.menu-who-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu-who-email { font-size: 14px; color: var(--muted-foreground); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- User menu trigger, avatar ---------- */

.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--primary-soft);
  color: var(--primary-soft-foreground);
  font-size: 14px;
  font-weight: 600;
}
.avatar-sm { width: 32px; height: 32px; font-size: 13px; }
.user-trigger {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 4px 8px 4px 4px;
  border: 1px solid transparent;
  border-radius: var(--radius-lg);
  background: transparent;
  color: var(--foreground);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.user-trigger:hover, .user-trigger[aria-expanded='true'] { background: var(--accent); }
.user-trigger:focus-visible { outline: 2px solid var(--ring); outline-offset: 1px; }
.user-trigger-text { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; max-width: 220px; }
.user-name { font-size: 14.5px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-role { font-size: 13.5px; color: var(--muted-foreground); }
.user-chevron { color: var(--muted-foreground); }
.user-cell { display: inline-flex; align-items: center; gap: 12px; min-width: 0; }

/* ---------- Dialogs and sheets ---------- */

dialog.modal {
  width: min(520px, calc(100vw - 32px));
  max-height: calc(100dvh - 48px);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  background: var(--card);
  color: var(--card-foreground);
  box-shadow: var(--shadow-xl);
  overflow: hidden;
  flex-direction: column;
}
dialog.modal[open] { display: flex; animation: dialog-in 0.16s ease-out; }
dialog.modal-wide { width: min(920px, calc(100vw - 32px)); }
dialog.modal::backdrop { background: var(--overlay); backdrop-filter: blur(2px); }
@keyframes dialog-in { from { opacity: 0; transform: translateY(8px) scale(0.98); } to { opacity: 1; transform: none; } }
.modal-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 20px 24px 0; }
.modal-title { margin: 0; font-size: 19px; font-weight: 600; letter-spacing: -0.01em; }
.modal-x { margin: -4px -8px 0 0; }
.modal-body { padding: 16px 24px 8px; overflow-y: auto; min-height: 0; }
.modal-body p { margin: 0 0 10px; }
.modal-body > * + * { margin-top: 14px; }
.modal-body h3 { margin: 20px 0 8px; font-size: 16px; }
.modal-body h4 { margin: 14px 0 6px; font-size: 15px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; padding: 16px 24px 20px; flex-wrap: wrap; }
.modal-confirm .modal-body { padding-top: 12px; }
.confirm-row { display: flex; gap: 14px; align-items: flex-start; }
.confirm-icon { display: inline-flex; align-items: center; justify-content: center; flex: none; width: 40px; height: 40px; border-radius: 50%; background: var(--danger-soft); color: var(--danger); }
.confirm-text { min-width: 0; color: var(--muted-foreground); }
.confirm-text p:last-child { margin-bottom: 0; }
.text-section + .text-section { margin-top: 16px; }

dialog.modal-sheet {
  width: min(680px, 100vw);
  height: 100dvh;
  max-height: 100dvh;
  max-width: 100vw;
  margin: 0 0 0 auto;
  border-radius: 0;
  border-width: 0 0 0 1px;
}
dialog.modal-sheet[open] { animation: sheet-in 0.2s ease-out; }
@keyframes sheet-in { from { transform: translateX(32px); opacity: 0; } to { transform: none; opacity: 1; } }
dialog.modal-sheet .modal-body { flex: 1; }
dialog.modal-sheet .modal-actions { border-top: 1px solid var(--border); }

/* ---------- Toasts ---------- */

.toaster { position: fixed; right: 20px; bottom: 20px; z-index: 2000; display: flex; flex-direction: column; gap: 10px; width: min(400px, calc(100vw - 32px)); margin: 0; padding: 0; list-style: none; pointer-events: none; }
.toast {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 14px 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--popover);
  color: var(--popover-foreground);
  box-shadow: var(--shadow-xl);
  pointer-events: auto;
  animation: toast-in 0.2s ease-out;
}
.toast-leaving { animation: toast-out 0.16s ease-in forwards; }
@keyframes toast-in { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateX(16px); } }
.toast-icon { margin-top: 2px; color: var(--muted-foreground); }
.toast-success .toast-icon { color: var(--success); }
.toast-error { border-color: var(--danger-border); }
.toast-error .toast-icon { color: var(--danger); }
.toast-body { flex: 1; min-width: 0; }
.toast-title { margin: 0; font-weight: 600; font-size: 15px; overflow-wrap: anywhere; }
.toast-description { margin: 2px 0 0; font-size: 14.5px; color: var(--muted-foreground); }
.toast-close { display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px; flex: none; margin: -4px -4px 0 0; border: 0; border-radius: var(--radius-sm); background: transparent; color: var(--muted-foreground); cursor: pointer; }
.toast-close:hover { background: var(--accent); color: var(--foreground); }
.toast-close:focus-visible { outline: 2px solid var(--ring); }

/* ---------- Tooltip ---------- */

.tooltip {
  z-index: 3000;
  max-width: 280px;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  background: var(--foreground);
  color: var(--background);
  font-size: 14px;
  line-height: 1.4;
  animation: pop-in 0.1s ease-out;
}
.tooltip[hidden] { display: none; }

/* ---------- Skeletons ---------- */

.skeleton { display: block; border-radius: var(--radius-sm); background: var(--muted); background-image: linear-gradient(90deg, transparent, color-mix(in srgb, var(--background) 55%, transparent), transparent); background-size: 200% 100%; animation: shimmer 1.4s ease-in-out infinite; }
@keyframes shimmer { from { background-position: 150% 0; } to { background-position: -50% 0; } }
.skeleton-block { display: flex; flex-direction: column; gap: 12px; }
.skeleton-table { gap: 14px; padding: 4px 0; }
.skeleton-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 190px), 1fr)); gap: 16px; }
.skeleton-card { display: flex; flex-direction: column; gap: 10px; padding: 18px 20px; border: 1px solid var(--border); border-radius: var(--radius-xl); }
.skeleton-gap { margin-bottom: 8px; }

/* ---------- Sign-in ---------- */

.admin.admin-login { display: flex; align-items: center; justify-content: center; min-height: 100vh; min-height: 100dvh; padding: 32px 16px; background: radial-gradient(ellipse at top, color-mix(in srgb, var(--primary) 10%, transparent), transparent 60%); }
.login { width: 100%; max-width: 420px; }
.login > * + * { margin-top: 20px; }
.login-brand { display: flex; align-items: center; justify-content: center; gap: 12px; font-size: 18px; font-weight: 600; letter-spacing: -0.01em; }
.login-brand .logo { width: 40px; height: 40px; }
.login-card { padding: 28px; box-shadow: var(--shadow-lg); }
.login-head { margin-bottom: 22px; text-align: center; }
.login-head h1 { margin: 0; font-size: 26px; font-weight: 700; letter-spacing: -0.02em; }
.login-head .page-description { margin-top: 6px; }
.login-form { max-width: none; }
.login-form .form-actions { margin-top: 24px; }
.login-foot { text-align: center; }

/* ---------- Responsive ---------- */

@media (max-width: 1100px) {
  .playground { grid-template-columns: minmax(0, 1fr); }
  .playground-result { position: static; }
}

@media (max-width: 960px) {
  .sidebar {
    width: min(300px, 86vw);
    box-shadow: var(--shadow-xl);
    transform: translateX(-105%);
    visibility: hidden;
    transition: transform 0.2s ease, visibility 0.2s;
  }
  body.nav-open .sidebar { transform: none; visibility: visible; }
  body.nav-open .sidebar-backdrop { display: block; position: fixed; inset: 0; z-index: 35; background: var(--overlay); }
  .sidebar-close { display: inline-flex; }
  .main-col { margin-left: 0; }
  .menu-btn { display: inline-flex; }
  .app-topbar { padding: 0 12px 0 8px; gap: 6px; }
  .admin { padding: 24px 20px 64px; }
}

@media (max-width: 640px) {
  .admin { padding: 20px 16px 56px; }
  .admin > * + * { margin-top: 20px; }
  .page-header h1 { font-size: 24px; }
  .page-actions { width: 100%; }
  .crumb:not(.crumb-current) { display: none; }
  .user-trigger-text, .user-chevron { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }
  .user-trigger { padding: 4px; }
  .card-header { padding: 16px 16px 0; }
  .card-header:last-child { padding-bottom: 16px; }
  .card-content { padding: 14px 16px 18px; }
  .card-flush { padding: 12px 0 0; }
  .card-footer { padding: 12px 16px; }
  .card-flush > .callout, .card-flush > div > .callout, .card-flush > .empty-state, .card-flush > div > .empty-state { margin: 0 16px 16px; }
  .toolbar-card { padding: 16px; }
  .results-card > .toolbar { padding: 14px 16px 4px; }
  .results-head { padding: 12px 16px; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .kpi { padding: 14px 16px; }
  .kpi-value { font-size: 24px; }
  dl.details { grid-template-columns: minmax(0, 1fr); gap: 2px; }
  dl.details dd { margin-bottom: 10px; }
  .toolbar .field, .toolbar .field-search { flex: 1 1 100%; max-width: none; }
  .toolbar .select-trigger { min-width: 0; }
  .toolbar-end { margin-left: 0; }
  .form-row .field { flex: 1 1 100%; }
  .spend { min-width: 130px; }
  .admin input:not([type='checkbox']):not([type='radio']), .admin textarea, .select-trigger, .select-search-input { font-size: 16px; }
  .login-card { padding: 22px 18px; }
  .modal-header { padding: 16px 16px 0; }
  .modal-body { padding: 14px 16px 6px; }
  .modal-actions { padding: 14px 16px 16px; }
  .modal-actions .btn { flex: 1 1 auto; }
  .toaster { right: 16px; bottom: 16px; }
  .field-switch { padding: 12px 14px; }
}

@media (prefers-reduced-motion: reduce) {
  .skeleton { animation: none; background-image: none; }
}
