:root {
  --bg-canvas: #f4f6f8;
  --bg-surface: #ffffff;
  --bg-subtle: #f8fafc;
  --bg-rail: #111b27;
  --bg-rail-active: #1b2b3f;
  --border: #dce2e8;
  --border-strong: #c5cfd9;
  --ink: #0f172a;
  --ink-muted: #526071;
  --ink-rail: #cbd5e1;
  --ink-rail-muted: #7c8ea3;
  --primary: #0f6cbd;
  --primary-hover: #0d5ca3;
  --primary-soft: #e8f2fc;
  --ok: #15803d;
  --ok-soft: #dcfce7;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --danger: #b91c1c;
  --danger-hover: #991b1b;
  --danger-soft: #fee2e2;
  --neutral-soft: #eef2f6;
  --font-sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Monaco, Consolas, monospace;
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 10px;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg-canvas);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.mono {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.num {
  font-variant-numeric: tabular-nums;
}

/* Focus visibility */
button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* Login shell */
.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 32px 28px;
}

.brand-mark {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 18px;
}

.brand-mark svg {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
}

.brand-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--ink);
  letter-spacing: -0.01em;
}

.login-subtitle {
  margin: 0 0 22px;
  color: var(--ink-muted);
  font-size: 13px;
}

/* App shell */
.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 236px minmax(0, 1fr);
}

.rail {
  background: var(--bg-rail);
  color: var(--ink-rail);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 20px 14px;
  border-right: 1px solid #0b131d;
  position: sticky;
  top: 0;
  height: 100vh;
}

.rail-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  margin-bottom: 16px;
}

.rail-brand svg,
.mobile-topbar svg {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
}

.rail-brand-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.rail-brand-name {
  font-size: 15px;
  font-weight: 600;
  color: #ffffff;
}

.rail-brand-sub {
  font-size: 12px;
  color: var(--ink-rail-muted);
}

.rail-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 11px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--ink-rail);
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  transition: background-color 0.12s ease, color 0.12s ease;
}

.nav-item:hover {
  background: rgba(255, 255, 255, 0.06);
  color: #ffffff;
}

.nav-item.active {
  background: var(--bg-rail-active);
  color: #ffffff;
  box-shadow: inset 3px 0 0 #38bdf8;
}

.nav-item svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  opacity: 0.85;
}

.rail-footer {
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  padding-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.user-chip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 0 6px;
}

.user-chip-name {
  font-size: 13px;
  font-weight: 600;
  color: #ffffff;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.role-pill {
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(56, 189, 248, 0.16);
  color: #7dd3fc;
  flex-shrink: 0;
}

.rail-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.rail-btn {
  padding: 6px 8px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--ink-rail);
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
}

.rail-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #ffffff;
}

.mobile-topbar {
  display: none;
}

/* Main content */
.main-pane {
  padding: 24px 28px 40px;
  max-width: 1240px;
  width: 100%;
  min-width: 0;
  margin: 0 auto;
}

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

.page-title {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.page-desc {
  margin: 3px 0 0;
  font-size: 13px;
  color: var(--ink-muted);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* Summary Strip */
.summary-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin-bottom: 16px;
  overflow: hidden;
}

.summary-cell {
  padding: 14px 18px;
  border-right: 1px solid var(--border);
  min-width: 0;
}

.summary-cell:last-child {
  border-right: 0;
}

.summary-label {
  font-size: 12px;
  color: var(--ink-muted);
  margin-bottom: 4px;
}

.summary-value {
  font-size: 22px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  display: flex;
  align-items: center;
  gap: 8px;
}

.summary-url {
  font-size: 13px;
  font-weight: 500;
  font-family: var(--font-mono);
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Surfaces & Tables */
.surface {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.surface + .surface {
  margin-top: 16px;
}

.surface-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.surface-title {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-subtle);
  flex-wrap: wrap;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}

th {
  padding: 10px 14px;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-muted);
  background: var(--bg-subtle);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  font-size: 13.5px;
}

tr:last-child td {
  border-bottom: 0;
}

tbody tr:hover {
  background: #fafcfe;
}

.cell-main {
  font-weight: 600;
  color: var(--ink);
}

.cell-sub {
  font-size: 12px;
  color: var(--ink-muted);
  margin-top: 2px;
}

.link-btn {
  border: 0;
  background: transparent;
  padding: 0;
  color: var(--primary);
  font-family: inherit;
  font-size: inherit;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
}

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

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}

