:root {
  color-scheme: dark;
  --bg: #05090e;
  --bg-2: #071119;
  --panel: rgba(8, 18, 27, 0.78);
  --panel-strong: rgba(9, 22, 33, 0.92);
  --panel-soft: rgba(17, 36, 50, 0.62);
  --line: rgba(202, 232, 255, 0.16);
  --line-strong: rgba(72, 224, 194, 0.42);
  --text: #f4fbff;
  --muted: #a8b8c7;
  --subtle: #718493;
  --teal: #48e0c2;
  --blue: #7bb7ff;
  --gold: #f0c75e;
  --green: #99e36a;
  --red: #ff6f86;
  --magenta: #ff6fb1;
  --shadow: 0 22px 80px rgba(0, 0, 0, 0.38);
  --glow: 0 0 26px rgba(72, 224, 194, 0.22);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  background: var(--bg);
}

body {
  margin: 0;
  min-width: 1120px;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
  letter-spacing: 0;
}

body.console-page,
body.login-page {
  background: #05090e;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  min-height: 36px;
  border: 1px solid rgba(202, 232, 255, 0.16);
  border-radius: 7px;
  background: rgba(13, 27, 39, 0.72);
  color: var(--text);
  padding: 0 13px;
  cursor: pointer;
  white-space: nowrap;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
  transition: border-color 160ms ease, background 160ms ease, color 160ms ease, box-shadow 160ms ease;
}

button:hover {
  border-color: var(--line-strong);
  background: rgba(22, 48, 63, 0.9);
  box-shadow: var(--glow);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
  box-shadow: none;
}

button.primary {
  color: #03120f;
  border-color: rgba(72, 224, 194, 0.86);
  background: linear-gradient(135deg, #48e0c2, #99e36a);
  font-weight: 800;
}

button.warning {
  color: #fff6d8;
  background: rgba(77, 58, 23, 0.84);
  border-color: rgba(240, 199, 94, 0.46);
}

button.danger {
  color: #ffe9ee;
  background: rgba(74, 24, 40, 0.88);
  border-color: rgba(255, 111, 134, 0.5);
}

button.ghost {
  background: rgba(255, 255, 255, 0.02);
}

button.wide {
  width: 100%;
}

input,
select,
textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid rgba(202, 232, 255, 0.15);
  border-radius: 7px;
  background: rgba(3, 10, 16, 0.72);
  color: var(--text);
  outline: none;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

input,
select {
  min-height: 36px;
  padding: 0 10px;
}

textarea {
  width: 100%;
  min-height: 300px;
  resize: vertical;
  padding: 12px;
  font: 12px Consolas, "Courier New", monospace;
  line-height: 1.55;
}

input[type="checkbox"],
input[type="radio"] {
  width: auto;
}

input:focus,
select:focus,
textarea:focus {
  border-color: rgba(72, 224, 194, 0.78);
  box-shadow: 0 0 0 3px rgba(72, 224, 194, 0.11);
}

.space-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  pointer-events: none;
}

.hud-grid {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  opacity: 0.28;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.035) 1px, transparent 1px);
  background-size: 54px 54px;
  mask-image: linear-gradient(to bottom, black 0%, black 72%, transparent 100%);
}

.app-shell {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 304px minmax(0, 1fr);
  min-height: 100vh;
}

.side-nav {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
  border-right: 1px solid rgba(72, 224, 194, 0.18);
  background: rgba(5, 13, 20, 0.82);
  backdrop-filter: blur(18px);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: 16px 0 80px rgba(0, 0, 0, 0.34);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 58px;
}

.brand-mark {
  width: 46px;
  height: 46px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  color: #03120f;
  background: var(--teal);
  font-weight: 900;
  box-shadow: 0 0 34px rgba(72, 224, 194, 0.32);
}

.brand-copy h1 {
  margin: 0;
  font-size: 18px;
  line-height: 1.2;
}

.brand-copy p,
.page-title .eyebrow,
.panel-header p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.nav-list {
  display: grid;
  gap: 8px;
}

