/* PLOTLINE application shell.
 *
 * P1 builds the STRUCTURE the DESIGN LOCK names — top command bar, left
 * grouped command rail, canvas, right Site-Dossier / permit panel, bottom
 * command line + snap/status bar. P7 (Donna) owns the finish.
 */

* { box-sizing: border-box; }

html, body {
  margin: 0; height: 100%;
  background: var(--bg); color: var(--ink);
  font-family: var(--font-ui);
  font-size: 13px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

#app {
  display: grid;
  grid-template-rows: 46px minmax(0, 1fr) 34px 26px;
  grid-template-columns: 232px minmax(0, 1fr) 320px;
  grid-template-areas:
    "topbar topbar topbar"
    "rail   canvas dossier"
    "cmdline cmdline cmdline"
    "status status status";
  height: 100vh;
}

/* ---------------- top command bar ---------------- */

.topbar {
  grid-area: topbar;
  display: flex; align-items: center; gap: 14px;
  padding: 0 14px;
  background: var(--chrome);
  border-bottom: 1px solid var(--line);
  min-width: 0;
}

.brand {
  display: flex; align-items: center; gap: 8px; flex: 0 0 auto;
  font-weight: 700; letter-spacing: .02em; font-size: 15px;
  white-space: nowrap;
}
.brand .dot { color: var(--accent); }
.brand small {
  color: var(--muted); font-size: 10px; font-weight: 500;
  letter-spacing: .12em; text-transform: uppercase; margin-left: 1px;
}
.brand-mark {
  width: 22px; height: 22px; flex: 0 0 auto;
}
.brand-mark rect {
  stroke: var(--accent); stroke-width: 1.6;
}
.brand-mark path {
  stroke: var(--ink); stroke-width: 1.7; stroke-linecap: round;
}
.brand-mark circle {
  fill: var(--accent);
}
.brand-mark .brand-blue {
  stroke: var(--blueprint); stroke-width: 1.6; stroke-dasharray: 2.4 2.2;
}
.brand-mark .brand-blue-fill {
  fill: var(--blueprint);
}

.menubar {
  display: flex; align-items: center; gap: 2px; flex-wrap: nowrap;
  min-width: 0;
}
.menubar button {
  background: none; border: 0; color: var(--muted); cursor: pointer;
  font: inherit; font-size: 12.5px; border-radius: 6px; padding: 6px 9px;
}
.menubar button:hover { background: var(--chrome-2); color: var(--ink); }

.addressbar {
  margin-left: auto;
  flex: 1 1 420px; display: flex; gap: 8px; align-items: center; max-width: 560px;
  min-width: 240px;
}

.addressbar input {
  flex: 1; height: 30px; padding: 0 10px;
  background: var(--panel); color: var(--ink);
  border: 1px solid var(--line); border-radius: 7px;
  font-family: var(--font-ui); font-size: 12.5px;
  min-width: 0;
}

.btn {
  height: 30px; padding: 0 12px;
  background: var(--panel); color: var(--muted);
  border: 1px solid var(--line); border-radius: 7px;
  font-family: var(--font-ui); font-size: 12px; cursor: pointer;
  white-space: nowrap;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #04222a; font-weight: 700; }
.btn:focus-visible, input:focus-visible, .cmd-item:focus-visible,
.panel-tab:focus-visible, .toggle:focus-visible, select:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}

/* ---------------- left command rail ---------------- */

.rail {
  grid-area: rail;
  background: var(--chrome);
  border-right: 1px solid var(--line);
  overflow-y: auto; padding: 8px 8px 12px;
}

.cmd-group-title {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 10px 6px 5px;
  font-size: 9.5px; letter-spacing: .13em; text-transform: uppercase;
  color: var(--faint); font-weight: 700;
}
/* The live/total count per group. The rail states what it can actually do
   rather than implying the whole catalog runs. */
.cmd-count { font-family: var(--font-mono); letter-spacing: 0; opacity: .8; }

