/* One token layer for the whole tool. Values follow the ux-ui-kit tokens. Base styles are the phone layout. */
:root {
  color-scheme: light dark;
  --surface-page: #f9fafb;
  --surface: #ffffff;
  --surface-sunken: #f3f4f6;
  --text: #111827;
  --text-muted: #4b5563;
  --border: #d1d5db;
  --border-strong: #6b7280;
  --action: #1d4ed8;
  --action-hover: #1e40af;
  --action-active: #1e3a8a;
  --on-action: #ffffff;
  --action-soft: #dbeafe;
  --link: #1d4ed8;
  --danger: #b91c1c;
  --danger-hover: #991b1b;
  --on-danger: #ffffff;
  --danger-soft: #fee2e2;
  --danger-text: #991b1b;
  --warn-soft: #fef3c7;
  --warn-text: #92400e;
  --ok-soft: #dcfce7;
  --ok-text: #166534;
  --neutral-soft: #e5e7eb;
  --neutral-text: #374151;
  --focus: #1d4ed8;
  --backdrop: rgb(17 24 39 / 0.55);

  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;
  --space-7: 3rem;

  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --fs-small: 0.8125rem;
  --fs-body: 0.875rem;
  --fs-input: 1rem;
  --fs-section: 1.0625rem;
  --fs-display: 2.25rem;

  --radius: 0.375rem;
  --radius-lg: 0.5rem;
  --line: 1px;
  --line-focus: 2px;
  --control: 2.75rem;
  --thumb: 3rem;
  --thumb-lg: 6rem;
  --page-max: 80rem;
  --sheet-max: 48rem;
  --measure: 40rem;
  --shadow: 0 8px 24px rgb(17 24 39 / 0.18);
  --dur: 120ms;
}

@media (prefers-color-scheme: dark) {
  :root {
    --surface-page: #030712;
    --surface: #111827;
    --surface-sunken: #1f2937;
    --text: #f9fafb;
    --text-muted: #d1d5db;
    --border: #4b5563;
    --border-strong: #9ca3af;
    --action: #2563eb;
    --action-hover: #1d4ed8;
    --action-active: #1e40af;
    --action-soft: #172554;
    --link: #93c5fd;
    --danger: #b91c1c;
    --danger-hover: #991b1b;
    --danger-soft: #450a0a;
    --danger-text: #fecaca;
    --warn-soft: #451a03;
    --warn-text: #fde68a;
    --ok-soft: #052e16;
    --ok-text: #bbf7d0;
    --neutral-soft: #374151;
    --neutral-text: #e5e7eb;
    --focus: #93c5fd;
    --backdrop: rgb(0 0 0 / 0.7);
    --shadow: 0 8px 24px rgb(0 0 0 / 0.6);
  }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--surface-page);
  color: var(--text);
  font: var(--fs-body) / 1.5 var(--font);
  overflow-wrap: anywhere;
}
h1, h2, h3, p, ul { margin: 0; }
ul { padding: 0; list-style: none; }
a { color: var(--link); }
svg.icon { width: 1em; height: 1em; flex: none; vertical-align: -0.125em; }
:focus-visible { outline: var(--line-focus) solid var(--focus); outline-offset: var(--line-focus); }
h1:focus { outline: none; }

