/**
 * ============================================================================
 * LAYOUT.CSS - Layout & Structure
 * ============================================================================
 * Header, navigation, context menu, bottom bar, forms, buttons
 * Versione: 4.0 - Unified layout
 */

/* ============================================================================
   HEADER - FIXED AT TOP
   ============================================================================ */
.header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-height);
    background: var(--color-white);
    z-index: var(--z-fixed);
    box-shadow: var(--shadow-md);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 var(--space-4);
}

.header__left {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.header__context-btn {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    background: none;
    border: none;
    cursor: pointer;
    padding: var(--space-2);
    border-radius: var(--radius-md);
    transition: background var(--transition-fast);
}

.header__context-btn:hover {
    background: var(--color-gray-100);
}

.header__context-icon {
    font-size: 32px;
    line-height: 1;
}

.header__context-icon--static {
    padding: var(--space-2);
}

.header__context-label {
    font-size: var(--font-size-base);
    font-weight: var(--font-weight-semibold);
    color: var(--color-text-primary);
    white-space: nowrap;
}

/* ============================================================================
   HAMBURGER MENU BUTTON
   ============================================================================ */
.hamburger {
    width: 48px;
    height: 48px;
    background: var(--color-primary);
    border: none;
    border-radius: var(--radius-lg);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-md);
    transition: background var(--transition-fast);
    flex-shrink: 0;
    padding: 0;
}

.hamburger:hover {
    background: var(--color-primary-dark);
}

.hamburger:active {
    transform: scale(0.95);
}

.hamburger__lines {
    display: flex;
    flex-direction: column;
    gap: 5px;
    width: 22px;
}

.hamburger__lines span {
    display: block;
    height: 3px;
    background: var(--color-white);
    border-radius: 2px;
}

/* ============================================================================
   CONTEXT MENU (opened by contextual icon)
   ============================================================================ */
.context-menu {
    position: fixed;
    top: var(--header-height);
    left: var(--space-4);
    background: var(--color-white);
    border-radius: 0 0 var(--radius-xl) var(--radius-xl);
    box-shadow: var(--shadow-xl);
    min-width: 260px;
    max-width: 90vw;
    padding: var(--space-3) 0;
    z-index: calc(var(--z-fixed) - 1);
    display: none;
}

.context-menu--active {
    display: block;
    animation: slideDown 200ms ease;
}

.context-menu__list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.context-menu__item {
    border-bottom: 1px solid var(--color-gray-100);
}

.context-menu__item:last-child {
    border-bottom: none;
}

.context-menu__btn,
.context-menu__link {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    width: 100%;
    padding: var(--space-3) var(--space-4);
    background: none;
    border: none;
    cursor: pointer;
    font-size: var(--font-size-base);
    font-weight: var(--font-weight-semibold);
    color: var(--color-text-primary);
    text-decoration: none;
    transition: background var(--transition-fast);
    text-align: left;
}

.context-menu__btn:hover,
.context-menu__link:hover {
    background: var(--color-gray-50);
}

.context-menu__separator {
    height: 0;
    margin: var(--space-2) var(--space-4);
    border: 0;
    border-top: 1px solid var(--color-gray-200, #e2e8f0);
    list-style: none;
}

.context-menu__checkbox-label {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    cursor: pointer;
    font-size: var(--font-size-base);
    font-weight: var(--font-weight-semibold);
    color: var(--color-text-primary);
    transition: background var(--transition-fast);
}

.context-menu__checkbox-label:hover {
    background: var(--color-gray-50);
}

.context-menu__checkbox-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.context-menu__icon {
    font-size: var(--font-size-xl);
    flex-shrink: 0;
    width: 28px;
    text-align: center;
}

/* ============================================================================
   MAIN DROPDOWN MENU (hamburger)
   ============================================================================ */
.menu {
    position: fixed;
    top: var(--header-height);
    right: var(--space-4);
    background: var(--color-white);
    border-radius: 0 0 var(--radius-xl) var(--radius-xl);
    box-shadow: var(--shadow-xl);
    min-width: 280px;
    max-width: 90vw;
    max-height: calc(100vh - var(--header-height) - 16px);
    overflow-y: auto;
    padding: var(--space-5);
    z-index: calc(var(--z-fixed) - 1);
    display: none;
}

.menu--active {
    display: block;
    animation: slideDown 300ms ease;
}

.menu__user {
    padding: var(--space-3);
    background: var(--color-gray-50);
    border-radius: var(--radius-md);
    margin-bottom: var(--space-4);
    font-size: var(--font-size-base);
    font-weight: 500;
    color: var(--color-gray-700);
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.menu__section {
    margin-bottom: var(--space-5);
    padding-bottom: var(--space-4);
    border-bottom: 1px solid var(--color-gray-200);
}

.menu__section:last-child {
    border-bottom: none;
    margin-bottom: 0;
}

.menu__section-title {
    margin-bottom: var(--space-3);
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-semibold);
    color: var(--color-text-primary);
}

/* ============================================================================
   MENU ITEM - COLLAPSIBLE STRUCTURE
   ============================================================================ */
.menu__item {
    border-bottom: 1px solid var(--color-gray-200);
}

.menu__item:last-child {
    border-bottom: none;
}

/* Menu Item Header (clickable) */
.menu__item-header {
    width: 100%;
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-4) 0;
    background: none;
    border: none;
    cursor: pointer;
    font-size: var(--font-size-base);
    font-weight: var(--font-weight-semibold);
    color: var(--color-text-primary);
    transition: color var(--transition-fast);
    text-align: left;
}

