/* The app's styles. They live in this file, not in the page, because the
   Content Security Policy allows only styles from the app's own files. See
   docs/architecture/security.md. */
/* The look: a light, warm frame around white paper, with brown as the accent
   for what is selected, pressed or focused. A colour, a size or a space is a
   token here, so that a theme changes in one place. See
   docs/working-notes/gui-review.md. */
:root {
  --accent: #6e461e;
  --accent-hover: #5a3814;
  --accent-text: white;
  --text: #1f1b16;
  --text-muted: #5c554c;
  --text-disabled: #9a9288;
  --paper: white;
  --frame: #f5f1ea;
  --hover: #f3ebde;
  --selected: #ead9bd;
  --help-paper: #fdfaf4;
  --help-side: #f6efe2;
  --border: #ddd5c8;
  /* At least 3:1 against white, as WCAG asks of a control's edge. */
  --border-strong: #968a79;
  --control-border: #767676;
  --error: #a00;
  --mark: #c00;
  --mark-text: #900;
  --shadow: rgb(0 0 0 / 0.25);
  --backdrop: rgb(0 0 0 / 0.3);
  --space-1: 0.25em;
  --space-2: 0.5em;
  --space-3: 0.75em;
  --space-4: 1em;
  --text-small: 0.85em;
  --text-heading: 1.1em;
  --radius: 0.35em;
}
body { margin: 0; font-family: system-ui, sans-serif; color: var(--text); background: var(--paper); }
#shell { display: flex; flex-direction: column; height: 100vh; }
header { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-1) var(--space-4); border-bottom: 1px solid var(--border); background: var(--frame); }
header .app-icon { width: 1.6em; height: 1.6em; }
header h1 { font-size: var(--text-heading); margin: 0 var(--space-2) 0 0; color: var(--accent); }
#help-button { margin-left: auto; }
/* Back and Forward, in the installed app's header and the help window's bar (ticket 053). A browser tab has its own. */
header .history-buttons { display: flex; gap: var(--space-1); }
#help-panel .history-back, #help-panel .history-forward { flex: none; }

/* One look for every button. The list rows, the tabs and the panel strips have their own below.
   Every :hover rule is inside @media (hover: hover). A touch screen keeps :hover on the last tapped
   element, so a button that was tapped off would show the hover colour instead of its plain one. */