.skip { position: absolute; left: var(--space-2); top: calc(var(--space-7) * -2); background: var(--surface); padding: var(--space-2) var(--space-3); z-index: 3; }
.skip:focus { top: var(--space-2); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* Shell */
.top { background: var(--surface); border-bottom: var(--line) solid var(--border); padding: var(--space-2) var(--space-4) 0; }
.brand { font-weight: 650; padding-block: var(--space-1); }
.steps { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--space-1); }
.step {
  appearance: none; background: none; border: 0; border-bottom: var(--line-focus) solid transparent; color: var(--text-muted);
  cursor: pointer; font: inherit; font-size: var(--fs-small); min-height: var(--control); padding: var(--space-1); text-align: left;
  transition: color var(--dur), border-color var(--dur);
}
.step strong { display: block; font-weight: 600; }
.step small { display: block; font-size: var(--fs-small); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.step:hover { color: var(--text); border-bottom-color: var(--border-strong); }
.step[aria-current="step"] { color: var(--link); border-bottom-color: var(--link); }
.page { margin-inline: auto; max-width: var(--page-max); padding: var(--space-5) var(--space-4) var(--space-7); }

/* Type */
.display { font-size: var(--fs-display); font-weight: 700; letter-spacing: -0.01em; line-height: 1.15; }
.lead { color: var(--text-muted); margin-top: var(--space-2); max-width: var(--measure); }
.section { margin-top: var(--space-6); }
.section > h2 { font-size: var(--fs-section); font-weight: 650; }
.section > .hint { margin-top: var(--space-1); }
.hint { color: var(--text-muted); font-size: var(--fs-small); }
.mono { font-family: var(--font-mono); font-size: var(--fs-small); }

/* Buttons */
.btn {
  align-items: center; appearance: none; background: var(--surface); border: var(--line) solid var(--border-strong); border-radius: var(--radius);
  color: var(--text); cursor: pointer; display: inline-flex; font: inherit; font-weight: 550; gap: var(--space-2); justify-content: center;
  min-height: var(--control); padding: var(--space-2) var(--space-4); text-decoration: none; transition: background var(--dur), border-color var(--dur);
}
.btn:hover { background: var(--surface-sunken); }
.btn:active { background: var(--neutral-soft); }
.btn.primary { background: var(--action); border-color: var(--action); color: var(--on-action); }
.btn.primary:hover { background: var(--action-hover); border-color: var(--action-hover); }
.btn.primary:active { background: var(--action-active); border-color: var(--action-active); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: var(--on-danger); }
.btn.danger:hover { background: var(--danger-hover); border-color: var(--danger-hover); }
.btn.danger-quiet { border-color: var(--danger-text); color: var(--danger-text); }
.btn.danger-quiet:hover { background: var(--danger-soft); }
.btn.link { background: none; border-color: transparent; color: var(--link); padding-inline: var(--space-2); text-decoration: underline; }
.btn.link:hover { background: var(--surface-sunken); }
.btn[disabled] { background: var(--neutral-soft); border-color: var(--neutral-soft); color: var(--text-muted); cursor: not-allowed; }
.btn-row { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-top: var(--space-4); }

/* Forms */
.form-grid { display: grid; gap: var(--space-4); grid-template-columns: minmax(0, 1fr); margin-top: var(--space-4); }
.field { display: grid; gap: var(--space-1); align-content: start; min-width: 0; }
.field > label, .label { font-weight: 550; }
.req { color: var(--danger-text); }
.input, .textarea {
  background: var(--surface); border: var(--line) solid var(--border-strong); border-radius: var(--radius); color: var(--text);
  font: inherit; font-size: var(--fs-input); min-height: var(--control); padding: var(--space-2) var(--space-3); width: 100%;
}
.textarea { min-height: calc(var(--control) * 3); resize: vertical; }
.input:hover, .textarea:hover { border-color: var(--text); }
.input[aria-invalid="true"] { border-color: var(--danger-text); }
.field-error { color: var(--danger-text); font-size: var(--fs-small); }
.check { align-items: center; display: inline-flex; gap: var(--space-2); justify-content: center; min-height: var(--control); min-width: var(--control); }
.check input { accent-color: var(--action); height: 1.125rem; margin: 0; width: 1.125rem; }
.counter { color: var(--text-muted); font-size: var(--fs-small); }
.counter.over { color: var(--danger-text); font-weight: 600; }

/* Listbox */
.lb { position: relative; min-width: 0; }
.lb-trigger {
  align-items: center; appearance: none; background: var(--surface); border: var(--line) solid var(--border-strong); border-radius: var(--radius);
  color: var(--text); cursor: pointer; display: flex; font: inherit; gap: var(--space-3); justify-content: space-between; min-height: var(--control);
  padding: var(--space-2) var(--space-3); text-align: left; width: 100%;
}
.lb-trigger:hover { background: var(--surface-sunken); }
.lb-trigger[aria-expanded="true"] { border-color: var(--focus); }
.lb-list {
  background: var(--surface); border: var(--line) solid var(--border-strong); border-radius: var(--radius); box-shadow: var(--shadow);
  left: 0; margin-top: var(--space-1); max-height: 16rem; min-width: 100%; overflow-y: auto; padding: var(--space-1); position: absolute; top: 100%; z-index: 2;
}
.lb-list li { border-radius: var(--radius); cursor: pointer; padding: var(--space-2) var(--space-3); white-space: nowrap; }
.lb-list li:hover, .lb-list li.active { background: var(--surface-sunken); }
.lb-list li[aria-selected="true"] { background: var(--action-soft); font-weight: 600; }

/* Surfaces */
.panel { background: var(--surface); border: var(--line) solid var(--border); border-radius: var(--radius-lg); padding: var(--space-4); }
.notice { align-items: flex-start; border: var(--line) solid var(--border); border-radius: var(--radius); display: flex; gap: var(--space-2); margin-top: var(--space-4); padding: var(--space-3); }
.notice.warn { background: var(--warn-soft); color: var(--warn-text); }
.notice.error { background: var(--danger-soft); color: var(--danger-text); }
.notice .icon { margin-top: 0.2em; }
.drop {
  align-items: center; background: var(--surface); border: var(--line-focus) dashed var(--border-strong); border-radius: var(--radius-lg); cursor: pointer;
  display: grid; gap: var(--space-2); justify-items: center; margin-top: var(--space-5); padding: var(--space-6) var(--space-4); text-align: center;
  transition: background var(--dur), border-color var(--dur);
}
.drop:hover, .drop.over { background: var(--action-soft); border-color: var(--action); }
.drop:focus-within { outline: var(--line-focus) solid var(--focus); outline-offset: var(--line-focus); }
.drop .icon { color: var(--link); height: var(--space-6); width: var(--space-6); }
.drop strong { font-size: var(--fs-section); }
.spinner { animation: spin 0.8s linear infinite; border: var(--line-focus) solid var(--border); border-radius: 50%; border-top-color: var(--action); display: inline-block; height: 1.25rem; width: 1.25rem; }
@keyframes spin { to { transform: rotate(360deg); } }
.empty { background: var(--surface); border: var(--line) solid var(--border); border-radius: var(--radius-lg); margin-top: var(--space-5); padding: var(--space-6) var(--space-4); }
.empty h2 { font-size: var(--fs-section); }
.empty p { color: var(--text-muted); margin-top: var(--space-1); max-width: var(--measure); }

/* Status */
.badge { align-items: center; border-radius: var(--radius); display: inline-flex; font-size: var(--fs-small); font-weight: 600; gap: var(--space-1); padding: 0 var(--space-2); white-space: nowrap; }
.badge.ready { background: var(--ok-soft); color: var(--ok-text); }
.badge.warn { background: var(--warn-soft); color: var(--warn-text); }
.badge.error { background: var(--danger-soft); color: var(--danger-text); }
.badge.excluded { background: var(--neutral-soft); color: var(--neutral-text); }
.issue-list { display: grid; gap: var(--space-2); margin-top: var(--space-3); }
.issue-list li { align-items: flex-start; display: flex; gap: var(--space-2); }
.issue-list .icon { margin-top: 0.2em; }
.issue-list .error { color: var(--danger-text); }
.issue-list .warn { color: var(--warn-text); }
.issue-count { font-weight: 650; }

/* Filters */
.toolbar { display: grid; gap: var(--space-2); grid-template-columns: minmax(0, 1fr); margin-top: var(--space-5); }
.chips { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.chip {
  appearance: none; background: var(--surface); border: var(--line) solid var(--border-strong); border-radius: var(--radius); color: var(--text); cursor: pointer;
  font: inherit; font-size: var(--fs-small); min-height: var(--control); padding: var(--space-1) var(--space-3);
}
.chip:hover { background: var(--surface-sunken); }
.chip[aria-pressed="true"] { background: var(--action-soft); border-color: var(--action); color: var(--link); font-weight: 650; }
.bulk { align-items: end; background: var(--surface-sunken); border-radius: var(--radius); display: grid; gap: var(--space-2); grid-template-columns: minmax(0, 1fr); margin-top: var(--space-3); padding: var(--space-3); }

/* Tables are stacked cards on a phone and real tables from the tablet width. */
.table { border-collapse: collapse; margin-top: var(--space-3); width: 100%; }
.table thead { display: none; }
.table, .table tbody, .table tr, .table td { display: block; }
.table tr { background: var(--surface); border: var(--line) solid var(--border); border-radius: var(--radius-lg); margin-bottom: var(--space-2); padding: var(--space-3); position: relative; }
.table td:first-child { padding: 0; position: absolute; right: var(--space-1); top: var(--space-1); }
.table td:nth-child(2) { padding-right: var(--control); }
.table td { padding: var(--space-1) 0; }
.table td[data-label]:not([data-label=""])::before { color: var(--text-muted); content: attr(data-label) ": "; font-size: var(--fs-small); }
.table tr.is-excluded .row-title { color: var(--text-muted); }
.row-main { align-items: flex-start; display: flex; gap: var(--space-3); }
.row-title {
  appearance: none; background: none; border: 0; color: var(--link); cursor: pointer; font: inherit; font-weight: 600; min-height: var(--control);
  padding: 0; text-align: left; text-decoration: underline; text-decoration-thickness: from-font;
}
.row-sub { color: var(--text-muted); font-size: var(--fs-small); }
.thumb {
  align-items: center; aspect-ratio: 1; background: var(--surface-sunken); border-radius: var(--radius); color: var(--text-muted); display: flex; flex: none;
  justify-content: center; object-fit: cover; overflow: hidden; width: var(--thumb);
}
.num { font-variant-numeric: tabular-nums; }
.pager { align-items: center; display: flex; flex-wrap: wrap; gap: var(--space-2); justify-content: space-between; margin-top: var(--space-3); }
.scroll-x { border: var(--line) solid var(--border); border-radius: var(--radius); margin-top: var(--space-3); overflow-x: auto; }
.data { border-collapse: collapse; font-size: var(--fs-small); min-width: 100%; }
.data th, .data td { border-bottom: var(--line) solid var(--border); max-width: 20rem; overflow-wrap: normal; padding: var(--space-2) var(--space-3); text-align: left; vertical-align: top; }
.data th { background: var(--surface-sunken); font-weight: 600; white-space: nowrap; }
.data tbody tr:last-child td { border-bottom: 0; }
.data .soft { color: var(--text-muted); }

.select-all-phone { align-items: center; display: flex; gap: var(--space-2); margin-top: var(--space-3); min-height: var(--control); }
.select-all-phone input { accent-color: var(--action); height: 1.125rem; margin: 0; width: 1.125rem; }

.session { align-items: center; display: flex; flex-wrap: wrap; font-size: var(--fs-small); gap: var(--space-1) var(--space-3); padding-block: var(--space-1); }
.save { align-items: center; color: var(--text-muted); display: inline-flex; gap: var(--space-1); }
.save.error { color: var(--danger-text); font-weight: 600; }
.who { color: var(--text-muted); }
.section-title { font-size: var(--fs-section); }
.suggest-list { display: grid; gap: var(--space-1); margin-top: var(--space-2); }
.suggest { appearance: none; background: var(--surface); border: var(--line) solid var(--border-strong); border-radius: var(--radius); color: var(--text); cursor: pointer; display: grid; font: inherit; gap: var(--space-1); min-height: var(--control); padding: var(--space-2) var(--space-3); text-align: left; width: 100%; }
.suggest:hover { background: var(--action-soft); border-color: var(--action); }
.more { margin-top: var(--space-3); }
.more summary { color: var(--link); cursor: pointer; font-weight: 550; min-height: var(--control); padding-block: var(--space-2); }
#aspectArea .form-grid { margin-top: var(--space-3); }

/* Rules */
.rule { align-items: end; display: grid; gap: var(--space-2); grid-template-columns: minmax(0, 1fr); margin-top: var(--space-3); padding-bottom: var(--space-3); border-bottom: var(--line) solid var(--border); }

/* Detail sheet */
dialog { background: var(--surface); border: 0; color: var(--text); padding: 0; }
dialog::backdrop { background: var(--backdrop); }
.sheet { height: 100dvh; margin: 0; max-height: none; max-width: none; width: 100%; }
.sheet-head { align-items: center; background: var(--surface); border-bottom: var(--line) solid var(--border); display: flex; gap: var(--space-2); justify-content: space-between; padding: var(--space-2) var(--space-4); position: sticky; top: 0; z-index: 1; }
.sheet-head h2 { font-size: var(--fs-section); }
.sheet-body { display: grid; gap: var(--space-5); grid-template-columns: minmax(0, 1fr); padding: var(--space-4); }
.sheet-section > h3 { font-size: var(--fs-body); font-weight: 650; margin-bottom: var(--space-2); }
.gallery { display: flex; flex-wrap: wrap; gap: var(--space-3); }
.gallery li { display: grid; gap: var(--space-1); width: var(--thumb-lg); }
.gallery .thumb { width: var(--thumb-lg); }
.gallery .btn { font-size: var(--fs-small); min-height: var(--control); padding: var(--space-1); }
.confirm { border-radius: var(--radius-lg); box-shadow: var(--shadow); max-width: min(28rem, calc(100vw - var(--space-5))); padding: var(--space-5); }
.confirm h2 { font-size: var(--fs-section); }
.confirm p { color: var(--text-muted); margin-top: var(--space-2); }

.toast { background: var(--text); border-radius: var(--radius); bottom: var(--space-4); box-shadow: var(--shadow); color: var(--surface); left: var(--space-4); padding: var(--space-3) var(--space-4); position: fixed; right: var(--space-4); z-index: 3; }

.stat-line { color: var(--text-muted); display: flex; flex-wrap: wrap; gap: var(--space-1) var(--space-4); margin-top: var(--space-2); }

@media (min-width: 48rem) {
  :root { --control: 2.25rem; --fs-input: 0.875rem; --thumb: 2.5rem; }
  .top { align-items: center; display: flex; gap: var(--space-6); padding-block: 0; }
  .steps { flex: 1; grid-template-columns: repeat(4, minmax(0, 9rem)); }
  .session { justify-content: flex-end; padding-block: 0; }
  .step { padding-block: var(--space-2); }
  .form-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .toolbar { align-items: center; grid-template-columns: minmax(0, 18rem) minmax(0, 12rem) 1fr; }
  .bulk { grid-template-columns: repeat(2, minmax(0, 11rem)) repeat(4, auto); justify-content: start; }
  .rule { grid-template-columns: repeat(3, minmax(0, 1fr)) auto; }

  .select-all-phone { display: none; }
  .table { background: var(--surface); border: var(--line) solid var(--border); display: table; }
  .table thead { display: table-header-group; }
  .table tbody { display: table-row-group; }
  .table tr { background: none; border: 0; border-radius: 0; display: table-row; margin: 0; padding: 0; }
  .table td:first-child { position: static; }
  .table td:nth-child(2) { padding-right: var(--space-3); }
  .table tr { position: static; }
  .table th, .table td { border-bottom: var(--line) solid var(--border); display: table-cell; padding: var(--space-2) var(--space-3); text-align: left; vertical-align: middle; }
  .table th { background: var(--surface-sunken); font-size: var(--fs-small); font-weight: 600; white-space: nowrap; }
  .table td[data-label]:not([data-label=""])::before { content: none; }
  .table tbody tr:hover { background: var(--surface-page); }

  .sheet { border-radius: var(--radius-lg) 0 0 var(--radius-lg); margin-left: auto; max-width: var(--sheet-max); }
  .toast { left: auto; max-width: 28rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
