/* RedColumn components. Uses only tokens from tokens.css (var(--c-…)), so light and dark both work.
   Spec: replica/design/components.md  ·  Preview: design.html */

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--c-bg);
  color: var(--c-text);
  font: var(--fw-base) var(--fs-base)/var(--lh-base) var(--font-sans);
  -webkit-font-smoothing: antialiased;
}

:focus-visible { outline: 2px solid var(--c-focus); outline-offset: 1px; }
.icon { width: 15px; height: 15px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.mono { font-family: var(--font-mono); }
.muted { color: var(--c-text-muted); }
.sep { width: 1px; align-self: stretch; margin: 6px var(--sp-2); background: var(--c-border); }

/* ---------- App shell ---------- */
.app {
  display: grid;
  height: 100%;
  grid-template-rows: var(--size-menubar) var(--size-toolbar) var(--size-tabs) 1fr var(--size-panel-bottom) var(--size-statusbar);
  grid-template-columns: var(--size-panel-left) 1fr var(--size-panel-right);
  grid-template-areas:
    "menu menu menu"
    "tools tools tools"
    "tabs tabs tabs"
    "left canvas right"
    "bottom bottom bottom"
    "status status status";
}

/* ---------- Menubar ---------- */
.menubar { grid-area: menu; display: flex; align-items: center; gap: 2px; padding: 0 var(--sp-3); background: var(--c-chrome); border-bottom: 1px solid var(--c-border); }
/* The brand (logo option B): the amber mark, then "Romby" strong and "Reader" quieter */
.menubar .brand { display: inline-flex; align-items: center; gap: 7px; margin-right: var(--sp-5); white-space: nowrap; letter-spacing: -.015em; }
.menubar .brand-mark { width: 18px; height: 18px; flex: none; }
.menubar .brand b { font-weight: 700; color: var(--c-text); }
.menubar .brand span { margin-left: -3px; font-weight: 400; color: var(--c-text); opacity: .62; }
.menubar button { all: unset; padding: 3px 8px; border-radius: var(--r-sm); cursor: default; }
.menubar button:hover, .menubar button[aria-expanded="true"] { background: var(--c-surface-2); }
.menubar .spacer { flex: 1; }

/* ---------- Toolbar + tool buttons ---------- */
.toolbar { grid-area: tools; display: flex; align-items: center; gap: 2px; padding: 0 var(--sp-3); background: var(--c-chrome); border-bottom: 1px solid var(--c-border); overflow-x: auto; }
.tool {
  position: relative; display: inline-grid; place-items: center;
  width: var(--size-tool-button); height: var(--size-tool-button);
  border: 0; border-radius: var(--r-sm); background: transparent; color: var(--c-text); cursor: default;
}
.tool:hover { background: var(--c-surface-2); }
.tool:active { transform: translateY(1px); }
.tool[aria-pressed="true"] { background: var(--c-surface-2); box-shadow: inset 0 0 0 1px var(--c-border); }
.tool[aria-pressed="true"]::after { content: ""; position: absolute; left: 4px; right: 4px; bottom: 0; height: 2px; background: var(--c-accent); }
.tool.locked { background: var(--c-surface-2); box-shadow: inset 0 0 0 1px var(--c-accent); color: var(--c-accent-strong); }
.tool:disabled { color: var(--c-text-muted); opacity: .5; }

/* ---------- Document tabs ---------- */
.tabs { display: flex; align-items: flex-end; gap: 2px; padding: 0 var(--sp-3); background: var(--c-surface-2); border-bottom: 1px solid var(--c-border); }
.tab { display: flex; align-items: center; gap: var(--sp-3); height: 22px; font-size: var(--fs-sm); padding: 0 var(--sp-4); border: 1px solid transparent; border-bottom: 0; border-radius: var(--r-md) var(--r-md) 0 0; background: transparent; color: var(--c-text-muted); font: inherit; }
.tab:hover { color: var(--c-text); }
.tab[aria-selected="true"] { background: var(--c-bg); color: var(--c-text); border-color: var(--c-border); box-shadow: inset 0 2px 0 var(--c-accent); }
.tab .dirty { width: 7px; height: 7px; border-radius: 50%; background: var(--c-accent); }

/* ---------- Panels ---------- */
.panel { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--c-bg); }
.panel.left { grid-area: left; border-right: 1px solid var(--c-border); }
.panel.right { grid-area: right; border-left: 1px solid var(--c-border); }
.panel.bottom { grid-area: bottom; border-top: 1px solid var(--c-border); }
.panel-tabs { display: flex; gap: 2px; padding: 0 var(--sp-2); background: var(--c-surface); border-bottom: 1px solid var(--c-border); }
.panel-tabs button { all: unset; padding: 6px 8px; font-size: var(--fs-sm); color: var(--c-text-muted); border-bottom: 2px solid transparent; }
.panel-tabs button[aria-selected="true"] { color: var(--c-text); border-bottom-color: var(--c-accent); }
.panel-header { display: flex; align-items: center; gap: var(--sp-2); height: 24px; padding: 0 var(--sp-4); font-size: var(--fs-xs); font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--c-text-muted); background: var(--c-surface); border-bottom: 1px solid var(--c-border); }
.panel-header .spacer { flex: 1; }
.panel-body { flex: 1; overflow: auto; padding: var(--sp-4); }
.section-label { margin: var(--sp-5) 0 var(--sp-3); font-size: var(--fs-xs); font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--c-text-muted); }
.section-label:first-child { margin-top: 0; }
.empty { display: grid; place-items: center; gap: var(--sp-3); padding: var(--sp-7) var(--sp-5); text-align: center; color: var(--c-text-muted); }