.nav-item {
  width: 100%;
  justify-content: flex-start;
  text-align: left;
  background: rgba(255, 255, 255, 0.02);
  border-color: transparent;
  color: var(--muted);
}

.nav-item.active,
.nav-item:hover {
  color: var(--text);
  background: rgba(72, 224, 194, 0.11);
  border-color: rgba(72, 224, 194, 0.34);
}

.side-panel,
.panel,
.audit-panel,
.metric,
.login-box,
.login-visual {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  backdrop-filter: blur(16px);
  box-shadow: var(--shadow);
}

.side-panel {
  padding: 12px;
}

.side-title {
  margin-bottom: 8px;
  color: var(--text);
  font-size: 13px;
  font-weight: 800;
}

.kv-row,
.kv-tile {
  min-height: 34px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid rgba(202, 232, 255, 0.08);
  color: var(--muted);
  font-size: 12px;
}

.kv-row:last-child {
  border-bottom: 0;
}

.kv-row strong,
.kv-tile strong {
  color: var(--text);
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mapping-list,
.risk-list {
  display: grid;
  gap: 8px;
}

.map-row,
.risk-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  min-height: 30px;
  align-items: center;
  border-bottom: 1px solid rgba(202, 232, 255, 0.08);
  color: var(--muted);
  font-size: 12px;
}

.map-row strong,
.risk-row strong {
  color: var(--text);
}

.main-console {
  min-width: 0;
  height: 100vh;
  overflow: auto;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
}

.command-bar {
  position: sticky;
  top: 0;
  z-index: 5;
  min-height: 78px;
  border-bottom: 1px solid rgba(72, 224, 194, 0.16);
  background: rgba(5, 10, 16, 0.82);
  backdrop-filter: blur(18px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 14px 18px;
}

.command-left {
  display: flex;
  align-items: center;
  gap: 18px;
  min-width: 0;
  flex: 1 1 auto;
}

.page-title {
  flex: 0 0 auto;
}

.page-title h2 {
  margin: 0;
  font-size: 20px;
  white-space: nowrap;
}

.status-strip,
.command-actions,
.panel-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.status-strip {
  color: var(--muted);
  font-size: 12px;
}

.lamp {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--subtle);
  display: inline-block;
  box-shadow: 0 0 12px currentColor;
}

.lamp.ok {
  color: var(--teal);
  background: var(--teal);
}

.lamp.warn {
  color: var(--gold);
  background: var(--gold);
}

.lamp.bad {
  color: var(--red);
  background: var(--red);
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid rgba(72, 224, 194, 0.14);
}

.metric {
  min-height: 92px;
  padding: 15px;
  overflow: hidden;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.metric strong {
  display: block;
  margin-top: 9px;
  font-size: 28px;
  line-height: 1;
}

.metric:nth-child(1) strong {
  color: var(--teal);
}

.metric:nth-child(2) strong {
  color: var(--blue);
}

.metric:nth-child(3) strong {
  color: var(--gold);
}

.metric:nth-child(4) strong {
  color: var(--green);
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(0, 0.85fr);
  grid-auto-rows: minmax(220px, auto);
  gap: 12px;
  padding: 14px 18px;
}

.panel,
.audit-panel {
  min-width: 0;
  min-height: 0;
  padding: 14px;
}

.panel-wide {
  grid-column: 1 / -1;
}

.panel-large {
  min-height: 360px;
}

.panel-header {
  min-height: 38px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.panel-header h3 {
  margin: 0;
  font-size: 15px;
}

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

.guide-step {
  min-height: 158px;
  border: 1px solid rgba(202, 232, 255, 0.12);
  border-radius: 8px;
  background: rgba(10, 24, 35, 0.7);
  padding: 12px;
}

.guide-step span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 24px;
  border-radius: 6px;
  background: rgba(72, 224, 194, 0.12);
  color: var(--teal);
  font-size: 12px;
  font-weight: 900;
}

.guide-step h4 {
  margin: 10px 0 6px;
  font-size: 14px;
}

.guide-step p,
.field-note {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.65;
}

.field-note {
  margin-top: 10px;
}

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

.billing-grid {
  display: grid;
  gap: 12px;
}

.billing-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 10px;
}

