/* Linework app chrome. The drawing itself is painted on canvas; see src/view/colors.js. */
:root {
  --bg: #16191e;
  --bg-2: #1d2128;
  --bg-3: #262b33;
  --line: #333a44;
  --text: #e8ebef;
  --muted: #a7b0bc;
  --accent: #4d9fff;
  --accent-text: #0b1220;
  --accent-soft: rgba(77, 159, 255, 0.16);
  --danger: #ff6b6b;
  --canvas: #0f1216;
  --card: rgba(29, 33, 40, 0.94);
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.45);
  --focus: #8cc2ff;
  --radius: 8px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: dark;
}
:root[data-theme="paper"] {
  --bg: #f4f5f7;
  --bg-2: #ffffff;
  --bg-3: #e9ecf0;
  --line: #d3d8df;
  --text: #1b2129;
  --muted: #535e6b;
  --accent: #0a5ad4;
  --accent-text: #ffffff;
  --accent-soft: rgba(10, 90, 212, 0.1);
  --danger: #c92a2a;
  --canvas: #ffffff;
  --card: rgba(255, 255, 255, 0.96);
  --shadow: 0 6px 24px rgba(20, 30, 50, 0.18);
  --focus: #0a5ad4;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  grid-template-columns: minmax(0, 1fr); /* never let a wide toolbar widen the page */
  height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 var(--font);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
.ic { width: 20px; height: 20px; flex: none; }
.sr, .skip:not(:focus) { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip:focus { position: fixed; top: 8px; left: 8px; z-index: 100; background: var(--bg-2); color: var(--text); padding: 8px 12px; border-radius: var(--radius); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }
kbd { font: 12px/1 ui-monospace, Consolas, monospace; padding: 2px 5px; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; background: var(--bg-3); }

/* ------------------------------------------------------------------ top bar */
.topbar {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 12px; padding-top: max(6px, env(safe-area-inset-top));
  background: var(--bg-2); border-bottom: 1px solid var(--line);
  min-height: 48px; position: relative;
}
.brand { display: flex; align-items: center; gap: 6px; font-weight: 650; font-size: 16px; letter-spacing: .2px; margin-right: 4px; }
.brand .ic { color: var(--accent); width: 22px; height: 22px; }
.docinfo { display: flex; align-items: center; gap: 8px; min-width: 0; }
.docname { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 36vw; }
.chip { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--bg-3); color: var(--muted); white-space: nowrap; }
.privacy { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; color: var(--muted); white-space: nowrap; }
.privacy .ic { width: 15px; height: 15px; }
.spacer { flex: 1; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 34px; padding: 6px 12px;
  background: var(--bg-3); border: 1px solid var(--line); border-radius: var(--radius);
  cursor: pointer; white-space: nowrap;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.btn.primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn.icon { padding: 6px; min-width: 34px; }
.btn.sm { min-height: 28px; padding: 3px 8px; font-size: 13px; }
.btn.icon.sm { min-width: 28px; padding: 3px; }
.btn.big { min-height: 46px; padding: 10px 22px; font-size: 16px; }

.menu { position: absolute; right: 12px; top: 46px; z-index: 30; background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 4px; display: grid; min-width: 180px; }
.menu button { display: flex; gap: 8px; align-items: center; padding: 10px 12px; background: none; border: 0; border-radius: 6px; text-align: left; cursor: pointer; }
.menu button:hover, .menu button:focus-visible { background: var(--accent-soft); }

/* ------------------------------------------------------------------ ribbon */
.topbar, .ribbon, .workspace, .statusbar { min-width: 0; }
.ribbon { display: flex; align-items: stretch; background: var(--bg-2); border-bottom: 1px solid var(--line); min-height: 58px; }
.tabs { display: flex; flex-direction: column; justify-content: center; gap: 2px; padding: 4px 8px; border-right: 1px solid var(--line); }
.tabs [role="tab"] {
  background: none; border: 0; border-radius: 6px; padding: 3px 12px; text-align: left; cursor: pointer;
  color: var(--muted); font-weight: 600; font-size: 13px; min-height: 22px;
}
.tabs [role="tab"][aria-selected="true"] { background: var(--accent-soft); color: var(--accent); }
.tabs [role="tab"]:hover { color: var(--text); }
.tools { display: flex; align-items: center; gap: 2px; padding: 4px 8px; overflow-x: auto; scrollbar-width: thin; flex: 1; }
.tool {
  display: inline-flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-width: 58px; height: 50px; padding: 4px 6px; flex: none;
  background: none; border: 1px solid transparent; border-radius: var(--radius); cursor: pointer;
  font-size: 12px; color: var(--text);
}
.tool:hover:not(:disabled) { background: var(--bg-3); }
.tool[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.tool:disabled { opacity: .4; cursor: not-allowed; }
.tool .ic { width: 22px; height: 22px; }
.sep { width: 1px; align-self: stretch; margin: 6px 6px; background: var(--line); flex: none; }
.field { display: inline-flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); padding: 0 6px; flex: none; }
.field select, .field input { min-height: 28px; padding: 2px 6px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg-3); color: var(--text); }
.field.author input { width: 120px; }
.swatches { display: flex; align-items: center; gap: 4px; padding: 0 4px; flex: none; }
.swatch { width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--bg-2); outline: 1px solid var(--line); cursor: pointer; padding: 0; background: var(--c, #888); position: relative; }
.swatch[aria-checked="true"] { outline: 2px solid var(--text); outline-offset: 1px; }
.swatch.custom { background: conic-gradient(red, yellow, lime, cyan, blue, magenta, red); display: inline-block; }
.swatch.custom input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; }

/* ------------------------------------------------------------------ workspace */
.workspace { position: relative; display: flex; min-height: 0; }
.stage { position: relative; flex: 1; min-width: 0; overflow: hidden; background: var(--canvas); outline: none; }
.stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#cv-drawing { transform-origin: 0 0; }
#cv-overlay { touch-action: none; cursor: grab; }
#cv-overlay.dragging { cursor: grabbing; }
#cv-overlay.crosshair { cursor: crosshair; }
#cv-overlay.pointer { cursor: pointer; }
#cv-overlay.move { cursor: move; }

.empty { position: absolute; inset: 0; display: grid; place-items: center; overflow: auto; padding: 24px 16px; background: var(--bg); }
.empty-card { max-width: 720px; width: 100%; text-align: center; }
.empty-card .hero { width: 56px; height: 56px; color: var(--accent); }
.empty-card h1 { font-size: 28px; margin: 8px 0 6px; }
.empty-card h2 { font-size: 15px; margin: 26px 0 10px; color: var(--muted); font-weight: 600; }
.lead { font-size: 16px; color: var(--muted); margin: 0 0 18px; }
.hint { color: var(--muted); font-size: 13px; margin: 8px 0 0; }
.promise { display: flex; gap: 10px; align-items: flex-start; text-align: left; max-width: 560px; margin: 20px auto 0; padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg-2); }
.promise .ic { color: var(--accent); margin-top: 1px; }
.samples { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 8px; }
.sample { display: grid; gap: 2px; text-align: left; padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg-2); cursor: pointer; }
.sample:hover { border-color: var(--accent); }
.sample span { font-size: 12px; color: var(--muted); }
.formats { color: var(--muted); font-size: 12px; margin-top: 18px; }

