/* =========================================================
   KEOTEACH · MAPAS CONCEPTUALES CON KEO
   Usa las variables de style.css (oscuro y claro). Se enlaza después de keo-brain.css.
========================================================= */

:root {
    --cm-stage: #0b1120;
    --cm-dot: rgba(148, 163, 255, .14);
    --cm-label-bg: #121a30;
    --cm-link: #8a93b8;
}

html[data-theme="light"] {
    --cm-stage: #f7f8fc;
    --cm-dot: rgba(70, 80, 140, .12);
    --cm-label-bg: #ffffff;
    --cm-link: #7a819c;
}

.maps-intro {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.maps-logo {
    width: 64px;
    height: 64px;
    display: grid;
    place-items: center;
    border-radius: 18px;
    background: linear-gradient(135deg, var(--primary), var(--primary-2));
    color: #fff;
    font-size: 26px;
}

/* =========================================================
   CREADOR
========================================================= */

.cm-home {
    display: grid;
    grid-template-columns: minmax(0, 1.15fr) minmax(0, .85fr);
    gap: 16px;
    align-items: start;
}

.cm-builder {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.cm-builder h3 {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0;
    font-family: var(--font-display);
}

.cm-builder h3 i { color: var(--primary-2); }

.cm-tabs {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 4px;
    padding: 4px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--surface);
}

.cm-tab {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 9px 10px;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: var(--text-soft);
    font-weight: 700;
    transition: background var(--transition), color var(--transition);
}

.cm-tab.active {
    background: linear-gradient(135deg, var(--primary), var(--primary-2));
    color: #fff;
}

.cm-source {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.cm-drop {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 26px 16px;
    border: 2px dashed color-mix(in srgb, var(--primary) 45%, var(--border));
    border-radius: 16px;
    background: color-mix(in srgb, var(--primary) 6%, transparent);
    color: var(--text);
    text-align: center;
    cursor: pointer;
    transition: border-color var(--transition), background var(--transition), transform var(--transition);
}

.cm-drop i { font-size: 30px; color: var(--primary-2); }
.cm-drop small { color: var(--text-muted); }
.cm-drop:hover,
.cm-drop:focus-visible,
.cm-drop.is-over {
    border-color: var(--primary);
    background: color-mix(in srgb, var(--primary) 13%, transparent);
    transform: translateY(-1px);
}

.cm-drop.is-reading { cursor: progress; }

.cm-file {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--surface-2);
    animation: cmFadeUp .35s ease both;
}

.cm-file > div {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
    overflow-wrap: anywhere;
}

.cm-file small { color: var(--text-muted); }
.cm-file .cm-file-note { color: var(--yellow); }

.cm-file-icon {
    width: 42px;
    height: 42px;
    display: grid;
    place-items: center;
    flex-shrink: 0;
    border-radius: 12px;
    background: color-mix(in srgb, var(--primary) 16%, transparent);
    color: var(--primary-2);
    font-size: 19px;
}

.cm-options {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px 16px;
    padding-top: 6px;
    border-top: 1px solid var(--border);
}

.cm-opt {
    display: flex;
    flex-direction: column;
    gap: 7px;
    margin: 0;
}

.cm-opt-label {
    color: var(--text-soft);
    font-size: 12.5px;
    font-weight: 700;
}

.cm-opt input[type="range"] {
    width: 100%;
    accent-color: var(--primary);
}

.cm-seg {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    padding: 3px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface);
}

.cm-seg-item {
    flex: 1 1 auto;
    position: relative;
}

.cm-seg-item input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.cm-seg-item span {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 7px 9px;
    border-radius: 9px;
    color: var(--text-soft);
    font-size: 12.5px;
    font-weight: 700;
    white-space: nowrap;
    cursor: pointer;
    transition: background var(--transition), color var(--transition);
}

.cm-seg-item input:checked + span {
    background: color-mix(in srgb, var(--primary) 22%, var(--surface-2));
    color: var(--text);
    box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--primary) 55%, transparent);
}

