/* Base + shared components (v2 copy of app/design/assets/base.css).
   Generic rules are guarded with :where(:not(.tpl *)) so they never reach inside the
   presentation engine (tpl.js / tpl.css), which uses some of the same class names. */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: var(--text-md);
  line-height: var(--leading-body);
  font-feature-settings: "cv11", "ss01";
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
img:where(:not(.tpl *)), svg:where(:not(.tpl *)) { display: block; max-width: 100%; }
.ico:where(:not(.tpl *)) { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
.logo-mark { color: var(--accent); --logo-ink: var(--accent-ink); }
:is(button, input, select, textarea):where(:not(.tpl *)) { font: inherit; color: inherit; }
h1:where(:not(.tpl *)), h2:where(:not(.tpl *)), h3:where(:not(.tpl *)), h4:where(:not(.tpl *)) { font-family: var(--font-display); letter-spacing: var(--tracking-display); line-height: var(--leading-tight); margin: 0; font-weight: var(--weight-semibold); }
p { margin: 0; }
a:where(:not(.tpl *)) { color: var(--accent); text-underline-offset: 3px; }
.num, .tabular { font-variant-numeric: tabular-nums; }

:focus { outline: none; }
*:where(:not(.tpl *)):focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: var(--radius-sm); }

[hidden] { display: none !important; }
.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip-link { position: absolute; left: var(--space-4); top: -60px; z-index: 100; background: var(--surface); color: var(--text); padding: var(--space-2) var(--space-4); border-radius: var(--radius-sm); box-shadow: var(--shadow-2); }
.skip-link:focus { top: var(--space-3); }

/* ---- Buttons ---- */
.btn:where(:not(.tpl *)) {
  --btn-bg: var(--surface); --btn-fg: var(--text); --btn-bd: var(--border);
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  min-height: var(--control-h); padding: 0 var(--space-4);
  border: 1px solid var(--btn-bd); border-radius: var(--radius-md);
  background: var(--btn-bg); color: var(--btn-fg);
  font-size: var(--text-md); font-weight: var(--weight-medium); line-height: 1;
  text-decoration: none; cursor: pointer; white-space: nowrap;
  transition: background var(--dur-fast) var(--ease-standard), border-color var(--dur-fast) var(--ease-standard), transform var(--dur-instant) var(--ease-standard), box-shadow var(--dur-fast);
}
.btn:hover { --btn-bg: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn-primary { --btn-bg: var(--accent); --btn-fg: var(--accent-ink); --btn-bd: transparent; }
.btn-primary:hover { --btn-bg: var(--accent-hover); }
.btn-ghost { --btn-bg: transparent; --btn-bd: transparent; }
.btn-ghost:hover { --btn-bg: var(--surface-2); }
.btn-danger { --btn-fg: var(--danger); }
.btn-lg { min-height: 48px; padding: 0 var(--space-6); font-size: var(--text-lg); border-radius: var(--radius-lg); }
.btn-sm { min-height: var(--control-h-sm); padding: 0 var(--space-3); font-size: var(--text-sm); }
.btn-icon { width: var(--control-h); padding: 0; }
.btn-icon.btn-sm { width: var(--control-h-sm); }
.btn[disabled], .btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn svg { width: 18px; height: 18px; flex: none; }
.btn-sm svg { width: 16px; height: 16px; }

/* ---- Form controls ---- */
.field { display: grid; gap: var(--space-2); }
.label { font-size: var(--text-sm); font-weight: var(--weight-medium); color: var(--text-2); }
.hint { font-size: var(--text-xs); color: var(--text-3); }
.input, .select, .textarea {
  width: 100%; min-height: var(--control-h); padding: var(--space-2) var(--space-3);
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-md);
  transition: border-color var(--dur-fast), box-shadow var(--dur-fast);
}
.textarea { min-height: 120px; resize: vertical; line-height: var(--leading-body); }
.input:focus-visible, .select:focus-visible, .textarea*:where(:not(.tpl *)):focus-visible { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 25%, transparent); }
.input[aria-invalid="true"], .textarea[aria-invalid="true"] { border-color: var(--danger); }

