/* The controls, each defined once. */

/* ---- buttons ---- */
button { height: var(--control-h); padding: 0 10px; border: 1px solid var(--border-strong); border-radius: var(--radius-s); background: var(--surface); cursor: pointer; white-space: nowrap; display: inline-flex; align-items: center; justify-content: center; gap: 6px; transition: background 0.1s, border-color 0.1s; }
button:hover { background: var(--surface-3); }
button:active { background: var(--border); }
button:disabled { opacity: 0.45; cursor: default; pointer-events: none; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
button.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
button.quiet { border-color: transparent; background: transparent; color: var(--text-2); }
button.quiet:hover { background: var(--surface-3); color: var(--text); }
button.danger { color: var(--danger); }
button.danger.primary { background: var(--danger); border-color: var(--danger); color: #fff; }
button.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
button.icon { width: var(--control-h); padding: 0; flex: none; }
button.icon.small { width: 22px; height: 22px; }
button svg.i { width: 16px; height: 16px; flex: none; }
svg.i { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }

/* ---- fields ---- */
input[type="number"], input[type="text"], select { height: var(--control-h); padding: 0 8px; border: 1px solid var(--border-strong); border-radius: var(--radius-s); background: var(--surface); min-width: 0; }
input[type="number"]:hover, input[type="text"]:hover, select:hover { border-color: var(--text-3); }
input[type="number"]:focus, input[type="text"]:focus, select:focus { border-color: var(--accent); outline: 2px solid var(--accent-soft); outline-offset: 0; }
input:disabled, select:disabled { opacity: 0.5; background: var(--surface-2); }
input::placeholder { color: var(--text-3); }
input[type="file"] { font-size: var(--text-s); color: var(--text-2); max-width: 100%; }
input[type="file"]::file-selector-button { font: inherit; height: var(--control-h); padding: 0 10px; margin-right: 8px; border: 1px solid var(--border-strong); border-radius: var(--radius-s); background: var(--surface); color: var(--text); cursor: pointer; }
input[type="range"] { accent-color: var(--accent); height: 16px; margin: 0; }
input[type="checkbox"] { accent-color: var(--accent); width: 15px; height: 15px; margin: 0; flex: none; }
label.check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }

/* a switch: a checkbox drawn as a track with a knob */
label.toggle { display: inline-flex; align-items: center; gap: 8px; vertical-align: middle; cursor: pointer; }
input.switch { appearance: none; -webkit-appearance: none; width: 30px; height: 18px; margin: 0; border-radius: 9px; background: var(--border-strong); position: relative; cursor: pointer; flex: none; transition: background 0.12s; }
input.switch::before { content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3); transition: left 0.12s; }
input.switch:checked { background: var(--accent); }
input.switch:checked::before { left: 14px; }

/* ---- sections of the inspector ---- */
.group { border-bottom: 1px solid var(--border); }
.group-head { width: 100%; height: 36px; padding: 0 var(--s4); border: 0; border-radius: 0; background: transparent; justify-content: flex-start; gap: 6px; font-weight: 600; }
.group-head:hover { background: var(--surface-2); }
.group-head svg.i { width: 14px; height: 14px; color: var(--text-3); transition: transform 0.12s; }
.group.closed .group-head svg.i { transform: rotate(-90deg); }
.group-body { padding: 2px var(--s4) var(--s3); }
.group.closed .group-body { display: none; }
.row { display: flex; align-items: center; gap: var(--s2); margin: 6px 0; flex-wrap: wrap; }
.row-label { width: 96px; flex: none; color: var(--text-2); }
.hint { color: var(--text-3); margin: 6px 0; font-size: var(--text-s); line-height: 1.45; }
.notice { background: var(--warn-soft); border: 1px solid var(--warn-border); border-radius: var(--radius-s); padding: 8px 10px; margin: 0 0 var(--s2); }
.notice button { height: 24px; vertical-align: middle; }
.empty { color: var(--text-3); padding: var(--s5); }

