/* hive-keeper admin SPA — custom styles on top of Pico.
   Desktop-oriented; base font a touch smaller than Pico's default. */

:root {
  font-size: 87.5%;
  /* Status colours taken from the logo: navy blue for info/confirmations,
     rose/magenta for errors and warnings. */
  --hk-info: #243d7a;
  --hk-error: #cc1b6b;
  /* Logo blue-violet, used for the "active" status chip. */
  --hk-active: #4e45e8;
  /* Chart series colours from the logo palette (navy + rose). */
  --hk-chart-1: #243d7a;
  --hk-chart-2: #cc1b6b;
}

[x-cloak] {
  display: none !important;
}

main.container {
  max-width: 72rem;
}

.login-view {
  max-width: 24rem;
  margin: 12vh auto 0;
}

/* Logo: large on the login card, compact in the top nav. */
.login-logo {
  display: block;
  height: 4.5rem;
  margin: 0 auto 0.75rem;
}

/* Login head (logo + wordmark + subtitle) centred under the logo. */
.login-view hgroup {
  text-align: center;
}

/* Wordmark: "HIVE" bold, "KEEPER" light. */
.wordmark {
  font-weight: 300;
  letter-spacing: 0.05em;
  margin-bottom: 0.25rem;
}

.hive {
  font-weight: 800;
}

/* Top-nav brand: logo + product name. */
.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.brand-logo {
  height: 2.4rem;
}

.brand-name {
  font-size: 1.05rem;
  font-weight: 300;
  letter-spacing: 0.04em;
}

.muted {
  color: var(--pico-muted-color);
}

.error {
  color: var(--hk-error);
  font-weight: 600;
}

/* Link-style button (e.g. "Forgot password?") — not a boxed button. */
.link-button {
  display: block;
  width: 100%;
  margin-top: 0.5rem;
  padding: 0.25rem;
  background: none;
  border: none;
  color: var(--pico-primary);
  font-size: 0.85em;
  text-decoration: underline;
  cursor: pointer;
}

.link-button:hover {
  color: var(--pico-primary-hover);
}

/* Clickable brand → home. */
.brand-home {
  cursor: pointer;
}

/* Tenant filter above the shared Devices table. */
.device-filter {
  max-width: 22rem;
  margin-bottom: 1rem;
}

/* Wider dialog for the deployment editor (holds a map + date pickers). */
dialog > article.wide-modal {
  max-width: 48rem;
}

/* Form controls (checkboxes, native date/time pickers) follow the purple accent.
   Note: the native date-picker popup only honours accent-color in some browsers
   (Chromium yes, Firefox largely ignores it). */
:root {
  accent-color: var(--pico-primary);
}

/* Leaflet location picker in the deployment form. */
.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/
   tiles; Pico's <a> styling makes the +/- zoom buttons look off). */
.leaflet-container img {
  max-width: none;
}

/* Restore Leaflet's zoom-button geometry (Pico's <a> padding/line-height broke it). */
.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-bar a.leaflet-disabled {
  color: #bbb;
  background: #f7f7f7;
}

.leaflet-control-attribution a {
  text-decoration: none;
  background: none;
}

/* Kill Pico's purple focus halo / backgrounds on map elements — it appeared as
   a lila box behind the (focusable) marker pin. */
.leaflet-container :focus {
  box-shadow: none !important;
  outline: none;
}

.leaflet-marker-icon,
.leaflet-marker-shadow {
  background: none;
  border: none;
}

/* flatpickr in the purple theme. */
.flatpickr-day.selected,
.flatpickr-day.selected:hover,
.flatpickr-day.startRange,
.flatpickr-day.endRange {
  background: var(--pico-primary);
  border-color: var(--pico-primary);
  color: var(--pico-primary-inverse);
}

.flatpickr-day.today {
  border-color: var(--pico-primary);
}

.flatpickr-day:hover {
  background: var(--pico-secondary-background);
}

/* Toast notifications: stacked top-right, colour-coded, click to dismiss. */
.toast-stack {
  position: fixed;
  top: 1.25rem;
  right: 1.25rem;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  width: min(30rem, calc(100vw - 2.5rem));
}

