@font-face {
  font-family: "Manrope";
  src: url("fonts/manrope/Manrope-Variable.woff2") format("woff2");
  font-weight: 400 800;
  font-style: normal;
  font-display: swap;
}

/*
 * Grist Factory's palette, with four values darkened until their text reads at 4.5:1 (WCAG AA) where the charter's
 * gave 3.7 to 4.4: --muted, --danger, --success and, for small text, --accent-text (the charter's --accent-hover).
 * --field-border is the 3:1 outline a field needs to be seen at all. All of it was measured, in both themes.
 */
:root {
  /* native controls follow the theme */
  color-scheme: light;
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-sunken: #eef1f6;
  --border: #dde2ea;
  --border-strong: #c3cad6;
  --ink: #1b2430;
  --muted: #5b6678;
  --field-border: #7a8496;
  --accent: #2f6fed;
  --accent-hover: #2558c4;
  --accent-text: var(--accent-hover);
  --accent-soft: #e8f0fe;
  --accent-ink: #ffffff;
  --danger: #c13333;
  --danger-soft: #fbe9e9;
  --warning: #b45309;
  --warning-soft: #fffbeb;
  --success: #187a42;
  --success-soft: #e6f4ea;
  --info: #2b3947;
  --info-soft: #eef1f4;
  --radius-sm: 7px;
  --radius: 11px;
  --shadow-card: 0 1px 3px rgba(27, 36, 48, 0.08);
  --shadow-float: 0 12px 32px rgba(27, 36, 48, 0.18), 0 2px 8px rgba(27, 36, 48, 0.08);
  --font-chrome: "Manrope", -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* Dark by the system preference unless a theme was chosen; the same values as :root[data-theme="dark"] below, keep them equal. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    color-scheme: dark;
    --bg: #141824;
    --surface: #1c2130;
    --surface-sunken: #10131c;
    --border: #2b3040;
    --border-strong: #3a4054;
    --ink: #eef1f6;
    --muted: #9aa3b2;
    --field-border: #6b7589;
    --accent: #5b8def;
    --accent-hover: #7ca2f2;
    --accent-soft: #1d2c4d;
    --accent-ink: #0b1220;
    --danger: #ef6a6a;
    --danger-soft: #3a1e22;
    --warning: #e3a53d;
    --warning-soft: #3a2c14;
    --success: #4bbf74;
    --success-soft: #16341f;
    --info: #d6dee5;
    --info-soft: #22282e;
    --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.4);
    --shadow-float: 0 16px 40px rgba(0, 0, 0, 0.55), 0 2px 10px rgba(0, 0, 0, 0.35);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #141824;
  --surface: #1c2130;
  --surface-sunken: #10131c;
  --border: #2b3040;
  --border-strong: #3a4054;
  --ink: #eef1f6;
  --muted: #9aa3b2;
  --field-border: #6b7589;
  --accent: #5b8def;
  --accent-hover: #7ca2f2;
  --accent-soft: #1d2c4d;
  --accent-ink: #0b1220;
  --danger: #ef6a6a;
  --danger-soft: #3a1e22;
  --warning: #e3a53d;
  --warning-soft: #3a2c14;
  --success: #4bbf74;
  --success-soft: #16341f;
  --info: #d6dee5;
  --info-soft: #22282e;
  --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.4);
  --shadow-float: 0 16px 40px rgba(0, 0, 0, 0.55), 0 2px 10px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

/* so that a rule setting `display` cannot show a hidden element */
[hidden] {
  display: none !important;
}

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-chrome);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.shell {
  max-width: 640px;
  margin: 0 auto;
  padding: 24px 16px 40px;
}

.masthead {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 20px;
}

/* Lets the title shrink and wrap beside the controls, rather than push them out of a narrow pane. */
.masthead-text {
  min-width: 0;
}

.masthead-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.eyebrow {
  margin: 0 0 6px;
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--accent-text);
}

h1 {
  margin: 0 0 8px;
  font-size: 1.65rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.15;
}

.lede {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
  max-width: 46ch;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  padding: 0;
}

.icon-btn:hover {
  color: var(--ink);
  border-color: var(--border-strong);
}

.icon-btn svg {
  width: 18px;
  height: 18px;
}

/* The icon buttons that act on a whole block sit in its head, beside its title. */
.icon-btn-sm {
  width: 30px;
  height: 30px;
}

.icon-btn-sm svg {
  width: 16px;
  height: 16px;
}

.block-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.block-head .eyebrow {
  margin: 0;
}

