:root {
  --bg: #08111c;
  --bg-soft: #0c1826;
  --sidebar: #061018;
  --card: rgba(16, 32, 48, 0.86);
  --card-solid: #102030;
  --line: rgba(148, 186, 210, 0.12);
  --text: #e8f2f7;
  --muted: #8aa0b5;
  --accent: #2ee6c7;
  --accent-2: #4cc3f0;
  --normal: #3ddc8a;
  --attention: #f0c14a;
  --critical: #ff5b7a;
  --offline: #7b8ea3;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.28);
  --radius: 18px;
  --sidebar-w: 268px;
}

* { box-sizing: border-box; }

html, body {
  min-height: 100%;
  background:
    radial-gradient(1200px 500px at 10% -10%, rgba(46, 230, 199, 0.08), transparent 50%),
    radial-gradient(900px 400px at 100% 0%, rgba(76, 195, 240, 0.08), transparent 45%),
    var(--bg);
  color: var(--text);
  font-family: "Manrope", "Segoe UI", sans-serif;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: #9ff6e6; }

.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-w);
  background: linear-gradient(180deg, #07131e 0%, #050d14 100%);
  border-right: 1px solid var(--line);
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 10px 22px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #2ee6c7, #1a8cff);
  color: #042018;
  font-weight: 800;
  letter-spacing: -1px;
}

.brand h1 {
  font-size: 1.05rem;
  margin: 0;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.brand small {
  color: var(--muted);
  display: block;
  font-size: 0.72rem;
  letter-spacing: 0.04em;
}

.nav-group {
  color: #6f879c;
  font-size: 0.68rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  padding: 18px 12px 8px;
}

.sidebar a.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #c9dbe8;
  padding: 12px;
  min-height: 44px;
  border-radius: 12px;
  margin-bottom: 4px;
  font-weight: 600;
  font-size: 0.92rem;
}

.sidebar a.nav-link:hover,
.sidebar a.nav-link.active {
  background: rgba(46, 230, 199, 0.1);
  color: var(--accent);
}

.sidebar-footer {
  margin-top: auto;
  padding: 12px;
  color: var(--muted);
  font-size: 0.8rem;
}

.main {
  flex: 1;
  min-width: 0;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 28px;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  background: rgba(8, 17, 28, 0.85);
  backdrop-filter: blur(16px);
  z-index: 10;
}

.page-title {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 700;
}

.page-kicker {
  color: var(--muted);
  font-size: 0.82rem;
  margin: 0;
}

.content {
  padding: 24px 28px 48px;
  padding-bottom: calc(48px + env(safe-area-inset-bottom, 0px));
}

.table-responsive {
  -webkit-overflow-scrolling: touch;
}

.health-score-cell {
  min-width: 120px;
}

.token-code {
  word-break: break-all;
}

.chart-range-wrap .range-btn {
  min-height: 44px;
}

.topbar-icon-btn {
  min-height: 44px;
  min-width: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 14px;
}

.sidebar-toggle {
  min-height: 44px;
  min-width: 44px;
  padding: 10px;
}

.back-row {
  margin-bottom: 16px;
}

.btn-back {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: rgba(46, 230, 199, 0.12);
  color: var(--accent);
  border: 1px solid rgba(46, 230, 199, 0.28);
  border-radius: 12px;
  font-weight: 700;
  padding: 8px 14px;
}

.btn-back:hover {
  background: rgba(46, 230, 199, 0.2);
  color: #9ff6e6;
}

.card, .vc-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

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

.kpi {
  padding: 20px;
  position: relative;
  overflow: hidden;
  text-align: left;
  color: inherit;
}

button.kpi, a.kpi {
  cursor: pointer;
  appearance: none;
  width: 100%;
}

button.kpi:hover, a.kpi:hover {
  border-color: rgba(46, 230, 199, 0.35);
  transform: translateY(-2px);
}

