/* ==========================================================================
   Demo — components
   Every class is prefixed a1- so it never collides with legacy Bootstrap 3.
   ========================================================================== */

/* ---------- Buttons ---------- */
.a1-btn {
  --_bg: var(--a1-surface); --_fg: var(--a1-ink); --_bd: var(--a1-line);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 42px; padding: 0 16px;
  border: 1px solid var(--_bd); border-radius: var(--a1-r-sm);
  background: var(--_bg); color: var(--_fg);
  font: 600 var(--a1-text-md)/1 var(--a1-font);
  text-decoration: none !important; white-space: nowrap; cursor: pointer;
  transition: background var(--a1-fast) var(--a1-ease), border-color var(--a1-fast) var(--a1-ease),
              box-shadow var(--a1-fast) var(--a1-ease), transform var(--a1-fast) var(--a1-ease);
  -webkit-tap-highlight-color: transparent;
}
.a1-btn:hover  { border-color: var(--a1-ink-4); }
.a1-btn:active { transform: translateY(1px); }
.a1-btn[disabled], .a1-btn[aria-disabled="true"] { opacity: .55; cursor: not-allowed; transform: none; }

.a1-btn--primary { --_bg: var(--a1-primary); --_fg: #fff; --_bd: transparent; box-shadow: 0 1px 2px rgba(76, 22, 184, .25), inset 0 1px 0 rgba(255,255,255,.14); }
.a1-btn--primary:hover  { --_bg: var(--a1-primary-hover); }
.a1-btn--primary:active { --_bg: var(--a1-primary-press); }

.a1-btn--soft   { --_bg: var(--a1-primary-soft); --_fg: var(--a1-primary-text); --_bd: transparent; }
.a1-btn--soft:hover { --_bd: var(--a1-purple-100); }
.a1-btn--ghost  { --_bg: transparent; --_bd: transparent; --_fg: var(--a1-ink-2); }
.a1-btn--ghost:hover { --_bg: var(--a1-line-2); }
.a1-btn--danger { --_bg: var(--a1-danger-500); --_fg: #fff; --_bd: transparent; }
.a1-btn--success{ --_bg: var(--a1-success-500); --_fg: #fff; --_bd: transparent; }

.a1-btn--sm    { min-height: 34px; padding: 0 12px; font-size: var(--a1-text-sm); border-radius: 8px; }
.a1-btn--lg    { min-height: 50px; padding: 0 22px; font-size: 16px; }
.a1-btn--block { display: flex; width: 100%; }
.a1-btn--icon  { width: 42px; padding: 0; }
.a1-btn--icon.a1-btn--sm { width: 34px; }

.a1-btn.is-loading { color: transparent !important; position: relative; pointer-events: none; }
.a1-btn.is-loading::after {
  content: ""; position: absolute; width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid currentColor; border-color: rgba(255,255,255,.9) rgba(255,255,255,.9) rgba(255,255,255,.25) rgba(255,255,255,.25);
  animation: a1-spin .7s linear infinite;
}
.a1-btn:not(.a1-btn--primary):not(.a1-btn--danger):not(.a1-btn--success).is-loading::after {
  border-color: var(--a1-primary) var(--a1-primary) var(--a1-purple-100) var(--a1-purple-100);
}
@keyframes a1-spin { to { transform: rotate(360deg); } }

/* ---------- Form fields ---------- */
.a1-field { display: grid; gap: 6px; margin-bottom: var(--a1-s4); }
.a1-label { font-size: var(--a1-text-sm); font-weight: 600; color: var(--a1-ink); }
.a1-label .req { color: var(--a1-danger-500); margin-left: 2px; }
.a1-help  { font-size: var(--a1-text-sm); color: var(--a1-ink-3); }

.a1-control { position: relative; display: flex; align-items: center; }
.a1-control > .a1-ico-lead {
  position: absolute; left: 13px; color: var(--a1-ink-4); pointer-events: none;
  width: 18px; height: 18px;
}
.a1-control > .a1-trail { position: absolute; right: 6px; }

.a1-input, .a1-select, .a1-textarea {
  width: 100%; min-height: 46px; padding: 11px 14px;
  border: 1px solid var(--a1-line); border-radius: var(--a1-r-sm);
  background: var(--a1-surface); color: var(--a1-ink);
  font: 400 16px/1.3 var(--a1-font);   /* 16px stops iOS zoom-on-focus */
  transition: border-color var(--a1-fast) var(--a1-ease), box-shadow var(--a1-fast) var(--a1-ease);
  -webkit-appearance: none; appearance: none;
}
.a1-control > .a1-ico-lead ~ .a1-input { padding-left: 42px; }
.a1-control > .a1-trail ~ .a1-input,
.a1-control .a1-input:has(+ .a1-trail) { padding-right: 48px; }
.a1-input::placeholder, .a1-textarea::placeholder { color: var(--a1-ink-4); }
.a1-input:hover, .a1-select:hover, .a1-textarea:hover { border-color: #CBD3E1; }
.a1-input:focus, .a1-select:focus, .a1-textarea:focus {
  outline: none; border-color: var(--a1-primary);
  box-shadow: 0 0 0 4px var(--a1-primary-soft);
}
.a1-select {
  padding-right: 40px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%2364748B' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m4 6 4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center;
}
.a1-textarea { min-height: 110px; resize: vertical; }

.a1-field.is-invalid .a1-input,
.a1-field.is-invalid .a1-select { border-color: var(--a1-danger-500); box-shadow: 0 0 0 4px var(--a1-danger-50); }
.a1-error { display: flex; gap: 6px; align-items: center; font-size: var(--a1-text-sm); color: var(--a1-danger-700); }
.a1-field.is-valid .a1-input { border-color: var(--a1-success-500); }

.a1-check { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; color: var(--a1-ink-2); font-size: var(--a1-text-md); user-select: none; }
.a1-check input {
  -webkit-appearance: none; appearance: none; margin: 0;
  width: 18px; height: 18px; border: 1.5px solid #B9C2D3; border-radius: 5px; background: var(--a1-surface);
  display: grid; place-items: center; cursor: pointer;
  transition: background var(--a1-fast), border-color var(--a1-fast);
}
.a1-check input:checked { background: var(--a1-primary); border-color: var(--a1-primary); }
.a1-check input:checked::after {
  content: ""; width: 9px; height: 5px; border: 2px solid #fff; border-top: 0; border-right: 0;
  transform: rotate(-45deg) translate(1px, -1px);
}

/* Segmented control (role="tablist") */
.a1-seg {
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px;
  padding: 4px; background: var(--a1-line-2); border-radius: 12px;
}
.a1-seg button {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 40px; border: 0; border-radius: 9px; background: transparent;
  color: var(--a1-ink-3); font: 600 var(--a1-text-md)/1 var(--a1-font); cursor: pointer;
  transition: background var(--a1-fast) var(--a1-ease), color var(--a1-fast) var(--a1-ease), box-shadow var(--a1-fast);
}
.a1-seg button:hover { color: var(--a1-ink); }
.a1-seg button[aria-selected="true"] { background: var(--a1-surface); color: var(--a1-ink); box-shadow: var(--a1-shadow-1), 0 0 0 1px var(--a1-line); }

/* ---------- Badges ---------- */
.a1-badge {
  --_bg: var(--a1-line-2); --_fg: var(--a1-ink-2); --_dot: var(--a1-ink-4);
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 9px 3px 8px; border-radius: var(--a1-r-pill);
  background: var(--_bg); color: var(--_fg);
  font: 600 12px/18px var(--a1-font); white-space: nowrap;
}
.a1-badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--_dot); }
.a1-badge--plain::before { display: none; }
.a1-badge--success  { --_bg: var(--a1-success-50); --_fg: var(--a1-success-700); --_dot: var(--a1-success-500); }
.a1-badge--pending  { --_bg: var(--a1-warning-50); --_fg: var(--a1-warning-700); --_dot: var(--a1-warning-500); }
.a1-badge--failed   { --_bg: var(--a1-danger-50);  --_fg: var(--a1-danger-700);  --_dot: var(--a1-danger-500); }
.a1-badge--refunded { --_bg: var(--a1-info-50);    --_fg: var(--a1-info-700);    --_dot: var(--a1-info-500); }
.a1-badge--brand    { --_bg: var(--a1-primary-soft); --_fg: var(--a1-primary-text); --_dot: var(--a1-primary); }

.a1-demo-pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: var(--a1-r-pill);
  background: var(--a1-primary-soft); color: var(--a1-primary-text);
  font: 600 12px/16px var(--a1-font); white-space: nowrap;
}
.a1-demo-pill .a1-ico { width: 14px; height: 14px; }

/* ---------- Cards ---------- */
.a1-card {
  background: var(--a1-surface); border: 1px solid var(--a1-line);
  border-radius: var(--a1-r-md); box-shadow: var(--a1-shadow-1);
}
.a1-card__head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 20px 0; }
.a1-card__title { font: 600 var(--a1-text-lg)/1.3 var(--a1-font-display); color: var(--a1-ink); }
.a1-card__body { padding: 18px 20px 20px; }

