/* What Bootstrap does not have.
 *
 * Deliberately short. Bootstrap plus the tokens in theme.css covers cards,
 * tables, forms, modals, badges, spacing and the grid; templates use its classes
 * directly. This file holds the application shell, which no CSS framework
 * provides, and the few patterns shared by more than one screen.
 *
 * Colours come from theme.css's tokens (--surface, --border, --text-*,
 * --tone-*), never from a hex code: a colour written here for one theme is the
 * colour that breaks in the other.
 */


/* --- Application shell ----------------------------------------------------
 * AdminLTE 4's app-wrapper / app-header / app-sidebar / app-main structure,
 * without its footer, drawn like the admin: sidebar, top bar and page are one
 * surface, divided by borders.
 */

:root {
  --lte-sidebar-width: 16rem;
  --lte-header-height: 4rem;
}

body:has(.adminlte-shell) {
  min-height: 100vh;
  overflow-x: hidden;
}

.adminlte-shell,
.adminlte-shell .app-wrapper {
  min-height: 100vh;
}

.adminlte-shell .app-wrapper {
  position: relative;
  background: var(--surface);
}

.adminlte-shell .app-header {
  position: fixed;
  z-index: 1035;
  top: 0;
  right: 0;
  left: var(--lte-sidebar-width);
  min-height: var(--lte-header-height);
  padding: 0 .75rem;
  background: var(--surface) !important;
  border-bottom: 1px solid var(--border);
  transition: left .2s ease-in-out;
}

.adminlte-shell .app-header .container-fluid {
  min-height: var(--lte-header-height);
}

.adminlte-shell .app-header .nav-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2.5rem;
  min-height: var(--lte-header-height);
  color: var(--text-muted);
}

.adminlte-shell .app-header .nav-link:hover,
.adminlte-shell .app-header .nav-link:focus-visible {
  color: var(--text-strong);
}

.app-search .form-control {
  background-color: var(--surface);
}

.app-sidebar-toggle {
  border: 0;
  background: transparent;
}

.app-sidebar-toggle svg {
  width: 1.25rem;
  height: 1.25rem;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-width: 2;
}

.adminlte-shell .app-sidebar {
  display: flex;
  flex-direction: column;
  position: fixed;
  z-index: 1040;
  top: 0;
  bottom: 0;
  left: 0;
  width: var(--lte-sidebar-width);
  overflow: hidden;
  background: var(--surface) !important;
  border-right: 1px solid var(--border);
  box-shadow: none !important;
  transition: margin-left .2s ease-in-out;
}

.adminlte-shell .sidebar-brand {
  display: flex;
  align-items: center;
  height: var(--lte-header-height);
  padding: 0 1.25rem;
  border-bottom: 1px solid var(--border);
}

.adminlte-shell .brand-link {
  display: flex;
  align-items: center;
  width: 100%;
  gap: .75rem;
  color: var(--text-strong);
  text-decoration: none;
}

.adminlte-shell .brand-link:hover {
  color: var(--text-strong);
  text-decoration: none;
}

.adminlte-shell .brand-mark {
  display: inline-grid;
  width: 2.25rem;
  height: 2.25rem;
  flex: 0 0 2.25rem;
  place-items: center;
  border-radius: var(--radius-card);
  background: var(--primary);
  color: #fff;
  font-weight: 700;
}