.progress { position: absolute; left: 50%; top: 40%; transform: translate(-50%, -50%); width: min(360px, 80%); padding: 16px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); z-index: 5; }
.progress-label { margin-bottom: 8px; font-weight: 600; }
.bar { height: 6px; border-radius: 3px; background: var(--bg-3); overflow: hidden; }
.fill { height: 100%; width: 0; background: var(--accent); transition: width .12s linear; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.measure-card { position: absolute; left: 12px; bottom: 12px; min-width: 220px; max-width: min(360px, calc(100% - 24px)); padding: 10px 12px; z-index: 4; }
.mc-head { display: flex; align-items: center; justify-content: space-between; color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .4px; }
.mc-value { font-size: 24px; font-weight: 650; font-variant-numeric: tabular-nums; margin: 2px 0; }
.mc-detail { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.mc-hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
.mc-hint:empty { display: none; }

.tool-hint { position: absolute; left: 50%; top: 10px; transform: translateX(-50%); z-index: 4; max-width: calc(100% - 24px); padding: 5px 12px; border-radius: 999px; background: var(--card); border: 1px solid var(--line); box-shadow: var(--shadow); font-size: 13px; color: var(--text); pointer-events: none; text-align: center; }
.finish-bar { position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); display: flex; gap: 8px; z-index: 6; padding: 6px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); }

