/* Caboodle Spreadsheet – Copyright (C) 2026 the Caboodle authors – GNU GPL v3, see LICENSE.txt
   SPDX-License-Identifier: GPL-3.0-only */
/* Shared look for every program: design tokens, buttons, menus, popovers, the colour picker, dialogs, toasts.
   Programs style themselves with these tokens only, so a theme (dark mode) changes everything at once.
   The program's colour: shared/chrome.js puts its three shades on <html> as --prog-c, --prog-c-strong, --prog-c-soft;
   use --prog, --prog-strong and --prog-soft (or --accent …), which the dark theme lightens or darkens.
   Dark mode: shared/shell.js sets data-theme="dark" on <html> (it follows the computer unless View › Theme says
   otherwise). Pages, slides, pictures and canvases keep their own colours. */
:root {
  /* surfaces */
  --bg: #fafafb;            /* the page behind everything */
  --surface: #ffffff;       /* bars, menus, cards, dialogs */
  --panel: #fafafb;         /* the left and right panels */
  --sunk: #f4f4f6;          /* recessed strips: status bar, inputs on panels */
  --desk: #e8e9ed;          /* around pages, slides and images */
  --page: #f4f4f6;          /* behind the cards in the record programs */
  --toolbar: #f4f4f6;
  /* text */
  --text: #18181b;
  --text-2: #3f3f46;
  --muted: #5f5f6b;
  --faint: #9a9aa3;
  /* lines */
  --line: #e6e6eb;
  --line-soft: #f0f0f3;
  --line-strong: #d4d4da;
  /* states */
  --hover: #f1f1f4;
  --prog: var(--prog-c, #4675c2);
  --prog-strong: var(--prog-c-strong, #2d569a);
  --prog-soft: var(--prog-c-soft, #ecf4ff);
  --accent: var(--prog);
  --accent-strong: var(--prog-strong);
  --accent-soft: var(--prog-soft);
  --active: var(--prog-soft);
  /* selection, handles and guides on canvases (the same in every program) */
  --sel: #2b6fd6;
  --sel-soft: rgba(43, 111, 214, .12);
  --guide: #e5397a;
  /* meaning */
  --danger: #b8342c;
  --danger-soft: #fdecea;
  --ok: #2d7a3a;
  --ok-soft: #e7f5ea;
  --warn: #8a5a00;
  --warn-soft: #fff4d6;
  --info: #2d569a;
  --info-soft: #ecf4ff;
  /* shape */
  --radius-s: 6px;
  --radius: 8px;
  --radius-l: 12px;
  --shadow: 0 1px 2px rgba(24, 24, 27, .08), 0 2px 6px rgba(24, 24, 27, .08);
  --pop-shadow: 0 16px 40px rgba(24, 24, 27, .14), 0 2px 6px rgba(24, 24, 27, .06);
  --scrim: rgba(24, 24, 27, .45);
  --mono: "Geist Mono", ui-monospace, Consolas, monospace;
  font-family: "Geist", system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--text);
}

/* ---------- dark: the same tokens, for the dark theme (data-theme on <html>, set by shared/shell.js) ---------- */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #141417;
  --surface: #1e1e22;
  --panel: #19191c;
  --sunk: #121215;
  --desk: #0d0d0f;
  --page: #141417;
  --toolbar: #232328;
  --text: #ececf1;
  --text-2: #c9c9d1;
  --muted: #9d9da8;
  --faint: #6d6d77;
  --line: #303036;
  --line-soft: #26262b;
  --line-strong: #44444c;
  --hover: #2a2a30;
  --prog: color-mix(in oklab, var(--prog-c, #4675c2) 82%, white);
  --prog-strong: color-mix(in oklab, var(--prog-c, #4675c2) 52%, white);
  --prog-soft: color-mix(in oklab, var(--prog-c, #4675c2) 28%, #1e1e22);
  --sel: #4a8af0;
  --sel-soft: rgba(74, 138, 240, .22);
  --guide: #ff5c96;
  --danger: #f2837b;
  --danger-soft: #3b1f1d;
  --ok: #72c483;
  --ok-soft: #1a3020;
  --warn: #e6b452;
  --warn-soft: #382c12;
  --info: #93b5f0;
  --info-soft: #1c283c;
  --shadow: 0 1px 2px rgba(0, 0, 0, .45), 0 2px 6px rgba(0, 0, 0, .35);
  --pop-shadow: 0 16px 40px rgba(0, 0, 0, .55), 0 2px 6px rgba(0, 0, 0, .4);
  --scrim: rgba(0, 0, 0, .6);
}
/* another program's colour on one element (files lists, Home): style="${OfficeShell.tint(p)}" */
.tint { --tint-strong: var(--tint-strong-l); --tint-soft: var(--tint-soft-l); }
:root[data-theme="dark"] .tint { --tint-strong: color-mix(in oklab, var(--tint) 52%, white); --tint-soft: color-mix(in oklab, var(--tint) 28%, var(--surface)); }
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); }
body { font-size: 13.5px; -webkit-font-smoothing: antialiased; }
button { font: inherit; color: inherit; }
.material-symbols-outlined { font-size: 20px; line-height: 1; vertical-align: middle; user-select: none; font-variation-settings: 'opsz' 20; }
.hidden, [hidden] { display: none !important; }
.muted { color: var(--muted); font-size: 12px; }

#app { display: flex; flex-direction: column; height: 100%; }

.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--surface); border-radius: var(--radius); padding: 6px 14px; cursor: pointer; font-size: 13.5px; white-space: nowrap; color: var(--text); }
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--text); border-color: var(--text); color: var(--surface); font-weight: 500; }
.btn.primary:hover { background: var(--text-2); border-color: var(--text-2); }
.btn.danger { color: var(--danger); }
.btn .material-symbols-outlined { font-size: 18px; }
.icon-btn { border: 0; background: none; width: 32px; height: 32px; border-radius: var(--radius); display: inline-flex; align-items: center; justify-content: center; cursor: pointer; color: var(--muted); flex: none; }
.icon-btn:hover { background: var(--hover); color: var(--text); }
.link-btn { border: 0; background: none; color: var(--accent-strong); cursor: pointer; padding: 4px 6px; font-size: 13px; }
.link-btn:hover { text-decoration: underline; }

/* small toolbar buttons inside panels and popovers */
.tb-btn { position: relative; border: 0; background: none; min-width: 28px; height: 28px; border-radius: var(--radius-s); display: inline-flex; align-items: center; justify-content: center; cursor: pointer; padding: 0 2px; color: var(--text-2); flex: none; }
.tb-btn:hover { background: var(--hover); }
.tb-btn.active { background: var(--accent-soft); color: var(--accent-strong); }
.tb-btn:disabled { opacity: .38; cursor: default; background: none; }
.tb-sep { width: 1px; height: 20px; background: var(--line); margin: 0 5px; flex: none; }
.tb-select { border: 0; background: transparent; height: 28px; border-radius: var(--radius-s); font: inherit; font-size: 13px; padding: 0 2px; cursor: pointer; color: var(--text-2); flex: none; }
.tb-select:hover { background: var(--hover); }
.tb-color { flex-direction: column; }
.tb-color .material-symbols-outlined { font-size: 18px; margin-top: -2px; }
.color-bar { display: block; width: 18px; height: 4px; margin-top: 1px; border-radius: 1px; box-shadow: inset 0 0 0 1px rgba(0,0,0,.15); }

/* ---------- menus & popovers ---------- */
.menu { position: fixed; z-index: 1120; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-l); box-shadow: var(--pop-shadow); padding: 6px; min-width: 220px; max-height: calc(100vh - 16px); overflow-y: auto; font-size: 13px; color: var(--text); }
.menu-item { display: flex; align-items: center; gap: 8px; padding: 4px 12px 4px 4px; border-radius: var(--radius-s); cursor: pointer; white-space: nowrap; min-height: 30px; }
.menu-item.hover, .menu-item:hover { background: var(--hover); }
.menu-item.disabled { opacity: .45; cursor: default; }
.mi-icon { width: 24px; display: inline-flex; justify-content: center; color: var(--text-2); }
.mi-label { flex: 1; }
.mi-hint { color: var(--muted); font-size: 12px; margin-left: 20px; }
.mi-short { color: var(--muted); font-family: var(--mono); font-size: 11px; margin-left: 24px; }
.mi-arrow { color: var(--muted); display: inline-flex; margin-right: -8px; }
.menu-sep { height: 1px; background: var(--line-soft); margin: 6px 0; }
.swatch { width: 16px; height: 16px; border-radius: 50%; display: inline-block; border: 1px solid rgba(0,0,0,.15); }

