/* BCD Markup — iPad + laptop annotation app */

:root {
  --bg: #0f1115;
  --bg-2: #161920;
  --bg-3: #1e222b;
  --bg-4: #262b36;
  --line: #2d3340;
  --line-2: #3a4150;
  --text: #eef0f4;
  --muted: #8b93a1;
  --faint: #5c6472;
  --accent: #e11d2e;
  --accent-soft: rgba(225, 29, 46, 0.16);
  --ok: #3dd68c;
  --warn: #f5c14a;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  --radius: 12px;
  --btn: 44px;
  --btn-sm: 36px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --topbar-h: 52px;
  --tools-h: 56px;
  --notes-w: 320px;
  --notes-h: 240px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; width: 100%;
  background: var(--bg); color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
}
body { padding: var(--safe-t) var(--safe-r) var(--safe-b) var(--safe-l); }
button, input, textarea, select { font: inherit; color: inherit; }
button { appearance: none; background: none; border: 0; padding: 0; cursor: pointer; }
button:focus { outline: none; }
button:focus-visible, .swatch:focus-visible, input:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
img { max-width: 100%; }

.app {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  height: 100%;
  min-height: 0;
}

/* ----- Top bar ----- */
.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: var(--topbar-h);
  padding: 6px 10px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--line);
  user-select: none;
}
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 6px 0 2px;
  flex: 0 0 auto;
  min-width: 0;
}
.brand img { width: 28px; height: 28px; border-radius: 7px; }
.brand-name { font-weight: 700; letter-spacing: -0.02em; font-size: 15px; }
.brand-name span { color: var(--accent); }
.doc-meta {
  flex: 1 1 auto;
  min-width: 0;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pager {
  display: none;
  align-items: center;
  gap: 4px;
  flex: 0 0 auto;
}
.pager.is-on { display: flex; }
.pager output { min-width: 72px; text-align: center; font-variant-numeric: tabular-nums; color: var(--muted); font-size: 13px; }
.topbar-actions { display: flex; align-items: center; gap: 6px; flex: 0 0 auto; margin-left: auto; }

/* ----- Buttons ----- */
.btn, .icon-btn, .tool-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: var(--btn);
  min-width: var(--btn);
  padding: 0 12px;
  border-radius: 10px;
  background: var(--bg-3);
  border: 1px solid var(--line);
  color: var(--text);
  font-weight: 600;
  font-size: 13px;
  white-space: nowrap;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.icon-btn { padding: 0; }
.btn:hover, .icon-btn:hover, .tool-btn:hover {
  background: var(--bg-4);
  border-color: var(--line-2);
}
.btn:active, .icon-btn:active, .tool-btn:active { transform: translateY(1px); }
.btn:disabled, .icon-btn:disabled, .tool-btn:disabled {
  opacity: 0.4; cursor: default; transform: none;
}
.btn-primary {
  background: var(--accent);
  border-color: transparent;
  color: #fff;
}
.btn-primary:hover { background: #f13242; }
.btn-ghost { background: transparent; }
.btn-danger:hover { border-color: var(--accent); color: #ffd4d7; }
.icon-btn svg, .tool-btn svg, .btn svg {
  width: 20px; height: 20px; flex: 0 0 auto;
  stroke: currentColor; fill: none; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round;
}
.tool-btn, .icon-btn { flex-direction: column; gap: 0; }
.tool-btn.is-on, .icon-btn.is-on, .toggle.is-on {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: #ffdadd;
}
.tool-btn .lbl {
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.02em;
  line-height: 1;
  margin-top: 2px;
  color: var(--muted);
}
.tool-btn.is-on .lbl { color: #ffdadd; }

/* ----- Tools row ----- */
.tools {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: var(--tools-h);
  padding: 6px 10px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: thin;
  user-select: none;
}
.tools::-webkit-scrollbar { height: 6px; }
.tool-group {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 0 0 auto;
}
.sep {
  width: 1px; align-self: stretch;
  background: var(--line);
  margin: 6px 6px;
  flex: 0 0 1px;
}
.swatches { display: flex; gap: 6px; align-items: center; padding: 0 4px; }
.swatch {
  width: 28px; height: 28px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.15);
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.3);
  cursor: pointer;
  min-width: 28px;
}
.swatch.is-on {
  outline: 2px solid var(--text);
  outline-offset: 2px;
  border-color: rgba(0,0,0,0.4);
}
.swatch.white { box-shadow: inset 0 0 0 1px #888; }
.thick {
  display: flex; align-items: center; gap: 8px;
  color: var(--muted); font-size: 12px; min-width: 120px;
}
.thick input[type="range"] {
  -webkit-appearance: none; appearance: none;
  height: 4px; background: var(--line-2); border-radius: 4px;
  width: 90px; outline: none;
}
.thick input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--text); cursor: pointer; border: 0;
}
.toggle-label {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: var(--btn); padding: 0 10px;
  border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg-3); color: var(--text);
  font-size: 12px; font-weight: 600; cursor: pointer;
  white-space: nowrap;
}
.toggle-label.is-on { background: var(--accent-soft); border-color: var(--accent); }
.toggle-label input { accent-color: var(--accent); width: 16px; height: 16px; }
.zoom-read {
  min-width: 52px; text-align: center;
  color: var(--muted); font-variant-numeric: tabular-nums; font-size: 12px;
  font-weight: 600;
}