.a1-glass {
  background: var(--a1-glass-bg);
  border: 1px solid var(--a1-glass-border);
  border-radius: var(--a1-r-lg);
  box-shadow: var(--a1-shadow-3);
  -webkit-backdrop-filter: var(--a1-glass-blur);
  backdrop-filter: var(--a1-glass-blur);
}
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .a1-glass { background: var(--a1-surface); }
}

/* Stat card: icon, label, value, change vs previous period */
.a1-stat { padding: 18px 20px; display: grid; gap: 10px; }
.a1-stat__top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.a1-stat__label { font-size: var(--a1-text-sm); font-weight: 600; color: var(--a1-ink-3); }
.a1-stat__icon {
  width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center;
  background: var(--a1-primary-soft); color: var(--a1-primary);
}
.a1-stat__icon--blue  { background: var(--a1-blue-50);  color: var(--a1-blue-500); }
.a1-stat__icon--cyan  { background: var(--a1-cyan-50);  color: var(--a1-cyan-700); }
.a1-stat__icon--green { background: var(--a1-success-50); color: var(--a1-success-500); }
.a1-stat__icon--amber { background: var(--a1-warning-50); color: var(--a1-warning-700); }
.a1-stat__icon--red   { background: var(--a1-danger-50);  color: var(--a1-danger-500); }
.a1-stat__value { font: 650 26px/1.15 var(--a1-font-display); color: var(--a1-ink); letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.a1-stat__foot  { display: flex; align-items: center; gap: 8px; font-size: var(--a1-text-sm); color: var(--a1-ink-3); }
.a1-delta { display: inline-flex; align-items: center; gap: 2px; font-weight: 700; font-variant-numeric: tabular-nums; }
.a1-delta--up   { color: var(--a1-success-700); }
.a1-delta--down { color: var(--a1-danger-700); }
.a1-stat__spark { height: 32px; }

/* ---------- Alerts ---------- */
.a1-alert {
  --_bg: var(--a1-info-50); --_fg: var(--a1-info-700);
  display: flex; gap: 10px; align-items: flex-start;
  padding: 12px 14px; border-radius: var(--a1-r-sm);
  background: var(--_bg); color: var(--_fg); font-size: var(--a1-text-md);
}
.a1-alert .a1-ico { margin-top: 2px; }
.a1-alert--success { --_bg: var(--a1-success-50); --_fg: var(--a1-success-700); }
.a1-alert--error   { --_bg: var(--a1-danger-50);  --_fg: var(--a1-danger-700); }
.a1-alert--warning { --_bg: var(--a1-warning-50); --_fg: var(--a1-warning-700); }

/* ---------- Toasts ---------- */
.a1-toasts {
  position: fixed; z-index: 1100; right: 20px; bottom: 20px;
  display: grid; gap: 10px; width: min(380px, calc(100vw - 32px));
  pointer-events: none;
}
.a1-toast {
  pointer-events: auto;
  display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: start;
  padding: 14px 14px 14px 16px; border-radius: var(--a1-r-md);
  background: var(--a1-ink); color: #E8ECF4; box-shadow: var(--a1-shadow-3);
  font-size: var(--a1-text-md); line-height: 1.45;
  animation: a1-toast-in var(--a1-med) var(--a1-ease);
}
:root[data-theme="dark"] .a1-toast { background: #1E2A44; border: 1px solid var(--a1-line); }
.a1-toast__icon { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; color: #fff; background: var(--a1-blue-500); }
.a1-toast__icon .a1-ico { width: 14px; height: 14px; }
.a1-toast--success .a1-toast__icon { background: var(--a1-success-500); }
.a1-toast--warning .a1-toast__icon { background: var(--a1-warning-500); }
.a1-toast--error   .a1-toast__icon { background: var(--a1-danger-500); }
.a1-toast--demo    .a1-toast__icon { background: var(--a1-purple-500); }
.a1-toast__close { border: 0; background: transparent; color: #94A3B8; cursor: pointer; padding: 2px; border-radius: 6px; }
.a1-toast__close:hover { color: #fff; }
.a1-toast.is-leaving { animation: a1-toast-out 180ms var(--a1-ease) forwards; }
@keyframes a1-toast-in  { from { opacity: 0; transform: translateY(8px) scale(.98); } }
@keyframes a1-toast-out { to   { opacity: 0; transform: translateY(6px); } }
@media (max-width: 575px) {
  .a1-toasts { left: 16px; right: 16px; bottom: max(16px, env(safe-area-inset-bottom)); width: auto; }
}

/* ---------- Modal ---------- */
.a1-modal { position: fixed; inset: 0; z-index: 1050; display: none; }
.a1-modal.is-open { display: grid; place-items: center; padding: 16px; }
.a1-modal__scrim { position: absolute; inset: 0; background: rgba(15, 23, 42, .45); -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); animation: a1-fade var(--a1-med) var(--a1-ease); }
.a1-modal__dialog {
  position: relative; width: min(480px, 100%); max-height: calc(100vh - 32px); overflow: auto;
  background: var(--a1-surface); border: 1px solid var(--a1-line); border-radius: var(--a1-r-lg);
  box-shadow: var(--a1-shadow-3); animation: a1-pop var(--a1-med) var(--a1-ease);
}
.a1-modal__head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 22px 22px 0; }
.a1-modal__body { padding: 16px 22px; }
.a1-modal__foot { display: flex; justify-content: flex-end; gap: 10px; padding: 0 22px 22px; }
@keyframes a1-fade { from { opacity: 0; } }
@keyframes a1-pop  { from { opacity: 0; transform: translateY(10px) scale(.98); } }
@media (max-width: 575px) {
  .a1-modal.is-open { place-items: end center; padding: 0; }
  .a1-modal__dialog { width: 100%; border-radius: var(--a1-r-lg) var(--a1-r-lg) 0 0; padding-bottom: env(safe-area-inset-bottom); }
  .a1-modal__foot .a1-btn { flex: 1; }
}

/* Summary list (confirmation modal, receipts) */
.a1-summary { display: grid; gap: 0; margin: 0; }
.a1-summary > div { display: flex; justify-content: space-between; gap: 16px; padding: 10px 0; border-bottom: 1px dashed var(--a1-line); }
.a1-summary > div:last-child { border-bottom: 0; }
.a1-summary dt { color: var(--a1-ink-3); }
.a1-summary dd { margin: 0; color: var(--a1-ink); font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- Table ---------- */
.a1-table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.a1-table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: var(--a1-text-md); }
.a1-table th {
  position: sticky; top: 0; z-index: 1;
  padding: 11px 16px; text-align: left; white-space: nowrap;
  background: var(--a1-surface-2); color: var(--a1-ink-3);
  font-size: var(--a1-text-sm); font-weight: 600;
  border-bottom: 1px solid var(--a1-line);
}
.a1-table td { padding: 13px 16px; border-bottom: 1px solid var(--a1-line-2); color: var(--a1-ink-2); vertical-align: middle; }
.a1-table tbody tr { transition: background var(--a1-fast); }
.a1-table tbody tr:hover { background: var(--a1-surface-2); }
.a1-table tbody tr:last-child td { border-bottom: 0; }
.a1-table .is-num { text-align: right; font-variant-numeric: tabular-nums; }
.a1-table th[aria-sort] { cursor: pointer; user-select: none; }
.a1-table th[aria-sort]::after { content: " ↕"; color: var(--a1-ink-4); }
.a1-table th[aria-sort="ascending"]::after  { content: " ↑"; color: var(--a1-primary); }
.a1-table th[aria-sort="descending"]::after { content: " ↓"; color: var(--a1-primary); }
.a1-cell-main { color: var(--a1-ink); font-weight: 600; }
.a1-cell-sub  { display: block; font-size: var(--a1-text-sm); color: var(--a1-ink-3); }

/* Phones: rows become cards. Needs data-label on each td. */
@media (max-width: 640px) {
  .a1-table--stack thead { display: none; }
  .a1-table--stack, .a1-table--stack tbody, .a1-table--stack tr, .a1-table--stack td { display: block; width: 100%; }
  .a1-table--stack tr { padding: 12px 14px; border-bottom: 1px solid var(--a1-line); }
  .a1-table--stack td { display: flex; justify-content: space-between; gap: 16px; padding: 5px 0; border: 0; text-align: right; }
  .a1-table--stack td::before { content: attr(data-label); color: var(--a1-ink-3); font-size: var(--a1-text-sm); text-align: left; }
  .a1-table--stack td[data-label=""]::before { display: none; }
}

/* Toolbar above tables */
.a1-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--a1-line); }
.a1-toolbar .a1-search { flex: 1 1 240px; }
.a1-pager { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; border-top: 1px solid var(--a1-line); font-size: var(--a1-text-sm); color: var(--a1-ink-3); }

/* ---------- Empty, loading ---------- */
.a1-empty { display: grid; justify-items: center; gap: 10px; padding: 48px 24px; text-align: center; }
.a1-empty__icon { width: 56px; height: 56px; border-radius: 16px; display: grid; place-items: center; background: var(--a1-primary-soft); color: var(--a1-primary); margin-bottom: 6px; }
.a1-empty__icon .a1-ico { width: 26px; height: 26px; }
.a1-empty h3 { font-size: var(--a1-text-lg); }
.a1-empty p { max-width: 42ch; color: var(--a1-ink-3); }
.a1-empty .a1-btn { margin-top: 8px; }

.a1-skel {
  display: block; height: 14px; border-radius: 6px;
  background: linear-gradient(90deg, var(--a1-line-2) 0%, var(--a1-line) 50%, var(--a1-line-2) 100%);
  background-size: 200% 100%; animation: a1-shimmer 1.3s ease-in-out infinite;
}
@keyframes a1-shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }

/* ---------- Code block (API docs) ---------- */
.a1-code { position: relative; border-radius: var(--a1-r-md); background: #0F172A; color: #E2E8F0; overflow: hidden; }
.a1-code__bar { display: flex; align-items: center; justify-content: space-between; padding: 8px 8px 8px 14px; background: #131C31; font-size: var(--a1-text-sm); color: #94A3B8; }
.a1-code pre { margin: 0; padding: 16px; overflow-x: auto; font: 13.5px/1.6 var(--a1-font-mono); }
.a1-code .a1-btn { --_bg: transparent; --_fg: #CBD5E1; --_bd: #2A3653; }

/* ---------- Avatar, misc ---------- */
.a1-avatar {
  width: 36px; height: 36px; border-radius: 50%; display: inline-grid; place-items: center; flex: none;
  background: var(--a1-primary-soft); color: var(--a1-primary-text); font: 700 13px/1 var(--a1-font);
}
.a1-avatar--lg { width: 64px; height: 64px; font-size: 22px; }
.a1-divider { height: 1px; background: var(--a1-line); border: 0; margin: var(--a1-s5) 0; }
.a1-kbd { font: 600 12px/1 var(--a1-font-mono); padding: 3px 6px; border: 1px solid var(--a1-line); border-bottom-width: 2px; border-radius: 6px; color: var(--a1-ink-2); background: var(--a1-surface); }