/* A button with an icon beside its label: the copy button shows a tick in place of its icon for a moment once the code is copied. */
button.btn-with-icon {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.btn-with-icon svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.btn-with-icon .icon-done,
.btn-with-icon.is-done .icon-copy {
  display: none;
}

.btn-with-icon.is-done .icon-done {
  display: block;
}

.brand-logo {
  display: block;
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  object-fit: contain;
}

/* Tabs */

.tabs {
  display: flex;
  gap: 0;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 4px;
  background: var(--surface);
  margin-bottom: 20px;
}

.tab {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--ink);
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 700;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.tab:hover:not([aria-selected="true"]) {
  background: var(--surface-sunken);
}

.tab[aria-selected="true"] {
  background: var(--accent);
  color: var(--accent-ink);
}

.panel {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.block {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow-card);
}

.field {
  margin-bottom: 14px;
}

label,
.label {
  display: block;
  font-weight: 700;
  font-size: 0.85rem;
  margin: 0 0 6px;
}

textarea,
input[type="text"],
input[type="search"],
select {
  width: 100%;
  border: 1.5px solid var(--field-border);
  border-radius: var(--radius-sm);
  background: var(--surface-sunken);
  color: var(--ink);
  padding: 10px;
  font-size: 0.85rem;
}

textarea {
  font-family: var(--font-mono);
  resize: vertical;
}

::placeholder {
  color: var(--muted);
  opacity: 1;
}

input[aria-invalid="true"] {
  border-color: var(--danger);
}

select,
input[type="text"],
input[type="search"] {
  font-family: var(--font-chrome);
}

input[type="search"] {
  appearance: none;
}

textarea:focus,
input[type="text"]:focus,
input[type="search"]:focus,
select:focus {
  outline: 2.5px solid var(--accent);
  outline-offset: 1px;
}

.actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
  flex-wrap: wrap;
}

button.btn {
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 700;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
}

button.btn:hover:not(:disabled) {
  border-color: var(--border-strong);
}

button.btn-primary {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
}

button.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

button.btn-ghost {
  background: transparent;
}

button.btn:disabled {
  background: var(--surface-sunken);
  border-color: var(--border);
  color: var(--muted);
  cursor: not-allowed;
}

/* Import mode: the two choices of a segmented control (see .segmented), a little larger than in the settings. */

.mode-picker .segmented-option {
  padding: 9px 8px;
  font-size: 0.85rem;
}

/* Columns preview table */

table#columns-preview {
  width: 100%;
  border-collapse: collapse;
  margin-top: 4px;
}

/* 1% makes the table give this column no more than its box needs. */
#columns-preview th.col-checkbox,
#columns-preview td.col-checkbox {
  width: 1%;
  padding: 0;
  white-space: nowrap;
}

.col-checkbox label {
  display: flex;
  margin: 0;
  padding: 8px 8px 8px 4px;
  cursor: pointer;
}

.col-checkbox input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

#columns-preview th,
#columns-preview td {
  text-align: left;
  border-bottom: 1px solid var(--border);
  padding: 7px 6px;
  font-size: 0.82rem;
}

#columns-preview th {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  white-space: nowrap;
}

.status-pill {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
}

.status-pill-new {
  background: var(--accent-soft);
  color: var(--accent-text);
}

.table-separator td {
  padding-top: 12px;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  background: var(--surface-sunken);
}

#table-ids-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.table-id-entry label {
  font-weight: 600;
  font-size: 0.82rem;
  color: var(--muted);
  margin-bottom: 3px;
}

/* The description a table will have, shown under the field of its id: the user's own words, so in italics. */
.table-description {
  margin: 4px 0 0;
  font-style: italic;
}

.tag {
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--surface-sunken);
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 700;
  white-space: nowrap;
}

.option {
  margin-top: 14px;
}

#export-select-all-row {
  margin: 0 0 8px;
}

.option label {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 24px;
  margin: 0;
  font-weight: 600;
  cursor: pointer;
}

.option input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.table-separator .tag {
  background: var(--surface);
}

.is-excluded td:not(.col-checkbox) {
  color: var(--muted);
}

label + .hint {
  margin: -2px 0 8px;
}

.status-pill-skip {
  background: var(--surface-sunken);
  color: var(--muted);
}

.field-error {
  color: var(--danger);
  font-size: 0.85rem;
  margin: 6px 0 0;
  font-weight: 600;
}

#warnings-block {
  margin-top: 16px;
  padding: 10px 12px;
  border: 1px solid var(--warning);
  border-radius: var(--radius-sm);
  background: var(--warning-soft);
}

#warnings-block .eyebrow {
  color: var(--warning);
}

#warnings-block ul {
  margin: 0;
  padding-left: 1.1rem;
}

#warnings-block li {
  font-size: 0.85rem;
  margin-bottom: 3px;
}

