/* ============================================================================
   legacy.css — stili per i moduli legacy (notifications.js, field-creator.js,
   pdf-editor.js) adattati alla shell nuova.

   Contiene:
   1) Sistema modale/notifiche (.modal-overlay/.modal/...) usato da notifications.js
      e dal modal "Configura Campo" di field-creator.js.
   2) Modale di progresso (.modal-progress/.progress-step/...).
   3) Pannelli dell'editor avanzato (#pdf-editor-toolbar, #pdf-properties-panel,
      #pdf-editor-controls, .pdf-editor-overlay, .toolbar-component, ...).

   I bottoni footer legacy usano classi .btn/.btn-primary: qui sono SCOPATI dentro
   .modal-footer per non collidere con la .btn della toolbar in /app/css/app.css.

   THEME-AWARE VIA TOKEN: tutte le superfici/bordi/testi usano i token del design
   system (--panel, --panel-2, --border, --text, --text-dim, --accent, --radius).
   Così luce/scuro seguono automaticamente il tema della shell → NON serve più il
   blocco :root[data-theme="dark"] con esadecimali duplicati (rimosso).
   Restano hardcoded solo: le pastiglie di stato colorate (badge success/error/
   warning/info) e i gradienti dell'editor avanzato, volutamente identitari.
   ============================================================================ */

/* ============================================================================
   1) SISTEMA MODALE / NOTIFICHE
   ============================================================================ */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    /* Scrim scuro in entrambi i temi (theme-agnostic). */
    background: rgba(0, 0, 0, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    opacity: 0;
    animation: legacyModalFadeIn 0.3s forwards;
    backdrop-filter: blur(4px);
}

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

.modal {
    background: var(--panel);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    max-width: 500px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow);
    animation: legacyModalSlideUp 0.3s ease;
    position: relative;
}

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

.modal-header {
    padding: 2rem 2rem 1rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 1rem;
}

.modal-icon {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    flex-shrink: 0;
}

