:root {
  --bg: #f6f7f4;
  --panel: #ffffff;
  --ink: #1f2933;
  --muted: #697586;
  --line: #d9e0dc;
  --primary: #116466;
  --primary-dark: #0b4f51;
  --accent: #c44536;
  --gold: #d9a441;
  --green: #2f8f5b;
  --shadow: 0 18px 45px rgba(31, 41, 51, 0.08);
}

* {
  box-sizing: border-box;
}

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

a {
  color: var(--primary);
  text-decoration: none;
}

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

.app-shell {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: 100vh;
}

.auth-shell {
  min-height: 100vh;
  background:
    linear-gradient(135deg, rgba(17, 100, 102, 0.95), rgba(196, 69, 54, 0.72)),
    url("/assets/img/mapa-referencia.jpeg");
  background-size: cover;
  background-position: center;
}

.sidebar {
  background: #17242a;
  color: #fff;
  padding: 28px 22px;
  display: flex;
  flex-direction: column;
  gap: 34px;
}

.brand {
  display: flex;
  gap: 12px;
  color: #fff;
  align-items: center;
}

.brand-mark {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--gold);
  color: #17242a;
  font-weight: 800;
}

.brand small,
.user-box small,
.muted {
  color: var(--muted);
}

.brand small {
  display: block;
  color: #a8bec2;
}

.sidebar nav {
  display: grid;
  gap: 8px;
}

.sidebar nav a {
  color: #dce7e5;
  padding: 11px 12px;
  border-radius: 8px;
}

.sidebar nav a:hover {
  background: rgba(255, 255, 255, 0.08);
}

.user-box {
  margin-top: auto;
  display: grid;
  gap: 6px;
  padding-top: 18px;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
}

.main {
  padding: 32px;
  min-width: 0;
}

.auth-shell .main {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
}

.public-shell .main {
  min-height: 100vh;
  padding: 32px;
}

.login-panel {
  width: min(980px, 100%);
  display: grid;
  grid-template-columns: 1.1fr 420px;
  gap: 28px;
  align-items: center;
}

.login-panel.single {
  grid-template-columns: minmax(320px, 460px);
  justify-content: center;
}

.login-copy {
  color: #fff;
}

.login-copy h1 {
  margin: 10px 0 14px;
  font-size: clamp(2.4rem, 5vw, 4.8rem);
  line-height: 0.96;
}

.login-copy p {
  max-width: 620px;
  font-size: 1.12rem;
  line-height: 1.7;
}

.eyebrow {
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.login-copy .eyebrow {
  color: #ffe0a6;
}

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

.page-header h1 {
  margin: 4px 0 0;
  font-size: 2rem;
}

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

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

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

.form-card.wide {
  max-width: 920px;
}

.form-card h2 {
  margin: 0;
}

label {
  display: grid;
  gap: 7px;
  color: #394450;
  font-weight: 700;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid #cfd7d3;
  border-radius: 8px;
  padding: 11px 12px;
  background: #fff;
  color: var(--ink);
}

textarea {
  resize: vertical;
}

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

.button {
  display: inline-flex;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 16px;
  color: var(--ink);
  background: #fff;
  cursor: pointer;
  font-weight: 800;
}

.button.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

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

.link-button {
  border: 0;
  background: transparent;
  color: #dce7e5;
  padding: 0;
  cursor: pointer;
  text-align: left;
}

.link-button.danger {
  color: var(--accent);
  margin-top: 18px;
  font-weight: 800;
}

.alert {
  padding: 13px 16px;
  border-radius: 8px;
  margin-bottom: 18px;
  border: 1px solid;
}

.alert.success {
  background: #e8f5ef;
  border-color: #b9ddcc;
  color: #1e6843;
}

.alert.error {
  background: #fff0ed;
  border-color: #efc2ba;
  color: #9f2d20;
}

.toolbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}

.search {
  display: flex;
  flex: 1;
  gap: 10px;
}

.segmented {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
  height: 42px;
}

.segmented button {
  border: 0;
  padding: 0 16px;
  background: transparent;
  cursor: pointer;
  font-weight: 800;
}

.segmented button.active {
  background: var(--ink);
  color: #fff;
}

.type-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 18px;
}

.legend-item,
.node-type-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 30px;
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: #394450;
  font-size: 0.88rem;
  font-weight: 800;
}

.node-type-badge {
  border-color: color-mix(in srgb, var(--node-color), white 45%);
  background: color-mix(in srgb, var(--node-color), white 88%);
  color: var(--ink);
  margin-bottom: 12px;
}

.visibility-badge {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  margin: 0 0 12px 8px;
  padding: 5px 10px;
  border-radius: 8px;
  font-size: 0.86rem;
  font-weight: 900;
}

.visibility-badge.public {
  background: #e8f5ef;
  color: #1e6843;
  border: 1px solid #b9ddcc;
}

.visibility-badge.private {
  background: #fff0ed;
  color: #9f2d20;
  border: 1px solid #efc2ba;
}

