/* ============================================
   MODAL & BUTTONS
   ============================================ */

/* ========== MODAL ========== */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal.open, .modal.active {
    display: flex;
}

.modal-content {
    background: white;
    border-radius: var(--radius);
    width: 90%;
    max-width: 600px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
}

.modal-small {
    max-width: 400px;
}

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

.modal-header h2 {
    font-size: 1.1rem;
    font-weight: 600;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--gray-500);
    padding: 0.25rem;
    line-height: 1;
}

.modal-close:hover {
    color: var(--gray-800);
}

.modal-body {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
}

.modal-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--gray-200);
    display: flex;
    gap: 0.75rem;
    justify-content: flex-end;
}

/* ========== BUTTONS ========== */
.btn-primary {
    background: var(--primary);
    color: white;
    border: none;
    padding: 0.6rem 1.25rem;
    border-radius: var(--radius);
    cursor: pointer;
    font-weight: 600;
    font-size: 0.85rem;
    transition: background 0.2s;
}

.btn-primary:hover {
    background: var(--primary-dark);
}

.btn-secondary {
    background: var(--gray-100);
    color: var(--gray-700);
    border: 1px solid var(--gray-300);
    padding: 0.6rem 1.25rem;
    border-radius: var(--radius);
    cursor: pointer;
    font-weight: 500;
    font-size: 0.85rem;
    transition: all 0.2s;
}

.btn-secondary:hover {
    background: var(--gray-200);
}

.btn-remove {
    background: var(--danger);
    color: white;
    border: none;
}

.btn-remove:hover {
    background: #b91c1c;
}

.btn-delete {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    background: var(--danger);
    color: white;
    border: none;
    border-radius: 4px;
    padding: 0.25rem 0.5rem;
    cursor: pointer;
    font-size: 0.7rem;
}

/* ========== LEGEND ITEMS ========== */
.legend-items {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    background: var(--gray-50);
    border-radius: 8px;
    border: 1px solid var(--gray-200);
}

.legend-item svg,
.legend-item-preview svg {
    width: 40px;
    height: 40px;
    flex-shrink: 0;
}

.legend-item-preview {
    width: 50px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.legend-item-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.legend-item-name,
.legend-item-desc {
    width: 100%;
    padding: 0.4rem 0.6rem;
    border: 1px solid var(--gray-300);
    border-radius: 6px;
    font-size: 0.85rem;
}

.legend-item-name:focus,
.legend-item-desc:focus {
    outline: none;
    border-color: var(--primary);
}

.legend-item-actions {
    display: flex;
    gap: 0.25rem;
}

.legend-item-actions button {
    padding: 0.4rem 0.6rem;
    border: 1px solid var(--gray-300);
    border-radius: 4px;
    background: white;
    cursor: pointer;
    font-size: 0.75rem;
}

.legend-item-actions button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.legend-item-remove {
    background: var(--danger);
    color: white;
    border: none;
    border-radius: 6px;
    width: 28px;
    height: 28px;
    cursor: pointer;
    font-size: 1rem;
}

.legend-empty {
    text-align: center;
    color: var(--gray-400);
    padding: 2rem;
}

/* ========== LEGEND PREVIEW ========== */
.modal-wide {
    max-width: 1000px;
    width: 95%;
}

.legend-modal-body {
    display: flex;
    gap: 1.5rem;
    min-height: 400px;
}

.legend-editor {
    flex: 1;
    min-width: 0;
}

.legend-editor h3,
.legend-preview-section h3 {
    margin: 0 0 1rem 0;
    font-size: 1rem;
    color: var(--gray-700);
    border-bottom: 1px solid var(--gray-200);
    padding-bottom: 0.5rem;
}

.legend-preview-section {
    flex: 0 0 350px;
    display: flex;
    flex-direction: column;
}

.legend-preview-box {
    flex: 1;
    background: #ffffff;
    border: 2px solid var(--gray-200);
    border-radius: 8px;
    padding: 1rem;
    overflow: auto;
    min-height: 300px;
}

.legend-preview-box svg {
    max-width: 100%;
    height: auto;
}

.legend-preview-actions {
    margin-top: 0.75rem;
    display: flex;
    justify-content: center;
}

.legend-preview-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--gray-400);
    font-style: italic;
}

@media (max-width: 768px) {
    .legend-modal-body {
        flex-direction: column;
    }
    .legend-preview-section {
        flex: none;
    }
}

/* ========== TOAST ========== */
.toast {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--gray-800);
    color: white;
    padding: 1rem 2rem;
    border-radius: var(--radius);
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    opacity: 0;
    transition: all 0.3s;
    z-index: 1100;
}

.toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}
