:root {
  color-scheme: light dark;
  --canvas: #f4f4f3;
  --canvas-soft: #e7e8e9;
  --surface: rgba(255, 255, 255, 0.84);
  --surface-solid: #ffffff;
  --text: #1c1d1f;
  --muted: #6d7175;
  --line: rgba(35, 38, 41, 0.13);
  --green: #595e63;
  --green-deep: #2e3134;
  --green-soft: #e3e5e7;
  --brown: #777d82;
  --cotton-gold: #b1842d;
  --cotton-gold-soft: #f2e7cc;
  --on-accent: #ffffff;
  --danger: #d0372f;
  --shadow: 0 12px 42px rgba(26, 48, 33, 0.08), 0 1px 2px rgba(26, 48, 33, 0.08);
  --radius-card: 24px;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Helvetica Neue", sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }

html { min-height: 100%; background: var(--canvas); }

body {
  min-width: 320px;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(circle at 8% 2%, color-mix(in srgb, var(--green) 11%, transparent), transparent 28rem),
    radial-gradient(circle at 96% 82%, rgba(110, 113, 117, 0.07), transparent 26rem),
    var(--canvas);
  -webkit-font-smoothing: antialiased;
}

button, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { color: inherit; }

.app-shell {
  width: min(100%, 1080px);
  margin: 0 auto;
  padding: calc(18px + env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) calc(34px + env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
}

.app-header {
  min-height: 52px;
  display: grid;
  grid-template-columns: 46px 1fr auto;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
}

.brand-mark {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 0;
  border-radius: 13px;
  background: linear-gradient(145deg, color-mix(in srgb, var(--green) 84%, white), color-mix(in srgb, var(--green) 82%, black));
  box-shadow: inset 0 1px rgba(255,255,255,.25), 0 6px 18px color-mix(in srgb, var(--green) 24%, transparent);
  cursor: pointer;
}

.brand-mark img {
  width: 40px;
  height: 40px;
  display: block;
  filter: drop-shadow(0 1px 1px rgba(7, 36, 18, .26));
}

.title-stack h1 { margin: 0; font-size: clamp(21px, 4vw, 27px); line-height: 1.12; letter-spacing: -.035em; }

.header-actions { display: flex; align-items: center; justify-content: flex-end; gap: 2px; }

.plain-button {
  min-height: 44px;
  padding: 0 8px;
  border: 0;
  background: transparent;
  color: var(--green);
  font-weight: 650;
  cursor: pointer;
}

.calculator-column, #parameter-mount { display: grid; gap: 16px; }
.calculator-column { width: min(100%, 760px); margin: 0 auto; }
#parameter-mount:empty { display: none; }

.card {
  overflow: hidden;
  border: 1px solid rgba(255,255,255,.66);
  border-radius: var(--radius-card);
  background: var(--surface);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px) saturate(135%);
  -webkit-backdrop-filter: blur(18px) saturate(135%);
}

.price-card { padding: 20px 16px 17px; }
.parameter-card { padding: 18px 16px 16px; }
.settings-reveal { animation: settings-reveal .22s ease-out both; }
@keyframes settings-reveal {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}
h2 { margin: 0; font-size: 17px; letter-spacing: -.015em; }

.section-heading { display: flex; justify-content: space-between; align-items: start; margin-bottom: 17px; }
.section-heading p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }

.fiber-mark { display: flex; gap: 3px; height: 27px; align-items: end; opacity: .7; }
.fiber-mark i { display: block; width: 4px; border-radius: 99px; background: var(--green); transform: rotate(13deg); }
.fiber-mark i:nth-child(1) { height: 15px; }
.fiber-mark i:nth-child(2) { height: 24px; }
.fiber-mark i:nth-child(3) { height: 19px; }

.price-bridge { display: grid; grid-template-columns: minmax(0, 1fr) 42px minmax(0, 1fr); align-items: center; }
.price-field { min-width: 0; display: grid; align-self: stretch; align-content: start; gap: 7px; }

