/* SmartTag design system — tokens, reset, base, components.
   Modern CSS only: @layer, light-dark(), color-mix(), :has(), container queries, logical properties.
   No build step, no external requests (fonts are the system stack). */

@layer reset, tokens, base, components, pages, utilities;

/* ------------------------------------------------------------------ reset */
@layer reset {
  *, *::before, *::after { box-sizing: border-box; }
  * { margin: 0; }
  html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
  body { min-block-size: 100dvh; line-height: 1.5; -webkit-font-smoothing: antialiased; }
  img, picture, video, canvas, svg { display: block; max-inline-size: 100%; }
  input, button, textarea, select { font: inherit; color: inherit; }
  button { cursor: pointer; }
  p, h1, h2, h3, h4 { overflow-wrap: break-word; }
  a { color: inherit; }
  table { border-collapse: collapse; }
  [hidden] { display: none !important; }
  @media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; scroll-behavior: auto !important; }
  }
}

/* ----------------------------------------------------------------- tokens */
@layer tokens {
  :root {
    color-scheme: light dark;

    --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
    --font-display: ui-rounded, "SF Pro Rounded", "Segoe UI Variable Display", var(--font);
    --mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, Menlo, monospace;

    /* fluid type scale */
    --fs-xs: clamp(.72rem, .70rem + .1vw, .78rem);
    --fs-s: clamp(.82rem, .80rem + .1vw, .88rem);
    --fs-m: clamp(.94rem, .92rem + .12vw, 1rem);
    --fs-l: clamp(1.1rem, 1.04rem + .3vw, 1.25rem);
    --fs-xl: clamp(1.35rem, 1.2rem + .7vw, 1.75rem);
    --fs-2xl: clamp(1.7rem, 1.4rem + 1.5vw, 2.5rem);
    --fs-3xl: clamp(2.1rem, 1.6rem + 2.6vw, 3.6rem);

    /* brand — venues override these through an inline style on <html> or a wrapper */
    --brand: #0f766e;
    --brand-ink: #ffffff;
    --accent: #f59e0b;

    --bg: light-dark(#f5f6f8, #0d1117);
    --surface: light-dark(#ffffff, #151b23);
    --surface-2: light-dark(#f0f2f5, #1c242e);
    --surface-3: light-dark(#e4e8ee, #26303c);
    --text: light-dark(#10151c, #e8edf3);
    --muted: light-dark(#566170, #98a3b3);
    --faint: light-dark(#8591a1, #6b7686);
    --border: light-dark(#e0e4ea, #2a3441);
    --border-strong: light-dark(#c8cfd9, #3a4656);
    --overlay: rgb(8 12 18 / .55);

    --ok: light-dark(#15803d, #4ade80);
    --ok-bg: light-dark(#e6f6ec, #10281a);
    --warn: light-dark(#b45309, #fbbf24);
    --warn-bg: light-dark(#fff3dc, #2d2410);
    --danger: light-dark(#c81e1e, #f87171);
    --danger-bg: light-dark(#fdeaea, #331616);
    --info: light-dark(#1d4ed8, #7aa7ff);
    --info-bg: light-dark(#e8effe, #15213b);

    --brand-soft: color-mix(in oklab, var(--brand) 12%, var(--surface));
    --brand-softer: color-mix(in oklab, var(--brand) 6%, var(--surface));
    --brand-strong: color-mix(in oklab, var(--brand) 82%, black);

    --r-s: 8px; --r-m: 12px; --r-l: 18px; --r-xl: 28px; --r-pill: 999px;
    --shadow-1: 0 1px 2px rgb(16 24 40 / .06), 0 1px 3px rgb(16 24 40 / .08);
    --shadow-2: 0 4px 12px rgb(16 24 40 / .08), 0 12px 32px rgb(16 24 40 / .10);
    --shadow-3: 0 12px 40px rgb(16 24 40 / .22);
    --ring: 0 0 0 3px color-mix(in oklab, var(--brand) 38%, transparent);

    --s-1: .25rem; --s-2: .5rem; --s-3: .75rem; --s-4: 1rem; --s-5: 1.5rem; --s-6: 2rem; --s-7: 3rem; --s-8: 4.5rem;
    --ease: cubic-bezier(.2, .7, .2, 1);
    --gutter: clamp(1rem, 4vw, 2rem);
  }
  :root[data-theme="light"] { color-scheme: light; }
  :root[data-theme="dark"] { color-scheme: dark; }
}

/* ------------------------------------------------------------------- base */
@layer base {
  body { font-family: var(--font); font-size: var(--fs-m); background: var(--bg); color: var(--text); }
  h1, h2, h3, h4 { line-height: 1.2; font-weight: 700; letter-spacing: -.01em; text-wrap: balance; }
  h1 { font-size: var(--fs-2xl); } h2 { font-size: var(--fs-xl); } h3 { font-size: var(--fs-l); } h4 { font-size: var(--fs-m); }
  p { text-wrap: pretty; }
  a { text-decoration-thickness: .08em; text-underline-offset: .18em; }
  :focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: 4px; }
  ::selection { background: color-mix(in oklab, var(--brand) 30%, transparent); }
  hr { border: 0; border-block-start: 1px solid var(--border); }
  small { font-size: var(--fs-s); }
  code, kbd, pre { font-family: var(--mono); font-size: .92em; }
  kbd { padding: .1em .45em; border: 1px solid var(--border-strong); border-bottom-width: 2px; border-radius: 6px; background: var(--surface-2); }
  .i { display: inline-block; vertical-align: -.22em; inline-size: 1.25em; block-size: 1.25em; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
  .sr-only { position: absolute; inline-size: 1px; block-size: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .skip-link { position: absolute; inset-inline-start: var(--s-3); inset-block-start: -4rem; z-index: 1000; padding: var(--s-2) var(--s-4); background: var(--brand); color: var(--brand-ink); border-radius: var(--r-s); }
  .skip-link:focus { inset-block-start: var(--s-3); }
}

/* ------------------------------------------------------------- components */
@layer components {
  /* buttons */
  .btn { --_bg: var(--surface); --_fg: var(--text); --_bd: var(--border-strong);
    display: inline-flex; align-items: center; justify-content: center; gap: .5em; min-block-size: 2.5rem; padding: .5rem 1rem;
    border: 1px solid var(--_bd); border-radius: var(--r-m); background: var(--_bg); color: var(--_fg); font-weight: 600; font-size: var(--fs-s);
    text-decoration: none; line-height: 1.2; white-space: nowrap; user-select: none; transition: background .15s var(--ease), border-color .15s, transform .08s, box-shadow .15s; }
  .btn:hover { --_bg: var(--surface-2); }
  .btn:active { transform: translateY(1px) scale(.99); }
  .btn:disabled, .btn[aria-disabled="true"] { opacity: .5; pointer-events: none; }
  .btn-primary { --_bg: var(--brand); --_fg: var(--brand-ink); --_bd: var(--brand); box-shadow: 0 1px 0 rgb(255 255 255 / .18) inset, var(--shadow-1); }
  .btn-primary:hover { --_bg: var(--brand-strong); --_bd: var(--brand-strong); }
  .btn-soft { --_bg: var(--brand-soft); --_fg: var(--brand-strong); --_bd: transparent; }
  .btn-soft:hover { --_bg: color-mix(in oklab, var(--brand) 20%, var(--surface)); }
  .btn-ghost { --_bg: transparent; --_bd: transparent; }
  .btn-ghost:hover { --_bg: var(--surface-2); }
  .btn-danger { --_bg: var(--danger-bg); --_fg: var(--danger); --_bd: transparent; }
  .btn-danger:hover { --_bg: color-mix(in oklab, var(--danger) 18%, var(--surface)); }
  .btn-danger-solid { --_bg: var(--danger); --_fg: #fff; --_bd: var(--danger); }
  .btn-sm { min-block-size: 2rem; padding: .25rem .7rem; font-size: var(--fs-xs); border-radius: var(--r-s); }
  .btn-lg { min-block-size: 3.1rem; padding: .75rem 1.5rem; font-size: var(--fs-m); border-radius: var(--r-l); }
  .btn-icon { inline-size: 2.5rem; padding: 0; }
  .btn-icon.btn-sm { inline-size: 2rem; }
  .btn-block { inline-size: 100%; }

  /* forms */
  .field { display: grid; gap: .35rem; align-content: start; }
  .field > label, .label { font-size: var(--fs-s); font-weight: 600; }
  .hint { font-size: var(--fs-xs); color: var(--muted); }
  .error-text { font-size: var(--fs-xs); color: var(--danger); font-weight: 600; }
  .input, .select, .textarea { inline-size: 100%; min-block-size: 2.6rem; padding: .55rem .8rem; border: 1px solid var(--border-strong);
    border-radius: var(--r-m); background: var(--surface); color: var(--text); transition: border-color .15s, box-shadow .15s; }
  .textarea { min-block-size: 5.5rem; resize: vertical; line-height: 1.45; }
  .input::placeholder, .textarea::placeholder { color: var(--faint); }
  .input:hover, .select:hover, .textarea:hover { border-color: var(--faint); }
  .input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--brand); box-shadow: var(--ring); }
  .field:has([aria-invalid="true"]) .input, .input[aria-invalid="true"] { border-color: var(--danger); }
  .input-group { display: flex; } .input-group > .input { border-start-end-radius: 0; border-end-end-radius: 0; }
  .input-group > .select { inline-size: auto; min-inline-size: 5rem; border-start-start-radius: 0; border-end-start-radius: 0; border-inline-start: 0; background-color: var(--surface-2); }
  .select { appearance: none; padding-inline-end: 2.2rem; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238591a1' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right .7rem center; background-size: 1.1rem; }
  .check { display: inline-flex; align-items: center; gap: .6rem; cursor: pointer; font-size: var(--fs-s); }
  .check input { inline-size: 1.15rem; block-size: 1.15rem; accent-color: var(--brand); }
  .switch { position: relative; display: inline-flex; align-items: center; gap: .65rem; cursor: pointer; font-size: var(--fs-s); white-space: nowrap; }
  .switch input { appearance: none; inline-size: 2.6rem; block-size: 1.5rem; border-radius: var(--r-pill); background: var(--surface-3); border: 1px solid var(--border-strong);
    position: relative; transition: background .2s var(--ease); flex: none; cursor: pointer; }
  .switch input::after { content: ""; position: absolute; inset-block-start: 2px; inset-inline-start: 2px; inline-size: 1.1rem; block-size: 1.1rem; border-radius: 50%;
    background: #fff; box-shadow: var(--shadow-1); transition: transform .2s var(--ease); }
  .switch input:checked { background: var(--brand); border-color: var(--brand); }
  .switch input:checked::after { transform: translateX(1.1rem); }
  [dir="rtl"] .switch input:checked::after { transform: translateX(-1.1rem); }
  .form-grid { display: grid; gap: var(--s-4); grid-template-columns: repeat(auto-fit, minmax(min(100%, 14rem), 1fr)); }
  .form-grid .span-2 { grid-column: 1 / -1; }
  .stepper { display: inline-flex; align-items: center; border: 1px solid var(--border-strong); border-radius: var(--r-pill); background: var(--surface); overflow: hidden; }
  .stepper button { inline-size: 2.4rem; block-size: 2.4rem; border: 0; background: transparent; display: grid; place-items: center; }
  .stepper button:hover { background: var(--surface-2); }
  .stepper output { min-inline-size: 2rem; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; }

  /* surfaces */
  .card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-l); box-shadow: var(--shadow-1); }
  .card-pad { padding: var(--s-5); }
  .card-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); padding: var(--s-4) var(--s-5); border-block-end: 1px solid var(--border); }
  .card-head h2, .card-head h3 { font-size: var(--fs-l); }
  .card-body { padding: var(--s-5); }
  .card-foot { padding: var(--s-3) var(--s-5); border-block-start: 1px solid var(--border); background: var(--surface-2); border-end-start-radius: inherit; border-end-end-radius: inherit; }
  .callout { display: flex; gap: var(--s-3); padding: var(--s-4); border-radius: var(--r-m); background: var(--info-bg); color: var(--text); border: 1px solid color-mix(in oklab, var(--info) 30%, transparent); }
  .callout > .i { color: var(--info); margin-block-start: .15rem; }
  .callout.warn { background: var(--warn-bg); border-color: color-mix(in oklab, var(--warn) 35%, transparent); } .callout.warn > .i { color: var(--warn); }
  .callout.danger { background: var(--danger-bg); border-color: color-mix(in oklab, var(--danger) 35%, transparent); } .callout.danger > .i { color: var(--danger); }
  .callout.ok { background: var(--ok-bg); border-color: color-mix(in oklab, var(--ok) 35%, transparent); } .callout.ok > .i { color: var(--ok); }

  /* badges and chips */
  .badge { display: inline-flex; align-items: center; gap: .35em; padding: .12rem .6rem; border-radius: var(--r-pill); font-size: var(--fs-xs); font-weight: 700;
    background: var(--surface-3); color: var(--text); white-space: nowrap; line-height: 1.5; }
  .badge.ok { background: var(--ok-bg); color: var(--ok); } .badge.warn { background: var(--warn-bg); color: var(--warn); }
  .badge.danger { background: var(--danger-bg); color: var(--danger); } .badge.info { background: var(--info-bg); color: var(--info); }
  .badge.brand { background: var(--brand-soft); color: var(--brand-strong); }
  .badge .dot { inline-size: .5em; block-size: .5em; border-radius: 50%; background: currentColor; }
  .chip { display: inline-flex; align-items: center; gap: .4rem; padding: .35rem .85rem; border: 1px solid var(--border-strong); border-radius: var(--r-pill);
    background: var(--surface); font-size: var(--fs-s); font-weight: 600; text-decoration: none; white-space: nowrap; transition: all .15s var(--ease); }
  .chip:hover { background: var(--surface-2); }
  .chip[aria-pressed="true"], .chip[aria-current="true"], .chip.active { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }

  /* dialogs, sheets, toasts */
  dialog { margin: auto; border: 0; padding: 0; background: var(--surface); color: var(--text); border-radius: var(--r-l); box-shadow: var(--shadow-3);
    inline-size: min(36rem, calc(100vw - 2rem)); max-block-size: calc(100dvh - 2rem); overflow: auto; }
  dialog::backdrop { background: var(--overlay); backdrop-filter: blur(3px); animation: fade .2s var(--ease); }
  dialog[open] { animation: pop .22s var(--ease); }
  dialog.sheet { margin: auto auto 0; border-end-start-radius: 0; border-end-end-radius: 0; inline-size: min(40rem, 100vw); max-block-size: 92dvh; }
  dialog.sheet[open] { animation: slide-up .28s var(--ease); }
  dialog.wide { inline-size: min(56rem, calc(100vw - 2rem)); }
  .dialog-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); padding: var(--s-4) var(--s-5); border-block-end: 1px solid var(--border); position: sticky; inset-block-start: 0; background: var(--surface); z-index: 1; }
  .dialog-body { padding: var(--s-5); display: grid; gap: var(--s-4); }
  .dialog-foot { display: flex; gap: var(--s-3); justify-content: flex-end; padding: var(--s-4) var(--s-5); border-block-start: 1px solid var(--border); position: sticky; inset-block-end: 0; background: var(--surface); }
  .toasts { position: fixed; inset-block-end: max(var(--s-4), env(safe-area-inset-bottom)); inset-inline: var(--s-4); display: grid; gap: var(--s-2); justify-items: center; z-index: 2000; pointer-events: none; }
  .toast { pointer-events: auto; display: flex; align-items: center; gap: var(--s-3); max-inline-size: min(30rem, 100%); padding: .7rem 1rem; border-radius: var(--r-m);
    background: var(--text); color: var(--bg); box-shadow: var(--shadow-2); font-size: var(--fs-s); font-weight: 600; animation: slide-up .25s var(--ease); }
  .toast.ok > .i { color: var(--ok); } .toast.err > .i { color: var(--danger); }
  .toast button { background: none; border: 0; color: inherit; text-decoration: underline; font-weight: 700; }
  @keyframes fade { from { opacity: 0; } }
  @keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } }
  @keyframes slide-up { from { opacity: 0; transform: translateY(24px); } }
  @keyframes pulse { 50% { opacity: .45; } }
  @keyframes ring { 0%, 100% { transform: rotate(0); } 15% { transform: rotate(14deg); } 30% { transform: rotate(-12deg); } 45% { transform: rotate(8deg); } 60% { transform: rotate(-5deg); } }

  /* tables (turn into stacked cards on narrow screens) */
  .table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--r-l); background: var(--surface); }
  .table { inline-size: 100%; font-size: var(--fs-s); }
  .table th { text-align: start; font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; padding: .7rem 1rem; background: var(--surface-2); white-space: nowrap; }
  .table td { padding: .75rem 1rem; border-block-start: 1px solid var(--border); vertical-align: middle; }
  .table tbody tr:hover { background: var(--surface-2); }
  .table .num { text-align: end; font-variant-numeric: tabular-nums; white-space: nowrap; }
  @media (max-width: 40rem) {
    .table.cards thead { display: none; }
    .table.cards, .table.cards tbody, .table.cards tr, .table.cards td { display: block; inline-size: 100%; }
    .table.cards tr { padding: .75rem 1rem; border-block-start: 1px solid var(--border); }
    .table.cards tr:first-child { border-block-start: 0; }
    .table.cards td { border: 0; padding: .15rem 0; display: flex; justify-content: space-between; gap: 1rem; text-align: end; }
    .table.cards td::before { content: attr(data-label); color: var(--muted); font-weight: 600; text-align: start; }
    .table.cards td:first-child { font-weight: 700; justify-content: flex-start; text-align: start; }
    .table.cards td:first-child::before { content: none; }
  }

  /* tabs */
  .tabs { display: flex; gap: var(--s-1); border-block-end: 1px solid var(--border); overflow-x: auto; scrollbar-width: none; }
  .tabs::-webkit-scrollbar { display: none; }
  .tab { padding: .7rem 1rem; text-decoration: none; font-weight: 600; font-size: var(--fs-s); color: var(--muted); border-block-end: 2px solid transparent; margin-block-end: -1px; white-space: nowrap; }
  .tab:hover { color: var(--text); }
  .tab[aria-current="page"], .tab.active { color: var(--brand-strong); border-color: var(--brand); }
  .segmented { display: inline-flex; padding: 3px; border-radius: var(--r-m); background: var(--surface-3); gap: 2px; }
  .segmented > * { padding: .35rem .85rem; border-radius: calc(var(--r-m) - 3px); border: 0; background: transparent; font-size: var(--fs-s); font-weight: 600; color: var(--muted); text-decoration: none; }
  .segmented > [aria-pressed="true"], .segmented > [aria-current="true"], .segmented > .active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-1); }

  .segmented > label { display: inline-flex; align-items: center; gap: .4rem; padding: .35rem .85rem; border-radius: calc(var(--r-m) - 3px); font-size: var(--fs-s); font-weight: 600; color: var(--muted); cursor: pointer; }
  .segmented > label:has(input:checked) { background: var(--surface); color: var(--text); box-shadow: var(--shadow-1); }
  .segmented > label:has(input:focus-visible) { outline: 2px solid var(--brand); outline-offset: 2px; }

  /* meters and skeletons */
  .meter { block-size: .5rem; border-radius: var(--r-pill); background: var(--surface-3); overflow: hidden; }
  .meter > span { display: block; block-size: 100%; border-radius: inherit; background: var(--ok); transition: inline-size .4s var(--ease); }
  .meter.low > span { background: var(--warn); } .meter.out > span { background: var(--danger); }
  .skeleton { background: linear-gradient(90deg, var(--surface-2), var(--surface-3), var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.4s infinite linear; border-radius: var(--r-s); }
  @keyframes shimmer { to { background-position: -200% 0; } }
  .empty { display: grid; justify-items: center; gap: var(--s-3); padding: var(--s-7) var(--s-5); text-align: center; color: var(--muted); }
  .empty .i { inline-size: 2.5rem; block-size: 2.5rem; color: var(--faint); }
  .empty h3 { color: var(--text); }
  .avatar { inline-size: 2.25rem; block-size: 2.25rem; border-radius: 50%; display: grid; place-items: center; background: var(--brand-soft); color: var(--brand-strong); font-weight: 800; font-size: var(--fs-s); flex: none; }
  .divider { block-size: 1px; background: var(--border); margin-block: var(--s-4); }
  .spinner { inline-size: 1.1em; block-size: 1.1em; border-radius: 50%; border: 2px solid currentColor; border-inline-end-color: transparent; animation: spin .7s linear infinite; }
  @keyframes spin { to { transform: rotate(360deg); } }
  details.disclosure > summary { cursor: pointer; font-weight: 600; list-style: none; display: flex; align-items: center; gap: .5rem; }
  details.disclosure > summary::before { content: ""; inline-size: .55rem; block-size: .55rem; border-inline-end: 2px solid currentColor; border-block-end: 2px solid currentColor; transform: rotate(-45deg); transition: transform .2s; }
  details.disclosure[open] > summary::before { transform: rotate(45deg); }
}

/* -------------------------------------------------------------- utilities */
@layer utilities {
  .stack { display: grid; gap: var(--gap, var(--s-4)); align-content: start; }
  .stack-s { --gap: var(--s-2); } .stack-l { --gap: var(--s-6); }
  .row { display: flex; align-items: center; gap: var(--gap, var(--s-3)); flex-wrap: wrap; }
  .row.nowrap { flex-wrap: nowrap; }
  .between { justify-content: space-between; } .end { justify-content: flex-end; } .center { justify-content: center; }
  .grow { flex: 1 1 0; min-inline-size: 0; }
  .grid-auto { display: grid; gap: var(--gap, var(--s-4)); grid-template-columns: repeat(auto-fill, minmax(min(100%, var(--min, 16rem)), 1fr)); }
  .muted { color: var(--muted); } .faint { color: var(--faint); } .strong { font-weight: 700; }
  .ok-text { color: var(--ok); } .warn-text { color: var(--warn); } .danger-text { color: var(--danger); }
  .small { font-size: var(--fs-s); } .xs { font-size: var(--fs-xs); }
  .num { font-variant-numeric: tabular-nums; }
  .center-text { text-align: center; } .end-text { text-align: end; }
  .truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .container { inline-size: min(100% - 2 * var(--gutter), 72rem); margin-inline: auto; }
  .container-s { inline-size: min(100% - 2 * var(--gutter), 42rem); margin-inline: auto; }
  .no-print { }
  .mt-0 { margin-block-start: 0 !important; } .mt-4 { margin-block-start: var(--s-4); } .mt-5 { margin-block-start: var(--s-5); }
  @media print { .no-print { display: none !important; } }
}
