/* ============================================================
   VEA Inventory — Stake Sheets
   List view reuses the tickets-table styles from base.css;
   this file covers the editor layout, capture state, drawing
   toolbar, legend and crop modal.
   ============================================================ */

.hidden { display: none !important; }

/* ── List view: preview grid ────────────────────────────────── */
.sheet-list-section {
  max-width: 1400px;
  margin: 0 auto;
  padding: 4px 24px 48px;
}

.sl-heading {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 10px 0 14px;
}
.sl-heading h2 { font-size: 17px; font-weight: 700; }

.sl-count {
  font-size: 12px;
  font-weight: 700;
  color: var(--color-text-muted);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 20px;
  padding: 2px 9px;
}

.sheet-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 16px;
}

.sl-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 64px 20px;
}

.sheet-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  cursor: pointer;
  transition: border-color .15s, box-shadow .15s;
}
.sheet-card:hover {
  border-color: var(--color-border-hover);
  box-shadow: var(--shadow-md);
}

.sc-thumb {
  aspect-ratio: 570 / 490;
  background: var(--color-bg);
  border-bottom: 1px solid var(--color-border);
}
.sc-thumb canvas { width: 100%; height: 100%; display: block; }

.sc-nomap {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: var(--color-text-faint);
  font-size: 12px;
}
.sc-nomap span { font-size: 30px; }

.sc-body { padding: 10px 12px 9px; }

