/* AnalogCams — Editor: panel lateral, modales, etiquetas, modo edición */

/* Edit button: hidden by default via CSS (belt+suspenders with inline style).
   Shown by JS toggling body.has-editor-token after token check. */
#editor-edit-btn {
    display: none;
}
body.has-editor-token #editor-edit-btn {
    display: flex;
}

/* ── Editor ──────────────────────────────────────────────────────────────── */
/* Pending change indicator — outline en <tr> no respeta border-radius del grupo */
tr.editor-pending > td {
    background: rgba(var(--accent-rgb), 0.07);
}
tr.editor-pending > td:first-child {
    box-shadow: inset 3px 0 0 var(--accent);
}
.camera-card.editor-pending {
    border-color: rgba(var(--accent-rgb), 0.45);
    box-shadow: inset 0 0 0 1.5px rgba(var(--accent-rgb), 0.45);
}
.cam-card.editor-pending {
    border-color: rgba(var(--accent-rgb), 0.45);
    box-shadow: inset 0 0 0 1.5px rgba(var(--accent-rgb), 0.45);
}

/* Edit mode: cursor + indicador sutil (misma lógica que la vista compacta)
   — borde tintado en tarjetas, franja izquierda en tabla; sin outline
   rectangular que en la tabla se lee demasiado fuerte. */
body.edit-mode #tableBody tr[data-serial],
body.edit-mode #groupedTableContainer tr[data-serial] {
    cursor: pointer;
    outline: none;
}

body.edit-mode #tableBody tr[data-serial] > td:first-child,
body.edit-mode #groupedTableContainer tr[data-serial] > td:first-child {
    box-shadow: inset 3px 0 0 rgba(var(--accent-rgb), 0.32);
}

body.edit-mode #cardsContainer .camera-card[data-serial],
body.edit-mode .brand-panel .cam-card[data-camera-id] {
    cursor: pointer;
    outline: none;
    border-color: rgba(var(--accent-rgb), 0.32);
    transition:
        transform 0.18s var(--ease-out),
        box-shadow 0.18s var(--ease-out),
        border-color 0.15s var(--ease-out);
}

@media (hover: hover) {
    body.edit-mode #tableBody tr[data-serial]:hover > td,
    body.edit-mode #groupedTableContainer tr[data-serial]:hover > td {
        background: rgba(var(--accent-rgb), 0.04);
    }

    body.edit-mode #tableBody tr[data-serial]:hover > td:first-child,
    body.edit-mode #groupedTableContainer tr[data-serial]:hover > td:first-child {
        box-shadow: inset 3px 0 0 rgba(var(--accent-rgb), 0.55);
    }

    body.edit-mode #cardsContainer .camera-card[data-serial]:hover {
        border-color: rgba(var(--accent-rgb), 0.55);
        transform: translateY(-2px);
        box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
    }

    body.edit-mode .brand-panel .cam-card[data-camera-id]:hover {
        border-color: rgba(var(--accent-rgb), 0.55);
        box-shadow: var(--shadow-md);
        transform: translateX(3px);
    }
}

/* Edit panel (slide-in) */
#editor-panel {
    position: fixed;
    top: 0;
    right: 0;
    height: 100vh;
    height: 100dvh;
    width: min(380px, 100vw);
    /* Mismo gris que .editor-modal (bg-surface), explícito en cabecera/cuerpo */
    background: var(--bg-surface);
    border-left: 1px solid var(--border);
    box-shadow: -8px 0 32px rgba(0, 0, 0, 0.4);
    z-index: var(--z-overlay);
    overflow: hidden;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
}

@media (prefers-reduced-motion: no-preference) {
    #editor-panel {
        animation: epSlideIn 0.2s ease-out;
    }
    @keyframes epSlideIn {
        from {
            transform: translateX(100%);
            opacity: 0;
        }
        to {
            transform: translateX(0);
            opacity: 1;
        }
    }
}

.ep-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 18px 16px 14px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-surface);
}

.ep-title {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.ep-brand {
    font-size: 0.68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-faint);
}

.ep-model {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--text-main);
}

.ep-serial {
    font-family: "DM Mono", monospace;
    font-size: 0.72rem;
    color: var(--text-faint);
}

