/* OSS owner app: chrome, Liquid Glass, buttons, forms, notices and labels. Every colour and face comes from tokens.css.
   Surfaces climb one rung at a time: parchment page, white grouped cell (hairline), tinted well inside a cell (no edge).
   Glass is chrome only, the parts that float over content: the nav, the step rail, a step's action bar and the chat composer. */

/* ---------- type ---------- */
h1, h2, h3 { color: var(--color-ink); line-height: 1.16; }
h1 { font-size: var(--text-display); margin-bottom: var(--space-xs); }
h2 { font-size: var(--text-section); margin-bottom: var(--space-xs); }
h3 { font-size: var(--text-title); margin-bottom: var(--space-xs); }
:lang(th) :is(h1, h2, h3), :is(h1, h2, h3):lang(th) { line-height: 1.38; letter-spacing: 0; }
p { margin: 0 0 var(--space-sm); }
a { color: var(--color-accent-ink); text-decoration-color: color-mix(in oklab, var(--color-accent-ink) 40%, transparent); transition: color var(--dur-micro) var(--ease-out), text-decoration-color var(--dur-micro) var(--ease-out); }
a:hover { color: var(--color-accent-press); text-decoration-color: currentColor; }
a:active { color: var(--color-ink); }
.lede { color: var(--color-ink-2); max-width: 60ch; }
.muted { color: var(--color-muted); }
.hint { margin: 0; color: var(--color-muted); font-size: var(--text-sm); }
.label { margin: 0 0 var(--space-2xs); color: var(--color-ink-2); font-size: var(--text-sm); font-weight: 600; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
.skip-link {
  position: absolute; left: var(--space-md); top: -4rem; z-index: var(--z-tooltip); padding: var(--space-xs) var(--space-md);
  border-radius: var(--radius-pill); background: var(--color-ink); color: var(--color-paper-2); text-decoration: none;
}
.skip-link:focus-visible { top: var(--space-md); }

/* ---------- Liquid Glass ---------- */
.topbar, .rail-nav, .step > .actions--end, .composer {
  background: var(--glass-sheen), var(--glass-fill);
  -webkit-backdrop-filter: var(--glass-blur); backdrop-filter: var(--glass-blur);
  box-shadow: inset 0 1px 0 var(--glass-rim), inset 0 0 0 1px var(--glass-edge), var(--glass-lift);
}
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .topbar, .rail-nav, .step > .actions--end, .composer { background: var(--glass-fill-strong); }
}

