:root {
  --bg: #eef2f6;
  --surface: #ffffff;
  --sidebar: #f8fafc;
  --text: #1a2332;
  --muted: #667788;
  --line: #d7e0ea;
  --brand: #0f766e;
  --brand-soft: #ccfbf1;
  --ok: #15803d;
  --ok-bg: #dcfce7;
  --bad: #b91c1c;
  --bad-bg: #fee2e2;
  --warn: #b45309;
  --warn-bg: #fef3c7;
  --sidebar-w: 200px;
  --topbar-h: 52px;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--bg);
  font-size: 14px;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
.hidden { display: none !important; }
code {
  font-family: ui-monospace, Consolas, monospace;
  background: #f1f5f9;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 0.9em;
}

/* login */
.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(900px 400px at 10% -10%, #d1fae5 0%, transparent 55%),
    radial-gradient(700px 360px at 100% 0%, #e0f2fe 0%, transparent 50%),
    var(--bg);
}
.login-card {
  width: min(400px, 100%);
  display: grid;
  gap: 12px;
}
.login-card h1 { margin: 0; font-size: 1.4rem; }
.sub, .hint { margin: 0; color: var(--muted); font-size: 0.92rem; }
/* shell */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar);
  border-right: 1px solid var(--line);
  padding: 16px 12px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.sidebar-brand {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 18px;
  padding: 0 8px;
}
.tag {
  display: inline-block;
  width: fit-content;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--brand);
  background: var(--brand-soft);
  border-radius: 999px;
  padding: 2px 8px;
}
.nav { display: grid; gap: 4px; }
.nav a {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--text);
  text-decoration: none;
  border-left: 3px solid transparent;
}
.nav a:hover { background: #eef6f4; }
.nav a.active {
  background: var(--brand-soft);
  border-left-color: var(--brand);
  font-weight: 600;
  color: var(--brand);
}
.nav-badge {
  background: var(--bad);
  color: #fff;
  border-radius: 999px;
  font-size: 0.72rem;
  min-width: 18px;
  text-align: center;
  padding: 0 6px;
}
.main-col { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar-title { display: flex; align-items: center; gap: 8px; font-weight: 600; flex: 1; }
.env-badge, .role-badge {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--warn-bg);
  color: var(--warn);
}
.role-badge { background: var(--brand-soft); color: var(--brand); }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.content {
  padding: 16px;
  width: min(1280px, 100%);
  margin: 0 auto;
}
.menu-btn { display: none; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: 0 8px 24px rgba(26, 35, 50, 0.05);
}
.card-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
  align-items: flex-start;
}
.card-head h2 { margin: 0 0 4px; font-size: 1.1rem; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; }
.empty-card { text-align: center; padding: 40px 16px; }

.stats { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; margin-bottom: 16px; }
.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  text-align: center;
  cursor: pointer;
  font: inherit;
  color: inherit;
}
.stat span { display: block; font-size: 1.45rem; font-weight: 700; }
.stat label { color: var(--muted); font-size: 0.78rem; }
.stat.online span { color: var(--ok); }
.stat.bad span { color: var(--bad); }
.stat.warn span { color: var(--warn); }

.alert-banner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  background: var(--bad-bg);
  color: var(--bad);
  border: 1px solid #fecaca;
  border-radius: 10px;
  padding: 10px 14px;
  margin-bottom: 16px;
  font-weight: 600;
}
.help-box {
  background: #f8fafc;
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--muted);
  font-size: 0.88rem;
  margin-bottom: 12px;
}

.row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; align-items: center; }
label { display: grid; gap: 4px; color: var(--muted); font-size: 0.85rem; }
.check { display: flex; align-items: center; gap: 6px; color: var(--text); }
input, select, button {
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
  background: #fff;
  color: var(--text);
}
.grow { flex: 1; min-width: 220px; }
.btn-primary {
  background: var(--brand);
  color: #fff;
  border: none;
  cursor: pointer;
  font-weight: 600;
}
.btn-primary:hover { filter: brightness(1.05); }
.btn-ghost {
  background: #fff;
  color: var(--brand);
  border: 1px solid var(--brand);
  cursor: pointer;
  font-weight: 600;
}
.btn-danger {
  background: var(--bad);
  color: #fff;
  border: none;
  cursor: pointer;
  font-weight: 600;
}
.btn-link {
  background: none;
  border: none;
  color: var(--brand);
  cursor: pointer;
  padding: 0 4px;
  font: inherit;
}
.msg { color: var(--bad); min-height: 1.2em; margin: 0; }
.msg.ok { color: var(--ok); }

