:root,
html[data-theme="light"] {
  --brand: #0f7a45;
  --brand-hover: #0c6438;
  --brand-soft: #e6f5ed;
  --brand-ink: #0a4d2c;

  --bg: #eef1f4;
  --bg-deep: #e4e9ee;
  --surface: #ffffff;
  --surface-2: #f7f9fb;
  --line: #d5dde5;
  --line-strong: #b8c4d0;

  --text: #15202b;
  --text-2: #3d4f60;
  --muted: #6b7c8c;

  --ok: #0f7a45;
  --warn: #b45309;
  --danger: #b42318;
  --info: #1d4f91;

  --sidebar-bg: rgba(255, 255, 255, 0.82);
  --input-bg: #ffffff;
  --chip-bg: #eef2f6;

  --sidebar-w: 15.5rem;
  --radius: 10px;
  --shadow: 0 1px 0 rgba(21, 32, 43, 0.04), 0 8px 24px rgba(21, 32, 43, 0.05);
  --font: "Sora", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  color-scheme: light;
}

html[data-theme="dark"] {
  --brand: #3dba74;
  --brand-hover: #52c984;
  --brand-soft: #143528;
  --brand-ink: #b6f0cd;

  --bg: #0f1412;
  --bg-deep: #0a0e0c;
  --surface: #171e1b;
  --surface-2: #1e2723;
  --line: #2a3530;
  --line-strong: #3a4841;

  --text: #e8f0eb;
  --text-2: #b4c4ba;
  --muted: #84948b;

  --ok: #3dba74;
  --warn: #e0a04a;
  --danger: #e07a6e;
  --info: #6a9fd4;

  --sidebar-bg: rgba(18, 24, 21, 0.92);
  --input-bg: #121814;
  --chip-bg: #243029;

  --shadow: 0 1px 0 rgba(0, 0, 0, 0.35), 0 12px 28px rgba(0, 0, 0, 0.35);
  color-scheme: dark;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(1200px 500px at 0% -10%, rgba(15, 122, 69, 0.08), transparent 55%),
    linear-gradient(180deg, var(--bg) 0%, var(--bg-deep) 100%);
}

body {
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

a {
  color: inherit;
  text-decoration: none;
}

button,
input,
select,
textarea {
  font: inherit;
}

#app {
  min-height: 100vh;
}

.mono {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
}

/* —— Login —— */
.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 2rem 1rem;
}