/* ---- tables ---- */
.scroll-x { overflow-x: auto; }
table.grid { border-collapse: collapse; margin: 6px 0; font-variant-numeric: tabular-nums; }
table.grid th, table.grid td { border: 1px solid var(--border); padding: 3px 7px; text-align: right; white-space: nowrap; }
table.grid th { background: var(--surface-2); font-weight: 600; text-align: center; color: var(--text-2); font-size: var(--text-s); }
table.grid td button.icon { border-color: transparent; background: transparent; color: var(--text-3); }
table.grid td button.icon:hover { background: var(--surface-3); color: var(--text); }
table.grid input[type="number"], table.grid input[type="text"] { height: 24px; padding: 0 5px; }
input.cell { width: 46px; text-align: center; }
input.cell.title, input.cell.wide { width: 92px; text-align: left; }
input.cell.outside { color: var(--text-3); background: var(--surface-2); }
/* a table of inputs that reads as a sheet: the cells are the fields */
table.sheet td { padding: 0; }
table.sheet td:has(> button), table.sheet td:has(> input[type="checkbox"]), table.sheet td:has(> label) { padding: 2px 5px; text-align: center; }
table.sheet input.cell { display: block; height: 26px; border: 0; border-radius: 0; padding: 0 7px; background: transparent; }
table.sheet input.cell:focus { outline: 2px solid var(--accent); outline-offset: -2px; background: var(--surface); }
table.sheet input.cell.outside { background: var(--surface-2); }
table.sheet input[type="number"].cell { text-align: right; }

/* ---- dialogs, toasts ---- */
dialog { border: 1px solid var(--border); border-radius: 12px; padding: 0; background: var(--surface); color: var(--text); box-shadow: var(--shadow-3); max-height: 88vh; }
dialog::backdrop { background: rgba(10, 12, 16, 0.45); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s4); padding: var(--s4) var(--s5) var(--s2); }
.dialog-head h2 { font-size: var(--text-l); }
.dialog-body { padding: 0 var(--s5) var(--s5); overflow: auto; }
.dialog-foot { display: flex; justify-content: flex-end; gap: var(--s2); padding: var(--s3) var(--s5) var(--s4); }
dialog.confirm { width: min(420px, 92vw); }
dialog.confirm p { padding: var(--s5) var(--s5) var(--s2); line-height: 1.5; }
dialog.help { width: min(640px, 94vw); }
dialog.help dl { display: grid; grid-template-columns: max-content 1fr; gap: 7px 16px; margin: 0; align-items: baseline; }
dialog.help dt { color: var(--text-2); }
dialog.help dd { margin: 0; }
dialog.help h3 { font-size: var(--text-s); text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-3); margin: var(--s4) 0 var(--s2); }

/* the tour: the page dimmed but for the part being explained, and a card beside it */
dialog.tour { position: fixed; inset: 0; width: 100vw; height: 100vh; max-width: none; max-height: none; margin: 0; border: 0; border-radius: 0; background: transparent; box-shadow: none; overflow: hidden; }
dialog.tour::backdrop { background: transparent; }
.tour-shade { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.tour-dim { fill: rgba(10, 12, 16, 0.55); }
.tour-outline { fill: none; stroke: var(--accent); stroke-width: 2; }
.tour-card { position: absolute; width: min(360px, calc(100vw - 32px)); padding: var(--s4) var(--s4) var(--s3); background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow-3); transition: left 0.2s, top 0.2s; }
dialog.tour.centred .tour-card { left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(420px, calc(100vw - 32px)); }
.tour-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s3); margin-bottom: var(--s2); }
.tour-head h2 { font-size: var(--text-l); }
.tour-count { color: var(--text-3); font-size: var(--text-s); white-space: nowrap; font-variant-numeric: tabular-nums; }
.tour-card p { color: var(--text-2); line-height: 1.5; margin-bottom: var(--s4); }
.tour-actions { display: flex; align-items: center; gap: var(--s2); flex-wrap: wrap; }
dialog.tour.busy { cursor: progress; }
dialog.tour.busy .tour-actions { opacity: 0.5; pointer-events: none; }

#toasts { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; align-items: center; z-index: 50; pointer-events: none; }
.toast { pointer-events: auto; display: flex; align-items: center; gap: 12px; max-width: min(560px, 92vw); padding: 9px 10px 9px 14px; border-radius: var(--radius); background: var(--text); color: var(--bg); box-shadow: var(--shadow-2); white-space: pre-line; animation: toast-in 0.16s ease-out; }
.toast.error { background: var(--danger); color: #fff; }
.toast button { height: 24px; background: transparent; color: inherit; border-color: currentColor; opacity: 0.9; }
.toast button:hover { background: rgba(127, 127, 127, 0.25); opacity: 1; }
.toast button.icon { border-color: transparent; }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

input.wide-field { flex: 1; min-width: 80px; }

table.grid td > button:not(.icon) { height: 22px; padding: 0 7px; font-size: var(--text-s); margin-right: 2px; }