/* ---------- Thumbnails ---------- */
.thumbs { display: grid; gap: var(--sp-5); justify-items: center; }
.thumb { display: grid; gap: var(--sp-2); justify-items: center; font-size: var(--fs-xs); color: var(--c-text-muted); }
.thumb .page { width: 150px; aspect-ratio: 36/24; background: var(--c-sheet); box-shadow: var(--shadow-sheet); outline: 2px solid transparent; outline-offset: 2px; }
.thumb.current .page { outline-color: var(--c-accent); }
.thumb.current { color: var(--c-text); }

/* ---------- Tree rows (layers / bookmarks) ---------- */
.tree-row { display: flex; align-items: center; gap: var(--sp-3); height: var(--size-row); padding: 0 var(--sp-2); border-radius: var(--r-sm); }
.tree-row:hover { background: var(--c-surface); }
.tree-row.off { color: var(--c-text-muted); }

/* ---------- Canvas + sheet ---------- */
.canvas { grid-area: canvas; position: relative; overflow: hidden; background: var(--c-canvas); display: grid; place-items: center; }
.sheet { position: relative; width: min(88%, 900px); aspect-ratio: 36/24; background: var(--c-sheet); box-shadow: var(--shadow-sheet); }
.sheet svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.readout { position: absolute; padding: 2px 6px; border-radius: var(--r-sm); background: #1c1f24; color: #fff; font: 600 var(--fs-xs)/var(--lh-xs) var(--font-mono); white-space: nowrap; pointer-events: none; }
/* The live measuring readout: drafting style, not a bubble. Square-ish corners, steady-width digits, two rows. */
.stage .readout { display: grid; gap: 1px; padding: 4px 7px 4px; border-radius: 3px; background: rgba(29, 29, 31, .92);
  box-shadow: 0 0 0 .5px rgba(255, 255, 255, .12); font-weight: 500; font-variant-numeric: tabular-nums; }
.readout .ro-row { display: flex; gap: 10px; justify-content: space-between; }
.readout b { font-weight: 600; font-size: 11px; }
.readout .ro-dim { color: #a1a1a6; }
.readout .ro-small { font-size: 9px; line-height: 12px; letter-spacing: .04em; text-transform: uppercase; }
.readout .ro-snap { color: #fbbf24; }
.zoom-float { position: absolute; right: var(--sp-5); bottom: var(--sp-5); display: flex; gap: 2px; padding: 2px; border-radius: var(--r-md); background: var(--c-bg); border: 1px solid var(--c-border); box-shadow: var(--shadow-pop); }

/* ---------- Form controls ---------- */
.field { display: grid; grid-template-columns: 76px 1fr; align-items: center; gap: var(--sp-2) var(--sp-4); margin-bottom: var(--sp-2); font-size: var(--fs-sm); }
.field > label { color: var(--c-text-muted); }
.input, .select {
  width: 100%; height: var(--size-input); padding: 0 var(--sp-3);
  border: 1px solid var(--c-border-input); border-radius: var(--r-sm);
  background: var(--c-bg); color: var(--c-text); font: inherit;
}
.input:hover, .select:hover { border-color: var(--c-text-muted); }
.input:focus-visible, .select:focus-visible { outline: 2px solid var(--c-focus); outline-offset: 0; }
.input[aria-invalid="true"] { border-color: var(--c-danger); }
.help-error { grid-column: 2; margin-top: -4px; color: var(--c-danger); font-size: var(--fs-xs); }
.input.mono { font-family: var(--font-mono); }
.row { display: flex; align-items: center; gap: var(--sp-3); }
input[type="range"] { flex: 1; accent-color: var(--c-accent); }
input[type="checkbox"] { accent-color: var(--c-accent); }

.segmented { display: inline-flex; padding: 2px; gap: 2px; border-radius: var(--r-md); background: var(--c-surface-2); }
.segmented button { border: 0; padding: 2px 8px; border-radius: var(--r-sm); background: transparent; color: var(--c-text-muted); font: inherit; font-size: var(--fs-sm); }
.segmented button[aria-pressed="true"] { background: var(--c-bg); color: var(--c-text); box-shadow: 0 1px 2px rgba(0,0,0,.15); }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-3); height: 24px; font-size: var(--fs-sm); padding: 0 var(--sp-5); border: 1px solid transparent; border-radius: var(--r-sm); font: inherit; font-weight: 600; cursor: default; }
.btn.sm { height: 22px; padding: 0 var(--sp-4); font-size: var(--fs-sm); }
.btn.primary { background: var(--c-accent); color: var(--c-on-accent); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.secondary { background: var(--c-surface-2); color: var(--c-text); border-color: var(--c-border); }
.btn.secondary:hover { border-color: var(--c-border-input); }
.btn.ghost { background: transparent; color: var(--c-text); }
.btn.ghost:hover { background: var(--c-surface-2); }
.btn.danger { background: var(--c-danger); color: #fff; }
.btn:disabled { opacity: .45; }
.btn .spinner { width: 12px; height: 12px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Color swatches ---------- */
.swatches { display: grid; grid-template-columns: repeat(6, 22px); gap: 6px; }
.swatch { width: 18px; height: 18px; border-radius: 1px; border: 1px solid rgba(0,0,0,.25); padding: 0; }
.swatch[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--c-bg), 0 0 0 4px var(--c-text); }

/* ---------- Data table (Markups List) ---------- */
.table-toolbar { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-2) var(--sp-4); border-bottom: 1px solid var(--c-border); background: var(--c-surface); }
.table-toolbar .input { width: 220px; }
.table-toolbar .spacer { flex: 1; }
.table-wrap { flex: 1; overflow: auto; }
table.grid { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.grid th { position: sticky; top: 0; z-index: 1; height: var(--size-row); padding: 0 var(--sp-4); text-align: left; font-weight: 600; color: var(--c-text-muted); background: var(--c-surface); border-bottom: 1px solid var(--c-border); white-space: nowrap; }
.grid th[aria-sort] { color: var(--c-text); }
.grid td { height: var(--size-row); padding: 0 var(--sp-4); border-bottom: 1px solid var(--c-border); white-space: nowrap; }
.grid td.num { text-align: right; font-family: var(--font-mono); }
.grid tbody tr:hover { background: var(--c-surface); }
.grid tbody tr[aria-selected="true"] { background: var(--c-accent-soft); box-shadow: inset 3px 0 0 var(--c-accent); }
.grid tfoot td { font-weight: 600; background: var(--c-surface); border-top: 1px solid var(--c-border); }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 2px; border: 1px solid rgba(0,0,0,.25); vertical-align: -1px; }

/* ---------- Status pill ---------- */
.pill { display: inline-flex; align-items: center; height: 18px; padding: 0 8px; border-radius: var(--r-pill); font-size: var(--fs-xs); font-weight: 600; border: 1px solid var(--c-border); color: var(--c-text-muted); }
.pill.accepted  { color: var(--c-success); border-color: transparent; background: color-mix(in srgb, var(--c-success) 15%, transparent); }
.pill.rejected  { color: var(--c-danger);  border-color: transparent; background: color-mix(in srgb, var(--c-danger) 15%, transparent); }
.pill.completed { color: var(--c-info);    border-color: transparent; background: color-mix(in srgb, var(--c-info) 15%, transparent); }
.pill.cancelled { color: var(--c-text-muted); border-color: transparent; background: var(--c-surface-2); text-decoration: line-through; }

/* ---------- Menus, dialogs, tooltips, toasts ---------- */
.menu { min-width: 200px; padding: var(--sp-2); border-radius: var(--r-md); background: var(--c-bg); border: 1px solid var(--c-border); box-shadow: var(--shadow-pop); font-size: var(--fs-sm); }
.menu button { all: unset; display: flex; width: calc(100% - 16px); align-items: center; gap: var(--sp-4); height: var(--size-row); padding: 0 var(--sp-4); border-radius: var(--r-sm); }
.menu button:hover, .menu button:focus-visible { background: var(--c-accent-soft); outline: none; }
.menu button .kbd { margin-left: auto; color: var(--c-text-muted); }
.menu hr { border: 0; border-top: 1px solid var(--c-border); margin: var(--sp-2) 0; }

.dialog { width: 360px; border-radius: var(--r-lg); background: var(--c-bg); border: 1px solid var(--c-border); box-shadow: var(--shadow-pop); }
.dialog header { padding: var(--sp-5) var(--sp-6) 0; font-size: var(--fs-lg); font-weight: 600; }
.dialog .body { padding: var(--sp-5) var(--sp-6); }
.dialog footer { display: flex; justify-content: flex-end; gap: var(--sp-3); padding: var(--sp-4) var(--sp-6); background: var(--c-surface); border-top: 1px solid var(--c-border); border-radius: 0 0 var(--r-lg) var(--r-lg); }

.tooltip { display: inline-flex; gap: var(--sp-4); padding: 4px 8px; border-radius: var(--r-sm); background: var(--c-text); color: var(--c-bg); font-size: var(--fs-xs); }
.tooltip .kbd { opacity: .7; }
.toast { display: inline-flex; align-items: center; gap: var(--sp-5); padding: var(--sp-2) var(--sp-4); border-radius: var(--r-sm); background: var(--c-text); color: var(--c-bg); box-shadow: var(--shadow-pop); font-size: var(--fs-sm); }
.toast .btn { color: var(--c-accent); background: transparent; padding: 0; height: auto; }

/* ---------- Status bar ---------- */
.statusbar { grid-area: status; display: flex; align-items: center; gap: var(--sp-2); padding: 0 var(--sp-3); font-size: var(--fs-xs); color: var(--c-text-muted); background: var(--c-surface); border-top: 1px solid var(--c-border); }
.statusbar button { all: unset; padding: 1px 6px; border-radius: var(--r-sm); }
.statusbar button:hover { background: var(--c-surface-2); color: var(--c-text); }
.statusbar .on { color: var(--c-accent-strong); font-weight: 600; }
.statusbar .spacer { flex: 1; }