button { padding: var(--space-1) var(--space-3); border: 1px solid var(--border-strong); border-radius: var(--radius); background: var(--paper); color: var(--text); font: inherit; font-size: 0.9em; cursor: pointer; }
@media (hover: hover) { button:hover:not(:disabled) { background: var(--hover); } }
button:active:not(:disabled) { background: var(--selected); }
/* A pressed tool: Help, Add pins, Set fixture point and Measure. */
button[aria-pressed=true] { border-color: var(--accent); background: var(--accent); color: var(--accent-text); }
@media (hover: hover) { button[aria-pressed=true]:hover:not(:disabled) { background: var(--accent-hover); } }
button:disabled { border-color: var(--border); color: var(--text-disabled); cursor: default; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input[type=checkbox], input[type=radio] { accent-color: var(--accent); }
input[type=text], input[type=search] { padding: 0.15em var(--space-2); border: 1px solid var(--border-strong); border-radius: var(--radius); background: var(--paper); color: var(--text); font: inherit; }

/* The notice about a link or opened files: a modal dialog, as the About box. */
dialog { border: 1px solid var(--border); border-radius: 0.5em; color: var(--text); box-shadow: 0 0.3em 1.2em var(--shadow); }
dialog::backdrop { background: var(--backdrop); }
#notice { padding: var(--space-4) 1.5em; max-width: min(32em, calc(100vw - 4em)); }
#notice h2 { margin: 0 0 var(--space-2); font-size: var(--text-heading); }
#notice ul { margin: var(--space-2) 0; padding-left: 1.2em; }
#notice .advice { color: var(--text-muted); }
#notice .notice-buttons { text-align: right; margin: var(--space-2) 0 0; }
/* The update toast: not modal, in the bottom right corner, until the designer chooses. */
#update-toast { position: fixed; right: var(--space-4); bottom: var(--space-4); z-index: 10; max-width: min(24em, calc(100vw - 2em)); padding: var(--space-3) var(--space-4); border: 1px solid var(--border); border-left: 4px solid var(--accent); border-radius: 0.5em; background: var(--paper); box-shadow: 0 0.2em 0.8em var(--shadow); }
#update-toast p { margin: 0 0 var(--space-2); }
#update-toast .update-buttons { display: flex; gap: var(--space-2); justify-content: flex-end; }
#about { padding: var(--space-4) 1.5em; max-width: 32em; }
#about[open] { display: grid; grid-template-columns: auto 1fr; gap: 0 1.5em; }
#about .about-icon { width: 96px; height: 96px; }
#about h2 { margin: 0 0 var(--space-2); font-size: 1.2em; }
#about p { margin: var(--space-2) 0; }
#about a { color: var(--accent); }
#about .about-mode { display: flex; align-items: center; gap: var(--space-2); margin-top: var(--space-2); }
#about .about-mode-hint { margin-top: 0; color: var(--text-muted); font-size: var(--text-small); }
#about .about-buttons { grid-column: 1 / -1; text-align: right; margin: var(--space-2) 0 0; }

main { position: relative; display: flex; flex: 1; min-height: 0; }
/* The footer with the signatures of the shown instruments. It keeps the height of one line when none is shown, so that selecting the first instrument does not shrink the picture. */
#signatures { padding: var(--space-1) var(--space-4); border-top: 1px solid var(--border); background: var(--frame); font-size: var(--text-small); }
#signatures ul { display: flex; flex-wrap: wrap; gap: 0 1.5em; min-height: 1.4em; margin: 0; padding: 0; list-style: none; line-height: 1.4; }
#signatures .swatch { margin-right: 0.4em; }
.panel-strip { flex: none; width: 1.2em; padding: 0; border: none; border-right: 1px solid var(--border); border-radius: 0; background: var(--frame); color: var(--text-muted); font: inherit; font-weight: bold; cursor: pointer; }
.panel-strip:last-child { border-right: none; border-left: 1px solid var(--border); }
@media (hover: hover) { .panel-strip:hover:not(:disabled) { background: var(--hover); color: var(--text); } }
.panel-strip:focus-visible { outline-offset: -2px; }
main.list-collapsed #instrument-list, main.panel-collapsed #side-panel { display: none; }
#instrument-list { width: 18em; overflow-y: auto; border-right: 1px solid var(--border); }
#instrument-list ul { margin: 0; padding: 0; list-style: none; }
/* "Open files…" and "Show bundled instruments", only in Advanced mode. */
#instrument-list .list-buttons { display: flex; flex-wrap: wrap; gap: var(--space-1) var(--space-2); margin: var(--space-2) 0.6em; }
#instrument-list .list-empty { margin: var(--space-2) 0.6em; color: var(--text-muted); font-size: var(--text-small); }
#instrument-list .list-heading { margin: var(--space-3) 0.6em var(--space-1); font-size: var(--text-small); color: var(--text-muted); }
#instrument-list li { display: flex; align-items: stretch; }
#instrument-list .toggle { display: flex; align-items: center; padding: 0 0.2em 0 0.6em; cursor: pointer; }
/* The checkbox is drawn here: a ticked box is filled with its instrument's colour, without a tick. */
#instrument-list .toggle input { appearance: none; margin: 0; width: 1.1em; height: 1.1em; border: 2px solid var(--control-border); border-radius: 0.2em; background: var(--paper); cursor: pointer; }
@media (hover: hover) { #instrument-list .toggle input:hover { border-color: var(--accent); } }
#instrument-list .toggle input:checked { border-color: var(--text); }
@media (hover: hover) { #instrument-list .toggle input:checked:hover { border-color: var(--accent); } }
/* One rule for each colour in model/colour_selector.gleam, from content.colour_class. */
#instrument-list .toggle input.colour-0:checked { background: rgb(0,0,0); }
#instrument-list .toggle input.colour-1:checked { background: rgb(0,140,0); }
#instrument-list .toggle input.colour-2:checked { background: rgb(120,40,230); }
#instrument-list .toggle input.colour-3:checked { background: rgb(0,130,150); }
#instrument-list .toggle input.colour-4:checked { background: rgb(200,0,200); }
#instrument-list .toggle input.colour-5:checked { background: rgb(130,120,0); }
#instrument-list .toggle input.colour-6:checked { background: rgb(0,70,30); }
#instrument-list .toggle input.colour-7:checked { background: rgb(210,0,100); }
#instrument-list .name { display: block; flex: 1; min-width: 0; overflow-wrap: anywhere; text-align: left; padding: 0.3em 0.8em; border: none; border-radius: 0; background: none; color: var(--text); font: inherit; cursor: pointer; }
#instrument-list .name:focus-visible { outline-offset: -2px; }
@media (hover: hover) { #instrument-list li:hover > :not(.new-pins) { background: var(--hover); } }
/* A selected row is tinted. The current instrument, the one that the tools and the help use (ticket 050), also has an accent bar at its left edge and a bold name. */
#instrument-list li:has(.name[aria-pressed=true]) > :not(.new-pins) { background: var(--selected); }
#instrument-list li:has(.name[aria-current=true]) .toggle { box-shadow: inset 4px 0 0 var(--accent); }
#instrument-list .name[aria-current=true] { font-weight: bold; }
/* The remove button of an opened file. */
#instrument-list .remove { flex: none; padding: 0 0.7em; border: none; border-radius: 0; background: none; color: var(--text-muted); font: inherit; cursor: pointer; }
@media (hover: hover) { #instrument-list .remove:hover { color: var(--error); } }
/* A contrast theme drops the box's colour and the row's tint, so the box keeps its colour, with borders in the theme's colours, and a selected row gets the theme's selection colours.
   A ticked box has the theme's selection colour as its border, so that a black box shows on a black theme. */
@media (forced-colors: active) {
  #instrument-list .toggle input, #instrument-list .toggle input:hover { forced-color-adjust: none; border-color: CanvasText; background-color: Canvas; }
  #instrument-list .toggle input:checked, #instrument-list .toggle input:checked:hover { border-color: Highlight; }
  #instrument-list .toggle input:focus-visible { outline-color: CanvasText; }
  #instrument-list .name[aria-pressed=true] { forced-color-adjust: none; background: Highlight; color: HighlightText; }
  button[aria-pressed=true] { border-width: 3px; }
}
/* Images and pin point files: a pin point file is indented below its image, and their ticked boxes are grey, because they keep their own colours. */
#instrument-list li.pin-file .toggle { padding-left: 1.8em; }
#instrument-list .toggle input.plain:checked { background: rgb(120,120,120); }
/* "New pin points" goes on a line of its own below the image name: the empty ::after item fills the first line. */
#instrument-list li:has(> .new-pins) { flex-wrap: wrap; }
#instrument-list li:has(> .new-pins)::after { content: ""; flex-basis: 100%; }
#instrument-list .new-pins { order: 1; flex: none; margin: var(--space-1) 0.6em 0.4em 2.3em; font-size: var(--text-small); }
/* The crosshair of the pin tool is Clavichord's, yellow or magenta. */
#drawing-svg.setting-fixture, #drawing-svg.measuring { cursor: crosshair; }
/* The measurement keeps its size in screen pixels. The text has a white halo, so that it reads on any line. */
.measurement { pointer-events: none; }
.measurement line { stroke: var(--mark); stroke-width: 1.5px; }
.measurement-text text { font: 13px system-ui, sans-serif; fill: var(--mark-text); paint-order: stroke; stroke: var(--paper); stroke-width: 3px; stroke-linejoin: round; }
#drawing-svg.adding-pins { cursor: url(cursors/crosshair-yellow.svg) 15 15, crosshair; }
#drawing-svg.adding-pins.magenta { cursor: url(cursors/crosshair-magenta.svg) 15 15, crosshair; }
@media (pointer: coarse) {
  #instrument-list .toggle { padding: 0 0.4em 0 0.8em; }
  #instrument-list .toggle input { width: 1.5em; height: 1.5em; }
  #instrument-list .name { padding-top: 0.6em; padding-bottom: 0.6em; }
}
.swatch { width: 0.8em; height: 0.8em; vertical-align: baseline; }
#side-panel h2.shown-files span { display: block; }
/* With several instruments, only the current one is bold (ticket 050), in the accent colour. */
#side-panel h2.shown-files span { font-weight: normal; }
#side-panel h2 .current { font-weight: bold; color: var(--accent); }
#side-panel h2.shown-files .swatch { margin-right: 0.4em; }
#instrument-list .unreadable { color: var(--error); }
#drawing { display: flex; flex-direction: column; flex: 1; min-width: 0; }
/* The tabs and the toolbar wrap to more rows in a narrow window, so that no button runs under the side panel. A button wider than the room scrolls instead. */
#tabs { display: flex; flex-wrap: wrap; overflow-x: auto; gap: var(--space-1); padding: var(--space-1) var(--space-2) 0; border-bottom: 1px solid var(--border); }
#tabs button { padding: var(--space-2) var(--space-3); font-size: 1em; border: none; border-bottom: 2px solid transparent; border-radius: var(--radius) var(--radius) 0 0; background: none; color: var(--text-muted); }
@media (hover: hover) { #tabs button:hover { background: var(--hover); color: var(--text); } }
#tabs button[aria-selected=true] { border-bottom-color: var(--accent); color: var(--text); font-weight: bold; }
#tabs button:focus-visible { outline-offset: -2px; }
#toolbar { display: flex; flex-wrap: wrap; overflow-x: auto; gap: var(--space-1); padding: var(--space-1) var(--space-2); border-bottom: 1px solid var(--border); }
#toolbar button { padding: 0.15em var(--space-2); }
#drawing-panel { flex: 1; min-height: 0; overflow: hidden; background: var(--paper); }
#drawing-panel svg { display: block; }
#drawing-svg { cursor: grab; touch-action: none; }
#drawing-svg.dragging { cursor: grabbing; }
#drawing-panel svg g { pointer-events: none; }
#drawing-panel.table-panel { overflow: auto; padding: 0 var(--space-4) var(--space-4); }
.table-panel table { border-collapse: collapse; font-variant-numeric: tabular-nums; }
.table-panel caption { text-align: left; font-weight: bold; padding: 0.6em 0; }
.table-panel th, .table-panel td { border: 1px solid var(--border); padding: 0.15em 0.6em; white-space: nowrap; }
.table-panel thead th { position: sticky; top: 0; background: var(--frame); }
.table-panel tbody th { background: var(--frame); font-weight: normal; text-align: center; }
.table-panel td.number { text-align: right; }
.table-panel td.text { text-align: center; }
.table-panel table.measurements tbody th { text-align: left; }
.table-panel tr.category th { font-weight: bold; }
.table-panel th.level-1 { padding-left: 1.6em; }
.table-panel th.level-2 { padding-left: 2.6em; }
.table-panel th.level-3 { padding-left: 3.6em; }
.table-panel th.level-4 { padding-left: 4.6em; }
.table-panel th.level-5 { padding-left: 5.6em; }
#side-panel { width: 16em; overflow-y: auto; border-left: 1px solid var(--border); padding: 0 0.8em; }
#side-panel h2 { font-size: var(--text-heading); }
#side-panel details { margin: 0 0 var(--space-4); }
#side-panel summary { font-weight: bold; margin-bottom: var(--space-1); cursor: pointer; }
#side-panel label { display: block; padding: 0.1em 0; }
#side-panel .clear-layers { margin-bottom: var(--space-1); }
#side-panel .marker-toggle { margin-top: 0.4em; }
.fixture-marker { fill: none; stroke: var(--mark); stroke-width: 1.5px; pointer-events: none; }
#side-panel .note { color: var(--error); }
#side-panel .hint { color: var(--text-muted); font-size: var(--text-small); margin: var(--space-1) 0; }
#raster .presets, #raster .raster-moves { display: flex; flex-wrap: wrap; gap: var(--space-1); margin: var(--space-1) 0; }
#raster input[type="text"] { width: 6em; margin-left: 0.4em; }
#raster input[aria-invalid="true"] { outline: 2px solid var(--error); }
.message { padding: var(--space-4) 1.5em; }

/* The help panel at the right of main, beside the view. See docs/system/help.md. */
#help-panel { flex: none; width: 24em; max-width: 40vw; overflow-y: auto; border-left: 1px solid var(--border); padding: var(--space-2) var(--space-4) var(--space-4); background: var(--help-paper); }
#help-panel .help-bar { display: flex; gap: 0.4em; position: sticky; top: -0.5em; padding: var(--space-2) 0; background: var(--help-paper); }
#help-panel .help-bar input { flex: 1; min-width: 0; }
#help-panel .help-close, #help-panel .help-detach, #help-panel .help-print { flex: none; }
#help-panel .help-follow { display: block; margin: 0.2em 0 0.6em; }
/* Beside the view, only the shown tab scrolls, below the bar and the tabs. */
#help-panel.help-tabbed { display: flex; flex-direction: column; overflow: hidden; padding-bottom: 0; }
#help-panel.help-tabbed .help-bar, #help-panel.help-tabbed .help-follow, #help-panel.help-tabbed .help-tabs { flex: none; }
#help-panel.help-tabbed [role=tabpanel] { flex: 1; min-height: 0; overflow-y: auto; padding-bottom: var(--space-4); }
/* The Contents and Page tabs of the panel beside the view, in the look of the main tabs. */
#help-panel .help-tabs { display: flex; gap: var(--space-1); margin-bottom: var(--space-2); border-bottom: 1px solid var(--border); }
#help-panel .help-tabs button { padding: var(--space-1) var(--space-3); font-size: 1em; border: none; border-bottom: 2px solid transparent; border-radius: var(--radius) var(--radius) 0 0; background: none; color: var(--text-muted); }
@media (hover: hover) { #help-panel .help-tabs button:hover { background: var(--hover); color: var(--text); } }
#help-panel .help-tabs button[aria-selected=true] { border-bottom-color: var(--accent); color: var(--text); font-weight: bold; }
#help-panel .help-tabs button:focus-visible { outline-offset: -2px; }
#help-panel .help-contents ul { margin: 0.2em 0; padding-left: 1.1em; list-style: none; }
#help-panel .help-contents > ul { padding-left: 0; }
#help-panel .help-contents a { display: inline-block; padding: 0.1em 0; }
#help-panel a { color: var(--accent); }
#help-panel a[aria-current=page] { font-weight: bold; color: inherit; text-decoration: none; }
#help-panel .help-page { line-height: 1.45; }
#help-panel .help-page h2 { font-size: 1.2em; margin: 0.8em 0 0.4em; }
#help-panel .help-page h3 { font-size: 1em; margin: var(--space-4) 0 var(--space-1); }
#help-panel .help-page a { overflow-wrap: anywhere; }
#help-panel .help-steps { display: flex; justify-content: space-between; gap: var(--space-4); margin-top: 1.5em; padding-top: var(--space-2); border-top: 1px solid var(--border); }
#help-panel .help-results ul { padding-left: 1.1em; }
#help-panel .hint { color: var(--text-muted); }
#help-panel .note { color: var(--error); }
/* The help window shows only the help, over the whole window. */
main.help-window #help-panel { position: static; flex: 1; width: auto; max-width: none; padding: 0; border-left: none; box-shadow: none; }
main.help-window #help-panel.help-columns { display: flex; overflow: hidden; }
#help-panel .help-side { flex: none; width: 16em; overflow-y: auto; padding: var(--space-2) var(--space-4) var(--space-4); border-right: 1px solid var(--border); background: var(--help-side); }
#help-panel .help-side h2 { font-size: var(--text-heading); margin: 0.6em 0 0.4em; }
#help-panel .help-side ul { margin: 0.2em 0; padding-left: 1.1em; list-style: none; }
#help-panel .help-side > ul { padding-left: 0; }
#help-panel .help-side a { display: inline-block; padding: 0.15em 0; }
#help-panel .help-main { flex: 1; min-width: 0; max-width: 48em; overflow-y: auto; padding: var(--space-2) 1.5em var(--space-4); }
main.help-window #help-panel:not(.help-columns) { overflow-y: auto; padding: var(--space-2) 1.5em var(--space-4); }
/* A narrow help window puts the contents above the page. */
@media (max-width: 36em) {
  main.help-window #help-panel.help-columns { flex-direction: column; overflow-y: auto; }
  #help-panel .help-side { width: auto; max-height: 35vh; border-right: none; border-bottom: 1px solid var(--border); }
  #help-panel .help-main { overflow-y: visible; }
}
main.help-window { background: var(--help-paper); }
/* In a very narrow window the help covers the view from the right, as a drawer, instead of taking room beside it. panel_strip.help_overlay_below is the same width. */
@media (max-width: 44em) {
  #help-panel { position: absolute; top: 0; right: 0; bottom: 0; width: auto; max-width: none; left: 2.6em; box-shadow: -0.3em 0 0.8em var(--shadow); }
}

/* Printing. The Print button puts #print-view in the page while the print
   dialog is open: the heading and the URL, and the drawing with its ruler
   fitted to a landscape page of the paper size that the user chooses.
   Without it, as with Ctrl+P, the drawing panel prints as it is on screen.
   The page has no margin, so the browser's own header and footer, with the
   full URL, have no room; #print-view keeps 10mm from the edge instead. */
#print-view, #help-print-view { display: none; }
/* A help page prints in portrait with a margin, while the drawing keeps its landscape page without one. */
@page help { size: portrait; margin: 15mm; }
@page { size: landscape; margin: 0; }
@media print {
  #shell { display: block; height: auto; }
  #shell > header, #signatures, .panel-strip, #instrument-list, #side-panel, main:not(.help-window) > #help-panel, #tabs, #toolbar, dialog, #update-toast { display: none !important; }
  #shell:has(#print-view) > main { display: none; }
  #print-view { display: flex; flex-direction: column; box-sizing: border-box; width: 100%; height: 100vh; padding: 10mm; }
  .print-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 2em; font-size: 10pt; color: black; }
  .print-heading ul { margin: 0; padding: 0; list-style: none; }
  .print-heading .swatch { margin-right: 0.4em; }
  .print-address { white-space: nowrap; }
  #print-view > svg { display: block; flex: 1; min-height: 0; width: 100%; }
  #shell:has(#help-print-view) > main { display: none; }
  #help-print-view { display: block; page: help; font-size: 11pt; line-height: 1.4; color: black; }
  #help-print-view h1 { font-size: 16pt; margin: 0 0 0.6em; }
  #help-print-view h2 { font-size: 12pt; margin: 1em 0 0.3em; }
  /* Ctrl+P in the help window prints the page alone too. */
  main.help-window #help-panel .help-side, main.help-window #help-panel .help-bar, main.help-window #help-panel .help-follow, main.help-window #help-panel .help-steps { display: none !important; }
}
