:root {
  --bg: #0d0f14;
  --bg-elevated: #151922;
  --bg-card: #1a1e28;
  --border: #2a3142;
  --text: #e6e9f0;
  --text-muted: #8b92a8;
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --success: #22c55e;
  --error: #ef4444;
  --radius: 10px;
  --font-sans: 'DM Sans', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
}

.screen {
  min-height: 100vh;
}

.screen.hidden {
  display: none !important;
}

.hidden {
  display: none !important;
}

/* ——— Login ——— */
#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(160deg, var(--bg) 0%, #12151c 50%, var(--bg-elevated) 100%);
}

.login-card {
  width: 100%;
  max-width: 400px;
  padding: 40px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.4);
}

.logo {
  text-align: center;
  margin-bottom: 32px;
}

.logo-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  font-size: 28px;
  color: var(--accent);
  margin-bottom: 16px;
}

.logo-icon.small {
  width: 32px;
  height: 32px;
  font-size: 18px;
  margin-right: 10px;
  margin-bottom: 0;
}

.logo h1 {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.logo p {
  margin: 4px 0 0;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.login-form .field {
  margin-bottom: 20px;
}

.login-form label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-muted);
}

.login-form input {
  width: 100%;
  padding: 12px 14px;
  font: inherit;
  font-size: 1rem;
  color: var(--text);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color 0.2s;
}

.login-form input:focus {
  outline: none;
  border-color: var(--accent);
}

.login-form .error {
  margin-bottom: 16px;
  font-size: 0.9rem;
  color: var(--error);
  min-height: 1.4em;
}

.login-form .btn {
  width: 100%;
  padding: 14px;
  font-size: 1rem;
  font-weight: 600;
  margin-top: 8px;
}

/* ——— Dashboard ——— */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.header-left {
  display: flex;
  align-items: center;
}

.header-left h1 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 600;
}

.user-email {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-right: 16px;
}

.main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px;
}

.section {
  margin-bottom: 40px;
}

.section h2 {
  margin: 0 0 16px;
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--text);
}

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

.section-head h2 {
  margin: 0;
}

.hint {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin: 0 0 16px;
}

.hint code {
  font-family: var(--font-mono);
  font-size: 0.8em;
  padding: 2px 6px;
  background: var(--bg-elevated);
  border-radius: 4px;
}

/* ——— Stats ——— */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 16px;
}

.stat-card {
  padding: 20px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.stat-card .label {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.stat-card .value {
  font-family: var(--font-mono);
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--text);
}

/* ——— Tables ——— */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
}

.table-scroll {
  max-height: 420px;
  overflow-y: auto;
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.table th,
.table td {
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.table th {
  font-weight: 600;
  color: var(--text-muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
  position: sticky;
  top: 0;
  background: var(--bg-card);
  z-index: 1;
}

.table tbody tr:hover {
  background: var(--bg-elevated);
}

.table td {
  vertical-align: middle;
}

.table .mono {
  font-family: var(--font-mono);
  font-size: 0.85em;
}

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

.search-input {
  padding: 10px 14px;
  font: inherit;
  font-size: 0.95rem;
  color: var(--text);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-width: 260px;
}

.search-input::placeholder {
  color: var(--text-muted);
}

.search-input:focus {
  outline: none;
  border-color: var(--accent);
}

.pagination-hint {
  margin-top: 8px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* ——— Config ——— */
.config-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}

.config-grid .field label {
  display: block;
  margin-bottom: 4px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.config-grid input {
  width: 100%;
  padding: 10px 12px;
  font: inherit;
  font-size: 0.95rem;
  color: var(--text);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.config-grid input:focus {
  outline: none;
  border-color: var(--accent);
}

.binary-payout-form .binary-payout-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 16px;
  margin-bottom: 12px;
}

.binary-payout-form .field {
  margin-bottom: 0;
}

.binary-payout-form .field label {
  display: block;
  margin-bottom: 4px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.binary-payout-form .field input,
.binary-payout-form .field select {
  padding: 10px 12px;
  font: inherit;
  font-size: 0.95rem;
  color: var(--text);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-width: 140px;
}

.binary-payout-form .field-actions {
  flex-shrink: 0;
}

.migrate-uid-form .migrate-uid-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 16px;
  margin-bottom: 12px;
}

.migrate-uid-form .field {
  margin-bottom: 0;
}

.migrate-uid-form .field input {
  min-width: 280px;
  font-family: var(--font-mono), monospace;
  font-size: 0.9rem;
}

.recreate-user-form .recreate-user-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 16px;
  margin-bottom: 12px;
}

.recreate-user-form .field {
  margin-bottom: 0;
}

.recreate-user-form .field input {
  min-width: 140px;
}

.recreate-user-form #recreate-uid {
  min-width: 280px;
  font-family: var(--font-mono), monospace;
  font-size: 0.9rem;
}

.message {
  font-size: 0.9rem;
  margin: 0;
}

.message.success {
  color: var(--success);
}

.message.error {
  color: var(--error);
}

/* ——— Buttons ——— */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 18px;
  font: inherit;
  font-weight: 500;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
}

.btn-ghost:hover {
  background: var(--bg-elevated);
  color: var(--text);
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.85rem;
}

/* ——— Modal ——— */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  cursor: pointer;
}