.cm-seg-item input:focus-visible + span {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

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

.cm-swatch {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    cursor: pointer;
}

.cm-swatch input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.cm-swatch span {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: 3px solid transparent;
    box-shadow: 0 0 0 1px var(--border);
    transition: transform var(--transition), border-color var(--transition);
}

.cm-swatch small {
    color: var(--text-muted);
    font-size: 11px;
}

.cm-swatch input:checked + span {
    border-color: var(--surface);
    box-shadow: 0 0 0 2px var(--primary);
    transform: scale(1.08);
}

.cm-swatch input:focus-visible + span { outline: 2px solid var(--primary); outline-offset: 3px; }

.cm-toggles {
    grid-column: 1 / -1;
    display: flex;
    flex-wrap: wrap;
    gap: 10px 20px;
}

.cm-go {
    align-self: stretch;
    justify-content: center;
    padding: 13px 18px;
    font-size: 15px;
}

.cm-side {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.cm-showcase {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    text-align: center;
}

.cm-showcase p { margin: 0; font-size: 13px; }

.cm-history h4 {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0 0 10px;
    font-family: var(--font-display);
}

.cm-history h4 i { color: var(--primary-2); }

.cm-history ul {
    margin: 0;
    padding: 0;
    list-style: none;
    display: grid;
    gap: 6px;
}

.cm-history li {
    display: flex;
    align-items: center;
    gap: 6px;
}

.cm-history .brain-none {
    padding: 10px 12px;
    border: 1px dashed var(--border);
    border-radius: 10px;
    color: var(--text-muted);
    font-size: 13px;
}

.cm-history-open {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 11px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface-2);
    color: var(--text);
    text-align: left;
    transition: border-color var(--transition), transform var(--transition);
}

.cm-history-open:hover {
    border-color: var(--primary);
    transform: translateX(2px);
}

.cm-history-open span:last-child {
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.cm-history-open strong {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.cm-history-open small { color: var(--text-muted); font-size: 11.5px; }

.cm-history-icon {
    width: 34px;
    height: 34px;
    display: grid;
    place-items: center;
    flex-shrink: 0;
    border-radius: 10px;
    background: color-mix(in srgb, var(--primary) 15%, transparent);
    color: var(--primary-2);
}

/* Mapa de ejemplo animado */

.cm-preview {
    width: 100%;
    max-width: 360px;
    height: auto;
}

.cm-preview-edges path {
    fill: none;
    stroke: var(--primary-2);
    stroke-width: 2.4;
    stroke-opacity: .55;
    stroke-dasharray: 220;
    stroke-dashoffset: 220;
    animation: cmDraw 2.6s ease-in-out infinite;
}

.cm-preview rect {
    fill: color-mix(in srgb, var(--primary) 22%, var(--surface));
    stroke: var(--primary-2);
    stroke-width: 2;
    transform-box: fill-box;
    transform-origin: center;
    animation: cmPreviewPop 2.6s ease-in-out infinite;
}

.cm-preview .p-root { fill: var(--primary); animation-delay: 0s; }
.cm-preview .p1 { animation-delay: .25s; }
.cm-preview .p2 { animation-delay: .35s; }
.cm-preview .p3 { animation-delay: .45s; }
.cm-preview .p4 { animation-delay: .6s; }
.cm-preview .p5 { animation-delay: .7s; }
.cm-preview .p6 { animation-delay: .8s; }

@keyframes cmDraw {
    0% { stroke-dashoffset: 220; }
    45%, 80% { stroke-dashoffset: 0; }
    100% { stroke-dashoffset: -220; }
}

@keyframes cmPreviewPop {
    0%, 100% { opacity: .35; transform: scale(.94); }
    40%, 75% { opacity: 1; transform: scale(1); }
}

/* Generando */

.cm-generating {
    max-width: 640px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 30px 20px;
    text-align: center;
}

.cm-generating h3 {
    margin: 0;
    font-family: var(--font-display);
    animation: cmFadeUp .4s ease both;
}

/* =========================================================
   VISOR
========================================================= */

.cm-viewer {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.cm-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px 14px;
}

.cm-title {
    flex: 1 1 240px;
    min-width: 0;
}

.cm-title h2 {
    margin: 0;
    font-family: var(--font-display);
    font-size: clamp(20px, 2.6vw, 26px);
    overflow-wrap: anywhere;
}

.cm-title small { color: var(--text-muted); }

.cm-tools {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}

.cm-seg.compact { flex-wrap: nowrap; }

.cm-seg-btn {
    width: 36px;
    height: 32px;
    display: grid;
    place-items: center;
    border: 0;
    border-radius: 9px;
    background: transparent;
    color: var(--text-soft);
    transition: background var(--transition), color var(--transition);
}

.cm-seg-btn.active {
    background: linear-gradient(135deg, var(--primary), var(--primary-2));
    color: #fff;
}

.cm-swatches.mini { gap: 6px; }

.cm-dot {
    width: 22px;
    height: 22px;
    padding: 0;
    border: 2px solid var(--surface);
    border-radius: 50%;
    box-shadow: 0 0 0 1px var(--border);
    transition: transform var(--transition), box-shadow var(--transition);
}

.cm-dot.active {
    box-shadow: 0 0 0 2px var(--primary);
    transform: scale(1.12);
}

.cm-tools .icon-btn.active {
    border-color: var(--primary);
    color: var(--primary-2);
}

.cm-search {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 0 10px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
    color: var(--text-muted);
}

.cm-search input {
    width: 150px;
    padding: 7px 0;
    border: 0;
    background: transparent;
    color: var(--text);
    outline: none;
}

.cm-stage {
    position: relative;
    height: min(72vh, 760px);
    min-height: 420px;
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background-color: var(--cm-stage);
    background-image: radial-gradient(var(--cm-dot) 1.2px, transparent 1.2px);
    background-size: 22px 22px;
}

.cm-stage:fullscreen {
    height: 100vh;
    border-radius: 0;
}

.cm-svg {
    width: 100%;
    height: 100%;
    display: block;
    cursor: grab;
    touch-action: none;
    user-select: none;
}

.cm-svg.is-panning { cursor: grabbing; }

/* Conceptos */

.cm-node { cursor: pointer; outline: none; }

.cm-node-inner {
    transform-box: fill-box;
    transform-origin: center;
    transition: transform .2s ease, opacity .25s ease, filter .25s ease;
}

.cm-node.is-new .cm-node-inner {
    animation: cmPop .55s cubic-bezier(.2, 1.4, .4, 1) both;
    animation-delay: calc(var(--d, 0) * 1ms);
}

.cm-box {
    stroke-width: 1.8;
    filter: drop-shadow(0 6px 14px rgba(0, 0, 0, .28));
    transition: stroke-width .2s ease;
}

html[data-theme="light"] .cm-box { filter: drop-shadow(0 5px 12px rgba(30, 40, 80, .12)); }

.cm-node.is-root .cm-box { stroke-width: 0; }

.cm-text { fill: var(--text); pointer-events: none; }
.cm-detail { fill: var(--text-soft); }
.cm-node.is-root .cm-text,
.cm-node.is-root .cm-detail { fill: #ffffff; }

.cm-node:hover .cm-node-inner { transform: scale(1.04); }
.cm-node:hover .cm-box,
.cm-node:focus-visible .cm-box { stroke-width: 3; }

.cm-node.is-selected .cm-box {
    stroke-width: 3.4;
    filter: drop-shadow(0 0 14px color-mix(in srgb, var(--primary) 60%, transparent));
}

.cm-node.is-dim .cm-node-inner { opacity: .28; }
.cm-node.is-hit .cm-box { stroke-width: 3.4; filter: drop-shadow(0 0 16px rgba(247, 201, 93, .65)); }

.cm-node.is-thinking .cm-box { animation: cmThink 1s ease-in-out infinite alternate; }

.cm-badge { cursor: pointer; }
.cm-badge text { fill: #fff; font-size: 11px; font-weight: 800; pointer-events: none; }
.cm-badge.minus { opacity: 0; transition: opacity .2s ease; }
.cm-node:hover .cm-badge.minus,
.cm-node:focus-visible .cm-badge.minus,
.cm-node.is-selected .cm-badge.minus { opacity: 1; }

/* Relaciones */

.cm-edge {
    fill: none;
    stroke-width: 2.4;
    stroke-opacity: .8;
    stroke-linecap: round;
}

.cm-edge.depth-1 { stroke-width: 3; }
.cm-edge.depth-3 { stroke-width: 1.8; }
.cm-edge.is-dim { stroke-opacity: .18; }

.cm-edge.is-new {
    stroke-dasharray: 1;
    stroke-dashoffset: 1;
    animation: cmLine .7s ease forwards;
    animation-delay: calc(var(--d, 0) * 1ms);
}

.cm-link {
    fill: none;
    stroke: var(--cm-link);
    stroke-width: 1.7;
    stroke-dasharray: 6 6;
    animation: cmMarch 1.4s linear infinite;
}

.cm-arrow-link { fill: var(--cm-link); }

.cm-rel { pointer-events: none; }

.cm-rel rect {
    fill: var(--cm-label-bg);
    stroke-width: 1;
}

.cm-rel text {
    fill: var(--text-soft);
    font: italic 600 11px Inter, system-ui, sans-serif;
}

.cm-rel.is-new {
    opacity: 0;
    animation: cmFadeIn .4s ease forwards;
    animation-delay: calc(var(--d, 0) * 1ms + 350ms);
}

.cm-rel-link rect { stroke: var(--cm-link); stroke-dasharray: 3 3; }

/* Controles del lienzo */

.cm-zoom {
    position: absolute;
    left: 12px;
    bottom: 12px;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: color-mix(in srgb, var(--surface) 88%, transparent);
    backdrop-filter: blur(8px);
}

.cm-zoom span {
    min-width: 46px;
    color: var(--text-soft);
    font-size: 12px;
    font-weight: 700;
    text-align: center;
}

.cm-hint {
    position: absolute;
    right: 14px;
    bottom: 14px;
    max-width: 50%;
    margin: 0;
    color: var(--text-muted);
    font-size: 11.5px;
    text-align: right;
    pointer-events: none;
}

.cm-summary {
    display: flex;
    gap: 10px;
    margin: 0;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--surface);
    color: var(--text-soft);
    font-size: 14px;
    line-height: 1.6;
}

.cm-summary i { margin-top: 4px; color: var(--primary-2); }

/* Panel del concepto */

.cm-drawer {
    --cm-accent: var(--primary);
    position: absolute;
    top: 12px;
    right: 12px;
    width: min(340px, calc(100% - 24px));
    max-height: calc(100% - 24px);
    overflow-y: auto;
    padding: 16px;
    border: 1px solid var(--border);
    border-top: 4px solid var(--cm-accent);
    border-radius: 16px;
    background: color-mix(in srgb, var(--surface) 94%, transparent);
    backdrop-filter: blur(10px);
    box-shadow: var(--shadow);
    opacity: 0;
    transform: translateX(16px);
    pointer-events: none;
    transition: opacity .25s ease, transform .25s ease;
}

.cm-drawer.open {
    opacity: 1;
    transform: none;
    pointer-events: auto;
}

.cm-drawer-head {
    display: flex;
    align-items: flex-start;
    gap: 8px;
}

.cm-trail {
    flex: 1;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px;
    color: var(--text-muted);
    font-size: 11.5px;
}

.cm-trail i { font-size: 8px; }

.cm-drawer h3 {
    margin: 8px 0 8px;
    font-family: var(--font-display);
    font-size: 20px;
    overflow-wrap: anywhere;
}

.cm-prop {
    margin: 0 0 10px;
    padding: 8px 10px;
    border-radius: 10px;
    background: color-mix(in srgb, var(--cm-accent) 12%, transparent);
    font-size: 13px;
}

.cm-prop em { color: var(--cm-accent); font-weight: 700; }

.cm-desc {
    margin: 0 0 10px;
    color: var(--text);
    font-size: 14.5px;
    line-height: 1.65;
}

.cm-example {
    margin: 0 0 12px;
    padding: 8px 10px;
    border-left: 3px solid var(--cm-accent);
    border-radius: 0 10px 10px 0;
    background: var(--surface-2);
    color: var(--text-soft);
    font-size: 13.5px;
}

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

/* Animaciones */

@keyframes cmPop {
    0% { opacity: 0; transform: scale(.4); }
    100% { opacity: 1; transform: scale(1); }
}

@keyframes cmLine {
    to { stroke-dashoffset: 0; }
}

@keyframes cmFadeIn {
    to { opacity: 1; }
}

@keyframes cmFadeUp {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: none; }
}

@keyframes cmMarch {
    to { stroke-dashoffset: -24; }
}

@keyframes cmThink {
    from { stroke-width: 1.8; }
    to { stroke-width: 5; }
}

/* =========================================================
   RESPONSIVE
========================================================= */

@media (max-width: 1100px) {
    .cm-home { grid-template-columns: 1fr; }
}

@media (max-width: 700px) {
    .cm-options { grid-template-columns: 1fr; }
    .maps-intro .keo-bot.intro { display: none; }
    .cm-stage { height: 68vh; min-height: 360px; }
    .cm-hint { display: none; }
    .cm-search input { width: 110px; }
    .cm-toolbar .btn span { display: none; }

    .cm-drawer {
        top: auto;
        right: 0;
        bottom: 0;
        left: 0;
        width: 100%;
        max-height: 60%;
        border-radius: 18px 18px 0 0;
        transform: translateY(24px);
    }

    .cm-zoom { bottom: 12px; }
    .cm-drawer.open ~ .cm-zoom,
    .cm-stage:has(.cm-drawer.open) .cm-zoom { opacity: 0; pointer-events: none; }
}

@media (prefers-reduced-motion: reduce) {
    .cm-preview-edges path,
    .cm-preview rect,
    .cm-node.is-new .cm-node-inner,
    .cm-edge.is-new,
    .cm-rel.is-new,
    .cm-link,
    .cm-node.is-thinking .cm-box,
    .cm-file,
    .cm-generating h3 {
        animation: none;
    }

    .cm-preview-edges path { stroke-dashoffset: 0; }
    .cm-edge.is-new { stroke-dasharray: none; }
    .cm-rel.is-new { opacity: 1; }
}