.sc-title {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
}
.sc-title strong { font-size: 13.5px; white-space: nowrap; }
.sc-name {
  font-size: 12.5px;
  color: var(--color-text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sc-addr {
  font-size: 12px;
  color: var(--color-text-faint);
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sc-foot {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  min-width: 0;
}
.sc-foot .tag {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 45%;
}
.sc-date {
  flex: 1;
  font-size: 11.5px;
  color: var(--color-text-faint);
  text-align: right;
}

/* ── Full-page editor: site nav hidden, back button in the bar ── */
body.editor-full .app-header { display: none; }
body.editor-full .sheet {
  /* header gone, tools live in the top bar → one bar + padding ≈ 78px */
  width: min(100%, calc((100vh - 78px) * 792 / 612));
}

/* ── Editor top bar ─────────────────────────────────────────── */
.stake-bar { flex-wrap: wrap; }

.stake-bar-title {
  font-size: 15px;
  font-weight: 700;
}

.save-state {
  font-size: 12px;
  color: var(--color-text-faint);
}
.save-state.dirty { color: #b45309; }

/* ══ The sheet — live replica of the printed landscape-letter page ══
   All geometry mirrors the SHEET constants in stake.js (792×612pt):
   positions are % of the page, fonts/borders use cqw (1cqw = 1% of
   sheet width) so the whole thing scales like a printed page. */

.sheet-wrap { padding: 0 24px 12px; }

.sheet {
  position: relative;
  /* Contain-fit: full width unless that would push the sheet past the
     bottom of the window — then scale down so the whole page stays in
     frame. 195px ≈ header + controls bar + tool strip + padding. */
  width: min(100%, calc((100vh - 195px) * 792 / 612));
  margin: 0 auto;
  aspect-ratio: 792 / 612;
  background: #fff;
  border: 1px solid var(--color-border);
  box-shadow: var(--shadow-md);
  container-type: inline-size;
}

/* printed border frame: 12pt inset */
.sheet-frame {
  position: absolute;
  inset: 1.96% 1.52%;
  border: 0.28cqw solid #14161a;
  pointer-events: none;
}

/* title: 32pt left, 24pt type */
.sheet-title {
  position: absolute;
  left: 4.04%;
  top: 3.4%;
  font-size: 3.03cqw;
  font-weight: 800;
  letter-spacing: .01em;
  color: #14161a;
  line-height: 1.2;
}

/* map slot: x32 y60 w570 h490 */
.sheet-map {
  position: absolute;
  left: 4.04%;
  top: 9.80%;
  width: 71.97%;
  height: 80.07%;
  background: var(--color-bg);
  border: 1px solid #14161a;
}
.sheet-map > * { position: absolute; inset: 0; }

/* legend row under the map */
.sheet-legend {
  position: absolute;
  left: 4.04%;
  top: 90.5%;
  width: 71.97%;
  height: 6.2%;
  display: flex;
  align-items: center;
  gap: 2.6cqw;
  font-size: 1.45cqw;
  color: #14161a;
  white-space: nowrap;
  overflow: hidden;
}

/* side column: x610 y24 w158 h564 */
.sheet-side {
  position: absolute;
  left: 77.02%;
  top: 3.92%;
  width: 19.95%;
  height: 92.16%;
  border: 0.13cqw solid #8a95a3;
  border-radius: 0.8cqw;
  padding: 1.3cqw;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  background: #fff;
}

.ss-label {
  font-size: 1.25cqw;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: #14161a;
  margin: 1.1cqw 0 0.35cqw;
}
.ss-label:first-child { margin-top: 0; }

.sheet-side input,
.sheet-side textarea {
  width: 100%;
  font-family: inherit;
  font-size: 1.5cqw;
  line-height: 1.35;
  padding: 0.5cqw 0.7cqw;
  border: 1px solid var(--color-border);
  border-radius: 0.4cqw;
  background: var(--color-bg);
  resize: none;
}
.sheet-side input:focus,
.sheet-side textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  background: #fff;
}

.ss-hint {
  font-size: 1.1cqw;
  color: var(--color-text-faint);
  margin-top: 0.5cqw;
}

.sheet-side .attach-btn {
  width: 100%;
  justify-content: center;
  font-size: 1.3cqw;
  padding: 0.6cqw;
}
.sheet-side .attached-ticket {
  font-size: 1.35cqw;
  padding: 0.6cqw 0.8cqw;
}

/* ── Map slot states ────────────────────────────────────────── */
.map-dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
  border: 2px dashed var(--color-border-hover);
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.map-dropzone:hover,
.map-dropzone.drag-over {
  border-color: var(--color-primary);
  background: var(--color-primary-light);
}

.frame-viewport {
  line-height: 0;
  background: #fff;
  overflow: hidden;
  cursor: grab;
  touch-action: none;
}
.frame-viewport:active { cursor: grabbing; }

#frameCanvas { display: block; width: 100%; height: 100%; }

.capture-hint {
  font-size: 11.5px;
  color: var(--color-text-faint);
  line-height: 1.4;
  flex: 1;
}

/* ── State tools live inside the top bar ────────────────────── */
.strip-row {
  display: flex;
  align-items: center;
  gap: 6px;
}
.stake-bar .capture-hint {
  flex: 0 1 auto;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 210px;
}

.tool-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 30px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  cursor: pointer;
  color: var(--color-text-muted);
  transition: background .12s, border-color .12s;
}
.tool-btn:hover  { border-color: var(--color-border-hover); background: var(--color-bg); }
.tool-btn.active {
  border-color: var(--color-primary);
  background: var(--color-primary-light);
  color: var(--color-primary);
}

.tool-sep {
  width: 1px;
  height: 20px;
  background: var(--color-border);
  margin: 0 4px;
}

.path-set-btn {
  height: 30px;
  min-width: 46px;
  padding: 0 12px;
}

.text-tool-btn {
  font-family: Georgia, serif;
  font-size: 17px;
  font-weight: 700;
}

.text-toolbar { gap: 5px; }
.text-mode-label {
  color: var(--color-text);
  font-size: 12px;
}

.compact-select,
.tool-stepper {
  display: flex;
  align-items: center;
}
.compact-select .tool-btn,
.tool-stepper .tool-btn {
  border-radius: 0;
  margin-left: -1px;
}
.compact-select .tool-btn:first-child,
.tool-stepper .tool-btn:first-child { margin-left: 0; border-radius: var(--radius-md) 0 0 var(--radius-md); }
.compact-select .tool-btn:last-child,
.tool-stepper .tool-btn:last-child { border-radius: 0 var(--radius-md) var(--radius-md) 0; }
.compact-select .tool-btn.selected {
  z-index: 1;
  border-color: var(--color-primary);
  background: var(--color-primary-light);
  color: var(--color-primary);
}

.color-trigger span {
  width: 17px;
  height: 17px;
  border: 1px solid #8a95a3;
  border-radius: 50%;
  background: var(--text-color, #000);
}

#textBackgroundChoices .tool-btn::before {
  content: '';
  width: 15px;
  height: 15px;
  border: 1px solid #8a95a3;
  border-radius: 2px;
}
#textBackgroundChoices .bg-transparent::before {
  background: linear-gradient(135deg, #fff 43%, #dc2626 44%, #dc2626 56%, #fff 57%);
}
#textBackgroundChoices .bg-black::before { background: #000; }
#textBackgroundChoices .bg-white::before { background: #fff; }

.font-select .tool-btn { font-size: 15px; }
.font-select .font-sans { font-family: Arial, Helvetica, sans-serif; }
.font-select .font-mono { font-family: "Courier New", Courier, monospace; }
.font-select .font-hand { font-family: "Segoe Print", "Bradley Hand", "Comic Sans MS", cursive; }

.tool-stepper output {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 35px;
  height: 30px;
  border-top: 1px solid var(--color-border);
  border-bottom: 1px solid var(--color-border);
  background: #fff;
  color: var(--color-text);
  font-size: 11px;
  font-weight: 700;
}
.rotation-stepper output {
  min-width: 42px;
  cursor: pointer;
}
.text-set-btn { height: 30px; padding: 0 13px; }
.text-mode-hint {
  color: var(--color-text-faint);
  font-size: 11px;
  white-space: nowrap;
}

.text-color-menu {
  position: fixed;
  z-index: 110;
  top: 55px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 11px;
  border: 1px solid var(--color-border-hover);
  border-radius: 20px;
  background: rgba(255, 255, 255, .98);
  box-shadow: var(--shadow-lg);
}
.text-color-menu > button,
.text-color-menu .custom-color {
  position: relative;
  flex: 0 0 28px;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 2px solid #fff;
  border-radius: 50%;
  background: var(--swatch);
  box-shadow: 0 0 0 1px var(--color-border-hover);
  cursor: pointer;
}
.text-color-menu > button.selected,
.text-color-menu .custom-color.selected {
  box-shadow: 0 0 0 2px var(--color-primary);
}
.text-color-menu .custom-color {
  overflow: hidden;
  background: conic-gradient(#dc2626, #f59e0b, #16a34a, #2563eb, #7c3aed, #dc2626);
}
.text-color-menu .custom-color input[type="color"] {
  position: absolute;
  inset: -8px;
  width: 42px;
  height: 42px;
  opacity: 0;
  cursor: pointer;
}

/* ── Annotate canvas (fills the map slot) ───────────────────── */
#drawCanvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}
#drawCanvas.tool-cursor { cursor: crosshair; }
#drawCanvas.erase-cursor { cursor: pointer; }
#drawCanvas.select-cursor { cursor: default; }
#drawCanvas.dragging-object { cursor: grabbing; }

.sheet-map > .text-inline-editor {
  inset: auto;
  z-index: 4;
  min-width: 34px;
  max-width: 92%;
  height: auto;
  padding: .12em .3em;
  border: 1px dashed var(--color-primary);
  border-radius: 2px;
  outline: 2px solid rgba(232, 82, 10, .16);
  text-align: center;
  line-height: 1.18;
  transform-origin: center;
}

.sheet-map > .path-hint {
  inset: auto 8px 8px;
  width: auto;
  height: auto;
  z-index: 2;
  pointer-events: none;
  padding: 5px 8px;
  border-radius: 4px;
  background: rgba(28, 31, 38, 0.82);
  color: #fff;
  font-size: clamp(9px, 1.15cqw, 12px);
  line-height: 1.25;
}

/* ── Legend items (cqw so they print-scale with the sheet) ──── */
.leg {
  display: inline-flex;
  align-items: center;
  gap: 0.75cqw;
}

.leg-swatch { display: inline-block; }
.leg-splice { background: #c8cdd4; border: 0.22cqw solid #4b5563; width: 2.1cqw; height: 1.15cqw; }
.leg-nid    { background: #fef2f2; border: 0.22cqw solid #dc2626; width: 1.15cqw; height: 1.8cqw; }
.leg-pole   { background: #8b6c53; border: 0.13cqw solid #5f4a38; border-radius: 50%; width: 1.5cqw; height: 1.5cqw; }
.leg-line   { width: 3.2cqw; border-top: 0.32cqw solid #dc2626; }
.leg-line.dashed { border-top-style: dashed; }
.leg-house  { width: 1.7cqw; height: 1.7cqw; }

/* ── Sidebar bits ───────────────────────────────────────────── */
.attach-btn { width: 100%; justify-content: center; }

.attached-ticket {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  background: var(--color-primary-light);
  border: 1px solid var(--color-primary);
  border-radius: var(--radius-md);
  font-size: 13px;
}
.attached-ticket .at-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
  color: var(--color-primary);
  text-decoration: none;
}
.attached-ticket .at-remove {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--color-text-muted);
  font-size: 14px;
  padding: 2px 4px;
}
.attached-ticket .at-remove:hover { color: var(--color-danger); }

/* ── Ticket picker modal ────────────────────────────────────── */
.ticket-pick-list {
  max-height: 55vh;
  overflow-y: auto;
  padding: 6px;
}

.ticket-pick-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  background: none;
  border: none;
  border-bottom: 1px solid var(--color-border);
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
}
.ticket-pick-row:hover { background: var(--color-primary-light); }
.ticket-pick-row .tp-title { flex: 1; font-weight: 600; }
.ticket-pick-row .tp-meta  { color: var(--color-text-faint); font-size: 12px; }

/* ── Responsive: below ~700px the sheet un-flattens into a stack ── */
@media (max-width: 700px) {
  .text-mode-hint { display: none; }
  .text-color-menu { top: 49px; }

  .sheet-wrap { padding: 0 12px 24px; }
  .sheet { aspect-ratio: auto; container-type: normal; }
  .sheet-frame { display: none; }
  .sheet-title {
    position: static;
    font-size: 18px;
    padding: 12px 12px 8px;
  }
  .sheet-map {
    position: relative;
    left: 0; top: 0;
    width: 100%;
    height: auto;
    aspect-ratio: 570 / 490;
  }
  .sheet-legend {
    position: static;
    width: 100%;
    height: auto;
    font-size: 11px;
    gap: 14px;
    padding: 8px 12px;
    flex-wrap: wrap;
    white-space: normal;
  }
  .leg { gap: 6px; }
  .leg-splice { width: 16px; height: 9px;  border-width: 2px; }
  .leg-nid    { width: 9px;  height: 14px; border-width: 2px; }
  .leg-pole   { width: 12px; height: 12px; border-width: 1px; }
  .leg-line   { width: 24px; border-top-width: 2.5px; }
  .leg-house  { width: 13px; height: 13px; }
  .sheet-side {
    position: static;
    width: 100%;
    height: auto;
    border: none;
    border-top: 1px solid var(--color-border);
    border-radius: 0;
    padding: 12px;
  }
  .ss-label { font-size: 11px; margin: 10px 0 4px; }
  .sheet-side input, .sheet-side textarea { font-size: 14px; padding: 6px 8px; border-radius: 4px; }
  .ss-hint { font-size: 11px; }
  .sheet-side .attach-btn { font-size: 13px; padding: 7px; }
  .sheet-side .attached-ticket { font-size: 13px; padding: 8px 10px; }
}