.badge-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.badge-ok {
  background: var(--ok-soft);
  color: var(--ok);
}

.badge-warn {
  background: var(--warn-soft);
  color: var(--warn);
}

.badge-danger {
  background: var(--danger-soft);
  color: var(--danger);
}

.badge-neutral {
  background: var(--neutral-soft);
  color: var(--ink-muted);
}

.badge-info {
  background: var(--primary-soft);
  color: var(--primary);
}

.member-list {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.member-tag {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 4px;
  background: var(--neutral-soft);
  color: var(--ink);
  font-size: 12px;
}

/* Controls & Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 13px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--bg-surface);
  color: var(--ink);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 0.12s ease, border-color 0.12s ease;
}

.btn:hover:not(:disabled) {
  background: var(--bg-subtle);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
}

.btn-danger {
  background: var(--bg-surface);
  border-color: #fecaca;
  color: var(--danger);
}

.btn-danger:hover:not(:disabled) {
  background: var(--danger-soft);
}

.btn-danger-solid {
  background: var(--danger);
  border-color: var(--danger);
  color: #ffffff;
}

.btn-danger-solid:hover:not(:disabled) {
  background: var(--danger-hover);
}

.btn-sm {
  padding: 4px 9px;
  font-size: 12px;
}

.btn-row {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

/* Form Elements */
.field {
  margin-bottom: 14px;
}

.field label {
  display: block;
  margin-bottom: 5px;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink);
}

.field-hint {
  margin-top: 4px;
  font-size: 12px;
  color: var(--ink-muted);
}

.input,
.select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  color: var(--ink);
  font-family: inherit;
  font-size: 13.5px;
}

.toolbar .input {
  width: auto;
  min-width: 240px;
  max-width: 100%;
  padding: 6px 10px;
  font-size: 13px;
}

.toolbar .select {
  width: auto;
  min-width: 150px;
  max-width: 100%;
  padding: 6px 10px;
  font-size: 13px;
}

.checkbox-list {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  max-height: 150px;
  overflow-y: auto;
  padding: 6px 10px;
  background: var(--bg-subtle);
}

.checkbox-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  font-size: 13px;
  cursor: pointer;
}

/* Alerts & Code Blocks */
.alert {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin-bottom: 14px;
  border: 1px solid transparent;
}

.alert-error {
  background: var(--danger-soft);
  border-color: #fecaca;
  color: var(--danger);
}

.alert-warn {
  background: var(--warn-soft);
  border-color: #fde68a;
  color: #92400e;
}

.code-box {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #f8fafc;
  padding: 10px 12px;
  margin-bottom: 12px;
}

.code-box-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-muted);
}

.code-box pre {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-all;
  color: var(--ink);
}

/* Meta strip on node detail */
.meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-subtle);
}

.meta-item-label {
  font-size: 12px;
  color: var(--ink-muted);
}

.meta-item-val {
  font-size: 13.5px;
  font-weight: 500;
  margin-top: 2px;
}

/* Empty State */
.empty-state {
  padding: 36px 20px;
  text-align: center;
  color: var(--ink-muted);
}

.empty-state p {
  margin: 0 0 12px;
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.48);
  display: grid;
  place-items: center;
  padding: 16px;
  z-index: 100;
}

.modal-card {
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px 24px;
}

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

.modal-title {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
}

.modal-foot {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

/* Pagination */
.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  font-size: 13px;
  color: var(--ink-muted);
}

/* Toast */
.toast-stack {
  position: fixed;
  right: 20px;
  bottom: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 200;
}

.toast {
  background: #0f172a;
  color: #ffffff;
  padding: 9px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.toast.error {
  background: var(--danger);
}

/* Responsive */
@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: minmax(0, 1fr);
  }

  .rail {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: 236px;
    z-index: 90;
    transform: translateX(-100%);
    transition: transform 0.16s ease;
  }

  .rail.open {
    transform: translateX(0);
  }

  .mobile-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    position: sticky;
    top: 0;
    z-index: 80;
    padding: 12px 16px;
    background: var(--bg-rail);
    color: #ffffff;
    border-bottom: 1px solid #0b131d;
  }

  .toolbar .input,
  .toolbar .select {
    width: 100%;
    min-width: 0;
  }

  .main-pane {
    padding: 16px 14px 32px;
  }

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

  .summary-cell:nth-child(2) {
    border-right: 0;
  }

  .summary-cell:nth-child(1),
  .summary-cell:nth-child(2) {
    border-bottom: 1px solid var(--border);
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
  }
}