.adminlte-shell .brand-text {
  overflow: hidden;
  font-size: .9375rem;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.adminlte-shell .sidebar-wrapper {
  flex: 1;
  min-height: 0;
  padding: 1rem .75rem;
  overflow-y: auto;
}

.adminlte-shell .sidebar-menu {
  gap: .125rem;
}

/* The admin's menu item: compact, rounded, a grey fill and primary text for the
   current page. */
.adminlte-shell .sidebar-menu-item {
  display: flex;
  align-items: center;
  gap: .75rem;
  min-height: 2.5rem;
  padding: .5rem .75rem;
  border-radius: var(--bs-border-radius);
  color: var(--text);
  font-size: .875rem;
  font-weight: 500;
  text-decoration: none;
}

.adminlte-shell .sidebar-menu-item:hover,
.adminlte-shell .sidebar-menu-item:focus-visible {
  background: var(--surface-hover);
  color: var(--text-strong);
  text-decoration: none;
}

.adminlte-shell .sidebar-menu-item.active {
  background: var(--surface-active);
  color: var(--primary-text);
}

.adminlte-shell .sidebar-menu-item .material-symbols-outlined {
  width: 1.25rem;
  height: 1.25rem;
  flex: 0 0 1.25rem;
  font-size: 1.25rem;
}

.adminlte-shell .sidebar-footer {
  padding: .75rem;
  border-top: 1px solid var(--border);
}

.adminlte-shell .sidebar-footer form {
  margin: 0;
}

.adminlte-shell .sidebar-logout {
  display: flex;
  width: 100%;
  align-items: center;
  gap: .75rem;
  min-height: 2.5rem;
  padding: .5rem .75rem;
  border: 0;
  border-radius: var(--bs-border-radius);
  background: transparent;
  color: var(--text);
  font: inherit;
  font-weight: 500;
  text-align: left;
}

.adminlte-shell .sidebar-logout:hover,
.adminlte-shell .sidebar-logout:focus-visible {
  background: var(--surface-hover);
  color: var(--text-strong);
}

.adminlte-shell .sidebar-logout svg {
  width: 1.25rem;
  height: 1.25rem;
  flex: 0 0 1.25rem;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.75;
}

.adminlte-shell .app-main {
  display: flex;
  min-height: 100vh;
  margin-left: var(--lte-sidebar-width);
  padding-top: var(--lte-header-height);
  background: var(--surface);
  transition: margin-left .2s ease-in-out;
}

.adminlte-shell .app-content {
  width: 100%;
  padding: 1.5rem;
}

.adminlte-shell.sidebar-collapse .app-sidebar {
  margin-left: calc(-1 * var(--lte-sidebar-width));
}

.adminlte-shell.sidebar-collapse .app-header,
.adminlte-shell.sidebar-collapse .app-main {
  margin-left: 0;
  left: 0;
}

@media (max-width: 991.98px) {
  .adminlte-shell .app-header {
    left: 0;
  }

  .adminlte-shell .app-sidebar {
    margin-left: calc(-1 * var(--lte-sidebar-width));
  }

  .adminlte-shell .app-main {
    margin-left: 0;
  }

  .adminlte-shell.sidebar-open .app-sidebar {
    margin-left: 0;
  }

  .adminlte-shell.sidebar-open::after {
    position: fixed;
    z-index: 1039;
    inset: 0;
    background: rgba(3, 7, 18, .5);
    content: "";
  }

  .adminlte-shell .app-content {
    padding: 1rem;
  }
}

/* The theme button shows the icon of the CURRENT choice, set on <html> by
   base.html before first paint — so it is right on load without waiting for JS. */
.theme-icon-light, .theme-icon-dark, .theme-icon-auto { display: none; }
[data-theme-choice="light"] .theme-icon-light,
[data-theme-choice="dark"]  .theme-icon-dark,
[data-theme-choice="auto"]  .theme-icon-auto,
html:not([data-theme-choice]) .theme-icon-auto { display: inline-block; }


/* --- Tinted accents ---------------------------------------------------------
 * A pale fill with matching text: badges, icon tiles, banners.
 */

.tint      { background: var(--tone-gray-bg);  color: var(--tone-gray-fg); }
.tint-blue { background: var(--tone-blue-bg);  color: var(--tone-blue-fg); }
.tint-green { background: var(--tone-green-bg); color: var(--tone-green-fg); }
.tint-amber { background: var(--tone-amber-bg); color: var(--tone-amber-fg); }
.tint-red  { background: var(--tone-red-bg);   color: var(--tone-red-fg); }
.tint-cyan { background: var(--tone-sky-bg);   color: var(--tone-sky-fg); }

/* The square behind an icon on a card. */
.icon-tile {
  width: 2.25rem;
  height: 2.25rem;
  border-radius: var(--radius-card);
  display: inline-grid;
  place-items: center;
  flex: none;
}


/* --- Station badges ----------------------------------------------------------
 * Two independent facts, two badges: whether the broker says the station is
 * connected, and whether its data is fresh. Shared by the control page, the
 * property pages and the live view.
 */
.station-status {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  margin-left: .5rem;
  padding: .125rem .5rem;
  border-radius: 1rem;
  font-size: .75rem;
  font-weight: 500;
  line-height: 1.25rem;
  vertical-align: middle;
  white-space: nowrap;
}
.status-dot {
  width: .375rem;
  height: .375rem;
  border-radius: 50%;
  background: currentColor;
}
.station-status-online   { background: var(--tone-green-bg); color: var(--tone-green-fg); }
.station-status-offline  { background: var(--tone-red-bg);   color: var(--tone-red-fg); }
/* Amber and grey rather than a second red: both need attention, neither means
   the plant is down, and a screen of red teaches people to ignore red. */
.station-status-stale    { background: var(--tone-amber-bg); color: var(--tone-amber-fg); }
.station-status-unknown  { background: var(--tone-gray-bg);  color: var(--tone-gray-fg); }
/* Blue: neither good nor bad, just a different kind of thing. */
.station-status-external { background: var(--tone-blue-bg);  color: var(--tone-blue-fg); }


/* --- Login page ------------------------------------------------------------ */

.login-page {
  display: flex;
  min-height: 100vh;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: var(--surface-muted);
}

.login-box {
  width: 100%;
  max-width: 380px;
}

.login-card {
  overflow: hidden;
}

.login-logo {
  margin-bottom: .75rem;
  text-align: center;
}

.login-logo a {
  color: var(--text-strong);
  font-size: 1.25rem;
  font-weight: 600;
  text-decoration: none;
}

.login-box-msg {
  color: var(--text-muted);
  text-align: center;
}

.login-box .input-group-text .material-symbols-outlined {
  font-size: 1.25rem;
}


/* --- Utilities ------------------------------------------------------------ */
.min-w-0 { min-width: 0; }

/* A building reached from the address search. The search lands on
   /liegenschaften/<id>/#building-<pk>; this marks which card the caller meant,
   and the margin keeps it from sliding under the top bar. */
[id^="building-"] { scroll-margin-top: 5rem; }
[id^="building-"]:target > * {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
  border-radius: var(--radius-card);
}


/* --- Parameterization: heading, search, station list ------------------------
 * Here rather than in control.css because the station rows are this screen's
 * frame; control.css holds what goes inside them.
 */

.control-heading-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 2rem;
}

