/* PlatDraft — drafting-table instrument aesthetic */
:root {
  --paper: #f6f2e8;
  --paper-2: #efe9da;
  --paper-3: #e7dfcc;
  --ink: #22303c;
  --ink-soft: #4a5867;
  --line: #cec4ab;
  --line-soft: #ddd5c2;
  --red: #a63a24;
  --green: #3d6b4f;
  --amber: #96690f;
  --blue: #2e4a68;
  --serif: "Spectral", Georgia, "Times New Roman", serif;
  --mono: "IBM Plex Mono", Consolas, "Courier New", monospace;
  --sans: "Archivo", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--sans);
  color: var(--ink);
  background-color: var(--paper);
  background-image:
    repeating-linear-gradient(0deg, transparent, transparent 23px, rgba(46, 74, 104, 0.055) 23px, rgba(46, 74, 104, 0.055) 24px),
    repeating-linear-gradient(90deg, transparent, transparent 23px, rgba(46, 74, 104, 0.055) 23px, rgba(46, 74, 104, 0.055) 24px);
  display: flex;
  flex-direction: column;
}

/* ---------- Top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 10px 20px;
  background: var(--ink);
  color: var(--paper);
  border-bottom: 3px double #0e161d;
}
.brand { display: flex; align-items: baseline; gap: 10px; }
.brand-mark { width: 26px; height: 26px; align-self: center; color: var(--paper); }
.brand-name { font-family: var(--serif); font-weight: 700; font-size: 22px; letter-spacing: 0.5px; }
.brand-tag { font-size: 11px; letter-spacing: 2.2px; text-transform: uppercase; color: #9fb0bf; }
.topbar-actions { display: flex; gap: 8px; }

.btn {
  font-family: var(--sans); font-size: 13px; font-weight: 600; letter-spacing: 0.4px;
  padding: 8px 14px; cursor: pointer; border-radius: 3px;
  border: 1px solid transparent;
  transition: transform 0.06s ease, background 0.15s ease;
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--red); color: #fdf8ef; border-color: #7e2b19; }
.btn.primary:hover { background: #b8452d; }
.btn.ghost { background: transparent; color: var(--paper); border-color: #43525f; }
.btn.ghost:hover { background: #2d3c4a; }
.btn.stamp {
  background: transparent; color: #e8c87a; border: 1px dashed #a5893f;
  font-family: var(--mono); text-transform: uppercase; letter-spacing: 1.5px; font-size: 11px;
}
.btn.stamp.licensed { color: #9fd0ae; border-color: #4d7a5d; }
.btn.wide { width: 100%; }
.workbench .btn.primary { box-shadow: 2px 2px 0 rgba(34, 48, 60, 0.18); }
.workbench .btn.ghost { color: var(--ink); border-color: var(--line); }
.workbench .btn.ghost:hover { background: var(--paper-2); }

/* ---------- Layout ---------- */
.workbench {
  flex: 1; display: grid; grid-template-columns: 440px 1fr; gap: 18px;
  padding: 18px; min-height: 0;
}
@media (max-width: 980px) { .workbench { grid-template-columns: 1fr; } }

.panel.left { display: flex; flex-direction: column; gap: 14px; min-width: 0; overflow-y: auto; }
.panel.right { display: flex; flex-direction: column; gap: 14px; min-width: 0; min-height: 480px; }

.panel-block {
  background: rgba(255, 253, 246, 0.82);
  border: 1px solid var(--line);
  box-shadow: 3px 3px 0 rgba(34, 48, 60, 0.07);
  padding: 14px 16px;
}
.block-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 10px; }
.block-head h2 {
  margin: 0; font-family: var(--serif); font-size: 16px; font-weight: 600;
  letter-spacing: 0.3px;
}
.block-head h2::after { content: ""; display: block; width: 44px; height: 2px; background: var(--red); margin-top: 4px; }
.minilink { background: none; border: none; color: var(--blue); font-size: 12.5px; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; font-family: var(--sans); }
.count { font-family: var(--mono); font-size: 12px; color: var(--ink-soft); }

textarea#deedText {
  width: 100%; min-height: 150px; resize: vertical;
  font-family: var(--mono); font-size: 12.5px; line-height: 1.55;
  color: var(--ink); background: #fffdf6;
  border: 1px solid var(--line); padding: 10px; border-radius: 2px;
}
textarea#deedText:focus, input:focus { outline: 2px solid rgba(46, 74, 104, 0.35); outline-offset: 1px; }
.parse-row { margin-top: 10px; }

