/* 
 * Karakal Mobile Optimizations
 * Responsive styles and mobile-specific adjustments
 */

/* -------------------------------- 
   TABLE OF CONTENTS:
   1. Global Mobile Adjustments
   2. Header & Navigation
   3. Sidebar
   4. Dashboard
   5. Calendar View
   6. Forms & Inputs
   7. Modals & Dialogs
   8. Cards & Lists
   9. Touch-optimized Controls
   10. Component-specific Mobile Styles
-------------------------------- */

/* -------------------------------- 
   1. Global Mobile Adjustments
-------------------------------- */

/* Global adjustments */
html {
    -webkit-text-size-adjust: 100%;
}

/* Mobile viewport settings */
@media (max-width: 768px) {

    body {
        font-size: 14px;
        padding: 8px;
    }

    h1 {
        font-size: 1.75rem;
    }

    h2 {
        font-size: 1.5rem;
    }

    h3 {
        font-size: 1.25rem;
    }

    h4 {
        font-size: 1.125rem;
    }

    .content-wrapper {
        padding: 1rem;
    }

    /* Improve touch experience */
    input,
    button,
    select,
    textarea,
    .btn {
        font-size: 16px;
        /* Prevents iOS zoom on focus */
    }

    /* Reduce margins and paddings */
    .page-header {
        margin-bottom: 1rem;
    }

    .dashboard-widget {
        margin-bottom: 1rem;
    }
}

/* -------------------------------- 
   2. Header & Navigation
-------------------------------- */

/* Mobile header */
@media (max-width: 768px) {
    .top-nav {
        padding: 0 0.75rem;
        height: 56px;
    }

    .logo-text {
        display: none;
    }

    .user-name {
        display: none;
    }

    /* Mobile menu button */
    .menu-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 40px;
        height: 40px;
        border: none;
        background: transparent;
        cursor: pointer;
        color: var(--text-primary);
    }

    /* Compact role switcher */
    .role-switcher {
        padding: 0.125rem;
    }

    .role-btn {
        padding: 0.375rem;
    }

    .role-text {
        display: none;
    }
}

/* Extra small screens */
@media (max-width: 576px) {
    .top-nav {
        padding: 0 0.5rem;
        height: 50px;
    }

    .nav-right {
        gap: 0.5rem;
    }
}

/* -------------------------------- 
   3. Sidebar
-------------------------------- */

/* Mobile sidebar - Popup menu */
@media (max-width: 768px) {
    /* The original sidebar is hidden via layout.css */

    /* Popup mobile sidebar styling */
    #mobile-sidebar {
        position: fixed;
        top: 70px;
        /* Position below the header */
        left: 50%;
        transform: translateX(-50%) scale(0.95);
        width: 280px;
        /* Fixed width that fits on mobile screens */
        max-height: calc(100vh - 100px);
        /* Ensure it doesn't overflow the viewport */
        overflow-y: auto;
        z-index: 1010;
        /* Higher than other elements */
        transition: all 0.2s ease-in-out;
        box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
        border-radius: 10px;
        border: 1px solid var(--border-color);
        background-color: var(--bg-primary);
        opacity: 0;
        visibility: hidden;
        padding-top: 40px;
        /* Space for close button */
        margin: 0;
        /* Reset any margins */
        display: block !important;
        pointer-events: none;
        /* Initially disable interactions */
    }

    /* Ensure the mobile sidebar has the same styling as the regular sidebar */
    #mobile-sidebar.visible {
        transform: translateX(-50%) scale(1);
        opacity: 1;
        visibility: visible;
        pointer-events: auto;
        /* Enable interactions when visible */
    }

    /* Overlay when sidebar is visible */
    .sidebar-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background-color: rgba(0, 0, 0, 0.5);
        z-index: 1005;
        /* Just below the sidebar but above other content */
        opacity: 0;
        transition: opacity 0.2s ease-in-out;
        pointer-events: none;
        /* Initially disable interactions */
    }

    .sidebar-overlay.visible {
        display: block;
        opacity: 1;
        pointer-events: auto;
        /* Enable interactions when visible */
    }

    /* Compact nav items */
    .nav-item a {
        padding: 0.75rem 1rem;
    }

    /* Make sure the main content area takes full width */
    .main-content {
        width: 100%;
        margin-left: 0;
    }

    /* Close button for the popup menu */
    .menu-close {
        display: flex;
        position: absolute;
        top: 10px;
        right: 10px;
        width: 36px;
        height: 36px;
        background: var(--bg-secondary);
        border: 1px solid var(--border-color);
        border-radius: 50%;
        color: var(--text-primary);
        cursor: pointer;
        padding: 0;
        align-items: center;
        justify-content: center;
        z-index: 1011;
        box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    }

    .menu-close:hover,
    .menu-close:focus {
        background: var(--bg-tertiary);
        color: var(--primary-color);
    }

    /* Fix for potential button styling issues */
    .menu-toggle {
        z-index: 1000;
    }

    /* Make the sidebar navigation more compact for popup style */
    .sidebar-nav {
        padding: 0;
    }

    .nav-section {
        margin-bottom: 0.75rem;
    }

    .nav-section-header {
        padding: 0.25rem 1rem;
        font-size: 0.75rem;
    }
}