.login-card {
  width: min(920px, 100%);
  display: grid;
  grid-template-columns: 1.05fr 1fr;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.login-brand {
  padding: 2.5rem 2.25rem;
  background:
    linear-gradient(155deg, #0a4d2c 0%, #0f7a45 48%, #1a9a5a 100%);
  color: #f4fff8;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 2rem;
}

.login-brand .mark {
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.login-brand .mark-dot {
  width: 0.7rem;
  height: 0.7rem;
  border-radius: 999px;
  background: #9ef0c0;
  box-shadow: 0 0 0 4px rgba(158, 240, 192, 0.25);
}

.login-brand h1 {
  margin: 1.25rem 0 0.6rem;
  font-size: clamp(1.8rem, 3vw, 2.35rem);
  line-height: 1.1;
  letter-spacing: -0.03em;
  font-weight: 700;
}

.login-brand p {
  margin: 0;
  max-width: 28ch;
  color: rgba(244, 255, 248, 0.86);
  font-size: 0.95rem;
}

.login-form {
  padding: 2.5rem 2.25rem;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.login-form h2 {
  margin: 0 0 0.35rem;
  font-size: 1.45rem;
  letter-spacing: -0.02em;
}

.login-form .sub {
  margin: 0 0 1.5rem;
  color: var(--muted);
  font-size: 0.92rem;
}

/* —— Shell —— */
.shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 1.25rem 0.9rem;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--line);
  backdrop-filter: blur(10px);
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.35rem 0.55rem;
}

.brand-mark {
  width: 2rem;
  height: 2rem;
  border-radius: 8px;
  background: linear-gradient(145deg, #0f7a45, #1a9a5a);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.2);
}

.brand-copy strong {
  display: block;
  font-size: 0.92rem;
  letter-spacing: -0.02em;
}

.brand-copy span {
  display: block;
  font-size: 0.72rem;
  color: var(--muted);
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  flex: 1;
}

.nav a {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.62rem 0.75rem;
  border-radius: 8px;
  color: var(--text-2);
  font-size: 0.9rem;
  font-weight: 500;
  border: 1px solid transparent;
}

.nav a:hover {
  background: var(--surface-2);
  color: var(--text);
}

.nav a.active {
  background: var(--brand-soft);
  color: var(--brand-ink);
  border-color: rgba(15, 122, 69, 0.18);
}

.nav .dot {
  width: 0.45rem;
  height: 0.45rem;
  border-radius: 999px;
  background: currentColor;
  opacity: 0.55;
}

.nav a.active .dot {
  opacity: 1;
  background: var(--brand);
}

.sidebar-foot {
  padding: 0.75rem;
  border-top: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.theme-toggle {
  align-self: stretch;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 550;
}

.sidebar-foot .who {
  font-size: 0.78rem;
  color: var(--muted);
  word-break: break-all;
}

.stream-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.72rem;
  color: var(--muted);
}

.stream-pill .lamp {
  width: 0.45rem;
  height: 0.45rem;
  border-radius: 999px;
  background: var(--line-strong);
}

.stream-pill.live .lamp {
  background: var(--ok);
  box-shadow: 0 0 0 3px rgba(15, 122, 69, 0.18);
}

.main {
  padding: 1.4rem 1.6rem 2.5rem;
  min-width: 0;
}

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.15rem;
}

.page-head h1 {
  margin: 0;
  font-size: 1.45rem;
  letter-spacing: -0.03em;
}

.page-head p {
  margin: 0.25rem 0 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  align-items: center;
  margin-bottom: 0.9rem;
}

.add-charger-form {
  align-items: flex-end;
  margin-bottom: 0;
}

.field-stack {
  display: grid;
  gap: 0.25rem;
  font-size: 0.75rem;
  text-transform: uppercase;
}

.add-charger-actions {
  display: flex;
  gap: 0.55rem;
  align-items: center;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.panel-pad {
  padding: 1rem 1.1rem;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.kpi {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem 1.05rem;
  box-shadow: var(--shadow);
}

.kpi .label {
  font-size: 0.78rem;
  color: var(--muted);
  margin-bottom: 0.45rem;
}

.kpi .value {
  font-size: 1.7rem;
  font-weight: 650;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}

.kpi .hint {
  margin-top: 0.35rem;
  font-size: 0.75rem;
  color: var(--muted);
}

.table-wrap {
  overflow: auto;
}

table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.86rem;
}

table.data th,
table.data td {
  padding: 0.72rem 0.9rem;
  text-align: left;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

table.data th {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
  background: var(--surface-2);
  position: sticky;
  top: 0;
  white-space: nowrap;
}

table.data tr:last-child td {
  border-bottom: none;
}

table.data tbody tr {
  cursor: default;
}

table.data tbody tr.clickable {
  cursor: pointer;
}

table.data tbody tr.clickable:hover td {
  background: rgba(15, 122, 69, 0.04);
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.18rem 0.5rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  border: 1px solid transparent;
  white-space: nowrap;
}

.badge::before {
  content: "";
  width: 0.38rem;
  height: 0.38rem;
  border-radius: 999px;
  background: currentColor;
}

.badge.online,
.badge.active,
.badge.ok {
  color: var(--brand-ink);
  background: var(--brand-soft);
  border-color: rgba(15, 122, 69, 0.16);
}

.badge.offline,
.badge.inactive,
.badge.ended {
  color: var(--text-2);
  background: #eef2f6;
  border-color: var(--line);
}

.badge.warn {
  color: #7c2d12;
  background: #fff7ed;
  border-color: #fed7aa;
}

.badge.danger,
.badge.blocked {
  color: #7f1d1d;
  background: #fef2f2;
  border-color: #fecaca;
}

.badge.protocol {
  color: var(--info);
  background: #eff6ff;
  border-color: #bfdbfe;
}

.badge.protocol::before {
  display: none;
}

.btn {
  appearance: none;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--text);
  border-radius: 8px;
  padding: 0.55rem 0.9rem;
  font-size: 0.86rem;
  font-weight: 550;
  cursor: pointer;
}

.btn:hover {
  background: var(--surface-2);
}

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

.btn-primary {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}

.btn-primary:hover {
  background: var(--brand-hover);
}

.btn-ghost {
  background: transparent;
}

.btn-danger {
  color: var(--danger);
  border-color: #f1b4b0;
  background: var(--input-bg);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 0.9rem;
}

.field label {
  font-size: 0.8rem;
  font-weight: 550;
  color: var(--text-2);
}

.field input,
.field select,
.field textarea,
.toolbar input,
.toolbar select {
  border: 1px solid var(--line-strong);
  background: var(--input-bg);
  border-radius: 8px;
  padding: 0.58rem 0.7rem;
  color: var(--text);
  min-width: 0;
}

.field input:focus,
.field select:focus,
.field textarea:focus,
.toolbar input:focus,
.toolbar select:focus,
.btn:focus-visible,
.nav a:focus-visible {
  outline: 2px solid rgba(15, 122, 69, 0.35);
  outline-offset: 1px;
}

.alert {
  padding: 0.7rem 0.85rem;
  border-radius: 8px;
  font-size: 0.86rem;
  margin-bottom: 0.9rem;
  border: 1px solid transparent;
}

.alert.error {
  background: #fef2f2;
  border-color: #fecaca;
  color: #7f1d1d;
}

.alert.info {
  background: #eff6ff;
  border-color: #bfdbfe;
  color: #1e3a5f;
}

.alert.warn {
  background: #fffbeb;
  border-color: #fde68a;
  color: #78350f;
}

.empty {
  padding: 2rem 1rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.92rem;
}

.split {
  display: grid;
  grid-template-columns: 1.35fr 0.9fr;
  gap: 0.85rem;
}

.detail-block h3 {
  margin: 0 0 0.7rem;
  font-size: 0.95rem;
  letter-spacing: -0.02em;
}

.kv {
  display: grid;
  grid-template-columns: 7.5rem 1fr;
  gap: 0.35rem 0.75rem;
  font-size: 0.84rem;
}

.kv dt {
  color: var(--muted);
}

.kv dd {
  margin: 0;
}

.perm-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.35rem 0.75rem;
  font-size: 0.82rem;
}

.perm-grid label {
  display: flex;
  gap: 0.45rem;
  align-items: center;
  color: var(--text-2);
}

.drawer-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-top: 1rem;
}

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

/* —— Database browser —— */
.tabs {
  display: flex;
  gap: 0.35rem;
  margin-bottom: 0.95rem;
  border-bottom: 1px solid var(--line);
  padding-bottom: 0.45rem;
}

.tab {
  appearance: none;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  border-radius: 8px;
  padding: 0.45rem 0.85rem;
  font-size: 0.86rem;
  font-weight: 550;
  cursor: pointer;
}

.tab:hover {
  color: var(--text);
  background: rgba(15, 122, 69, 0.06);
}

.tab.active {
  color: var(--brand-ink);
  background: var(--brand-soft);
  border-color: rgba(15, 122, 69, 0.16);
}

.db-split {
  grid-template-columns: 14rem 1fr;
}

.db-side-head {
  padding: 0.7rem 0.9rem;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
}

.db-table-list {
  list-style: none;
  margin: 0;
  padding: 0.35rem;
  max-height: min(70vh, 36rem);
  overflow: auto;
}

.db-table-list li {
  margin: 0;
}

.db-table-item {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
  appearance: none;
  border: none;
  background: transparent;
  text-align: left;
  padding: 0.5rem 0.55rem;
  border-radius: 7px;
  cursor: pointer;
  color: var(--text);
  font-size: 0.84rem;
}

.db-table-item:hover {
  background: rgba(15, 122, 69, 0.06);
}

.db-table-item.active {
  background: var(--brand-soft);
  color: var(--brand-ink);
}

.db-sql {
  width: 100%;
  min-height: 10rem;
  resize: vertical;
  border: 1px solid var(--line-strong);
  background: var(--input-bg);
  color: var(--text);
  border-radius: 8px;
  padding: 0.7rem 0.8rem;
  line-height: 1.4;
  font-family: var(--mono);
}

.db-grid {
  font-size: 0.8rem;
}

.db-grid td,
.db-grid th {
  white-space: nowrap;
  max-width: 18rem;
  overflow: hidden;
  text-overflow: ellipsis;
}

.db-pk {
  display: inline-block;
  margin-left: 0.25rem;
  padding: 0.05rem 0.3rem;
  border-radius: 4px;
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  color: var(--info);
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  vertical-align: middle;
}

.db-row-actions {
  white-space: nowrap;
}

.db-row-actions .btn {
  padding: 0.3rem 0.55rem;
  font-size: 0.76rem;
}

@media (max-width: 980px) {
  .shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: relative;
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--line);
  }

  .nav {
    flex-direction: row;
    flex-wrap: wrap;
  }

  .kpi-grid,
  .split,
  .db-split,
  .login-card {
    grid-template-columns: 1fr;
  }

  .login-brand {
    min-height: 180px;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
    animation: none !important;
  }
}