.basis-pill {
  justify-self: start;
  padding: 4px 9px;
  border-radius: 999px;
  color: var(--on-accent);
  background: var(--green);
  font-size: 10px;
  font-weight: 700;
}
.basis-pill.lint { background: var(--brown); }
.basis-pill.is-passive { color: var(--muted); background: var(--canvas-soft); }

.input-shell {
  min-width: 0;
  display: block;
  padding: 9px 10px 8px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255,255,255,.38);
  transition: border-color .18s, box-shadow .18s;
}
.price-field:focus-within .input-shell { border-color: var(--green); box-shadow: 0 0 0 3px color-mix(in srgb, var(--green) 22%, transparent); }
.price-field.has-error .input-shell, .compact-field.has-error .compact-input { border-color: var(--danger); }
.field-label { display: block; margin-bottom: 3px; color: var(--muted); font-size: 11px; }
.value-row { display: flex; align-items: baseline; gap: 4px; }

input {
  min-width: 0;
  width: 100%;
  height: 31px;
  padding: 0;
  border: 0;
  outline: 0;
  color: var(--text);
  background: transparent;
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: clamp(16px, 4.6vw, 20px);
  font-weight: 700;
  letter-spacing: -.04em;
}
.unit { flex: 0 0 auto; color: var(--muted); font-size: 9px; white-space: nowrap; }
.bridge-symbol { display: grid; place-items: center; color: var(--green); }
.bridge-symbol span { font-size: 25px; font-weight: 700; line-height: 1; }
.bridge-symbol small { margin-top: 2px; color: var(--muted); font-size: 9px; }
.field-error { min-height: 0; color: var(--danger); font-size: 10px; line-height: 1.3; }
.field-error:empty { display: none; }
.card-error { min-height: 0; margin: 10px 0 0; color: var(--danger); font-size: 12px; }
.card-error:empty { display: none; }

.parameter-card h2 { margin-bottom: 14px; }
.parameter-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 10px; }
.compact-field { min-width: 0; display: grid; gap: 6px; color: var(--muted); font-size: 12px; }
.compact-input {
  min-height: 50px;
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: rgba(255,255,255,.3);
}
.compact-field:focus-within .compact-input { border-color: var(--green); box-shadow: 0 0 0 3px color-mix(in srgb, var(--green) 20%, transparent); }
.compact-input input { font-size: 16px; font-weight: 600; letter-spacing: -.02em; }
.compact-input b { flex: 0 0 auto; color: var(--muted); font-size: 9px; font-weight: 500; white-space: nowrap; }

.sheet-dialog {
  width: min(calc(100% - 32px), 390px);
  padding: 0;
  border: 0;
  border-radius: 22px;
  color: var(--text);
  background: rgba(250, 251, 249, .96);
  box-shadow: 0 28px 90px rgba(0,0,0,.25);
  backdrop-filter: blur(24px);
}
.sheet-dialog::backdrop { background: rgba(8, 13, 9, .34); backdrop-filter: blur(3px); }
.sheet-dialog form { padding: 22px 20px 16px; }
.sheet-dialog form > p { margin: 10px 0 20px; color: var(--muted); font-size: 14px; line-height: 1.55; }
.dialog-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.dialog-button { min-height: 46px; border: 0; border-radius: 13px; color: var(--green); background: var(--canvas-soft); font-weight: 650; cursor: pointer; }
.dialog-button.primary { color: var(--on-accent); background: var(--green); }
.dialog-button:disabled { opacity: .52; cursor: wait; }

.password-field { display: grid; gap: 7px; margin-top: 16px; color: var(--muted); font-size: 12px; }
.password-field input {
  height: 48px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 13px;
  color: var(--text);
  background: var(--surface-solid);
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 18px;
  letter-spacing: .08em;
}
.password-field input:focus { border-color: var(--green); box-shadow: 0 0 0 3px color-mix(in srgb, var(--green) 20%, transparent); }
#unlock-status.is-error { color: var(--danger); }