.kpi .label {
  color: var(--muted);
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.kpi .value {
  font-size: 2.1rem;
  font-weight: 800;
  margin-top: 6px;
  font-variant-numeric: tabular-nums;
}

.live-strip {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px 14px;
}
.live-strip .badge-status {
  font-size: 0.72rem;
  cursor: pointer;
  border: 1px solid transparent;
  min-height: 36px;
  padding: 8px 12px;
}
.live-strip button.badge-status {
  appearance: none;
}
.live-strip .badge-status:hover,
.live-strip .badge-status.is-active {
  outline: 2px solid rgba(46, 230, 199, 0.45);
  outline-offset: 2px;
}

.live-value {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.35rem !important;
}
.live-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--normal);
  box-shadow: 0 0 0 0 rgba(61, 220, 138, 0.7);
  animation: livePulse 1.4s infinite;
}
@keyframes livePulse {
  0% { box-shadow: 0 0 0 0 rgba(61, 220, 138, 0.55); }
  70% { box-shadow: 0 0 0 10px rgba(61, 220, 138, 0); }
  100% { box-shadow: 0 0 0 0 rgba(61, 220, 138, 0); }
}
@keyframes cardFlash {
  0% { border-color: rgba(46, 230, 199, 0.9); box-shadow: 0 0 0 1px rgba(46, 230, 199, 0.35); }
  100% { border-color: var(--line); box-shadow: var(--shadow); }
}
.lab-card.is-updating {
  animation: cardFlash 0.9s ease;
}
.fridge-card.status-pop .badge-status {
  animation: statusPop 0.6s ease;
}
@keyframes statusPop {
  0% { transform: scale(1); }
  40% { transform: scale(1.12); }
  100% { transform: scale(1); }
}
.recover-banner {
  background: rgba(61, 220, 138, 0.14);
  border: 1px solid rgba(61, 220, 138, 0.4);
  color: var(--normal);
  border-radius: 12px;
  padding: 10px 12px;
  font-weight: 700;
}

.kpi-flash {
  color: var(--accent) !important;
}

.kpi .hint { color: var(--muted); font-size: 0.82rem; }

.kpi::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 4px;
  background: var(--accent);
}

.kpi.normal::before { background: var(--normal); }
.kpi.attention::before { background: var(--attention); }
.kpi.critical::before { background: var(--critical); }
.kpi.offline::before { background: var(--offline); }

.fridge-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

a.fridge-card {
  display: block;
  color: inherit;
  padding: 18px;
  cursor: pointer;
  pointer-events: auto;
  position: relative;
  z-index: 1;
  transition: transform .18s ease, border-color .18s ease;
}

.open-hint {
  margin-top: 12px;
  color: var(--accent);
  font-size: 0.8rem;
  font-weight: 700;
}

.fridge-card:hover {
  transform: translateY(-3px);
  border-color: rgba(46, 230, 199, 0.35);
}