.ep-form {
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.ep-field {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.ep-label {
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
}

.ep-select,
.ep-textarea {
    background: var(--bg-body);
    border: 1px solid var(--border);
    color: var(--text-main);
    border-radius: var(--radius-sm);
    padding: 7px 10px;
    font-size: 0.875rem;
    font-family: inherit;
    width: 100%;
    outline: none;

    transition:
        border-color 0.15s,
        box-shadow 0.15s;
}
.ep-textarea {
    resize: vertical;
}

.ep-select:focus,
.ep-textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-dim);
}

.ep-actions {
    display: flex;
    gap: 10px;
    flex-shrink: 0;
    padding: 12px 16px max(12px, env(safe-area-inset-bottom));
    border-top: 1px solid var(--border);
    background: var(--bg-surface);
    z-index: 1;
}
.ep-actions .btn {
    flex: 1;
}

@media (max-width: 768px) {
    #editor-panel {
        width: 100%;
        max-width: 100%;
    }

    .ep-actions {
        box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.18);
    }

    .ep-actions .btn {
        min-height: 44px;
    }
}

#editor-review-save-btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

/* Settings modal */
.editor-modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 100vh;
    height: 100dvh;
    background: rgba(0, 0, 0, 0.6);
    z-index: var(--z-modal);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    overflow-y: auto;
}

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

.editor-modal {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 24px;
    width: min(440px, 100%);
    max-height: calc(100% - 32px);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 14px;
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.5);
}

.editor-modal-title {
    font-size: 1rem;
    font-weight: 700;
}

.editor-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    background: var(--bg-surface);
}

.editor-modal-header .editor-modal-title {
    margin: 0;
    flex: 1;
    min-width: 0;
}

.editor-modal-divider {
    border: none;
    border-top: 1px solid var(--border);
    margin: 4px 0;
}

.editor-modal-subtitle {
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--text-main);
}

.editor-pin-status {
    display: block;
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: -6px;
}

/* El anillo de foco del campo (outline 3px + outline-offset 3px = 6px
   fuera del borde) dejaba solo ~2px libres hasta este texto con el mismo
   -6px que .editor-pin-status — en móvil se veía solapado. Sin negativo:
   el hueco del gap del modal (14px) ya deja sitio de sobra al anillo. */
.editor-pin-error {
    font-size: 0.8rem;
    color: var(--err-color, #ff453a);
}

.editor-modal-desc {
    font-size: 0.84rem;
    color: var(--text-muted);
    line-height: 1.55;
}

.editor-modal-desc a {
    color: var(--accent);
    text-decoration: underline;
}

.editor-modal-desc code {
    font-family: "DM Mono", monospace;
    font-size: 0.82em;
    background: var(--bg-hover);
    padding: 1px 4px;
    border-radius: 3px;
}

.editor-modal-label {
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
}

.editor-modal-input {
    background: var(--bg-body);
    border: 1px solid var(--border);
    color: var(--text-main);
    border-radius: var(--radius-sm);
    padding: 8px 12px;
    min-height: 44px; /* control principal del modal: mínimo táctil */
    font:
        0.875rem "DM Mono",
        monospace;
    width: 100%;
    outline: none;
    transition:
        border-color 0.15s,
        box-shadow 0.15s;
}

.editor-modal-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-dim);
}

/* Estos modales enfocan el input al abrir (correcto: son de teclear), pero
   el foco por script en un campo de texto siempre pinta :focus-visible, y
   el anillo amarillo global chocaba con el borde acento del propio campo
   (doble anillo, parecía un fallo). Se armoniza al acento: sigue habiendo
   indicador de foco de 3px, solo cambia el color. Gana al global de
   components.css porque aquel usa :where() (especificidad cero). */
.editor-modal-input:focus-visible {
    outline-color: var(--accent) !important;
}

.editor-modal-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    flex-wrap: wrap;
}

/* ── Panel de revisión de cambios pendientes ─────────────────────────────── */
.editor-review-list {
    display: flex;
    flex-direction: column;
    max-height: 40vh;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}
.editor-review-item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 12px 14px;
    cursor: pointer;
}
.editor-review-item:not(:last-child) {
    border-bottom: 1px solid var(--border-subtle);
}
.editor-review-item input[type="checkbox"] {
    margin-top: 2px;
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    accent-color: var(--accent);
}
.editor-review-item-main {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
    font-size: 0.86rem;
}
.editor-review-item-main strong {
    font-weight: 600;
    color: var(--text-main);
}
.editor-review-item-sub {
    font-size: 0.76rem;
    color: var(--text-muted);
}
@media (hover: hover) {
    .editor-review-item:hover {
        background: var(--bg-hover);
    }
}

