:root {
  color-scheme: dark;
  --bg: #07111f;
  --bg-soft: #0d1829;
  --panel: rgba(12, 21, 36, 0.92);
  --panel-strong: #132238;
  --line: rgba(148, 163, 184, 0.18);
  --line-strong: rgba(94, 234, 212, 0.24);
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #3dd5b7;
  --accent-strong: #14b8a6;
  --danger: #fb7185;
  --warning: #fbbf24;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Segoe UI", "Microsoft YaHei", sans-serif;
  background:
    radial-gradient(circle at top left, rgba(45, 212, 191, 0.12), transparent 30%),
    radial-gradient(circle at top right, rgba(34, 197, 94, 0.12), transparent 28%),
    linear-gradient(180deg, #07111f 0%, #030712 100%);
  color: var(--text);
}

body.auth-login-mode {
  display: grid;
  place-items: center;
  padding: 32px;
}

body.modal-open {
  overflow: hidden;
}

.hidden {
  display: none !important;
}

.login-shell {
  width: min(980px, 100%);
}

.login-card {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(320px, 420px);
  gap: 28px;
  padding: 32px;
  border: 1px solid var(--line);
  border-radius: 28px;
  background: rgba(7, 17, 31, 0.86);
  box-shadow: 0 32px 80px rgba(2, 6, 23, 0.42);
  backdrop-filter: blur(18px);
}

.login-copy {
  display: grid;
  gap: 12px;
  align-content: center;
}

.login-copy h1 {
  margin: 0;
  font-size: clamp(30px, 4vw, 44px);
}

.login-copy p {
  margin: 0;
  max-width: 52ch;
  color: var(--muted);
  line-height: 1.7;
}

.eyebrow {
  display: inline-flex;
  width: fit-content;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(61, 213, 183, 0.14);
  color: #9ef3df;
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.login-form,
.form-grid,
.stack-grid {
  display: grid;
  gap: 14px;
}

.login-form {
  padding: 24px;
  border-radius: 24px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(19, 34, 56, 0.98), rgba(10, 19, 34, 0.92));
}

.field {
  display: grid;
  gap: 8px;
}

.field span,
.panel-title p,
.muted,
.message,
.meta-line {
  color: var(--muted);
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid rgba(148, 163, 184, 0.2);
  border-radius: 14px;
  background: rgba(15, 23, 42, 0.75);
  color: var(--text);
  padding: 12px 14px;
  font: inherit;
}

textarea {
  min-height: 120px;
  resize: vertical;
}

input:focus,
textarea:focus,
select:focus {
  outline: 0;
  border-color: var(--line-strong);
  box-shadow: 0 0 0 3px rgba(20, 184, 166, 0.18);
}

.workspace-shell {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 20px 12px;
  border-right: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(4, 12, 24, 0.96), rgba(7, 17, 31, 0.92));
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand {
  display: grid;
  gap: 2px;
  margin-bottom: 12px;
  padding: 0 8px;
}

.brand strong {
  font-size: 18px;
}

.brand span {
  font-size: 11px;
  color: var(--muted);
}

.nav-groups {
  display: grid;
  gap: 4px;
  align-content: start;
  flex: 1;
}

.nav-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: #94a3b8;
  padding: 10px 12px;
  text-align: left;
  cursor: pointer;
  font-size: 14px;
  transition: all 0.15s ease;
}

.nav-item:hover {
  color: #e2e8f0;
  background: rgba(148, 163, 184, 0.08);
}

.nav-item.active {
  color: #a7f3d0;
  border-color: rgba(61, 213, 183, 0.22);
  background: rgba(14, 116, 144, 0.14);
}

.nav-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  opacity: 0.7;
}

.nav-item.active .nav-icon {
  opacity: 1;
  color: var(--accent);
}

.nav-label {
  flex: 1;
  white-space: nowrap;
}