/* Export checklist (also reused by the Import tab's multi-table picker, and by the choice of the elements to keep) */

/* A long list scrolls in its block, not the whole pane, so that the action stays near. */
.checklist {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 260px;
  overflow-y: auto;
}

.checklist li {
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
}

.checklist li:hover {
  border-color: var(--border-strong);
  background: var(--surface-sunken);
}

.checklist label {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 11px;
  font-weight: 600;
  font-size: 0.85rem;
  margin: 0;
  cursor: pointer;
}

.checklist input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

/* Export: the row of a table holds its box and the button that unfolds the choice of its columns, a box for each. */

.table-row {
  display: flex;
  align-items: center;
}

/* The name takes what the button leaves, and wraps. */
.table-row > label {
  flex: 1;
  min-width: 0;
}

.columns-toggle {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
  gap: 6px;
  min-width: 28px;
  min-height: 28px;
  margin-right: 6px;
  padding: 4px 6px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  font: inherit;
  cursor: pointer;
}

.columns-toggle:hover {
  color: var(--ink);
}

.columns-toggle:focus-visible {
  outline: 2.5px solid var(--accent);
  outline-offset: 1px;
}

/* The chevron is two borders turned, not an icon: it points right when folded, down when unfolded. */
.columns-toggle::after {
  content: "";
  width: 6px;
  height: 6px;
  margin: 0 3px 2px 2px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(-45deg);
}

.columns-toggle[aria-expanded="true"]::after {
  margin-bottom: 4px;
  transform: rotate(45deg);
}

/* A row that is unfolded lets the list grow: the choice of columns is not read through two boxes that scroll. */
#export-table-list:has(.columns-toggle[aria-expanded="true"]) {
  max-height: none;
}

/* The columns of a table: a list of their own, which scrolls when the table has many. */
.columns-list {
  display: flex;
  flex-direction: column;
  gap: 1px;
  max-height: 11rem;
  margin: 0 8px 8px 38px;
  padding-top: 6px;
  border-top: 1px dashed var(--border);
  overflow-y: auto;
}

.checklist .columns-list label {
  padding: 4px 6px;
  font-size: 0.82rem;
  font-weight: 500;
}

/* Export: the search of a table, above the list */

.search {
  margin: 0 0 10px;
}

#export-search-status:empty {
  margin: 0;
}

/* The elements of the columns (labels, choices, formulas…) that Export and Import let the user leave out: folded, with what is chosen written on the summary; a few short rows side by side once unfolded. */

.elements {
  margin: 14px 0 0;
  min-width: 0;
}

.elements summary {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 2px 10px;
  padding: 5px 0;
  cursor: pointer;
  list-style: none;
}

.elements summary::-webkit-details-marker {
  display: none;
}

.elements summary::before {
  content: "";
  width: 6px;
  height: 6px;
  margin: 0 4px 2px 3px;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(-45deg);
}

.elements[open] > summary::before {
  margin-bottom: 4px;
  transform: rotate(45deg);
}

.elements summary:focus-visible {
  outline: 2.5px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

.elements summary .eyebrow {
  margin: 0;
}

.elements-state {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 600;
}

.elements[open] > summary {
  margin-bottom: 6px;
}

.elements-list {
  max-height: none;
  overflow: visible;
}

.elements-list li {
  display: flex;
}

.elements-list label {
  flex: 1;
  align-items: flex-start;
}

.elements-list input[type="checkbox"] {
  margin-top: 1px;
}

.element-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  min-width: 0;
}

/* The name and the count share a line while they fit: the count goes under the name rather than squeezing it. */
.element-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0 8px;
}

.element-hint {
  font-size: 0.75rem;
  font-weight: 400;
  line-height: 1.35;
  color: var(--muted);
}

.elements-list .tag {
  margin-left: auto;
}

#export-output {
  min-height: 200px;
}

#copy-status:empty {
  display: none;
}

.hint {
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.4;
  margin: 8px 0 0;
}

.hint code {
  font-family: var(--font-mono);
  background: var(--info-soft);
  padding: 1px 4px;
  border-radius: 4px;
}

/* Export: referenced-tables information banner */

.refs-banner {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 14px 0;
}

.refs-banner p {
  margin: 0;
}

.refs-list {
  margin: 0;
  padding-left: 1.1rem;
}

.refs-list li {
  font-size: 0.85rem;
}

.refs-banner .actions {
  margin-top: 2px;
}

/* Status messages */

.status {
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 0.9rem;
  font-weight: 600;
  margin: 0;
}

.status-info {
  background: var(--info-soft);
  color: var(--info);
}

.status-warning {
  background: var(--warning-soft);
  color: var(--warning);
}

