:root {
  --bg: #f4f6f8;
  --card: #fff;
  --text: #1a1f36;
  --muted: #6b7280;
  --accent: #0b6bcb;
  --accent2: #0854a0;
  --border: #e3e8ee;
  --ok: #0d7a4c;
  --err: #b42318;
  --warn: #b54708;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Segoe UI", "Noto Sans TC", "PingFang TC", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.topbar {
  display: flex; align-items: center; gap: 1.5rem;
  padding: .75rem 1.25rem;
  background: #0f172a; color: #e2e8f0;
}
.topbar a { color: #e2e8f0; }
.brand a { font-weight: 700; letter-spacing: .02em; }
.nav { display: flex; gap: 1rem; flex: 1; }
.nav a { opacity: .9; }
.nav a:hover { opacity: 1; text-decoration: none; border-bottom: 2px solid #38bdf8; }
.userbox { font-size: .9rem; color: #cbd5e1; }
.userbox a { color: #7dd3fc; }
.container { max-width: 1100px; margin: 1.25rem auto; padding: 0 1rem 2rem; }
.footer { text-align: center; color: var(--muted); font-size: .85rem; padding: 2rem 1rem; }
h1 { font-size: 1.5rem; margin: 0 0 1rem; }
h2 { font-size: 1.15rem; margin: 1.5rem 0 .75rem; }
.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 10px; padding: 1rem 1.25rem; margin-bottom: 1rem;
  box-shadow: 0 1px 2px rgba(16,24,40,.04);
}
.muted { color: var(--muted); }
.alert { padding: .75rem 1rem; border-radius: 8px; margin-bottom: 1rem; }
.alert.ok { background: #ecfdf3; color: var(--ok); border: 1px solid #abefc6; }
.alert.error { background: #fef3f2; color: var(--err); border: 1px solid #fecdca; }
label { display: block; font-size: .9rem; margin: .6rem 0 .25rem; font-weight: 600; }
input[type=text], input[type=email], input[type=password], select, textarea {
  width: 100%; max-width: 420px; padding: .5rem .65rem;
  border: 1px solid var(--border); border-radius: 8px; font: inherit; background: #fff;
}
textarea { max-width: 100%; min-height: 80px; }
.row { display: flex; flex-wrap: wrap; gap: 1rem; }
.row > div { flex: 1 1 200px; }
button, .btn {
  display: inline-block; margin-top: .75rem; padding: .5rem 1rem;
  background: var(--accent); color: #fff; border: none; border-radius: 8px;
  font: inherit; cursor: pointer; text-decoration: none;
}
button:hover, .btn:hover { background: var(--accent2); text-decoration: none; }
.btn.secondary { background: #64748b; }
.btn.danger { background: var(--err); }
.btn.small { padding: .25rem .6rem; font-size: .85rem; margin-top: 0; }
table { width: 100%; border-collapse: collapse; font-size: .95rem; }
th, td { text-align: left; padding: .55rem .4rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; }
.tree-indent { display: inline-block; }
.badge {
  display: inline-block; padding: .1rem .45rem; border-radius: 999px;
  background: #e0f2fe; color: #075985; font-size: .75rem; font-weight: 600;
}
.badge.group { background: #fef3c7; color: #92400e; }
.actions { white-space: nowrap; }
.login-wrap { max-width: 400px; margin: 3rem auto; }
.grid-stats { display: grid; grid-template-columns: repeat(auto-fit,minmax(160px,1fr)); gap: 1rem; }
.stat { background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 1rem; }
.stat .n { font-size: 1.75rem; font-weight: 700; }
.stat .l { color: var(--muted); font-size: .85rem; }
.form-actions { margin-top: 1rem; display: flex; gap: .5rem; flex-wrap: wrap; }

.lang-switch { margin-left: auto; font-size: .85rem; color: #94a3b8; white-space: nowrap; }
.lang-switch a { color: #7dd3fc; margin: 0 .15rem; }
.lang-switch strong { color: #f8fafc; margin: 0 .15rem; }
.topbar .userbox { margin-left: .5rem; }

.check-row {
  margin: .75rem 0 .25rem;
  max-width: 420px;
}
.check-row label {
  display: inline-flex;
  align-items: center;
  gap: .45rem;
  margin: 0;
  font-weight: 500;
  cursor: pointer;
}
.check-row input[type=checkbox] {
  width: auto;
  max-width: none;
  margin: 0;
  accent-color: var(--accent);
}

/* Portal */
.container-wide { max-width: 1280px; }
.portal-header-card { margin-bottom: 1rem; }
.portal-header-row {
  display: flex; flex-wrap: wrap; gap: 1rem; align-items: flex-start;
  justify-content: space-between;
}
.portal-identity { flex: 1 1 240px; }
.portal-time-form {
  display: flex; flex-wrap: wrap; gap: .75rem; align-items: flex-end;
}
.portal-time-form label {
  margin: 0; font-weight: 600; font-size: .8rem;
}
.portal-time-form input[type=datetime-local] {
  display: block; width: auto; max-width: none; margin-top: .2rem;
  padding: .4rem .5rem; border: 1px solid var(--border); border-radius: 8px; font: inherit;
}
.portal-time-form .btn { margin-top: 0; }
.chart-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
}
@media (max-width: 1024px) {
  .chart-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 640px) {
  .chart-grid { grid-template-columns: 1fr; }
}
.chart-card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 10px; overflow: hidden;
  box-shadow: 0 1px 2px rgba(16,24,40,.04);
}
.chart-header {
  padding: .55rem 1rem; border-bottom: 1px solid var(--border);
  font-weight: 600; font-size: .95rem; color: var(--text);
}
.chart-body { width: 100%; height: 280px; }
.chart-body-wrap {
  position: relative;
  width: 100%;
  min-height: 280px;
}
.chart-placeholder {
  display: none;
  position: absolute;
  inset: 0;
  z-index: 2;
  align-items: center;
  justify-content: center;
  gap: .55rem;
  flex-direction: column;
  background: rgba(255, 255, 255, .82);
  color: var(--muted, #64748b);
  font-size: .95rem;
  font-weight: 600;
  letter-spacing: .02em;
  pointer-events: none;
}
.chart-card.is-calculating .chart-placeholder,
.chart-card.is-error .chart-placeholder {
  display: flex;
}
.chart-card.is-error .chart-placeholder {
  color: #b91c1c;
  background: rgba(254, 242, 242, .92);
}
.chart-placeholder-spinner {
  width: 1.35rem;
  height: 1.35rem;
  border: 2px solid #cbd5e1;
  border-top-color: #3b82f6;
  border-radius: 50%;
  animation: astiq-spin .8s linear infinite;
}
.chart-card.is-error .chart-placeholder-spinner {
  display: none;
}
@keyframes astiq-spin {
  to { transform: rotate(360deg); }
}
.kpi-calculating {
  color: var(--muted, #64748b);
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: .02em;
}
.kpi-error {
  color: #b91c1c;
  font-size: 1rem;
  font-weight: 600;
}

.portal-no-data { margin: .5rem 0 1rem; }
.status-online { color: var(--ok); font-weight: 600; }
.status-offline { color: var(--muted); font-weight: 600; }
.portal-tree td { vertical-align: middle; }

.portal-time-form select {
  display: block; width: auto; min-width: 12rem; max-width: 22rem; margin-top: .2rem;
  padding: .4rem .5rem; border: 1px solid var(--border); border-radius: 8px; font: inherit;
  background: #fff;
}
.kpi-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  margin-top: .75rem;
}
@media (max-width: 900px) {
  .kpi-row { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 480px) {
  .kpi-row { grid-template-columns: 1fr; }
}
.kpi-card { margin: 0; padding: 1rem 1.1rem; }
.kpi-label {
  color: var(--muted); font-size: .75rem;
  text-transform: uppercase; letter-spacing: .03em;
}
.kpi-value { font-size: 1.75rem; font-weight: 700; line-height: 1.2; margin-top: .25rem; }
.kpi-unit { font-size: .85rem; font-weight: 500; color: var(--muted); }

.table-wrap { overflow-x: auto; }
.meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: .4rem .75rem;
}
.meta-item .l { color: var(--muted); font-size: .7rem; text-transform: uppercase; letter-spacing: .03em; }
.meta-item .v { font-weight: 600; font-size: .9rem; }
.cells-row { display: flex; flex-wrap: wrap; gap: .3rem; }
.cell-chip {
  background: #f8fafc; border: 1px solid var(--border); border-radius: 6px;
  padding: .15rem .35rem; font-size: .78rem;
  line-height: 1.25;
}
.cell-chip .n { color: var(--muted); font-size: .68rem; margin-right: .2rem; }
.cell-chip.is-max {
  border-color: #91d5ff;
  background: #e6f7ff;
  color: #1890ff;
}
.cell-chip.is-max .n { color: #1890ff; }
.cell-chip.is-min {
  border-color: #ffccc7;
  background: #fff2f0;
  color: #ff4d4f;
}
.cell-chip.is-min .n { color: #ff4d4f; }

.meta-card h2, .cells-card h2 { margin-top: 0; }
.track-card h2 { margin-top: 0; }
.track-body { height: 360px; }
.map-track {
  height: 400px;
  width: 100%;
  border-radius: 8px;
  border: 1px solid var(--border);
  z-index: 0;
  background: #e8eef4;
}
.track-card table th, .track-card table td { white-space: nowrap; }

.track-card table tr.track-row { cursor: pointer; }
.track-card table tr.track-row:hover { background: #eef5fc; }
.track-card table tr.track-row.is-selected { background: #d9ebff; outline: 2px solid #0b6bcb; outline-offset: -2px; }

/* BMS overview: compact vertical battery + denser meta */
.bms-overview {
  display: flex;
  gap: .75rem;
  align-items: stretch;
  background: #fafafa;
  padding: .65rem .75rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  margin-top: .35rem;
}
.battery-icon-box {
  flex: 0 0 auto;
  width: 64px;
  height: 96px;
  border: 3px solid #d4ebf7;
  border-radius: 12px;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fff;
  overflow: hidden;
  box-shadow: inset 0 0 6px rgba(0,0,0,0.03);
  align-self: center;
}
.battery-icon-box::before {
  content: '';
  width: 22px;
  height: 5px;
  background: #d4ebf7;
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  border-radius: 0 0 3px 3px;
  z-index: 10;
}
.battery-icon-box.is-empty {
  border-color: #e3e8ee;
  opacity: .85;
}
.battery-icon-box.is-empty::before {
  background: #e3e8ee;
}
.battery-fill {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  transition: height 0.5s ease-in-out, background 0.3s ease;
  z-index: 1;
}
.battery-level-text {
  font-size: 1.05rem;
  font-weight: 800;
  z-index: 5;
  text-shadow: 0px 1px 2px rgba(255,255,255,0.6);
  line-height: 1;
}
.bms-overview .meta-grid {
  flex: 1;
  min-width: 0;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: .25rem .6rem;
}
/* Inline-ish meta rows: label + value tighter */
.bms-overview .meta-item {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: .15rem .4rem;
  padding: .15rem 0;
  border-bottom: 1px dashed #e8eef4;
}
.bms-overview .meta-item:last-child { border-bottom: 0; }
.bms-overview .meta-item .l {
  text-transform: none;
  letter-spacing: 0;
  font-size: .72rem;
  min-width: 3.2rem;
}
.bms-overview .meta-item .v {
  font-size: .82rem;
  font-weight: 600;
  word-break: break-word;
}
@media (max-width: 640px) {
  .bms-overview {
    flex-direction: row;
    align-items: stretch;
    gap: .55rem;
    padding: .5rem .55rem;
  }
  .battery-icon-box {
    width: 52px;
    height: 78px;
    border-width: 2px;
    border-radius: 10px;
  }
  .battery-level-text { font-size: .9rem; }
  .bms-overview .meta-grid {
    grid-template-columns: repeat(auto-fit, minmax(96px, 1fr));
  }
}

/* Temperature sensors (T1..Tn) — horizontal bars under BMS overview */
.temp-sensors {
  margin-top: .55rem;
  padding: .45rem .55rem .35rem;
  background: #fafafa;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.temp-sensors-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: .5rem;
  margin-bottom: .3rem;
}
.temp-sensors-title {
  padding-left: .6rem;
  border-left: 4px solid #3b82f6;
  font-size: .86rem;
  font-weight: 800;
  color: #1c385c;
  text-transform: uppercase;
  letter-spacing: .02em;
}
.temp-sensors-count {
  font-size: .72rem;
  white-space: nowrap;
}
.temp-bar {
  display: flex;
  align-items: center;
  gap: .4rem;
  margin: .22rem 0;
}
.temp-bar-label {
  flex: 0 0 4.7rem;
  font-size: .75rem;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: .02em;
}
.temp-bar-track {
  flex: 1 1 auto;
  min-width: 0;
  height: 13px;
  border-radius: 999px;
  background: #e5e7eb;
  overflow: hidden;
  box-shadow: inset 0 0 3px rgba(0,0,0,0.04);
}
.temp-bar-fill {
  height: 100%;
  border-radius: 999px;
  width: 0;
  transition: width .45s ease, background .3s ease;
  min-width: 0;
}
.temp-bar-fill.is-ok { background: #3b82f6; }
.temp-bar-fill.is-warn { background: #f97316; }
.temp-bar-fill.is-hot { background: #ef4444; }
.temp-bar-val.is-ok { color: #3b82f6; }
.temp-bar-val.is-warn { color: #f97316; }
.temp-bar-val.is-hot { color: #ef4444; }
.temp-bar-fill.is-empty {
  background: #e5e7eb;
}
.temp-bar-val {
  flex: 0 0 3.8rem;
  text-align: right;
  font-size: .78rem;
  font-weight: 600;
  color: #233954;
  font-variant-numeric: tabular-nums;
}
.temp-bar-val.is-empty,
.temp-bar.is-empty .temp-bar-val { color: #94a3b8; }
@media (max-width: 640px) {
  .temp-sensors { padding: .4rem .45rem .3rem; }
  .temp-bar-label { flex: 0 0 auto; min-width: 3.5rem; max-width: 38%; }
  .temp-bar-track {
    flex: 1 1 40%;
    min-width: 4rem;
    height: 14px;
    background: #e5e7eb;
  }
  .temp-bar-fill { min-height: 14px; }
  .temp-bar-val { flex-basis: 3.2rem; font-size: .74rem; }
}

/* ST status badges (charge / discharge / health) */
.st-card h2 { margin-top: 0; }
.st-badges {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  margin-top: .35rem;
  align-items: stretch;
}
.st-badge {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: .25rem;
  box-sizing: border-box;
  padding: .4rem .35rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #f8fafc;
  color: var(--muted);
}
.st-badge--fet {
  width: 5.5rem;
  height: 5.5rem;
  aspect-ratio: 1 / 1;
  flex: 0 0 5.5rem;
  max-width: 5.5rem;
}
.st-badge .st-ico,
svg.st-ico {
  width: 1.35rem !important;
  height: 1.35rem !important;
  max-width: 1.35rem;
  max-height: 1.35rem;
  display: block;
  flex-shrink: 0;
  overflow: hidden;
  flex: 0 0 auto;
  margin-top: 0;
}
.st-badge-body {
  min-width: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .05rem;
}
.st-badge-label {
  font-size: .68rem;
  color: inherit;
  opacity: .85;
  letter-spacing: .02em;
  line-height: 1.15;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.st-badge-state {
  font-weight: 700;
  font-size: .9rem;
  line-height: 1.15;
  color: inherit;
}
.st-badge-sub {
  font-size: .62rem;
  margin-top: .05rem;
  line-height: 1.2;
  color: inherit;
  opacity: .9;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.st-badge--health {
  flex: 1 1 12rem;
  min-width: 12rem;
  max-width: none;
  width: auto;
  height: auto;
  min-height: 5.5rem;
  aspect-ratio: auto;
  flex-direction: row;
  align-items: center;
  justify-content: flex-start;
  text-align: left;
  gap: .65rem;
  padding: .6rem .75rem;
}
.st-badge--health .st-badge-body {
  align-items: flex-start;
}
.st-badge--health .st-badge-label {
  font-size: .8rem;
  overflow: visible;
  text-overflow: unset;
  white-space: normal;
}
.st-badge--health .st-badge-state {
  font-size: 1rem;
}
.st-badge--health .st-badge-sub {
  font-size: .82rem;
  overflow: visible;
  text-overflow: unset;
  white-space: normal;
  word-break: break-word;
}
.st-badge.is-on,
.st-badge.is-ok {
  background: #ecfdf5;
  border-color: #6ee7b7;
  color: #047857;
}
.st-badge.is-off {
  /* FET OFF — red / closed */
  background: #fef2f2;
  border-color: #fca5a5;
  color: #b91c1c;
}
.st-badge.is-bad {
  /* Health abnormal — amber warning (not FET-OFF red) */
  background: #fffbeb;
  border-color: #fcd34d;
  color: #b45309;
}
.st-ts {
  margin: .55rem 0 0;
  font-size: .78rem;
}
@media (max-width: 640px) {
  .st-badges { flex-direction: row; flex-wrap: wrap; }
  .st-badge--fet {
    width: 4.75rem;
    height: 4.75rem;
    flex-basis: 4.75rem;
    max-width: 4.75rem;
  }
  .st-badge--health {
    min-width: 100%;
    flex: 1 1 100%;
  }
}

/* Chart header actions (PNG / CSV export) */
.chart-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
  flex-wrap: wrap;
}
.chart-header-title { flex: 1 1 auto; min-width: 0; }
.chart-actions {
  display: flex;
  gap: .35rem;
  flex: 0 0 auto;
}
.chart-actions .btn-export {
  margin-top: 0;
  padding: .2rem .55rem;
  font-size: .75rem;
  font-weight: 600;
  background: #f1f5f9;
  color: #334155;
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  line-height: 1.3;
}
.chart-actions .btn-export:hover {
  background: #e0f2fe;
  color: #075985;
  border-color: #bae6fd;
}


/* Multi-tenant branding */
.topbar .brand a { display: inline-flex; align-items: center; gap: .5rem; text-decoration: none; }
.topbar .brand-logo { height: 28px; max-width: 160px; object-fit: contain; display: block; }
.topbar .brand-text { font-weight: 700; letter-spacing: .02em; color: #e2e8f0; }
.login-page { min-height: 100vh; }
.login-main { padding: 1rem; }
.login-brand { text-align: center; margin-bottom: .75rem; }
.login-brand .brand { display: inline-block; }
.login-brand .brand-logo { height: 48px; max-width: 220px; object-fit: contain; }
.login-brand .brand-text { font-size: 1.4rem; font-weight: 700; color: var(--text); }
.login-title { text-align: center; margin: .25rem 0 .35rem; font-size: 1.35rem; }
.login-sub { text-align: center; margin: 0 0 1rem; }
.login-wrap .lang-switch {
  margin: 1.1rem 0 0;
  padding-top: .85rem;
  border-top: 1px solid var(--border);
  text-align: center;
  color: var(--muted);
  font-size: .9rem;
}
.login-wrap .lang-switch a { color: var(--accent); }
.login-wrap .lang-switch strong { color: var(--text); }
.color-pair { display: flex; gap: .5rem; align-items: center; max-width: 420px; }
.color-pair input[type=color] { width: 42px; height: 36px; padding: 0; border: 1px solid var(--border); border-radius: 8px; background: #fff; }
.color-pair input[type=text] { flex: 1; max-width: none; }
.brand-preview img { max-height: 48px; max-width: 180px; object-fit: contain; margin: .35rem 0; border: 1px solid var(--border); border-radius: 6px; padding: .25rem; background: #fff; }
.brand-colors > div { flex: 1 1 160px; }

/* Brand form: stacked full-width fields (no crowded 2-col with hints) */
.brand-form .brand-field {
  margin: 0 0 .85rem;
}
.brand-form .brand-field > label {
  margin-top: 0;
}
.brand-form .brand-field input[type=text],
.brand-form .brand-field select,
.brand-form .brand-field textarea {
  max-width: 100%;
  width: 100%;
}
.brand-form .field-hint {
  margin: .25rem 0 0;
  font-size: .85rem;
  line-height: 1.4;
  max-width: 40rem;
}
.brand-form .brand-slug-adv {
  margin-top: .55rem;
  font-size: .9rem;
}
.brand-form .brand-slug-adv > summary {
  cursor: pointer;
  color: var(--muted);
  font-weight: 600;
  user-select: none;
}
.brand-form .brand-slug-adv[hidden] {
  display: none !important;
}
.brand-form .brand-slug-adv input[type=text] {
  margin-top: .35rem;
}

/* Brand editor live login preview */
.brand-editor {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 340px);
  gap: 1.25rem;
  align-items: start;
}
@media (max-width: 960px) {
  .brand-editor { grid-template-columns: 1fr; }
}
.brand-live-preview {
  position: sticky;
  top: 1rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  padding: .75rem;
  box-shadow: 0 1px 2px rgba(16,24,40,.04);
}
.brand-live-preview-head { font-weight: 700; margin-bottom: .25rem; }
.brand-live-preview-hint { font-size: .8rem; margin: 0 0 .6rem; }
.brand-live-stage {
  border: 1px solid #d0d7de;
  border-radius: 8px;
  overflow: hidden;
  min-height: 280px;
  display: flex;
  flex-direction: column;
  background: #e2e8f0;
}
.brand-live-topbar {
  height: 36px;
  padding: 0 .6rem;
  display: flex;
  align-items: center;
  background: #0f172a;
  color: #e2e8f0;
}
.brand-live-topbar .pv-logo-img { height: 22px; max-width: 120px; object-fit: contain; display: block; }
.brand-live-topbar .pv-logo-text { font-size: .85rem; font-weight: 700; color: #e2e8f0; }
.brand-live-body {
  flex: 1;
  padding: 1rem .75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f1f5f9;
  min-height: 240px;
}
.brand-live-card {
  width: 100%;
  max-width: 220px;
  background: rgba(255,255,255,.94);
  border-radius: 8px;
  border: 1px solid rgba(15,23,42,.08);
  padding: .75rem;
  box-shadow: 0 4px 16px rgba(15,23,42,.08);
}
.pv-logo-wrap { margin-bottom: .4rem; min-height: 28px; }
.pv-logo-wrap .pv-logo-img { height: 32px; max-width: 160px; object-fit: contain; }
.pv-logo-wrap .pv-logo-text { font-weight: 700; font-size: 1rem; }
.pv-title { font-weight: 700; font-size: .95rem; margin-bottom: .2rem; }
.pv-sub { font-size: .75rem; opacity: .85; margin-bottom: .55rem; }
.pv-field {
  height: 22px;
  border-radius: 4px;
  border: 1px solid #d0d7de;
  background: #fff;
  margin-bottom: .4rem;
}
.pv-btn {
  margin-top: .35rem;
  height: 28px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .8rem;
  font-weight: 600;
  background: #0b6bcb;
  color: #fff;
}

/* Responsive topbar: desktop chrome outside <details>; mobile hamburger dropdown */
.topbar {
  position: relative;
  flex-wrap: nowrap;
}
.topbar-brand-slot {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}
.topbar-desktop {
  display: flex;
  flex: 1;
  align-items: center;
  gap: 1rem;
  min-width: 0;
}
.topbar-desktop .nav { flex: 1; }
.topbar-desktop .lang-switch { margin-left: auto; }
.topbar-desktop .userbox { margin-left: .5rem; white-space: nowrap; }
.topbar-menu {
  display: none;
  flex: 1;
  align-items: center;
  min-width: 0;
}
.topbar-menu-btn {
  display: none;
  list-style: none;
  cursor: pointer;
  padding: .35rem .55rem;
  margin: 0;
  border: 1px solid rgba(148, 163, 184, .45);
  border-radius: 8px;
  background: rgba(15, 23, 42, .35);
  color: #e2e8f0;
  font-size: 1.15rem;
  line-height: 1;
  user-select: none;
}
.topbar-menu-btn::-webkit-details-marker { display: none; }
.topbar-menu-btn::marker { content: ""; }
.topbar-menu-btn:hover,
.topbar-menu-btn:focus-visible {
  border-color: #38bdf8;
  outline: none;
}
.topbar-menu-panel {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex: 1;
  min-width: 0;
  width: 100%;
}

@media (min-width: 769px) {
  .topbar-desktop {
    display: flex;
    flex: 1;
    align-items: center;
    gap: 1rem;
    min-width: 0;
  }
  .topbar-desktop .nav { flex: 1; }
  .topbar-desktop .lang-switch { margin-left: auto; }
  .topbar-menu { display: none !important; }
}

@media (max-width: 768px) {
  .topbar {
    justify-content: space-between;
    gap: .5rem;
    padding: .65rem 1rem;
    flex-wrap: wrap;
  }
  .topbar-desktop { display: none !important; }
  .topbar-menu {
    flex: 0 0 auto;
    order: 1;
    display: block;
    position: static;
  }
  .topbar-brand-slot {
    order: 2;
    margin-left: auto;
  }
  .topbar-menu-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
  .topbar-menu-panel {
    display: none;
    position: absolute;
    left: 0;
    right: 0;
    top: 100%;
    z-index: 40;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    padding: .5rem 1rem .85rem;
    background: #0f172a;
    border-bottom: 1px solid rgba(148, 163, 184, .25);
    box-shadow: 0 8px 16px rgba(15, 23, 42, .35);
  }
  .topbar-menu[open] > .topbar-menu-panel {
    display: flex;
  }
  .topbar-menu-panel .nav {
    display: flex;
    flex-direction: column;
    gap: 0;
    flex: none;
    width: 100%;
  }
  .topbar-menu-panel .nav a {
    display: block;
    padding: .65rem 0;
    border-bottom: 1px solid rgba(148, 163, 184, .2);
  }
  .topbar-menu-panel .nav a:hover {
    border-bottom-color: #38bdf8;
  }
  .topbar-menu-panel .userbox {
    margin: .65rem 0 0;
    padding: .5rem 0;
    white-space: normal;
    line-height: 1.4;
  }
  .topbar-menu-panel .lang-switch {
    margin: .35rem 0 0;
    white-space: normal;
  }
}

/* Devices admin: filter bar + sortable headers + batch select */
.device-filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem .75rem;
  align-items: center;
  margin: .5rem 0 1rem;
  padding: .65rem .75rem;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.device-filter-bar .device-filter-label {
  font-weight: 600;
  font-size: .85rem;
  color: var(--muted);
  margin-right: .25rem;
}
.device-filter-bar input[type=search],
.device-filter-bar select {
  width: auto;
  max-width: none;
  min-width: 140px;
  margin: 0;
}
.device-filter-bar input[type=search] {
  flex: 1 1 180px;
  min-width: 160px;
}
.device-filter-bar .btn {
  margin-top: 0;
}
.device-tree-table th.sortable {
  padding: 0;
  vertical-align: middle;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  pointer-events: auto;
  position: relative;
  z-index: 1;
}
.device-tree-table th.sortable .th-sort {
  display: flex;
  align-items: center;
  gap: .15rem;
  width: 100%;
  min-height: 2.4rem;
  margin: 0 !important;
  padding: .55rem .4rem;
  background: transparent !important;
  color: var(--muted) !important;
  border: none !important;
  border-radius: 0;
  font: inherit;
  font-weight: 600;
  font-size: .8rem;
  text-transform: uppercase;
  letter-spacing: .03em;
  text-align: left;
  cursor: pointer;
  pointer-events: auto;
  box-sizing: border-box;
}
.device-tree-table th.sortable .th-sort:hover,
.device-tree-table th.sortable:hover .th-sort {
  color: var(--accent) !important;
  background: #f1f5f9 !important;
}
.device-tree-table th.sortable.is-sorted .th-sort {
  color: var(--accent) !important;
}
.device-tree-table th.sortable .sort-ind {
  font-size: .7rem;
  opacity: .85;
  pointer-events: none;
}
.device-tree-table .col-select {
  width: 2.2rem;
  text-align: center;
}
.device-tree-table .device-select {
  width: auto;
  max-width: none;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
}
#batch-move-card .form-actions .btn {
  margin-top: 0;
}

/* Custom compare modal (device charts) */
.astiq-modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(15, 23, 42, .45);
}
.astiq-modal-backdrop.is-open { display: flex; }
.astiq-modal {
  width: min(920px, 100%);
  max-height: min(92vh, 900px);
  overflow: auto;
  background: var(--card, #fff);
  border: 1px solid var(--border, #e2e8f0);
  border-radius: 12px;
  box-shadow: 0 20px 50px rgba(15, 23, 42, .25);
  padding: 1rem 1.1rem 1.15rem;
}
.astiq-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  margin-bottom: .75rem;
}
.astiq-modal-header h2 {
  margin: 0;
  font-size: 1.1rem;
}
.astiq-modal-close {
  margin-top: 0;
  padding: .25rem .55rem;
  background: #f1f5f9;
  color: #334155;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: .85rem;
  cursor: pointer;
}
.astiq-modal-close:hover { background: #e2e8f0; }
.astiq-compare-metrics {
  display: flex;
  flex-wrap: wrap;
  gap: .45rem .85rem;
  margin: .35rem 0 .85rem;
}
.astiq-compare-metrics label {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  font-size: .9rem;
  cursor: pointer;
  user-select: none;
}
.astiq-compare-metrics input { width: auto; margin: 0; accent-color: var(--accent); }
.astiq-compare-group-title {
  flex-basis: 100%;
  width: 100%;
  font-size: .78rem;
  font-weight: 600;
  color: var(--muted);
  margin: .45rem 0 .15rem;
  letter-spacing: .02em;
}
.astiq-compare-group {
  display: flex;
  flex-wrap: wrap;
  gap: .45rem .85rem;
  flex-basis: 100%;
  width: 100%;
}
.astiq-modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  align-items: center;
  margin-bottom: .75rem;
}
.astiq-modal-actions .btn { margin-top: 0; }
.astiq-modal-actions .btn:disabled,
.astiq-modal-actions .btn[disabled] {
  opacity: .45;
  cursor: not-allowed;
}
.astiq-compare-chart {
  width: 100%;
  height: 380px;
  min-height: 280px;
  background: #fafbfc;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.astiq-compare-hint { font-size: .85rem; color: var(--muted); margin: 0 0 .5rem; }
.chart-toolbar-row {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  align-items: center;
  margin: .25rem 0 .85rem;
}
.chart-toolbar-row .btn { margin-top: 0; }

/* Group detail: highlight BMS row used for charts */
.portal-tree tr.is-chart-source { background: #eff6ff; }
.portal-tree tr.is-chart-source td { border-color: #bfdbfe; }