.guide-dialog { width: min(calc(100% - 24px), 720px); max-height: min(92dvh, 900px); }
.guide-content, .theme-content { padding: 20px; overflow: auto; }
.guide-intro { margin: 8px 0 18px; color: var(--muted); font-size: 14px; }
.guide-steps { display: grid; gap: 18px; margin: 0; padding: 0; list-style: none; counter-reset: guide-step; }
.guide-steps > li { counter-increment: guide-step; padding-top: 18px; border-top: 1px solid var(--line); }
.guide-copy b { display: block; font-size: 15px; }
.guide-copy b::before { content: counter(guide-step) ". "; color: var(--green-deep); }
.guide-copy p { margin: 7px 0 0; color: var(--muted); font-size: 13px; line-height: 1.65; }
.theme-dialog { width: min(calc(100% - 28px), 470px); }
.palette-grid { display: grid; gap: 9px; margin-top: 18px; }
.palette-grid > button { min-height: 64px; display: grid; grid-template-columns: 78px 1fr; align-items: center; gap: 12px; padding: 9px 12px; border: 1px solid var(--line); border-radius: 15px; color: var(--text); background: var(--surface-solid); text-align: left; cursor: pointer; }
.palette-grid > button[aria-pressed="true"] { border-color: var(--green); box-shadow: 0 0 0 3px color-mix(in srgb, var(--green) 20%, transparent); }
.palette-grid b, .palette-grid small { display: block; }
.palette-grid small { margin-top: 3px; color: var(--muted); }
.palette-swatches { display: flex; align-items: center; }
.palette-swatches i { width: 29px; height: 29px; display: block; margin-right: -7px; border: 2px solid var(--surface-solid); border-radius: 50%; box-shadow: 0 1px 3px rgba(0,0,0,.15); }
.palette-swatches.silver i:nth-child(1) { background: #171819; }
.palette-swatches.silver i:nth-child(2) { background: #f7f7f5; }
.palette-swatches.silver i:nth-child(3) { background: #92979c; }
.palette-swatches.gold i:nth-child(1) { background: #18150f; }
.palette-swatches.gold i:nth-child(2) { background: #fffaf0; }
.palette-swatches.gold i:nth-child(3) { background: #c89a3a; }
.palette-swatches.custom i:nth-child(1) { background: #6f63b6; }
.palette-swatches.custom i:nth-child(2) { background: #d76a93; }
.palette-swatches.custom i:nth-child(3) { background: #4b9e98; }
.color-picker { min-height: 64px; display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-top: 12px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 15px; background: var(--canvas-soft); }
.color-picker span, .color-picker b, .color-picker small { display: block; }
.color-picker small { margin-top: 3px; color: var(--muted); font-size: 11px; }
.color-picker input { width: 48px; height: 44px; flex: 0 0 auto; padding: 3px; border: 1px solid var(--line); border-radius: 11px; background: var(--surface-solid); cursor: pointer; }
.theme-footnote { margin: 13px 2px 0; color: var(--muted); font-size: 12px; line-height: 1.55; }

.contact-dialog { width: min(calc(100% - 28px), 430px); max-height: min(90dvh, 690px); }
.contact-content { padding: 20px; overflow: auto; }
.dialog-title-row { display: flex; align-items: start; justify-content: space-between; gap: 15px; }
.dialog-title-row small { color: var(--green); font-size: 11px; font-weight: 700; }
.dialog-title-row h2 { margin-top: 4px; font-size: 20px; }
.close-button { width: 44px; height: 44px; margin: -8px -8px 0 0; border: 0; border-radius: 50%; color: var(--muted); background: var(--canvas-soft); font-size: 26px; line-height: 1; cursor: pointer; }
.contact-links { display: grid; gap: 8px; margin: 18px 0; }
.contact-links a { min-height: 56px; display: grid; grid-template-columns: 42px 1fr 15px; align-items: center; gap: 7px; padding: 8px 13px; border-radius: 14px; color: var(--green-deep); background: var(--green-soft); text-decoration: none; }
.contact-links small { color: var(--muted); }
.contact-links strong { overflow-wrap: anywhere; font-size: 15px; }
.contact-links span { font-size: 24px; }
.qr-section { padding-top: 16px; border-top: 1px solid var(--line); }
.qr-section h3 { margin: 0 0 10px; font-size: 15px; }
.qr-section img { display: block; width: 100%; height: auto; max-height: 390px; object-fit: contain; border-radius: 16px; background: white; }
.qr-section p { margin: 9px 0 0; color: var(--muted); font-size: 12px; text-align: center; }

.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

.record-actions-card { padding: 20px; }
.compact-heading { margin-bottom: 14px; }
.record-note-field { display: grid; gap: 7px; color: var(--muted); font-size: 12px; }
.record-note-field input,
.history-search input,
.admin-inline-field input,
.new-user-form input,
.admin-credential-form input,
.template-content input {
  height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--text);
  background: var(--surface-solid);
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 0;
}
.record-note-field input:focus,
.history-search input:focus,
.admin-inline-field input:focus,
.new-user-form input:focus,
.admin-credential-form input:focus,
.template-content input:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--green) 20%, transparent);
}

.record-action-buttons { display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px; margin-top: 12px; }
.action-button {
  min-height: 44px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--green-deep);
  background: var(--surface-solid);
  font-weight: 700;
  cursor: pointer;
}
.action-button.primary { border-color: transparent; color: var(--on-accent); background: var(--green); }
.action-button:disabled, .text-button:disabled { opacity: .45; cursor: not-allowed; }
.inline-status { min-height: 1.35em; margin: 10px 1px 0; color: var(--muted); font-size: 12px; line-height: 1.45; }
.inline-status:empty { margin-top: 0; }
.inline-status.is-error { color: var(--danger); }

.records-card { overflow: visible; }
.records-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: 7px;
  border-bottom: 1px solid var(--line);
  border-radius: var(--radius-card) var(--radius-card) 0 0;
  background: color-mix(in srgb, var(--canvas-soft) 72%, transparent);
}
.records-tabs button {
  min-height: 44px;
  border: 0;
  border-radius: 14px;
  color: var(--muted);
  background: transparent;
  font-weight: 700;
  cursor: pointer;
}
.records-tabs button[aria-selected="true"] { color: var(--green-deep); background: var(--surface-solid); box-shadow: 0 2px 10px rgba(0,0,0,.06); }
.count-badge { min-width: 21px; height: 21px; display: inline-grid; place-items: center; margin-left: 5px; padding: 0 6px; border-radius: 99px; color: var(--on-accent); background: var(--green); font: 700 11px/1 ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; }
.ledger-status { min-height: 1.35em; margin: 11px 18px 0; color: var(--muted); font-size: 12px; line-height: 1.45; }
.ledger-status:empty { min-height: 0; margin-top: 0; }
.ledger-status.is-error { color: var(--danger); }
#history-panel, #comparison-panel { padding: 16px 18px 19px; }
.history-search { display: block; margin-bottom: 13px; }
.history-search input { width: 100%; }
.records-list { display: grid; }
.record-row, .comparison-row { padding: 15px 2px; border-top: 1px solid var(--line); }
.record-row:first-child, .comparison-row:first-child { padding-top: 2px; border-top: 0; }
.record-row-heading { display: flex; align-items: start; justify-content: space-between; gap: 16px; }
.record-row-heading h3 { margin: 4px 0 0; font-size: 15px; font-weight: 700; overflow-wrap: anywhere; }
.record-time, .comparison-index { color: var(--muted); font: 600 11px/1.35 ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; }
.basis-label { flex: 0 0 auto; padding: 5px 8px; border-radius: 99px; color: var(--green-deep); background: var(--green-soft); font-size: 10px; font-weight: 700; }
.record-metrics { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
.record-metric { padding: 9px 10px; border: 1px solid var(--line); border-radius: 11px; background: color-mix(in srgb, var(--surface-solid) 54%, transparent); }
.record-metric small, .record-metric strong { display: block; }
.record-metric small { color: var(--muted); font-size: 10px; }
.record-metric strong { margin-top: 4px; font: 700 14px/1.2 ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; }
.record-row-actions, .admin-row-actions, .template-row-actions { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 8px; }
.text-button { min-height: 35px; padding: 0 9px; border: 0; border-radius: 9px; color: var(--green-deep); background: var(--green-soft); font-size: 12px; font-weight: 700; cursor: pointer; }
.text-button.danger { color: var(--danger); background: color-mix(in srgb, var(--danger) 9%, transparent); }
.empty-state { margin: 0; padding: 25px 10px; color: var(--muted); font-size: 13px; text-align: center; }
.load-more-button { width: 100%; min-height: 42px; margin-top: 10px; border: 1px solid var(--line); border-radius: 12px; color: var(--green-deep); background: transparent; font-weight: 700; cursor: pointer; }
.comparison-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 9px; }
.comparison-toolbar p { margin: 0; color: var(--muted); font-size: 12px; }
.price-delta { margin-top: 12px; }
.price-delta-label { display: flex; justify-content: space-between; gap: 10px; color: var(--muted); font-size: 10px; }
.price-delta-label strong { color: var(--cotton-gold); font: 700 11px/1 ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; }
.price-delta-track { position: relative; height: 4px; margin-top: 8px; border-radius: 99px; background: color-mix(in srgb, var(--cotton-gold) 23%, var(--canvas-soft)); }
.price-delta-track::before, .price-delta-track::after { content: ""; position: absolute; top: -2px; width: 1px; height: 8px; background: color-mix(in srgb, var(--cotton-gold) 55%, transparent); }
.price-delta-track::before { left: 0; }
.price-delta-track::after { right: 0; }
.price-delta-track i { position: absolute; top: 50%; width: 11px; height: 11px; border: 2px solid var(--surface-solid); border-radius: 50%; background: var(--cotton-gold); box-shadow: 0 1px 5px color-mix(in srgb, var(--cotton-gold) 42%, transparent); transform: translate(-50%, -50%); }

.share-dialog { width: min(calc(100% - 32px), 620px); max-height: min(88dvh, 760px); }
.share-dialog-layout { display: grid; grid-template-rows: auto minmax(120px, 1fr) auto auto; max-height: min(88dvh, 760px); padding: 20px; }
.share-preview { min-height: 180px; max-height: 48dvh; margin: 17px 0 0; padding: 16px; overflow: auto; border: 1px solid var(--line); border-radius: 14px; color: var(--text); background: var(--surface-solid); font: 600 14px/1.75 ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; white-space: pre-wrap; overflow-wrap: anywhere; }
.share-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; padding-top: 12px; background: inherit; }

.admin-dialog { width: min(calc(100% - 32px), 900px); max-height: 90dvh; }
.admin-layout { max-height: 90dvh; padding: 22px; overflow: auto; }
.admin-title-row { align-items: center; }
.admin-note { margin: 10px 0 0; color: var(--muted); font-size: 12px; line-height: 1.6; }
.admin-section { margin-top: 22px; padding-top: 20px; border-top: 1px solid var(--line); }
.admin-section[aria-busy="true"] { cursor: progress; }
.admin-section[aria-busy="true"] input,
.admin-section[aria-busy="true"] button { opacity: .55; }
.admin-section-heading { display: flex; justify-content: space-between; gap: 14px; }
.admin-section-heading h3 { margin: 0; font-size: 16px; }
.admin-section-heading p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.new-user-form { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto; align-items: end; gap: 9px; margin-top: 14px; }
.admin-credential-form { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); align-items: end; gap: 9px; margin-top: 14px; }
.admin-credential-form button { grid-column: 1 / -1; justify-self: start; }
.new-user-form label, .admin-credential-form label, .admin-inline-field { display: grid; gap: 6px; color: var(--muted); font-size: 11px; }
.admin-user-list, .template-list { display: grid; gap: 10px; margin-top: 13px; }
.admin-user-row { display: grid; grid-template-columns: auto minmax(130px, 1fr) minmax(150px, 1fr); align-items: end; gap: 9px 12px; padding: 13px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface-solid); }
.user-state { align-self: center; padding: 5px 8px; border-radius: 99px; font-size: 10px; font-weight: 700; }
.user-state.enabled { color: var(--green-deep); background: var(--green-soft); }
.user-state.disabled { color: var(--muted); background: var(--canvas-soft); }
.admin-row-actions { grid-column: 2 / -1; margin-top: 0; }
.template-heading { align-items: end; }
.template-add-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.template-row { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 12px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 13px; background: var(--surface-solid); }
.template-visible { display: grid; justify-items: center; gap: 4px; color: var(--muted); font-size: 10px; }
.template-visible input { width: 18px; height: 18px; accent-color: var(--green); }
.template-content { min-width: 0; }
.template-content small, .template-content strong { display: block; }
.template-content strong { margin-top: 3px; font-size: 13px; overflow-wrap: anywhere; }
.template-content input { width: 100%; margin-top: 5px; }
.template-type { color: var(--muted); font-size: 10px; }
.template-row-actions { justify-content: flex-end; margin: 0; }