.sidebar-logout {
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

/* ── Tab bar (page-level sub-navigation) ── */

.tab-bar {
  display: flex;
  gap: 2px;
  padding: 4px;
  border-radius: 12px;
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid var(--line);
  margin-bottom: 18px;
  overflow-x: auto;
}

.tab-bar-item {
  padding: 8px 16px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s ease;
}

.tab-bar-item:hover {
  color: var(--text);
  background: rgba(148, 163, 184, 0.1);
}

.tab-bar-item.active {
  color: #a7f3d0;
  background: rgba(20, 184, 166, 0.15);
}

.workspace {
  padding: 28px;
}

.workspace-header {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: flex-start;
  margin-bottom: 22px;
}

.workspace-header h1 {
  margin: 0;
  font-size: 30px;
}

.workspace-header p {
  margin: 8px 0 0;
  color: var(--muted);
}

.session-badge {
  padding: 10px 14px;
  border-radius: 999px;
  background: rgba(61, 213, 183, 0.12);
  color: #a7f3d0;
  white-space: nowrap;
}

.flash {
  margin-bottom: 18px;
  padding: 14px 16px;
  border-radius: 16px;
  border: 1px solid rgba(61, 213, 183, 0.24);
  background: rgba(15, 23, 42, 0.72);
}

.flash.error {
  border-color: rgba(251, 113, 133, 0.28);
  color: #fecdd3;
}

.view-host {
  display: grid;
  gap: 18px;
}

.panel,
.metric-card,
.table-panel,
.editor-panel,
.placeholder-card,
.modal-card {
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--panel);
  box-shadow: 0 18px 50px rgba(2, 6, 23, 0.26);
}

.panel,
.table-panel,
.editor-panel,
.placeholder-card,
.modal-card {
  padding: 20px;
}

.metrics-grid,
.split-layout,
.triple-layout,
.form-columns,
.toolbar-row,
.summary-grid {
  display: grid;
  gap: 18px;
}

.metrics-grid {
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.metric-card {
  padding: 18px;
}

.metric-card strong {
  display: block;
  margin-top: 10px;
  font-size: 34px;
}

.metric-card small {
  display: block;
  margin-top: 10px;
  color: var(--muted);
}

.split-layout {
  grid-template-columns: minmax(0, 1.2fr) minmax(320px, 0.8fr);
}

.triple-layout {
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 1.1fr) minmax(320px, 0.8fr);
}

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

.panel-header,
.toolbar-row,
.action-row,
.status-row,
.tab-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.panel-header,
.toolbar-row {
  justify-content: space-between;
}

.panel-title h2,
.panel-title h3 {
  margin: 0;
}

.panel-title p {
  margin: 6px 0 0;
}

.primary-btn,
.ghost-btn,
.danger-btn,
.tab-btn {
  border: 1px solid transparent;
  border-radius: 14px;
  padding: 10px 14px;
  font: inherit;
  cursor: pointer;
}

.primary-btn {
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-strong) 100%);
  color: #022c22;
  font-weight: 700;
}

.ghost-btn,
.tab-btn {
  background: rgba(15, 23, 42, 0.88);
  border-color: rgba(148, 163, 184, 0.18);
  color: var(--text);
}

.danger-btn {
  background: rgba(127, 29, 29, 0.4);
  border-color: rgba(251, 113, 133, 0.28);
  color: #fecdd3;
}

.tab-btn.active {
  border-color: rgba(61, 213, 183, 0.28);
  background: rgba(13, 148, 136, 0.18);
}

.shop-shell {
  display: grid;
  gap: 18px;
}

.shop-main-layout {
  display: grid;
  gap: 18px;
  grid-template-columns: minmax(240px, 0.62fr) minmax(0, 1.45fr) minmax(320px, 0.9fr);
}

.shop-runtime-panel {
  padding-bottom: 16px;
}

.shop-runtime-stats {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.shop-runtime-billboard {
  max-height: 92px;
  overflow: auto;
}

.shop-family-tabs {
  margin-bottom: 4px;
}

.shop-family-btn {
  min-width: 92px;
  justify-content: center;
}

.shop-category-tabs {
  align-items: stretch;
}

.shop-tab-btn {
  min-width: 180px;
  display: grid;
  gap: 4px;
  justify-items: start;
  text-align: left;
}

.shop-tab-title {
  font-weight: 700;
}

.shop-tab-meta {
  font-size: 12px;
  color: var(--muted);
}

.shop-category-cell {
  min-width: 180px;
}

.shop-category-cell strong,
.shop-selected-meta strong {
  display: block;
  font-size: 14px;
}

.shop-category-cell span,
.shop-selected-meta span {
  color: var(--muted);
  font-size: 12px;
}

.shop-selected-meta {
  padding: 14px;
  border-radius: 18px;
  border: 1px solid rgba(148, 163, 184, 0.12);
  background: rgba(15, 23, 42, 0.56);
}

.shop-item-row {
  cursor: pointer;
}

.shop-item-row td:last-child {
  position: sticky;
  right: 0;
  background: inherit;
}

.table-wrap {
  overflow: auto;
  border-radius: 18px;
  border: 1px solid rgba(148, 163, 184, 0.12);
}

.data-table {
  width: 100%;
  min-width: 860px;
  border-collapse: collapse;
}

.data-table th,
.data-table td {
  padding: 12px 14px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.1);
  text-align: left;
  white-space: nowrap;
}