.control-heading-row > form { flex: 1 1 26rem; justify-content: flex-end; }

/* The search box is the way into this screen — 90 stations and nothing useful
   happens until one is picked — so it is the widest control on it. Drawn like
   every other input. */
.control-search {
  display: flex;
  width: min(100%, 36rem);
  min-height: 2.75rem;
  align-items: center;
  gap: .6rem;
  padding: 0 .85rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--bs-border-radius-lg);
  background: var(--surface);
  box-shadow: 0 1px 2px rgba(0, 0, 0, .04);
  font-size: .9375rem;
}

.control-search:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(var(--primary-rgb), .2);
}

.control-search .material-symbols-outlined {
  color: var(--text-subtle);
  font-size: 1.25rem;
}

.control-search input {
  width: 100%;
  min-width: 0;
  padding: .2rem 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text-strong);
  font: inherit;
}

.control-search input::placeholder {
  color: var(--text-subtle);
}

.stations-panel {
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  background: var(--surface);
}

.station-row {
  display: flex;
  align-items: center;
  gap: .5rem;
  min-height: 4.25rem;
  padding: .75rem 1.25rem .75rem .75rem;
  border-bottom: 1px solid var(--border);
}

.stations-panel > .station-row:last-of-type,
.stations-panel > .collapse-region:last-child {
  border-bottom: 0;
}

.station-row:has(.station-open:hover),
.station-row:has(.station-open:focus-visible) {
  background: var(--surface-hover);
}

/* The row holds two separate links: the chevron expands the station in place,
   the rest of the card opens it on its own page. They are siblings because an
   <a> cannot contain another one. */
.station-disclosure {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  align-self: stretch;
  padding: 0 .25rem;
  border-radius: var(--bs-border-radius);
  text-decoration: none;
}

.station-disclosure:hover { text-decoration: none; }

.disclosure-icon {
  color: var(--text-subtle);
  font-size: 1.4rem;
}

.station-disclosure:hover .disclosure-icon,
.station-disclosure:focus-visible .disclosure-icon {
  color: var(--primary-text);
}

.station-open {
  display: flex;
  flex: 1 1 auto;
  align-items: center;
  gap: .75rem;
  min-width: 0;
  align-self: stretch;
  color: inherit;
  text-decoration: none;
}

.station-open:hover { color: inherit; text-decoration: none; }

.station-main {
  display: flex;
  align-items: center;
  gap: .75rem;
}

.station-title {
  color: var(--text-strong);
  font-size: .9375rem;
  font-weight: 500;
}

.station-updated {
  display: flex;
  align-items: center;
  gap: .25rem;
  margin-top: .2rem;
  color: var(--text-muted);
  font-size: .8125rem;
}