/* Segmented control */
.seg { display: inline-flex; padding: 3px; gap: 2px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-md); }
.seg button { min-height: 34px; padding: 0 var(--space-3); border: 0; background: transparent; border-radius: 7px; cursor: pointer; font-size: var(--text-sm); font-weight: var(--weight-medium); color: var(--text-2); }
.seg button[aria-selected="true"], .seg button[aria-pressed="true"], .seg button[aria-checked="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow-1); }

/* Tabs */
.tabs:where(:not(.tpl *)) { display: flex; gap: var(--space-1); border-bottom: 1px solid var(--border); }
.tab:where(:not(.tpl *)) { position: relative; min-height: 44px; padding: 0 var(--space-3); border: 0; background: none; cursor: pointer; color: var(--text-2); font-weight: var(--weight-medium); font-size: var(--text-sm); }
.tab[aria-selected="true"] { color: var(--text); }
.tab[aria-selected="true"]::after { content: ""; position: absolute; left: var(--space-2); right: var(--space-2); bottom: -1px; height: 2px; background: var(--accent); border-radius: 2px; }

/* Badges */
.badge { display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 var(--space-2); border-radius: var(--radius-full); font-size: var(--text-xs); font-weight: var(--weight-medium); background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); white-space: nowrap; }
.badge-accent { background: var(--accent-soft); color: var(--accent-soft-ink); border-color: transparent; }
.badge-success { background: var(--success-soft); color: var(--success); border-color: transparent; }
.badge-warning { background: var(--warning-soft); color: var(--warning); border-color: transparent; }
.badge-sample { background: var(--warning-soft); color: var(--warning); border-color: transparent; text-transform: uppercase; letter-spacing: var(--tracking-caps); font-size: 11px; height: 22px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); }

/* Alerts / inline status */
.alert { display: flex; gap: var(--space-3); align-items: flex-start; padding: var(--space-3) var(--space-4); border-radius: var(--radius-md); font-size: var(--text-sm); border: 1px solid transparent; }
.alert svg { width: 18px; height: 18px; flex: none; margin-top: 2px; }
.alert-error { background: var(--danger-soft); color: var(--danger); }
.alert-success { background: var(--success-soft); color: var(--success); }
.alert-info { background: var(--accent-soft); color: var(--accent-soft-ink); }
.alert-warning { background: var(--warning-soft); color: var(--warning); }

/* Spinner / progress */
.spinner { width: 18px; height: 18px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: ds-spin 700ms linear infinite; flex: none; }
@keyframes ds-spin { to { transform: rotate(360deg); } }
.progress { height: 6px; background: var(--surface-3); border-radius: var(--radius-full); overflow: hidden; }
.progress > span { display: block; height: 100%; width: 0; background: var(--accent); border-radius: inherit; transition: width var(--dur-base) var(--ease-standard); }

/* Toast */
.toast-region { position: fixed; left: 50%; bottom: var(--space-6); transform: translateX(-50%); z-index: 80; display: grid; gap: var(--space-2); pointer-events: none; width: min(92vw, 420px); }
.toast { pointer-events: auto; display: flex; align-items: center; gap: var(--space-3); padding: var(--space-3) var(--space-4); background: var(--text); color: var(--bg); border-radius: var(--radius-md); box-shadow: var(--shadow-3); font-size: var(--text-sm); animation: ds-toast var(--dur-base) var(--ease-enter); }
.toast .btn { --btn-bg: transparent; --btn-fg: var(--bg); --btn-bd: color-mix(in srgb, var(--bg) 30%, transparent); margin-left: auto; }
@keyframes ds-toast { from { opacity: 0; transform: translateY(8px); } }

/* Dialog */
dialog.dialog { padding: 0; border: 1px solid var(--border); border-radius: var(--radius-xl); background: var(--surface); color: var(--text); box-shadow: var(--shadow-3); width: min(720px, calc(100vw - 32px)); max-height: calc(100vh - 32px); }
dialog.dialog::backdrop { background: var(--overlay); }
dialog.dialog[open] { animation: ds-dialog var(--dur-slow) var(--ease-enter); }
@keyframes ds-dialog { from { opacity: 0; transform: translateY(12px) scale(0.98); } }

/* Logo */
.logo { display: inline-flex; align-items: center; gap: 10px; font-family: var(--font-display); font-weight: var(--weight-bold); font-size: 18px; letter-spacing: -0.02em; color: var(--text); text-decoration: none; }
.logo-mark { width: 26px; height: 26px; flex: none; }

/* Theme toggle icon swap */
[data-theme-toggle] .i-sun { display: none; }
:root[data-theme="dark"] [data-theme-toggle] .i-sun { display: block; }
:root[data-theme="dark"] [data-theme-toggle] .i-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) [data-theme-toggle] .i-sun { display: block; }
  :root:not([data-theme="light"]) [data-theme-toggle] .i-moon { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-iteration-count: 1 !important; transition-duration: 1ms !important; scroll-behavior: auto !important; }
  .spinner { animation: ds-spin 1.6s linear infinite !important; }
}