/* -------------------------------- 
   4. Dashboard
-------------------------------- */

/* Mobile dashboard */
@media (max-width: 768px) {

    /* Stack stats in columns on small screens */
    .dashboard-stats {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.75rem;
    }

    .stat-card {
        padding: 0.75rem;
    }

    .stat-icon {
        width: 36px;
        height: 36px;
        font-size: 1.25rem;
    }

    .stat-value {
        font-size: 1.25rem;
    }

    /* Single column for dashboard widgets */
    .dashboard-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    /* Reduce padding in widget headers */
    .widget-header {
        padding: 0.75rem;
    }

    .widget-content {
        padding: 0.75rem;
    }
}

/* Extra small devices */
@media (max-width: 576px) {
    .dashboard-stats {
        grid-template-columns: 1fr;
    }

    .stat-card {
        margin-bottom: 0.5rem;
    }
}

/* -------------------------------- 
   5. Calendar View
-------------------------------- */

/* Mobile calendar */
@media (max-width: 768px) {

    /* Simplify calendar nav */
    .calendar-controls {
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    /* Keep the default flexbox behavior for desktop view */
    /* Only apply full width to dashboard mini calendar */
    .dashboard-widget .calendar-navigation {
        width: 100%;
        justify-content: space-between;
        margin-bottom: 0.5rem;
    }

    /* Smaller calendar days - use !important to override conflicts */
    .calendar-weekday {
        font-size: 0.75rem !important;
        padding: 0.5rem 0 !important;
    }

    .calendar-day {
        height: auto !important;
        min-height: 40px !important;
        font-size: 0.875rem !important;
    }

    /* Adjust time slot view */
    .time-slots-grid {
        grid-template-columns: repeat(3, 1fr);
    }

    .time-slot-button {
        padding: 0.5rem;
        font-size: 0.8125rem;
    }
}

/* Extra small screens */
@media (max-width: 576px) {
    .calendar-weekday {
        padding: 0.25rem 0 !important;
    }

    .calendar-day {
        min-height: 36px !important;
    }

    .time-slots-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* -------------------------------- 
   6. Forms & Inputs
-------------------------------- */

/* Mobile-optimized forms */
@media (max-width: 768px) {

    /* Enlarge input targets for touch */
    .form-input,
    .form-select,
    .form-textarea {
        padding: 0.625rem;
        font-size: 16px;
        /* Prevent iOS zoom */
        min-height: 44px;
    }

    .form-checkbox,
    .form-radio {
        width: 20px;
        height: 20px;
    }

    /* Stack form controls on mobile */
    .form-row {
        flex-direction: column;
    }

    .form-group {
        margin-right: 0;
        margin-bottom: 0.75rem;
    }

    /* Enlarge date/time inputs */
    input[type="date"],
    input[type="time"] {
        height: 44px;
    }

    /* Adjust filters bar */
    .filters-bar {
        flex-direction: column;
        align-items: stretch;
        padding: 0.75rem;
    }

    .filter-group {
        margin-bottom: 0.5rem;
    }
}

/* -------------------------------- 
   7. Modals & Dialogs
-------------------------------- */

/* Mobile modals - New popup style */
@media (max-width: 768px) {
    .modal-content {
        position: relative !important;
        width: 90% !important;
        max-width: 350px !important;
        margin: 0 auto !important;
        height: auto !important;
        max-height: 85vh !important;
        border-radius: 10px !important;
        box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2) !important;
        transition: transform 0.2s ease-in-out, opacity 0.2s ease-in-out !important;
    }

    /* Handle larger size modals on mobile */
    .modal-content.modal-lg,
    .modal-content.modal-xl {
        max-width: 90% !important;
    }

    .modal-content.modal-full {
        min-width: 100%;
        min-height: 100%;
    }

    /* Special sizing for specific modal types */
    .modal-content {
        height: 100vh;
        max-height: 100vh;
        border-radius: 0;
        top: 0;
    }

    .modal:not(.hidden) .modal-content {
        transform: scale(1) !important;
        opacity: 1 !important;
    }

    .modal {
        padding: 0 !important;
    }

    /* Override the default animation for mobile */
    .modal:not(.active):not(.hidden) .modal-content {
        opacity: 1 !important;
    }

    /* Ensure pointers work correctly */
    .modal:not(.hidden) {
        pointer-events: auto !important;
    }

    /* Backdrop blur effect */
    .modal-overlay {
        backdrop-filter: blur(2px) !important;
    }

    .modal-header {
        height: 56px;
        padding: 0 1rem;
        display: flex;
        align-items: center;
        justify-content: space-between;
    }

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

    .modal-footer {
        padding: 0.75rem 1rem;
    }

    .modal-close {
        width: 36px !important;
        height: 36px !important;
        background: var(--bg-secondary) !important;
        border: 1px solid var(--border-color) !important;
        border-radius: 50% !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1) !important;
        font-size: 0 !important;
        /* Hide text content if any */
        position: absolute !important;
        right: 10px !important;
        top: 10px !important;
        z-index: 10 !important;
    }

    .modal-close:hover,
    .modal-close:focus {
        background: var(--bg-tertiary) !important;
        color: var(--primary-color) !important;
    }

    /* Ensure SVG is visible and sized correctly */
    .modal-close svg {
        width: 18px !important;
        height: 18px !important;
        display: block !important;
    }

    /* Consistent styling with the sidebar popup */
    .modal-content {
        background-color: var(--bg-primary);
    }

    /* Animation */
    @keyframes modalSlideIn {
        from {
            transform: translateY(-20px) scale(0.95);
            opacity: 0;
        }

        to {
            transform: translateY(0) scale(1);
            opacity: 1;
        }
    }
}