.cmd-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 6px 7px; margin: 0 0 3px;
  font-size: 11.5px; color: var(--muted);
  cursor: pointer; border: 1px solid transparent; border-radius: 6px;
  background: none; width: 100%; text-align: left;
  font-family: var(--font-ui);
  min-height: 27px;
}
.cmd-item:hover { background: var(--chrome-2); color: var(--ink); }
.cmd-item:active { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
.cmd-item[data-live="false"] { color: var(--faint); }
.cmd-item[data-live="false"]::after {
  content: "soon"; font-size: 9px; color: var(--faint);
  text-transform: uppercase; letter-spacing: .06em;
}

/* ---------------- canvas ---------------- */

.canvas-wrap {
  grid-area: canvas; position: relative; background: var(--bg); overflow: hidden;
}
.canvas-wrap::before {
  content: "";
  position: absolute; inset: 14px; z-index: 0; pointer-events: none;
  border: 1px solid color-mix(in srgb, var(--line) 72%, transparent);
  border-radius: 2px;
  box-shadow: var(--shadow);
}
.canvas-wrap canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#c-basemap { z-index: 0; }
#c-static  { z-index: 1; }
#c-active  { z-index: 2; }
#c-overlay { z-index: 3; }

/* The persistent chrome line P4 requires verbatim on the drawing surface. */
.legal-chrome {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 4;
  padding: 5px 10px;
  font-size: 10.5px; color: var(--muted);
  background: color-mix(in srgb, var(--chrome) 88%, transparent);
  border-top: 1px solid var(--line-2);
  pointer-events: none;
  text-align: center;
}

/* ---------------- right dossier / resolver panel ---------------- */

.dossier {
  grid-area: dossier;
  background: var(--chrome);
  border-left: 1px solid var(--line);
  overflow-y: auto; padding: 12px;
}

.panel-title {
  font-size: 10px; letter-spacing: .12em; text-transform: uppercase;
  color: var(--faint); margin: 14px 0 8px; font-weight: 700;
}
.panel-title:first-child { margin-top: 0; }

.kv {
  display: flex; justify-content: space-between; gap: 10px;
  padding: 4px 0; font-size: 12px;
  border-bottom: 1px dotted var(--line-2);
}
.kv:last-child { border-bottom: 0; }
.kv .k { color: var(--muted); }
.kv .v { font-family: var(--font-mono); font-size: 11.5px; text-align: right; color: var(--ink); }

/* ---------------- layer rows ---------------- */

.layer-row { align-items: center; }
.layer-row.is-current { background: var(--accent-soft); border-radius: 6px; margin: 0 -4px; padding: 3px 4px; }
.layer-row.is-current .layer-pick { font-weight: 600; }
.layer-row.is-current .layer-pick::before { content: "▸ "; color: var(--accent); }
.layer-pick, .layer-vis {
  border: none; background: none; padding: 0; cursor: pointer;
  font-family: inherit; font-size: inherit; text-align: inherit;
}
.layer-pick { font-family: var(--font-ui); }
.layer-vis { font-family: var(--font-mono); font-size: 12px; color: var(--muted); text-align: right; }
.layer-pick:hover, .layer-vis:hover { text-decoration: underline; }

.chip {
  display: inline-block; padding: 2px 7px; border-radius: 20px;
  font-size: 10px; letter-spacing: .06em; text-transform: uppercase;
}
.chip.warn { background: var(--flag); color: #1b1200; }
.chip.ok { background: var(--ok); color: #04231a; }

/* ---------------- command line + status bar ---------------- */

.cmdline {
  grid-area: cmdline;
  display: flex; align-items: center; gap: 8px; padding: 0 10px;
  background: var(--chrome); border-top: 1px solid var(--line);
}
.cmdline .prompt { color: var(--accent); font-family: var(--font-mono); font-size: 12px; }
.cmdline input {
  flex: 1; height: 24px; background: transparent; border: none; color: var(--ink);
  font-family: var(--font-mono); font-size: 12.5px;
}
.cmdline input:focus { outline: none; }

.statusbar {
  grid-area: status;
  display: flex; align-items: center; gap: 6px; padding: 0 10px;
  background: var(--chrome-2); border-top: 1px solid var(--line-2);
  font-family: var(--font-mono); font-size: 11px; color: var(--muted);
  min-width: 0;
}

.toggle {
  padding: 1px 7px; border-radius: 5px; cursor: pointer;
  border: 1px solid var(--line); background: var(--panel); color: var(--muted);
  font-family: var(--font-mono); font-size: 10.5px;
}
.toggle[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #04222a; }

.statusbar .coords { margin-left: auto; }

/* ---------------- P3 tabbed panels (Layers · Sheets · Blocks) ---------------- */

.panel-tabs {
  display: flex; gap: 0; margin: 14px -4px 6px;
  border-bottom: 1px solid var(--line);
}
.panel-tab {
  flex: 1; padding: 6px 8px; font-family: var(--font-ui); font-size: 11px;
  letter-spacing: .08em; text-transform: uppercase; color: var(--muted);
  background: none; border: none; border-bottom: 2px solid transparent;
  cursor: pointer;
}
.panel-tab[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); }
.panel-tab:hover { color: var(--ink); }

.panel-body-p3 { margin: 4px -4px 0; }
.panel-title.small { font-size: 9px; color: var(--faint); margin: 10px 0 4px; }

/* Layer manager table */
.lm-table {
  width: 100%; border-collapse: collapse; font-size: 11px;
  font-family: var(--font-mono);
}
.lm-table th {
  text-align: left; font-weight: 500; font-size: 9px; letter-spacing: .06em;
  text-transform: uppercase; color: var(--faint); padding: 4px 3px;
  border-bottom: 1px solid var(--line);
}
.lm-table td { padding: 3px 3px; border-bottom: 1px dotted var(--line-2); }
.lm-table tr.is-current td { background: var(--accent-soft); }
.lm-table tr.is-current .lm-name { font-weight: 600; }
.lm-table tr.is-system .lm-name { opacity: .85; }
.lm-cur, .lm-toggle {
  border: none; background: none; padding: 1px 3px; cursor: pointer;
  color: var(--muted); font-family: inherit; font-size: 10.5px;
}
.lm-cur:hover, .lm-toggle:hover { color: var(--ink); }
.lm-toggle[aria-pressed="true"] { color: var(--accent); }
.lm-name { font-family: var(--font-ui); font-size: 12px; }
.lm-swatch {
  display: inline-block; width: 14px; height: 12px; border: 1px solid var(--line);
  border-radius: 2px; cursor: pointer;
}
.lm-lt, .lm-lw {
  background: var(--panel); border: 1px solid var(--line); border-radius: 4px;
  color: var(--ink); font-family: var(--font-mono); font-size: 10.5px;
  padding: 0 2px; max-width: 78px;
}
.lm-toolbar {
  display: flex; align-items: center; gap: 10px; margin-top: 10px;
}
.lm-hint {
  font-size: 10px; color: var(--faint); flex: 1;
}
.lm-legacy { margin-top: 12px; font-size: 11px; color: var(--faint); }
.lm-legacy summary { cursor: pointer; padding: 3px 0; }

/* Sheet manager */
.sheet-tabs {
  display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 10px;
}
.sheet-tab {
  padding: 3px 10px; font-family: var(--font-mono); font-size: 11px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 5px;
  color: var(--muted); cursor: pointer;
}
.sheet-tab.active {
  background: var(--accent); border-color: var(--accent); color: #04222a; font-weight: 600;
}
.sheet-add {
  padding: 3px 8px; background: transparent; border: 1px dashed var(--line);
  border-radius: 3px; color: var(--faint); cursor: pointer; font-size: 12px;
}
.sheet-detail .kv { margin: 4px 0; align-items: center; }
.sheet-detail .kv input, .sheet-detail .kv select {
  background: var(--chrome-2); border: 1px solid var(--line); border-radius: 3px;
  color: var(--ink); padding: 2px 6px; font-family: var(--font-mono); font-size: 11px;
  max-width: 160px;
}
.tb-fields { margin-top: 12px; }
.tb-field {
  display: grid; grid-template-columns: 1fr 1.6fr; gap: 6px;
  padding: 3px 0; align-items: center; font-size: 11px;
}
.tb-field label {
  display: flex; align-items: center; justify-content: space-between; gap: 4px;
  font-family: var(--font-mono); font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em;
}
.tb-field .tb-source {
  font-size: 8.5px; color: var(--faint); text-transform: lowercase; letter-spacing: 0;
  padding: 0 4px; border: 1px solid var(--line); border-radius: 2px;
}
.tb-field.missing label { color: var(--flag); }
.tb-field.missing .tb-source { color: var(--flag); border-color: var(--flag); }
.tb-field input {
  background: var(--chrome-2); border: 1px solid var(--line); border-radius: 3px;
  color: var(--ink); padding: 2px 6px; font-family: var(--font-mono); font-size: 11px;
}
.tb-field.missing input { border-color: var(--flag); }

/* Block palette */
.bp-count { font-size: 11px; color: var(--muted); margin-bottom: 8px; }
.bp-cat {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 8px 0 4px;
  font-size: 10px; letter-spacing: .10em; text-transform: uppercase; color: var(--faint);
}
.bp-cat-count { font-family: var(--font-mono); }
.bp-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
.bp-tile {
  background: var(--panel); border: 1px solid var(--line); border-radius: 5px;
  padding: 4px; cursor: pointer; color: var(--ink);
  display: flex; flex-direction: column; align-items: center; gap: 3px;
}
.bp-tile:hover { border-color: var(--accent); }
.bp-thumb {
  width: 100%; aspect-ratio: 12 / 6; display: flex; align-items: center; justify-content: center;
  color: var(--accent);
}
.bp-thumb svg { width: 100%; height: 100%; }
.bp-name { font-family: var(--font-mono); font-size: 9.5px; color: var(--muted); text-align: center; word-break: break-all; }

/* ---------------- P4: Site Dossier panel ----------------
 *
 * Every rule below reuses an existing token. No new colour is introduced —
 * the design lock says refine and extend, never depart, and a data panel is
 * exactly where a fresh accent would start to creep in.
 */

.ds-group { margin-bottom: 2px; }

.ds-note {
  font-size: 11px; line-height: 1.45; color: var(--muted);
  margin: 6px 0 8px; padding-left: 8px; border-left: 2px solid var(--line);
}
.ds-warn { border-left-color: var(--flag); color: var(--ink); }

.ds-near { font-size: 11.5px; color: var(--muted); margin: 4px 0 8px; }
.ds-near ul { margin: 4px 0 0; padding-left: 18px; }
.ds-near li { font-family: var(--font-mono); font-size: 11.5px; }

/* candidate picker — the user chooses; the software does not guess */
.ds-cands { list-style: none; margin: 6px 0 0; padding: 0; }
.ds-cands li { margin-bottom: 4px; }
.ds-cand {
  width: 100%; text-align: left; cursor: pointer; color: var(--ink);
  background: var(--chrome-2); border: 1px solid var(--line); border-radius: 3px;
  padding: 6px 8px; font-family: inherit;
  display: flex; flex-direction: column; gap: 2px;
}
.ds-cand:hover { border-color: var(--accent); }
.ds-cand-loc { font-size: 12.5px; }
.ds-cand-meta { font-family: var(--font-mono); font-size: 10.5px; color: var(--muted); }

/* service health — a failed stage is a visible row, never a missing one */
.ds-health { list-style: none; margin: 0; padding: 0; }
.ds-health li {
  border-left: 2px solid var(--line); padding: 4px 0 6px 8px; margin-bottom: 6px;
  display: flex; flex-direction: column; gap: 2px;
}
.ds-health-unavailable, .ds-health-error { border-left-color: var(--bad); }
.ds-health-unverified, .ds-health-no_record, .ds-health-skipped,
.ds-health-disagreement, .ds-health-out_of_coverage { border-left-color: var(--flag); }
.ds-health-src { font-family: var(--font-mono); font-size: 10px; color: var(--faint); }
.ds-health-why { font-size: 11.5px; color: var(--ink); line-height: 1.4; }
.ds-health-eff { font-size: 11px; color: var(--muted); line-height: 1.4; }

.ds-attrib { list-style: none; margin: 0; padding: 0; }
.ds-attrib li { font-size: 10.5px; color: var(--faint); line-height: 1.45; margin-bottom: 3px; }

.dossier a { color: var(--accent); }

/* ---------------- P9: Permit Set resolver panel ----------------
 * Namespaced `rs-`. Every colour is an existing token — this panel introduces
 * no new palette, per the design lock. It lives in the `#resolver-body` slot
 * the approved mockup already reserved under the "Permit Set" title.
 */

.rs-scope-label {
  display: block; font-size: 9px; letter-spacing: .09em; text-transform: uppercase;
  color: var(--faint); margin: 2px 0 4px;
}
.rs-scope {
  width: 100%; font-family: inherit; font-size: 12px; color: var(--ink);
  background: var(--chrome-2); border: 1px solid var(--line); border-radius: 3px;
  padding: 5px 6px; cursor: pointer;
}
.rs-scope:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.rs-params { display: flex; flex-direction: column; gap: 4px; margin-bottom: 6px; }
.rs-param { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.rs-param-k { font-size: 11.5px; color: var(--muted); }
.rs-param input[type="number"] {
  width: 92px; font-family: var(--font-mono); font-size: 11.5px; text-align: right;
  color: var(--ink); background: var(--chrome-2); border: 1px solid var(--line);
  border-radius: 3px; padding: 3px 5px;
}
.rs-param-bool { justify-content: flex-start; gap: 6px; font-size: 11.5px; color: var(--muted); cursor: pointer; }
.rs-param-bool input { accent-color: var(--accent); }
.rs-param input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.rs-resolve, .rs-build {
  width: 100%; margin: 6px 0 2px; cursor: pointer; font-family: inherit; font-size: 11.5px;
  color: var(--ink); background: var(--accent-soft); border: 1px solid var(--accent);
  border-radius: 3px; padding: 6px 8px;
}
.rs-resolve:hover, .rs-build:hover { background: var(--accent); color: var(--chrome); }
.rs-resolve:disabled { opacity: .6; cursor: progress; }
.rs-resolve:focus-visible, .rs-build:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.rs-build { background: var(--chrome-2); border-color: var(--line); }
.rs-build:hover { background: var(--accent-soft); border-color: var(--accent); color: var(--ink); }

.rs-forms, .rs-sheets { list-style: none; margin: 0; padding: 0; }
.rs-form, .rs-sheet {
  display: flex; flex-direction: column; gap: 1px;
  padding: 5px 0 5px 7px; border-left: 2px solid var(--line-2);
  border-bottom: 1px solid var(--line-2);
}
.rs-form-head { display: flex; gap: 6px; align-items: baseline; }
.rs-form-code, .rs-sheet-code {
  font-family: var(--font-mono); font-size: 10.5px; color: var(--accent); flex: 0 0 auto;
}
.rs-form-title, .rs-sheet-title { font-size: 12px; color: var(--ink); line-height: 1.3; }
.rs-form-meta { font-family: var(--font-mono); font-size: 10px; color: var(--faint); }
.rs-form-why { font-size: 11px; color: var(--muted); line-height: 1.4; }
.rs-form-foot { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; font-size: 10.5px; }
.rs-sheet { flex-direction: row; flex-wrap: wrap; gap: 6px; align-items: baseline; }
.rs-sheet-scale { font-family: var(--font-mono); font-size: 10px; color: var(--muted); }
.rs-sheet-notes { flex: 1 0 100%; font-size: 10.5px; color: var(--muted); line-height: 1.4; }
.rs-prov .kv .v { font-size: 10px; color: var(--faint); }

@media (max-width: 1180px) {
  #app { grid-template-columns: 196px minmax(0, 1fr) 288px; }
  .brand small { display: none; }
  .menubar button { padding: 6px 6px; }
}

@media (max-width: 940px) {
  body { overflow: auto; }
  #app {
    min-height: 100vh; height: auto;
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(220px, 28vh) minmax(58vh, 1fr) auto 34px 30px;
    grid-template-areas:
      "topbar"
      "rail"
      "canvas"
      "dossier"
      "cmdline"
      "status";
  }
  .topbar {
    min-height: 52px; height: auto; flex-wrap: wrap; gap: 8px;
    padding: 8px 10px;
  }
  .brand { flex-basis: auto; }
  .menubar { order: 3; flex: 1 0 100%; overflow-x: auto; padding-bottom: 1px; }
  .addressbar { order: 2; flex: 1 1 100%; max-width: none; margin-left: 0; min-width: 0; }
  .rail {
    border-right: 0; border-bottom: 1px solid var(--line);
    display: grid; grid-template-columns: repeat(2, minmax(0, 1fr));
    align-content: start; gap: 0 6px;
  }
  .cmd-group-title, .cmd-item { break-inside: avoid; }
  .canvas-wrap { min-height: 58vh; }
  .dossier {
    max-height: none; border-left: 0; border-top: 1px solid var(--line);
  }
  .statusbar { overflow-x: auto; }
  .statusbar #status-msg { min-width: 180px; }
}

@media (max-width: 560px) {
  .rail { grid-template-columns: 1fr; max-height: 260px; }
  .btn { padding: 0 9px; }
  .brand { font-size: 14px; }
  .legal-chrome { font-size: 9.5px; line-height: 1.3; }
}