.node-type-badge::before {
  content: "";
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--node-color);
}

.type-color-preview {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  width: fit-content;
  min-height: 34px;
  padding: 6px 10px;
  border: 1px solid color-mix(in srgb, var(--selected-type-color), white 48%);
  border-radius: 8px;
  background: color-mix(in srgb, var(--selected-type-color), white 88%);
  color: var(--ink);
  font-size: 0.86rem;
  font-weight: 800;
}

.type-color-preview[hidden] {
  display: none;
}

.type-color-swatch {
  width: 18px;
  height: 18px;
  border-radius: 999px;
  background: var(--selected-type-color);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.72);
}

.type-color-preview strong {
  color: var(--muted);
  font-size: 0.78rem;
}

.visibility-field {
  display: grid;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}

.visibility-field legend {
  padding: 0 6px;
  color: #394450;
  font-weight: 900;
}

.radio-option {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.radio-option input {
  width: auto;
  margin-top: 4px;
}

.radio-option span {
  display: grid;
  gap: 3px;
}

.radio-option small {
  color: var(--muted);
  font-weight: 600;
}

.mind-map,
.tree-view {
  display: none;
}

.mind-map.active,
.tree-view.active {
  display: block;
}

.mind-map {
  --map-content-width: 1480px;
  --map-content-height: 720px;
  height: min(680px, calc(100vh - 250px));
  min-height: 520px;
  position: relative;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(rgba(255,255,255,0.82), rgba(255,255,255,0.9)),
    repeating-linear-gradient(0deg, transparent, transparent 31px, rgba(217, 224, 220, 0.55) 32px),
    repeating-linear-gradient(90deg, transparent, transparent 31px, rgba(217, 224, 220, 0.55) 32px);
  padding: 36px;
  cursor: grab;
  overscroll-behavior: contain;
}

.mind-map.is-dragging {
  cursor: grabbing;
  user-select: none;
}

.map-center {
  position: absolute;
  left: calc(36px + (var(--map-content-width) / 2));
  top: calc(36px + (var(--map-content-height) / 2));
  transform: translate(-50%, -50%);
  width: 250px;
  min-height: 96px;
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: center;
  text-align: center;
  border-radius: 8px;
  color: #fff;
  background: #17242a;
  border: 3px solid var(--gold);
  font-weight: 900;
  box-shadow: var(--shadow);
  z-index: 2;
}

.map-center > span:first-child {
  display: grid;
  gap: 5px;
}

.map-center strong {
  font-size: 1rem;
}

.map-center small {
  color: rgba(255, 255, 255, 0.76);
  font-size: 0.72rem;
  font-weight: 700;
  line-height: 1.25;
}

.root-action {
  border-color: rgba(255, 255, 255, 0.82);
  background: #fff;
  color: #17242a;
}

.map-edges {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: visible;
  z-index: 0;
}

.branches {
  position: relative;
  z-index: 1;
  width: var(--map-content-width);
  min-height: var(--map-content-height);
  display: grid;
  grid-template-columns: minmax(0, 520px) minmax(0, 520px);
  column-gap: 440px;
  row-gap: 34px;
  align-content: center;
  align-items: start;
}

.branch {
  position: relative;
  padding: 12px;
  min-width: 0;
}

.branch:nth-child(odd) {
  text-align: right;
}

.branch-label {
  position: relative;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 8px 13px;
  border-radius: 8px;
  border: 2px solid var(--branch-color);
  background: color-mix(in srgb, var(--branch-color), black 8%);
  color: #fff;
  font-weight: 900;
  box-shadow: 0 10px 24px color-mix(in srgb, var(--branch-color), transparent 76%);
  max-width: 100%;
}

.branch-label > span:first-child {
  overflow-wrap: anywhere;
}

.node-actions {
  display: inline-flex;
  gap: 5px;
  align-items: center;
  flex: 0 0 auto;
}

.node-action {
  display: inline-grid;
  place-items: center;
  width: 25px;
  height: 25px;
  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--ink);
  font-size: 0.88rem;
  font-weight: 900;
  line-height: 1;
  text-decoration: none;
  cursor: pointer;
}

.node-action:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 12px rgba(31, 41, 51, 0.16);
}

.branch-children {
  position: relative;
  display: grid;
  gap: 14px;
  margin-top: 16px;
}

.leaf {
  position: relative;
  z-index: 1;
  display: inline-flex;
  gap: 8px;
  justify-content: flex-end;
  align-items: center;
  width: fit-content;
  max-width: 500px;
  padding: 5px 9px;
  border: 2px solid var(--node-color);
  border-radius: 8px;
  background: color-mix(in srgb, var(--node-color), white 90%);
  color: var(--ink);
  box-shadow: 0 8px 18px color-mix(in srgb, var(--node-color), transparent 86%);
}

.branch:nth-child(even) .leaf {
  justify-self: start;
}

.branch:nth-child(odd) .leaf {
  justify-self: end;
}

.leaf-title {
  font-weight: 750;
  overflow-wrap: anywhere;
}