.data-table thead th {
  position: sticky;
  top: 0;
  background: rgba(10, 19, 34, 0.98);
  font-size: 13px;
  color: #cbd5e1;
}

.data-table tbody tr:hover {
  background: rgba(20, 184, 166, 0.08);
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  background: rgba(61, 213, 183, 0.12);
  color: #8ef0d8;
}

.badge.warn {
  background: rgba(251, 191, 36, 0.14);
  color: #fde68a;
}

.badge.danger {
  background: rgba(251, 113, 133, 0.16);
  color: #fecdd3;
}

.badge.muted {
  background: rgba(148, 163, 184, 0.12);
  color: #94a3b8;
}

.warn-btn {
  padding: 4px 12px;
  border: 1px solid rgba(251, 191, 36, 0.5);
  border-radius: 6px;
  background: rgba(251, 191, 36, 0.12);
  color: #fde68a;
  cursor: pointer;
  font-size: 12px;
}
.warn-btn:hover { background: rgba(251, 191, 36, 0.25); }

.inline-form {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.inline-form input,
.inline-form select {
  width: auto;
  min-width: 180px;
}

.placeholder-card h2 {
  margin-top: 0;
}

.placeholder-card p {
  margin-bottom: 0;
  line-height: 1.7;
}

.storage-grid {
  display: grid;
  gap: 14px;
}

.storage-card {
  padding: 14px;
  border-radius: 18px;
  border: 1px solid rgba(148, 163, 184, 0.14);
  background: rgba(15, 23, 42, 0.5);
}

.storage-card h4 {
  margin: 0 0 10px;
}

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

.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(3, 7, 18, 0.72);
  backdrop-filter: blur(8px);
  z-index: 50;
}

.modal-card {
  width: min(520px, calc(100vw - 48px));
}

.modal-card.modal-card-wide {
  width: min(780px, calc(100vw - 48px));
  max-height: calc(100vh - 48px);
  overflow-y: auto;
}

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

.readonly {
  opacity: 0.78;
}

.editor-sticky {
  position: sticky;
  top: 0;
}

.message.error {
  color: #fecdd3;
}

.checkbox-line {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.checkbox-line input {
  width: auto;
}

.field.compact {
  padding-top: 12px;
}

.entity-list {
  display: grid;
  gap: 12px;
}

.entity-row {
  width: 100%;
  display: grid;
  gap: 4px;
  border: 1px solid rgba(148, 163, 184, 0.16);
  border-radius: 16px;
  background: rgba(15, 23, 42, 0.62);
  color: var(--text);
  padding: 14px;
  text-align: left;
  cursor: pointer;
}

.entity-row strong {
  font-size: 15px;
}

.entity-row span {
  color: var(--muted);
  font-size: 13px;
}

.entity-row.active,
.entity-row:hover {
  border-color: rgba(61, 213, 183, 0.28);
  background: rgba(13, 148, 136, 0.14);
}

.table-actions {
  display: flex;
  gap: 8px;
}

.table-actions button {
  white-space: nowrap;
}

.empty-state {
  padding: 20px;
  border: 1px dashed rgba(148, 163, 184, 0.18);
  border-radius: 18px;
  color: var(--muted);
}

.summary-grid.two-col {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.row-selected {
  background: rgba(20, 184, 166, 0.12);
}

.code-block {
  padding: 14px;
  border-radius: 18px;
  border: 1px solid rgba(148, 163, 184, 0.12);
  background: rgba(15, 23, 42, 0.56);
  color: #cbd5e1;
  white-space: pre-wrap;
  word-break: break-word;
}

.world-row {
  display: grid;
  gap: 14px;
  padding: 16px;
  border-radius: 18px;
  border: 1px solid rgba(148, 163, 184, 0.14);
  background: rgba(15, 23, 42, 0.42);
}

.world-remove {
  width: fit-content;
}

@media (max-width: 1320px) {
  .split-layout,
  .triple-layout,
  .shop-main-layout,
  .shop-runtime-stats,
  .form-columns,
  .workspace-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    flex-direction: row;
    flex-wrap: wrap;
    overflow-y: visible;
  }

  .nav-groups {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
  }

  .sidebar-logout {
    margin-top: 0;
    border-top: 0;
  }

  .tab-bar {
    flex-wrap: wrap;
  }
}

@media (max-width: 920px) {
  body.auth-login-mode {
    padding: 16px;
  }

  .login-card,
  .storage-fields {
    grid-template-columns: 1fr;
  }

  .workspace {
    padding: 18px;
  }

  .workspace-header {
    flex-direction: column;
  }
}
