/*
 * UI components shared by every page (public site and the agent). Uses tokens.css only.
 *
 *   .ic              icon from the sprite (macro icon() / UI.icon())
 *   .ui-btn          buttons: --primary --secondary --quiet --dark --light --outline-light, --sm --lg, --block, --arrow
 *   .ui-iconbtn      square icon buttons: --sm --bare
 *   .ui-field        label + control + hint/error;  .ui-input  the control;  .ui-check;  .ui-meter
 *   .ui-card         bordered surface (--raised)
 *   .ui-chip         pill (filter/choice);  .ui-badge  count or tag;  .ui-kbd
 *   .ui-alert        inline message: --success --warning --danger
 *   .ui-toasts       toast stack; .ui-toast: --success --error
 *   .ui-dialog       modal backdrop (.is-open); the panel inside is the caller's
 *   .ui-table        data table (+ .ui-table-wrap for scrolling)
 *   .ui-tab          tab button
 *   .ui-scroll       thin scrollbars;  .ui-brand  logo + wordmark;  .ui-container  page width
 *
 * Page and app styles (site.css, home.css, agent.css) compose these; they do not
 * restyle them. Add a part here only when a page needs it.
 */
/* Base: a small reset (same rules as the Tailwind preflight every page was built on),
   then the document defaults. Components style themselves; elements stay unopinionated. */
*, *::before, *::after { box-sizing: border-box; border: 0 solid var(--border); }
html { line-height: 1.5; -webkit-text-size-adjust: 100%; tab-size: 4; }
body {
    margin: 0;
    font-family: var(--font-sans);
    line-height: inherit;
    color: var(--text);
    background: var(--bg);
    overflow-x: hidden;
}
h1, h2, h3, h4, h5, h6 { margin: 0; font-size: inherit; font-weight: inherit; font-family: var(--font-display); line-height: 1.2; }
p, blockquote, figure, pre, dl, dd { margin: 0; }
hr { height: 0; margin: 0; color: inherit; border-top-width: 1px; }
ol, ul, menu { list-style: none; margin: 0; padding: 0; }
a { color: inherit; text-decoration: inherit; }
b, strong { font-weight: bolder; }
code, kbd, samp, pre { font-family: var(--font-mono); font-size: 1em; }
small { font-size: 80%; }
table { text-indent: 0; border-color: inherit; border-collapse: collapse; }
button, input, optgroup, select, textarea { font: inherit; color: inherit; margin: 0; padding: 0; }
button, select { text-transform: none; }
button, [type='button'], [type='reset'], [type='submit'] { -webkit-appearance: button; background-color: transparent; background-image: none; }
button, [role='button'] { cursor: pointer; }
:disabled { cursor: default; }
textarea { resize: vertical; }
input::placeholder, textarea::placeholder { opacity: 1; color: var(--faint); }
img, svg, video, canvas, iframe { display: block; vertical-align: middle; }
img, video { max-width: 100%; height: auto; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid rgba(82, 98, 232, .55); outline-offset: 2px; }
:focus:not(:focus-visible) { outline: none; }
::selection { background: var(--primary-line); }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Icon ------------------------------------------------------------------ */
.ic {
    width: 1.15em; height: 1.15em; flex: none; display: inline-block; vertical-align: -.2em;
    fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}
.ic--spin { animation: ui-spin .9s linear infinite; }
@keyframes ui-spin { to { transform: rotate(360deg); } }