:focus-visible { outline: 3px solid color-mix(in srgb, var(--green) 38%, transparent); outline-offset: 2px; }

@media (min-width: 780px) {
  .app-shell { padding-top: calc(30px + env(safe-area-inset-top)); }
  .app-header { margin-bottom: 22px; }
  .price-card { padding: 24px 21px 20px; }
  .parameter-card { padding: 21px; }
}

@media (max-width: 640px) {
  .app-header { grid-template-columns: 44px 1fr; }
  .header-actions { grid-column: 1 / -1; width: 100%; margin-top: -4px; }
  .header-actions .plain-button { padding-inline: 7px; font-size: 13px; }
  .record-action-buttons, .new-user-form, .admin-credential-form { grid-template-columns: 1fr; }
  .record-metrics { grid-template-columns: 1fr; }
  .admin-user-row { grid-template-columns: 1fr; align-items: stretch; }
  .admin-row-actions { grid-column: auto; }
  .template-row { grid-template-columns: auto minmax(0, 1fr); }
  .template-row-actions { grid-column: 2; justify-content: flex-start; }
}

@media (max-width: 375px) {
  .app-shell { padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(12px, env(safe-area-inset-right)); }
  .app-header { grid-template-columns: 44px 1fr; gap: 9px; }
  .title-stack h1 { font-size: 20px; }
  .price-card { padding-inline: 12px; }
  .bridge-symbol { width: 34px; }
  .price-bridge { grid-template-columns: minmax(0, 1fr) 34px minmax(0, 1fr); }
  .input-shell { padding-inline: 8px; }
}

