:root {
  --bg: #f6f8fb;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --line: #e4eaf2;
  --line-strong: #cbd6e4;
  --text: #172033;
  --muted: #68758a;
  --blue: #2563eb;
  --blue-soft: #eaf1ff;
  --cyan: #2563eb;
  --green: #0f9f6e;
  --green-soft: #eafaf3;
  --amber: #b7791f;
  --amber-soft: #fff7df;
  --red: #d63c3c;
  --red-soft: #fff0f0;
  --shadow: 0 18px 45px rgba(20, 35, 62, 0.08);
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

a {
  color: inherit;
  text-decoration: none;
}

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

button {
  cursor: pointer;
}

.console-grid {
  display: none;
}

.sidebar {
  position: fixed;
  inset: 16px auto 16px 16px;
  width: 260px;
  display: flex;
  flex-direction: column;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.sidebar-title {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 12px;
  min-height: 58px;
  margin-bottom: 18px;
  padding: 0 2px 16px;
  border-bottom: 1px solid var(--line);
}

.sidebar-title span,
.sidebar-footer,
.eyebrow,
.panel-head span,
.code-card p,
small {
  color: var(--muted);
}

.sidebar-title strong {
  display: block;
  color: var(--text);
  font-size: 20px;
  line-height: 1.1;
}

.sidebar-title span {
  display: block;
  margin-top: 2px;
  font-size: 12px;
}

.sidebar nav {
  display: grid;
  gap: 8px;
}

.sidebar nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  padding: 0 10px;
  border: 1px solid transparent;
  border-radius: 8px;
  color: #364157;
}

.sidebar nav a:hover,
.sidebar nav a.active {
  border-color: #bfd0ea;
  background: var(--blue-soft);
  color: var(--blue);
}

.nav-icon {
  display: grid;
  place-items: center;
  width: 38px;
  height: 26px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  color: var(--blue);
  font-size: 11px;
}

.sidebar-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: auto;
  padding-top: 18px;
  font-size: 13px;
}

.pulse {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 5px rgba(15, 159, 110, 0.12);
}

.main {
  width: min(1480px, calc(100% - 308px));
  margin-left: 292px;
  padding: 18px 18px 48px 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 76px;
  margin-bottom: 18px;
  padding: 0 4px;
}

.topbar h1,
.hero-band h2,
.detail-hero h2,
.login-panel h1,
.scan-panel h1 {
  margin: 0;
  font-size: clamp(28px, 4vw, 48px);
  line-height: 1.06;
}

.topbar h1 {
  font-size: 30px;
}

.eyebrow {
  margin: 0 0 8px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.top-actions,
.button-row,
.form-actions,
.card-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.primary-button,
.ghost-button,
.text-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 0 14px;
  border-radius: 8px;
  border: 1px solid var(--line-strong);
  color: var(--text);
  background: #ffffff;
}

.primary-button {
  border-color: var(--blue);
  background: var(--blue);
  color: #ffffff;
  box-shadow: 0 10px 22px rgba(37, 99, 235, 0.18);
}

.ghost-button:hover,
.text-button:hover {
  border-color: #adc3e7;
  background: var(--blue-soft);
}

.ghost-button:disabled,
.text-button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.text-button.danger {
  border-color: #f2b4b4;
  color: var(--red);
}

.ghost-button.danger {
  border-color: #f2b4b4;
  color: var(--red);
}

.hero-band,
.detail-hero,
.reserved-band,
.toolbar-panel,
.panel,
.code-card,
.empty-state,
.login-panel,
.scan-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.hero-band,
.detail-hero,
.reserved-band,
.toolbar-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 22px;
  margin-bottom: 16px;
}

.hero-band {
  border-color: #cfe0f7;
  background: var(--surface);
}

.hero-band p,
.detail-hero p,
.reserved-band p {
  max-width: 760px;
  margin: 10px 0 0;
  color: var(--muted);
}

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