.problems { margin-top: 10px; border-left: 3px solid var(--amber); background: #f7efd9; padding: 8px 12px; font-size: 12.5px; }
.problems h3 { margin: 0 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: 1px; color: var(--amber); }
.problems div { font-family: var(--mono); font-size: 11.5px; margin: 3px 0; color: var(--ink-soft); }
.problems b { color: var(--amber); font-weight: 600; }

/* ---------- Calls table ---------- */
.calls-table-wrap { overflow-x: auto; }
table.calls { width: 100%; border-collapse: collapse; font-family: var(--mono); font-size: 13px; }
table.calls th {
  text-align: left; font-family: var(--sans); font-size: 10.5px; text-transform: uppercase;
  letter-spacing: 1.2px; color: var(--ink-soft); font-weight: 600;
  border-bottom: 2px solid var(--ink); padding: 4px 6px;
}
table.calls td { border-bottom: 1px solid var(--line-soft); padding: 3px 6px; vertical-align: middle; }
table.calls td:first-child { color: var(--ink-soft); font-size: 11.5px; width: 26px; }
table.calls input {
  width: 100%; border: 1px solid transparent; background: transparent;
  font-family: var(--mono); font-size: 13px; color: var(--ink); padding: 5px 4px; border-radius: 2px;
}
table.calls input:hover { border-color: var(--line); background: #fffdf6; }
table.calls input:focus { border-color: var(--blue); background: #fffdf6; }
table.calls tr.invalid input { color: var(--red); }
table.calls tr.invalid td:first-child::after { content: " ⚠"; color: var(--red); }
table.calls .curve-note { font-size: 10.5px; color: var(--blue); display: block; padding-left: 4px; }
.rowbtn {
  border: none; background: none; cursor: pointer; font-size: 14px; color: var(--ink-soft);
  padding: 2px 6px; border-radius: 2px;
}
.rowbtn:hover { color: var(--red); background: var(--paper-2); }
.rowbtn.add { color: var(--green); font-weight: 700; }
tr.add-row td { border-bottom: none; padding-top: 8px; }
tr.add-row input { border: 1px dashed var(--line); background: #fffdf6; }

/* ---------- Meta fields ---------- */
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.field-grid label { font-size: 10.5px; text-transform: uppercase; letter-spacing: 1.2px; color: var(--ink-soft); font-weight: 600; display: flex; flex-direction: column; gap: 4px; }
.field-grid input {
  font-family: var(--sans); font-size: 13px; color: var(--ink);
  border: 1px solid var(--line); background: #fffdf6; padding: 7px 8px; border-radius: 2px;
}
.privacy-note { font-size: 12px; color: var(--ink-soft); margin: 2px 4px 12px; }
.privacy-note em { color: var(--green); font-style: normal; font-weight: 600; }

/* ---------- Stats ---------- */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.stat {
  background: rgba(255, 253, 246, 0.82); border: 1px solid var(--line);
  box-shadow: 3px 3px 0 rgba(34, 48, 60, 0.07);
  padding: 10px 14px; display: flex; flex-direction: column; gap: 3px;
}
.stat-label { font-size: 10px; text-transform: uppercase; letter-spacing: 1.4px; color: var(--ink-soft); font-weight: 600; }
.stat-value { font-family: var(--mono); font-size: 17px; font-weight: 500; }
.stat-value.good { color: var(--green); }
.stat-value.warn { color: var(--amber); }
.stat-value.bad { color: var(--red); }
@media (max-width: 1200px) { .stats { grid-template-columns: repeat(2, 1fr); } }

/* ---------- Plat frame ---------- */
.plat-frame {
  position: relative; flex: 1; min-height: 380px;
  background: #fffdf6;
  border: 1px solid var(--ink);
  box-shadow: 4px 4px 0 rgba(34, 48, 60, 0.12);
  padding: 10px;
}
.plat-corner { position: absolute; width: 14px; height: 14px; border-color: var(--red); border-style: solid; border-width: 0; }
.plat-corner.tl { top: 4px; left: 4px; border-top-width: 2px; border-left-width: 2px; }
.plat-corner.tr { top: 4px; right: 4px; border-top-width: 2px; border-right-width: 2px; }
.plat-corner.bl { bottom: 4px; left: 4px; border-bottom-width: 2px; border-left-width: 2px; }
.plat-corner.br { bottom: 4px; right: 4px; border-bottom-width: 2px; border-right-width: 2px; }
.plat-host { position: absolute; inset: 10px; }
.plat-host svg.plat { width: 100%; height: 100%; display: block; }
.plat-empty {
  height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; color: var(--ink-soft); text-align: center; font-size: 14px; line-height: 1.5;
}
.plat-empty svg { width: 84px; height: 84px; opacity: 0.5; }

/* plat drawing text */
.plat text { font-family: var(--mono); }
.plat .parcel { fill: rgba(46, 74, 104, 0.06); stroke: var(--ink); stroke-width: 1.6; }
.plat .call-label { font-size: 11px; fill: var(--ink-soft); }
.plat .closure-gap { stroke: var(--red); stroke-width: 1.4; stroke-dasharray: 6 4; }
.plat .pob { fill: var(--red); }
.plat .pob-label { font-size: 11px; fill: var(--red); font-weight: 600; }
.plat .compass, .plat .scalebar { stroke: var(--ink-soft); fill: var(--ink-soft); }
.plat .compass text, .plat .scalebar text { font-size: 11px; stroke: none; }

/* ---------- Print exhibit ---------- */
#exhibit { display: none; }

@media print {
  body { background: #fff; display: block; }
  #appChrome, .workbench, #licenseDialog { display: none !important; }
  #exhibit { display: block; position: relative; padding: 24pt 30pt; color: #1a2530; }
  .ex-watermark {
    position: fixed; top: 45%; left: 0; right: 0; text-align: center;
    transform: rotate(-24deg); font-family: var(--sans); font-weight: 700;
    font-size: 40pt; letter-spacing: 4pt; color: rgba(166, 58, 36, 0.16);
    pointer-events: none;
  }
  .ex-watermark[hidden] { display: none; }
  .ex-head { display: flex; justify-content: space-between; align-items: flex-start; border-bottom: 2.5pt double #1a2530; padding-bottom: 8pt; }
  .ex-head h1 { font-family: var(--serif); font-size: 19pt; margin: 0 0 3pt; }
  .ex-head p { margin: 0; font-size: 10.5pt; color: #4a5867; }
  .ex-brand { display: flex; align-items: center; gap: 6pt; font-family: var(--serif); font-weight: 700; font-size: 12pt; }
  .ex-brand svg { width: 20pt; height: 20pt; }
  .ex-plat { margin: 12pt auto; height: 300pt; }
  .ex-plat svg { width: 100%; height: 100%; }
  .ex-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18pt; margin-top: 6pt; }
  .ex-grid h3 { font-family: var(--serif); font-size: 11pt; margin: 0 0 5pt; border-bottom: 1pt solid #1a2530; padding-bottom: 2pt; }
  .ex-calls, .ex-report { width: 100%; border-collapse: collapse; font-family: var(--mono); font-size: 8.5pt; }
  .ex-calls th { text-align: left; font-family: var(--sans); font-size: 7pt; text-transform: uppercase; letter-spacing: 1pt; padding: 2pt 4pt; border-bottom: 1pt solid #1a2530; }
  .ex-calls td, .ex-report td { padding: 2.5pt 4pt; border-bottom: 0.5pt solid #c9c0ab; }
  .ex-report td:first-child { font-family: var(--sans); font-size: 8pt; text-transform: uppercase; letter-spacing: 0.8pt; color: #4a5867; }
  .ex-notes { font-size: 9pt; margin: 8pt 0 0; }
  .ex-disclaimer { font-size: 7.5pt; color: #6a7684; margin-top: 8pt; line-height: 1.45; }
  .ex-foot { display: flex; justify-content: space-between; margin-top: 14pt; border-top: 1pt solid #1a2530; padding-top: 5pt; font-size: 9pt; font-family: var(--mono); }
}

/* ---------- License dialog ---------- */
dialog#licenseDialog {
  border: 1px solid var(--ink); border-radius: 3px; padding: 0;
  background: var(--paper); color: var(--ink);
  box-shadow: 6px 6px 0 rgba(34, 48, 60, 0.2);
  width: min(420px, 92vw);
}
dialog#licenseDialog::backdrop { background: rgba(34, 48, 60, 0.45); }
.license-form { padding: 20px 22px; display: flex; flex-direction: column; gap: 12px; }
.license-form h2 { font-family: var(--serif); margin: 0; font-size: 19px; }
.license-status { margin: 0; font-size: 13px; color: var(--ink-soft); }
.license-status.ok { color: var(--green); font-weight: 600; }
.license-form label { font-size: 11px; text-transform: uppercase; letter-spacing: 1.2px; font-weight: 600; color: var(--ink-soft); display: flex; flex-direction: column; gap: 5px; }
.license-form input { font-family: var(--mono); font-size: 14px; padding: 9px 10px; border: 1px solid var(--line); background: #fffdf6; }
.license-hint { margin: 0; font-size: 11.5px; color: var(--ink-soft); }
.license-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
