:root {
  --bg: #0f1419;
  --panel: #1a222c;
  --panel-2: #243040;
  --border: #2f3d4d;
  --text: #e8eef4;
  --muted: #8fa3b5;
  --accent: #2dd4a8;
  --accent-dim: #1a8f72;
  --warn: #e8a838;
  --danger: #e85d5d;
  --camera: #5b9fd4;
  --fiber: #c4a35a;
  --cat6: #6bcf7f;
  --font: "IBM Plex Sans", "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }
/* Class rules below set display, which would otherwise beat the UA
   stylesheet's [hidden] rule and leave hidden panels laid out. */
[hidden] { display: none !important; }
html, body {
  margin: 0;
  height: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.app {
  display: grid;
  grid-template-columns: 300px 1fr 320px;
  grid-template-rows: 52px 1fr;
  height: 100vh;
}
.app.share-mode {
  grid-template-columns: 1fr 320px;
}
.app.share-mode .toolbar { display: none; }

.topbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0 1rem;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.brand {
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--accent);
}
.brand span { color: var(--muted); font-weight: 500; margin-left: 0.4rem; }
.topbar .spacer { flex: 1; }
.topbar .meta { color: var(--muted); font-size: 0.85rem; }

.toolbar, .side {
  background: var(--panel);
  border-right: 1px solid var(--border);
  overflow: auto;
  padding: 0.75rem;
}
.side {
  border-right: none;
  border-left: 1px solid var(--border);
}

h2, h3 {
  margin: 0 0 0.6rem;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-weight: 600;
}

.tool-group { margin-bottom: 1.25rem; }
.tool-btn, button, .btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  width: 100%;
  margin: 0.2rem 0;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel-2);
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
  text-align: left;
}
.tool-btn:hover, button:hover, .btn:hover {
  border-color: var(--accent-dim);
}
.tool-btn.active {
  border-color: var(--accent);
  background: #16352c;
  color: var(--accent);
}
.tool-btn.wide, .btn.inline {
  width: auto;
  display: inline-flex;
}
.btn.primary {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: #04150f;
  font-weight: 600;
}
.btn.danger { border-color: var(--danger); color: var(--danger); }

select, input, textarea {
  width: 100%;
  margin: 0.25rem 0 0.5rem;
  padding: 0.45rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
}
label {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 0.4rem;
}

#map {
  height: 100%;
  width: 100%;
  background: #1c2833;
}

.totals {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.85rem;
  margin-bottom: 0.85rem;
}
.totals .big {
  font-size: 1.6rem;
  font-weight: 700;
  font-family: var(--mono);
  color: var(--accent);
}
.totals .sub {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 0.25rem;
}
.totals .warn {
  color: var(--warn);
  font-size: 0.8rem;
  margin-top: 0.4rem;
}
.admin-totals {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 0.5rem;
  line-height: 1.45;
}

.bom-list { list-style: none; margin: 0; padding: 0; }
.bom-list li {
  padding: 0.45rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.82rem;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.25rem 0.5rem;
}
.bom-list .cat {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-top: 0.35rem;
}
.bom-list .name { color: var(--text); }
.bom-list .price {
  font-family: var(--mono);
  color: var(--accent);
  white-space: nowrap;
}
.bom-list .est { color: var(--warn); font-size: 0.7rem; }

.hint {
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.4;
  margin: 0.4rem 0;
}
.auth-status {
  min-height: 1.2em;
  font-weight: 500;
}
.auth-status.ok {
  color: var(--accent);
}
.auth-status.warn {
  color: var(--warn);
}
#auth-form {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}
.component-summary {
  padding: 0.55rem;
  margin-bottom: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel-2);
  font-family: var(--mono);
  font-size: 0.78rem;
}
.capacity-error {
  color: var(--danger);
  font-weight: 600;
}

/* Leaflet tweaks */
.leaflet-container { background: #1c2833; font: inherit; }
.leaflet-control-attribution { font-size: 10px !important; }

.leaflet-div-icon.node-marker {
  background: transparent;
  border: none;
}
.node-icon {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: #04120e;
  box-shadow: 0 1px 4px rgba(0,0,0,.45);
  transform-origin: center center;
}
.node-icon.camera {
  background: var(--camera);
  position: relative;
}
.node-icon.camera::after {
  content: "";
  position: absolute;
  top: -7px;
  left: 50%;
  width: 0;
  height: 0;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-bottom: 8px solid #fff;
  transform: translateX(-50%);
}
.node-icon.network_box { background: #a78bfa; }
.node-icon.core_rack { background: #f472b6; }
.node-icon.gate { background: var(--warn); }
.node-icon.wifi_ap { background: #34d399; }
.map-rotating {
  cursor: crosshair !important;
}
.btn.rotate-active {
  border-color: var(--camera);
  background: #163040;
  color: var(--camera);
}

.admin-layout {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.5rem;
}
.admin-layout table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}
.admin-layout th, .admin-layout td {
  border-bottom: 1px solid var(--border);
  padding: 0.45rem 0.4rem;
  text-align: left;
  vertical-align: top;
}
.admin-layout th { color: var(--muted); font-weight: 600; }
.admin-layout input, .admin-layout select {
  margin: 0;
  padding: 0.3rem;
  font-size: 0.8rem;
}
.badge {
  display: inline-block;
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  font-size: 0.7rem;
  text-transform: uppercase;
}
.badge.listed { background: #16352c; color: var(--accent); }
.badge.confirm { background: #3a2e14; color: var(--warn); }

.login-box {
  max-width: 360px;
  margin: 4rem auto;
  padding: 1.5rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
}

@media (max-width: 900px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: 52px auto 45vh auto;
  }
  .toolbar, .side { border: none; max-height: 220px; }
  .app.share-mode {
    grid-template-columns: 1fr;
  }
}

.auth-gate {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: var(--bg);
}
.auth-gate .login-box {
  width: min(420px, 100%);
}
label.check {
  display: flex;
  gap: 0.5rem;
  align-items: flex-start;
  font-size: 0.85rem;
  color: var(--muted);
  margin: 0.5rem 0;
}
label.check input { margin-top: 0.2rem; }
textarea {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 0.45rem 0.55rem;
  font: inherit;
}
.node-icon.site_need {
  background: #8b5cf6;
}

.flow-steps {
  list-style: none;
  margin: 0 0 0.5rem;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}
.flow-steps li {
  padding: 0.35rem 0.5rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.85rem;
}
.flow-steps li.active {
  border-color: var(--accent);
  color: var(--text);
  background: rgba(45, 212, 168, 0.08);
}
.flow-steps li.done {
  border-color: var(--accent-dim);
  color: var(--accent);
}

.port-meter {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-family: var(--mono);
  font-size: 0.75rem;
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
  background: var(--panel-2);
  border: 1px solid var(--border);
}
.port-meter.over { border-color: var(--danger); color: var(--danger); }

.box-defaults { margin: 0.5rem 0; }

.port-badge {
  position: absolute;
  bottom: -10px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 9px;
  font-family: var(--mono);
  white-space: nowrap;
  background: #122018;
  border: 1px solid var(--accent-dim);
  color: var(--accent);
  padding: 0 3px;
  border-radius: 3px;
  pointer-events: none;
}
.node-icon { position: relative; }
