/*
 * PlanInk — PDF markup tool for large-format plan sets, served over the LAN.
 *
 * Copyright © 2025 N2EDU INC. All rights reserved.
 * Unauthorized use, reproduction, or distribution of this software,
 * in whole or in part, is strictly prohibited without prior written
 * permission from N2EDU INC.
 */

/* PlanInk — graphite chrome, redline accent, title-block lettering */

:root {
  --bg-chrome: #1a1d21;
  --bg-panel: #23272d;
  --bg-viewer: #2c3036;
  --ink: #d7dade;
  --ink-dim: #8b9097;
  --line: #383d44;
  --redline: #d8260f;
  --redline-soft: rgba(216, 38, 15, 0.16);
  --focus: #4fb8c9;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, "Segoe UI", Roboto, Ubuntu, sans-serif;
  background: var(--bg-chrome);
  color: var(--ink);
}

body { display: flex; flex-direction: column; }

/* ---------- Toolbar: styled like a drawing title block ---------- */

#toolbar-inner {
  display: flex;
  align-items: center;
  gap: 4px;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: thin;
  -ms-overflow-style: none;
  white-space: nowrap;
  width: 100%;
  padding-bottom: 2px;
}
/* Chrome scrollbar: hidden by default, appears only on hover */
#toolbar-inner::-webkit-scrollbar { height: 3px; }
#toolbar-inner::-webkit-scrollbar-track {
  background: transparent;
}
#toolbar-inner::-webkit-scrollbar-thumb {
  background-color: transparent;
  border-radius: 3px;
}
#toolbar-inner:hover::-webkit-scrollbar-thumb {
  background-color: var(--line, #cccccc);
}
/* Firefox */
#toolbar-inner { scrollbar-width: thin; scrollbar-color: transparent transparent; }
#toolbar-inner:hover { scrollbar-color: var(--line, #cccccc) transparent; }

#toolbar {
  display: flex;
  align-items: stretch;
  gap: 10px;
  padding: 6px 12px;
  background: var(--bg-chrome);
  border-bottom: 1px solid var(--line);
  user-select: none;
  -webkit-user-select: none;
}

.tb-group { display: flex; align-items: center; gap: 4px; }
.tb-rule { width: 1px; background: var(--line); margin: 4px 2px; }
.tb-spacer { flex: 1; }

.tb-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 52px;
  padding: 5px 8px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 3px;
  color: var(--ink-dim);
  cursor: pointer;
}
.tb-btn svg {
  width: 18px; height: 18px;
  fill: none; stroke: currentColor; stroke-width: 1.6;
  stroke-linecap: round; stroke-linejoin: round;
}
.tb-btn span {
  font-family: ui-monospace, "Cascadia Mono", "SF Mono", Menlo, monospace;
  font-size: 9px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
.tb-btn:hover:not(:disabled) { color: var(--ink); border-color: var(--line); }
.tb-btn:disabled { opacity: 0.35; cursor: default; }
.tb-btn.active {
  color: var(--redline);
  background: var(--redline-soft);
  border-color: var(--redline);
}
.tb-btn.sq { min-width: 32px; font-size: 16px; padding: 8px; color: var(--ink-dim); }
.tb-btn.sq:hover { color: var(--ink); }
.tb-btn:focus-visible, input:focus-visible, #btn-open-empty:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 1px;
}

/* .swatch removed — toolbar swatches replaced with native color picker */

/* Color picker dropdown */
.color-picker {
  position: relative;
  display: inline-flex;
  align-items: center;
}
.color-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 7px;
  border-radius: 5px;
  border: 1.5px solid var(--line);
  background: var(--bg-chrome);
  color: var(--fg);
  cursor: pointer;
  font-size: 0.72rem;
  height: 28px;
  white-space: nowrap;
}
.color-btn::before {
  content: "";
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--c);
  border: 1.5px solid var(--line);
  flex-shrink: 0;
}
.color-btn svg { display: none; }
.color-btn:hover { border-color: var(--redline); }
/* color-dropdown removed — native OS picker used instead */

#width-group {
  gap: 8px;
  font-family: ui-monospace, Menlo, monospace;
  font-size: 9px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-dim);
}
#width-group input { width: 90px; accent-color: var(--redline); }
#width-readout { min-width: 44px; color: var(--ink); }

#zoom-group { gap: 6px; }
#zoom-readout {
  font-family: ui-monospace, Menlo, monospace;
  font-size: 11px;
  min-width: 46px;
  text-align: center;
  color: var(--ink);
}

/* ---------- Viewer ---------- */

#viewer {
  flex: 1;
  overflow: auto;
  background: var(--bg-viewer);
  position: relative;
}
#viewer.tool-pan { cursor: grab; }
#viewer.tool-pan.panning { cursor: grabbing; }
#viewer.tool-pen, #viewer.tool-highlighter { cursor: crosshair; }
#viewer.tool-eraser { cursor: cell; }
/* select tool cursor managed via JS inline style */

