/* Tucutun - Comprehensive Responsive Design System */

/* Base Mobile-First Responsive Utilities */
:root {
    /* Mobile-first breakpoints */
    --breakpoint-xs: 480px;
    --breakpoint-sm: 640px;
    --breakpoint-md: 768px;
    --breakpoint-lg: 1024px;
    --breakpoint-xl: 1280px;
    --breakpoint-2xl: 1536px;
    
    /* Touch target sizes */
    --touch-target-min: 44px;
    --touch-target-comfortable: 48px;
    
    /* Mobile-specific spacing */
    --mobile-spacing: 1rem;
    --mobile-spacing-lg: 1.5rem;
}

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

/* Mobile-first font sizes */
@media (max-width: 768px) {
    :root {
        /* Ensure minimum 16px font size on mobile for readability */
        --font-size-xs: 0.875rem;  /* 14px */
        --font-size-sm: 1rem;       /* 16px */
        --font-size-base: 1.0625rem; /* 17px */
        --font-size-lg: 1.125rem;   /* 18px */
        --font-size-xl: 1.25rem;    /* 20px */
        --font-size-2xl: 1.5rem;    /* 24px */
        --font-size-3xl: 1.75rem;   /* 28px */
        --font-size-4xl: 2rem;      /* 32px */
    }
    
    /* Adjust base body font */
    body {
        font-size: 16px !important;
        -webkit-text-size-adjust: 100%;
        -ms-text-size-adjust: 100%;
    }
    
    /* Responsive headings */
    h1, .h1 { font-size: 1.75rem !important; }
    h2, .h2 { font-size: 1.5rem !important; }
    h3, .h3 { font-size: 1.25rem !important; }
    h4, .h4 { font-size: 1.125rem !important; }
    h5, .h5 { font-size: 1rem !important; }
    h6, .h6 { font-size: 0.875rem !important; }
}

/* ============================= */
/* MOBILE NAVIGATION */
/* ============================= */

/* Mobile navigation overlay */
.mobile-nav-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1075;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.mobile-nav-overlay.active {
    display: block;
    opacity: 1;
}

/* Mobile hamburger button */
.mobile-menu-toggle {
    display: none;
    width: var(--touch-target-min);
    height: var(--touch-target-min);
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: var(--radius-md);
    transition: background 0.2s ease;
}

.mobile-menu-toggle:hover {
    background: var(--color-surface);
}

.mobile-menu-toggle:active {
    transform: scale(0.95);
}

/* Hamburger icon animation */
.hamburger-icon {
    position: relative;
    width: 24px;
    height: 20px;
}

.hamburger-icon span {
    position: absolute;
    left: 0;
    width: 100%;
    height: 2px;
    background: var(--color-text-primary);
    transition: all 0.3s ease;
}

.hamburger-icon span:nth-child(1) { top: 0; }
.hamburger-icon span:nth-child(2) { top: 50%; transform: translateY(-50%); }
.hamburger-icon span:nth-child(3) { bottom: 0; }

/* Active state animation */
.mobile-menu-toggle.active .hamburger-icon span:nth-child(1) {
    transform: rotate(45deg) translateY(9px);
}

.mobile-menu-toggle.active .hamburger-icon span:nth-child(2) {
    opacity: 0;
}

.mobile-menu-toggle.active .hamburger-icon span:nth-child(3) {
    transform: rotate(-45deg) translateY(-9px);
}

/* Mobile navigation styles */
@media (max-width: 768px) {
    /* Header stays fixed at top on mobile */
    .header {
        padding: 0 var(--mobile-spacing);
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        z-index: 1100;
        background: var(--color-background);
        border-bottom: 1px solid var(--color-border);
    }
    
    /* Dashboard wrapper adjusts for fixed header */
    .dashboard-wrapper {
        margin-top: var(--header-height);
    }
    
    /* Sidebar mobile styles */
    .sidebar {
        position: fixed;
        top: var(--header-height);
        left: -100%;
        width: 280px !important;
        height: calc(100vh - var(--header-height));
        transition: left 0.3s ease;
        box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
        z-index: 1050;
    }
    
    .sidebar.mobile-open {
        left: 0;
    }
    
    /* Main content adjustment */
    .main-content {
        margin-left: 0 !important;
        padding-left: 0 !important;
        width: 100% !important;
    }
    
    /* Ensure collapsed state doesn't affect mobile */
    html.sidebar-collapsed .main-content,
    body.sidebar-collapsed .main-content {
        margin-left: 0 !important;
        width: 100% !important;
    }
    
    /* Bootstrap navbar mobile adjustments */
    .navbar {
        padding: 0.75rem 1rem !important;
    }
    
    .navbar-brand {
        font-size: 1.125rem !important;
    }
    
    .navbar-nav {
        padding: 1rem 0;
    }
    
    .navbar-nav .nav-link {
        padding: 0.75rem 1rem !important;
        font-size: 1rem !important;
    }
}

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

/* Table wrapper for horizontal scrolling */
.table-responsive-mobile {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0 -1rem;
    padding: 0 1rem;
}