.leaf .node-action {
  border-color: color-mix(in srgb, var(--node-color), white 34%);
  background: #fff;
}

.leaf em {
  border: 1px solid color-mix(in srgb, var(--node-color), white 35%);
  border-radius: 8px;
  padding: 2px 7px;
  background: color-mix(in srgb, var(--node-color), white 86%);
  color: var(--ink);
  font-size: 0.72rem;
  font-style: normal;
  font-weight: 800;
}

.branch:nth-child(even) .leaf {
  justify-content: flex-start;
}

.leaf small {
  color: var(--muted);
}

.tree-view {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
}

.tree-node {
  margin: 8px 0;
}

.tree-node summary {
  display: flex;
  gap: 8px;
  align-items: center;
  cursor: pointer;
  padding: 8px 0;
}

.tree-node summary a {
  color: var(--ink);
  font-weight: 800;
}

.tree-node summary small {
  color: var(--node-color);
  font-weight: 800;
}

.tree-children {
  margin-left: 22px;
  padding-left: 18px;
  border-left: 2px solid color-mix(in srgb, var(--node-color), white 60%);
}

.type-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex: 0 0 auto;
  background: var(--node-color);
}

.type-dot.large {
  width: 34px;
  height: 34px;
}

.grid-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}

.type-card {
  padding: 18px;
  display: flex;
  gap: 14px;
}

.type-card h2,
.detail-card h2 {
  margin: 0 0 8px;
  font-size: 1.1rem;
}

.user-table {
  display: grid;
  gap: 0;
}

.user-table-head,
.user-table-row {
  display: grid;
  grid-template-columns: 1.1fr 0.9fr 1.4fr 1.3fr 0.9fr;
  gap: 12px;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

.user-table-head {
  color: var(--muted);
  font-size: 0.82rem;
  text-transform: uppercase;
  font-weight: 900;
}

.user-table-row span {
  overflow-wrap: anywhere;
}

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

.table-actions form {
  margin: 0;
}

.details-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(300px, 0.8fr);
  gap: 16px;
}

.detail-card {
  padding: 20px;
}

.detail-card dl {
  display: grid;
  grid-template-columns: 130px 1fr;
  gap: 8px 14px;
  margin: 18px 0 0;
}

.detail-card dt {
  color: var(--muted);
  font-weight: 800;
}

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

.resource-list {
  margin-top: 14px;
}

.resource-row a {
  display: grid;
  gap: 3px;
  min-width: 0;
  color: var(--ink);
}

.resource-row strong,
.resource-row small {
  overflow-wrap: anywhere;
}

.resource-row small {
  color: var(--muted);
}

.icon-danger {
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 1px solid #efc2ba;
  border-radius: 999px;
  background: #fff0ed;
  color: var(--accent);
  cursor: pointer;
  font-size: 1.1rem;
  font-weight: 900;
  line-height: 1;
}

.icon-danger:hover {
  background: #ffe2dc;
}

.inline-form {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.timeline-item {
  display: grid;
  gap: 4px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.timeline-item small {
  color: var(--muted);
}

.empty-state {
  margin: 10vh auto;
  max-width: 560px;
  text-align: center;
  background: #fff;
  padding: 32px;
  border-radius: 8px;
  border: 1px solid var(--line);
}

.empty-state.compact {
  margin: 80px auto;
}

.modal-open {
  overflow: hidden;
}

.node-modal[hidden] {
  display: none;
}

.node-modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 24px;
}

.node-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(23, 36, 42, 0.62);
}

.node-modal-panel {
  position: relative;
  z-index: 1;
  width: min(860px, 100%);
  max-height: calc(100vh - 48px);
  overflow: auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 26px 70px rgba(31, 41, 51, 0.24);
  padding: 22px;
}

.node-modal-panel header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 12px;
}

.node-modal-panel h2 {
  margin: 4px 0 0;
  font-size: 1.55rem;
}

.node-modal-panel p {
  line-height: 1.65;
}

.node-modal-panel [hidden] {
  display: none !important;
}

.node-modal-panel dl {
  display: grid;
  grid-template-columns: 150px 1fr;
  gap: 8px 14px;
  margin: 18px 0 0;
}

.node-modal-panel dt {
  color: var(--muted);
  font-weight: 900;
}

.modal-content-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-top: 20px;
}

.modal-content-grid article {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fff;
}

.modal-content-grid h3 {
  margin: 0 0 8px;
  font-size: 1rem;
}

.modal-history {
  grid-column: 1 / -1;
}

.node-modal-close {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  font-size: 1.2rem;
  font-weight: 900;
}

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

  .sidebar {
    position: static;
    gap: 18px;
  }

  .sidebar nav,
  .toolbar,
  .page-header,
  .search {
    flex-direction: column;
  }

  .login-panel,
  .form-grid,
  .details-grid,
  .modal-content-grid {
    grid-template-columns: 1fr;
  }

  .main {
    padding: 20px;
  }
}
