/* LandPool — map-first, clean. Desktop first; narrow screens collapse the side panels into drawers. */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --ink: #1f2937;
  --muted: #6b7280;
  --line: #e5e7eb;
  --accent: #1d4ed8;
  --accent-ink: #ffffff;
  --warn: #b45309;
  --warn-bg: #fef3c7;
  --error: #b91c1c;
  --error-bg: #fee2e2;
  --ok: #047857;
  --selection: #f59e0b;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 4px 16px rgba(0, 0, 0, .06);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --sidebar-w: 232px;
  --panel-w: 300px;
  --topbar-h: 52px;
  --status-h: 36px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { font: 14px/1.4 var(--font); color: var(--ink); background: var(--bg); overflow: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3 { margin: 0; font-weight: 600; }

.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ------------------------------------------------------------- layout */
.app {
  height: 100%;
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr var(--panel-w);
  grid-template-rows: var(--topbar-h) 1fr auto var(--status-h);
  grid-template-areas:
    "top   top   top"
    "side  stage panel"
    "table table table"
    "stat  stat  stat";
}
.topbar { grid-area: top; }
.sidebar { grid-area: side; }
.stage { grid-area: stage; position: relative; min-width: 0; }
.panel { grid-area: panel; }
.table-wrap { grid-area: table; }
.statusbar { grid-area: stat; }

/* ------------------------------------------------------------- topbar */
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 0 14px;
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 800; letter-spacing: .08em; color: var(--accent); }
.brand span { color: var(--ink); }
.project-name input {
  border: 1px solid transparent; border-radius: 6px; padding: 5px 8px; min-width: 200px; background: transparent; font-weight: 600;
}
.project-name input:hover, .project-name input:focus { border-color: var(--line); background: var(--bg); outline: none; }
.save-state { color: var(--muted); font-size: 12px; white-space: nowrap; }

.search { position: relative; margin-left: auto; width: min(360px, 34vw); }
.search input { width: 100%; padding: 7px 10px; border: 1px solid var(--line); border-radius: 20px; background: var(--bg); }
.search input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.search__results {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 1200; margin: 0; padding: 4px; list-style: none;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); max-height: 320px; overflow: auto;
}
.search__hit { display: flex; flex-direction: column; width: 100%; text-align: left; padding: 6px 10px; border: 0; background: none; border-radius: 6px; }
.search__hit:hover { background: var(--bg); }
.search__hit span { color: var(--muted); font-size: 12px; }
.search__empty { padding: 8px 10px; color: var(--muted); }

.menu-wrap { position: relative; }
.menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 1200; min-width: 220px; padding: 6px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
}
.menu button { display: block; width: 100%; text-align: left; padding: 7px 10px; border: 0; background: none; border-radius: 6px; }
.menu button:hover { background: var(--bg); }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; }
.menu__danger { color: var(--error); }

/* ------------------------------------------------------------ buttons */
.btn {
  padding: 6px 12px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface);
}
.btn:hover { background: var(--bg); }
.btn--primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn--primary:hover { filter: brightness(1.08); background: var(--accent); }
.btn--danger { color: var(--error); border-color: #fca5a5; }
.btn--danger:hover { background: var(--error-bg); }
.btn--small { padding: 3px 9px; font-size: 12px; }
.btn:disabled { opacity: .45; cursor: default; }
.icon-btn { border: 0; background: none; font-size: 18px; padding: 4px 8px; }
.link { border: 0; background: none; color: var(--accent); padding: 2px 0; text-align: left; }
.link:hover { text-decoration: underline; }
.only-narrow { display: none; }

/* ------------------------------------------------------------ sidebar */
.sidebar {
  display: flex; flex-direction: column; overflow: auto; background: var(--surface); border-right: 1px solid var(--line);
}
.side-section { padding: 12px 12px 10px; border-bottom: 1px solid var(--line); }
.side-section--grow { flex: 1; }
.side-title { font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); margin-bottom: 8px; }

.tools { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
.tools--actions { margin-top: 6px; }
.tool {
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 7px 2px 5px;
  border: 1px solid transparent; border-radius: 6px; background: none; font-size: 11px; color: var(--ink);
}
.tool i { font-style: normal; font-size: 16px; line-height: 1; }
.tool:hover { background: var(--bg); }
.tool.is-active { background: #dbeafe; border-color: #bfdbfe; color: var(--accent); }
.tool:disabled { opacity: .4; }

.hint { margin: 8px 0 0; color: var(--muted); font-size: 12px; }
.hint--measure { color: var(--error); font-weight: 600; }
.hint--measure:empty, .hint--history:empty { display: none; }
.hint--history { font-size: 11px; }

.segmented { display: flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; margin-bottom: 8px; }
.segmented button { flex: 1; padding: 5px 0; border: 0; background: var(--surface); font-size: 12px; }
.segmented button + button { border-left: 1px solid var(--line); }
.segmented button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }

.field { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 6px; font-size: 12px; color: var(--muted); }
.field select { padding: 4px 6px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); color: var(--ink); max-width: 130px; }

