/*
 * IWMP design system (see architecture.md's "Design system" section and the
 * approved "Parzellenbaum" mockup). A deliberate palette/typography, not
 * stock Bootstrap defaults: Public Sans for UI/body text, IBM Plex Mono for
 * tabular data (dates, numbers), a warm neutral ground instead of
 * Bootstrap's default grey, a muted gold instead of a plain warning yellow
 * for Flaeche/polygon accents (kept distinct from the brand green so drawn
 * shapes read clearly against green UI chrome). requirements.md mandates a
 * light, green-based scheme; no dark-mode branch is needed here - this is a
 * real deployed app under our own control, not a claude.ai Artifact with a
 * viewer-controlled theme.
 *
 * Bootstrap 5.3's compiled CSS bakes per-component colour variables
 * (--bs-btn-bg etc.) rather than referencing --bs-primary/--bs-border-radius
 * throughout, so retheming without a Sass rebuild means overriding the
 * classes we actually use directly, not just the root Bootstrap variables.
 */

:root {
  /* Brand green */
  --iwmp-green: #68a94a;
  --iwmp-green-dark: #4f8038;
  --green-tint: #eef5e9;
  /* One step deeper than --green-tint, same hue family - used for the
   * Kulturen body (.baum-kulturen) nested *inside* a Schlag box, itself
   * inside a Parzelle's already-green-tinted body (.baum-schlaege). Without
   * this, .baum-kulturen used --surface-sunken, which is close enough to
   * --green-tint in both hue and lightness that the two nesting levels were
   * hard to tell apart at a glance. */
  --green-tint-deep: #d9ead2;

  /* Neutrals - chosen with a slight warm/green bias, not plain grey */
  --ink: #23261f;
  --ink-soft: #5b6154;
  --ground: #f6f7f2;
  --surface: #ffffff;
  --surface-sunken: #f0f2ea;
  --line: #dfe3d6;
  --line-soft: #ebede4;
  --muted-badge: #9aa08e;

  /* Flaeche/polygon accent (map draw layer, list thumbnails - see
   * app/static/js/geoadmin-map.js, app/parzelle.py) */
  --amber: #b8860b;
  --amber-tint: #fbf1d9;
  --amber-line: #e4c876;

  /* Betrieb map marker (farm icon) - deliberately distinct from --amber
   * above (that's the Flaeche/polygon accent). Not readable from JS/Python,
   * so kept in sync by hand: baked into app/static/img/betrieb-marker.png
   * (see the generation notes in architecture.md's "Map" section) and used
   * by app/static/js/geoadmin-map.js's betriebMarkerStyle(). */
  --betrieb-marker: #e07b1a;

  /* Geraet (Device) map marker - a 5th distinct color, so a located Device
   * doesn't get lost against the Betrieb marker/Parzelle+Schlag polygon
   * colors already on screen at once (Betrieb detail view). Not readable
   * from JS/SVG, so kept in sync by hand with
   * app/static/img/sensor-marker.svg and geoadmin-map.js's
   * geraetMarkerStyle(). */
  --geraet-marker: #0000ff;

  --shadow: 0 1px 2px rgba(35, 38, 31, 0.06), 0 4px 14px rgba(35, 38, 31, 0.05);
  --radius: 10px;
}

body {
  background: var(--ground);
  color: var(--ink);
  font-family: "Public Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
}

.text-brand {
  color: var(--iwmp-green);
}

/* Tabular data - date columns in the Parzelle/Schlag/Kultur tree
 * (_baum_macros.html), anywhere else numbers need to line up. */
.mono {
  font-family: "IBM Plex Mono", ui-monospace, "SF Mono", Consolas, monospace;
  font-variant-numeric: tabular-nums;
}

.btn-primary {
  --bs-btn-bg: var(--iwmp-green);
  --bs-btn-border-color: var(--iwmp-green);
  --bs-btn-hover-bg: var(--iwmp-green-dark);
  --bs-btn-hover-border-color: var(--iwmp-green-dark);
  --bs-btn-active-bg: var(--iwmp-green-dark);
  --bs-btn-active-border-color: var(--iwmp-green-dark);
  --bs-btn-disabled-bg: var(--iwmp-green);
  --bs-btn-disabled-border-color: var(--iwmp-green);
  --bs-btn-focus-shadow-rgb: 104, 169, 74;
}