.metric-card {
  min-height: 132px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.metric-card span,
.metric-card small {
  display: block;
  color: var(--muted);
}

.metric-card strong {
  display: block;
  margin: 14px 0 8px;
  color: var(--blue);
  font-size: 38px;
}

.dashboard-grid,
.detail-grid,
.domain-grid,
.settings-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.panel {
  min-width: 0;
  padding: 18px;
}

.panel.wide {
  grid-column: span 2;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.panel-head h2,
.code-card h2,
.form-section h2 {
  margin: 0;
  font-size: 18px;
}

.bars {
  display: grid;
  grid-template-columns: repeat(14, minmax(18px, 1fr));
  align-items: end;
  gap: 8px;
  height: 260px;
  padding-top: 8px;
}

.bar-wrap {
  display: grid;
  grid-template-rows: 1fr auto;
  gap: 8px;
  height: 100%;
}

.bar-wrap span {
  align-self: end;
  min-height: 5px;
  border-radius: 6px 6px 2px 2px;
  background: var(--blue);
}

.bar-wrap small {
  text-align: center;
  font-size: 11px;
}

.health-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.health-grid div {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.health-grid b {
  display: block;
  font-size: 28px;
  color: var(--green);
}

.attention-list,
.stack-list {
  display: grid;
  gap: 10px;
  margin: 14px 0 0;
  padding: 0;
  list-style: none;
}

.attention-list li,
.stack-list a,
.domain-row,
.target-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.stack-list span,
.target-row small,
.domain-row small,
td small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
}

.table-wrap {
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}

th,
td {
  padding: 12px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-weight: 700;
  background: #fbfdff;
}

.mono {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 12px;
}

.code-list {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.code-card {
  min-height: 248px;
  padding: 18px;
}

.code-card-head {
  display: flex;
  justify-content: space-between;
  gap: 14px;
}

.code-meta {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin: 18px 0;
}

.code-meta span {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--muted);
}

.code-meta b {
  display: block;
  margin-top: 4px;
  color: var(--text);
}

.tag-row,
.reserved-list {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.tag-row span,
.reserved-list span,
.status {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 9px;
  border: 1px solid #bfe8d7;
  border-radius: 999px;
  background: var(--green-soft);
  color: var(--green);
  font-size: 12px;
  font-weight: 700;
}

.status.paused,
.status.pending {
  border-color: #f0d18d;
  background: var(--amber-soft);
  color: var(--amber);
}

.status.archived,
.status.error {
  border-color: #f2b4b4;
  background: var(--red-soft);
  color: var(--red);
}

.status-actions {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.status-actions .text-button {
  min-height: 30px;
  padding: 0 10px;
  font-size: 12px;
}

.form-shell,
.settings-grid {
  max-width: 1180px;
}

.entity-form,
.compact-form,
.filters {
  display: grid;
  gap: 14px;
}

.compact-form {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.compact-form .full,
.compact-form button {
  grid-column: 1 / -1;
}

.form-divider {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-top: 4px;
  border-top: 1px solid var(--line);
  color: var(--text);
  font-size: 14px;
}

.form-divider span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}

.settings-strip {
  display: grid;
  grid-template-columns: minmax(180px, 0.9fr) minmax(220px, 1.4fr) auto;
  align-items: center;
  gap: 14px;
  padding: 14px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.settings-strip .ghost-button {
  grid-column: auto;
  white-space: nowrap;
}

.settings-strip b,
.modal-head h2 {
  color: var(--text);
}

.settings-strip span,
.safe-mini-preview small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}

.safe-mini-preview {
  min-width: 0;
}

.safe-mini-preview strong,
.safe-mini-preview small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.safe-mini-preview strong {
  display: block;
  line-height: 1.18;
}

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

.field-grid .full {
  grid-column: 1 / -1;
}

.form-section {
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

input,
select,
textarea {
  width: 100%;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  outline: none;
  background: #ffffff;
  color: var(--text);
}

input[type="color"] {
  min-height: 42px;
  padding: 4px;
}

textarea {
  padding-top: 10px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.check-line {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 42px;
}

.check-line input {
  width: 18px;
  min-height: 18px;
}

.form-error {
  min-height: 20px;
  color: var(--red);
}

.modal {
  width: min(92vw, 760px);
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
}

.modal::backdrop {
  background: rgba(15, 23, 42, 0.36);
  backdrop-filter: blur(6px);
}

.modal-card {
  display: grid;
  gap: 18px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 26px 70px rgba(20, 35, 62, 0.22);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.modal-head h2 {
  margin: 0;
  font-size: 22px;
}

.detail-stats {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.detail-stats span {
  min-width: 112px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--muted);
}

.detail-stats b {
  display: block;
  color: var(--blue);
  font-size: 24px;
}

#qr-canvas {
  display: block;
  width: 220px;
  height: 220px;
  margin: 0 auto 14px;
  border: 10px solid #ffffff;
  border-radius: 8px;
  box-shadow: 0 10px 24px rgba(20, 35, 62, 0.12);
}

.qr-link {
  overflow-wrap: anywhere;
  color: var(--muted);
}

.warning-box {
  padding: 14px;
  border: 1px solid #f0d18d;
  border-radius: 8px;
  color: var(--amber);
  background: var(--amber-soft);
}

.target-list,
.domain-list {
  display: grid;
  gap: 10px;
}

.target-actions,
.target-form-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.target-form-actions {
  grid-column: 1 / -1;
}

.add-target {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.empty-state {
  padding: 30px;
  text-align: center;
}

.login-body,
.scan-body,
.gateway-body {
  display: grid;
  place-items: center;
  min-height: 100vh;
  background: var(--bg);
}

.login-stage {
  width: min(94vw, 460px);
}

.login-panel,
.scan-panel {
  position: relative;
  overflow: hidden;
  padding: 34px;
}

.login-copy,
.scan-panel p {
  color: var(--muted);
}

.login-form,
.scan-form {
  display: grid;
  gap: 14px;
  margin-top: 22px;
}

.scan-panel,
.gateway-panel {
  width: min(92vw, 520px);
  text-align: center;
}

.gateway-panel {
  padding: 30px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.gateway-panel h1 {
  margin: 0 0 16px;
  font-size: 26px;
}

.gateway-image-wrap {
  display: grid;
  place-items: center;
  width: min(420px, 100%);
  min-height: 280px;
  margin: 18px auto;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.gateway-image-wrap img {
  display: block;
  max-width: 100%;
  max-height: 68vh;
  border-radius: 6px;
}

.gateway-loader {
  width: 42px;
  height: 42px;
  margin: 24px auto;
  border: 4px solid var(--line);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.scan-beam {
  display: block;
  width: 80px;
  height: 3px;
  margin: 0 auto 22px;
  border-radius: 999px;
  background: var(--blue);
}

@media (max-width: 1180px) {
  .metrics,
  .code-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .dashboard-grid,
  .detail-grid,
  .domain-grid,
  .settings-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 860px) {
  .sidebar {
    position: static;
    width: auto;
    margin: 10px;
  }

  .sidebar nav {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .main {
    width: auto;
    margin: 0;
    padding: 10px;
  }

  .topbar,
  .hero-band,
  .detail-hero,
  .reserved-band,
  .toolbar-panel {
    align-items: stretch;
    flex-direction: column;
  }

  .metrics,
  .code-list,
  .dashboard-grid,
  .detail-grid,
  .domain-grid,
  .settings-grid,
  .field-grid,
  .compact-form {
    grid-template-columns: 1fr;
  }

  .panel.wide {
    grid-column: auto;
  }

  .settings-strip {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .settings-strip .ghost-button {
    width: 100%;
  }

  .bars {
    grid-template-columns: repeat(7, minmax(22px, 1fr));
    height: 220px;
  }
}
