:root {
  --bg: #0b1220;
  --panel: #121a2b;
  --panel-border: rgba(255, 255, 255, 0.08);
  --text: #e8eef7;
  --muted: #9aa8bd;
  --accent: #3b82f6;
  --ok: #22c55e;
  --warn: #f59e0b;
  --bad: #ef4444;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top, rgba(59, 130, 246, 0.18), transparent 42%),
    linear-gradient(180deg, #0a1020 0%, var(--bg) 100%);
}

.page,
.auth-page {
  max-width: 960px;
  margin: 0 auto;
  padding: 3rem 1.5rem 2rem;
}

.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding-top: 2rem;
  padding-bottom: 2rem;
}

.auth-card {
  width: min(100%, 460px);
  background: rgba(18, 26, 43, 0.94);
  border: 1px solid var(--panel-border);
  border-radius: 20px;
  padding: 2rem 1.75rem;
  box-shadow: var(--shadow);
  text-align: center;
}

.auth-card h1 {
  margin: 0 0 0.35rem;
  font-size: 2rem;
}

.subtitle,
.signed-in {
  margin: 0 0 1.25rem;
  color: var(--muted);
}

.auth-purpose {
  margin: 0 0 0.75rem;
  color: var(--text);
  font-size: 0.98rem;
  line-height: 1.55;
}

.subtitle {
  margin-bottom: 1.25rem;
  font-size: 0.92rem;
}

.signed-in {
  font-size: 0.95rem;
}

.logo {
  display: block;
  margin: 0 auto 1.25rem;
  max-width: min(320px, 86vw);
  height: auto;
}

.hero {
  text-align: center;
  margin-bottom: 2.5rem;
}

h1 {
  margin: 0 0 1rem;
  font-size: clamp(2rem, 5vw, 3rem);
  line-height: 1.1;
}

.lead {
  margin: 0 auto;
  max-width: 42rem;
  font-size: 1.08rem;
  line-height: 1.65;
  color: var(--muted);
}

.auth-form {
  display: grid;
  gap: 1rem;
  text-align: left;
}

.auth-form label span {
  display: block;
  margin-bottom: 0.4rem;
  font-size: 0.92rem;
  color: var(--muted);
}

.auth-form input {
  width: 100%;
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 0.75rem 0.85rem;
  background: rgba(8, 12, 22, 0.85);
  color: var(--text);
  font: inherit;
}

.password-field {
  position: relative;
}

.password-field input {
  padding-right: 2.75rem;
}

.password-toggle {
  position: absolute;
  top: 50%;
  right: 0.55rem;
  transform: translateY(-50%);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.password-toggle:hover,
.password-toggle:focus-visible {
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
  outline: none;
}

.password-toggle svg {
  display: block;
}

.password-toggle svg[hidden] {
  display: none;
}

.auth-form input:focus {
  outline: 2px solid rgba(59, 130, 246, 0.45);
  border-color: rgba(59, 130, 246, 0.55);
}

.btn-primary {
  margin-top: 0.25rem;
  width: 100%;
  border: 0;
  border-radius: 12px;
  padding: 0.85rem 1rem;
  background: linear-gradient(180deg, #3b82f6, #2563eb);
  color: white;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.btn-primary:hover {
  filter: brightness(1.05);
}

.alert {
  margin: 0 0 1rem;
  padding: 0.75rem 0.85rem;
  border-radius: 12px;
  font-size: 0.92rem;
}

.alert-error {
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.35);
  color: #fecaca;
}

.cf-turnstile {
  display: flex;
  justify-content: center;
}

.cards {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}

.card {
  background: rgba(18, 26, 43, 0.92);
  border: 1px solid var(--panel-border);
  border-radius: 18px;
  padding: 1.35rem 1.4rem;
  box-shadow: var(--shadow);
}

.card h2 {
  margin: 0 0 0.75rem;
  font-size: 1.05rem;
}

.card p {
  margin: 0;
  line-height: 1.6;
  color: var(--muted);
}

.status-line {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  margin-bottom: 0.65rem !important;
  color: var(--text) !important;
}

.status-dot {
  width: 0.72rem;
  height: 0.72rem;
  border-radius: 999px;
  background: var(--muted);
  box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.04);
}

.status-ok {
  background: var(--ok);
}

.status-warn {
  background: var(--warn);
}

.status-bad {
  background: var(--bad);
}

.muted {
  font-size: 0.95rem;
}

.footer {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-top: 2.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--panel-border);
  color: var(--muted);
  font-size: 0.92rem;
}