/* ---------- chrome ---------- */
.topbar {
  position: sticky; top: var(--space-sm); z-index: var(--z-sticky-nav);
  width: min(100% - 2 * var(--space-md), 1160px); margin: var(--space-sm) auto 0;
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-sm);
  min-height: 56px; padding: var(--space-2xs) var(--space-2xs) var(--space-2xs) var(--space-lg); border-radius: var(--radius-pill);
}
.topbar-actions { display: flex; align-items: center; gap: var(--space-2xs); }
.brand { display: inline-flex; align-items: center; gap: var(--space-sm); min-height: 44px; text-decoration: none; color: var(--color-ink); }
.brand:hover { color: var(--color-ink); }
.wordmark {
  font-family: var(--font-display); font-size: 1.25rem; font-weight: 600; line-height: 1; letter-spacing: 0.08em;
  color: var(--color-accent-ink); white-space: nowrap; font-synthesis: none;
}
.brand-sub { color: var(--color-ink-2); font-size: var(--text-sm); }
.shell {
  width: 100%; max-width: calc(880px + 2 * var(--gutter)); margin: 0 auto; flex: 1;
  padding: var(--space-xl) var(--gutter) var(--space-2xl);
}
.shell--wide { max-width: calc(1160px + 2 * var(--gutter)); }
.shell--narrow { max-width: calc(440px + 2 * var(--gutter)); padding-top: var(--space-2xl); }
.foot {
  width: min(100% - 2 * var(--gutter), 1160px); margin: 0 auto;
  padding: var(--space-lg) 0 var(--space-xl); border-top: var(--rule-hair) solid var(--color-rule);
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-xs) var(--space-xl);
  color: var(--color-muted); font-size: var(--text-sm);
}
.foot .wordmark { font-size: 1rem; }
.contact-line { margin: 0; }
.contact-line a { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.foot-links { display: flex; flex-wrap: wrap; gap: 0 var(--space-lg); margin: 0 0 0 auto; padding: 0; list-style: none; }
.foot-links a { display: inline-flex; align-items: center; min-height: 44px; color: var(--color-ink-2); text-decoration: none; }
.foot-links a:hover { color: var(--color-accent-ink); text-decoration: underline; }
.link-row { list-style: none; margin: var(--space-lg) 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: var(--space-2xs) var(--space-lg); }
.link-row a { display: inline-flex; align-items: center; min-height: 44px; }

/* ---------- surfaces ---------- */
.card {
  background: var(--color-paper-2); border: var(--rule-hair) solid var(--color-rule); border-radius: var(--radius-card);
  padding: var(--space-xl);
}
.card + .card { margin-top: var(--space-lg); }
.panel { background: var(--color-paper-3); border-radius: var(--radius-inner); padding: var(--space-lg); }
.shell--narrow > .card { padding: var(--space-xl) var(--space-xl) var(--space-lg); }
.card > .lede { margin-bottom: var(--space-lg); }

/* ---------- buttons: one filled primary, an outlined pill, a text button ---------- */
.btn, .btn-quiet, .btn-text {
  position: relative; display: inline-flex; align-items: center; justify-content: center; gap: var(--space-xs);
  min-height: 44px; padding: 0 var(--space-lg); border-radius: var(--radius-pill); cursor: pointer;
  font: 400 var(--text-md)/1.2 var(--font-body); letter-spacing: inherit; text-align: center; text-decoration: none;
  transition: transform var(--dur-micro) var(--ease-out), background-color var(--dur-micro) var(--ease-out), color var(--dur-micro) var(--ease-out), box-shadow var(--dur-micro) var(--ease-out);
}
.btn { border: 0; background: var(--color-accent-ink); color: var(--color-paper-2); }
.btn:hover { background: var(--color-accent-press); color: var(--color-paper-2); }
.btn-quiet { border: 0; background: transparent; color: var(--color-accent-ink); box-shadow: inset 0 0 0 1px var(--color-accent-ink); }
.btn-quiet:hover { background: var(--color-accent-wash); color: var(--color-accent-press); }
.btn-text { min-height: 44px; padding: 0 var(--space-sm); border: 0; background: none; color: var(--color-accent-ink); }
.btn-text:hover { color: var(--color-accent-press); text-decoration: underline; text-underline-offset: 0.2em; }
:is(.btn, .btn-quiet, .btn-text):active { transform: scale(0.96); }
:is(.btn, .btn-quiet, .btn-text):focus-visible { outline: 2px solid var(--color-focus); outline-offset: 2px; transition: none; }
:is(.btn, .btn-quiet, .btn-text):disabled, :is(.btn, .btn-quiet, .btn-text)[aria-disabled="true"] { opacity: 0.55; cursor: not-allowed; transform: none; }
:is(.btn, .btn-quiet, .btn-text)[aria-busy="true"] { cursor: progress; opacity: 0.8; }
.btn-small { min-height: 38px; padding: 0 var(--space-md); font-size: var(--text-sm); }
.btn-small::after { content: ""; position: absolute; inset: -3px 0; }
.btn-wide { width: 100%; }
.btn-danger { color: var(--color-error); box-shadow: inset 0 0 0 1px var(--color-error); }
.btn-danger:hover { background: var(--color-error-wash); color: var(--color-error); }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-sm); margin-top: var(--space-lg); }
.actions--end { justify-content: flex-end; }
.lang-toggle { min-width: 52px; font-size: var(--text-sm); font-weight: 600; box-shadow: none; color: var(--color-ink); }
.lang-toggle:hover { background: var(--tint-hover); color: var(--color-ink); }
.topbar :is(.btn-text, .btn-quiet) { white-space: nowrap; }
.topbar .btn-text { color: var(--color-ink-2); }
.topbar .btn-text:hover { color: var(--color-ink); }