.toast {
  padding: 1rem 1.25rem;
  border-radius: var(--pico-border-radius);
  color: #fff;
  font-size: 1em;
  font-weight: 600;
  line-height: 1.4;
  box-shadow: var(--pico-card-box-shadow);
  cursor: pointer;
  animation: toast-in 0.2s ease-out;
}

.toast.info {
  background: var(--hk-info);
}

.toast.error {
  background: var(--hk-error);
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(-0.5rem); }
  to { opacity: 1; transform: translateY(0); }
}

/* Main navigation: brand + sections left, avatar menu right. */
nav.topnav {
  margin-bottom: 1.5rem;
  border-bottom: 1px solid var(--pico-muted-border-color);
}

/* Menu/breadcrumb links: neutral, not the purple accent. Pico drives link colour
   through the --pico-color variable (and flips it to the accent on
   hover/active/aria-current), so we override the variable, not `color`. */
nav.topnav a,
nav[aria-label="breadcrumb"] a {
  --pico-color: var(--pico-contrast);
  --pico-underline: transparent;
}

nav.topnav a[aria-current="page"] {
  font-weight: 700;
}

/* Avatar menu (top-right): round initial button + custom dropdown panel. */
.avatar-menu {
  position: relative;
  margin: 0;
  list-style: none;
}

button.avatar {
  width: auto;
  margin: 0;
  padding: 0;
  border: none;
  background: transparent;
  cursor: pointer;
  --pico-box-shadow: none;
}

button.avatar:focus {
  outline: none;
  box-shadow: none;
}

/* Keep a visible ring only for keyboard focus. */
button.avatar:focus-visible .avatar-circle {
  outline: 2px solid var(--pico-primary);
  outline-offset: 2px;
}

.avatar-circle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.2rem;
  height: 2.2rem;
  border-radius: 50%;
  background: var(--pico-primary-background);
  color: var(--pico-primary-inverse);
  font-weight: 700;
}

.avatar-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 0.4rem);
  z-index: 10;
  min-width: 13rem;
  padding: 0.75rem;
  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);
}

.avatar-email {
  margin: 0 0 0.5rem;
  font-size: 0.85em;
  color: var(--pico-muted-color);
  word-break: break-all;
}

/* Subtle menu-item look (not a boxed button), distinct from Sign out.
   Pico redefines --pico-color to the (white) button text inside <button>, so use
   --pico-contrast to stay readable on the panel background. */
.avatar-action {
  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;
}

.avatar-action:hover {
  background: var(--pico-secondary-background);
  color: var(--pico-secondary-inverse);
}

.avatar-divider {
  margin: 0.4rem 0;
  border: none;
  border-top: 1px solid var(--pico-muted-border-color);
}

.avatar-signout {
  width: 100%;
  margin: 0;
}

/* Breadcrumb on sub-pages — sits directly under the top nav, above the card. */
nav[aria-label="breadcrumb"] {
  margin-top: 0.25rem;
  margin-bottom: 0.5rem;
}

/* Section header: title left, "+ Add" action right. */
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.section-head button {
  width: auto;
  margin: 0;
}

/* Modal footer: actions on the right, compact. */
dialog article footer {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
}

dialog article footer button {
  width: auto;
  margin: 0;
}

/* Action column: right-aligned, compact buttons. */
table td:last-child {
  text-align: right;
  white-space: nowrap;
}

table button {
  width: auto;
  margin: 0 0 0 0.4rem;
  padding: 0.25rem 0.6rem;
}

table input,
table select {
  margin: 0;
}

/* Role checkbox group on the user form. */
fieldset.roles {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 1.25rem;
  margin: 0.5rem 0 1rem;
}

fieldset.roles label {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.logo-field .logo-preview {
  max-height: 6rem;
  max-width: 16rem;
  display: block;
  margin-bottom: 0.75rem;
}

/* Tenant logo thumbnail in the list. */
.row-logo {
  height: 1.8rem;
  max-width: 4rem;
  vertical-align: middle;
}

/* Small icon-only button (battery chart trigger, kebab toggle). */
.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;
}