.footer a {
  color: var(--accent);
  text-decoration: none;
}

.footer a:hover {
  text-decoration: underline;
}

@media (max-width: 640px) {
  .page {
    padding-top: 2rem;
  }

  .footer {
    flex-direction: column;
  }
}

/* Authenticated app shell */
.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.app-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.65rem 1.25rem;
  border-bottom: 1px solid var(--panel-border);
  background: rgba(8, 12, 22, 0.92);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.app-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}

.app-logo {
  width: auto;
  height: 34px;
  display: block;
}

.app-name {
  font-size: 1.15rem;
  font-weight: 700;
  white-space: nowrap;
}

.app-tagline {
  color: var(--muted);
  font-size: 0.92rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-topbar-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.app-user-menu {
  position: relative;
}

.app-user-trigger {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  border: 1px solid var(--panel-border);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text);
  border-radius: 999px;
  padding: 0.35rem 0.75rem;
  cursor: pointer;
  font: inherit;
}

.app-user-dropdown {
  position: absolute;
  right: 0;
  top: calc(100% + 0.4rem);
  min-width: 220px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 0.5rem;
  z-index: 30;
}

.app-user-dropdown[hidden] {
  display: none;
}

.app-user-email {
  margin: 0.25rem 0.5rem 0.5rem;
  color: var(--muted);
  font-size: 0.82rem;
}

.app-user-dropdown a {
  display: block;
  padding: 0.55rem 0.65rem;
  border-radius: 10px;
  color: var(--text);
  text-decoration: none;
}

.app-user-dropdown a:hover {
  background: rgba(255, 255, 255, 0.05);
}

.btn-ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 0.45rem 0.85rem;
  color: var(--text);
  text-decoration: none;
  font-size: 0.92rem;
}

.btn-ghost:hover {
  background: rgba(255, 255, 255, 0.05);
}

.app-body {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  flex: 1;
  min-height: 0;
}

.app-sidebar {
  border-right: 1px solid var(--panel-border);
  padding: 1rem 0.85rem;
  background: rgba(8, 12, 22, 0.55);
}

.app-sidebar-label {
  margin: 0 0 0.65rem 0.55rem;
  color: var(--muted);
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.app-nav,
.app-sidebar-foot {
  display: grid;
  gap: 0.25rem;
}

.app-sidebar-foot {
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--panel-border);
}

.app-nav-link {
  display: block;
  padding: 0.55rem 0.65rem;
  border-radius: 10px;
  color: var(--muted);
  text-decoration: none;
}

.app-nav-link:hover,
.app-nav-link.is-active {
  color: var(--text);
  background: rgba(59, 130, 246, 0.12);
}

.app-main {
  padding: 1.25rem 1.5rem 2rem;
  min-width: 0;
}

.app-breadcrumb {
  margin-bottom: 1rem;
  color: var(--muted);
  font-size: 0.88rem;
}

.app-breadcrumb a {
  color: var(--accent);
  text-decoration: none;
}

.page-head {
  margin-bottom: 1.25rem;
}

.page-head--split {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.page-head h1 {
  margin: 0 0 0.35rem;
  font-size: clamp(1.6rem, 3vw, 2.2rem);
}

.period-form {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--muted);
  font-size: 0.92rem;
}