.station-updated .material-symbols-outlined {
  font-size: 1rem;
}

.row-count {
  margin-left: auto;
  color: var(--text-muted);
  font-size: .8125rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.row-count .material-symbols-outlined {
  font-size: 1rem;
}

.collapse-region {
  border-bottom: 1px solid var(--border);
  background: var(--surface-muted);
}

.collapse-region[hidden] {
  display: none;
}

.collapse-region .nav-tabs {
  --bs-nav-tabs-link-active-bg: var(--surface-muted);
  --bs-nav-tabs-link-active-border-color: var(--border) var(--border) var(--surface-muted);
}

.circuits-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
  padding: 1.25rem;
}

.circuit-card {
  padding: 1rem 1.1rem .5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  background: var(--surface);
}

.circuit-title {
  color: var(--text-strong);
  font-size: .9375rem;
  font-weight: 500;
}

.status-badge,
.type-badge {
  display: inline-flex;
  align-items: center;
  padding: .1rem .5rem;
  border-radius: var(--bs-border-radius);
  font-size: .75rem;
  font-weight: 500;
  white-space: nowrap;
}

@media (max-width: 767.98px) {
  .control-heading-row {
    align-items: stretch;
    flex-direction: column;
    gap: 1rem;
  }

  .control-search {
    width: 100%;
  }

  .station-row {
    align-items: flex-start;
    padding: .75rem;
  }

  .station-row .row-count {
    display: none;
  }

  .circuits-list {
    grid-template-columns: 1fr;
    padding: 1rem;
  }
}


/* --- Property page: site plan left, facts right ------------------------------ */

/* The plan fits the window's height, so on a wide screen it cannot use the full
   width; the panel takes what is left instead of it standing empty on both sides
   of a centred plan. From 1200px the two sit side by side; below, the panel
   follows the plan.

   Side by side, the plan column is `auto` — exactly as wide as the plan — and the
   plan sizes itself against the layout (container units), not against its own
   column, which would be circular. So no gap opens between plan and panel. */
.property-layout {
  container-type: inline-size;
  display: grid;
  gap: 1.5rem;
  grid-template-columns: minmax(0, 1fr);
}
@media (min-width: 1200px) {
  .property-layout {
    grid-template-columns: auto minmax(20rem, 26rem);
    justify-content: start;
    align-items: start;
  }
  .property-layout .schematic {
    /* The layout's width less the panel and the gap; or the width at which the
       plan fills the window's height below the page header; never under 40rem. */
    width: max(40rem, min(calc(100cqw - 21.5rem), calc((100dvh - 15rem) * var(--ratio, 1.5))));
    margin-inline: 0;
  }
}

/* The plan's title, with the Edit menu at its right end. A fixed height, so
   the plan sits at the same place whether the menu is shown or not. */
.site-plan-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 2rem;
  margin-bottom: .5rem;
}

.site-plan-title {
  font-size: .875rem;
  font-weight: 600;
  margin: 0;
  color: var(--text-strong);
}

.property-panel {
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  background: var(--surface);
}
/* Level with the plan, not with the "Site plan" title above it. */
@media (min-width: 1200px) {
  .property-panel { margin-top: 2.5rem; }
}
.panel-section {
  padding: 1rem 1.1rem;
}
.panel-section + .panel-section {
  border-top: 1px solid var(--border);
}
.panel-title {
  margin: 0 0 .6rem;
  font-size: .75rem;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.panel-actions {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  margin-top: .85rem;
}

.panel-station + .panel-station {
  margin-top: .85rem;
  padding-top: .85rem;
  border-top: 1px dashed var(--border);
}
.panel-station-name {
  font-weight: 600;
  color: var(--text-strong);
  font-size: .875rem;
}
.panel-station-status {
  display: flex;
  flex-wrap: wrap;
  gap: .35rem;
  margin: .35rem 0;
}
.panel-station-meta {
  display: flex;
  flex-wrap: wrap;
  gap: .25rem .75rem;
  font-size: .8rem;
  color: var(--text-muted);
}
.panel-station-host {
  font-family: var(--bs-font-monospace);
  font-size: .75rem;
}
.panel-links {
  display: flex;
  flex-wrap: wrap;
  gap: .25rem 1rem;
  margin-top: .4rem;
  font-size: .8rem;
}
.panel-links a {
  display: inline-flex;
  align-items: center;
  gap: .25rem;
}
.panel-links .material-symbols-outlined {
  font-size: 1rem;
}
.panel-station-status .station-status { margin-left: 0; }
