/* hive-keeper user portal — page-specific styles on top of Pico and the shared
   common.css. */

main.container {
  max-width: 60rem;
  /* Our max-width override keeps the container fluid below 60rem, but Pico drops
     the container padding to 0 from 576px up (it relies on centring instead).
     Between 576px and 60rem that left content glued to the edge — restore the
     side padding so there's always a gutter. */
  padding-left: var(--pico-spacing);
  padding-right: var(--pico-spacing);
}

/* Tenant's own logo, shown in the brand slot in place of the product logo. */
.tenant-brand-logo {
  height: 2.6rem;
  max-width: 12rem;
  object-fit: contain;
  display: block;
}

/* Language dropdown: globe + current code, opens a small menu (Deutsch/English).
   Mirrors the avatar-menu pattern; scales to more languages. */
.lang-menu {
  position: relative;
  margin: 0;
  list-style: none;
}

button.lang-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  width: auto;
  margin: 0;
  padding: 0.25rem 0.5rem;
  background: transparent;
  border: 1px solid var(--pico-muted-border-color);
  border-radius: var(--pico-border-radius);
  color: var(--pico-contrast);
  font-size: 0.85em;
  cursor: pointer;
  --pico-box-shadow: none;
}

button.lang-toggle:hover {
  background: var(--pico-secondary-background);
}

.lang-toggle .globe-icon {
  width: 1em;
  height: 1em;
}

.lang-caret {
  font-size: 0.7em;
  opacity: 0.7;
}

.lang-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 0.3rem);
  z-index: 10;
  min-width: 8rem;
  padding: 0.3rem;
  background: var(--pico-card-background-color);
  border: 1px solid var(--pico-muted-border-color);
  border-radius: var(--pico-border-radius);
  box-shadow: var(--pico-card-box-shadow);
}

.lang-option {
  display: block;
  width: 100%;
  margin: 0;
  padding: 0.4rem 0.5rem;
  background: none;
  border: none;
  border-radius: var(--pico-border-radius);
  text-align: left;
  font-size: 0.9em;
  font-weight: normal;
  color: var(--pico-contrast);
  cursor: pointer;
}

.lang-option:hover {
  background: var(--pico-secondary-background);
  color: var(--pico-secondary-inverse);
}

.lang-option[aria-current="true"] {
  font-weight: 700;
}

/* Right-align the language dropdown above the login / activation / reset card. */
.lang-top {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 0.5rem;
}

/* Keep the inline refresh button from stretching to full width in the header. */
.reload {
  width: auto;
  margin: 0;
}

article > header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

table th[scope="row"] {
  width: 12rem;
  white-space: nowrap;
}

/* ---- Monitoring dashboard ---- */
/* Sub-heading within a card (e.g. "Active" / "Past" in the deployments list). */
.dash-heading {
  margin: 1.25rem 0 0.6rem;
  font-size: 1rem;
}

/* Card section heading with an optional trailing action (e.g. "+ Add deployment"). */
.dash-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.8rem;
}
.dash-section-head strong {
  font-size: 1.05rem;
}
/* Direct action buttons only — don't bleed into a nested kebab menu's panel
   buttons (those keep their full-width .kebab-action styling). */
.dash-section-head > button {
  width: auto;
  margin: 0;
}

/* Small icon-only button (refresh, battery-chart trigger). */
.icon-button {
  width: auto;
  margin: 0;
  padding: 0.2rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--pico-muted-color);
  cursor: pointer;
  --pico-box-shadow: none;
  line-height: 0;
}
.icon-button:hover {
  color: var(--pico-primary);
  background: transparent;
}
.icon-button:focus-visible {
  outline: 2px solid var(--pico-primary);
  outline-offset: 2px;
}

/* Responsive grids of deployment / device cards. */
.deploy-grid,
.dash-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 1rem;
}
.deploy-card,
.hive-card {
  margin: 0;
  padding: 1rem 1.1rem;
}
/* Active-deployment cards link to the detail page. */
.deploy-card.clickable {
  cursor: pointer;
}
.deploy-card.clickable:hover {
  outline: 1px solid var(--pico-primary);
}

/* Forage photo header: a full-bleed image at the top of the card with a small
   forage label, an ⓘ credit toggle and an expandable attribution panel. */