@media (prefers-color-scheme: dark) {
  :root {
    --canvas: #0e0f10;
    --canvas-soft: #242629;
    --surface: rgba(29, 31, 33, .9);
    --surface-solid: #2b2d30;
    --text: #f5f5f3;
    --muted: #a4a7aa;
    --line: rgba(235, 238, 240, .14);
    --green: #c4c8cc;
    --green-deep: #f0f2f3;
    --green-soft: #2b2e31;
    --brown: #8e9398;
    --cotton-gold: #d4ad59;
    --cotton-gold-soft: #392f1d;
    --on-accent: #171819;
    --danger: #ff6b63;
    --shadow: 0 18px 50px rgba(0,0,0,.24), 0 1px rgba(255,255,255,.03);
  }
  .card { border-color: rgba(255,255,255,.05); }
  .input-shell, .compact-input { background: rgba(255,255,255,.025); }
  .sheet-dialog { background: rgba(31, 33, 35, .97); }
  :root[data-palette="gold"] {
    --green: #d6b25f;
    --green-deep: #f3d990;
    --green-soft: #342c1e;
    --brown: #b58b42;
    --on-accent: #211708;
  }
}

/* Query-only preview hook used for deterministic visual QA; normal visits follow the system. */
:root[data-theme="dark"] {
  --canvas: #0e0f10;
  --canvas-soft: #242629;
  --surface: rgba(29, 31, 33, .9);
  --surface-solid: #2b2d30;
  --text: #f5f5f3;
  --muted: #a4a7aa;
  --line: rgba(235, 238, 240, .14);
  --green: #c4c8cc;
  --green-deep: #f0f2f3;
  --green-soft: #2b2e31;
  --brown: #8e9398;
  --cotton-gold: #d4ad59;
  --cotton-gold-soft: #392f1d;
  --on-accent: #171819;
  --danger: #ff6b63;
  --shadow: 0 18px 50px rgba(0,0,0,.24), 0 1px rgba(255,255,255,.03);
  color-scheme: dark;
}
:root[data-theme="dark"] .card { border-color: rgba(255,255,255,.05); }
:root[data-theme="dark"] .input-shell,
:root[data-theme="dark"] .compact-input { background: rgba(255,255,255,.025); }
:root[data-theme="dark"] .sheet-dialog { background: rgba(31, 33, 35, .97); }