.text-editor { position: absolute; z-index: 8; width: 260px; padding: 8px; background: var(--card); border: 1px solid var(--accent); border-radius: var(--radius); box-shadow: var(--shadow); }
.text-editor textarea { width: 100%; resize: vertical; min-height: 54px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg-2); }
.te-actions { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 6px; }
.te-hint { font-size: 11px; color: var(--muted); }

/* ------------------------------------------------------------------ layers panel */
.panel { width: 300px; flex: none; display: flex; flex-direction: column; background: var(--bg-2); border-left: 1px solid var(--line); min-height: 0; }
.panel-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px 6px; }
.panel-head h2 { font-size: 15px; margin: 0; }
.panel-head .count { color: var(--muted); font-weight: 400; font-size: 13px; }
.panel-tools { display: flex; gap: 6px; padding: 0 12px 8px; border-bottom: 1px solid var(--line); }
.panel-tools input { flex: 1; min-width: 0; min-height: 28px; padding: 3px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg-3); }
.layer-list { list-style: none; margin: 0; padding: 4px 0; overflow-y: auto; flex: 1; }
.layer { display: flex; align-items: center; gap: 8px; padding: 3px 8px 3px 12px; min-height: 34px; }
.layer:hover { background: var(--bg-3); }
.layer input[type="checkbox"] { width: 17px; height: 17px; accent-color: var(--accent); margin: 0; flex: none; cursor: pointer; }
.layer label { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; cursor: pointer; }
.layer .lname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.layer.off .lname { color: var(--muted); text-decoration: line-through; text-decoration-color: var(--line); }
.layer .ln-count { font-size: 11px; color: var(--muted); margin-left: auto; font-variant-numeric: tabular-nums; }
.layer .sw { width: 14px; height: 14px; border-radius: 3px; border: 1px solid var(--line); flex: none; }
.layer .sw.fg { background: linear-gradient(135deg, #fff 50%, #000 50%); }
.layer .iso { opacity: .55; }
.layer:hover .iso, .layer .iso:focus-visible { opacity: 1; }

/* ------------------------------------------------------------------ status bar + toasts */
.statusbar { display: flex; align-items: center; gap: 14px; padding: 3px 12px; padding-bottom: max(3px, env(safe-area-inset-bottom)); min-height: 28px; background: var(--bg-2); border-top: 1px solid var(--line); font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; }
.st.coords { font-variant-numeric: tabular-nums; color: var(--text); min-width: 210px; }
.st.info { overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.toasts { position: absolute; top: 46px; left: 50%; transform: translateX(-50%); display: grid; gap: 8px; z-index: 9; width: max-content; max-width: min(460px, calc(100% - 24px)); pointer-events: none; }
.toasts > * { pointer-events: auto; }
.toast { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; background: var(--card); border: 1px solid var(--line); border-left: 4px solid var(--accent); border-radius: var(--radius); box-shadow: var(--shadow); animation: toast-in .18s ease-out; }
.toast.warn { border-left-color: #f0a500; }
.toast.error { border-left-color: var(--danger); }
.toast .msg { flex: 1; }
.toast .msg small { display: block; color: var(--muted); margin-top: 2px; }
.toast details { margin-top: 4px; font-size: 12px; color: var(--muted); }
.toast details ul { margin: 4px 0 0; padding-left: 18px; }
.toast .btn { min-height: 26px; }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }

.drop-overlay { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; background: rgba(10, 20, 35, .55); pointer-events: none; }
.drop-overlay > div { display: grid; gap: 6px; text-align: center; padding: 28px 40px; border: 2px dashed var(--accent); border-radius: 16px; background: var(--card); font-size: 20px; font-weight: 600; }
.drop-overlay small { font-size: 13px; color: var(--muted); font-weight: 400; }

/* ------------------------------------------------------------------ dialogs */
dialog { padding: 0; border: 1px solid var(--line); border-radius: 12px; background: var(--bg-2); color: var(--text); box-shadow: var(--shadow); max-width: min(860px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); }
dialog::backdrop { background: rgba(5, 10, 20, .5); }
.dlg { display: flex; flex-direction: column; max-height: calc(100dvh - 26px); }
.dlg-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.dlg-head h2 { margin: 0; font-size: 17px; }
.dlg-body { padding: 12px 16px; overflow: auto; }
.dlg-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--line); }
.help-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 8px 24px; }
.help-grid h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); margin: 8px 0 6px; }
.help-grid dl { display: grid; grid-template-columns: minmax(0, 8.5em) 1fr; gap: 6px 10px; margin: 0; font-size: 13px; }
.help-grid dt { line-height: 1.9; }
.help-grid dd { margin: 0; color: var(--muted); }
.note { font-size: 12px; color: var(--muted); }
.form-grid { display: grid; gap: 12px; min-width: min(420px, calc(100vw - 60px)); }
.form-grid label { display: grid; gap: 4px; font-size: 13px; }
.form-grid input[type="text"] { min-height: 32px; padding: 4px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg-3); }
.form-grid fieldset { border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px 8px; display: flex; gap: 16px; flex-wrap: wrap; }
.form-grid legend { font-size: 12px; color: var(--muted); padding: 0 4px; }
.form-grid .radio, .form-grid .check { display: flex; align-items: center; gap: 6px; }

