* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: #f4f5f7;
    color: #1f2937;
}

.container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 24px;
}

h1 {
    font-size: 1.6rem;
    margin: 0 0 20px;
}

h2 {
    font-size: 1.1rem;
    margin: 0 0 16px;
    color: #374151;
}

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

.panel-header h2 { margin: 0; }

.layout {
    display: grid;
    grid-template-columns: 1.2fr 1fr 0.9fr;
    gap: 20px;
}

@media (max-width: 1200px) {
    .layout { grid-template-columns: 1fr 1fr; }
    .list-panel { grid-column: 1 / -1; }
}

@media (max-width: 860px) {
    .layout { grid-template-columns: 1fr; }
    .list-panel { grid-column: auto; }
}

.form-panel, .preview-panel, .list-panel {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    padding: 20px;
}

.field { margin-bottom: 14px; }

.field-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.field-row-3 {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr;
    gap: 12px;
}

fieldset {
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 12px 14px;
    margin: 0 0 14px;
}

fieldset legend {
    font-size: 0.85rem;
    font-weight: 600;
    color: #4b5563;
    padding: 0 6px;
}

select {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 0.95rem;
    background: #fff;
}

select:focus {
    outline: none;
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

label {
    display: block;
    font-size: 0.9rem;
    font-weight: 600;
    margin-bottom: 6px;
    color: #374151;
}

input[type="text"],
input[type="number"],
input[type="file"] {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 0.95rem;
    background: #fff;
}

input[type="text"]:focus,
input[type="number"]:focus {
    outline: none;
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

small {
    display: block;
    margin-top: 4px;
    color: #6b7280;
    font-size: 0.8rem;
}

code {
    background: #f3f4f6;
    padding: 1px 5px;
    border-radius: 3px;
    font-size: 0.8rem;
}

button {
    background: #2563eb;
    color: #fff;
    border: none;
    padding: 10px 18px;
    font-size: 0.95rem;
    font-weight: 600;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.15s;
}

button:hover:not(:disabled) { background: #1d4ed8; }

button:disabled {
    background: #9ca3af;
    cursor: not-allowed;
}

.preview {
    min-height: 320px;
    background: #f9fafb;
    border: 1px dashed #d1d5db;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 12px;
    overflow: auto;
}

.preview canvas,
.preview img {
    max-width: 100%;
    height: auto;
    background: #fff;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.preview {
    flex-direction: column;
    gap: 10px;
}

.preview-caption {
    font-family: monospace;
    font-size: 0.85rem;
    color: #4b5563;
    text-align: center;
    word-break: break-all;
}

.placeholder {
    color: #9ca3af;
    font-style: italic;
    margin: 0;
}

.actions {
    margin-top: 12px;
    display: flex;
    justify-content: flex-end;
}

.status {
    margin-top: 10px;
    font-size: 0.9rem;
    color: #374151;
    min-height: 1.2em;
}

.status.error { color: #b91c1c; }

.field.checkbox {
    margin-top: 6px;
}

.field.checkbox label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 500;
    cursor: pointer;
}

.field.checkbox input[type="checkbox"] {
    width: auto;
    margin: 0;
}

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 10px;
    width: 100%;
}

.card {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    padding: 6px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.card img {
    width: 100%;
    height: auto;
    display: block;
}

.card small {
    font-size: 0.75rem;
    color: #4b5563;
    word-break: break-all;
    text-align: center;
}

.list-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.list-header h2 { margin: 0; }

.btn-sec {
    background: #e5e7eb;
    color: #111827;
    padding: 6px 12px;
    font-size: 0.85rem;
    font-weight: 500;
}

.btn-sec:hover:not(:disabled) { background: #d1d5db; }

.list-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 0;
    margin-bottom: 8px;
    border-bottom: 1px solid #e5e7eb;
}

.sel-all {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.85rem;
    cursor: pointer;
}

.sel-all input { width: auto; margin: 0; }

.sel-contador {
    font-size: 0.8rem;
    color: #6b7280;
}

.btn-primary.full {
    width: 100%;
    margin-bottom: 10px;
}

.sel-item {
    width: 20px !important;
    height: 20px;
    margin: 0;
    flex-shrink: 0;
    cursor: pointer;
    accent-color: #2563eb;
}

.lista-item:has(.sel-item:checked) {
    background: #eff6ff;
    border-color: #2563eb;
}

.lista-archivos {
    max-height: 480px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.lista-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 8px;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    cursor: pointer;
    background: #fff;
    transition: background 0.12s, border-color 0.12s;
}

.lista-item:hover {
    background: #f3f4f6;
    border-color: #9ca3af;
}

.lista-item img {
    width: 44px;
    height: 44px;
    object-fit: contain;
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 4px;
    flex-shrink: 0;
}

.lista-item .info {
    flex: 1;
    min-width: 0;
}

.lista-item .nombre {
    font-size: 0.85rem;
    font-weight: 600;
    color: #111827;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.lista-item .meta {
    font-size: 0.72rem;
    color: #6b7280;
}

.modal {
    position: fixed;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal.open { display: flex; }

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.6);
}

.modal-content {
    position: relative;
    background: #fff;
    border-radius: 10px;
    padding: 20px;
    max-width: 90vw;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
}

.modal-content img {
    max-width: 100%;
    max-height: 75vh;
    object-fit: contain;
    background: #fff;
    border: 1px solid #e5e7eb;
}

.modal-caption {
    font-family: monospace;
    font-size: 0.9rem;
    color: #374151;
    word-break: break-all;
    text-align: center;
}

.modal-close {
    position: absolute;
    top: 8px;
    right: 10px;
    background: transparent;
    color: #6b7280;
    font-size: 1.8rem;
    line-height: 1;
    padding: 0 8px;
    cursor: pointer;
}

.modal-close:hover { color: #111827; background: transparent; }

.modal-pdf {
    width: 90vw;
    height: 90vh;
    max-width: 1200px;
    max-height: none;
    padding: 12px;
    gap: 8px;
}

.modal-pdf-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    width: 100%;
    padding: 0 4px;
}

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

.modal-close-btn {
    background: #e5e7eb;
    color: #111827;
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 6px;
    font-size: 1.4rem;
    line-height: 1;
    cursor: pointer;
}

.modal-close-btn:hover { background: #d1d5db; }

#modalPdfFrame {
    flex: 1;
    width: 100%;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    background: #f3f4f6;
}