/* Compact modal when keyboard is open on mobile — toggled via JS (.modal-compact)
   using visualViewport.height, since @media (max-height) uses the layout viewport
   which does NOT change when the software keyboard opens. */
.modal-compact {
    padding: 8px !important;
    align-items: flex-start !important;
}

.modal-compact .editor-modal {
    padding: 16px !important;
    gap: 8px !important;
}

/* Toast */
.editor-toast {
    position: fixed;
    bottom: calc(80px + env(safe-area-inset-bottom, 0px));
    left: 50%;
    transform: translateX(-50%);
    z-index: var(--z-editor-toast);
    background: var(--bg-raised);
    border: 1px solid var(--border);
    color: var(--text-main);
    padding: 10px 20px;
    border-radius: 8px;
    font:
        500 14px system-ui,
        sans-serif;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
    white-space: normal;
    max-width: min(480px, calc(100vw - 32px));
    width: max-content;
    text-align: center;
    word-break: break-word;
}

.editor-toast-error {
    border-color: var(--err-color);
    color: var(--err-tx);
}

/* Camera rows marked for deletion */
tr.editor-deleted,
.camera-card.editor-deleted {
    opacity: 0.3;
    pointer-events: none;
    text-decoration: line-through;
}

@media (prefers-reduced-motion: no-preference) {
    .editor-toast {
        animation: toastIn 0.2s ease-out;
    }
    @keyframes toastIn {
        from {
            opacity: 0;
            transform: translateX(-50%) translateY(8px);
        }
        to {
            opacity: 1;
            transform: translateX(-50%) translateY(0);
        }
    }
}

/* ============================================
   ETIQUETAS — panel de edición
============================================ */
.ep-tags-field {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.ep-tags-head {
    display: flex;
    align-items: center;
    gap: 8px;
}

.ep-tags-head .ep-label {
    margin: 0;
}

.ep-tags-assigned-empty,
.ep-tags-catalog-empty {
    margin: 0;
    font-size: 0.78rem;
    color: var(--text-faint);
    line-height: 1.45;
}

.ep-tag-assigned-chips,
.ep-tag-catalog-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
}

.ep-tags-catalog {
    box-sizing: border-box;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    background: rgba(255, 255, 255, 0.04);
    overflow: hidden;
}

.ep-tags-catalog-summary {
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 8px;
    width: 100%;
    min-height: 44px;
    padding: 0 14px;
    margin: 0;
    border: none;
    border-radius: 0;
    background: transparent;
    cursor: pointer;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-muted);
    line-height: 1.2;
    list-style: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    transition: color 0.12s ease, background 0.12s ease;
}

.ep-tags-catalog-summary::-webkit-details-marker {
    display: none;
}

.ep-tags-catalog-summary::after {
    content: "";
    flex-shrink: 0;
    width: 7px;
    height: 7px;
    margin-left: auto;
    border-right: 1.5px solid var(--text-faint);
    border-bottom: 1.5px solid var(--text-faint);
    transform: rotate(45deg) translateY(-1px);
    transition: transform 0.15s var(--ease-out);
}

.ep-tags-catalog[open] .ep-tags-catalog-summary::after {
    transform: rotate(-135deg) translateY(1px);
}

@media (hover: hover) {
    .ep-tags-catalog-summary:hover {
        background: rgba(255, 255, 255, 0.04);
        color: var(--text-main);
    }
}

.ep-tags-catalog-summary:focus {
    outline: none;
}

.ep-tags-catalog-summary:focus-visible {
    outline: none;
    box-shadow: inset 0 0 0 2px var(--accent);
}

.ep-tags-catalog[open] .ep-tags-catalog-summary {
    border-bottom: 1px solid var(--border-subtle);
}

.ep-tags-catalog[open] .ep-tags-search {
    display: block;
    width: auto;
    margin: 10px 12px 8px;
}

.ep-tags-catalog[open] .ep-tag-catalog-chips {
    padding: 0 12px 4px;
}

.ep-tags-catalog[open] .ep-tags-catalog-empty {
    padding: 0 12px 10px;
}

.ep-tag-chip {
    padding: 4px 11px;
    border: none;
    border-radius: 99px;
    font-size: 0.75rem;
    font-weight: 500;
    font-family: inherit;
    color: var(--text-muted);
    background: rgba(255, 255, 255, 0.07);
    cursor: pointer;
    transition:
        background 0.12s ease,
        color 0.12s ease,
        border-color 0.12s ease,
        box-shadow 0.12s ease;
    line-height: 1.4;
}