.menu__item-header:hover {
    color: var(--color-primary);
}

.menu__item-icon {
    font-size: var(--font-size-xl);
    flex-shrink: 0;
}

.menu__item-title {
    flex: 1;
    text-align: left;
}

.menu__item-arrow {
    font-size: var(--font-size-sm);
    transition: transform var(--transition-fast);
    flex-shrink: 0;
}

.menu__item-header[aria-expanded="true"] .menu__item-arrow {
    transform: rotate(180deg);
}

/* Menu Item Content (collapsible) */
.menu__item-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 300ms ease;
}

.menu__item-content--active {
    max-height: 600px;
    padding-bottom: var(--space-4);
}

/* ============================================================================
   FORMS
   ============================================================================ */
.form__group {
    margin-bottom: var(--space-3);
}

.form__input,
.form__select {
    width: 100%;
    padding: var(--space-3);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    font-size: var(--font-size-base);
    font-family: inherit;
    transition: border-color var(--transition-fast);
}

.form__input:focus,
.form__select:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(33, 150, 243, 0.1);
}

.form__input--file {
    border: 2px dashed var(--color-border);
    cursor: pointer;
}

/* ============================================================================
   BUTTONS
   ============================================================================ */
.btn {
    display: inline-block;
    padding: var(--space-3) var(--space-5);
    border: none;
    border-radius: var(--radius-md);
    font-size: var(--font-size-base);
    font-weight: var(--font-weight-semibold);
    cursor: pointer;
    transition: all var(--transition-fast);
    text-align: center;
    font-family: inherit;
}

.btn:active {
    transform: translateY(1px);
}

.btn--primary {
    background: var(--color-primary);
    color: var(--color-white);
}

.btn--primary:hover {
    background: var(--color-primary-dark);
}

.btn--secondary {
    background: var(--color-secondary);
    color: var(--color-white);
}

.btn--success {
    background: var(--color-success);
    color: var(--color-white);
}

.btn--success:hover {
    background: #45A049;
}

.btn--danger {
    background: var(--color-danger);
    color: var(--color-white);
}

.btn--danger:hover {
    background: #E53935;
}

.btn--full {
    width: 100%;
}

/* ============================================================================
   BOTTOM BAR - FIXED AT BOTTOM
   ============================================================================ */
.bottom-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-4);
    background: var(--color-white);
    box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.1);
    z-index: var(--z-fixed);
}

.bottom-bar__btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-4);
    border: none;
    border-radius: var(--radius-md);
    font-size: var(--font-size-base);
    font-weight: var(--font-weight-semibold);
    cursor: pointer;
    transition: all var(--transition-fast);
    color: var(--color-white);
    font-family: inherit;
    white-space: nowrap;
}

.bottom-bar__btn.btn--primary {
    background: var(--color-primary);
}
.bottom-bar__btn.btn--primary:hover {
    background: var(--color-primary-dark);
}

.bottom-bar__btn.btn--success {
    background: var(--color-success);
}
.bottom-bar__btn.btn--success:hover {
    background: #45A049;
}

.bottom-bar__btn.btn--secondary {
    background: var(--color-secondary);
}

.bottom-bar__btn.btn--danger {
    background: var(--color-danger);
}
.bottom-bar__btn.btn--danger:hover {
    background: #E53935;
}

.bottom-bar__btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Add bottom padding to content when bottom bar is present */
.page-wrapper:has(.bottom-bar) .content-wrapper {
    padding-bottom: 80px;
}

/* ============================================================================
   MOBILE RESPONSIVE
   ============================================================================ */
@media (max-width: 768px) {
    .header {
        height: var(--header-height-mobile);
        padding: 0 var(--space-3);
    }

    .header__context-icon {
        font-size: 28px;
    }

    .header__context-label {
        font-size: var(--font-size-sm);
    }

    .hamburger {
        width: 42px;
        height: 42px;
    }

    .hamburger__lines {
        width: 18px;
        gap: 4px;
    }

    .hamburger__lines span {
        height: 2px;
    }

    .context-menu {
        top: var(--header-height-mobile);
        left: var(--space-3);
        min-width: 240px;
    }

    .menu {
        top: var(--header-height-mobile);
        min-width: 260px;
    }

    .bottom-bar {
        padding: var(--space-2) var(--space-3);
    }

    .bottom-bar__btn {
        font-size: var(--font-size-sm);
        padding: var(--space-2) var(--space-3);
    }
}