.popover { position: fixed; z-index: 1200; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-l); box-shadow: var(--pop-shadow); padding: 8px; color: var(--text); }
/* the shared color picker: suggested colors, and to their right a custom picker */
.color-pop { display: flex; flex-direction: column; gap: 6px; padding: 2px; }
.cp-head { display: flex; align-items: center; }
.cp-head .link-btn { padding: 2px 2px; }
.cp-body { display: flex; gap: 14px; align-items: flex-start; }
.cp-sugg { display: flex; flex-direction: column; gap: 3px; }
.cp-label { font-size: 11px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); margin: 0 0 3px 1px; }
.cp-recent .cp-label { margin-top: 8px; }
.color-row { display: flex; gap: 3px; }
.color-row.cp-gap { margin-bottom: 5px; }
.color-sw { width: 18px; height: 18px; border-radius: 50%; border: 1px solid rgba(0,0,0,.12); cursor: pointer; padding: 0; flex: none; }
.color-sw:hover { transform: scale(1.15); box-shadow: 0 0 0 1px var(--surface), 0 0 0 2px var(--text-2); }
.color-sw.sel { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--text); }
.color-sw:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.cp-custom { width: 176px; flex: none; display: flex; flex-direction: column; gap: 8px; padding-left: 14px; border-left: 1px solid var(--line-soft); }
.cp-sv { position: relative; height: 112px; border-radius: 6px; cursor: crosshair; touch-action: none; outline: none; }
.cp-sv-w, .cp-sv-b { position: absolute; inset: 0; border-radius: 6px; pointer-events: none; }
.cp-sv-w { background: linear-gradient(to right, #fff, rgba(255,255,255,0)); }
.cp-sv-b { background: linear-gradient(to top, #000, rgba(0,0,0,0)); }
.cp-hue { position: relative; height: 12px; border-radius: 6px; cursor: pointer; touch-action: none; outline: none;
  background: linear-gradient(to right, #f00 0%, #ff0 16.7%, #0f0 33.3%, #0ff 50%, #00f 66.7%, #f0f 83.3%, #f00 100%); }
.cp-knob { position: absolute; width: 14px; height: 14px; border-radius: 50%; border: 2px solid #fff; box-sizing: border-box; pointer-events: none;
  box-shadow: 0 0 0 1px rgba(0,0,0,.35); transform: translate(-50%, -50%); }
.cp-hue .cp-knob { top: 50%; }
.cp-sv:focus-visible .cp-knob, .cp-hue:focus-visible .cp-knob { box-shadow: 0 0 0 2px var(--accent); }
.cp-fields { display: flex; align-items: center; gap: 6px; }
.cp-preview { width: 28px; height: 28px; border-radius: 6px; flex: none; box-shadow: inset 0 0 0 1px rgba(0,0,0,.15); }
.cp-hex { flex: 1; min-width: 0; width: 0; height: 28px; padding: 0 7px; border: 1px solid var(--line); border-radius: 6px; font: 12px var(--mono); color: var(--text); background: var(--surface); }
.cp-hex:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.cp-eye { width: 28px; height: 28px; flex: none; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); display: inline-flex; align-items: center; justify-content: center; cursor: pointer; color: var(--text); padding: 0; }
.cp-eye:hover { background: var(--hover); }
.cp-eye .material-symbols-outlined { font-size: 17px; }
.cp-use { justify-content: center; }
.color-pop.inline { padding: 0; }
.color-pop.inline .cp-body { flex-direction: column; gap: 10px; align-items: stretch; }
.color-pop.inline .cp-custom { width: auto; padding-left: 0; border-left: 0; }
.color-pop.inline .cp-sv { height: 76px; }
.color-pop.inline .cp-body { gap: 8px; }
.color-pop.inline .cp-recent .cp-label { margin-top: 5px; }
.color-pop.inline .cp-custom { gap: 7px; }
/* a color field in forms and dialogs (opens the picker) */
.color-field { display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 2px 0 4px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); cursor: pointer; font: 12px var(--mono); color: var(--text); vertical-align: middle; }
.color-field:hover { background: var(--hover); }
.color-field:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.cf-swatch { width: 20px; height: 20px; border-radius: 4px; box-shadow: inset 0 0 0 1px rgba(0,0,0,.15); flex: none; }
.color-field .material-symbols-outlined { font-size: 18px; color: var(--muted); }
.icon-pop { display: flex; gap: 2px; }
/* ---------- dialogs ---------- */
.modal-overlay { position: fixed; inset: 0; z-index: 1150; background: var(--scrim); display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal-overlay.nonblocking { background: transparent; pointer-events: none; align-items: flex-start; justify-content: flex-end; padding-top: 150px; padding-right: 24px; }
.modal-overlay.nonblocking .modal { pointer-events: auto; }
.modal { background: var(--surface); color: var(--text); border-radius: 14px; box-shadow: 0 12px 40px rgba(0,0,0,.25); width: 480px; max-width: 100%; max-height: calc(100vh - 32px); display: flex; flex-direction: column; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 16px 8px 24px; }
.modal-head h2 { margin: 0; font-size: 18px; font-weight: 600; }
.modal-body { padding: 8px 24px; overflow: auto; }
.modal-body p { line-height: 1.5; }
.modal-body h3 { font-size: 14px; font-weight: 600; margin: 16px 0 6px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 24px 18px; }
.modal-foot .left { margin-right: auto; }
.form { display: flex; flex-direction: column; gap: 10px; }
label.field { display: flex; flex-direction: column; gap: 4px; }
.field-label { font-size: 12px; color: var(--muted); }
.inp { border: 1px solid var(--line-strong); border-radius: var(--radius-s); padding: 7px 9px; font: inherit; font-size: 13.5px; background: var(--surface); color: var(--text); width: 100%; }
.inp:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.note-input { resize: vertical; min-height: 100px; font-family: inherit; }
label.inline { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; margin-right: 10px; cursor: pointer; }
.kbd-table { border-collapse: collapse; width: 100%; font-size: 13px; }
.kbd-table td { padding: 5px 6px; border-bottom: 1px solid var(--line-soft); }
kbd { font: 11.5px var(--mono); background: var(--sunk); color: var(--text); border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; white-space: nowrap; }
ul.feat { padding-left: 18px; margin: 4px 0; line-height: 1.55; font-size: 13px; }

/* ---------- misc ---------- */
/* messages: a stack at the bottom centre, the newest at the bottom */
.toast-stack { position: fixed; left: 50%; bottom: 56px; transform: translateX(-50%); z-index: 2000; display: flex; flex-direction: column; align-items: center; gap: 8px; width: max-content; max-width: calc(100vw - 32px); pointer-events: none; }
.toast { position: relative; transform: translateY(20px); opacity: 0; background: #18181b; color: #fafafb; padding: 10px 18px; border-radius: var(--radius); font-size: 13.5px; line-height: 1.45; transition: opacity .2s, transform .2s; max-width: min(640px, calc(100vw - 32px)); box-shadow: var(--shadow); pointer-events: auto; cursor: default; }
.toast.show { opacity: 1; transform: none; }
.toast.error { background: #7f1d1d; }
#loading { position: fixed; inset: 0; display: flex; flex-direction: column; gap: 14px; align-items: center; justify-content: center; background: var(--bg); z-index: 3000; color: var(--muted); }
.spinner { width: 32px; height: 32px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.load-error { max-width: 480px; text-align: center; line-height: 1.6; color: var(--text); padding: 16px; }
/* dropping files on a program: the same look everywhere – a frame round the window and what will happen, at the bottom
   (nothing covers the page, so pictures can be dropped exactly where they should go) */
.drop-hint { display: none; position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); z-index: 2500; max-width: min(640px, calc(100vw - 48px)); padding: 10px 18px; border-radius: 999px; background: var(--accent-strong); color: #fff; font-size: 13.5px; font-weight: 500; text-align: center; box-shadow: 0 6px 20px rgba(0, 0, 0, .25); pointer-events: none; }
body.dragging .drop-hint { display: block; }
body.dragging::after { content: ''; position: fixed; inset: 8px; border: 2.5px dashed var(--accent); border-radius: 14px; background: color-mix(in srgb, var(--accent-soft) 16%, transparent); pointer-events: none; z-index: 2499; }