.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
th, td {
  border-bottom: 1px solid var(--line);
  padding: 10px 8px;
  text-align: left;
  white-space: nowrap;
}
th { color: var(--muted); font-weight: 600; background: #f8fafc; }
tr.dim { opacity: 0.55; }
.empty { text-align: center; color: var(--muted); padding: 28px !important; white-space: normal; }
.ops {
  display: inline-flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}
.pile-code-cell {
  white-space: nowrap;
}
.pile-code-link {
  font-family: ui-monospace, Consolas, monospace;
  font-weight: 600;
  padding: 0;
}
.logs-form {
  display: grid;
  gap: 10px;
  margin-bottom: 12px;
}
.logs-form .form-row {
  display: grid;
  grid-template-columns: 88px minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}
.logs-form .form-row .form-label {
  color: var(--muted);
  font-size: 0.85rem;
}
.logs-form input,
.logs-form select {
  width: 100%;
  max-width: 420px;
}
.logs-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.log-view {
  margin: 0;
  min-height: 320px;
  max-height: min(60vh, 560px);
  overflow: auto;
  background: #0f172a;
  color: #e2e8f0;
  border-radius: 10px;
  padding: 12px 14px;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 0.78rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-all;
}
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
}
.badge.on { background: var(--ok-bg); color: var(--ok); }
.badge.off { background: var(--bad-bg); color: var(--bad); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.kv th { width: 140px; text-align: left; }
.kv td, .kv th { background: transparent; }

/* pile detail page */
.detail-page {
  display: grid;
  gap: 16px;
}
.detail-page-head {
  display: grid;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px;
}
.detail-page-title-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}
.detail-page-title-row h2 {
  margin: 0;
  font-size: 1.15rem;
}
.detail-page-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.detail-page-body {
  display: grid;
  gap: 16px;
}
.detail-cols {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}
@media (max-width: 900px) {
  .detail-cols { grid-template-columns: 1fr; }
}
.detail-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px;
}
.detail-card h3 {
  margin: 0 0 12px;
  font-size: 0.95rem;
  font-weight: 600;
}
.detail-page .detail-kv {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px 16px;
}
.detail-page .detail-kv.single-col {
  grid-template-columns: 1fr;
}
.detail-page .monitor-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}
@media (max-width: 768px) {
  .detail-page .detail-kv,
  .detail-page .monitor-grid {
    grid-template-columns: 1fr 1fr;
  }
}
.sidebar-collapse {
  margin-top: auto;
  width: 100%;
  font-size: 0.8rem;
}
.shell.collapsed .sidebar {
  width: 56px;
  padding: 12px 6px;
}
.shell.collapsed .sidebar-brand strong,
.shell.collapsed .nav a,
.shell.collapsed .sidebar-collapse {
  font-size: 0;
}
.shell.collapsed .nav a {
  justify-content: center;
  padding: 10px 4px;
}
.shell.collapsed .nav a::before {
  content: attr(data-route);
  font-size: 0.65rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
}
.shell.collapsed .nav a.active::before { color: var(--brand); }
.shell.collapsed .tag { display: none; }
.shell.collapsed .sidebar-collapse {
  font-size: 0.65rem;
  padding: 6px 2px;
}
.shell.collapsed .sidebar-collapse::after { content: "»"; font-size: 0.9rem; }
body.role-operator .admin-only,
body.role-tenant .admin-only,
body.role-tenant .master-only { display: none !important; }
.detail-kv { display: grid; gap: 8px; }
.detail-kv div { display: grid; gap: 2px; }
.detail-kv label { color: var(--muted); font-size: 0.8rem; }
.detail-section {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}
.detail-section h3 {
  margin: 0 0 8px;
  font-size: 0.95rem;
  font-weight: 600;
}
.gun-panels {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 12px;
}
.gun-panel {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  background: #fff;
}
.gun-panel.gun-charging {
  border-color: #1a7a4c;
  box-shadow: inset 0 0 0 1px rgba(26, 122, 76, 0.2);
}
.gun-panel.gun-active {
  border-color: #b8860b;
}
.gun-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}
.monitor-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}
.monitor-grid .cell {
  background: #f8fafc;
  border-radius: 8px;
  padding: 8px 10px;
}
.monitor-grid .cell strong {
  display: block;
  font-size: 1.05rem;
  font-variant-numeric: tabular-nums;
}
.monitor-grid .cell span {
  color: var(--muted);
  font-size: 0.75rem;
}
.mono-sm {
  font-family: ui-monospace, Consolas, monospace;
  font-size: 0.8rem;
  word-break: break-all;
}
.rt-cell { font-size: 0.82rem; line-height: 1.35; }
.rt-cell .rt-status { font-weight: 600; }
.rt-cell .rt-meta { color: var(--muted); }
.confirm-box {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--surface);
  border-radius: 12px;
  padding: 20px;
  z-index: 60;
  width: min(400px, calc(100% - 32px));
  box-shadow: 0 16px 40px rgba(0,0,0,0.15);
}