.btn {
  border-radius: 7px;
}

/* Cards and tables: same Bootstrap classes used on every page, restyled once
 * here rather than per-template. */
.card {
  background-color: var(--surface);
  border-color: var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.table {
  --bs-table-border-color: var(--line-soft);
  /* Replaces Bootstrap's default grey .table-striped rows (every table in
   * the app uses .table-striped - betriebe/_list_body.html,
   * admin/_liste_body.html) with the same green tint the Parzelle tree's
   * boxes use, instead of an unrelated grey. */
  --bs-table-striped-bg: var(--green-tint);
  background-color: var(--surface);
  color: var(--ink);
}

.form-control,
.form-select {
  border-color: var(--line);
  border-radius: 7px;
}

.form-control:focus,
.form-select:focus {
  border-color: var(--iwmp-green);
  box-shadow: 0 0 0 0.2rem rgba(104, 169, 74, 0.15);
}

/* Checkboxes (map layer-toggle controls - _map_shell.html - are the only
 * ones in the app so far) - Bootstrap's default checked/focus state is blue. */
.form-check-input:checked {
  background-color: var(--iwmp-green);
  border-color: var(--iwmp-green);
}

.form-check-input:focus {
  border-color: var(--iwmp-green);
  box-shadow: 0 0 0 0.2rem rgba(104, 169, 74, 0.15);
}

/* Betrieb detail view's tabs (_detail_body.html) - Bootstrap's default
 * nav-tabs link/active color is blue. */
.nav-tabs .nav-link {
  color: var(--ink-soft);
}

.nav-tabs .nav-link:hover,
.nav-tabs .nav-link:focus {
  color: var(--iwmp-green-dark);
}

.nav-tabs .nav-link.active {
  color: var(--iwmp-green-dark);
  border-bottom: 2px solid var(--iwmp-green);
}

/* Status badges (Aktuell/Vergangen - see _baum_macros.html's status_badge
 * macro): a dot indicator for "current" rather than Bootstrap's plain
 * subtle-color badge. */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  white-space: nowrap;
}

.status-badge.current {
  background: var(--green-tint);
  color: var(--iwmp-green-dark);
}

.status-badge.current::before {
  content: "";
  width: 0.4rem;
  height: 0.4rem;
  border-radius: 50%;
  background: var(--iwmp-green);
}

.status-badge.past {
  background: var(--surface-sunken);
  color: var(--muted-badge);
}

/*
 * Parzelle/Schlag/Kultur tree (app/templates/_baum_macros.html,
 * betriebe/_detail_body.html) - nested boxes with labeled fields, not a
 * table, per the approved mockup. Classes are prefixed `baum-` (not the
 * mockup's bare `.row`/`.field`/`.actions`) because `.row` in particular
 * would collide with Bootstrap's own grid row class, already used
 * elsewhere for form layout.
 */
