:root {
  color-scheme: dark;
  --bg: #0b1220;
  --card: #111827;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #22c55e;
  --accent-bg: #14532d;
  --danger: #f87171;
  --border: #1f2937;
  font-family: "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  place-items: center;
  background:
    radial-gradient(1200px 600px at 10% -10%, #16324f 0%, transparent 55%),
    radial-gradient(900px 500px at 100% 0%, #1a3a2a 0%, transparent 50%),
    var(--bg);
  color: var(--text);
  padding: 24px;
}

.card {
  width: min(480px, 100%);
  padding: 28px;
  border-radius: 18px;
  background: rgba(17, 24, 39, 0.92);
  border: 1px solid var(--border);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
}

.badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--accent-bg);
  color: #bbf7d0;
  font-size: 0.82rem;
  margin-bottom: 12px;
}

h1 {
  margin: 0 0 8px;
  font-size: 1.55rem;
  letter-spacing: -0.02em;
}

.lead {
  margin: 0 0 20px;
  color: var(--muted);
  line-height: 1.5;
  font-size: 0.95rem;
}

.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 16px;
}

.tab {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  padding: 10px;
  border-radius: 10px;
  cursor: pointer;
  font: inherit;
}

.tab.active {
  background: #0f172a;
  color: var(--text);
  border-color: #334155;
}

.form {
  display: grid;
  gap: 12px;
}

label {
  display: grid;
  gap: 6px;
  font-size: 0.9rem;
  color: var(--muted);
}

input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #0b1220;
  color: var(--text);
  font: inherit;
}

input:focus {
  outline: 2px solid #166534;
  border-color: #166534;
}

.btn {
  margin-top: 4px;
  padding: 12px 16px;
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  color: #052e16;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn.is-busy {
  cursor: wait;
  opacity: 0.75;
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  font-weight: 500;
}

.actions {
  display: grid;
  gap: 10px;
}

.hint {
  margin: 4px 0 0;
  color: #64748b;
  font-size: 0.85rem;
  line-height: 1.4;
}

.msg, .banner {
  padding: 12px 14px;
  border-radius: 10px;
  margin-bottom: 14px;
  font-size: 0.92rem;
  line-height: 1.4;
}

.msg.ok, .banner.ok {
  background: rgba(34, 197, 94, 0.12);
  color: #bbf7d0;
  border: 1px solid rgba(34, 197, 94, 0.25);
}

.msg.err, .banner.err {
  background: rgba(248, 113, 113, 0.12);
  color: #fecaca;
  border: 1px solid rgba(248, 113, 113, 0.25);
}

.okline {
  margin: 0 0 16px;
  color: var(--muted);
}

.okline strong {
  color: var(--text);
}

.role {
  display: inline-block;
  margin-left: 8px;
  padding: 2px 8px;
  border-radius: 999px;
  background: #1e3a8a;
  color: #bfdbfe;
  font-size: 0.78rem;
}

a.btn {
  display: inline-block;
  text-align: center;
  text-decoration: none;
}

.card-wide { width: min(960px, 100%); }

.card-diagnose { width: min(1100px, 100%); }

.akb-slots {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0 0 14px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(15, 23, 42, 0.65);
}

.akb-slot {
  border: 1px solid var(--border);
  background: #0b1220;
  color: var(--muted);
  padding: 5px 8px;
  border-radius: 8px;
  cursor: pointer;
  font: inherit;
  font-size: 0.78rem;
  min-width: 52px;
}

.akb-slot.active {
  color: #ecfdf5;
  border-color: #22c55e;
  background: #14532d;
}

.akb-slot.is-live {
  box-shadow: inset 0 0 0 1px rgba(34, 197, 94, 0.45);
}

.akb-slot.is-busy {
  color: #fde68a;
  border-color: #ca8a04;
}

.akb-slot .akb-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  margin-right: 5px;
  background: #64748b;
}

.akb-slot.is-live .akb-dot { background: #22c55e; }
.akb-slot.is-err .akb-dot { background: #f87171; }

.diag-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 14px 0 0;
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
}

.diag-tab {
  border: 1px solid var(--border);
  background: #0b1220;
  color: var(--muted);
  padding: 8px 12px;
  border-radius: 8px 8px 0 0;
  cursor: pointer;
  font: inherit;
  font-size: 0.88rem;
}

.diag-tab.active {
  color: var(--text);
  border-color: #334155;
  background: #111827;
  border-bottom-color: #111827;
}

.diag-tab.diag-tab-alert {
  color: #ff6b6b;
  background: rgba(216, 0, 0, 0.14);
  border-color: #D80000;
  font-weight: 700;
}

.diag-tab.diag-tab-alert.active {
  color: #ff8a8a;
  background: rgba(216, 0, 0, 0.22);
}

.diag-tab-panels {
  margin-top: 0;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 0 12px 12px 12px;
  background: rgba(15, 23, 42, 0.55);
  min-height: 280px;
}

.diag-tab-panel { display: none; }
.diag-tab-panel.active { display: block; }

.cells-chart {
  width: 100%;
  max-width: 100%;
  height: auto;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background: #f8fafc;
  display: block;
}

.chart-wrap {
  background: #f8fafc;
  border-radius: 10px;
  padding: 4px;
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  margin-top: 10px;
  color: #e2e8f0;
  font-size: 0.88rem;
}

.chart-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 110px;
}

