/**
 * EDITOR DE ANOTACIONES PGN
 * Superficie responsive para escritorio, tablet y móvil.
 */

:root {
    --annotation-accent: var(--theme-accent-primary, #d5b84b);
    --annotation-accent-contrast: var(--theme-text-on-accent, #111111);
    --annotation-bg: var(--theme-modal-bg, #171717);
    --annotation-surface: var(--theme-bg-secondary, #202020);
    --annotation-surface-strong: var(--theme-bg-tertiary, #282828);
    --annotation-border: var(--theme-border, rgba(213, 184, 75, 0.3));
    --annotation-text: var(--theme-text-primary, #f5f5f5);
    --annotation-muted: var(--theme-text-secondary, #b5b5b5);
    --annotation-control-bg: var(--theme-bg-tertiary, #282828);
    --annotation-control-text: var(--theme-button-text, var(--annotation-text));
    --annotation-danger: #ef5b65;
    --annotation-danger-soft: rgba(239, 91, 101, 0.12);
}

html[data-theme="light-matrix"] {
    --annotation-accent-contrast: #ffffff;
}

body.annotation-modal-open {
    overflow: hidden;
}

.annotation-modal-container [hidden] {
    display: none !important;
}

.annotation-modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 10000;
    display: none;
    place-items: center;
    padding: clamp(14px, 3vw, 32px);
    background: rgba(0, 0, 0, 0.66);
    -webkit-backdrop-filter: blur(9px);
    backdrop-filter: blur(9px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 180ms ease;
}

.annotation-modal-overlay.active {
    display: grid;
    opacity: 1;
    pointer-events: auto;
}

.annotation-modal-container {
    position: relative;
    width: min(720px, 100%);
    max-height: min(760px, calc(100dvh - 40px));
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    overflow: hidden;
    color: var(--annotation-text);
    background: var(--annotation-bg);
    border: 1px solid var(--annotation-border);
    border-radius: 22px;
    box-shadow:
        0 30px 90px rgba(0, 0, 0, 0.48),
        0 0 0 1px color-mix(in srgb, var(--annotation-accent) 8%, transparent);
    animation: annotationModalIn 220ms ease-out both;
    isolation: isolate;
}

@keyframes annotationModalIn {
    from {
        opacity: 0;
        transform: translateY(12px) scale(0.985);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.annotation-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    min-width: 0;
    padding: 18px 20px;
    background: var(--annotation-surface-strong);
    border-bottom: 1px solid var(--annotation-border);
}

.annotation-modal-heading,
.annotation-modal-title-row {
    min-width: 0;
}

.annotation-modal-heading {
    flex: 1 1 auto;
    overflow: hidden;
}

.annotation-modal-kicker {
    display: block;
    margin-bottom: 3px;
    color: var(--annotation-muted);
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 0.16em;
    text-transform: uppercase;
}

.annotation-modal-title-row {
    display: flex;
    align-items: center;
    gap: 10px;
    overflow: hidden;
}

.annotation-modal-title {
    flex: 0 1 auto;
    margin: 0;
    overflow: hidden;
    color: var(--annotation-text);
    font-size: clamp(18px, 2.6vw, 23px);
    font-weight: 800;
    line-height: 1.1;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.annotation-move-chip {
    flex: 0 0 auto;
    min-width: 48px;
    max-width: 92px;
    padding: 5px 10px;
    overflow: hidden;
    color: var(--annotation-accent);
    font-weight: 800;
    text-align: center;
    text-overflow: ellipsis;
    white-space: nowrap;
    background: color-mix(in srgb, var(--annotation-accent) 11%, var(--annotation-surface-strong));
    border: 1px solid color-mix(in srgb, var(--annotation-accent) 45%, transparent);
    border-radius: 999px;
}

.move-display {
    color: inherit;
}

.annotation-modal-close {
    flex: 0 0 auto;
    width: 40px;
    min-width: 40px;
    height: 40px;
    min-height: 40px;
    display: grid;
    place-items: center;
    padding: 0;
    color: var(--annotation-control-text);
    font: 400 1.65rem/1 Arial, sans-serif;
    background: var(--annotation-control-bg);
    border: 1px solid color-mix(in srgb, var(--annotation-control-text) 30%, var(--annotation-border));
    border-radius: 50%;
    cursor: pointer;
    transition: color 160ms ease, border-color 160ms ease, background 160ms ease;
}

.annotation-modal-close:hover {
    color: var(--annotation-accent-contrast);
    background: var(--annotation-accent);
    border-color: var(--annotation-accent);
}

.annotation-modal-content {
    min-height: 0;
    display: grid;
    align-content: start;
    gap: 12px;
    padding: 18px 20px 24px;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-color: var(--annotation-accent) transparent;
    scrollbar-width: thin;
}

.annotation-modal-content::-webkit-scrollbar {
    width: 7px;
}

.annotation-modal-content::-webkit-scrollbar-thumb {
    background: var(--annotation-accent);
    border-radius: 999px;
}

.annotation-section {
    padding: 15px;
    background: var(--annotation-surface);
    border: 1px solid var(--annotation-border);
    border-radius: 15px;
}

.annotation-section--primary {
    border-color: color-mix(in srgb, var(--annotation-accent) 52%, var(--annotation-border));
    box-shadow: inset 3px 0 0 var(--annotation-accent);
}

.annotation-section--quick {
    padding-block: 13px;
}

.annotation-section-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 10px;
}

.annotation-section-title,
.annotation-subsection-title {
    display: block;
    color: var(--annotation-text);
    font-size: 13px;
    font-weight: 800;
    line-height: 1.3;
}

.annotation-section--primary > .annotation-section-title {
    margin-bottom: 9px;
}

.annotation-textarea-wrapper {
    display: grid;
    gap: 9px;
}

.annotation-textarea {
    width: 100%;
    min-height: 78px;
    padding: 12px 13px;
    resize: vertical;
    color: var(--annotation-text);
    font: inherit;
    font-size: 14px;
    line-height: 1.5;
    background: color-mix(in srgb, var(--annotation-surface-strong) 76%, var(--annotation-surface));
    border: 1px solid var(--annotation-border);
    border-radius: 11px;
    outline: none;
    transition: border-color 160ms ease, box-shadow 160ms ease;
}

.annotation-textarea--primary {
    min-height: 102px;
}

.annotation-textarea::placeholder {
    color: color-mix(in srgb, var(--annotation-muted) 72%, transparent);
}

.annotation-textarea:focus {
    border-color: var(--annotation-accent);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--annotation-accent) 17%, transparent);
}

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

.annotation-inline-btn {
    min-height: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 0 11px;
    color: var(--annotation-control-text);
    font: inherit;
    font-size: 12px;
    font-weight: 700;
    background: var(--annotation-control-bg);
    border: 1px solid color-mix(in srgb, var(--annotation-control-text) 28%, var(--annotation-border));
    border-radius: 10px;
    cursor: pointer;
}

.annotation-inline-icon {
    width: 17px;
    height: 17px;
    flex: 0 0 17px;
    background: currentColor;
    -webkit-mask-position: center;
    mask-position: center;
    -webkit-mask-repeat: no-repeat;
    mask-repeat: no-repeat;
    -webkit-mask-size: contain;
    mask-size: contain;
}

.annotation-inline-icon--diagram {
    -webkit-mask-image: url('../svg/diagram.svg');
    mask-image: url('../svg/diagram.svg');
}

.annotation-inline-btn:hover,
.annotation-inline-btn.active {
    color: var(--annotation-control-text);
    background: color-mix(in srgb, var(--annotation-accent) 18%, var(--annotation-control-bg));
    border-color: var(--annotation-accent);
}

.annotation-inline-btn.is-active {
    color: var(--annotation-accent-contrast);
    background: var(--annotation-accent);
    border-color: var(--annotation-accent);
}

.annotation-inline-btn--danger:hover {
    color: var(--annotation-danger);
    background: var(--annotation-danger-soft);
    border-color: var(--annotation-danger);
}

.annotation-quality-grid {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 8px;
}

.nag-btn {
    min-width: 0;
    min-height: 43px;
    padding: 8px 10px;
    overflow: hidden;
    color: var(--annotation-muted);
    font: inherit;
    font-size: 12px;
    font-weight: 700;
    line-height: 1.2;
    text-overflow: ellipsis;
    background: var(--annotation-control-bg);
    border: 1px solid var(--annotation-border);
    border-radius: 10px;
    cursor: pointer;
    transition: color 150ms ease, background 150ms ease, border-color 150ms ease, transform 150ms ease;
}

.nag-btn:hover {
    color: var(--annotation-text);
    border-color: color-mix(in srgb, var(--annotation-accent) 70%, var(--annotation-border));
    transform: translateY(-1px);
}

.nag-btn.selected,
.nag-btn[aria-pressed="true"] {
    color: var(--annotation-accent);
    background: color-mix(in srgb, var(--annotation-accent) 14%, var(--annotation-control-bg));
    border-color: var(--annotation-accent);
    box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--annotation-accent) 25%, transparent);
}

.nag-btn--quality {
    min-height: 58px;
    display: grid;
    place-content: center;
    gap: 2px;
    text-align: center;
}

.nag-btn--quality strong {
    color: inherit;
    font-size: 18px;
}

.nag-btn--quality span {
    overflow: hidden;
    font-size: 10px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.nag-btn-clear,
.annotation-clear-inline {
    min-height: 30px;
    padding: 0 8px;
    color: var(--annotation-muted);
    font: inherit;
    font-size: 11px;
    font-weight: 700;
    background: transparent;
    border: 0;
    border-radius: 8px;
    cursor: pointer;
}

.nag-btn-clear:hover {
    color: var(--annotation-accent);
    background: color-mix(in srgb, var(--annotation-accent) 10%, transparent);
}

.annotation-disclosure {
    overflow: clip;
    background: var(--annotation-surface);
    border: 1px solid var(--annotation-border);
    border-radius: 14px;
}

.annotation-disclosure > summary {
    min-height: 48px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 0 15px;
    color: var(--annotation-text);
    font-size: 13px;
    font-weight: 800;
    list-style: none;
    cursor: pointer;
    user-select: none;
}

.annotation-disclosure > summary::-webkit-details-marker {
    display: none;
}

.annotation-disclosure > summary::after {
    content: "+";
    flex: 0 0 auto;
    color: var(--annotation-accent);
    font-size: 18px;
    font-weight: 500;
}

.annotation-disclosure[open] > summary::after {
    content: "−";
}

.annotation-disclosure > summary small {
    margin-left: auto;
    overflow: hidden;
    color: var(--annotation-muted);
    font-size: 10px;
    font-weight: 650;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.annotation-disclosure[open] > summary {
    border-bottom: 1px solid var(--annotation-border);
}

.annotation-disclosure-body {
    padding: 14px;
}

.annotation-symbol-groups {
    display: grid;
    gap: 15px;
}

.annotation-subsection {
    min-width: 0;
}

.annotation-subsection + .annotation-subsection {
    padding-top: 14px;
    border-top: 1px solid var(--annotation-border);
}

.annotation-subsection > .annotation-subsection-title {
    margin-bottom: 9px;
}

.annotation-nag-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
}

.annotation-nag-grid--compact {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.variation-info {
    color: var(--annotation-accent) !important;
}

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

.variation-action-btn {
    min-height: 46px;
    padding: 9px 11px;
    color: var(--annotation-text);
    font: inherit;
    font-size: 12px;
    font-weight: 750;
    background: var(--annotation-control-bg);
    border: 1px solid var(--annotation-border);
    border-radius: 10px;
    cursor: pointer;
}

.variation-action-btn:hover {
    color: var(--annotation-accent);
    border-color: var(--annotation-accent);
}

.variation-action-btn--danger:hover {
    color: var(--annotation-danger);
    background: var(--annotation-danger-soft);
    border-color: var(--annotation-danger);
}

.annotation-disclosure--danger > summary {
    color: color-mix(in srgb, var(--annotation-danger) 82%, var(--annotation-text));
}

.annotation-cleanup-list {
    display: grid;
    gap: 8px;
}

.annotation-cleanup-btn {
    width: 100%;
    min-height: 54px;
    display: grid;
    gap: 3px;
    padding: 11px 12px;
    color: var(--annotation-text);
    font: inherit;
    text-align: left;
    background: var(--annotation-control-bg);
    border: 1px solid var(--annotation-border);
    border-radius: 10px;
    cursor: pointer;
}

.annotation-cleanup-btn strong {
    font-size: 12px;
}

.annotation-cleanup-btn span {
    color: var(--annotation-muted);
    font-size: 10px;
    line-height: 1.35;
}

.annotation-cleanup-btn:hover,
.annotation-cleanup-btn--danger:hover {
    color: var(--annotation-danger);
    background: var(--annotation-danger-soft);
    border-color: var(--annotation-danger);
}

.annotation-modal-footer {
    min-height: 72px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 12px 20px;
    background: var(--annotation-surface-strong);
    border-top: 1px solid var(--annotation-border);
}

.annotation-save-state {
    min-width: 0;
    color: var(--annotation-muted);
    font-size: 11px;
    font-weight: 700;
}

.annotation-save-state[data-state="dirty"] {
    color: var(--annotation-accent);
}

.annotation-modal-footer-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 9px;
}

.annotation-modal-btn {
    min-width: 112px;
    min-height: 44px;
    padding: 0 17px;
    color: var(--annotation-text);
    font: inherit;
    font-size: 13px;
    font-weight: 800;
    background: transparent;
    border: 1px solid var(--annotation-border);
    border-radius: 11px;
    cursor: pointer;
    transition: transform 150ms ease, filter 150ms ease, opacity 150ms ease;
}

.annotation-modal-btn.primary {
    color: var(--annotation-accent-contrast);
    background: var(--annotation-accent);
    border-color: var(--annotation-accent);
}

.annotation-modal-btn:hover:not(:disabled) {
    filter: brightness(1.08);
    transform: translateY(-1px);
}

.annotation-modal-btn:disabled {
    opacity: 0.42;
    cursor: not-allowed;
}

.annotation-visually-hidden {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
}

.annotation-modal-container button:focus-visible,
.annotation-modal-container textarea:focus-visible,
.annotation-modal-container summary:focus-visible,
.annotation-confirm-modal button:focus-visible {
    outline: 3px solid color-mix(in srgb, var(--annotation-accent) 48%, transparent);
    outline-offset: 2px;
}

/* Confirmaciones semánticas dentro del editor */
.annotation-confirm-overlay {
    position: fixed;
    inset: 0;
    z-index: 10020;
    display: grid;
    place-items: center;
    padding: 18px;
    background: rgba(0, 0, 0, 0.76);
    -webkit-backdrop-filter: blur(6px);
    backdrop-filter: blur(6px);
}

.annotation-confirm-modal {
    width: min(430px, 100%);
    padding: 21px;
    color: var(--annotation-text);
    background: var(--annotation-bg);
    border: 1px solid var(--annotation-border);
    border-radius: 17px;
    box-shadow: 0 24px 70px rgba(0, 0, 0, 0.55);
}

.annotation-confirm-kicker {
    display: block;
    margin-bottom: 5px;
    color: var(--annotation-muted);
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 0.14em;
    text-transform: uppercase;
}

.annotation-confirm-modal h3 {
    margin: 0 0 8px;
    font-size: 18px;
}

.annotation-confirm-modal p {
    margin: 0;
    color: var(--annotation-muted);
    font-size: 13px;
    line-height: 1.55;
}

.annotation-confirm-actions {
    display: flex;
    justify-content: flex-end;
    gap: 9px;
    margin-top: 19px;
}

.annotation-confirm-btn {
    min-height: 42px;
    padding: 0 14px;
    color: var(--annotation-text);
    font: inherit;
    font-size: 12px;
    font-weight: 800;
    background: transparent;
    border: 1px solid var(--annotation-border);
    border-radius: 10px;
    cursor: pointer;
}

.annotation-confirm-btn--primary {
    color: var(--annotation-accent-contrast);
    background: var(--annotation-accent);
    border-color: var(--annotation-accent);
}

.annotation-confirm-btn--danger {
    color: #ffffff;
    background: var(--annotation-danger);
    border-color: var(--annotation-danger);
}

@media (max-width: 1024px) {
    .annotation-modal-container {
        width: min(640px, 100%);
    }

    .annotation-quality-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .annotation-nag-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 600px) and (orientation: portrait) {
    .annotation-modal-overlay {
        place-items: end center;
        padding: 0;
        background: rgba(0, 0, 0, 0.72);
    }

    .annotation-modal-container {
        width: 100%;
        height: min(88dvh, 760px);
        max-height: 88dvh;
        border-right: 0;
        border-bottom: 0;
        border-left: 0;
        border-radius: 20px 20px 0 0;
        animation-name: annotationSheetIn;
    }

    @keyframes annotationSheetIn {
        from {
            opacity: 0;
            transform: translateY(28px);
        }
        to {
            opacity: 1;
            transform: translateY(0);
        }
    }

    .annotation-modal-header {
        gap: 10px;
        padding: 13px 14px 12px;
    }

    .annotation-modal-kicker {
        font-size: 9px;
    }

    .annotation-modal-title {
        font-size: 17px;
    }

    .annotation-move-chip {
        min-width: 43px;
        padding: 4px 8px;
        font-size: 13px;
    }

    .annotation-modal-close {
        width: 36px;
        min-width: 36px;
        height: 36px;
        min-height: 36px;
        font-size: 1.45rem;
    }

    .annotation-modal-content {
        gap: 9px;
        padding: 12px 12px 18px;
    }

    .annotation-section {
        padding: 12px;
        border-radius: 13px;
    }

    .annotation-textarea--primary {
        min-height: 88px;
    }

    .annotation-quality-grid {
        gap: 6px;
    }

    .nag-btn--quality {
        min-height: 51px;
        padding: 6px;
    }

    .nag-btn--quality strong {
        font-size: 17px;
    }

    .annotation-disclosure > summary {
        min-height: 46px;
        padding-inline: 12px;
    }

    .annotation-disclosure-body {
        padding: 11px;
    }

    .variation-action-grid,
    .annotation-nag-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .annotation-modal-footer {
        min-height: 64px;
        gap: 8px;
        padding: 9px 12px calc(9px + env(safe-area-inset-bottom));
    }

    .annotation-save-state {
        font-size: 10px;
    }

    .annotation-modal-footer-actions {
        flex: 1 1 auto;
    }

    .annotation-modal-btn {
        min-width: 0;
        min-height: 42px;
        flex: 1 1 0;
        padding-inline: 13px;
    }

    .annotation-confirm-actions {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (orientation: landscape) and (max-height: 620px) {
    .annotation-modal-overlay {
        padding: 8px;
    }

    .annotation-modal-container {
        width: min(900px, 98vw);
        max-height: calc(100dvh - 16px);
        border-radius: 15px;
    }

    .annotation-modal-header {
        padding: 10px 15px;
    }

    .annotation-modal-kicker {
        display: none;
    }

    .annotation-modal-title {
        font-size: 16px;
    }

    .annotation-modal-content {
        gap: 8px;
        padding: 10px 14px 14px;
    }

    .annotation-section {
        padding: 10px 12px;
    }

    .annotation-textarea--primary {
        min-height: 70px;
    }

    .annotation-quality-grid {
        grid-template-columns: repeat(6, minmax(0, 1fr));
    }

    .nag-btn--quality {
        min-height: 46px;
    }

    .annotation-disclosure > summary {
        min-height: 40px;
    }

    .annotation-modal-footer {
        min-height: 54px;
        padding: 6px 14px;
    }

    .annotation-modal-btn {
        min-height: 38px;
    }
}

@media (max-width: 380px) {
    .annotation-save-state {
        display: none;
    }

    .annotation-modal-footer-actions {
        width: 100%;
    }

    .annotation-disclosure > summary small {
        max-width: 80px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .annotation-modal-overlay,
    .annotation-modal-container,
    .nag-btn,
    .annotation-modal-btn {
        animation: none !important;
        transition: none !important;
    }
}