.show-sm { display: none !important; }

/* ------------------------------------------------------------------ small screens */
@media (max-width: 760px) {
  .privacy span, .hide-sm { display: none !important; }
  .show-sm { display: inline-flex !important; }
  .brand span { display: none; }
  .docname { max-width: 40vw; }
  .ribbon { flex-direction: column; min-height: 0; }
  .tabs { flex-direction: row; border-right: 0; border-bottom: 1px solid var(--line); padding: 4px 8px; }
  .tabs [role="tab"] { flex: 1; text-align: center; padding: 6px 8px; min-height: 32px; }
  .tools { padding: 2px 4px; }
  .tool { min-width: 54px; height: 50px; }
  .field.author input { width: 100px; }
  .panel { position: absolute; right: 0; top: 0; bottom: 0; z-index: 20; width: min(320px, 88vw); box-shadow: var(--shadow); }
  .measure-card { left: 8px; bottom: 8px; min-width: 0; }
  .mc-value { font-size: 20px; }
  .st.coords { min-width: 0; }
  .toasts { top: 8px; }
  .empty-card h1 { font-size: 22px; }
}

/* ------------------------------------------------------------------ print */
#print-root { display: none; }
@media print {
  body { display: block; height: auto; overflow: visible; background: #fff; color: #000; }
  body > :not(#print-root) { display: none !important; }
  #print-root { display: block !important; }
  .print-sheet { width: 100%; height: 100%; display: flex; flex-direction: column; page-break-after: avoid; break-inside: avoid; }
  .print-sheet img { display: block; width: 100%; height: auto; max-height: calc(100vh - 22mm); object-fit: contain; border: 0.3mm solid #000; }
  .title-strip { display: grid; grid-template-columns: 2fr 1fr 1fr 1fr; border: 0.3mm solid #000; border-top: 0; font: 9pt/1.25 Arial, Helvetica, sans-serif; }
  .title-strip > div { padding: 1.2mm 2mm; border-left: 0.3mm solid #000; }
  .title-strip > div:first-child { border-left: 0; }
  .title-strip small { display: block; font-size: 6.5pt; text-transform: uppercase; color: #333; }
  .title-strip strong { font-size: 10pt; }
}