.deploy-card {
  position: relative;
  overflow: hidden;
}
.dep-photo {
  position: relative;
  margin: -1rem -1.1rem 0.8rem;
  height: 150px;
  background: var(--pico-muted-border-color);
}
.dep-photo > img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
/* Detail page: a flat full-width photo banner with the key/value list below it. */
.dep-photo-detail {
  width: 100%;
  margin: 0 0 1.1rem;
  height: 150px;
}
.dep-photo-detail > img {
  border-radius: var(--pico-border-radius);
}
.dep-detail-top .hive-kv {
  margin: 0;
}
.dep-photo-label {
  position: absolute;
  left: 0.5rem;
  bottom: 0.5rem;
  padding: 0.15rem 0.55rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: #fff;
  background: rgba(0, 0, 0, 0.7);
  border-radius: 1rem;
  max-width: calc(100% - 3rem);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.credit-toggle {
  position: absolute;
  top: 0.4rem;
  right: 0.4rem;
  width: 1.7rem;
  height: 1.7rem;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  background: rgba(0, 0, 0, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 50%;
  cursor: pointer;
}
.credit-toggle > svg {
  display: block;
}
.credit-toggle:hover {
  background: rgba(0, 0, 0, 0.85);
}
/* High-contrast attribution panel: solid dark surface, light text, bright links —
   readable over any photo. */
.credit-panel {
  position: absolute;
  top: 2.3rem;
  right: 0.4rem;
  left: 0.4rem;
  max-width: 19rem;
  margin-left: auto;
  padding: 0.55rem 0.7rem;
  font-size: 0.8rem;
  line-height: 1.4;
  color: #f3f5f8;
  background: #14171c;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: var(--pico-border-radius);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.5);
  cursor: default;
}
/* Force every text node in the panel light — defeat any global text colour
   (e.g. .muted / Pico --pico-color) that would otherwise darken it. */
.credit-panel,
.credit-panel p,
.credit-panel span,
.credit-panel strong {
  color: #f3f5f8;
}
.credit-panel p {
  margin: 0 0 0.25rem;
}
.credit-panel p:last-child {
  margin-bottom: 0;
}
.credit-panel .credit-title {
  font-weight: 700;
}
.credit-panel a {
  color: #8fc4ff;
  text-decoration: underline;
}
.credit-panel a:hover {
  color: #b9daff;
}
.credit-panel .muted {
  color: rgba(243, 245, 248, 0.7);
}

/* Compact inline action buttons in tables (deployments list). */
table td button {
  width: auto;
  margin: 0 0 0 0.4rem;
  padding: 0.25rem 0.6rem;
}
/* Action column: a real table cell (no flex — that drops it from the table's
   column layout), right-aligned with inline button + kebab on one line. */
.row-actions {
  text-align: right;
  white-space: nowrap;
}
/* Deployment name: plain text, but the whole cell opens the detail view. */
.dep-name {
  font-weight: 600;
  cursor: pointer;
}
.nowrap {
  white-space: nowrap;
}

/* Leaflet location picker in the deployment modal. */
.deploy-map {
  height: 18rem;
  margin: 0.25rem 0 0.75rem;
  border-radius: var(--pico-border-radius);
  z-index: 0;
}
/* Undo Pico styles that leak onto Leaflet (img max-width distorts the marker;
   Pico's <a>/focus styling breaks the zoom buttons and adds a halo on the pin). */
.leaflet-container img {
  max-width: none;
}
.leaflet-bar a {
  display: block;
  width: 30px;
  height: 30px;
  line-height: 30px;
  padding: 0;
  text-align: center;
  font-size: 1.25rem;
  font-weight: 700;
  color: #333;
  background: #fff;
  text-decoration: none;
  box-shadow: none;
  border-radius: 0;
}
.leaflet-bar a:hover {
  background: #f4f4f4;
  color: #000;
}
.leaflet-control-attribution a {
  text-decoration: none;
  background: none;
}
.leaflet-container :focus {
  box-shadow: none !important;
  outline: none;
}
.leaflet-marker-icon,
.leaflet-marker-shadow {
  background: none;
  border: none;
}

/* Table pager (deployments list): count left, prev/next right. */
.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin: 0.5rem 0 1rem;
}
.pager button {
  width: auto;
  margin: 0 0 0 0.4rem;
}
.deploy-card strong {
  display: block;
}
/* Title on the left, Waagen-ID on the right of the same row. */
.dep-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
}
.dep-device {
  font-size: 0.85em;
  flex: none;
}
/* Weight change on a deployment card: big total + smaller "today" beside it. */
.dep-delta {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0.1rem 0.6rem;
  margin: 0.4rem 0 0.3rem;
}
.dep-delta-total {
  font-size: 1.7rem;
  font-weight: 700;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}
.dep-delta-today {
  font-size: 0.85em;
  color: var(--pico-muted-color);
  font-variant-numeric: tabular-nums;
}
.dep-desc {
  margin: 0.35rem 0 0.25rem;
}
.dep-meta {
  margin: 0.1rem 0;
  font-size: 0.85em;
}
.dep-loc {
  font-size: 0.85em;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin: 0.1rem 0;
}
.dep-loc-icon {
  flex: none;
}
/* Map-pin button that opens the read-only map view. */
.map-icon {
  --pico-box-shadow: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.6rem;
  height: 1.6rem;
  margin: 0;
  padding: 0;
  border: none;
  border-radius: var(--pico-border-radius);
  background: transparent;
  color: var(--pico-primary);
  cursor: pointer;
}
.map-icon:hover,
.map-icon:focus-visible {
  background: var(--pico-secondary-background);
  color: var(--pico-primary-hover);
}