.modal-content {
  position: relative;
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.5);
}

.modal-content h2 {
  margin: 0 0 20px 0;
  font-size: 1.25rem;
  font-weight: 600;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 600;
}

.modal-close {
  padding: 8px 14px;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-muted);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  cursor: pointer;
  border-radius: var(--radius);
  font-family: var(--font-sans);
}

.modal-close:hover {
  color: var(--text);
  background: var(--border);
}

.modal-close:hover {
  background: var(--bg-elevated);
  color: var(--text);
}

.form-grid {
  display: grid;
  gap: 16px;
  margin-bottom: 24px;
}

.form-grid .field label {
  display: block;
  margin-bottom: 4px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.form-grid input,
.form-grid select {
  width: 100%;
  padding: 10px 12px;
  font: inherit;
  font-size: 0.95rem;
  color: var(--text);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.form-grid input:focus,
.form-grid select:focus {
  outline: none;
  border-color: var(--accent);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

/* ——— Loading ——— */
.loading {
  text-align: center;
  padding: 40px;
  color: var(--text-muted);
}

.spinner {
  display: inline-block;
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 12px;
}

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

/* ——— Network page (same style as app Network section) ——— */
.network-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.network-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: #1b5e20;
  color: #fff;
  elevation: 0;
}

.network-header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.network-back {
  color: rgba(255,255,255,0.9);
  text-decoration: none;
  font-size: 0.95rem;
  font-weight: 500;
}

.network-back:hover {
  color: #fff;
}

.network-header h1 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 600;
}

.btn-network-icon {
  background: transparent;
  color: #fff;
  border: none;
  padding: 8px 12px;
  font-size: 1.25rem;
  cursor: pointer;
  border-radius: 8px;
}

.btn-network-icon:hover {
  background: rgba(255,255,255,0.15);
}

.network-main {
  flex: 1;
  padding: 12px;
  background: linear-gradient(180deg, rgba(27,94,32,0.12) 0%, #f5f5f5 100%);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* Single white card (same as app) */
.network-card {
  flex: 1;
  min-height: 280px;
  display: flex;
  flex-direction: column;
  background: #fff;
  border-radius: 20px;
  box-shadow: 0 6px 24px rgba(0,0,0,0.08), 0 10px 32px rgba(27,94,32,0.05);
  overflow: hidden;
}

.network-card-top {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px 16px;
  padding: 16px 16px 0;
}

.network-root-label {
  font-size: 0.8rem;
  font-weight: 500;
  color: #757575;
  margin: 0;
}

.network-root-select {
  padding: 6px 10px;
  font-size: 0.9rem;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  background: #fff;
  color: #333;
  min-width: 200px;
}

.network-zoom-hint {
  margin: 0 0 0 auto;
  font-size: 0.8rem;
  color: #757575;
}

.network-card-body {
  flex: 1;
  padding: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 200px;
}

.network-empty {
  text-align: center;
  padding: 32px 24px;
}

.network-empty-icon {
  width: 72px;
  height: 72px;
  margin: 0 auto 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 48px;
  color: rgba(27,94,32,0.5);
}

.network-empty-title {
  margin: 0 0 8px;
  font-size: 1.25rem;
  font-weight: 600;
  color: #003300;
}

.network-empty-sub {
  margin: 0;
  font-size: 0.95rem;
  color: #757575;
}

.network-loading {
  text-align: center;
  padding: 40px;
  color: #757575;
}

.network-loading p {
  margin: 12px 0 0;
  font-size: 0.9rem;
}

.network-spinner {
  border-top-color: #1b5e20;
}

.network-tree-content {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.network-viewport {
  overflow: auto;
  padding: 0 8px 16px;
  max-height: 60vh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
}

.network-card-footer {
  padding: 12px 16px 20px;
  border-top: 1px solid #f0f0f0;
}

.network-assign-link {
  background: none;
  border: none;
  padding: 0;
  font-size: 0.9rem;
  color: #1b5e20;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
}

.network-assign-link:hover {
  text-decoration: underline;
}

/* Assign sheet (bottom sheet like app) */
.network-sheet {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  pointer-events: none;
}

.network-sheet:not(.hidden) {
  pointer-events: auto;
}

.network-sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.35);
  cursor: pointer;
}

.network-sheet-content {
  position: relative;
  width: 100%;
  max-width: 420px;
  max-height: 85vh;
  overflow-y: auto;
  background: #fff;
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -4px 24px rgba(0,0,0,0.15);
  padding: 24px 24px 32px;
}

.network-sheet-content h3 {
  margin: 0 0 8px;
  font-size: 1.2rem;
  font-weight: 600;
  color: #1a1e28;
}

.network-sheet-hint {
  margin: 0 0 20px;
  font-size: 0.9rem;
  color: #666;
}

.network-sheet-content .field {
  margin-bottom: 16px;
}

.network-sheet-content .field label {
  display: block;
  margin-bottom: 4px;
  font-size: 0.85rem;
  color: #555;
}

.network-sheet-content .field select {
  width: 100%;
  padding: 10px 12px;
  font-size: 0.95rem;
  border: 1px solid #ddd;
  border-radius: 10px;
  background: #fff;
}

.network-sheet-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid #eee;
}

.network-tree-inner {
  position: relative;
  flex-shrink: 0;
}

.app-tree-lines {
  position: absolute;
  left: 0;
  top: 0;
  pointer-events: none;
}

.app-tree-nodes {
  position: absolute;
  left: 0;
  top: 0;
  pointer-events: none;
}

.app-tree-node {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  pointer-events: auto;
  cursor: default;
}

.app-tree-node[data-uid] {
  cursor: pointer;
}

.app-tree-node .app-tree-avatar {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 700;
  font-size: 1.25rem;
  flex-shrink: 0;
  border: 1.5px solid transparent;
  box-shadow: 0 3px 6px rgba(0,0,0,0.15);
}

.app-tree-node.root .app-tree-avatar {
  width: 64px;
  height: 64px;
  font-size: 1.5rem;
  border-width: 2px;
}

.app-tree-node.active .app-tree-avatar {
  background: linear-gradient(135deg, #4caf50 0%, #1b5e20 100%);
  border-color: #003300;
}

.app-tree-node.root.active .app-tree-avatar {
  background: linear-gradient(135deg, rgba(27,94,32,0.95) 0%, #003300 100%);
}

.app-tree-node.inactive .app-tree-avatar {
  background: linear-gradient(135deg, #a5d6a7 0%, rgba(165,214,167,0.75) 100%);
  border-color: rgba(165,214,167,0.6);
}

.app-tree-node-empty .app-tree-avatar {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: #f5f5f5;
  border: 1.5px solid #e0e0e0;
  color: #bdbdbd;
  font-size: 1rem;
}

.app-tree-node .app-tree-name {
  margin-top: 6px;
  font-size: 0.75rem;
  font-weight: 600;
  color: #424242;
  text-align: center;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.app-tree-node .app-tree-uniqueid {
  margin-top: 2px;
  font-size: 0.65rem;
  font-family: var(--font-mono);
  color: #666;
  text-align: center;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.app-tree-node .app-tree-pkg {
  margin-top: 2px;
  font-size: 0.65rem;
  color: #1b5e20;
  font-weight: 500;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.btn-network-primary {
  background: #1b5e20;
  color: #fff;
  border: none;
  padding: 10px 18px;
  border-radius: 10px;
  font-weight: 500;
  cursor: pointer;
}

.btn-network-primary:hover {
  background: #2e7d32;
}

.network-message {
  font-size: 0.9rem;
  margin: 0;
}

.network-message.success {
  color: #22c55e;
}

.network-message.error {
  color: #ef4444;
}

.header-link {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.95rem;
  font-weight: 500;
  margin-left: 20px;
}

.header-link:hover {
  color: var(--text);
}

/* Network user info panel (existing info, like app bottom sheet) */
.network-user-info-panel {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  pointer-events: none;
}

.network-user-info-panel:not(.hidden) {
  pointer-events: auto;
}

.network-user-info-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.35);
  cursor: pointer;
}

.network-user-info-content {
  position: relative;
  width: 100%;
  max-width: 420px;
  max-height: 85vh;
  overflow-y: auto;
  background: #fff;
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -4px 24px rgba(0,0,0,0.15);
  padding: 24px 24px 32px;
}

.network-user-info-content h3 {
  margin: 0 0 16px 0;
  font-size: 1.2rem;
  font-weight: 600;
  color: #1a1e28;
}

.network-user-info-content dl {
  margin: 0 0 20px 0;
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 8px 16px;
  font-size: 0.9rem;
}

.network-user-info-content dt {
  margin: 0;
  font-weight: 500;
  color: #666;
}

.network-user-info-content dd {
  margin: 0;
  color: #333;
  word-break: break-word;
}

.network-user-info-content dd.mono {
  font-family: var(--font-mono);
  font-size: 0.85em;
}

.btn-network-ghost {
  background: #f5f5f5;
  color: #333;
  border: 1px solid #e0e0e0;
  padding: 10px 18px;
  border-radius: 10px;
  font-weight: 500;
  cursor: pointer;
}

.btn-network-ghost:hover {
  background: #eee;
}