/* ----- Main stage + notes ----- */
.main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--notes-w);
  min-height: 0;
}
.main.notes-collapsed { grid-template-columns: minmax(0, 1fr) 0; }
.main.notes-collapsed .notes { display: none; }

.stage {
  position: relative;
  min-height: 0;
  background-color: #2a2e36;
  background-image:
    linear-gradient(45deg, #252930 25%, transparent 25%),
    linear-gradient(-45deg, #252930 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #252930 75%),
    linear-gradient(-45deg, transparent 75%, #252930 75%);
  background-size: 28px 28px;
  background-position: 0 0, 0 14px, 14px -14px, -14px 0;
  overflow: hidden;
  touch-action: none;
  cursor: crosshair;
}
.stage[data-cursor="pan"] { cursor: grab; }
.stage[data-cursor="panning"] { cursor: grabbing; }
.stage[data-cursor="text"] { cursor: text; }
.stage[data-cursor="pin"] { cursor: pointer; }
.stage canvas {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  touch-action: none;
  display: block;
}

.empty {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 10px;
  padding: 32px 24px;
  text-align: center;
  background: radial-gradient(ellipse at center, rgba(15,17,21,0.55), rgba(15,17,21,0.15));
  pointer-events: none;
}
.empty.is-off { display: none; }
.empty h1 { margin: 8px 0 0; font-size: 28px; letter-spacing: -0.03em; }
.empty p { margin: 0; max-width: 440px; color: var(--muted); line-height: 1.5; }
.empty .row { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 10px; pointer-events: auto; }
.empty kbd, .help kbd {
  display: inline-block;
  padding: 1px 6px;
  border: 1px solid var(--line-2);
  border-bottom-width: 2px;
  border-radius: 6px;
  background: var(--bg-3);
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text);
}

/* text editor overlay */
.text-editor {
  position: absolute;
  z-index: 5;
  min-width: 80px;
  padding: 4px 6px;
  border: 2px solid var(--accent);
  border-radius: 4px;
  background: rgba(15, 17, 21, 0.86);
  color: inherit;
  outline: none;
  resize: both;
  line-height: 1.25;
  box-shadow: var(--shadow);
}

/* pin popover */
.pin-pop {
  position: absolute;
  z-index: 6;
  width: 260px;
  background: var(--bg-2);
  border: 1px solid var(--line-2);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 10px;
  display: none;
}
.pin-pop.is-on { display: block; }
.pin-pop header {
  display: flex; align-items: center; justify-content: space-between;
  font-weight: 700; font-size: 13px; margin-bottom: 6px;
}
.pin-pop textarea {
  width: 100%; min-height: 72px;
  background: var(--bg-3); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px; resize: vertical; outline: none;
}
.pin-pop .row { display: flex; justify-content: flex-end; gap: 6px; margin-top: 8px; }

/* ----- Notes ----- */
.notes {
  display: flex; flex-direction: column;
  min-height: 0;
  background: var(--bg-2);
  border-left: 1px solid var(--line);
}
.notes-head {
  display: flex; align-items: center; gap: 8px;
  min-height: 48px; padding: 6px 12px;
  border-bottom: 1px solid var(--line);
  font-weight: 700;
}
.notes-head span { color: var(--muted); font-weight: 600; font-size: 13px; }
.notes-list {
  flex: 1; min-height: 0; overflow: auto;
  padding: 8px;
  touch-action: pan-y;
}
.note-card {
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px;
  margin-bottom: 8px;
}
.note-card.is-on { border-color: var(--accent); }
.note-card header {
  display: flex; align-items: center; gap: 8px; margin-bottom: 6px;
}
.pin-badge {
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--accent); color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 800; flex: 0 0 auto;
}
.note-card textarea {
  width: 100%; min-height: 56px;
  background: transparent; border: 0; outline: none; resize: vertical;
  color: var(--text); line-height: 1.4;
}
.notes-empty { color: var(--muted); padding: 16px 12px; line-height: 1.5; font-size: 13px; }
.notes-actions { padding: 8px 12px calc(8px + var(--safe-b)); border-top: 1px solid var(--line); }

/* ----- Toast / modal / help ----- */
.toast {
  position: fixed; left: 50%; bottom: calc(24px + var(--safe-b));
  transform: translateX(-50%) translateY(12px);
  background: #111; color: #fff;
  border: 1px solid var(--line-2);
  padding: 10px 16px; border-radius: 10px;
  box-shadow: var(--shadow);
  opacity: 0; pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 50; max-width: 90vw;
  font-weight: 600; font-size: 13px;
}
.toast.is-on { opacity: 1; transform: translateX(-50%) translateY(0); }

.overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.55);
  display: none;
  align-items: center; justify-content: center;
  z-index: 40; padding: 24px;
  touch-action: auto;
}
.overlay.is-on { display: flex; }
.modal {
  width: min(640px, 100%);
  max-height: min(80vh, 720px);
  overflow: auto;
  background: var(--bg-2);
  border: 1px solid var(--line-2);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 20px 22px 18px;
  touch-action: pan-y;
}
.modal h2 { margin: 0 0 12px; font-size: 20px; letter-spacing: -0.02em; }
.modal p { color: var(--muted); line-height: 1.5; }
.help-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 20px;
  margin: 12px 0 0;
  font-size: 13px;
}
.help-grid div { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.help-grid .k { color: var(--muted); }

.install-tip {
  display: none;
  align-items: center; gap: 10px;
  margin: 0 10px 0;
  padding: 8px 10px;
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 12px; color: var(--muted);
}
.install-tip.is-on { display: flex; }
.install-tip p { margin: 0; flex: 1; }

/* ----- Responsive: iPad portrait / narrow ----- */
@media (max-width: 960px), (orientation: portrait) and (max-width: 1180px) {
  .main {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) auto;
  }
  .main.notes-collapsed { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); }
  .notes {
    border-left: 0;
    border-top: 1px solid var(--line);
    max-height: min(38vh, 380px);
  }
  .note-card textarea { min-height: 40px; }
  .brand-name { display: none; }
}