/* -------------------------------- 
   8. Cards & Lists
-------------------------------- */

/* Mobile-optimized cards */
@media (max-width: 768px) {
    .card {
        margin-bottom: 1rem;
    }

    .card-header {
        padding: 0.75rem;
    }

    .card-body {
        padding: 0.75rem;
    }

    .card-footer {
        padding: 0.75rem;
    }

    /* Booking cards on mobile */
    .booking-card {
        padding: 0.75rem;
    }

    .booking-card-footer {
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .booking-card-footer .btn {
        flex: 1;
    }

    /* Meeting type cards */
    .meeting-type-cards {
        grid-template-columns: 1fr;
    }

    .meeting-type-card {
        margin-bottom: 0.75rem;
    }

    /* Timeline items */
    .timeline-item {
        flex-direction: column;
    }

    .timeline-time {
        width: 100%;
        margin-bottom: 0.25rem;
    }
}

/* -------------------------------- 
   9. Touch-optimized Controls
-------------------------------- */

/* Touch-friendly controls */
@media (max-width: 768px) {

    /* Increase touch target size for better UX */
    .btn,
    .nav-item a,
    .tab-button,
    .form-input,
    .form-select {
        min-height: 16px;
    }

    /* Tab buttons should be easier to tap */
    .tab-button {
        flex: 1;
        text-align: center;
        white-space: nowrap;
    }

    /* Ensure sufficient spacing between touchable elements */
    .btn+.btn {
        margin-left: 0.5rem;
    }

    /* Adjust button groups for touch */
    .btn-group .btn {
        padding-left: 0.75rem;
        padding-right: 0.75rem;
    }

    /* Checkbox and radio enhancements */
    input[type="checkbox"],
    input[type="radio"] {
        transform: scale(1.2);
    }

    label {
        display: inline-flex;
        align-items: center;
        min-height: 44px;
    }
}

/* -------------------------------- 
   10. Component-specific Mobile Styles
-------------------------------- */

/* Mobile view switcher */
@media (max-width: 768px) {
    .view-switcher {
        width: 100%;
        justify-content: center;
        margin-top: 0.5rem;
    }

    .view-switcher .btn {
        flex: 1;
    }
}

/* Mobile-friendly tabs */
@media (max-width: 768px) {
    .tabs-header {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        white-space: nowrap;
        padding-bottom: 4px;
    }

    .tab-button {
        padding: 0.625rem 0.75rem;
    }
}

/* Mobile wizard steps */
@media (max-width: 768px) {
    .wizard-steps {
        overflow-x: auto;
        padding-bottom: 0.5rem;
        margin-bottom: 1rem;
        -webkit-overflow-scrolling: touch;
    }

    .wizard-step {
        min-width: 120px;
    }

    .wizard-footer {
        position: sticky;
        bottom: 0;
        background-color: var(--bg-primary);
        padding: 0.75rem 0;
        margin-top: 1rem;
        box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
    }
}

/* Mobile date-time picker */
@media (max-width: 768px) {
    .date-time-picker {
        flex-direction: column;
    }

    .calendar-container {
        width: 100%;
        margin-right: 0;
        margin-bottom: 1rem;
    }

    .time-slots-container {
        width: 100%;
    }
}

/* Mobile notifications */
@media (max-width: 768px) {
    .notification-container {
        width: 100%;
        max-width: 100%;
        right: 0;
        bottom: 0;
    }

    .notification {
        margin: 0.5rem;
        border-radius: 8px;
    }
}

/* Mobile email template editor */
@media (max-width: 768px) {
    .editor-toolbar {
        overflow-x: auto;
        white-space: nowrap;
        padding-bottom: 4px;
    }
}

/* Mobile intake form builder */
@media (max-width: 992px) {
    .form-builder {
        flex-direction: column;
        grid-template-columns: 1fr !important;
        display: flex !important;
    }

    .form-builder-sidebar,
    .form-builder-properties {
        width: 100%;
        border: none !important;
        padding: 0 !important;
        margin-bottom: 1rem;
    }

    .form-builder-content {
        width: 100%;
        margin: 1rem 0;
    }

    /* Special case for form builder modal - needs more space */
    .modal-content.modal-lg,
    .modal-content.modal-xl,
    [id*="formBuilder"] .modal-content,
    [id*="emailEditor"] .modal-content {
        max-width: 95% !important;
    }
}

/* Calendar override date modal */
@media (max-width: 768px) {
    .time-range-inputs {
        flex-direction: column;
    }

    .time-range-inputs input {
        margin-bottom: 0.5rem;
    }
}

/* Analytics charts */
@media (max-width: 768px) {
    .analytics-stats {
        grid-template-columns: repeat(2, 1fr);
    }

    .stat-card {
        padding: 0.75rem;
    }

    .chart-container {
        height: 200px;
    }
}

@media (max-width: 576px) {
    .analytics-stats {
        grid-template-columns: 1fr;
    }
}