/* ═══════════════════════════════════════════════════════════════ */
/* FaenaCore Portal - Responsive CSS for Mobile (Android)         */
/* ═══════════════════════════════════════════════════════════════ */

/* ─── Base resets for mobile ─── */
*, *::before, *::after {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
}

body {
    margin: 0;
    overflow-x: hidden;
}

/* ─── Ensure inputs are not zoomed on iOS/Android ─── */
input, select, textarea {
    font-size: 16px !important;
}

/* ─── Mobile overlay backdrop ─── */
.mobile-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 99;
    backdrop-filter: blur(2px);
}

.mobile-overlay.active {
    display: block;
}

/* ─── Mobile header (hidden on desktop) ─── */
.mobile-header {
    display: none;
    background: linear-gradient(135deg, #1a0533, #6b21a8);
    color: white;
    padding: 0.6rem 1rem;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 50;
}

.mobile-header .hamburger-btn {
    background: rgba(255,255,255,0.15);
    border: none;
    color: white;
    width: 40px;
    height: 40px;
    border-radius: 8px;
    font-size: 1.4rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.mobile-header .app-title {
    font-weight: 700;
    font-size: 1.1rem;
}

/* ═══════════════════════════════════════════════════════════════ */
/* BREAKPOINT: Tablets and below (≤ 1024px)                       */
/* ═══════════════════════════════════════════════════════════════ */
@media (max-width: 1024px) {
    /* Sidebar becomes overlay */
    .sidebar {
        position: fixed !important;
        top: 0;
        left: 0;
        bottom: 0;
        z-index: 100;
        transform: translateX(-100%);
        transition: transform 0.3s ease !important;
        width: 280px !important;
    }

    .sidebar.mobile-open {
        transform: translateX(0) !important;
    }

    .sidebar.collapsed {
        transform: translateX(-100%) !important;
        width: 280px !important;
    }

    .mobile-header {
        display: flex !important;
    }

    .mobile-overlay {
        display: none;
    }

    .mobile-overlay.active {
        display: block;
    }

    /* Main content takes full width */
    .app-main-content {
        width: 100% !important;
        margin-left: 0 !important;
    }

    /* Top bar adjustments */
    .app-topbar {
        padding: 0.5rem 0.75rem !important;
        flex-wrap: wrap;
        gap: 0.25rem;
    }

    .app-topbar .topbar-info {
        font-size: 0.75rem !important;
    }

    .app-topbar .topbar-actions {
        gap: 0.4rem !important;
    }

    /* ─── Templates page responsive ─── */
    .templates-layout {
        flex-direction: column !important;
        height: auto !important;
        min-height: calc(100vh - 100px) !important;
    }

    .templates-sidebar {
        width: 100% !important;
        min-width: unset !important;
        max-width: unset !important;
        max-height: 45vh !important;
        flex-shrink: 0;
    }

    .templates-detail {
        flex: 1 !important;
        min-height: 50vh;
    }

    /* ─── Section cards bigger on tablet ─── */
    .section-card {
        padding: 0.8rem 1rem !important;
    }

    .section-card-header {
        padding: 0.7rem 1rem !important;
    }

    .section-card-header strong {
        font-size: 1rem !important;
    }
}

/* ═══════════════════════════════════════════════════════════════ */
/* BREAKPOINT: Mobile phones (≤ 768px)                            */
/* ═══════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
    /* Font sizes adapted */
    h2 { font-size: 1.1rem !important; }
    h3 { font-size: 0.95rem !important; }
    h4 { font-size: 0.85rem !important; }

    /* ─── Login screen responsive ─── */
    .login-card {
        width: 90% !important;
        max-width: 400px;
        padding: 1.5rem !important;
    }

    .login-grid {
        grid-template-columns: 1fr !important;
    }

    /* ─── Page padding reduced ─── */
    .page-padding {
        padding: 0.5rem !important;
    }

    /* ─── Grids: 4 cols → 2 cols ─── */
    .grid-4 {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    /* ─── Grids: 3 cols → 2 cols ─── */
    .grid-3 {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    /* ─── Cards ─── */
    .card-responsive {
        padding: 0.75rem !important;
        margin-bottom: 0.5rem;
    }

    /* ─── Tables scrollable ─── */
    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* ─── Top bar simplified ─── */
    .app-topbar {
        padding: 0.4rem 0.5rem !important;
        font-size: 0.7rem !important;
    }

    .app-topbar .online-badge {
        display: none !important;
    }

    .app-topbar .user-name {
        display: none !important;
    }

    /* ─── Templates page: stacked layout ─── */
    .templates-layout {
        flex-direction: column !important;
        height: auto !important;
        padding: 0.5rem !important;
    }

    .templates-sidebar {
        width: 100% !important;
        min-width: unset !important;
        max-width: unset !important;
    }

    /* ─── Template list items bigger touch targets ─── */
    .template-list-item {
        padding: 0.6rem 0.75rem !important;
        min-height: 44px;
    }

    .template-list-item span {
        font-size: 0.85rem !important;
    }

    /* ─── Section cards much bigger on mobile ─── */
    .section-card {
        border-radius: 10px !important;
        margin-bottom: 1rem !important;
    }

    .section-card-header {
        padding: 0.8rem 1rem !important;
        flex-wrap: wrap;
        gap: 0.3rem;
    }

    .section-card-header strong {
        font-size: 1.05rem !important;
    }

    .section-card-header .section-btns {
        gap: 0.4rem;
    }

    .section-card-header .section-btns button {
        padding: 0.35rem 0.7rem !important;
        font-size: 0.8rem !important;
    }

    /* ─── Item rows: bigger touch targets ─── */
    .item-row {
        padding: 0.6rem 0.75rem !important;
        min-height: 40px;
        flex-wrap: wrap;
        gap: 0.3rem;
    }

    .item-row span {
        font-size: 0.9rem !important;
    }

    /* ─── Modal form: single column on mobile ─── */
    .modal-grid-2 {
        grid-template-columns: 1fr !important;
    }

    /* ─── Button actions row ─── */
    .action-row {
        flex-wrap: wrap !important;
    }

    .action-row button {
        padding: 0.5rem 1rem !important;
        font-size: 0.8rem !important;
    }
}

/* ═══════════════════════════════════════════════════════════════ */
/* BREAKPOINT: Small phones (≤ 480px)                             */
/* ═══════════════════════════════════════════════════════════════ */
@media (max-width: 480px) {
    /* Grids: 2 cols → 1 col */
    .grid-4, .grid-3, .grid-2 {
        grid-template-columns: 1fr !important;
    }

    /* Even smaller fonts */
    h2 { font-size: 1rem !important; }
    h3 { font-size: 0.9rem !important; }

    /* Template detail header */
    .template-detail-header {
        padding: 0.75rem !important;
    }

    .template-detail-header h2 {
        font-size: 1rem !important;
    }

    .template-detail-header .template-actions {
        flex-wrap: wrap;
        gap: 0.3rem;
    }

    .template-detail-header .template-actions button {
        padding: 0.3rem 0.6rem !important;
        font-size: 0.7rem !important;
    }

    /* Section items add form */
    .add-item-form {
        grid-template-columns: 1fr !important;
    }
}

/* ═══════════════════════════════════════════════════════════════ */
/* Utility classes                                                */
/* ═══════════════════════════════════════════════════════════════ */
.hidden-mobile {
    display: inherit;
}

.visible-mobile {
    display: none !important;
}

@media (max-width: 768px) {
    .hidden-mobile {
        display: none !important;
    }
    .visible-mobile {
        display: inherit !important;
    }
}

/* ─── Smooth scrolling on mobile ─── */
@media (max-width: 1024px) {
    main {
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
}

/* ─── Touch-friendly scrollbar ─── */
@media (max-width: 768px) {
    ::-webkit-scrollbar {
        width: 4px;
        height: 4px;
    }
    ::-webkit-scrollbar-thumb {
        background: rgba(0,0,0,0.2);
        border-radius: 4px;
    }
}