.chart-swatch {
  width: 12px;
  height: 12px;
  border-radius: 2px;
  display: inline-block;
}

.table-wrap {
  overflow-x: auto;
  margin-top: 12px;
}

.ir-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.ir-table th,
.ir-table td {
  border: 1px solid var(--border);
  padding: 6px 8px;
  text-align: left;
}

.ir-table th {
  background: #0b1220;
  color: var(--muted);
  font-weight: 600;
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 10px;
}

.field-row {
  display: grid;
  gap: 4px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #0b1220;
}

.field-row span { color: var(--muted); font-size: 0.82rem; }
.field-row strong { font-size: 0.98rem; word-break: break-word; }

.live-log-tall { max-height: 420px; min-height: 280px; }

.toprow {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 8px;
}

.panel { margin-top: 8px; }

.owner-panel {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.owner-panel h2 {
  margin: 0 0 12px;
  font-size: 1.05rem;
}

.users-list {
  margin: 12px 0 0;
  padding: 0;
  list-style: none;
  color: var(--muted);
  font-size: 0.88rem;
}

.users-list li {
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 16px 0;
}

.stat {
  background: #0b1220;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
}

.stat-label {
  color: #64748b;
  font-size: 0.78rem;
  margin-bottom: 6px;
}

.stat-value {
  font-size: 0.95rem;
  word-break: break-all;
}

.bms-indicators {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 0 0 12px;
}

.status-pill {
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 0.88rem;
  font-weight: 600;
  border: 1px solid transparent;
}

.status-pill.status-bad {
  background: rgba(248, 113, 113, 0.15);
  color: #fecaca;
  border-color: rgba(248, 113, 113, 0.35);
}

.status-pill.status-good {
  background: rgba(34, 197, 94, 0.15);
  color: #bbf7d0;
  border-color: rgba(34, 197, 94, 0.35);
}

.status-pill.status-wait {
  background: rgba(250, 204, 21, 0.12);
  color: #fde68a;
  border-color: rgba(250, 204, 21, 0.35);
}

.dash-placeholder {
  margin: 16px 0;
  padding: 16px;
  border-radius: 12px;
  border: 1px dashed #334155;
  background: rgba(15, 23, 42, 0.6);
}

.dash-placeholder h2 {
  margin: 0 0 8px;
  font-size: 1.1rem;
}

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin: 12px 0;
}

.inline-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: #94a3b8;
  font-size: 0.9rem;
}

.inline-label select {
  background: #0b1220;
  color: #e2e8f0;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
}

.meters {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 12px 0;
}

.meters-6 {
  grid-template-columns: repeat(3, 1fr);
}

@media (min-width: 900px) {
  .meters-6 { grid-template-columns: repeat(6, 1fr); }
}

.verdict {
  margin: 12px 0;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
}

.verdict-label {
  color: #64748b;
  font-size: 0.78rem;
  margin-bottom: 4px;
}

.verdict-text {
  font-size: 1rem;
}

.verdict-ok {
  background: rgba(34, 197, 94, 0.12);
  border-color: #166534;
}

.verdict-warn {
  background: rgba(234, 179, 8, 0.12);
  border-color: #854d0e;
}

.verdict-fail,
.verdict-error {
  background: rgba(239, 68, 68, 0.12);
  border-color: #991b1b;
}

.cells-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(88px, 1fr));
  gap: 8px;
  margin: 10px 0 12px;
}

.cell-pill {
  background: #0b1220;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.cell-pill.cell-min {
  border-color: #38bdf8;
  box-shadow: inset 0 0 0 1px rgba(56, 189, 248, 0.35);
}

.cell-pill.cell-max {
  border-color: #f59e0b;
  box-shadow: inset 0 0 0 1px rgba(245, 158, 11, 0.35);
}

.cells-controls {
  margin-bottom: 8px;
  align-items: center;
}

.cell-delta-alert {
  color: #D80000;
  font-weight: 700;
  font-size: 0.9rem;
}