/* Pastiglie di stato: colori fissi (badge), leggibili su modale chiara e scura. */
.modal-icon.success { background: #e8f5e9; color: #2e7d32; }
.modal-icon.error   { background: #ffebee; color: #c62828; }
.modal-icon.warning { background: #fff3e0; color: #e65100; }
.modal-icon.info    { background: #e3f2fd; color: #1565c0; }

.modal-title { flex: 1; }

.modal-title h2 {
    margin: 0;
    font-size: 1.5rem;
    color: var(--text);
}

.modal-title p {
    margin: 0.25rem 0 0;
    font-size: 0.9rem;
    color: var(--text-dim);
}

.modal-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-dim);
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.modal-close:hover {
    background: var(--panel-2);
    color: var(--text);
}

.modal-body {
    padding: 2rem;
}

.modal-body p {
    margin: 0 0 1rem;
    line-height: 1.6;
    color: var(--text-dim);
}

.modal-body ul {
    margin: 1rem 0;
    padding-left: 1.5rem;
}

.modal-body li {
    margin: 0.5rem 0;
    color: var(--text-dim);
}

.modal-body code {
    background: var(--panel-2);
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-size: 0.9em;
    color: var(--danger);
}

.modal-body pre {
    background: var(--panel-2);
    padding: 1rem;
    border-radius: 8px;
    overflow-x: auto;
    font-size: 0.85rem;
    margin: 1rem 0;
    white-space: pre-wrap;
    word-break: break-word;
}

.modal-footer {
    padding: 1rem 2rem 2rem;
    display: flex;
    gap: 0.75rem;
    justify-content: flex-end;
    flex-wrap: wrap;
}

/* Bottoni footer legacy — SCOPATI in .modal-footer per non collidere con la
   .btn della toolbar in app.css. Superfici/bordi via token. */
.modal-footer .btn,
.modal-footer .modal-btn {
    min-width: 100px;
    padding: 0.75rem 1.5rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    background: var(--panel-2);
    color: var(--text);
    transition: all 0.2s;
}

.modal-footer .btn:hover,
.modal-footer .modal-btn:hover {
    background: var(--panel);
    border-color: var(--accent);
}

.modal-footer .btn-primary,
.modal-footer .modal-btn.primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.modal-footer .btn-primary:hover,
.modal-footer .modal-btn.primary:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(43, 108, 255, 0.3);
}

/* .modal-btn usato anche nel modal "Configura Campo" di field-creator.js
   (fuori dal .modal-footer, ma qui e' sempre dentro .modal-footer). */

/* ============================================================================
   2) MODALE DI PROGRESSO
   ============================================================================ */
.loader {
    display: inline-block;
    width: 40px;
    height: 40px;
    border: 4px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: legacySpin 0.8s linear infinite;
}

@keyframes legacySpin {
    0%   { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.modal-progress {
    text-align: center;
}

.modal-progress .loader {
    margin: 2rem auto;
}

.modal-progress-text {
    font-size: 1.1rem;
    color: var(--text-dim);
    margin-top: 1rem;
}

.modal-progress-steps {
    margin-top: 1.5rem;
    text-align: left;
}

.progress-step {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    margin: 0.5rem 0;
    border-radius: 6px;
    background: var(--panel-2);
}

/* Tinte di stato con rgba: leggibili su panel-2 sia chiaro sia scuro. */
.progress-step.active {
    background: rgba(43, 108, 255, .14);
    border-left: 3px solid var(--accent);
}

.progress-step.completed {
    background: rgba(22, 163, 74, .15);
}

.progress-step-icon {
    font-size: 1.5rem;
}

.progress-step-text {
    flex: 1;
    font-size: 0.95rem;
    color: var(--text-dim);
}

.progress-step.active .progress-step-text {
    color: var(--accent);
    font-weight: 500;
}

.progress-step.completed .progress-step-text {
    color: #16a34a;
}

/* Modale responsive */
@media (max-width: 768px) {
    .modal {
        width: 95%;
        max-width: none;
    }
    .modal-header { padding: 1.5rem 1.5rem 0.75rem; }
    .modal-body   { padding: 1.5rem; }
    .modal-footer {
        padding: 0.75rem 1.5rem 1.5rem;
        flex-direction: column;
    }
    .modal-footer .btn,
    .modal-footer .modal-btn { width: 100%; min-height: 44px; }
    .modal-icon {
        width: 50px;
        height: 50px;
        font-size: 1.5rem;
    }
    .modal-title h2 { font-size: 1.25rem; }
}

/* ============================================================================
   3) EDITOR AVANZATO — barre e pannelli legacy (pdf-editor.js)
   Superfici/bordi/testi via token → dark mode automatica.
   ============================================================================ */

/* Barra controlli (top) */
.pdf-editor-controls {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: var(--panel);
    color: var(--text);
    border-bottom: 1px solid var(--border);
    padding: 0.75rem 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    z-index: 9999;
    box-shadow: var(--shadow);
}

.pdf-editor-controls.hidden { display: none; }

.controls-left,
.controls-center,
.controls-right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.controls-center {
    flex: 1;
    justify-content: center;
    gap: 1rem;
}

.control-btn {
    padding: 0.5rem 1rem;
    border: 1px solid var(--border);
    background: var(--panel);
    color: var(--text);
    border-radius: 6px;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.control-btn:hover:not(:disabled) {
    background: var(--panel-2);
    border-color: var(--accent);
}

.control-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.control-btn.icon-btn {
    padding: 0.5rem;
    font-size: 1.2rem;
    min-width: 36px;
}

/* Gradienti identitari dell'editor avanzato (invariati, ok su entrambi i temi). */
.control-btn.exit-btn {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    color: #fff;
    border: none;
    font-weight: 600;
}

.control-btn.exit-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(245, 87, 108, 0.3);
}

.control-btn.primary-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
    border: none;
    font-weight: 600;
}

.control-btn.primary-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

.control-divider {
    width: 1px;
    height: 24px;
    background: var(--border);
    margin: 0 0.25rem;
}

.control-checkbox {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    cursor: pointer;
    user-select: none;
    color: var(--text);
}

.control-checkbox input[type="checkbox"] { cursor: pointer; accent-color: var(--accent); }

.editor-title {
    font-weight: 600;
    font-size: 1rem;
    color: var(--text);
}

.field-counter {
    font-size: 0.875rem;
    color: var(--text-dim);
    background: var(--panel-2);
    padding: 0.25rem 0.75rem;
    border-radius: 12px;
}

/* Toolbar componenti (sinistra) */
.pdf-editor-toolbar {
    position: fixed;
    left: 0;
    top: 60px;
    bottom: 0;
    width: 280px;
    background: var(--panel);
    color: var(--text);
    border-right: 1px solid var(--border);
    z-index: 9998;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow);
}

.pdf-editor-toolbar.hidden { display: none; }

.toolbar-header {
    padding: 1rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.toolbar-close-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-dim);
    cursor: pointer;
    padding: 0;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.2s;
}

.toolbar-close-btn:hover {
    background: var(--panel-2);
    color: var(--text);
}

.toolbar-search {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
}

.toolbar-search input {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.875rem;
    background: var(--panel-2);
    color: var(--text);
}

.toolbar-components {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem;
}

.toolbar-component {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    margin-bottom: 0.5rem;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: grab;
    transition: all 0.2s;
    color: var(--text);
}

.toolbar-component:hover {
    background: var(--panel-2);
    border-color: var(--accent);
    transform: translateX(4px);
}

.toolbar-component:active { cursor: grabbing; }

.component-icon {
    font-size: 1.5rem;
    flex-shrink: 0;
}

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

.component-name {
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--text);
    margin-bottom: 0.125rem;
}