.plan-cards {
  display: grid;
  grid-template-columns: repeat(2, minmax(260px, 1fr));
  gap: 12px;
}

.plan-card {
  min-height: 260px;
  border: 1px solid rgba(202, 232, 255, 0.12);
  border-radius: 8px;
  background: rgba(10, 24, 35, 0.7);
  padding: 14px;
  display: grid;
  grid-template-rows: 1fr auto auto;
  gap: 12px;
}

.plan-card.featured {
  border-color: rgba(72, 224, 194, 0.34);
  box-shadow: var(--glow);
}

.plan-card span {
  color: var(--teal);
  font-size: 12px;
  font-weight: 900;
}

.plan-card h4 {
  margin: 8px 0 6px;
  font-size: 17px;
}

.plan-card p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.65;
}

.plan-card ul {
  margin: 0;
  padding-left: 18px;
  color: #d6e3ec;
  font-size: 12px;
  line-height: 1.8;
}

.tv-grid {
  display: grid;
  grid-template-columns: minmax(260px, 0.7fr) minmax(420px, 1.3fr);
  gap: 12px;
}

.tv-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  align-content: start;
}

.tv-form label,
.form-grid label,
.login-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.tv-url-field {
  grid-column: 1 / -1;
}

.message-output {
  min-height: 260px;
}

.kv-tile {
  min-height: 60px;
  border: 1px solid rgba(202, 232, 255, 0.12);
  border-radius: 7px;
  background: rgba(10, 24, 35, 0.7);
  padding: 10px 12px;
}

.kv-tile.wide strong {
  max-width: 420px;
}

.settings-tabs {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  border-bottom: 1px solid rgba(202, 232, 255, 0.1);
  padding-bottom: 8px;
}

.tab-button {
  background: transparent;
  color: var(--muted);
}