.baum-tree {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.baum-parzelle {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden; /* clips the green .baum-schlaege body to the same rounded corners */
}

.baum-row {
  display: grid;
  align-items: center;
  gap: 0.75rem;
  padding: 0.7rem 1rem;
}

.baum-row-parzelle {
  grid-template-columns: 1.6rem 2.5rem 1.7fr 0.9fr 0.9fr 1fr 1fr auto;
}

.baum-row-schlag {
  grid-template-columns: 1.6rem 2.5rem 1.9fr 1.3fr 0.8fr auto;
}

.baum-row-kultur {
  grid-template-columns: 2.1fr 1.3fr 0.8fr auto;
}

/* Massnahme boxes (app/templates/_massnahme_macros.html) - same shape as
 * .baum-row-kultur (name-cell, one field, status badge, actions - no
 * disclosure, Massnahmen aren't nested). */
.baum-row-massnahme {
  grid-template-columns: 2.1fr 1.3fr 0.8fr auto;
}

/* Sensor boxes (app/templates/_sensor_macros.html) - same shape as
 * .baum-row-schlag minus the Fläche thumbnail column (a Device has no
 * shape to preview); Zuordnung rows one level down reuse .baum-row-kultur's
 * own shape exactly (name-cell, one field, status badge, actions). */
.baum-row-sensor {
  grid-template-columns: 1.6rem 1.9fr 1.3fr 0.8fr auto;
}

.baum-row-zuordnung {
  grid-template-columns: 2.1fr 1.3fr 0.8fr auto;
}

.baum-disclosure {
  width: 1.6rem;
  height: 1.6rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
  border-radius: 6px;
  transition: background 0.15s ease;
}

.baum-disclosure:hover {
  background: var(--surface-sunken);
}

.baum-disclosure svg {
  width: 0.75rem;
  height: 0.75rem;
  transition: transform 0.15s ease;
}

.baum-disclosure[aria-expanded="true"] svg {
  transform: rotate(90deg);
}

.baum-thumb {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 7px;
  background: var(--amber-tint);
  border: 1px solid var(--amber-line);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.baum-thumb.empty {
  background: var(--surface-sunken);
  border-color: var(--line);
}

.baum-thumb svg {
  width: 1.65rem;
  height: 1.65rem;
}

.baum-name-cell {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  min-width: 0;
}

.baum-name-cell .name {
  font-weight: 600;
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.baum-row-schlag .baum-name-cell .name,
.baum-row-kultur .baum-name-cell .name {
  font-size: 0.88rem;
}

.baum-name-cell .sub {
  font-size: 0.76rem;
  color: var(--ink-soft);
}

.baum-field {
  display: flex;
  flex-direction: column;
  gap: 0.05rem;
  min-width: 0;
}

.baum-field .k {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.65rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted-badge);
}

.baum-field .v {
  font-size: 0.86rem;
}

.baum-field .v.mono {
  font-size: 0.83rem;
}

.baum-actions {
  display: flex;
  gap: 0.15rem;
  opacity: 0.45;
  transition: opacity 0.15s ease;
}

.baum-row:hover .baum-actions,
.baum-row:focus-within .baum-actions,
.baum-row.editing .baum-actions {
  opacity: 1;
}

.baum-icon-btn {
  width: 1.75rem;
  height: 1.75rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: var(--ink-soft);
  border-radius: 6px;
  cursor: pointer;
}

.baum-icon-btn:hover {
  background: var(--surface-sunken);
  color: var(--ink);
}

.baum-icon-btn.danger:hover {
  background: #fbeaea;
  color: #b3423a;
}

.baum-icon-btn.save {
  color: var(--iwmp-green-dark);
}

.baum-icon-btn svg {
  width: 0.95rem;
  height: 0.95rem;
}

.baum-schlaege {
  background: var(--green-tint);
  border-top: 1px solid var(--line);
  padding: 0.6rem 0.6rem 0.6rem 2.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.baum-schlag {
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  position: relative;
}

.baum-schlag::before {
  content: "";
  position: absolute;
  left: -1.15rem;
  top: 1.35rem;
  width: 0.9rem;
  height: 1px;
  background: var(--line);
}

.baum-kulturen {
  background: var(--green-tint-deep);
  border-top: 1px solid var(--line);
  padding: 0.5rem 0.5rem 0.5rem 2.4rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.baum-kultur {
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: 7px;
}

.baum-empty {
  padding: 1.1rem 1rem;
  color: var(--ink-soft);
  font-size: 0.85rem;
  font-style: italic;
}

/* Telemetry section inside an expanded Sensor box
 * (app/templates/_sensor_macros.html, app/static/js/sensor-telemetry.js) -
 * sits below the Zuordnungen sub-list, same indent, plain surface (not
 * the tree's green tint) since it isn't another nesting level. */
.sensor-telemetrie {
  padding: 0.6rem 0.6rem 0.6rem 2.4rem;
  border-top: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.sensor-charts {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.sensor-charts svg {
  max-width: 100%;
  height: auto;
}

.sensor-chart-empty {
  color: var(--ink-soft);
  font-size: 0.85rem;
  font-style: italic;
}

/* Inline edit state */
.baum-row.editing {
  background: var(--amber-tint);
  outline: 1px dashed var(--amber-line);
  outline-offset: -1px;
  border-radius: 7px;
}

.baum-row.editing input,
.baum-row.editing select {
  font: inherit;
  font-size: 0.85rem;
  width: 100%;
  padding: 0.3rem 0.45rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
}

.baum-row.editing input[type="date"] {
  font-family: "IBM Plex Mono", monospace;
}

/* Sorte's <select> + "type new" fallback stack vertically in
 * .baum-name-cell (see kulturen/_zeile_form.html), same spacing as the
 * cell's own name/sub pairing. */
.baum-row.editing .baum-name-cell select {
  margin-bottom: 0.25rem;
}

/* Filter toolbar (Aktuell/Alle/Zeitraum) above the tree */
.baum-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.baum-filter {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.25rem;
  box-shadow: var(--shadow);
}

.baum-filter a {
  font-size: 0.82rem;
  font-weight: 600;
  border: none;
  background: transparent;
  color: var(--ink-soft);
  padding: 0.4rem 0.85rem;
  border-radius: 999px;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s ease, color 0.15s ease;
}

.baum-filter a:hover {
  color: var(--ink);
}

.baum-filter a.active {
  background: var(--iwmp-green);
  color: #fff;
}

@media (max-width: 720px) {
  .baum-row-parzelle {
    grid-template-columns: 1.6rem 2.2rem 1fr auto;
  }
  .baum-row-parzelle .baum-field {
    display: none;
  }
  .baum-row-schlag {
    grid-template-columns: 1.6rem 2.2rem 1fr auto;
  }
  .baum-row-schlag .baum-field {
    display: none;
  }
  .baum-row-kultur {
    grid-template-columns: 1fr auto;
  }
  .baum-row-kultur .baum-field {
    display: none;
  }
  .baum-row-massnahme {
    grid-template-columns: 1fr auto;
  }
  .baum-row-massnahme .baum-field {
    display: none;
  }
  .baum-row-sensor {
    grid-template-columns: 1.6rem 1fr auto;
  }
  .baum-row-sensor .baum-field {
    display: none;
  }
  .baum-row-zuordnung {
    grid-template-columns: 1fr auto;
  }
  .baum-row-zuordnung .baum-field {
    display: none;
  }
}

/*
 * Admin section (app/routers/admin.py, app/templates/admin/) - a persistent
 * left menu of reference lists + a swappable right content pane, the same
 * "shell + htmx-swapped body" shape as #map-pane/#data-pane above, just
 * without a map: nothing here needs Split.js or a live JS object to
 * preserve across navigation, so the shell itself is plain CSS.
 */
#admin-menu {
  width: 220px;
  flex-shrink: 0;
  overflow-y: auto;
  background: var(--surface);
  border-right: 1px solid var(--line);
}

#admin-menu .list-group-item {
  border: none;
  border-radius: 7px;
  color: var(--ink-soft);
  font-weight: 500;
}

#admin-menu .list-group-item:hover {
  background: var(--surface-sunken);
  color: var(--ink);
}

#admin-menu .list-group-item.active {
  background: var(--green-tint);
  color: var(--iwmp-green-dark);
  font-weight: 600;
}

#admin-content {
  flex: 1 1 auto;
  overflow-y: auto;
  min-width: 0;
}

/*
 * Split map/data layout (see architecture.md's "Map" section). #split-container
 * fills the space below the navbar; Split.js drives the divider at >=992px
 * (see app/static/js/split-layout.js), below that the panes stack via the
 * media query at the bottom of this block.
 */
#split-container {
  min-height: 0; /* let children shrink/scroll inside a flex parent */
}