@media (hover: hover) {
    .ep-tag-chip:hover {
        background: rgba(255, 255, 255, 0.13);
        color: var(--text-main);
    }
}

.ep-tag-chip.active {
    background: var(--accent);
    color: #fff;
}

.ep-tag-chip:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.ep-new-tag-row {
    display: flex;
    gap: 8px;
    align-items: center;
}

.ep-new-tag-row[hidden] {
    display: none !important;
}

.ep-new-tag-input {
    flex: 1;
    padding: 5px 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg-input, var(--bg-surface));
    color: var(--text-main);
    font: inherit;
    font-size: 0.8rem;
}

.ep-new-tag-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-dim);
}

/* Confirmar = ac-icon-success-btn; cancelar = ep-tag-del; añadir = ac-icon-accent-btn */

/* ── Tag item wrapper (chip + action) ── */
.ep-tag-item {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.ep-tag-item--assigned {
    gap: 4px;
}

.ep-tag-unassign,
.ep-tag-catalog-del {
    box-sizing: border-box;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 26px;
    height: 26px;
    min-width: 26px;
    min-height: 26px;
    padding: 0;
    margin: 0;
    border: none;
    border-radius: 999px;
    background: transparent;
    color: var(--text-faint);
    cursor: pointer;
    transition:
        opacity 0.12s,
        background 0.12s,
        color 0.12s,
        transform 0.08s var(--ease-out);
}

.ep-tag-unassign svg,
.ep-tag-catalog-del svg,
.ep-tag-del svg {
    width: var(--ac-icon-sm);
    height: var(--ac-icon-sm);
    pointer-events: none;
}

.ep-tag-unassign:focus-visible {
    opacity: 1;
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    color: var(--text-muted);
}

@media (hover: hover) {
    .ep-tag-unassign:hover {
        background: rgba(var(--err-rgb), 0.12);
        color: var(--err-color);
    }
}

.ep-tag-unassign:active {
    transform: scale(0.96);
}

/* Borrado del catálogo: visible dentro del acordeón */
.ep-tag-catalog-del {
    display: inline-flex;
    opacity: 0.55;
}

@media (hover: hover) {
    .ep-tags-catalog .ep-tag-catalog-del:hover {
        opacity: 1;
        background: rgba(var(--err-rgb), 0.12);
        color: var(--err-color);
    }
}

.ep-tag-catalog-del:focus-visible {
    outline: 2px solid var(--err-color);
    outline-offset: 2px;
    opacity: 1;
}

.ep-tag-del {
    box-sizing: border-box;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    min-width: 32px;
    min-height: 32px;
    padding: 0;
    margin: 0;
    border: none;
    border-radius: 999px;
    background: transparent;
    color: var(--text-faint);
    cursor: pointer;
    opacity: 0.55;
    transition:
        opacity 0.12s,
        background 0.12s,
        color 0.12s,
        transform 0.08s var(--ease-out);
}

.ep-tag-del:focus-visible {
    opacity: 1;
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

@media (hover: hover) {
    .ep-tag-item:hover .ep-tag-del {
        opacity: 1;
    }

    .ep-tag-del:hover {
        background: rgba(var(--err-rgb), 0.12);
        color: var(--err-color);
        opacity: 1;
    }
}

.ep-tag-del:active {
    transform: scale(0.96);
    background: rgba(var(--err-rgb), 0.18);
    opacity: 1;
}

#editor-pending-btn {
    position: relative;
}
/* .icon-btn pone display:flex como regla de autor, que gana al
   [hidden]{display:none} del user-agent por origen (no por especificidad) —
   sin esto el botón seguía pintándose vacío con el atributo hidden puesto,
   incluso fuera de modo edición y sin ningún cambio pendiente. */
#editor-pending-btn[hidden] {
    display: none;
}
.editor-pending-count {
    position: absolute;
    top: -2px;
    right: -2px;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    border-radius: 999px;
    background: var(--accent);
    color: #fff;
    font-size: 0.62rem;
    font-weight: 700;
    line-height: 16px;
    text-align: center;
    box-shadow: 0 0 0 2px var(--bg-body);
    pointer-events: none;
}

.editor-pending-count:empty {
    display: none;
}