:root[data-theme="light"] {
  --canvas: #f4f4f3;
  --canvas-soft: #e7e8e9;
  --surface: rgba(255, 255, 255, 0.84);
  --surface-solid: #ffffff;
  --text: #1c1d1f;
  --muted: #6d7175;
  --line: rgba(35, 38, 41, 0.13);
  --green: #595e63;
  --green-deep: #2e3134;
  --green-soft: #e3e5e7;
  --brown: #777d82;
  --cotton-gold: #b1842d;
  --cotton-gold-soft: #f2e7cc;
  --on-accent: #ffffff;
  --danger: #d0372f;
  --shadow: 0 12px 42px rgba(26, 48, 33, 0.08), 0 1px 2px rgba(26, 48, 33, 0.08);
  color-scheme: light;
}
:root[data-theme="light"] .card { border-color: rgba(255,255,255,.66); }
:root[data-theme="light"] .input-shell,
:root[data-theme="light"] .compact-input { background: rgba(255,255,255,.3); }
:root[data-theme="light"] .sheet-dialog { background: rgba(250, 251, 249, .96); }

:root[data-palette="gold"] {
  --green: #9a701c;
  --green-deep: #6b4b0b;
  --green-soft: #f1e6ca;
  --brown: #785b26;
  --on-accent: #ffffff;
}

:root[data-theme="dark"][data-palette="gold"] {
  --green: #d6b25f;
  --green-deep: #f3d990;
  --green-soft: #342c1e;
  --brown: #b58b42;
  --on-accent: #211708;
}

:root[data-theme="light"][data-palette="gold"] {
  --green: #9a701c;
  --green-deep: #6b4b0b;
  --green-soft: #f1e6ca;
  --brown: #785b26;
  --on-accent: #ffffff;
}

:root[data-palette="custom"] {
  --green-deep: color-mix(in srgb, var(--green) 60%, var(--text));
  --green-soft: color-mix(in srgb, var(--green) 18%, var(--surface-solid));
  --brown: color-mix(in srgb, var(--green) 62%, #7b5d39);
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; }
}