.component-desc {
    font-size: 0.75rem;
    color: var(--text-dim);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Pannello proprieta' (destra) */
.pdf-properties-panel {
    position: fixed;
    right: 0;
    top: 60px;
    bottom: 0;
    width: 300px;
    background: var(--panel);
    color: var(--text);
    border-left: 1px solid var(--border);
    z-index: 9998;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow);
}

.pdf-properties-panel.hidden { display: none; }

.properties-header {
    padding: 1rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.properties-content {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
}

.property-section { margin-bottom: 1.5rem; }

.property-section-title {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-dim);
    text-transform: uppercase;
    margin: 0 0 0.75rem 0;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border);
}

.property-field { margin-bottom: 1rem; }

.property-field label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text);
    margin-bottom: 0.375rem;
}

.property-input {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.875rem;
    font-family: inherit;
    background: var(--panel-2);
    color: var(--text);
    transition: border-color 0.2s;
}

.property-input:focus {
    outline: none;
    border-color: var(--accent);
}

.property-input-small {
    width: 80px;
    display: inline-block;
}

.property-value {
    padding: 0.5rem;
    background: var(--panel-2);
    border-radius: 6px;
    font-size: 0.875rem;
    color: var(--text-dim);
}

/* Overlay editor sopra il canvas */
.pdf-editor-overlay {
    background: transparent;
    user-select: none;
}

.pdf-field {
    border-radius: 4px;
    font-family: Arial, sans-serif;
    user-select: none;
}

.pdf-field.selected { z-index: 101 !important; }

.resize-handle {
    border-radius: 50%;
    transition: all 0.2s;
}

.resize-handle:hover { transform: scale(1.3); }

.no-selection-message {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-dim);
}

/* Scrollbar dei pannelli */
.toolbar-components::-webkit-scrollbar,
.properties-content::-webkit-scrollbar { width: 6px; }

.toolbar-components::-webkit-scrollbar-track,
.properties-content::-webkit-scrollbar-track { background: var(--panel-2); }

.toolbar-components::-webkit-scrollbar-thumb,
.properties-content::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

.toolbar-components::-webkit-scrollbar-thumb:hover,
.properties-content::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

/* Responsive editor */
@media (max-width: 1200px) {
    .pdf-editor-toolbar { width: 240px; }
    .pdf-properties-panel { width: 260px; }
}

@media (max-width: 968px) {
    .pdf-editor-controls {
        flex-wrap: wrap;
        gap: 0.5rem;
        padding: 0.5rem;
    }
    .controls-left,
    .controls-center,
    .controls-right {
        width: 100%;
        justify-content: space-between;
    }
    .pdf-editor-toolbar,
    .pdf-properties-panel {
        width: 100%;
        max-width: 320px;
    }
    .control-btn {
        font-size: 0.75rem;
        padding: 0.375rem 0.75rem;
    }
    .editor-title { font-size: 0.875rem; }
}

@media (max-width: 768px) {
    .pdf-editor-toolbar,
    .pdf-properties-panel {
        position: fixed;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        z-index: 10000;
        box-shadow: var(--shadow);
    }
    .pdf-properties-panel {
        transform: translateX(100%);
        left: auto;
        right: 0;
    }
    .pdf-editor-toolbar:not(.hidden),
    .pdf-properties-panel:not(.hidden) {
        transform: translateX(0);
    }
    .control-btn {
        min-height: 44px;
        min-width: 44px;
    }
    .resize-handle {
        width: 16px !important;
        height: 16px !important;
    }
    .property-input {
        min-height: 44px;
        font-size: 16px; /* evita zoom iOS */
    }
}

/* ============================================================================
   NOTA: il blocco :root[data-theme="dark"] con esadecimali duplicati è stato
   rimosso — ora le superfici usano i token (--panel/--panel-2/--border/--text/
   --text-dim/--accent) che virano da soli col tema. Le pastiglie di stato
   (.modal-icon.success/error/warning/info) e i gradienti dell'editor avanzato
   restano volutamente a colori fissi in entrambi i temi.
   ============================================================================ */