@media (max-width: 768px) {
    /* Horizontal scrolling for tables */
    .table-responsive,
    table {
        display: block;
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    /* Prevent table from breaking layout */
    .table {
        min-width: 600px;
    }
    
    /* Card-based table layout for complex data */
    .table-card-mobile {
        display: none;
    }
    
    @media (max-width: 640px) {
        /* Hide regular table on very small screens */
        .table-responsive-cards .table {
            display: none;
        }
        
        /* Show card layout */
        .table-card-mobile {
            display: block;
        }
        
        .table-card-mobile .table-card-item {
            background: var(--color-background);
            border: 1px solid var(--color-border);
            border-radius: var(--radius-lg);
            padding: 1rem;
            margin-bottom: 1rem;
        }
        
        .table-card-mobile .table-card-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 0.75rem;
            padding-bottom: 0.75rem;
            border-bottom: 1px solid var(--color-border);
        }
        
        .table-card-mobile .table-card-body {
            display: grid;
            gap: 0.5rem;
        }
        
        .table-card-mobile .table-card-row {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 0.25rem 0;
        }
        
        .table-card-mobile .table-card-label {
            font-weight: 500;
            color: var(--color-text-secondary);
            font-size: 0.875rem;
        }
        
        .table-card-mobile .table-card-value {
            font-weight: 400;
            color: var(--color-text-primary);
        }
    }
}

/* ============================= */
/* TOUCH-FRIENDLY ELEMENTS */
/* ============================= */

/* Ensure minimum touch target sizes */
@media (hover: none) and (pointer: coarse) {
    /* Buttons in main content areas - NOT in card headers */
    .main-content > .btn,
    .modal .btn:not(.card-header .btn),
    form:not(.card-header form) .btn {
        min-height: var(--touch-target-min);
        min-width: var(--touch-target-min);
    }
    
    /* Card header buttons remain compact */
    .card-header .btn,
    .card-header button,
    .accordion-header .btn,
    .accordion-header button {
        min-height: auto !important;
        height: auto !important;
        padding: 0.5rem 0.875rem !important;
        font-size: 13px !important;
    }
    
    /* Form inputs */
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="tel"],
    input[type="number"],
    input[type="date"],
    input[type="time"],
    input[type="datetime-local"],
    select,
    textarea,
    .form-control,
    .form-select,
    .form-input,
    .form-textarea {
        min-height: var(--touch-target-comfortable);
        padding: 0.75rem 1rem !important;
        font-size: 16px !important; /* Prevents zoom on iOS */
        box-sizing: border-box !important;
    }
    
    /* Checkboxes and radio buttons */
    input[type="checkbox"],
    input[type="radio"] {
        width: 24px;
        height: 24px;
        margin: 0.5rem;
    }
    
    /* Links in navigation */
    .nav-link,
    .dropdown-item,
    .sidebar-nav-item {
        min-height: var(--touch-target-min);
        padding: 0.75rem 1rem !important;
    }
    
    /* Add spacing between interactive elements */
    .btn + .btn,
    .form-group + .form-group {
        margin-top: 0.75rem;
    }
}

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

/* Mobile layout adjustments */
@media (max-width: 768px) {
    /* Stack grid layouts */
    .stats-grid,
    .grid,
    [class*="grid-cols-"] {
        grid-template-columns: 1fr !important;
        gap: 1rem !important;
    }
    
    /* Stack flex layouts */
    .flex-row,
    .d-flex:not(.flex-column) {
        flex-direction: column !important;
    }
    
    /* Full width containers on mobile */
    .container,
    .container-fluid {
        padding-left: 1rem !important;
        padding-right: 1rem !important;
    }
    
    /* Remove all padding from page content wrappers on mobile */
    .page-content {
        padding: 0 !important;
    }
    
    /* Ensure main content has no extra padding */
    .main-content {
        padding: 0 !important;
    }
    
    /* Cards and panels */
    .card {
        border-radius: 0.75rem !important;
        margin-bottom: 1rem !important;
    }
    
    .card-body {
        padding: 1rem !important;
    }
    
    /* Page headers */
    .page-header {
        padding: 1rem !important;
        margin-bottom: 1rem !important;
    }
    
    .page-title {
        font-size: 1.5rem !important;
    }
    
    /* Breadcrumbs */
    .breadcrumb {
        font-size: 0.875rem !important;
        padding: 0.5rem 1rem !important;
        overflow-x: auto;
        white-space: nowrap;
    }
    
    /* Modals */
    .modal-dialog {
        margin: 0.5rem !important;
        max-width: calc(100% - 1rem) !important;
    }
    
    .modal-content {
        border-radius: 0.75rem !important;
    }
    
    /* Stat cards */
    .stat-card {
        padding: 1rem !important;
    }
    
    .stat-value {
        font-size: 1.5rem !important;
    }
    
    /* Two-column layouts to single column */
    [style*="grid-template-columns: 2fr 1fr"],
    [style*="grid-template-columns: 1fr 1fr"] {
        grid-template-columns: 1fr !important;
    }
}

