:root {
  --bg-top: #5d78c8;
  --bg-bottom: #344f97;
  --card: rgba(35, 39, 54, 0.94);
  --card-soft: rgba(35, 39, 54, 0.82);
  --ink: #f2f5ff;
  --muted: #c7cde3;
  --line: rgba(196, 206, 238, 0.42);
  --primary: #f73768;
  --primary-2: #eb2c5c;
  --danger: #ff6585;
  --ok: #6be39f;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: "Segoe UI", "Helvetica Neue", sans-serif;
  background:
    radial-gradient(circle at 12% 0%, rgba(143, 178, 255, 0.5) 0%, transparent 34%),
    radial-gradient(circle at 100% 100%, rgba(78, 112, 204, 0.45) 0%, transparent 42%),
    linear-gradient(180deg, var(--bg-top), var(--bg-bottom));
}

.shell {
  width: min(1120px, calc(100% - 24px));
  margin: 18px auto 28px;
  display: grid;
  gap: 14px;
}

.page { display: none; }
.page.active { display: block; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: 0 14px 38px rgba(5, 13, 44, 0.32);
  padding: 18px;
  backdrop-filter: blur(6px);
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

h1 { margin: 0; font-size: 28px; letter-spacing: 0.2px; }
h2 { margin: 0 0 12px; font-size: 20px; }

.brand-stack {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.brand-app-logo {
  width: 72px;
  height: 72px;
  object-fit: contain;
}

.brand-title {
  font-size: 36px;
  line-height: 1;
  text-align: center;
}

.brand-card,
.login-card {
  width: min(520px, 100%);
  margin: 0 auto;
}

.login-card .actions {
  justify-content: center;
}

.login-card .actions .primary {
  min-width: 180px;
  width: min(220px, 100%);
}

body.route-viewer .card {
  background: var(--card-soft);
}

body.route-viewer .brand-card {
  display: none;
}

.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.grid.one-col { grid-template-columns: 1fr; }

label {
  display: block;
  margin: 0;
  font-size: 13px;
  color: var(--muted);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

input {
  width: 100%;
  margin-top: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--ink);
}

input::placeholder { color: rgba(236, 241, 255, 0.58); }

.actions { margin-top: 12px; display: flex; gap: 8px; flex-wrap: wrap; }
.actions.compact { margin-top: 0; }

.password-field {
  position: relative;
}

.password-field input {
  margin-top: 0;
  padding-right: 46px;
}

button {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--ink);
  padding: 9px 12px;
  cursor: pointer;
}

button.primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  border-color: transparent;
  color: #fff;
  font-weight: 600;
}

button.primary.loading {
  position: relative;
  color: transparent;
  pointer-events: none;
}

button.primary.loading::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 18px;
  height: 18px;
  margin-left: -9px;
  margin-top: -9px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.45);
  border-top-color: #fff;
  animation: btn-spin 0.8s linear infinite;
}

.icon-btn {
  width: 34px;
  height: 34px;
  padding: 0;
  display: grid;
  place-items: center;
  border-radius: 999px;
  border: 0;
  background: transparent;
  color: rgba(232, 238, 255, 0.76);
}

.password-field .icon-btn {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
}

.pass-toggle::before {
  content: "";
  width: 20px;
  height: 20px;
  display: block;
  background-repeat: no-repeat;
  background-position: center;
  background-size: 20px 20px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' stroke='%23dbe4ff' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round' viewBox='0 0 24 24'%3E%3Cpath d='M1 12s4-7 11-7 11 7 11 7-4 7-11 7S1 12 1 12z'/%3E%3Ccircle cx='12' cy='12' r='3'/%3E%3C/svg%3E");
}

.pass-toggle.is-visible::before {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' stroke='%23dbe4ff' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round' viewBox='0 0 24 24'%3E%3Cpath d='M17.94 17.94A10.94 10.94 0 0 1 12 19C5 19 1 12 1 12a21.73 21.73 0 0 1 5.17-5.94'/%3E%3Cpath d='M9.9 4.24A10.94 10.94 0 0 1 12 4c7 0 11 8 11 8a21.72 21.72 0 0 1-2.16 3.19'/%3E%3Cpath d='M14.12 14.12a3 3 0 0 1-4.24-4.24'/%3E%3Cpath d='M1 1l22 22'/%3E%3C/svg%3E");
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.1);
}