.fridge-card .temp {
  font-size: 2rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.meta { color: var(--muted); font-size: 0.82rem; }

.badge-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.badge-status.normal { background: rgba(61, 220, 138, 0.15); color: var(--normal); }
.badge-status.attention { background: rgba(240, 193, 74, 0.15); color: var(--attention); }
.badge-status.critical { background: rgba(255, 91, 122, 0.16); color: var(--critical); }
.badge-status.offline { background: rgba(123, 142, 163, 0.18); color: #c5d0dc; }

.table {
  --bs-table-bg: transparent;
  --bs-table-color: var(--text);
  --bs-table-border-color: var(--line);
  --bs-table-striped-bg: rgba(255,255,255,0.02);
  --bs-table-hover-bg: rgba(46, 230, 199, 0.05);
}

.form-control, .form-select {
  background: #0b1a27;
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 12px;
  min-height: 44px;
}

.form-control::placeholder,
textarea.form-control::placeholder {
  color: #b7c9d8;
  opacity: 1;
}

.form-check-input {
  background-color: #0b1a27;
  border-color: var(--line);
}
.form-check-input:checked {
  background-color: var(--accent);
  border-color: var(--accent);
}
.form-check-label {
  color: var(--text);
}

.form-select option {
  background: #0b1a27;
  color: var(--text);
}

.form-control:focus, .form-select:focus {
  background: #0b1a27;
  color: var(--text);
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(46, 230, 199, 0.15);
}

.step {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  margin-bottom: 10px;
}
.step.locked { opacity: 0.45; pointer-events: none; }
.step.done .fw-semibold { color: var(--normal); }
.step.current {
  border-color: rgba(46, 230, 199, 0.55);
  background: rgba(46, 230, 199, 0.08);
  box-shadow: 0 0 0 3px rgba(46, 230, 199, 0.12);
}
.step-now {
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #042018;
  background: var(--accent);
  border-radius: 999px;
  padding: 3px 8px;
}
.workflow-track {
  display: flex;
  align-items: center;
  gap: 8px;
}
.wf-node {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 800;
  border: 1px solid var(--line);
  color: var(--muted);
}
.wf-node.current {
  border-color: var(--accent);
  color: #042018;
  background: var(--accent);
}
.wf-node.done {
  border-color: var(--normal);
  color: var(--normal);
  background: rgba(61, 220, 138, 0.12);
}
.wf-line {
  flex: 1;
  height: 2px;
  background: var(--line);
}
.wf-line.done { background: var(--normal); }

.btn-accent {
  background: linear-gradient(135deg, #2ee6c7, #1bb89e);
  color: #042018;
  font-weight: 700;
  border: 0;
  border-radius: 12px;
  padding: 10px 16px;
}

.btn-ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 12px;
}

.range-btn.active {
  background: rgba(46, 230, 199, 0.16);
  border-color: #2ee6c7;
  color: #e8fbff;
}

.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(460px, 100%);
  padding: 36px;
}

.health-bar {
  height: 8px;
  border-radius: 99px;
  background: rgba(255,255,255,0.08);
  overflow: hidden;
}

.health-bar span {
  display: block;
  height: 100%;
  border-radius: 99px;
}

.timeline {
  border-left: 2px solid var(--line);
  margin-left: 10px;
  padding-left: 18px;
}

.timeline-item { margin-bottom: 16px; position: relative; }
.timeline-item::before {
  content: "";
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  position: absolute;
  left: -24px;
  top: 6px;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
}

.avatar {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: rgba(46, 230, 199, 0.16);
  display: grid;
  place-items: center;
  color: var(--accent);
  font-weight: 700;
}

.alert-toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
}

@media (max-width: 1100px) {
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

.sidebar-toggle { display: none; }
.sidebar-backdrop {
  display: none;
  pointer-events: none;
}

@media (max-width: 900px) {
  .sidebar-toggle { display: grid; place-items: center; }
  .sidebar {
    position: fixed;
    transform: translateX(-110%);
    transition: transform .2s ease;
    box-shadow: var(--shadow);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 15;
  }
  .sidebar-backdrop.show {
    display: block;
    pointer-events: auto;
  }
  .content, .topbar {
    padding-left: 16px;
    padding-right: 16px;
    padding-left: calc(16px + env(safe-area-inset-left, 0px));
    padding-right: calc(16px + env(safe-area-inset-right, 0px));
  }
  .topbar {
    flex-wrap: wrap;
    gap: 12px;
    align-items: flex-start;
  }
  .topbar-start,
  .topbar-end {
    min-width: 0;
  }
  .topbar-start {
    flex: 1 1 220px;
  }
  .topbar-end {
    flex: 0 0 auto;
    margin-left: auto;
  }
  .topbar-titles {
    min-width: 0;
  }
  .page-title {
    font-size: 1.1rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: min(52vw, 280px);
  }
  .user-chip-text {
    display: none;
  }
  body.sidebar-open {
    overflow: hidden;
  }
}

@media (max-width: 480px) {
  .kpi-grid { grid-template-columns: 1fr; }
  .page-title { max-width: 46vw; }
  .login-card { padding: 24px; }
}