/* Tablet adjustments */
@media (min-width: 769px) and (max-width: 1024px) {
    /* Sidebar adjustments */
    .sidebar {
        width: 220px !important;
    }
    
    .sidebar.collapsed {
        width: 60px !important;
    }
    
    /* Grid adjustments */
    .stats-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }
    
    /* Container padding */
    .container {
        padding-left: 1.5rem !important;
        padding-right: 1.5rem !important;
    }
}

/* ============================= */
/* FORM OPTIMIZATION */
/* ============================= */

@media (max-width: 768px) {
    /* Single column forms */
    .form-row,
    .row.g-3 {
        display: block !important;
    }
    
    .col,
    [class*="col-"] {
        width: 100% !important;
        max-width: 100% !important;
        padding-left: 0 !important;
        padding-right: 0 !important;
    }
    
    /* Full width inputs */
    .form-control,
    .form-select,
    .form-input,
    .form-textarea,
    input,
    select,
    textarea {
        width: 100% !important;
        box-sizing: border-box !important;
    }
    
    /* Form spacing */
    .form-group,
    .mb-3 {
        margin-bottom: 1.25rem !important;
    }
    
    /* Form labels */
    .form-label {
        margin-bottom: 0.5rem !important;
        font-size: 0.9375rem !important;
        font-weight: 500 !important;
    }
    
    /* Submit buttons */
    .form-actions,
    .d-grid {
        display: grid !important;
        gap: 0.75rem !important;
    }
    
    .form-actions .btn,
    .d-grid .btn {
        width: 100% !important;
        justify-content: center !important;
    }
}

/* ============================= */
/* OVERFLOW AND VIEWPORT FIXES */
/* ============================= */

/* Prevent horizontal scroll */
* {
    max-width: 100vw;
}

body {
    overflow-x: hidden;
}

/* Fix for fixed elements */
@media (max-width: 768px) {
    .fixed,
    [style*="position: fixed"] {
        position: fixed !important;
        max-width: 100vw !important;
    }
}

/* ============================= */
/* UTILITY CLASSES */
/* ============================= */

/* Hide on mobile */
@media (max-width: 768px) {
    .hide-mobile {
        display: none !important;
    }
}

/* Show only on mobile */
.show-mobile {
    display: none !important;
}

@media (max-width: 768px) {
    .show-mobile {
        display: block !important;
    }
}

/* Text alignment on mobile */
@media (max-width: 768px) {
    .text-mobile-center {
        text-align: center !important;
    }
    
    .text-mobile-left {
        text-align: left !important;
    }
    
    .text-mobile-right {
        text-align: right !important;
    }
}

/* Margin and padding utilities for mobile */
@media (max-width: 768px) {
    .p-mobile-0 { padding: 0 !important; }
    .p-mobile-1 { padding: 0.25rem !important; }
    .p-mobile-2 { padding: 0.5rem !important; }
    .p-mobile-3 { padding: 1rem !important; }
    .p-mobile-4 { padding: 1.5rem !important; }
    
    .m-mobile-0 { margin: 0 !important; }
    .m-mobile-1 { margin: 0.25rem !important; }
    .m-mobile-2 { margin: 0.5rem !important; }
    .m-mobile-3 { margin: 1rem !important; }
    .m-mobile-4 { margin: 1.5rem !important; }
}

/* ============================= */
/* SECTION ACTION BUTTONS - FINAL OVERRIDE */
/* This MUST be at the end to override ALL other styles */
/* ============================= */

/* Reset ALL browser defaults for section-action buttons */
a.section-action,
button.section-action,
.section-action {
    /* Reset browser defaults */
    -webkit-appearance: none !important;
    -moz-appearance: none !important;
    appearance: none !important;
    box-sizing: border-box !important;
    margin: 0 !important;
    
    /* Exact sizing - matches across all elements */
    padding: 0.5rem 0.875rem !important;
    font-size: 0.8125rem !important;
    font-weight: 500 !important;
    line-height: 1.2 !important;
    
    /* Layout */
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 0.375rem !important;
    
    /* Reset height constraints */
    height: auto !important;
    min-height: unset !important;
    max-height: none !important;
    min-width: unset !important;
    
    /* Typography */
    font-family: inherit !important;
    text-decoration: none !important;
    text-align: center !important;
    white-space: nowrap !important;
    
    /* Appearance */
    border-radius: 6px !important;
    cursor: pointer !important;
    vertical-align: middle !important;
}

/* Icon sizing inside section-action */
a.section-action i,
button.section-action i,
.section-action i {
    font-size: 0.75rem !important;
    line-height: 1 !important;
    margin: 0 !important;
    padding: 0 !important;
}

/* ============================= */
/* PRINT STYLES */
/* ============================= */

@media print {
    .sidebar,
    .mobile-menu-toggle,
    .no-print {
        display: none !important;
    }
    
    .main-content {
        margin-left: 0 !important;
    }
}