/* Battery % next to its history-chart icon. */
.battery-cell {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  white-space: nowrap;
}

/* Keep the row's actions on one line, right-aligned: Deployments button + kebab. */
.row-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.75rem;
}

/* Per-row "⋮" action menu — mirrors the avatar menu. */
.kebab-menu {
  position: relative;
}

.kebab-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 0.3rem);
  z-index: 10;
  min-width: 9rem;
  /* Grow to fit the longest entry instead of wrapping it. */
  width: max-content;
  max-width: 18rem;
  padding: 0.4rem;
  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);
}

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

.kebab-action:hover {
  background: var(--pico-secondary-background);
  color: var(--pico-secondary-inverse);
}

.kebab-action.danger {
  color: var(--pico-del-color, #b3261e);
}

.kebab-divider {
  margin: 0.3rem 0;
  border: none;
  border-top: 1px solid var(--pico-muted-border-color);
}

/* Battery history chart (inline SVG). */
.battery-chart-wrap {
  margin: 0.5rem 0 0.25rem;
}

.battery-chart {
  width: 100%;
  height: auto;
  display: block;
}

/* Readings (Messreihen) page: sensor select + timescale buttons + ECharts graph. */
.readings-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.5rem;
}

.readings-type {
  margin: 0;
  min-width: 14rem;
}

.readings-scales {
  display: flex;
  gap: 0.25rem;
}

.readings-scales button {
  width: auto;
  margin: 0;
}

/* Highlight the active timescale (otherwise plain outline buttons). */
.readings-scales button.active-scale {
  background: var(--pico-primary);
  color: var(--pico-primary-inverse);
  border-color: var(--pico-primary);
}

.readings-chart {
  width: 100%;
  height: 380px;
}

/* Filter/search box above a table (tenants, MCC/MNC). */
.table-filter,
.mcc-search {
  max-width: 28rem;
}

/* Authority tags (chips) */
.tag {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.1rem 0.55rem;
  margin: 0.15rem 0.25rem 0.15rem 0;
  border-radius: 1rem;
  background: var(--pico-muted-border-color);
  color: var(--pico-color);
  font-size: 0.8em;
  white-space: nowrap;
}

/* Status chips: outlined, colour-coded. */
.tag.active {
  background: transparent;
  border: 1px solid var(--hk-active);
  color: var(--hk-active);
  text-transform: uppercase;
}

.tag.suspended {
  background: transparent;
  border: 1px solid var(--pico-del-color);
  color: var(--pico-del-color);
}

button.tag-remove {
  width: auto;
  margin: 0;
  padding: 0;
  border: none;
  background: transparent;
  color: inherit;
  font-size: 1.1em;
  line-height: 1;
  cursor: pointer;
}

/* Tag input: chips + inline text field inside one bordered box. */
.tag-input {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.1rem;
  padding: 0.3rem 0.5rem;
  margin-bottom: 1rem;
  border: 1px solid var(--pico-form-element-border-color);
  border-radius: var(--pico-border-radius);
}

.tag-input select {
  width: auto;
  min-width: 7rem;
  margin: 0;
  padding: 0.25rem 1.5rem 0.25rem 0.25rem;
  border: none;
  background-color: transparent;
  --pico-box-shadow: none;
}

.tag-input select:focus {
  outline: none;
  box-shadow: none;
}

.tags-cell .tag {
  margin: 0.1rem 0.25rem 0.1rem 0;
}

/* Collapsible "advanced" disclosure on forms (e.g. cellular APN / SIM PIN). */
details.advanced {
  margin: 0.25rem 0 0.5rem;
}

details.advanced > summary {
  cursor: pointer;
  font-size: 0.875rem;
  color: var(--pico-muted-color);
}

details.advanced > small {
  display: block;
  margin: 0.35rem 0 0.6rem;
}

/* Device commands modal: action buttons grid + pending list. */
.command-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 0.75rem;
}
.command-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.command-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.3rem 0;
  border-top: 1px solid var(--pico-muted-border-color, #e0e0e0);
}