/* Button ---------------------------------------------------------------- */
.ui-btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 10px 14px; border-radius: var(--r-md); border: 1px solid transparent;
    font-family: inherit; font-size: 13.5px; font-weight: 600; white-space: nowrap;
    cursor: pointer; text-decoration: none; transition: all .15s var(--ease);
}
.ui-btn:active { transform: scale(.97); }
.ui-btn:disabled { opacity: .55; cursor: default; transform: none; box-shadow: none; }
.ui-btn--primary { background: var(--primary); color: var(--on-color); box-shadow: var(--shadow-primary); }
.ui-btn--primary:hover { background: var(--primary-strong); color: var(--on-color); transform: translateY(-1px); }
.ui-btn--secondary { background: var(--surface); border-color: var(--border); color: var(--text); }
.ui-btn--secondary:hover { background: var(--surface-3); color: var(--text); }
.ui-btn--quiet { background: transparent; color: var(--text-2); }
.ui-btn--quiet:hover { background: var(--surface-3); color: var(--text); }
.ui-btn--dark { background: var(--ink); color: var(--on-color); }
.ui-btn--dark:hover { background: var(--ink-2); color: var(--on-color); transform: translateY(-1px); }
.ui-btn--light { background: var(--surface); color: var(--ink); box-shadow: 0 18px 35px rgba(0, 0, 0, .25); }
.ui-btn--light:hover { color: var(--ink); transform: translateY(-1px); box-shadow: 0 22px 40px rgba(0, 0, 0, .3); }
.ui-btn--outline-light { border-color: rgba(255, 255, 255, .28); color: var(--on-color); }
.ui-btn--outline-light:hover { border-color: rgba(255, 255, 255, .55); color: var(--on-color); }
.ui-btn--sm { padding: 5px 10px; font-size: var(--fs-xs); border-radius: var(--r-sm); gap: 5px; }
.ui-btn--lg { padding: 13px 22px; font-size: var(--fs-base); border-radius: 12px; }
.ui-btn--block { display: flex; width: 100%; }
.ui-btn .ic { width: 1.1em; height: 1.1em; }
.ui-btn--arrow .ic:last-child { transition: transform .2s var(--ease); }
.ui-btn--arrow:hover .ic:last-child { transform: translateX(2px); }

.ui-iconbtn {
    width: 36px; height: 36px; border-radius: 10px; border: 1px solid var(--border);
    background: var(--surface); color: var(--muted); cursor: pointer;
    display: inline-grid; place-items: center; flex: none; transition: all .15s; padding: 0;
}
.ui-iconbtn:hover { color: var(--primary-strong); border-color: var(--primary); }
.ui-iconbtn:disabled { opacity: .45; cursor: default; }
.ui-iconbtn:disabled:hover { color: var(--muted); border-color: var(--border); }
.ui-iconbtn--sm { width: 28px; height: 28px; border-radius: var(--r-sm); font-size: 12px; }
.ui-iconbtn--bare { border-color: transparent; background: transparent; }
.ui-iconbtn--bare:hover { background: var(--surface-3); border-color: transparent; }
.ui-iconbtn .ic { width: 16px; height: 16px; }
.ui-iconbtn--sm .ic { width: 14px; height: 14px; }

/* Field ----------------------------------------------------------------- */
.ui-field { display: block; margin-bottom: var(--sp-4); }
.ui-field__label { display: flex; justify-content: space-between; align-items: baseline; gap: var(--sp-2); margin-bottom: 6px; font-size: 12.5px; font-weight: 600; color: var(--text-2); }
.ui-field__label a { font-weight: 600; }
.ui-input {
    display: block; width: 100%; height: 42px; padding: 0 13px;
    border: 1px solid var(--border-strong); border-radius: var(--r-md); background: var(--surface);
    font: inherit; font-size: 14.5px; color: var(--text);
    transition: border-color .15s, box-shadow .15s;
}
textarea.ui-input { height: auto; min-height: 120px; padding: 11px 13px; line-height: 1.5; resize: vertical; }
select.ui-input { appearance: none; padding-right: 36px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%239aa1ad' stroke-width='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 12px center; }
.ui-input::placeholder { color: var(--faint); }
.ui-input:hover { border-color: var(--border-hover); }
.ui-input:focus { outline: none; border-color: var(--primary); box-shadow: var(--ring); }
.ui-field__hint { display: block; margin-top: 6px; font-size: var(--fs-xs); color: var(--muted); }
.ui-field__error { display: block; margin-top: 6px; font-size: var(--fs-xs); color: var(--danger); }
.ui-field.is-invalid .ui-input { border-color: var(--danger-bright); box-shadow: var(--ring-danger); }
.ui-check { display: inline-flex; align-items: center; gap: var(--sp-2); font-size: var(--fs-sm); color: var(--text-2); cursor: pointer; }
.ui-check input { width: 16px; height: 16px; margin: 0; accent-color: var(--primary); }
.ui-meter { display: flex; gap: 4px; margin-top: 8px; }
.ui-meter span { flex: 1; height: 4px; border-radius: 2px; background: var(--surface-3); transition: background .2s; }
.ui-meter[data-score="1"] span:nth-child(1) { background: var(--danger-bright); }
.ui-meter[data-score="2"] span:nth-child(-n+2) { background: var(--warning-bright); }
.ui-meter[data-score="3"] span { background: var(--success-bright); }