.period-form select,
.stack-form input,
.stack-form select {
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 0.55rem 0.7rem;
  background: rgba(8, 12, 22, 0.85);
  color: var(--text);
  font: inherit;
}

.flow-cards,
.settings-grid,
.iface-grid {
  display: grid;
  gap: 1rem;
}

.flow-cards {
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}

.flow-card,
.settings-card,
.iface-card,
.device-panel {
  background: rgba(18, 26, 43, 0.92);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  padding: 1.2rem 1.25rem;
  box-shadow: var(--shadow);
}

.flow-card {
  text-decoration: none;
  color: inherit;
}

.flow-card--muted {
  opacity: 0.72;
}

.flow-step {
  display: inline-flex;
  width: 1.6rem;
  height: 1.6rem;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: rgba(59, 130, 246, 0.18);
  color: #93c5fd;
  font-size: 0.82rem;
  font-weight: 700;
  margin-bottom: 0.75rem;
}

.flow-link {
  display: inline-block;
  margin-top: 1rem;
  color: var(--accent);
  font-size: 0.92rem;
}

.device-panel {
  display: grid;
  grid-template-columns: minmax(180px, 280px) minmax(0, 1fr);
  gap: 1.25rem;
  margin-bottom: 1rem;
}

.device-image {
  width: 100%;
  max-height: 220px;
  object-fit: contain;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.25);
}

.device-meta {
  margin: 0.85rem 0 0;
  padding-left: 1.1rem;
  color: var(--muted);
}

.iface-grid {
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
}

.iface-head {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 0.75rem;
  align-items: center;
  margin-bottom: 1rem;
}

.iface-port {
  width: 1rem;
  height: 3.2rem;
  border-radius: 999px;
  box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.04);
}

.iface-port.status-ok,
.iface-status.status-ok { background: var(--ok); color: #bbf7d0; }
.iface-port.status-warn,
.iface-status.status-warn { background: var(--warn); color: #fde68a; }
.iface-port.status-bad,
.iface-status.status-bad { background: var(--bad); color: #fecaca; }
.iface-port.status-unknown,
.iface-status.status-unknown { background: var(--muted); color: var(--text); }

.iface-status {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 0.35rem 0.55rem;
  border-radius: 999px;
}

.badge {
  display: inline-block;
  margin-left: 0.35rem;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--muted);
  font-size: 0.72rem;
  vertical-align: middle;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.metric-label {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  margin-bottom: 0.15rem;
}

.spark-wrap {
  border-top: 1px solid var(--panel-border);
  padding-top: 0.85rem;
}

.spark-label {
  margin: 0 0 0.5rem;
  color: var(--muted);
  font-size: 0.82rem;
}

.sparkline {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 72px;
}

.spark-bar {
  flex: 1;
  min-width: 4px;
  border-radius: 4px 4px 0 0;
  opacity: 0.9;
}

.settings-grid {
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}

.settings-card-link {
  text-decoration: none;
  color: inherit;
}

.stack-form {
  display: grid;
  gap: 0.85rem;
  margin-top: 1rem;
}

.stack-form label span {
  display: block;
  margin-bottom: 0.35rem;
  color: var(--muted);
  font-size: 0.88rem;
}

.btn-inline {
  width: auto;
  margin-top: 0;
}

.readonly-block p {
  display: grid;
  gap: 0.2rem;
  margin: 0 0 1rem;
}

.readonly-block span {
  color: var(--muted);
  font-size: 0.82rem;
}

.alert-ok {
  background: rgba(34, 197, 94, 0.12);
  border: 1px solid rgba(34, 197, 94, 0.35);
  color: #bbf7d0;
}

.status-unknown {
  background: var(--muted);
}

@media (max-width: 960px) {
  .app-tagline {
    display: none;
  }

  .app-body {
    grid-template-columns: 1fr;
  }

  .app-sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--panel-border);
  }

  .device-panel {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .app-topbar {
    flex-wrap: wrap;
  }

  .metric-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