.layers { display: flex; flex-direction: column; gap: 4px; }
.layer { display: flex; align-items: center; gap: 8px; font-size: 13px; cursor: pointer; }
.swatch { width: 12px; height: 12px; border-radius: 3px; flex: none; opacity: .85; }

.issues { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 3px; }
.issues__none { color: var(--muted); font-size: 12px; }
.issue { display: block; width: 100%; text-align: left; padding: 5px 8px; border: 0; border-radius: 6px; font-size: 12px; }
.issue--warning { background: var(--warn-bg); color: var(--warn); }
.issue--error { background: var(--error-bg); color: var(--error); }
button.issue:hover { filter: brightness(.96); }
.issues--inline { margin-top: 10px; }
.issues--inline .issue { cursor: default; }

.storage-note { margin: 0; padding: 10px 12px; font-size: 11px; color: var(--muted); }

/* ---------------------------------------------------------------- map */
.map { position: absolute; inset: 0; background: #e5e7eb; }
.leaflet-container { font: inherit; }
.leaflet-control-attribution { font-size: 10px; background: rgba(255, 255, 255, .85); }
.lp-tip { font-size: 12px; }
.lp-measure-label {
  background: var(--surface); color: var(--error); border: 1px solid var(--error); border-radius: 6px;
  font-weight: 600; font-size: 12px; padding: 3px 8px; box-shadow: var(--shadow);
}
.lp-measure-label::before { display: none; }

/* -------------------------------------------------------------- panel */
.panel { background: var(--surface); border-left: 1px solid var(--line); overflow: auto; }
.panel__content { padding: 14px; }
.panel__title { font-size: 16px; margin-bottom: 8px; }
.panel__meta { margin: -4px 0 8px; color: var(--muted); font-size: 12px; }
.panel__hint { color: var(--muted); font-size: 12px; margin: 10px 0 0; }
.panel__actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }

.props { margin: 0; display: grid; grid-template-columns: 1fr; gap: 2px; }
.prop { display: grid; grid-template-columns: 110px 1fr; align-items: center; gap: 8px; padding: 3px 0; border-bottom: 1px solid var(--line); }
.prop dt { color: var(--muted); font-size: 12px; }
.prop dd { margin: 0; min-width: 0; }
.prop__value { font-weight: 600; }
.prop__input { width: 100%; padding: 4px 6px; border: 1px solid transparent; border-radius: 5px; background: transparent; }
.prop__input:hover { border-color: var(--line); }
.prop__input:focus { border-color: var(--accent); background: var(--bg); outline: none; }