html[data-theme="dark"] .badge.offline,
html[data-theme="dark"] .badge.inactive,
html[data-theme="dark"] .badge.ended {
  background: var(--chip-bg);
  color: var(--text-2);
}

html[data-theme="dark"] .badge.warn {
  color: #fbbf24;
  background: #3a2a12;
  border-color: #6b4a1a;
}

html[data-theme="dark"] .badge.danger,
html[data-theme="dark"] .badge.blocked {
  color: #fca5a5;
  background: #3a1a1a;
  border-color: #6b2a2a;
}

html[data-theme="dark"] .badge.protocol {
  color: #93c5fd;
  background: #1a2a3a;
  border-color: #2a4a6b;
}

html[data-theme="dark"] .alert.error {
  background: #3a1a1a;
  border-color: #6b2a2a;
  color: #fca5a5;
}

html[data-theme="dark"] .alert.info {
  background: #1a2a3a;
  border-color: #2a4a6b;
  color: #93c5fd;
}

html[data-theme="dark"] .alert.warn {
  background: #3a2a12;
  border-color: #6b4a1a;
  color: #fbbf24;
}

html[data-theme="dark"] .btn-danger {
  border-color: #6b2a2a;
}

html[data-theme="dark"] table.data tbody tr.clickable:hover td {
  background: rgba(61, 186, 116, 0.08);
}