.bms-com-modal {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(2, 6, 23, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.bms-com-modal-card {
  width: min(520px, 100%);
  max-height: min(80vh, 640px);
  overflow: auto;
  background: #0f172a;
  border: 1px solid #334155;
  border-radius: 14px;
  padding: 16px 18px 14px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
}

.bms-com-modal-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: #f8fafc;
  margin-bottom: 6px;
}

.bms-com-modal-hint,
.bms-com-modal-empty {
  color: #94a3b8;
  font-size: 0.88rem;
  margin: 0 0 12px;
  line-height: 1.4;
}

.bms-com-pick-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 14px;
}

.bms-com-pick-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid #334155;
  background: #111827;
  color: #e2e8f0;
  cursor: pointer;
  font: inherit;
}

.bms-com-pick-btn:hover {
  border-color: #38bdf8;
  background: #0b1220;
}

.bms-com-pick-btn strong {
  font-size: 1rem;
  color: #7dd3fc;
}

.bms-com-pick-btn span {
  font-size: 0.82rem;
  color: #94a3b8;
}

.bms-com-modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.cell-pill span {
  color: #64748b;
  font-size: 0.72rem;
}

.cell-pill strong {
  font-size: 0.82rem;
}

.btn-accent {
  background: linear-gradient(135deg, #059669, #10b981);
  border-color: #059669;
}

.meter {
  background: #0b1220;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.meter span {
  color: #64748b;
  font-size: 0.75rem;
}

.meter strong {
  font-size: 1rem;
}

.live-log {
  margin: 0;
  max-height: 240px;
  overflow: auto;
  padding: 12px;
  border-radius: 10px;
  background: #020617;
  border: 1px solid #1e293b;
  color: #86efac;
  font-size: 0.78rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}

@media (max-width: 640px) {
  .status-grid,
  .meters { grid-template-columns: 1fr; }
  .toprow { flex-direction: column; }
}

[hidden] { display: none !important; }

.card-wide {
  max-width: 960px;
}

.quota-hint {
  color: #93c5fd;
  font-weight: 500;
}

.owner-panel {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

.owner-panel h2 {
  margin: 0 0 8px;
}

.owner-panel h3 {
  margin: 20px 0 8px;
  font-size: 1rem;
}

.form-inline {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: flex-end;
  margin-bottom: 12px;
}

.form-inline label {
  flex: 1 1 140px;
}

.chk {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.88rem;
  color: #94a3b8;
  flex: 0 0 auto !important;
}

.table-wrap {
  overflow-x: auto;
  margin: 12px 0;
}

.owner-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.owner-table th,
.owner-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

.owner-table th {
  color: #64748b;
  font-weight: 600;
}

.btn-small {
  padding: 4px 10px;
  font-size: 0.82rem;
}

.archive-actions {
  white-space: nowrap;
}

.archive-actions .btn {
  margin: 2px 2px 2px 0;
}

.dot-on {
  color: #4ade80;
}

.dot-off {
  color: #64748b;
}

.muted {
  color: #64748b;
}

.btn-disabled {
  opacity: 0.45;
  pointer-events: none;
}

.topnav {
  display: flex;
  gap: 8px;
  max-width: 960px;
  margin: 16px auto 0;
  padding: 0 12px;
}

.topnav a {
  padding: 8px 14px;
  border-radius: 10px;
  text-decoration: none;
  color: #94a3b8;
  border: 1px solid transparent;
  font-size: 0.9rem;
}

.topnav a:hover {
  color: #e2e8f0;
  background: rgba(15, 23, 42, 0.8);
}

.topnav a.active {
  color: #e2e8f0;
  border-color: #334155;
  background: rgba(15, 23, 42, 0.9);
}

.view-panel {
  margin-top: 12px;
}

.owner-table tr.client-row {
  cursor: pointer;
}
.owner-table tr.client-row:hover td {
  background: rgba(34, 197, 94, 0.08);
}
.client-email-link {
  color: #86efac;
  text-decoration: underline;
  text-underline-offset: 2px;
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}
.client-detail-head {
  margin-bottom: 8px;
}
.client-detail-head .h2-small {
  margin: 0 0 4px;
}

.tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 0.75rem;
  background: #1e293b;
  color: #cbd5e1;
}

.tag-ok { background: rgba(34, 197, 94, 0.2); color: #4ade80; }
.tag-err { background: rgba(239, 68, 68, 0.2); color: #f87171; }
.tag-muted { background: #0f172a; color: #64748b; }

@keyframes mail-beacon-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.45); }
  50% { box-shadow: 0 0 0 6px rgba(239, 68, 68, 0); }
}
.mail-beacon-pulse { animation: mail-beacon-pulse 1.5s ease-in-out infinite; }