@media (max-width: 820px) {
  .btn .hide-sm { display: none; }
  .doc-meta { display: none; }
  .thick { min-width: 100px; }
  .sep { margin: 4px 3px; }
}

/* Laptop short screens (1366x768 etc.) */
@media (max-height: 800px) {
  :root { --topbar-h: 48px; --tools-h: 48px; --btn: 40px; }
  .tool-btn .lbl { display: none; }
  .topbar, .tools { padding-top: 4px; padding-bottom: 4px; }
}

@media (max-width: 1366px) and (min-width: 961px) {
  :root { --notes-w: 280px; }
}

/* Very wide desktops */
@media (min-width: 1800px) {
  :root { --notes-w: 360px; }
}

/* Prefer denser chrome with a mouse, keep large targets on coarse pointers */
@media (pointer: fine) {
  .btn, .icon-btn, .tool-btn { min-height: 40px; min-width: 40px; }
}

@media (pointer: coarse) {
  .btn, .icon-btn, .tool-btn, .toggle-label { min-height: 44px; min-width: 44px; }
  .swatch { width: 32px; height: 32px; min-width: 32px; }
}

/* Print not really used */
@media print {
  .topbar, .tools, .notes { display: none !important; }
  .main { display: block; }
  .stage { background: #fff; }
}

/* Keep tools on one row at typical laptop widths */
@media (min-width: 1100px) and (max-width: 1500px) and (max-height: 900px) {
  .tool-btn .lbl { display: none; }
  .thick { min-width: 100px; }
  .thick input[type="range"] { width: 72px; }
  .swatches { gap: 4px; }
  .sep { margin: 4px 3px; }
  .toggle-label { padding: 0 8px; }
}
