:root {
  --bg: #0a0a0f;
  --panel: #14141c;
  --card: #1b1b26;
  --border: #2a2a38;
  --gold: #d4a537;
  --teal: #2ec4b6;
  --text: #f2f2f5;
  --text-dim: #9a9aa8;
  --danger: #e05260;
  --radius: 14px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.hidden { display: none !important; }

/* ---------- AUTH ---------- */
#auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 24px;
}

.logo {
  text-align: center;
  font-size: 24px;
  margin: 0 0 20px;
}
.logo span { color: var(--gold); }

.tabs { display: flex; gap: 8px; margin-bottom: 20px; }
.tab-btn {
  flex: 1;
  padding: 10px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 10px;
  cursor: pointer;
  font-weight: 600;
}
.tab-btn.active { background: var(--teal); color: #06231f; border-color: var(--teal); }

.auth-form { display: flex; flex-direction: column; gap: 6px; }
.auth-form label { font-size: 13px; color: var(--text-dim); margin-top: 8px; }
.auth-form input {
  background: #0f0f16;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 11px 12px;
  border-radius: 10px;
  font-size: 15px;
}
.auth-form input:focus { outline: none; border-color: var(--teal); }

.form-error { color: var(--danger); font-size: 13px; min-height: 18px; }
.hint { color: var(--text-dim); font-size: 12px; margin-top: 10px; }

.btn-primary, .btn-secondary, .btn-danger {
  padding: 12px;
  border-radius: 10px;
  border: none;
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
  margin-top: 8px;
}
.btn-primary { background: var(--gold); color: #241a04; }
.btn-secondary { background: #2a2a38; color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }

/* ---------- APP ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 5;
}
.brand { font-weight: 700; color: var(--gold); }
.topbar-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.icon-btn {
  background: #1e1e2a;
  color: var(--text);
  border: 1px solid var(--border);
  padding: 8px 12px;
  border-radius: 10px;
  font-size: 13px;
  cursor: pointer;
}
.icon-btn:hover { border-color: var(--teal); }

.chart-container {
  overflow: auto;
  padding: 40px 20px 100px;
  min-height: calc(100vh - 60px);
}

.chart-root { display: flex; justify-content: center; }

.tree-node { display: flex; flex-direction: column; align-items: center; }
.tree-children {
  display: flex;
  gap: 24px;
  margin-top: 28px;
  padding-top: 28px;
  position: relative;
  border-top: 2px solid var(--border);
}
.tree-children::before {
  content: '';
  position: absolute;
  top: -2px; left: 50%;
  width: 2px; height: 28px;
  background: var(--border);
}

.node-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 190px;
  cursor: grab;
  transition: border-color .15s;
}
.node-card:hover { border-color: var(--teal); }
.node-card.drag-over { border-color: var(--gold); box-shadow: 0 0 0 2px var(--gold); }

.avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--teal);
  color: #06231f;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
  flex-shrink: 0;
}
.avatar.root { background: var(--gold); color: #241a04; }

.node-info { flex: 1; min-width: 0; }
.node-title { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.node-subtitle { font-size: 12px; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.node-role { font-size: 10px; letter-spacing: .04em; color: var(--teal); margin-top: 2px; }

.node-actions { display: flex; gap: 4px; }
.node-actions button {
  background: #262633; border: none; color: var(--text);
  width: 24px; height: 24px; border-radius: 6px; cursor: pointer; font-size: 13px;
}

/* ---------- MODALS ---------- */
.modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.6);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  z-index: 50;
}
.modal-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  width: 100%; max-width: 420px;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-card h2 { margin-top: 0; }
.modal-card label { display: block; font-size: 13px; color: var(--text-dim); margin-top: 12px; }
.modal-card input {
  width: 100%;
  background: #0f0f16;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 10px;
  margin-top: 4px;
  font-size: 14px;
}
.modal-actions { display: flex; gap: 8px; margin-top: 20px; align-items: center; }
.spacer { flex: 1; }

.cabinet-profile { background: #0f0f16; border-radius: 10px; padding: 14px; margin-top: 10px; font-size: 14px; line-height: 1.7; }
.users-list { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.user-row { display: flex; align-items: center; gap: 8px; background: #0f0f16; padding: 8px 10px; border-radius: 10px; font-size: 13px; }
.user-row .u-name { flex: 1; }
.user-row select { background: #1e1e2a; color: var(--text); border: 1px solid var(--border); border-radius: 6px; padding: 4px; }
.user-row button { background: var(--danger); border: none; color: #fff; border-radius: 6px; padding: 4px 8px; cursor: pointer; }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: #1e1e2a; border: 1px solid var(--border); color: var(--text);
  padding: 10px 18px; border-radius: 10px; font-size: 13px; z-index: 100;
}
.toast.error { border-color: var(--danger); color: var(--danger); }