.status-success {
  background: var(--success-soft);
  color: var(--success);
}

.status-error {
  background: var(--danger-soft);
  color: var(--danger);
}

/* The dialogs: Réglages, and the confirmation Import asks for before it writes in the document */

dialog.dialog {
  border: none;
  border-radius: var(--radius);
  padding: 0;
  width: min(420px, calc(100vw - 32px));
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-float);
}

dialog.dialog::backdrop {
  background: rgba(20, 24, 36, 0.45);
}

/* The confirmation: what will be added, any warning, what is never touched, and the two buttons. */

.dialog-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 18px 18px 6px;
}

.dialog-body p {
  margin: 0;
}

.dialog-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 800;
  overflow-wrap: anywhere;
}

/* Many tables or columns scroll in the dialog; its buttons stay in view. */
.confirm-list {
  max-height: 12rem;
  margin: 0;
  padding-left: 1.2rem;
  overflow-y: auto;
  font-size: 0.88rem;
  font-weight: 600;
}

.confirm-list li {
  overflow-wrap: anywhere;
}

.dialog-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
  padding: 12px 18px 18px;
}

/* A dialog that can be taller than the pane: its content scrolls under its title, and its buttons stay in view. */
dialog.dialog-fixed-actions[open] {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.dialog-fixed-actions .dialog-body {
  min-height: 0;
  overflow-y: auto;
}

.dialog-fixed-actions .dialog-actions {
  flex: none;
}

.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
}

.settings-header h2 {
  margin: 0;
  font-size: 1rem;
  font-weight: 800;
}

.settings-body {
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.settings-section p.eyebrow {
  margin-bottom: 8px;
}

/* Theme and language choices: the radio is hidden inside its label. */
.segmented {
  display: flex;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 3px;
  gap: 3px;
}

.segmented-option {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 7px 8px;
  border-radius: calc(var(--radius-sm) - 3px);
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--muted);
  cursor: pointer;
  text-align: center;
}

/* The radio stays in the page for the keyboard and for screen readers; the label around it is what is seen. */
.segmented-option input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented-option.is-checked {
  background: var(--accent);
  color: var(--accent-ink);
}

/* The hidden radio's focus ring, drawn on its label. */
.segmented-option:has(input:focus-visible) {
  outline: 2.5px solid var(--accent);
  outline-offset: 1px;
}

.credits-list {
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.credits-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.82rem;
}

.credits-row dt {
  color: var(--muted);
  font-weight: 600;
}

.credits-row dd {
  margin: 0;
  font-weight: 600;
  text-align: right;
}

.credits-row dd a {
  display: inline-block;
  padding: 3px 0;
  color: var(--accent-text);
  text-decoration: none;
}

.credits-row dd a:hover {
  text-decoration: underline;
}

/* Long identifiers have no break opportunity: wrap them instead of overflowing narrow panes. */
#columns-preview td,
#columns-preview th,
.table-id-entry label,
.checklist span,
/* A long identifier has no space to wrap at: it is broken rather than left to overflow the pane. */
#export-search-status,
#warnings-list li,
.field-error,
.table-description,
.refs-list li {
  overflow-wrap: anywhere;
}

/* The markup is French: for a reader of English it stays hidden until js/i18n.js has translated it, or for two seconds if that never happens. */
html[data-pending-locale] body {
  visibility: hidden;
  animation: reveal 0s 2s forwards;
}

@keyframes reveal {
  to {
    visibility: visible;
  }
}

/* The action of a block stays in reach while the block is longer than the pane; a very short pane (a page zoomed in) keeps it in the flow, where it takes no room from the content. */
@media (min-height: 480px) {
  html {
    scroll-padding-bottom: 5rem;
  }

  .actions-sticky {
    position: sticky;
    bottom: 0;
    z-index: 1;
    margin: 14px -18px -18px;
    padding: 12px 18px;
    border-top: 1px solid var(--border);
    border-radius: 0 0 var(--radius) var(--radius);
    background: var(--surface);
  }
}

/* A short pane, which a Grist widget often is: the title and the code box are what the buttons need above them. */
@media (max-height: 640px) {
  .shell {
    padding-top: 12px;
  }

  .masthead .eyebrow,
  .lede {
    display: none;
  }

  #source-input {
    height: 8.5rem;
  }
}

/* High-contrast modes drop backgrounds: keep what they said (selected, framed) as outlines and borders. */
@media (forced-colors: active) {
  .tab[aria-selected="true"],
  .segmented-option.is-checked {
    outline: 2px solid Highlight;
    outline-offset: -2px;
  }

  dialog.dialog,
  .status,
  #warnings-block {
    border: 1px solid CanvasText;
  }
}