/* Card ------------------------------------------------------------------ */
.ui-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--shadow-sm); }
.ui-card--raised { box-shadow: var(--shadow-lg); border-color: transparent; }

/* Chip, badge, kbd ------------------------------------------------------- */
.ui-chip {
    display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px;
    border: 1px solid var(--border); border-radius: var(--r-full); background: var(--surface);
    font-size: var(--fs-sm); font-weight: 500; color: var(--text-2); line-height: 1.3; white-space: nowrap;
    cursor: pointer; transition: all .15s var(--ease);
}
.ui-chip:hover { border-color: var(--primary-line); background: var(--primary-soft); color: var(--primary-strong); }
.ui-chip.is-active, .ui-chip[aria-pressed="true"] { border-color: var(--primary); background: var(--primary-soft); color: var(--primary-strong); }
.ui-chip .ic { width: 14px; height: 14px; }
.ui-badge {
    display: inline-block; min-width: 18px; padding: 0 6px; border-radius: var(--r-full);
    background: var(--primary-soft); color: var(--primary-strong);
    font-size: 11px; font-weight: 700; text-align: center;
}
.ui-badge--accent { background: var(--accent-soft); color: var(--accent-strong); }
.ui-badge--neutral { background: var(--surface-3); color: var(--muted); }
.ui-badge--upper { padding: 2px 8px; text-transform: uppercase; letter-spacing: .06em; font-size: 10.5px; }
.ui-kbd {
    display: inline-block; padding: 0 6px; border: 1px solid var(--border); border-bottom-width: 2px;
    border-radius: var(--r-xs); background: var(--surface); color: var(--muted);
    font-family: var(--font-mono); font-size: 11px;
}

/* Alert (inline) --------------------------------------------------------- */
.ui-alert {
    display: flex; align-items: flex-start; gap: 10px; padding: 11px 14px; border-radius: var(--r-md);
    border: 1px solid var(--primary-line); background: var(--primary-soft); color: var(--primary-strong);
    font-size: var(--fs-sm); line-height: 1.5;
}
.ui-alert .ic { width: 16px; height: 16px; margin-top: 1px; }
.ui-alert--success { border-color: var(--success-line); background: var(--success-soft); color: var(--success); }
.ui-alert--warning { border-color: var(--warning-line); background: var(--warning-soft); color: var(--warning); }
.ui-alert--danger { border-color: var(--danger-line); background: var(--danger-soft); color: var(--danger-strong); }

