/**
 * D-One - Form Components Standard
 * Componenti standard per form elements (input, select, textarea, switch, toggle)
 * Versione: 1.0
 * Data: 2025-12-08
 * Owner: Pixel - Head of Product & UX
 */

/* ========================================
   BASE FORM ELEMENTS
   ======================================== */

.input,
.select,
.textarea {
    width: 100%;
    padding: var(--space-3);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    background: var(--bg-card);
    color: var(--text-primary);
    font-size: var(--font-size-base);
    font-family: var(--font-sans);
    transition: all 0.2s ease;
    box-sizing: border-box;
}

/* Input e Select compatti (simili a quick-nav-item: 2.25rem height) */
.input,
.select {
    padding: 0.5rem 0.75rem; /* Stesso padding verticale di quick-nav-item */
    font-size: var(--font-size-sm); /* Stesso font-size di quick-nav-item */
    height: 2.25rem; /* Stessa altezza di quick-nav-item */
    line-height: 1.2;
}

.input:focus,
.select:focus,
.textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.input:disabled,
.select:disabled,
.textarea:disabled {
    background: var(--bg-hover);
    color: var(--text-muted);
    cursor: not-allowed;
    opacity: 0.6;
}

.textarea {
    resize: vertical;
    min-height: 100px;
    line-height: 1.5;
}

/* ========================================
   LABELS
   ======================================== */

.option-group {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.option-group label {
    font-weight: var(--font-weight-medium);
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
    margin-bottom: var(--space-1);
}

.option-group.full-width {
    grid-column: 1 / -1;
}

/* ========================================
   OPTIONS GRID (per form con più campi)
   ======================================== */

.options-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--space-4);
}

@media (max-width: 768px) {
    .options-grid {
        grid-template-columns: 1fr;
    }
}

/* ========================================
   OPTIONS TOGGLE (Collapsible)
   ======================================== */

.advanced-options {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    margin-top: var(--space-4);
    overflow: hidden;
}

.options-toggle {
    width: 100%;
    padding: var(--space-4);
    background: var(--bg-card);
    border: none;
    display: flex;
    align-items: center;
    font-size: var(--font-size-base);
    font-weight: var(--font-weight-medium);
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.2s ease;
}

.options-toggle:hover {
    background: var(--bg-hover);
}

.toggle-icon {
    transition: transform 0.3s ease;
    margin-left: auto;
}

.options-toggle.active .toggle-icon,
.options-toggle[aria-expanded="true"] .toggle-icon {
    transform: rotate(180deg);
}

.options-content {
    padding: var(--space-5);
    border-top: 1px solid var(--border-color);
    animation: slideDown 0.3s ease;
}

.options-content.hidden {
    display: none;
}

@keyframes slideDown {
    from {
        opacity: 0;
        max-height: 0;
    }
    to {
        opacity: 1;
        max-height: 500px;
    }
}

/* ========================================
   TOGGLE BUTTONS (Tab-style)
   ======================================== */

.toggle-group {
    display: flex;
    gap: var(--space-2);
    border-bottom: 2px solid var(--border-color);
    padding-bottom: var(--space-3);
    margin-bottom: var(--space-4);
}

.toggle-btn {
    flex: 1;
    padding: var(--space-2) var(--space-3);
    background: transparent;
    border: none;
    border-bottom: 3px solid transparent;
    color: var(--text-secondary);
    cursor: pointer;
    font-weight: var(--font-weight-medium);
    font-size: var(--font-size-sm);
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
}

.toggle-btn:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
    border-radius: var(--radius-md) var(--radius-md) 0 0;
}

.toggle-btn.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
    font-weight: var(--font-weight-semibold);
}

/* ========================================
   SWITCH (Toggle Switch)
   ======================================== */

.switch {
    position: relative;
    display: inline-block;
    width: 48px;
    height: 24px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.switch-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--border-color);
    transition: 0.3s;
    border-radius: 24px;
}

.switch-slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: 0.3s;
    border-radius: 50%;
    box-shadow: var(--box-shadow);
}

.switch input:checked + .switch-slider {
    background-color: var(--primary);
}

.switch input:checked + .switch-slider:before {
    transform: translateX(24px);
}

.switch input:focus + .switch-slider {
    box-shadow: 0 0 0 3px var(--primary-light);
}

.switch input:disabled + .switch-slider {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Switch con label */
.switch-group {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

.switch-group label {
    font-size: var(--font-size-base);
    color: var(--text-primary);
    cursor: pointer;
    user-select: none;
}

/* ========================================
   CHECKBOX & RADIO (Custom Styled)
   ======================================== */

.checkbox-group,
.radio-group {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.checkbox-item,
.radio-item {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    cursor: pointer;
}

.checkbox-item input[type="checkbox"],
.radio-item input[type="radio"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: var(--primary);
}

.checkbox-item label,
.radio-item label {
    font-size: var(--font-size-base);
    color: var(--text-primary);
    cursor: pointer;
    user-select: none;
    margin: 0;
}

/* ========================================
   FILTER SELECT (per filtri/tabelle)
   ======================================== */

.filter-select {
    flex: 1;
    min-width: 180px;
    padding: 0.5rem 0.75rem; /* Allineato a input/select compatti */
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    background: var(--bg-card);
    color: var(--text-primary);
    font-size: var(--font-size-sm);
    height: 2.25rem; /* Stessa altezza di quick-nav-item */
    line-height: 1.2;
    cursor: pointer;
    transition: all 0.2s ease;
}

.filter-select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

/* ========================================
   RESPONSIVE
   ======================================== */

@media (max-width: 768px) {
    .input,
    .select {
        /* Mantieni dimensioni compatte anche su mobile */
        padding: 0.5rem 0.75rem;
        font-size: var(--font-size-sm);
        height: 2.25rem;
    }
    
    .textarea {
        font-size: var(--font-size-base);
        /* Textarea mantiene padding normale */
    }
    
    .filter-select {
        padding: 0.5rem 0.75rem;
        height: 2.25rem;
    }
    
    .toggle-group {
        flex-wrap: wrap;
    }
    
    .toggle-btn {
        min-width: 100px;
    }
    
    .options-grid {
        grid-template-columns: 1fr;
    }
}
