:root {
  color-scheme: light;
  --ink: #102a43;
  --muted: #627d98;
  --line: #d9e2ec;
  --soft: #f0f4f8;
  --panel: #ffffff;
  --primary: #0f766e;
  --primary-dark: #115e59;
  --primary-soft: #ccfbf1;
  --accent: #d97706;
  --danger: #b91c1c;
  --danger-soft: #fee2e2;
  --shadow: 0 18px 50px rgba(16, 42, 67, 0.09);
  --radius: 22px;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: #f8fafc; }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(20, 184, 166, .09), transparent 34rem),
    linear-gradient(180deg, #f8fafc 0%, #eef4f7 100%);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
}

a { color: var(--primary-dark); text-underline-offset: 3px; }
a:hover { color: var(--primary); }
button, input, textarea, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
h1, h2, h3, p { margin-top: 0; }
h1 { font-size: clamp(2rem, 4vw, 3.6rem); line-height: 1.05; letter-spacing: -.045em; margin-bottom: .65rem; }
h2 { font-size: clamp(1.35rem, 2.3vw, 2rem); line-height: 1.15; letter-spacing: -.025em; }
h3 { line-height: 1.2; }
code { padding: .14rem .38rem; border-radius: .45rem; background: #e2e8f0; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .9em; }

.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: .9rem clamp(1rem, 4vw, 3.5rem);
  border-bottom: 1px solid rgba(217, 226, 236, .85);
  background: rgba(248, 250, 252, .92);
  backdrop-filter: blur(16px);
}

.brand { display: inline-flex; align-items: center; gap: .65rem; color: var(--ink); font-weight: 900; text-decoration: none; letter-spacing: -.02em; }
.brand-mark { display: grid; place-items: center; width: 2.25rem; height: 2.25rem; border-radius: .75rem; color: white; background: var(--primary); font-size: .8rem; box-shadow: 0 8px 20px rgba(15, 118, 110, .22); }
.main-nav { display: flex; align-items: center; gap: .35rem; }
.main-nav a, .link-button { border: 0; border-radius: 999px; padding: .6rem .85rem; color: var(--muted); background: transparent; text-decoration: none; cursor: pointer; }
.main-nav a:hover, .main-nav a.active, .link-button:hover { color: var(--ink); background: white; }
.inline-form { display: inline; margin: 0; }

.page-shell { width: min(1180px, calc(100% - 2rem)); margin: 0 auto; padding: 2rem 0 4rem; }
.narrow-shell { max-width: 850px; }
.hero-panel, .form-hero {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 2rem;
  margin-bottom: 2.5rem;
  padding: clamp(1.5rem, 4vw, 3rem);
  border: 1px solid rgba(204, 251, 241, .8);
  border-radius: calc(var(--radius) + 6px);
  color: #ecfeff;
  background: linear-gradient(135deg, #134e4a, #0f766e 65%, #0d9488);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.hero-panel > div:first-child, .form-hero > div:first-child { max-width: 760px; }
.hero-panel p, .form-hero p { color: rgba(236, 254, 255, .84); font-size: 1.05rem; }
.hero-panel.simple { align-items: center; }
.privacy-chip { flex: 0 0 auto; padding: .75rem 1rem; border: 1px solid rgba(255,255,255,.2); border-radius: 999px; background: rgba(255,255,255,.1); font-weight: 800; }
.privacy-chip span { color: #5eead4; }
.eyebrow { margin-bottom: .45rem; color: var(--primary); font-size: .76rem; font-weight: 900; letter-spacing: .16em; text-transform: uppercase; }
.hero-panel .eyebrow, .form-hero .eyebrow { color: #99f6e4; }
.muted { color: var(--muted); }
.compact { margin: .55rem 0 0; font-size: .88rem; }

.section-heading { display: flex; align-items: end; justify-content: space-between; gap: 1rem; margin: 0 0 1rem; }
.section-heading h2 { margin-bottom: 0; }
.form-card-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }
.form-card { position: relative; display: flex; min-height: 280px; flex-direction: column; padding: 1.45rem; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); box-shadow: 0 10px 30px rgba(16, 42, 67, .055); }
.form-card-number { color: #94a3b8; font-size: .78rem; font-weight: 900; letter-spacing: .14em; }
.form-card h3 { margin: 1.8rem 0 .7rem; font-size: 1.35rem; }
.form-card p { flex: 1; color: var(--muted); }
.entries-section { margin-top: 3.2rem; }
.count-pill { padding: .45rem .75rem; border-radius: 999px; color: var(--primary-dark); background: var(--primary-soft); font-size: .85rem; font-weight: 800; }
.entry-list { display: grid; gap: .75rem; }
.entry-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 1.15rem 1.25rem; border: 1px solid var(--line); border-radius: 18px; background: white; }
.entry-row h3 { margin: .1rem 0 .3rem; }
.entry-row h3 a { color: var(--ink); text-decoration: none; }
.entry-form { margin-bottom: 0; color: var(--primary); font-size: .78rem; font-weight: 900; text-transform: uppercase; letter-spacing: .1em; }
.entry-actions, .toolbar, .import-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: .55rem; }
.toolbar.left { justify-content: flex-start; }
.empty-state { padding: 3rem; border: 1px dashed #b8c5d1; border-radius: var(--radius); text-align: center; background: rgba(255,255,255,.6); }

.button { display: inline-flex; align-items: center; justify-content: center; min-height: 2.65rem; padding: .68rem 1rem; border: 1px solid transparent; border-radius: .85rem; font-weight: 850; line-height: 1; text-decoration: none; cursor: pointer; transition: transform .12s ease, box-shadow .12s ease, background .12s ease; }
.button:hover { transform: translateY(-1px); }
.button.primary { color: white; background: var(--primary); box-shadow: 0 8px 20px rgba(15, 118, 110, .18); }
.button.primary:hover { color: white; background: var(--primary-dark); }
.button.secondary { color: var(--ink); border-color: var(--line); background: white; }
.button.ghost { color: var(--primary-dark); border-color: #99d8d2; background: transparent; }
.button.danger { color: white; background: var(--danger); }
.button.wide { width: 100%; }
.button.large { min-height: 3.15rem; padding-inline: 1.35rem; }

.auth-shell { display: grid; min-height: calc(100vh - 70px); place-items: center; padding: 2rem 1rem; }
.auth-card { width: min(460px, 100%); padding: clamp(1.5rem, 5vw, 2.6rem); border: 1px solid var(--line); border-radius: 28px; background: white; box-shadow: var(--shadow); }
.auth-brand { margin-bottom: 2.4rem; }
.auth-card h1 { font-size: 2.6rem; }
.auth-switch { margin: 1.3rem 0 0; text-align: center; color: var(--muted); }
.stack-form { display: grid; gap: 1rem; }
.stack-form label, .field-group, .form-meta-card label { display: grid; gap: .42rem; font-weight: 760; }
input, textarea, select { width: 100%; min-height: 2.85rem; padding: .72rem .82rem; border: 1px solid #b8c5d1; border-radius: .72rem; color: var(--ink); background: white; outline: none; }
textarea { resize: vertical; }
input:focus, textarea:focus, select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(15, 118, 110, .12); }
input:disabled, textarea:disabled, select:disabled { color: #243b53; border-color: #d9e2ec; background: #f8fafc; opacity: 1; }
.help { color: var(--muted); font-size: .78rem; font-weight: 500; }
.alert { padding: .8rem 1rem; border-radius: .75rem; margin-bottom: 1rem; }
.alert.error { color: #7f1d1d; border: 1px solid #fecaca; background: var(--danger-soft); }

.form-hero { align-items: center; margin-bottom: 1rem; }
.form-hero .toolbar .button { border-color: rgba(255,255,255,.28); color: white; }
.form-hero .toolbar .secondary { color: var(--ink); }
.import-panel, .form-meta-card, .form-section, .content-card { padding: 1.35rem; border: 1px solid var(--line); border-radius: var(--radius); background: white; box-shadow: 0 8px 24px rgba(16, 42, 67, .045); }
.import-panel { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 1rem; align-items: center; margin-bottom: 1rem; }
.import-panel h2 { margin-bottom: .35rem; }
.csv-box { grid-column: 1 / -1; padding-top: 1rem; border-top: 1px solid var(--line); }
.csv-box label { display: block; margin-bottom: .4rem; font-weight: 800; }
.csv-box textarea { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .84rem; }

.csv-action-buttons { margin-top: .8rem; }
.csv-action-buttons .button { flex: 0 1 auto; }
.csv-append-help { margin: .8rem 0 0; line-height: 1.55; }
@media (max-width: 520px) {
  .csv-action-buttons { display: grid; grid-template-columns: 1fr; width: 100%; }
  .csv-action-buttons .button { width: 100%; }
}
.hidden { display: none !important; }
.form-container { display: grid; gap: 1rem; }
.form-meta-card { display: flex; justify-content: space-between; align-items: end; gap: 1rem; }
.form-meta-card label { width: min(520px, 100%); }
#dynamic-form { display: grid; gap: 1rem; }
.form-section-heading { margin-bottom: 1.15rem; padding-bottom: .9rem; border-bottom: 1px solid var(--line); }
.form-section-heading h2 { margin-bottom: .25rem; }
.form-section-heading p { margin: 0; color: var(--muted); }
.fields-layout { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.field-textarea, .checkbox-group, .data-grid { grid-column: 1 / -1; }
.field-label { display: block; }
.field-select-text { align-content: start; }
.field-select-text .select-text-preset { margin-bottom: .05rem; }
.checkbox-group { margin: 0; padding: .9rem; border: 1px solid var(--line); border-radius: .85rem; }
.checkbox-group legend { padding: 0 .35rem; font-weight: 800; }
.check-option { display: inline-flex; width: auto; align-items: center; gap: .48rem; margin: .35rem .85rem .35rem 0; font-weight: 600; }
.check-option input { width: 1.1rem; min-height: 1.1rem; margin: 0; accent-color: var(--primary); }
.strong-check { font-weight: 800; }
.data-grid { display: grid; gap: .8rem; }
.grid-row-card { border: 1px solid var(--line); border-radius: 16px; background: #fbfdfe; overflow: hidden; }
.grid-row-heading { padding: .9rem 1rem; border-bottom: 1px solid var(--line); background: var(--soft); }
.grid-row-heading h3 { margin: 0; font-size: 1.02rem; }
.grid-row-heading p { margin: .18rem 0 0; color: var(--muted); font-size: .84rem; }
.grid-row-fields { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .8rem; padding: 1rem; }
.grid-row-fields .field-textarea { grid-column: span 2; }
.sticky-save { position: sticky; bottom: 1rem; display: flex; align-items: center; justify-content: flex-end; gap: 1rem; padding: .9rem; border: 1px solid rgba(153, 216, 210, .9); border-radius: 16px; background: rgba(240, 253, 250, .96); box-shadow: var(--shadow); backdrop-filter: blur(12px); }
.status-text { margin: 0; color: var(--muted); font-size: .9rem; }
.success-text { color: #166534; }
.error-text { color: var(--danger); }
.danger-zone { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 1.2rem; border: 1px solid #fecaca; border-radius: var(--radius); background: #fff7f7; }
.danger-zone h2 { margin-bottom: .25rem; font-size: 1.2rem; }
.danger-zone p { margin: 0; color: #7f1d1d; }
.danger-zone.block { display: grid; margin-top: 1rem; }
.compact-form { max-width: 460px; }
.prose h2 { margin-top: 1.8rem; }
.prose h2:first-child { margin-top: 0; }
.prose p { color: #486581; }
.site-footer { padding: 1.5rem; color: #829ab1; text-align: center; font-size: .78rem; }
.site-footer p { margin: 0; }
.error-shell { display: grid; min-height: 75vh; place-items: center; align-content: center; padding: 2rem; text-align: center; }
.error-code { color: var(--primary); font-size: 5rem; font-weight: 950; letter-spacing: -.08em; }
.clipboard-fallback { position: fixed; left: -9999px; top: -9999px; }

@media (max-width: 920px) {
  .form-card-grid { grid-template-columns: 1fr; }
  .form-card { min-height: 220px; }
  .grid-row-fields { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .import-panel { grid-template-columns: 1fr; }
  .import-actions { justify-content: flex-start; }
}

@media (max-width: 680px) {
  .site-header { align-items: flex-start; }
  .main-nav { flex-wrap: wrap; justify-content: flex-end; }
  .main-nav a, .link-button { padding: .45rem .65rem; font-size: .85rem; }
  .page-shell { width: min(100% - 1rem, 1180px); padding-top: .7rem; }
  .hero-panel, .form-hero { align-items: flex-start; flex-direction: column; padding: 1.4rem; }
  .hero-panel .privacy-chip { align-self: flex-start; }
  .fields-layout, .grid-row-fields { grid-template-columns: 1fr; }
  .grid-row-fields .field-textarea { grid-column: auto; }
  .form-meta-card, .entry-row, .danger-zone { align-items: stretch; flex-direction: column; }
  .entry-actions { justify-content: flex-start; }
  .sticky-save { align-items: stretch; flex-direction: column; }
  .sticky-save .button { width: 100%; }
}

.repeatable-group { grid-column: 1 / -1; display: grid; gap: .85rem; }
.repeatable-list { display: grid; gap: .85rem; }
.repeatable-card { border: 1px solid var(--line); border-radius: 16px; background: #fbfdfe; overflow: hidden; }
.repeatable-card-heading { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .8rem 1rem; border-bottom: 1px solid var(--line); background: var(--soft); }
.repeatable-card-heading h3 { margin: 0; font-size: 1.02rem; }
.repeatable-item-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .8rem; padding: 1rem; }
.repeatable-item-fields .field-textarea { grid-column: 1 / -1; }
.repeatable-actions { display: flex; justify-content: flex-start; }
.compact-button { min-height: 2.15rem; padding: .5rem .72rem; border-radius: .7rem; font-size: .82rem; }
.entry-actions .inline-form { display: inline-flex; }

@media (max-width: 680px) {
  .repeatable-card-heading { align-items: stretch; flex-direction: column; }
  .repeatable-item-fields { grid-template-columns: 1fr; }
  .repeatable-item-fields .field-textarea { grid-column: auto; }
}

.entry-filters {
  display: grid;
  grid-template-columns: minmax(240px, 2fr) minmax(180px, 1fr) minmax(170px, 1fr) auto;
  gap: .8rem;
  align-items: end;
  margin-bottom: 1rem;
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: white;
}
.entry-filters label { display: grid; gap: .4rem; font-weight: 760; }
.entry-filters label > span { color: var(--muted); font-size: .82rem; }
.filter-actions { display: flex; gap: .55rem; align-items: center; }

@media (max-width: 920px) {
  .entry-filters { grid-template-columns: 1fr 1fr; }
  .filter-search { grid-column: 1 / -1; }
}

@media (max-width: 680px) {
  .entry-filters { grid-template-columns: 1fr; }
  .filter-search { grid-column: auto; }
  .filter-actions { align-items: stretch; flex-direction: column; }
  .filter-actions .button { width: 100%; }
}

.summary-panel {
  display: grid;
  gap: 1rem;
  padding: 1.35rem;
  border: 1px solid #99d8d2;
  border-radius: var(--radius);
  background: #f0fdfa;
  box-shadow: 0 8px 24px rgba(16, 42, 67, .045);
}
.summary-panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.summary-panel-heading h2 { margin-bottom: .3rem; }
.summary-panel-heading p { margin-bottom: 0; }
.summary-result { display: grid; gap: 1rem; }
.summary-preview {
  padding: 1.1rem;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: white;
}
.summary-preview h2 { margin-bottom: 1rem; font-size: 1.55rem; }
.summary-preview h3 { margin: 1.2rem 0 .55rem; color: var(--primary-dark); font-size: 1.08rem; }
.summary-preview p { margin: .35rem 0; color: #334e68; white-space: pre-wrap; }
.summary-preview ul { margin: .35rem 0 .85rem 1.15rem; padding: 0; }
.summary-preview li { margin: .32rem 0; color: #334e68; }
.summary-downloads { padding-top: .25rem; }
.button:disabled { cursor: wait; opacity: .65; transform: none; }

@media (max-width: 680px) {
  .summary-panel-heading { align-items: stretch; flex-direction: column; }
  .summary-panel-heading .button { width: 100%; }
  .summary-downloads { align-items: stretch; flex-direction: column; }
  .summary-downloads .button { width: 100%; }
}

/* Structured database summaries */
.summary-table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 18px; background: white; }
.summary-table { width: 100%; border-collapse: collapse; min-width: 980px; }
.summary-table th, .summary-table td { padding: .9rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.summary-table th { color: var(--muted); background: var(--soft); font-size: .78rem; letter-spacing: .04em; text-transform: uppercase; }
.summary-table tbody tr:last-child td { border-bottom: 0; }
.summary-name-link { color: var(--ink); font-weight: 830; }
.linked-entry-list { display: grid; gap: .25rem; }
.linked-entry-list a { color: var(--primary-dark); font-size: .86rem; }
.summary-row-actions { flex-wrap: wrap; min-width: 270px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

.summary-editor-card { display: grid; gap: 1.4rem; }
.summary-editor-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
#summary-entry-ids { min-height: 8rem; }
.editable-summary-section { display: grid; gap: .8rem; padding-top: 1rem; border-top: 1px solid var(--line); }
.compact-heading { margin-bottom: 0; }
.summary-item-editor { display: grid; gap: .75rem; }
.summary-item-row {
  display: grid;
  grid-template-columns: minmax(130px, .7fr) minmax(180px, 1fr) minmax(260px, 2fr) auto;
  gap: .65rem;
  align-items: start;
  padding: .75rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fbfdfe;
}
.summary-item-row textarea { min-height: 3.1rem; }
.summary-item-remove { margin-top: .2rem; }
.summary-items-empty { margin: 0; padding: .9rem; border: 1px dashed var(--line); border-radius: 12px; }
.summary-system-meta { display: flex; flex-wrap: wrap; gap: 1.2rem; padding: .8rem 1rem; border-radius: 12px; background: var(--soft); }
.summary-system-meta p { margin: 0; color: var(--muted); font-size: .86rem; }

@media (max-width: 920px) {
  .summary-item-row { grid-template-columns: 1fr 1fr; }
  .summary-item-value { grid-column: 1 / -1; }
}

@media (max-width: 680px) {
  .summary-editor-grid, .summary-item-row { grid-template-columns: 1fr; }
  .summary-item-value { grid-column: auto; }
  .summary-table { min-width: 0; }
  .summary-table thead { display: none; }
  .summary-table, .summary-table tbody, .summary-table tr, .summary-table td { display: block; width: 100%; }
  .summary-table tr { padding: .8rem; border-bottom: 1px solid var(--line); }
  .summary-table tbody tr:last-child { border-bottom: 0; }
  .summary-table td { display: grid; grid-template-columns: 110px 1fr; gap: .7rem; padding: .45rem 0; border: 0; }
  .summary-table td::before { content: attr(data-label); color: var(--muted); font-size: .75rem; font-weight: 800; text-transform: uppercase; }
  .summary-row-actions { min-width: 0; }
}

/* Database-entry summary builder */
.summary-builder { display: grid; gap: 1.25rem; }
.summary-form-source-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 1rem;
}
.summary-form-source-card {
  display: flex;
  min-height: 210px;
  flex-direction: column;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.1rem;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: white;
}
.summary-form-source-card h3 { margin-bottom: .45rem; }
.summary-form-source-card p { margin: 0; color: var(--muted); }
.summary-form-source-card.is-empty { background: #f8fafc; opacity: .76; }
.summary-source-card-footer { display: grid; gap: .7rem; align-items: start; }
.summary-source-card-footer .count-pill { justify-self: start; }
.summary-source-card-footer .button { width: 100%; }
.summary-form-source-card .button:disabled { cursor: not-allowed; }
.summary-source-workspace {
  display: grid;
  gap: 1rem;
  padding: 1.2rem;
  border: 1px solid #99d8d2;
  border-radius: 18px;
  background: #f0fdfa;
}
.summary-workspace-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}
.summary-workspace-heading h3 { margin-bottom: .35rem; }
.summary-entry-picker {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: .65rem;
  max-height: 430px;
  overflow: auto;
  padding: .25rem;
}
.summary-entry-option {
  display: flex;
  align-items: flex-start;
  gap: .7rem;
  padding: .8rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: white;
  cursor: pointer;
}
.summary-entry-option:hover { border-color: #7bc9c1; }
.summary-entry-option input { margin-top: .25rem; }
.summary-entry-option-text { display: grid; gap: .25rem; min-width: 0; }
.summary-entry-option-text strong { overflow-wrap: anywhere; }
.summary-entry-option-text small { color: var(--muted); line-height: 1.4; }
.summary-context-field { margin: 0; }
.summary-generate-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
.summary-generate-actions .status-text { margin: 0; }

@media (max-width: 680px) {
  .summary-workspace-heading, .summary-generate-actions { align-items: stretch; flex-direction: column; }
  .summary-workspace-heading .toolbar, .summary-generate-actions .button { width: 100%; }
  .summary-workspace-heading .toolbar .button { flex: 1; }
  .summary-entry-picker { grid-template-columns: 1fr; max-height: 520px; }
}

/* v1.6: keep saved-entry selectors compact without changing the click target. */
.summary-entry-option input[type="checkbox"] {
  width: .9rem;
  height: .9rem;
  min-width: .9rem;
  flex: 0 0 .9rem;
  margin: .2rem 0 0;
}


/* v1.8: selectable local summary model. */
.summary-model-field {
  margin: 0;
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: white;
}
.summary-model-field select { max-width: 100%; }

.all-data-export { display: grid; gap: .8rem; margin-bottom: 1rem; }
.all-data-export .section-heading { align-items: flex-start; margin-bottom: 0; }
.all-data-export .section-heading p:last-child { max-width: 760px; margin-bottom: 0; color: var(--muted); }
.all-data-export-actions { margin-top: .15rem; }


/* v1.8.4: compact, responsive per-form actions. */
.summary-form-source-card { min-width: 0; }
.summary-source-card-actions {
  display: grid;
  width: 100%;
  min-width: 0;
  grid-template-columns: minmax(0, .65fr) minmax(0, 1.35fr);
  gap: .5rem;
}
.summary-source-card-actions .button {
  width: 100%;
  min-width: 0;
  padding-inline: .65rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.form-export-workspace {
  display: grid;
  gap: 1rem;
  padding: 1.2rem;
  border: 1px solid #a9c7ef;
  border-radius: 18px;
  background: #f5f9ff;
}
.form-export-context-field { margin: 0; }
.form-export-actions .toolbar { flex-wrap: wrap; }
@media (max-width: 680px) {
  .summary-source-card-actions { grid-template-columns: minmax(0, .55fr) minmax(0, 1.45fr); }
  .form-export-actions { align-items: stretch; flex-direction: column; }
  .form-export-actions .toolbar, .form-export-actions .button { width: 100%; }
}

@media (max-width: 340px) {
  .summary-source-card-actions { grid-template-columns: 1fr; }
}


/* v1.9: installable Progressive Web App controls. */
.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;
}

.pwa-install-button {
  position: fixed;
  right: max(1rem, env(safe-area-inset-right));
  bottom: max(1rem, env(safe-area-inset-bottom));
  z-index: 40;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .45rem;
  min-height: 2.8rem;
  padding: .72rem 1rem;
  border: 1px solid rgba(255, 255, 255, .28);
  border-radius: 999px;
  color: white;
  background: var(--primary);
  box-shadow: 0 14px 34px rgba(15, 118, 110, .32);
  font-weight: 850;
  cursor: pointer;
}
.pwa-install-button:hover { background: var(--primary-dark); transform: translateY(-1px); }
.pwa-install-button:focus-visible { outline: 3px solid rgba(20, 184, 166, .32); outline-offset: 3px; }
.pwa-install-button:disabled { cursor: wait; opacity: .7; transform: none; }
.offline-card { text-align: left; }

@media (max-width: 480px) {
  .pwa-install-button {
    right: max(.65rem, env(safe-area-inset-right));
    bottom: max(.65rem, env(safe-area-inset-bottom));
    min-height: 2.55rem;
    padding: .62rem .85rem;
    font-size: .88rem;
  }
}

@media (display-mode: standalone) {
  .site-header {
    padding-top: calc(.9rem + env(safe-area-inset-top));
    padding-left: max(clamp(1rem, 4vw, 3.5rem), env(safe-area-inset-left));
    padding-right: max(clamp(1rem, 4vw, 3.5rem), env(safe-area-inset-right));
  }
  .site-footer { padding-bottom: calc(1.5rem + env(safe-area-inset-bottom)); }
  .pwa-install-button { display: none !important; }
}

/* v1.9.2: responsive, accessible mobile navigation. */
.brand { min-width: 0; }
.brand-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mobile-nav-toggle { display: none; }

@media (max-width: 760px) {
  .site-header {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: .65rem;
    padding: .7rem max(.8rem, env(safe-area-inset-right)) .7rem max(.8rem, env(safe-area-inset-left));
  }

  .brand { max-width: 100%; }

  .mobile-nav-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .5rem;
    min-width: 5rem;
    min-height: 2.7rem;
    padding: .55rem .75rem;
    border: 1px solid var(--line);
    border-radius: .8rem;
    color: var(--ink);
    background: white;
    box-shadow: 0 6px 16px rgba(16, 42, 67, .06);
    font-weight: 850;
    cursor: pointer;
  }

  .mobile-nav-toggle:hover { background: var(--soft); }
  .mobile-nav-toggle:focus-visible { outline: 3px solid rgba(15, 118, 110, .2); outline-offset: 2px; }
  .mobile-nav-toggle-icon { display: grid; width: 1.1rem; gap: .2rem; }
  .mobile-nav-toggle-icon span { display: block; width: 100%; height: 2px; border-radius: 999px; background: currentColor; transition: transform .16s ease, opacity .16s ease; }
  .mobile-nav-open .mobile-nav-toggle-icon span:nth-child(1) { transform: translateY(.4rem) rotate(45deg); }
  .mobile-nav-open .mobile-nav-toggle-icon span:nth-child(2) { opacity: 0; }
  .mobile-nav-open .mobile-nav-toggle-icon span:nth-child(3) { transform: translateY(-.4rem) rotate(-45deg); }

  .main-nav {
    grid-column: 1 / -1;
    display: none;
    width: 100%;
    max-height: min(70vh, 28rem);
    flex-direction: column;
    flex-wrap: nowrap;
    align-items: stretch;
    justify-content: flex-start;
    gap: .2rem;
    padding: .45rem;
    border: 1px solid var(--line);
    border-radius: 1rem;
    background: rgba(255, 255, 255, .98);
    box-shadow: 0 16px 35px rgba(16, 42, 67, .12);
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  .main-nav.is-open { display: flex; }
  .main-nav a, .main-nav .link-button {
    display: flex;
    width: 100%;
    min-height: 2.8rem;
    align-items: center;
    justify-content: flex-start;
    padding: .72rem .85rem;
    border-radius: .72rem;
    font-size: .95rem;
    text-align: left;
  }
  .main-nav a.active { color: var(--primary-dark); background: var(--primary-soft); }
  .main-nav .inline-form { display: block; width: 100%; }
  .main-nav .link-button { border: 0; }
}

@media (max-width: 480px) {
  .site-header { gap: .5rem; }
  .brand { gap: .5rem; font-size: .95rem; }
  .brand-mark { width: 2rem; height: 2rem; border-radius: .65rem; font-size: .72rem; }
  .mobile-nav-toggle { min-width: 4.75rem; min-height: 2.55rem; padding: .5rem .65rem; font-size: .88rem; }
  .main-nav { max-height: calc(100vh - 5.5rem - env(safe-area-inset-top)); border-radius: .85rem; }
}

@media (max-width: 340px) {
  .mobile-nav-toggle { min-width: 2.75rem; width: 2.75rem; padding-inline: .6rem; }
  .mobile-nav-toggle-label { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
}

@media (min-width: 761px) {
  .main-nav { display: flex !important; }
}

/* v2.0.1: settings, numeric PIN and WebAuthn device unlock. */
.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}
.app-lock-status-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
.credential-list { display: grid; gap: .75rem; }
.credential-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(17rem, auto);
  align-items: center;
  gap: 1rem;
  padding: .85rem;
  border: 1px solid var(--line);
  border-radius: .9rem;
  background: var(--soft);
}
.credential-row > div { min-width: 0; display: grid; gap: .2rem; }
.credential-row strong { overflow-wrap: anywhere; }
.credential-row span { color: var(--muted); font-size: .84rem; }
.credential-remove-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: .5rem;
}
.credential-remove-form input { min-width: 0; }
.button.compact { min-height: 2.45rem; padding: .55rem .75rem; }
.unlock-shell { padding-top: max(2rem, env(safe-area-inset-top)); }
.unlock-card { max-width: 30rem; }
.biometric-button { gap: .55rem; }
.unlock-divider {
  display: flex;
  align-items: center;
  gap: .75rem;
  color: var(--muted);
  font-size: .82rem;
  text-transform: uppercase;
  letter-spacing: .08em;
}
.unlock-divider::before,
.unlock-divider::after { content: ''; flex: 1; height: 1px; background: var(--line); }
.pin-input {
  text-align: center;
  letter-spacing: .45em;
  font-size: 1.35rem;
  font-variant-numeric: tabular-nums;
}
.unlock-logout-form { display: flex; justify-content: center; }
.form-status.success { color: #166534; }
.form-status.error { color: #b91c1c; }

html.app-lock-obscured { overflow: hidden; background: #0f172a; }
html.app-lock-obscured body { overflow: hidden; }
html.app-lock-obscured::before {
  content: 'Private Forms locked';
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: grid;
  place-items: center;
  padding: 2rem;
  color: white;
  background: #0f172a;
  font-size: 1.1rem;
  font-weight: 850;
  letter-spacing: .02em;
}
html.app-lock-obscured body { visibility: hidden !important; }
html.app-lock-obscured::before { visibility: visible !important; }

@media (max-width: 760px) {
  .settings-grid { grid-template-columns: 1fr; }
  .app-lock-status-card { align-items: stretch; flex-direction: column; }
  .app-lock-status-card form .button { width: 100%; }
  .credential-row { grid-template-columns: 1fr; }
  .credential-remove-form { grid-template-columns: 1fr auto; }
}

@media (max-width: 480px) {
  .credential-remove-form { grid-template-columns: 1fr; }
  .credential-remove-form .button { width: 100%; }
  .pin-input { letter-spacing: .32em; }
}

/* Calories and weight page */
.calories-hero { align-items: center; }
.calorie-form-grid,
.calorie-history-grid {
  display: grid;
  grid-template-columns: minmax(0, .85fr) minmax(0, 1.35fr);
  gap: 1rem;
  margin-top: 1rem;
}
.calorie-panel { align-content: start; }
.weight-comparison {
  padding: .85rem 1rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--soft);
  color: #334e68;
  font-weight: 720;
}
.weight-comparison.lower { border-color: #86d4c8; background: #ecfdf5; color: #0f766e; }
.weight-comparison.higher { border-color: #f3c98b; background: #fff7ed; color: #9a3412; }
.weight-comparison.same { border-color: #b8c7d9; background: #f8fafc; }
.ingredient-builder { display: grid; gap: .8rem; }
.ingredient-list { display: grid; gap: .8rem; }

.ingredient-builder-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: .5rem;
}
.recipe-row {
  border-color: #b9d8d3;
  background: #f8fffd;
}
.recipe-row .ingredient-row-heading {
  background: #eaf8f5;
}
.recipe-row-fields {
  grid-template-columns: minmax(220px, 2fr) repeat(3, minmax(130px, 1fr));
}
.recipe-suggestion strong { color: var(--primary-dark); }
.ingredient-row {
  overflow: visible;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fbfdfe;
}
.ingredient-row-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .8rem;
  padding: .7rem .85rem;
  border-bottom: 1px solid var(--line);
  background: var(--soft);
  border-radius: 16px 16px 0 0;
}
.ingredient-row-fields {
  display: grid;
  grid-template-columns: repeat(4, minmax(130px, 1fr));
  gap: .75rem;
  align-items: end;
  padding: .9rem;
}
.ingredient-row-fields label { position: relative; display: grid; gap: .4rem; font-weight: 760; }
.ingredient-measurement-fields select { width: 100%; }

.ingredient-row-fields label > span,
.ingredient-calculated > span { color: var(--muted); font-size: .8rem; }
.ingredient-name-field { z-index: 2; grid-column: 1 / -1; }
.measurement-detail-field[hidden] { display: none; }
.measurement-detail-field small { font-weight: 500; line-height: 1.35; }
.ingredient-suggestions {
  position: absolute;
  top: calc(100% + .35rem);
  left: 0;
  right: 0;
  z-index: 30;
  max-height: 260px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: white;
  box-shadow: var(--shadow);
}
.ingredient-suggestion {
  display: grid;
  width: 100%;
  gap: .12rem;
  padding: .7rem .8rem;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: white;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}
.ingredient-suggestion:last-child { border-bottom: 0; }
.ingredient-suggestion:hover,
.ingredient-suggestion:focus { background: var(--primary-soft); outline: none; }
.ingredient-suggestion span { color: var(--muted); font-size: .78rem; }
.ingredient-suggestion-status { padding: .75rem .8rem; color: var(--muted); font-size: .84rem; }
.error-text { color: var(--danger); }
.ingredient-calculated {
  display: grid;
  gap: .3rem;
  min-height: 44px;
  align-content: center;
  padding: .6rem .75rem;
  border-radius: 12px;
  background: var(--primary-soft);
}
.ingredient-equivalent { color: var(--muted); font-size: .72rem; line-height: 1.35; }
.calorie-total-row {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto;
  gap: .75rem;
  align-items: end;
}
.calorie-total-row label { display: grid; gap: .4rem; font-weight: 760; }
.weight-chart-card { margin-top: 1rem; }
.weight-chart-heading { align-items: start; }
.weight-chart-controls {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
  margin: .9rem 0 .7rem;
}
.weight-chart-control-group {
  min-width: 0;
  margin: 0;
  padding: .75rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--soft);
}
.weight-chart-control-group legend {
  padding: 0 .3rem;
  color: var(--muted);
  font-size: .8rem;
  font-weight: 800;
}
.segmented-control {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(86px, 1fr));
  gap: .4rem;
}
.segmented-button {
  min-height: 42px;
  padding: .55rem .65rem;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: white;
  color: var(--ink);
  font: inherit;
  font-size: .86rem;
  font-weight: 760;
  cursor: pointer;
}
.segmented-button:hover,
.segmented-button:focus-visible { border-color: var(--primary); outline: none; }
.segmented-button.active,
.segmented-button[aria-pressed="true"] {
  border-color: var(--primary);
  background: var(--primary);
  color: white;
}
.weight-chart-status { min-height: 1.3rem; margin: 0 0 .65rem; font-size: .86rem; }
.weight-chart-figure { margin: 0; }
.weight-chart-shell {
  width: 100%;
  min-height: 320px;
  overflow-x: auto;
  overflow-y: hidden;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: linear-gradient(180deg, #ffffff 0%, #fbfdfe 100%);
}
.weight-chart-shell svg { display: block; width: 100%; min-width: 720px; height: auto; }
.weight-chart-grid line { stroke: #dfe8ee; stroke-width: 1; vector-effect: non-scaling-stroke; }
.weight-chart-grid .weight-chart-x-grid { stroke: #edf2f5; }
.weight-chart-axes line { stroke: #8193a3; stroke-width: 1.25; vector-effect: non-scaling-stroke; }
.weight-chart-labels text { fill: var(--muted); font-family: inherit; font-size: 12px; }
.weight-chart-labels .weight-chart-axis-title { fill: var(--ink); font-size: 13px; font-weight: 760; }
.weight-chart-line { fill: none; stroke: var(--primary); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
.weight-chart-points circle { fill: white; stroke: var(--primary-dark); stroke-width: 3; vector-effect: non-scaling-stroke; }
.weight-chart-points circle:focus { outline: none; stroke-width: 5; }
.weight-chart-figure figcaption { margin-top: .6rem; color: var(--muted); font-size: .82rem; }

.nutrition-reference-note {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 1rem;
  padding: 1.1rem 1.25rem;
}
.nutrition-reference-note h2 { margin-bottom: .35rem; }
.nutrition-reference-note p:last-child { margin-bottom: 0; color: var(--muted); }
.health-entry-list { display: grid; gap: .65rem; }
.health-entry-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: .8rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fbfdfe;
}
.health-entry-row > div { display: grid; gap: .18rem; }
.health-entry-row span { color: var(--muted); font-size: .84rem; }
.weight-change { color: var(--muted); }
.weight-change.lower { color: var(--primary-dark); }
.weight-change.higher { color: #9a3412; }
.food-history-entry { border: 1px solid var(--line); border-radius: 14px; background: #fbfdfe; }
.food-history-entry summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: .85rem;
  cursor: pointer;
  list-style: none;
}
.food-history-entry summary::-webkit-details-marker { display: none; }
.food-history-entry summary > span:first-child { display: grid; gap: .2rem; }
.food-history-entry summary small { color: var(--muted); }
.food-history-body { display: grid; gap: .8rem; padding: 0 .85rem .85rem; border-top: 1px solid var(--line); }
.food-history-body ul { margin: .8rem 0 0; padding-left: 1.2rem; }
.food-history-body li { margin: .35rem 0; }
.food-history-body form { justify-self: start; }
.empty-state.compact { padding: 1rem; }

@media (max-width: 980px) {
  .calorie-form-grid,
  .calorie-history-grid { grid-template-columns: 1fr; }
  .ingredient-row-fields { grid-template-columns: 1fr 1fr; }
  .ingredient-name-field { grid-column: 1 / -1; }
}

@media (max-width: 680px) {
  .weight-chart-controls { grid-template-columns: 1fr; }
  .segmented-control { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .weight-chart-heading { align-items: stretch; }
  .weight-chart-heading .count-pill { align-self: start; }
  .weight-chart-shell { min-height: 260px; }
  .weight-chart-shell svg { min-width: 680px; }
  .ingredient-row-fields,
  .recipe-row-fields,
  .calorie-total-row { grid-template-columns: 1fr; }
  .ingredient-name-field { grid-column: auto; }
  .ingredient-row-heading,
  .nutrition-reference-note,
  .health-entry-row { align-items: stretch; flex-direction: column; }
  .ingredient-builder-actions,
  .ingredient-builder-actions .button,
  .nutrition-reference-note .button,
  .calorie-total-row .button,
  .health-entry-row .button { width: 100%; }
  .ingredient-suggestions { position: static; margin-top: .25rem; }
}

@media (max-width: 380px) {
  .segmented-control { grid-template-columns: 1fr; }
}

/* Food nutrition reference details */
.search-health-rating {
  justify-self: start;
  margin-top: .18rem;
  padding: .18rem .42rem;
  border-radius: 999px;
  background: var(--soft);
  color: var(--muted);
  font-size: .72rem;
  font-weight: 800;
}
.reference-calorie-note { margin: -.25rem .9rem .7rem; }
.ingredient-nutrition-panel {
  display: grid;
  gap: .8rem;
  margin: 0 .9rem .9rem;
  padding: .85rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: white;
}
.ingredient-nutrition-panel[hidden] { display: none; }
.ingredient-nutrition-heading {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: .8rem;
}
.ingredient-nutrition-heading > div { display: grid; gap: .2rem; }
.dataset-link-label {
  display: block;
  margin-top: .2rem;
  color: var(--muted);
  font-size: .76rem;
  overflow-wrap: anywhere;
}
.dataset-link-label code {
  padding: .08rem .3rem;
  border-radius: 6px;
  background: var(--soft);
  color: var(--ink);
}
.health-rating {
  flex: 0 0 auto;
  padding: .34rem .55rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--soft);
  font-size: .76rem;
  font-weight: 850;
  white-space: nowrap;
}
.health-rating-5,
.health-rating-4 { border-color: #8fd6c8; background: #ecfdf5; color: #0f766e; }
.health-rating-3 { border-color: #e4c878; background: #fffbeb; color: #92400e; }
.health-rating-2,
.health-rating-1 { border-color: #efb0a8; background: #fff1f2; color: #9f1239; }
.traffic-light-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: .45rem;
}
.traffic-chip {
  padding: .4rem .5rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: .75rem;
  font-weight: 800;
  text-align: center;
}
.traffic-green { border-color: #86d4c8; background: #ecfdf5; color: #0f766e; }
.traffic-amber { border-color: #e4c878; background: #fffbeb; color: #92400e; }
.traffic-red { border-color: #efb0a8; background: #fff1f2; color: #9f1239; }
.traffic-unknown { background: var(--soft); color: var(--muted); }
.nutrition-value-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: .55rem;
}
.nutrition-value {
  display: grid;
  gap: .12rem;
  min-width: 0;
  padding: .55rem;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: #fbfdfe;
}
.nutrition-value span,
.nutrition-value small { color: var(--muted); font-size: .72rem; }
.nutrition-value strong { font-size: .92rem; overflow-wrap: anywhere; }
.other-nutrients { border-top: 1px solid var(--line); padding-top: .7rem; }
.other-nutrients summary { cursor: pointer; font-weight: 800; }
.compact-nutrients { margin-top: .65rem; }
.nutrition-total-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: .5rem;
  margin-top: .8rem;
}
.nutrition-total-grid > div {
  display: grid;
  gap: .12rem;
  padding: .55rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--soft);
}
.nutrition-total-grid span { color: var(--muted); font-size: .72rem; }
.food-history-ingredients { display: grid; gap: .65rem; padding-left: 0 !important; list-style: none; }
.food-history-ingredients > li {
  display: grid;
  gap: .45rem;
  margin: 0 !important;
  padding: .65rem;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: white;
}
.ingredient-history-nutrients { display: flex; flex-wrap: wrap; gap: .35rem; }
.ingredient-history-nutrients span {
  padding: .2rem .4rem;
  border-radius: 999px;
  background: var(--soft);
  color: var(--muted);
  font-size: .72rem;
}

@media (max-width: 760px) {
  .ingredient-nutrition-heading { align-items: stretch; flex-direction: column; }
  .health-rating { align-self: start; }
  .traffic-light-grid,
  .nutrition-value-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .nutrition-total-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 420px) {
  .traffic-light-grid,
  .nutrition-value-grid,
  .nutrition-total-grid { grid-template-columns: 1fr; }
}