/* Device card: hardware id + battery on top, then a label/value list. */
.hive-card-head {
  margin-bottom: 0.6rem;
}
.hive-card-head code {
  font-weight: 700;
}
.hive-kv {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.25rem 0.9rem;
  margin: 0;
}
.hive-kv dt {
  color: var(--pico-muted-color);
}
.hive-kv dd {
  margin: 0;
  overflow-wrap: anywhere;
}
/* Keep the timestamp on one line (it wrapped after the comma on narrow cards). */
.hive-kv .when {
  white-space: nowrap;
}
/* A template x-if wraps each optional dt/dd pair; keep the grid alignment. */
.dl-row {
  display: contents;
}

/* Signal-strength bars, drawn as one SVG so they stay even at fractional zoom. */
.signal-svg {
  height: 0.9em;
  width: auto;
  margin-right: 0.4rem;
  vertical-align: -0.1em;
}
.signal-svg rect {
  fill: var(--pico-muted-border-color);
}
.signal-svg rect.on {
  fill: var(--pico-primary, #1095c1);
}

/* Operator value with its brand icon (Simple Icons SVG injected via x-html). */
.operator-cell {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.operator-icon {
  display: inline-flex;
  align-items: center;
}
.operator-icon svg {
  height: 1.15em;
  width: auto;
}

/* SIM data-usage bar: fill shows the share of the allowance consumed. */
.value-with-icon {
  display: flex;
  align-items: center;
  gap: 0.3rem;
}
/* The chart-icon glyphs sit low in their viewBox; lift them to optically centre. */
.value-with-icon .icon-button {
  position: relative;
  top: -2px;
}
.usage-bar {
  position: relative;
  width: 100%;
  min-width: 6rem;
  max-width: 12rem;
  height: 0.6rem;
  border-radius: 999px;
  background: var(--pico-muted-border-color);
  overflow: hidden;
  cursor: help;
}
.usage-bar-fill {
  height: 100%;
  border-radius: inherit;
  background: var(--pico-primary, #1095c1);
  transition: width 0.3s ease;
}
.usage-bar.is-warn .usage-bar-fill {
  background: #e0922f;
}
.usage-bar.is-danger .usage-bar-fill {
  background: var(--hk-error, #cc1b6b);
}

/* Battery-history modal: wider dialog, control row, chart. */
dialog > article.wide-modal {
  max-width: 48rem;
}
.chart-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: flex-end;
  margin-bottom: 0.75rem;
}
.inline-field {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  margin: 0;
}
.inline-field select,
.inline-field input {
  margin: 0;
  width: auto;
}
/* Readings controls: keep Auflösung and the range column top-aligned. */
.readings-controls {
  align-items: flex-start;
}
/* Range column: a [label | field] grid so the custom "Von" field lands
   directly under the "Zeitraum" select (same column). */
.range-col {
  display: grid;
  grid-template-columns: max-content auto;
  align-items: center;
  gap: 0.5rem 0.6rem;
}
.range-col .rc-label {
  white-space: nowrap;
}
/* Each field keeps its natural width, left-aligned in the column, so the
   Zeitraum select doesn't stretch to the wider Von/Bis row. */
.range-col .rc-field {
  justify-self: start;
  width: auto;
  margin: 0;
}
.custom-range {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
/* Narrower date+time inputs for the Von/Bis pickers. (!important to beat
   Pico's high-specificity input width rule.) */
.dt-input {
  width: 10.5rem !important;
  /* Drop Pico's default input margin so the Von/Bis labels center on the field. */
  margin: 0 !important;
}
.tz-note {
  font-size: 0.8em;
  margin: 0.25rem 0 0.75rem;
}
.battery-chart {
  width: 100%;
  height: 340px;
}

/* Grouped reading charts on the deployment detail (ported from the admin readings page). */
.readings-section {
  margin-top: 1.25rem;
}
.reading-charts {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.detail-card {
  margin: 0;
  padding: 1rem 1.1rem;
}
.detail-card h3 {
  margin: 0 0 0.6rem;
  font-size: 1rem;
}
/* Card header: title left, the save-as-image button right. */
.readings-chart {
  width: 100%;
  height: 300px;
}

/* Fullscreen chart modal: a near-full-viewport dialog with the chart filling it. */
.chart-full-dialog article {
  max-width: 96vw;
  width: 96vw;
  max-height: 94vh;
  margin: 3vh auto;
}
.chart-full {
  width: 100%;
  height: calc(86vh - 6rem);
  min-height: 320px;
}

/* On phones, modals fill the screen edge-to-edge (no margin / rounded corners),
   so the limited space isn't wasted on a centred, bordered card. */
@media (max-width: 640px) {
  dialog > article,
  dialog > article.wide-modal,
  .chart-full-dialog > article {
    width: 100%;
    max-width: none;
    min-width: 0;
    height: 100vh;
    height: 100dvh;
    max-height: none;
    margin: 0;
    border-radius: 0;
    overflow-y: auto;
  }
  .chart-full {
    height: calc(100dvh - 7rem);
  }
}