/* modal / dialog — 居中弹窗 */
.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  z-index: 55;
}
.modal {
  position: fixed;
  inset: 0;
  z-index: 56;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  pointer-events: none;
}
.modal:not(.hidden) {
  pointer-events: auto;
}
.modal-panel.modal-panel-sm {
  width: min(480px, calc(100vw - 32px));
}
.modal-panel {
  width: min(720px, calc(100vw - 32px));
  max-height: min(92vh, 800px);
  background: var(--surface);
  border-radius: 12px;
  box-shadow: 0 20px 48px rgba(0, 0, 0, 0.18);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: modal-in 0.18s ease-out;
}
@keyframes modal-in {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
}
.modal-head h2 { margin: 0; font-size: 1.1rem; }
.modal-body {
  padding: 16px 20px;
  display: grid;
  gap: 12px;
  overflow: auto;
  flex: 1;
}
.modal-body.modal-form {
  gap: 10px;
}
.modal-form .form-row {
  display: grid;
  grid-template-columns: 140px minmax(0, 1fr);
  gap: 12px 16px;
  align-items: center;
}
.modal-form .form-label {
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.3;
}
.modal-form .form-control {
  display: grid;
  gap: 4px;
  min-width: 0;
}
.modal-form .form-row > input,
.modal-form .form-row > select,
.modal-form .form-control > input {
  width: 100%;
  min-width: 0;
}
.modal-form .cert-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.modal-form .cert-row input[type="file"] {
  flex: 1 1 180px;
  min-width: 0;
}
.modal-form-full {
  grid-column: 1 / -1;
}
.modal-form #edit-auth-block,
.modal-form #edit-cert-tls-block,
.modal-form #edit-cert-client-block {
  display: grid;
  gap: 10px;
}
.modal-form #edit-auth-block.hidden,
.modal-form #edit-cert-tls-block.hidden,
.modal-form #edit-cert-client-block.hidden {
  display: none;
}
@media (max-width: 560px) {
  .modal-form .form-row {
    grid-template-columns: 1fr;
    gap: 4px;
  }
}
.modal-foot {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px 20px;
  border-top: 1px solid var(--line);
  background: #fafbfc;
}
.platform-form-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 12px;
}
.platform-form-grid .grow { flex: 1 1 220px; min-width: 180px; }
.msg.err { color: var(--bad); }
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #0f172a;
  color: #fff;
  padding: 10px 16px;
  border-radius: 8px;
  z-index: 70;
  font-size: 0.9rem;
}

@media (max-width: 900px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .menu-btn { display: inline-flex; }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 30;
    transform: translateX(-105%);
    transition: transform 0.2s ease;
    box-shadow: 8px 0 24px rgba(0,0,0,0.08);
  }
  .sidebar.open { transform: translateX(0); }
}
@media (max-width: 640px) {
  .stats { grid-template-columns: 1fr 1fr; }
  .topbar-right span:not(.role-badge) { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .sidebar { transition: none; }
}

/* OCPP 标准配置键 */
.modal-panel-config {
  width: min(720px, 96vw);
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}
.modal-panel-config .modal-body {
  overflow: auto;
  max-height: calc(90vh - 140px);
}
.config-keys-list {
  display: grid;
  gap: 10px;
}
.config-key-row {
  display: grid;
  grid-template-columns: minmax(200px, 1.1fr) minmax(180px, 1fr);
  gap: 10px 16px;
  align-items: start;
}
.config-key-row .config-key-name {
  font-size: 0.86rem;
  font-weight: 600;
  color: #1e293b;
  padding-top: 8px;
  word-break: break-word;
}
.config-key-row .config-key-control {
  display: grid;
  gap: 4px;
}
.config-key-row input[type="text"],
.config-key-row input[type="number"],
.config-key-row select {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 0.9rem;
  background: #fff;
}
.config-key-row input:disabled,
.config-key-row select:disabled,
.config-key-row .config-readonly {
  background: #eef1f5 !important;
  color: #64748b;
  cursor: not-allowed;
}
.config-feature-list {
  display: grid;
  gap: 4px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #eef1f5;
}
.config-feature-list label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: #64748b;
}
.config-feature-list input {
  accent-color: #94a3b8;
}
.config-unit {
  font-size: 0.78rem;
  color: var(--muted);
}
@media (max-width: 640px) {
  .config-key-row {
    grid-template-columns: 1fr;
  }
}