#pages {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  padding: 24px;
  width: max-content;
  min-width: 100%;
}

.page {
  position: relative;
  background: #fff;
  box-shadow: 0 2px 14px rgba(0, 0, 0, 0.45);
  flex: none;
}
/* tiles is now a <canvas> — one GPU texture per page, no img compositing */
.page canvas.tiles {
  position: absolute;
  top: 0; left: 0;
  display: block;
  image-rendering: auto;
}
.page canvas.sel-overlay {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  pointer-events: none;
}

.page canvas.ink {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
}
.page .page-label {
  position: absolute;
  bottom: -18px;
  right: 0;
  font-family: ui-monospace, Menlo, monospace;
  font-size: 10px;
  letter-spacing: 0.14em;
  color: var(--ink-dim);
}

/* ---------- Empty state ---------- */

#empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  text-align: center;
  padding: 24px;
  /* faint drafting grid */
  background-image:
    linear-gradient(var(--line) 1px, transparent 1px),
    linear-gradient(90deg, var(--line) 1px, transparent 1px);
  background-size: 48px 48px;
  background-position: center;
}
.es-logo {
  width: 220px;
  max-width: 60vw;
  height: auto;
  opacity: 0.85;
  filter: drop-shadow(0 2px 8px rgba(0,0,0,0.15));
  user-select: none;
  -webkit-user-drag: none;
}
#empty-state p { color: var(--ink); max-width: 420px; background: var(--bg-viewer); }
#empty-state .es-hint { color: var(--ink-dim); font-size: 13px; }
#btn-open-empty {
  margin-top: 8px;
  padding: 10px 22px;
  font-family: ui-monospace, Menlo, monospace;
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #fff;
  background: var(--redline);
  border: none;
  border-radius: 3px;
  cursor: pointer;
}
#btn-open-empty:hover { filter: brightness(1.1); }

/* ---------- Status bar ---------- */

#statusbar {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 12px;
  border-top: 1px solid var(--line);
  font-family: ui-monospace, Menlo, monospace;
  font-size: 10px;
  letter-spacing: 0.08em;
  color: var(--ink-dim);
  background: var(--bg-chrome);
}

@media (prefers-reduced-motion: no-preference) {
  .tb-btn { transition: all 120ms ease; }
}

/* ---------- Shape hint bar ---------- */
#shape-hint {
  display: none;
  padding: 4px 14px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--line);
  font-family: ui-monospace, Menlo, monospace;
  font-size: 10px;
  letter-spacing: 0.1em;
  color: var(--focus);
  text-transform: uppercase;
}
#shape-hint.visible { display: block; }

/* Fill toggle */
.toggle-label {
  display: flex;
  align-items: center;
  gap: 5px;
  font-family: ui-monospace, Menlo, monospace;
  font-size: 9px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-dim);
  cursor: pointer;
  user-select: none;
}
.toggle-label input[type=checkbox] { accent-color: var(--redline); }
#fill-opacity { width: 70px; accent-color: var(--redline); }

/* Shape-tool cursor variants */
#viewer.tool-line,
#viewer.tool-rect,
#viewer.tool-triangle,
#viewer.tool-polygon,
#viewer.tool-arrow,
#viewer.tool-circle,
#viewer.tool-diamond { cursor: crosshair; }

/* Preview canvas (SVG overlay injected per page) */
.page .preview {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: visible;
}

/* ===== THEME VARIABLES ===== */

/* Light theme (explicit) */
[data-theme="light"] {
  --bg:        #f4f4f4;
  --bg-chrome: #ffffff;
  --fg:        #1a1a1a;
  --line:      #cccccc;
  --active:    #1554C9;
  --active-fg: #ffffff;
  --redline:   #D8260F;
  --shadow:    rgba(0,0,0,0.12);
}

/* Dark theme (explicit) */
[data-theme="dark"] {
  --bg:        #1a1a2e;
  --bg-chrome: #16213e;
  --fg:        #e0e0e0;
  --line:      #3a3a5c;
  --active:    #4a7fff;
  --active-fg: #ffffff;
  --redline:   #ff5c42;
  --shadow:    rgba(0,0,0,0.4);
}

/* Auto: follow OS preference */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:        #1a1a2e;
    --bg-chrome: #16213e;
    --fg:        #e0e0e0;
    --line:      #3a3a5c;
    --active:    #4a7fff;
    --active-fg: #ffffff;
    --redline:   #ff5c42;
    --shadow:    rgba(0,0,0,0.4);
  }
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg:        #f4f4f4;
    --bg-chrome: #ffffff;
    --fg:        #1a1a1a;
    --line:      #cccccc;
    --active:    #1554C9;
    --active-fg: #ffffff;
    --redline:   #D8260F;
    --shadow:    rgba(0,0,0,0.12);
  }
}

#theme-group { margin-left: auto; }
#btn-theme { min-width: 64px; }
