:root {
  color-scheme: light;
  --bg: #f5f7f8;
  --surface: #ffffff;
  --surface-soft: #eef3f1;
  --text: #17201d;
  --muted: #66736f;
  --line: #dce5e1;
  --accent: #16715f;
  --accent-dark: #0f594a;
  --danger: #b42318;
  --warning: #b45309;
  --blue: #245d8f;
  --shadow: 0 18px 45px rgba(18, 32, 28, 0.12);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

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

.auth-screen {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 28px;
  background: var(--bg);
}

.auth-card {
  display: grid;
  gap: 18px;
  width: min(420px, 100%);
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.auth-brand {
  padding-bottom: 4px;
}

.auth-note {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.45;
}

.auth-error {
  margin: 0;
  padding: 10px 12px;
  border-radius: 8px;
  background: #fde8e6;
  color: var(--danger);
  font-size: 14px;
  font-weight: 700;
}

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

button {
  cursor: pointer;
}

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

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 28px;
  border-right: 1px solid var(--line);
  background: #fbfcfc;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  font-weight: 800;
  letter-spacing: 0;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 24px;
  line-height: 1.1;
}

h2 {
  margin-bottom: 0;
  font-size: 28px;
  line-height: 1.15;
}

h3 {
  margin-bottom: 0;
  font-size: 20px;
  line-height: 1.2;
}

.workspace {
  min-width: 0;
  padding: 28px;
}

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

.toolbar-actions {
  display: flex;
  gap: 10px;
}

.primary-action,
.ghost-button,
.icon-button,
.link-action {
  border: 0;
  border-radius: 8px;
  transition:
    background 0.15s ease,
    color 0.15s ease,
    border-color 0.15s ease,
    transform 0.15s ease;
}

.primary-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 44px;
  padding: 0 16px;
  background: var(--accent);
  color: white;
  font-weight: 700;
}

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

.primary-action.compact {
  min-height: 38px;
  padding: 0 14px;
}

.ghost-button {
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font-weight: 650;
}

.ghost-button:hover {
  border-color: #b9c8c3;
  background: var(--surface-soft);
}

.ghost-button.small {
  min-height: 32px;
  padding: 0 10px;
  font-size: 13px;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  background: transparent;
  color: var(--muted);
  font-size: 22px;
}

.icon-button:hover {
  background: var(--surface-soft);
  color: var(--text);
}

.stats {
  display: grid;
  gap: 10px;
}

.user-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.user-panel strong {
  display: block;
  max-width: 170px;
  overflow: hidden;
  font-size: 14px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stat-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

.stat-row span:first-child {
  color: var(--muted);
}

.stat-row strong {
  font-size: 20px;
}

.empty-state {
  display: grid;
  place-items: center;
  gap: 12px;
  min-height: 430px;
  padding: 32px;
  border: 1px dashed #b9c8c3;
  border-radius: 8px;
  background: var(--surface);
  text-align: center;
}

.empty-state p {
  max-width: 460px;
  color: var(--muted);
}

.empty-icon {
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--accent);
  font-size: 30px;
  font-weight: 800;
}

.tree-panel {
  display: grid;
  gap: 12px;
}

.node {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  overflow: hidden;
}

.node-header {
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 14px;
}

.node-toggle {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
}

.node-toggle.is-empty {
  visibility: hidden;
}

.node-title {
  min-width: 0;
}

.node-title-row {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}

.node-name {
  overflow: hidden;
  font-size: 16px;
  font-weight: 750;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.node-description {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.badge {
  display: inline-flex;
  align-items: center;
  height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.badge.level-high {
  background: #fde8e6;
  color: var(--danger);
}

.badge.level-medium {
  background: #fff2d7;
  color: var(--warning);
}

.badge.level-low {
  background: #e7f5ff;
  color: var(--blue);
}

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

.link-action {
  min-height: 32px;
  padding: 0 10px;
  background: var(--surface-soft);
  color: var(--accent-dark);
  font-size: 13px;
  font-weight: 750;
}

.link-action:hover {
  background: #dcece7;
}

.danger-action {
  color: var(--danger);
}

.node-children {
  display: grid;
  gap: 10px;
  padding: 0 14px 14px 46px;
}

.node.collapsed > .node-children {
  display: none;
}

.node-depth-1 {
  background: #fbfcfc;
}

.node-depth-2 {
  background: #ffffff;
}

.node-depth-3 {
  background: #fbfcfc;
}

.meta-list {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 8px;
}

.chip {
  max-width: 100%;
  padding: 5px 8px;
  border-radius: 8px;
  background: #eef3f1;
  color: #31413c;
  font-size: 12px;
  line-height: 1.35;
}

dialog {
  width: min(720px, calc(100vw - 28px));
  padding: 0;
  border: 0;
  border-radius: 8px;
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(12, 23, 21, 0.42);
  backdrop-filter: blur(3px);
}

.dialog-card {
  padding: 22px;
}

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

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

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

.field label {
  color: #293833;
  font-size: 14px;
  font-weight: 750;
}

.field input,
.field textarea,
.field select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  outline: none;
}

.field input,
.field select {
  min-height: 42px;
  padding: 0 12px;
}

.field textarea {
  min-height: 92px;
  padding: 11px 12px;
  resize: vertical;
}

.field input:focus,
.field textarea:focus,
.field select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(22, 113, 95, 0.13);
}

.text-list-field {
  display: grid;
  gap: 8px;
}

.text-list-items {
  display: grid;
  gap: 8px;
}

.text-list-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 34px;
  gap: 8px;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 22px;
}

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .toolbar {
    flex-direction: column;
  }
}

@media (max-width: 620px) {
  .sidebar,
  .workspace {
    padding: 18px;
  }

  .node-header {
    grid-template-columns: 32px minmax(0, 1fr);
  }

  .node-actions {
    grid-column: 1 / -1;
    flex-wrap: wrap;
    padding-left: 42px;
  }

  .node-children {
    padding-left: 24px;
  }

  .toolbar-actions,
  .dialog-actions {
    width: 100%;
  }

  .toolbar-actions button,
  .dialog-actions button {
    flex: 1;
  }
}
