/* Terra — land parcels, North Portugal
   Palette: lichen paper, granite, deep moss, vinho accent for the selected parcel */
:root {
  --paper: #EDEFE8;
  --paper-2: #E2E5DC;
  --granite: #B8BDB3;
  --granite-2: #8B9187;
  --ink: #1B231D;
  --ink-2: #4A544C;
  --moss: #2F5240;
  --moss-2: #3F6C55;
  --vinho: #7C2D3C;
  --vinho-2: #A23E50;
  --sun: #D8A23E;
  --white: #FBFBF8;
  --danger: #B23A2E;
  --radius: 14px;
  --radius-s: 8px;
  --shadow: 0 10px 30px rgba(27, 35, 29, .18), 0 1px 2px rgba(27, 35, 29, .12);
  --font: "Bricolage Grotesque", "Segoe UI", Roboto, system-ui, sans-serif;
  --panel-w: 380px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; overscroll-behavior: none; }   /* no pull-to-refresh while dragging the sheet */
body {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -.01em; }
h1 { font-size: 22px; }
h2 { font-size: 17px; }
h3 { font-size: 14px; color: var(--ink-2); font-weight: 500; }
p { margin: 0 0 .6em; }
a { color: var(--moss); }
button { font: inherit; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--ink-2); }
.small { font-size: 13px; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 16px; border-radius: 999px; border: 1px solid transparent;
  background: var(--moss); color: var(--white); font-weight: 600;
  transition: background .15s, transform .05s;
  min-height: 42px;
}
.btn:hover { background: var(--moss-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.secondary { background: var(--paper-2); color: var(--ink); border-color: var(--granite); }
.btn.secondary:hover { background: var(--white); }
.btn.ghost { background: transparent; color: var(--moss); padding-inline: 8px; }
.btn.ghost:hover { background: var(--paper-2); }
.btn.danger { background: transparent; color: var(--danger); border-color: transparent; }
.btn.danger:hover { background: #F6E3E0; }
.btn.accent { background: var(--vinho); }
.btn.accent:hover { background: var(--vinho-2); }
.btn.block { width: 100%; }
.btn.sm { min-height: 34px; padding: 6px 12px; font-size: 13px; }
.btn svg { width: 18px; height: 18px; flex: none; }
:focus-visible { outline: 3px solid rgba(216, 162, 62, .8); outline-offset: 2px; }

/* ---------- forms ---------- */
.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 13px; color: var(--ink-2); }
.input, .field input, .field select, .field textarea {
  width: 100%; padding: 10px 12px; border-radius: var(--radius-s);
  border: 1px solid var(--granite); background: var(--white);
  min-height: 42px;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--moss); outline: none; box-shadow: 0 0 0 3px rgba(47, 82, 64, .15); }
.field textarea { min-height: 80px; resize: vertical; }
.row { display: flex; gap: 10px; align-items: center; }
.row > * { flex: 1; }
.row.tight > * { flex: none; }
.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; }
.switch input { appearance: none; width: 44px; height: 26px; border-radius: 999px; background: var(--granite); position: relative; flex: none; transition: background .15s; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: var(--white); transition: left .15s; box-shadow: 0 1px 2px rgba(0,0,0,.25); }
.switch input:checked { background: var(--sun); }
.switch input:checked::after { left: 21px; }
.note { padding: 10px 12px; border-radius: var(--radius-s); background: var(--paper-2); font-size: 13px; color: var(--ink-2); }
.note.error { background: #F6E3E0; color: var(--danger); }
.note.ok { background: #E1EEE4; color: var(--moss); }

/* ---------- map shell ---------- */
#map { position: fixed; inset: 0; background: var(--paper-2); }
.leaflet-container { font-family: var(--font); }
.leaflet-control-attribution { font-size: 10px; background: rgba(251,251,248,.75) !important; }
.zoom-chip { font-size: 11px; font-variant-numeric: tabular-nums; color: var(--ink); background: rgba(251,251,248,.85); border-radius: 6px; padding: 2px 7px; margin: 0 4px 4px 0 !important; box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.leaflet-control-zoom { display: none; }
.leaflet-bar a { border-bottom-color: var(--paper-2) !important; }
.parcel-label { background: transparent; border: 0; padding: 0; font-size: 12px; font-weight: 700; color: var(--ink); box-shadow: none; white-space: nowrap;
  text-shadow: 0 0 3px #fff, 0 0 3px #fff, 0 0 6px #fff, 0 1px 2px rgba(255,255,255,.9); }   /* halo instead of a box, readable on imagery */
.parcel-label::before { display: none; }
.cad-tip { font-weight: 700; color: var(--ink); text-align: center; line-height: 1.3; }
.cad-tip b { color: var(--ink); }
.parcel-label b { display: block; }
#map:not(.cad-labels) .cad-tip { display: none; }   /* labels only from LABEL_ZOOM (app.js) */

/* wordmark */
.brand { text-decoration: none; color: inherit;
  position: fixed; top: 14px; left: 14px; z-index: 1000;
  display: flex; align-items: center; gap: 10px;
  padding: 8px 14px 8px 10px; border-radius: 999px;
  background: var(--white); box-shadow: var(--shadow);
}
.brand .mark, .panel-head .mark { width: 30px; height: 30px; border-radius: 9px; background: var(--moss); display: grid; place-items: center; flex: none; }
.brand .mark svg, .panel-head .mark svg { width: 18px; height: 18px; }
.brand strong { font-size: 16px; letter-spacing: -.01em; }
.brand .count { font-size: 12px; color: var(--ink-2); padding-left: 8px; border-left: 1px solid var(--granite); }

/* map action stack */
.map-actions {
  position: fixed; right: 14px; bottom: 52px; z-index: 1000;
  display: flex; flex-direction: column; gap: 8px;
}
.map-actions .btn.icon, .top-actions .btn.icon {
  width: 46px; height: 46px; min-height: 0; padding: 0; border-radius: 14px;
  background: var(--white); color: var(--ink); box-shadow: var(--shadow); border: 0;
}
.map-actions .btn.icon.on { background: var(--moss); color: var(--white); }
.map-actions .btn.icon svg, .top-actions .btn.icon svg { width: 20px; height: 20px; }
.top-actions { position: fixed; right: 14px; top: 14px; z-index: 1000; display: flex; gap: 8px; }
.top-actions .btn.icon.lang { font-size: 13px; font-weight: 700; letter-spacing: .04em; color: var(--ink-2); }

/* pick / draw mode banner */
.mode-banner {
  position: fixed; left: 50%; top: 14px; transform: translateX(-50%); z-index: 1001;
  background: var(--ink); color: var(--white); padding: 10px 14px 10px 16px; border-radius: 999px;
  display: flex; align-items: center; gap: 12px; box-shadow: var(--shadow); font-size: 14px; max-width: calc(100vw - 28px);
}
.mode-banner .btn { min-height: 32px; padding: 4px 12px; font-size: 13px; background: var(--vinho); }

/* ---------- side panel / bottom sheet ---------- */
.panel {
  position: fixed; z-index: 1000; display: flex; flex-direction: column;
  background: var(--white); box-shadow: var(--shadow); overflow: hidden;
  left: 14px; top: 14px; bottom: 28px; width: var(--panel-w); border-radius: var(--radius);
}
.panel .grip { display: none; }
.panel-head { padding: 16px 18px 10px; border-bottom: 1px solid var(--paper-2); }
.tabs { display: flex; gap: 4px; padding: 10px 12px; border-bottom: 1px solid var(--paper-2); }
.tabs button { flex: 1; padding: 8px 10px; border: 0; border-radius: 999px; background: transparent; color: var(--ink-2); font-weight: 600; }
.tabs button[aria-selected="true"] { background: var(--paper-2); color: var(--ink); }
.panel-body { overflow: auto; flex: 1; padding: 14px 18px 18px; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.view { display: none; }
.view.active { display: block; }

/* parcel list */
.plist { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.plist li { display: grid; grid-template-columns: 12px 1fr auto auto; gap: 12px; align-items: center; padding: 10px 12px; border-radius: 10px; cursor: pointer; border: 1px solid transparent; }
.plist li:hover { background: var(--paper); }
.plist li.selected { background: var(--paper-2); border-color: var(--granite); }
.plist .sw { width: 12px; height: 12px; border-radius: 3px; border: 1px solid rgba(0,0,0,.2); }
.plist .t { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.plist .s { font-size: 12px; color: var(--ink-2); }
.plist .m { font-size: 13px; color: var(--ink-2); text-align: right; white-space: nowrap; }
.plist .pub { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--sun); margin-left: 6px; vertical-align: middle; }
.empty { padding: 26px 8px; text-align: center; color: var(--ink-2); }
.empty svg { width: 44px; height: 44px; opacity: .5; margin-bottom: 8px; }

/* parcel detail */
.detail-head { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 12px; }
.detail-head h2 { flex: 1; }
.measures { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 10px 0 16px; }
.measure { padding: 10px 12px; border-radius: 10px; background: var(--paper); }
.measure b { display: block; font-size: 18px; font-weight: 600; letter-spacing: -.02em; }
.measure span { font-size: 12px; color: var(--ink-2); }
.reg { font-variant-numeric: tabular-nums; }
.section-title { display: flex; align-items: center; justify-content: space-between; margin: 18px 0 8px; }
.section-title h3 { margin: 0; }
.bar { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
details.raw summary { cursor: pointer; color: var(--ink-2); font-size: 13px; margin: 8px 0; }
.raw table { width: 100%; font-size: 12px; border-collapse: collapse; }
.raw td { padding: 3px 4px; border-bottom: 1px solid var(--paper-2); vertical-align: top; word-break: break-word; }
.raw td:first-child { color: var(--ink-2); width: 40%; }

/* field manager */
.flist { list-style: none; margin: 0 0 12px; padding: 0; }
.flist li { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--paper-2); }
.flist li span.type { font-size: 12px; color: var(--ink-2); background: var(--paper-2); border-radius: 999px; padding: 2px 8px; }
.flist li b { flex: 1; font-weight: 500; }

/* legend */
.legend { display: grid; gap: 6px; margin-top: 10px; }
.legend div { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.legend i { width: 14px; height: 14px; border-radius: 3px; border: 1px solid rgba(0,0,0,.2); display: inline-block; }

/* toast */
.toast { position: fixed; left: 50%; bottom: 40px; transform: translateX(-50%); z-index: 2000; background: var(--ink); color: var(--white); padding: 10px 16px; border-radius: 999px; box-shadow: var(--shadow); font-size: 14px; max-width: calc(100vw - 28px); }

/* modal */
.modal-bg { position: fixed; inset: 0; z-index: 1500; background: rgba(27,35,29,.45); display: grid; place-items: center; padding: 16px; }
.modal { width: min(420px, 100%); background: var(--white); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); max-height: 90vh; overflow: auto; }
.modal h2 { margin-bottom: 12px; }

/* ---------- mobile: panel becomes a bottom sheet ---------- */
@media (max-width: 760px) {
  :root { --panel-w: 100%; }
  .panel {
    left: 0; right: 0; bottom: 0; top: auto; width: 100%;
    height: 46vh; max-height: calc(100dvh - 80px); border-radius: 18px 18px 0 0;
    transition: height .2s ease;
  }
  .panel.tall { height: calc(100dvh - 80px); }
  .panel.short { height: 96px; }
  .panel .grip { display: block; width: 40px; height: 5px; border-radius: 999px; background: var(--granite); margin: 8px auto 0; cursor: grab; touch-action: none; }
  .panel-head { padding: 8px 16px 8px; touch-action: none; cursor: grab; }   /* whole head drags the sheet */
  .panel-head button, .panel-head a { touch-action: auto; }
  .map-actions { bottom: calc(46vh + 14px); transition: bottom .2s ease; }
  .panel.short ~ .map-actions { bottom: 110px; }
  .panel.tall ~ .map-actions { bottom: calc(100dvh - 80px + 14px); }
  .brand .count { display: none; }
  .mode-banner { top: auto; bottom: calc(46vh + 14px); font-size: 13px; }
  .toast { bottom: calc(46vh + 70px); }
  .measures { grid-template-columns: 1fr 1fr; }
}

/* ---------- login page ---------- */
body.auth { display: grid; place-items: center; min-height: 100dvh; padding: 20px;
  background:
    radial-gradient(1200px 600px at 10% -10%, #d9dfd3 0, transparent 60%),
    var(--paper);
}
.auth-card { width: min(420px, 100%); background: var(--white); border-radius: 20px; padding: 28px 26px 22px; box-shadow: var(--shadow); position: relative; }
.auth-card .brand { position: static; box-shadow: none; padding: 0; margin-bottom: 18px; background: transparent; }
.auth-card h1 { margin-bottom: 4px; }
.auth-card .lead { color: var(--ink-2); margin-bottom: 20px; }
.contours { position: fixed; inset: 0; z-index: -1; opacity: .35; pointer-events: none; }
.auth-switch { text-align: center; margin-top: 14px; font-size: 14px; color: var(--ink-2); }
.auth-switch button { background: none; border: 0; color: var(--moss); font-weight: 600; padding: 0 2px; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* actions log */
.actions { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--paper-2); }
.alist { list-style: none; margin: 0 0 12px; padding: 0; display: grid; gap: 8px; }
.alist li { padding: 8px 10px; border-radius: var(--radius-s); background: var(--paper); cursor: pointer; border: 1px solid transparent; }
.alist li.editing { border-color: var(--moss); background: #E1EEE4; }
.alist .a-head { display: flex; align-items: center; gap: 8px; }
.alist .a-head b { flex: 1; }
.alist .cov { font-size: 12px; font-weight: 600; color: var(--moss); background: #E1EEE4; border-radius: 999px; padding: 2px 8px; }
.alist .a-val { font-size: 14px; margin: 2px 0; }

/* kind pills + wishlist badge */
.pills { display: flex; gap: 6px; }
.pills button { flex: 1; min-height: 38px; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--granite); background: var(--white); color: var(--ink-2); font-weight: 600; }
.pills button[aria-pressed="true"] { background: var(--moss); border-color: var(--moss); color: var(--white); }
.wish { display: inline-block; margin-left: 6px; font-size: 11px; font-weight: 600; color: #8A5A2B; background: #F6EAD0; border-radius: 999px; padding: 1px 7px; vertical-align: middle; }

/* layers popover (next to the layers button) */
.layer-pop { position: fixed; z-index: 1001; width: 260px; padding: 12px 14px; border-radius: var(--radius); background: var(--white); box-shadow: var(--shadow); }
.layer-pop .switch { padding: 10px 0 0; font-size: 14px; }

/* lower pane with the selected parcel's details */
.subpanel { flex: 0 0 55%; height: 55%; display: flex; flex-direction: column; border-top: 2px solid var(--paper-2); background: var(--white); }   /* fixed height: tabs don't resize it */
.sub-tabs { padding: 6px 12px; }
.sub-tabs .close { flex: none; width: 34px; padding: 0; color: var(--ink-2); }
.sub-body { flex: 1; min-height: 0; overflow: auto; padding: 12px 18px 16px; overscroll-behavior: contain; }
.sview { display: none; } .sview.active { display: block; }
.plist li .info { min-height: 0; padding: 4px 6px; margin: -4px -6px -4px 0; color: var(--ink-2); }
.plist li .info svg { width: 18px; height: 18px; }
.field.inline { grid-template-columns: 96px 1fr; align-items: center; margin-bottom: 10px; }
.field.inline label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.field.inline input, .field.inline select { min-height: 38px; padding: 6px 10px; }
.pills.locked { opacity: .5; pointer-events: none; }

/* ISO date text with a calendar icon; the native picker sits invisibly on top of the icon */
.datepick { position: relative; }
.datepick input:not([type=date]) { padding-right: 40px; }
.datepick .cal { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); width: 32px; height: 32px; display: grid; place-items: center; color: var(--ink-2); border-radius: 8px; overflow: hidden; }
.datepick .cal svg { width: 18px; height: 18px; }
.datepick .cal input[type=date] { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; min-height: 0; padding: 0; border: 0; }
.datepick .cal input[type=date]::-webkit-calendar-picker-indicator { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }

/* tag suggestions under the tag box */
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.chip { min-height: 0; padding: 4px 10px; border-radius: 999px; border: 1px solid var(--granite); background: var(--paper); color: var(--ink); font-size: 13px; }
.chip:hover { background: var(--paper-2); }
input[type=range].short { width: 33%; min-width: 90px; justify-self: start; accent-color: var(--moss); }
.subpanel.readonly .sub-tabs [data-stab=actions] { display: none; }
.subpanel.readonly #manage-fields { display: none; }