.card { margin-top: 12px; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg); }
.card--accent { background: #eff6ff; border-color: #bfdbfe; }
.card__label { font-size: 10px; letter-spacing: .1em; color: var(--muted); }
.card__big { font-size: 24px; font-weight: 700; margin-top: 2px; }
.card__sub { color: var(--muted); font-size: 12px; }
.card__row { display: flex; justify-content: space-between; gap: 8px; padding: 3px 0; font-size: 13px; }
.card__row span { color: var(--muted); }
.card__row--total { border-top: 1px solid var(--line); margin-top: 4px; padding-top: 6px; }
.card__row--total b { color: var(--ok); }

.other { margin-top: 12px; }
.other summary { cursor: pointer; color: var(--muted); font-size: 12px; }
.sel-list { list-style: none; margin: 0; padding: 0; max-height: 40vh; overflow: auto; }

/* ---------------------------------------------------------- status bar */
.statusbar {
  display: flex; align-items: center; gap: 18px; padding: 0 14px; font-size: 12px; color: var(--muted);
  background: var(--surface); border-top: 1px solid var(--line); overflow: hidden; white-space: nowrap;
}
.statusbar b { color: var(--ink); font-weight: 600; margin-left: 4px; }
.stat-issues.is-warn b { color: var(--warn); }
.statusbar__table { margin-left: auto; }

/* --------------------------------------------------------------- table */
.table-wrap { background: var(--surface); border-top: 1px solid var(--line); height: 34vh; display: flex; flex-direction: column; }
.table-wrap[hidden] { display: none; }
.table-head { display: flex; justify-content: space-between; padding: 6px 12px; font-size: 12px; color: var(--muted); border-bottom: 1px solid var(--line); }
.table-head .hint { margin: 0; }
.table-scroll { overflow: auto; flex: 1; }
.table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.table th { position: sticky; top: 0; background: var(--bg); text-align: left; padding: 6px 10px; border-bottom: 1px solid var(--line); cursor: pointer; user-select: none; white-space: nowrap; }
.table td { padding: 5px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.table tbody tr { cursor: pointer; }
.table tbody tr:hover { background: var(--bg); }
.table tbody tr.is-selected { background: #fef3c7; }

/* --------------------------------------------------------------- modal */
.modal { border: 0; border-radius: 12px; padding: 0; width: min(520px, 94vw); box-shadow: var(--shadow); }
.modal::backdrop { background: rgba(17, 24, 39, .4); }
.modal__title { padding: 16px 20px 0; font-size: 16px; }
.modal__body { padding: 12px 20px; max-height: 70vh; overflow: auto; }
.modal__actions { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px 16px; border-top: 1px solid var(--line); }
.form { display: grid; gap: 8px; }
.form__row { display: grid; grid-template-columns: 140px 1fr; align-items: center; gap: 10px; }
.form__label { color: var(--muted); font-size: 13px; }
.form input, .form select, .form textarea { padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); width: 100%; }
.form input:focus, .form select:focus, .form textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.form__note { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.projects { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.projects li { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 10px; border: 1px solid var(--line); border-radius: var(--radius); }
.projects li.is-current { border-color: var(--accent); background: #eff6ff; }
.projects__name { display: flex; flex-direction: column; }
.projects__name span { color: var(--muted); font-size: 12px; }
.projects__actions { display: flex; gap: 6px; }

/* -------------------------------------------------------------- toasts */
.toasts { position: fixed; left: 50%; bottom: calc(var(--status-h) + 14px); transform: translateX(-50%); z-index: 1300; display: flex; flex-direction: column; gap: 6px; align-items: center; pointer-events: none; }
.toast { padding: 8px 14px; border-radius: 20px; background: #111827; color: #fff; font-size: 13px; box-shadow: var(--shadow); max-width: 80vw; transition: opacity .5s; }
.toast--warn { background: var(--warn); }
.toast--error { background: var(--error); }
.toast.is-out { opacity: 0; }
.offline { margin: 0; padding: 12px 16px; background: var(--error-bg); color: var(--error); }

/* --------------------------------------------------------------- print */
.print-only { display: none; }
@media print {
  @page { size: A4 landscape; margin: 10mm; }
  body { overflow: visible; }
  .app { display: block; height: auto; }
  .topbar, .sidebar, .panel, .statusbar, .table-wrap, .toasts, .leaflet-control-zoom, .leaflet-pm-toolbar { display: none !important; }
  .stage { position: relative; height: 165mm; }
  .print-only { display: block; }
  .print-header { position: absolute; top: 6mm; left: 6mm; z-index: 1000; background: rgba(255,255,255,.92); padding: 6px 10px; border-radius: 6px; }
  .print-header h1 { font-size: 18px; }
  .print-header div { color: var(--muted); font-size: 12px; }
  .north-arrow { position: absolute; top: 6mm; right: 6mm; z-index: 1000; background: rgba(255,255,255,.92); border-radius: 6px; padding: 4px 8px; text-align: center; font-weight: 700; line-height: 1.1; }
  .print-footer { position: static; margin-top: 4mm; }
  .legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 11px; }
  .legend i { display: inline-block; width: 14px; height: 10px; margin-right: 5px; vertical-align: -1px; border-radius: 2px; opacity: .8; }
  .print-stats { margin-top: 4px; font-size: 11px; }
  .print-attribution { margin-top: 2px; font-size: 9px; color: var(--muted); }
}

/* ---------------------------------------------------------- responsive */
@media (max-width: 960px) {
  .app { grid-template-columns: 1fr; grid-template-areas: "top" "stage" "table" "stat"; }
  .only-narrow { display: inline-block; }
  .sidebar, .panel {
    position: fixed; top: var(--topbar-h); bottom: var(--status-h); z-index: 1100; width: min(86vw, 320px);
    box-shadow: var(--shadow); transition: transform .2s;
  }
  .sidebar { left: 0; transform: translateX(-100%); }
  .panel { right: 0; transform: translateX(100%); }
  body.show-sidebar .sidebar, body.show-panel .panel { transform: none; }
  .search { width: 40vw; }
  .save-state, .project-name { display: none; }
  .statusbar { gap: 12px; font-size: 11px; }
  .statusbar span:nth-child(n+5):not(.stat-issues) { display: none; }
}