html[data-theme="dark"] .db-table-item:hover {
  background: rgba(61, 186, 116, 0.1);
}

.desk {
  max-width: 34rem;
}

.desk h1 {
  margin: 0.2rem 0 0.4rem;
  font-size: 1.7rem;
  letter-spacing: -0.03em;
}

.desk-lead {
  color: var(--text-2);
  margin: 0 0 1.1rem;
}

.desk-kicker {
  margin: 0;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.desk-uid,
.desk-amount {
  font-size: 1.55rem;
  padding: 0.75rem 0.8rem;
  letter-spacing: 0.02em;
}

.desk-card {
  margin-top: 1rem;
}

.desk-uid-line {
  margin: 0.35rem 0 0;
  font-size: 1.15rem;
}

.desk-balance {
  margin: 0.2rem 0 0.8rem;
  font-size: clamp(2.4rem, 7vw, 3.4rem);
  line-height: 1.05;
  letter-spacing: -0.04em;
}

.desk-balance span {
  font-size: 0.42em;
  letter-spacing: 0;
  color: var(--muted);
}

.desk-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
}

.desk-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.desk-device {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.15rem;
  text-align: left;
  width: 100%;
  padding: 0.75rem 0.85rem;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}

.desk-device:hover {
  border-color: var(--brand);
}

.desk-device .mono {
  font-size: 0.8rem;
  color: var(--muted);
}

.map-layout {
  display: grid;
  grid-template-columns: 1fr minmax(14rem, 18rem);
  gap: 1rem;
  min-height: calc(100vh - 10rem);
}

@media (max-width: 900px) {
  .map-layout {
    grid-template-columns: 1fr;
  }
}

.map-canvas-wrap {
  overflow: hidden;
  min-height: 28rem;
}

.map-canvas {
  width: 100%;
  height: 100%;
  min-height: 28rem;
}

.map-side h3 {
  font-size: 0.85rem;
  margin: 1rem 0 0.4rem;
}

.map-list {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  max-height: 40vh;
  overflow: auto;
}

.map-list-item {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  width: 100%;
  text-align: left;
  padding: 0.55rem 0.6rem;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}

.map-list-item:hover {
  border-color: var(--brand);
}

.map-list-item .lamp {
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 50%;
  margin-top: 0.35rem;
  background: #8a9390;
  flex-shrink: 0;
}

.map-list-item .lamp.on {
  background: var(--brand);
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr));
  gap: 1rem;
}