/* WARN-level chip (device logs). */
.tag.pending {
  background: transparent;
  border: 1px solid var(--pico-color-amber, #b8860b);
  color: var(--pico-color-amber, #b8860b);
}

/* Device log table: horizontal scroll on narrow screens; keep the time column on one line. */
.log-table-wrap {
  overflow-x: auto;
}
.log-table-wrap td.nowrap {
  white-space: nowrap;
}

/* Device-details page: responsive grid of themed cards with label/value lists. */
.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1rem;
}
.detail-card {
  margin: 0;
  padding: 1rem 1.1rem;
}
.detail-card h3 {
  margin: 0 0 0.6rem;
  font-size: 1rem;
}
.detail-card dl {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.2rem 0.9rem;
  margin: 0 0 0.6rem;
}
.detail-card dt {
  color: var(--pico-muted-color);
}
.detail-card dd {
  margin: 0;
  overflow-wrap: anywhere;
}
/* Sensor rows wrap a dt/dd pair (single x-for root) but keep the grid alignment. */
.detail-card .dl-row {
  display: contents;
}

/* Signal-strength bars (device connectivity). Drawn as one SVG so the bars stay
   even at fractional browser zoom (no per-element sub-pixel rounding). */
.signal-svg {
  height: 0.9em;
  width: auto;
  margin-left: 0.4rem;
  vertical-align: -0.1em;
}
.signal-svg rect {
  fill: var(--pico-muted-border-color);
}
.signal-svg rect.on {
  fill: var(--pico-primary, #1095c1);
}

/* Inline label+select in a section header (e.g. the logs level filter). */
.inline-field {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  margin: 0;
}
.inline-field select {
  margin: 0;
  width: auto;
}

/* Logs table: sortable Time header + left-aligned message column. */
th.sortable {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
.log-table-wrap th.log-msg,
.log-table-wrap td.log-msg {
  text-align: left;
}

/* Logs pager bar (count + per-page + prev/next). */
.log-pager {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin: 0.5rem 0;
}

/* Prev/Next below the logs table. */
.log-pager-bottom {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  margin: 0.75rem 0;
}

/* Context-menu heading + a wider panel for command labels. */
.kebab-panel-wide {
  min-width: 13rem;
}
.kebab-heading {
  margin: 0.1rem 0.4rem 0.35rem;
  font-size: 0.72em;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--pico-muted-color);
}

/* Chart control row (resolution + range selects above a chart). */
.chart-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: flex-end;
  margin-bottom: 0.75rem;
}

/* A dd value with a trailing small icon button (e.g. SIM data + usage-graph icon). */
.detail-card dd.value-with-icon {
  display: flex;
  align-items: center;
  gap: 0.3rem;
}
.detail-card dd.value-with-icon .icon-button {
  padding: 0.1rem;
}
/* A value whose title carries extra info on hover (e.g. a sensor's timestamp). */
.has-tooltip {
  cursor: help;
}

/* Inline SIM provider logo (SVG injected via x-html). */
.sim-logo {
  display: inline-flex;
  align-items: center;
}
.sim-logo svg {
  height: 1.1em;
  width: auto;
}

/* Operator value with its brand icon (Simple Icons SVG injected via x-html,
   already tinted in the brand colour). */
.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;
}

/* SIMs settings table: compact inline selects + filter bar. */
.sim-filter {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: flex-end;
  margin-bottom: 0.75rem;
}
.sim-filter input[type="search"] {
  margin: 0;
  max-width: 22rem;
  flex: 1 1 16rem;
}
.sim-table td {
  vertical-align: middle;
}
.sim-table select {
  width: auto;
  min-width: 9rem;
  margin: 0;
}
/* Right-aligned actions cell — a normal table cell (not a flex td) so the row
   border stays aligned. */
.sim-table td.sim-actions {
  text-align: right;
}
.sim-table td.sim-actions button {
  width: auto;
  margin: 0;
}

/* Grouped reading charts: stacked cards, each chart a bit shorter than the full
   single-chart height. */
.reading-charts {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.reading-charts .readings-chart {
  height: 300px;
}