.icon-btn:focus-visible {
  outline: 2px solid rgba(247, 55, 104, 0.75);
  outline-offset: 1px;
}

@keyframes btn-spin {
  to {
    transform: rotate(360deg);
  }
}

button:disabled { opacity: 0.5; cursor: default; }

#msg { margin-top: 12px; min-height: 20px; font-size: 14px; }
.muted { color: var(--muted); }
.error { color: var(--danger); }
.ok { color: var(--ok); }

.viewer { display: none; gap: 10px; }
.viewer.visible { display: grid; }
.viewer-toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.screen-name {
  font-weight: 700;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 12px;
  background: rgba(255, 255, 255, 0.08);
}

.screen-list { display: flex; flex-wrap: wrap; gap: 8px; }

.screen-list button.active {
  background: rgba(82, 124, 238, 0.35);
  border-color: rgba(136, 168, 255, 0.75);
  color: #f4f7ff;
  font-weight: 600;
}

.canvas-wrap {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
  background: rgba(18, 24, 45, 0.6);
  min-height: 260px;
}

.diagram-wrap {
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
  background: rgba(18, 24, 45, 0.6);
  min-height: 260px;
}

#diagramSvg {
  display: block;
  width: 100%;
  height: auto;
  min-height: 260px;
}

.canvas-wrap img {
  display: block;
  width: 100%;
  height: auto;
  user-select: none;
  pointer-events: none;
}

.hotspot-layer { position: absolute; inset: 0; }

.hotspot {
  position: absolute;
  border: 2px solid rgba(233, 43, 90, 0.9);
  background: rgba(233, 43, 90, 0.22);
  border-radius: 8px;
  cursor: pointer;
}

.diagram-edge {
  stroke: rgba(160, 189, 255, 0.95);
  stroke-width: 2.6;
  fill: none;
  opacity: 0.95;
}

.diagram-node-group {
  cursor: pointer;
}

.diagram-card {
  fill: rgba(55, 73, 129, 0.98);
  stroke: rgba(184, 205, 255, 0.9);
  stroke-width: 2;
  rx: 14;
}

.diagram-node-group.active .diagram-card {
  fill: rgba(237, 46, 96, 0.96);
  stroke: rgba(255, 196, 215, 0.95);
  stroke-width: 2.4;
}

.diagram-thumb-bg {
  fill: rgba(12, 19, 42, 0.9);
  rx: 10;
}

.diagram-thumb {
  opacity: 1;
}

.diagram-thumb-frame {
  fill: none;
  stroke: rgba(210, 224, 255, 0.42);
  stroke-width: 1.4;
}

.diagram-label {
  fill: #f4f7ff;
  font-size: 14px;
  font-weight: 600;
  text-anchor: middle;
  dominant-baseline: middle;
  pointer-events: none;
}

.diagram-sub {
  fill: rgba(223, 234, 255, 0.82);
  font-size: 11px;
  text-anchor: middle;
  dominant-baseline: middle;
  pointer-events: none;
}

.diagram-empty-thumb {
  fill: rgba(204, 218, 255, 0.7);
  font-size: 11px;
  text-anchor: middle;
  dominant-baseline: middle;
  pointer-events: none;
}

.raw { margin-top: 4px; }

pre {
  margin: 0;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(11, 16, 33, 0.9);
  color: #f0f4ff;
  max-height: 300px;
  overflow: auto;
}

#msgLogin, #msgApp { margin-top: 12px; min-height: 20px; font-size: 14px; }

.site-footer {
  width: 100%;
  display: grid;
  place-items: center;
  padding: 0 0 14px;
}

.footer-logo {
  width: 128px;
  height: auto;
  object-fit: contain;
  filter: drop-shadow(0 4px 14px rgba(5, 10, 32, 0.3));
  opacity: 0.92;
}

.app-version {
  margin-top: 10px;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.4);
  font-family: monospace;
}

@media (max-width: 720px) {
  .grid { grid-template-columns: 1fr; }
  .shell { width: calc(100% - 16px); margin-top: 8px; }
  .card { padding: 14px; border-radius: 14px; }
  h1 { font-size: 22px; }
  .topbar { align-items: flex-start; flex-direction: column; }
  .brand-card,
  .login-card { width: 100%; }
  .brand-title { font-size: 28px; }
  .brand-app-logo { width: 60px; height: 60px; }
  .login-card .actions .primary {
    width: 100%;
    max-width: 260px;
  }
}