.tab-button.active {
  color: var(--text);
  background: rgba(72, 224, 194, 0.11);
  border-color: var(--line-strong);
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

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

.auth-panel {
  min-height: 80px;
  border: 1px solid rgba(202, 232, 255, 0.12);
  border-radius: 8px;
  background: rgba(10, 24, 35, 0.72);
  padding: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.auth-panel h4 {
  margin: 0;
  font-size: 14px;
}

.auth-panel p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.check-row {
  min-height: 36px;
  display: flex !important;
  align-items: center;
  gap: 8px;
  padding-top: 18px;
}

.check-row input {
  min-height: auto;
}

.save-status {
  min-width: 72px;
  color: var(--muted);
  font-size: 12px;
}

.table-wrap {
  width: 100%;
  height: calc(100% - 50px);
  min-height: 160px;
  overflow: auto;
}

.table-wrap.compact {
  min-height: 240px;
}

table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 12px;
}

th,
td {
  height: 34px;
  border-bottom: 1px solid rgba(202, 232, 255, 0.08);
  padding: 0 9px;
  text-align: left;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

th {
  position: sticky;
  top: 0;
  color: var(--muted);
  background: rgba(13, 29, 42, 0.96);
  font-weight: 800;
}

.empty-cell {
  color: var(--muted);
  text-align: center;
}

.tag {
  display: inline-flex;
  align-items: center;
  height: 22px;
  max-width: 100%;
  padding: 0 7px;
  border-radius: 999px;
  background: rgba(202, 232, 255, 0.1);
  color: var(--muted);
}

.tag.ok {
  color: var(--teal);
}

.tag.bad {
  color: var(--red);
}

.tag.warn {
  color: var(--gold);
}

.audit-panel {
  margin: 0 18px 18px;
}

.logs {
  height: 220px;
  overflow: auto;
  font: 12px Consolas, "Courier New", monospace;
  line-height: 1.45;
  color: #d2dde7;
}

.log-line {
  min-height: 24px;
  border-bottom: 1px solid rgba(202, 232, 255, 0.08);
  display: grid;
  grid-template-columns: 92px 76px 110px minmax(0, 1fr);
  gap: 8px;
  align-items: center;
}

.muted {
  color: var(--muted);
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 20;
  min-width: 220px;
  max-width: 360px;
  min-height: 42px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: rgba(8, 18, 27, 0.94);
  color: var(--text);
  box-shadow: var(--shadow);
  padding: 12px 14px;
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.login-page {
  min-width: 0;
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 22px;
  overflow-x: hidden;
}

.auth-stage {
  position: relative;
  z-index: 1;
  width: min(1040px, calc(100vw - 32px));
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(320px, 430px) minmax(320px, 1fr);
  align-items: stretch;
  gap: 16px;
}

.login-box,
.login-visual {
  width: 100%;
  min-width: 0;
  padding: 24px;
  overflow-wrap: anywhere;
}

.login-brand {
  margin-bottom: 20px;
}

.login-form {
  display: grid;
  gap: 13px;
}

.login-form label {
  font-size: 13px;
}

#login-error,
#register-error {
  min-height: 18px;
  margin: 0;
  color: var(--red);
  font-size: 13px;
}

.form-help {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
}

.form-link {
  color: var(--teal);
  font-size: 13px;
  text-decoration: none;
}

.form-link:hover {
  text-decoration: underline;
}

.login-visual {
  min-height: 430px;
  display: grid;
  align-content: center;
  gap: 18px;
  overflow: hidden;
}

.login-visual span {
  color: var(--teal);
  font-size: 12px;
  font-weight: 900;
}

.login-visual h2 {
  margin: 0;
  font-size: 44px;
  line-height: 1.05;
}

.login-visual p {
  max-width: 520px;
  margin: 0;
  color: #dbe8f1;
  line-height: 1.72;
}

.visual-steps {
  display: grid;
  grid-template-columns: 1fr 42px 1fr 42px 1fr;
  align-items: center;
  gap: 10px;
}

.visual-steps i {
  min-height: 40px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(202, 232, 255, 0.14);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  font-style: normal;
  font-size: 12px;
}

.visual-steps b {
  height: 1px;
  background: var(--teal);
  box-shadow: 0 0 14px rgba(72, 224, 194, 0.7);
}

@media (max-width: 1180px) {
  .guide-grid {
    grid-template-columns: repeat(2, minmax(220px, 1fr));
  }
}

@media (max-width: 980px) {
  body {
    min-width: 0;
  }

  .app-shell,
  .auth-stage {
    grid-template-columns: 1fr;
  }

  .side-nav {
    position: static;
    height: auto;
  }

  .main-console {
    height: auto;
  }

  .command-bar,
  .command-left,
  .auth-panel {
    align-items: stretch;
    flex-direction: column;
  }

  .metric-grid,
  .content-grid,
  .ops-grid,
  .billing-summary,
  .plan-cards,
  .tv-grid,
  .tv-form,
  .form-grid,
  .guide-grid,
  .visual-steps {
    grid-template-columns: 1fr;
  }

  .visual-steps b {
    width: 1px;
    height: 18px;
    justify-self: center;
  }

  .login-visual {
    min-height: 320px;
  }

  .login-visual h2 {
    font-size: 34px;
  }

  .audit-panel {
    margin: 0 18px 18px;
  }
}

@media (max-width: 560px) {
  .login-page {
    padding: 14px;
    justify-items: start;
  }

  .auth-stage {
    width: min(360px, calc(100vw - 28px));
    max-width: 100%;
  }

  .login-box,
  .login-visual {
    padding: 18px;
  }

  .side-nav,
  .command-bar,
  .metric-grid,
  .content-grid {
    padding-left: 14px;
    padding-right: 14px;
  }

  .page-title h2 {
    font-size: 18px;
  }

  .metric strong {
    font-size: 24px;
  }
}