/* Toast ----------------------------------------------------------------- */
.ui-toasts {
    position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: var(--z-toast);
    display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none;
    width: max-content; max-width: calc(100vw - 32px);
}
.ui-toasts--top { top: 84px; bottom: auto; }
.ui-toast {
    pointer-events: auto; display: flex; align-items: center; gap: 10px; max-width: 460px;
    padding: 11px 12px 11px 14px; border-radius: 12px; background: #111827; color: #f9fafb;
    font-size: var(--fs-sm); line-height: 1.4; box-shadow: 0 14px 34px rgba(15, 23, 42, .28);
    animation: ui-enter .22s var(--ease) both;
}
.ui-toast > .ic { width: 16px; height: 16px; color: #a5b4fc; }
.ui-toast--error > .ic { color: #fca5a5; }
.ui-toast--success > .ic { color: #6ee7b7; }
.ui-toast span { flex: 1; min-width: 0; }
.ui-toast button { border: 0; background: transparent; color: #9ca3af; width: 26px; height: 26px; border-radius: 7px; cursor: pointer; display: grid; place-items: center; flex: none; padding: 0; }
.ui-toast button:hover { background: rgba(255, 255, 255, .1); color: var(--on-color); }
.ui-toast button .ic { width: 14px; height: 14px; }
.ui-toast.is-leaving { opacity: 0; transform: translateY(6px); transition: opacity .2s, transform .2s; }
@keyframes ui-enter { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* Dialog ---------------------------------------------------------------- */
.ui-dialog {
    position: fixed; inset: 0; z-index: var(--z-dialog); display: none; place-items: center;
    background: rgba(17, 24, 39, .35); backdrop-filter: blur(4px);
}
.ui-dialog.is-open { display: grid; }

/* Table ----------------------------------------------------------------- */
.ui-table { width: 100%; border-collapse: collapse; font-size: var(--fs-xs); }
.ui-table th, .ui-table td { padding: 5px 7px; border-bottom: 1px solid #f0f1f4; text-align: left; white-space: nowrap; max-width: 200px; overflow: hidden; text-overflow: ellipsis; }
.ui-table th { position: sticky; top: 0; z-index: 1; background: var(--surface); color: var(--muted); font-weight: 600; text-transform: capitalize; white-space: normal; line-height: 1.25; vertical-align: bottom; min-width: 52px; } /* headers wrap so a long label doesn't widen its column */
.ui-table th.is-sortable { cursor: pointer; user-select: none; }
.ui-table__sort { all: unset; cursor: pointer; border-radius: 3px; }
.ui-table__sort:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.ui-table th.is-sortable:hover { color: var(--text); }
.ui-table th.is-sorted { color: var(--primary-strong); }
.ui-table th .ic { width: 10px; height: 10px; margin-left: 4px; stroke-width: 2.5; vertical-align: -1px; }
.ui-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.ui-table tbody tr:hover td { background: var(--surface-2); }
.ui-table-wrap { max-height: 320px; overflow: auto; border: 1px solid #f0f1f4; border-radius: var(--r-sm); }

/* Tabs ------------------------------------------------------------------ */
.ui-tab {
    border: 0; border-bottom: 2px solid transparent; margin-bottom: -1px; background: transparent;
    padding: 8px 12px 12px; font-family: inherit; font-size: 13.5px; font-weight: 600; color: var(--muted);
    cursor: pointer; transition: color .15s, border-color .15s;
}
.ui-tab:hover { color: var(--text); }
.ui-tab.is-active, .ui-tab[aria-selected="true"] { color: var(--primary-strong); border-bottom-color: var(--primary); }

/* Scroll area: thin scrollbars ------------------------------------------ */
.ui-scroll { scrollbar-width: thin; scrollbar-color: #d1d5db #f3f4f6; }
.ui-scroll::-webkit-scrollbar { width: 6px; height: 6px; }
.ui-scroll::-webkit-scrollbar-track { background: #f3f4f6; border-radius: var(--r-full); }
.ui-scroll::-webkit-scrollbar-thumb { background-color: #d1d5db; border-radius: var(--r-full); transition: background-color .15s; }
.ui-scroll::-webkit-scrollbar-thumb:hover { background-color: #9ca3af; }

/* Brand ----------------------------------------------------------------- */
.ui-brand { display: inline-flex; align-items: center; gap: 10px; text-decoration: none; }
.ui-brand__mark {
    width: 36px; height: 36px; border-radius: 50%; background: var(--brand-gradient); color: var(--on-color);
    display: grid; place-items: center; flex: none; box-shadow: 0 6px 16px rgba(82, 98, 232, .28);
}
.ui-brand__mark .ic { width: 18px; height: 18px; stroke-width: 2; }
.ui-brand__name { font-family: var(--font-display); font-size: 19px; font-weight: 800; letter-spacing: -.02em; color: var(--primary-strong); }

/* Layout ---------------------------------------------------------------- */
.ui-container { width: 100%; max-width: calc(var(--container) + 2 * var(--gutter)); margin: 0 auto; padding: 0 var(--gutter); }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