#map-pane {
  /* flex-basis must stay `auto` (the "0 0 auto" here) so Split.js's inline
   * `width` (see app/static/js/split-layout.js) actually drives sizing on
   * drag — a fixed flex-basis like `40%` would silently win over `width`
   * per the flexbox spec, making the divider look draggable but do nothing. */
  flex: 0 0 auto;
  min-height: 320px;
  position: relative; /* anchors #layer-control */
}

#map {
  height: 100%;
  width: 100%;
}

/* Layer-toggle control (see app/static/js/map-shell.js's setLayerControlVisible),
 * shown only on list views with more than one overlay to toggle. Lives here
 * (not in a body partial) because #map-pane is outside the htmx-swapped
 * region — see architecture.md's Map section. */
#layer-control {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  z-index: 1;
  background: rgba(255, 255, 255, 0.9);
}

#data-pane {
  flex: 1 1 auto;
  overflow-y: auto;
}

.gutter {
  background-color: var(--line);
  background-repeat: no-repeat;
  background-position: 50%;
}

.gutter.gutter-horizontal {
  cursor: col-resize;
}

@media (max-width: 991.98px) {
  #map-pane {
    flex: 0 0 auto;
    height: 45vh;
  }

  #data-pane {
    flex: 0 0 auto;
  }
}