/* ---------- forms ---------- */
fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
legend { padding: 0; margin-bottom: var(--space-xs); color: var(--color-ink); font-weight: 600; }
.field { display: flex; flex-direction: column; gap: var(--space-2xs); min-width: 0; }
.field > label { color: var(--color-ink-2); font-size: var(--text-sm); font-weight: 600; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-md) var(--space-lg); }
.stack { display: grid; gap: var(--space-md); }
.span-2 { grid-column: 1 / -1; }
input:not([type="checkbox"], [type="radio"]), textarea, select {
  width: 100%; min-height: 44px; padding: var(--space-xs) var(--space-sm); border: 1px solid var(--color-edge); border-radius: var(--radius-control);
  background: var(--color-paper-2); color: var(--color-ink); font: 400 var(--text-md)/1.45 var(--font-body);
  transition: border-color var(--dur-micro) var(--ease-out), background-color var(--dur-micro) var(--ease-out);
}
input:not([type="checkbox"], [type="radio"]):hover, textarea:hover, select:hover { border-color: var(--color-ink-2); }
textarea { min-height: 96px; resize: vertical; }
input::placeholder, textarea::placeholder { color: var(--color-muted); opacity: 1; }
input:focus-visible, textarea:focus-visible, select:focus-visible { outline: 2px solid var(--color-focus); outline-offset: -1px; transition: none; }
input:disabled, textarea:disabled, select:disabled { opacity: 0.55; cursor: not-allowed; }
[aria-invalid="true"] { border-color: var(--color-error) !important; background: var(--color-error-wash); }
input[type="checkbox"], input[type="radio"] { width: 1.25rem; height: 1.25rem; margin: 0.15rem 0 0; accent-color: var(--color-accent-ink); flex: none; cursor: pointer; }
input[type="checkbox"]:focus-visible, input[type="radio"]:focus-visible { outline: 2px solid var(--color-focus); outline-offset: 2px; }
.check { display: flex; align-items: flex-start; gap: var(--space-sm); min-height: 44px; padding: var(--space-xs) 0; color: var(--color-ink); cursor: pointer; }
.field-error { margin: var(--space-2xs) 0 0; color: var(--color-error); font-size: var(--text-sm); font-weight: 600; }
.choice {
  display: flex; gap: var(--space-sm); padding: var(--space-md); border-radius: var(--radius-inner); cursor: pointer;
  background: var(--color-paper-3); box-shadow: inset 0 0 0 1px transparent;
  transition: box-shadow var(--dur-micro) var(--ease-out), background-color var(--dur-micro) var(--ease-out);
}
.choice:hover { box-shadow: inset 0 0 0 1px var(--color-edge); }
.choice:active { background: var(--color-accent-wash); }
.choice:has(input:checked) { background: var(--color-accent-wash); box-shadow: inset 0 0 0 2px var(--color-accent-ink); }
.choice:has(input:focus-visible) { outline: 2px solid var(--color-focus); outline-offset: 2px; }
.choice-title { display: block; color: var(--color-ink); font-weight: 600; }
.choice-text { display: block; color: var(--color-ink-2); font-size: var(--text-sm); }

/* ---------- notices and status labels ---------- */
.notice { margin: var(--space-md) 0; padding: var(--space-sm) var(--space-md); border-radius: var(--radius-inner); background: var(--color-accent-wash); color: var(--color-ink); }
.notice--ok { background: var(--color-success-wash); }
.notice--warn { background: var(--color-warn-wash); }
.notice--error { background: var(--color-error-wash); }
.notice > :last-child { margin-bottom: 0; }
.notice h2 { font-size: var(--text-title); }
.pill {
  display: inline-flex; align-items: center; padding: var(--space-3xs) var(--space-sm); border-radius: var(--radius-pill);
  font-size: var(--text-xs); font-weight: 600; line-height: 1.45; white-space: nowrap;
  background: var(--color-paper-3); color: var(--color-ink-2);
}
.pill[data-tone="ok"] { background: var(--color-success-wash); color: var(--color-success); }
.pill[data-tone="warn"] { background: var(--color-warn-wash); color: var(--color-warn); }
.pill[data-tone="error"] { background: var(--color-error-wash); color: var(--color-error); }
.pill[data-tone="soon"] { background: var(--color-accent-wash); color: var(--color-accent-ink); }

/* ---------- legal pages ---------- */
.legal { max-width: 760px; }
.legal p:not([class]) { line-height: 1.7; max-width: 68ch; }
.legal h2 { margin-top: var(--space-xl); }

@media (max-width: 640px) {
  .topbar { padding-left: var(--space-md); gap: 0; }
  .topbar-actions { gap: 0; }
  .topbar :is(.btn-text, .btn-quiet) { padding: 0 var(--space-xs); }
  .brand-sub { display: none; }
  .shell { padding-top: var(--space-lg); }
  .card, .shell--narrow > .card { padding: var(--space-lg) var(--space-md); border-radius: 18px; }
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .actions { flex-direction: column-reverse; align-items: stretch; }
  .actions > * { width: 100%; }
  .foot-links { margin-left: 0; }
}
