/* Mobile-First CSS for Flask Quote Management System */
/* Phase 1: Critical Display Fixes */

/* Mobile card styles */
.mobile-card-view {
    padding: 0 15px;
}

/* Mobile card header - two column layout (ID left, client right) */
.mobile-card-header {
    gap: 0.75rem;
    align-items: flex-start;
}

.mobile-card-id {
    display: flex;
    flex-direction: column;
    min-width: 50px;
    flex-shrink: 0;
}

.mobile-card-id .entity-type {
    font-size: 0.7rem;
    color: #6c757d;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    line-height: 1;
}

.mobile-card-id .entity-num {
    font-size: 0.95rem;
    font-weight: 600;
    color: #2c3e50;
    line-height: 1.2;
}

.mobile-card-client {
    flex: 1;
    min-width: 0; /* Allow text truncation */
}

/* Mobile card footer - compact badge/price/description row */
.mobile-card-footer {
    gap: 0.75rem;
    align-items: flex-start;
    padding-top: 0.5rem;
    border-top: 1px solid #f0f0f0;
}

.mobile-card-status {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    flex-shrink: 0;
    min-width: 60px;
}

.mobile-card-desc {
    line-height: 1.3;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.mobile-card {
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    transition: transform 0.2s ease;
}

.mobile-card:active {
    transform: scale(0.98);
}

.mobile-card-header .card-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: #2c3e50;
}

.detail-row {
    display: flex;
    align-items: center;
    margin-bottom: 8px;
    font-size: 0.9rem;
    color: #6c757d;
}

.detail-row i {
    width: 16px;
    text-align: center;
    color: #0d6efd;
}

.mobile-card-stats .stat-number {
    font-size: 1.2rem;
    font-weight: 600;
    color: #2c3e50;
}

.mobile-card-stats .stat-label {
    font-size: 0.75rem;
    color: #6c757d;
    text-transform: uppercase;
}

.mobile-card-actions .btn {
    min-height: 44px; /* Touch target compliance */
    font-size: 0.9rem;
}

/* Ensure proper spacing for touch */
.mobile-card-actions .btn-group .btn {
    border-radius: 0;
}

.mobile-card-actions .btn-group .btn:first-child {
    border-radius: 6px 0 0 6px;
}

.mobile-card-actions .btn-group .btn:last-child {
    border-radius: 0 6px 6px 0;
}

/* Mobile bottom navigation */
.mobile-bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: white;
    border-top: 1px solid #dee2e6;
    z-index: 1000;
    /* Respect iOS safe area */
    padding-bottom: env(safe-area-inset-bottom);
}

/* Spacer to prevent content being hidden behind fixed bottom nav */
.mobile-bottom-spacer {
    height: calc(64px + env(safe-area-inset-bottom));
}

.mobile-nav-container {
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding: 8px 0;
    max-width: 100%;
}

.mobile-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-decoration: none;
    color: #6c757d;
    font-size: 0.75rem;
    padding: 8px 12px;
    min-height: 44px; /* Touch target */
    min-width: 44px;
    border: none;
    background: none;
    transition: color 0.2s ease;
}

.mobile-nav-item:hover,
.mobile-nav-item.active {
    color: #0d6efd;
}

.mobile-nav-item i {
    font-size: 1.2rem;
    margin-bottom: 2px;
}

/* Mobile menu overlay */
.mobile-menu-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1050;
}

.mobile-menu {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: white;
    border-radius: 20px 20px 0 0;
    padding: 20px;
    transform: translateY(100%);
    transition: transform 0.3s ease;
}

.mobile-menu-overlay.show .mobile-menu {
    transform: translateY(0);
}

.mobile-menu-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 1px solid #dee2e6;
}

.mobile-menu-item {
    display: flex;
    align-items: center;
    padding: 15px 0;
    color: #2c3e50;
    text-decoration: none;
    font-size: 1rem;
    border-bottom: 1px solid #f8f9fa;
    min-height: 44px;
}

.mobile-menu-item:hover {
    color: #0d6efd;
    background: #f8f9fa;
    margin: 0 -20px;
    padding-left: 20px;
    padding-right: 20px;
}

.mobile-menu-divider {
    height: 1px;
    background-color: #dee2e6;
    margin: 10px 0;
}

/* Mobile-optimized forms */
.mobile-optimized-form {
    padding: 0;
}

.form-control-mobile {
    min-height: 44px; /* Touch target compliance */
    font-size: 16px; /* Prevent zoom on iOS */
    padding: 12px 16px;
    border-radius: 8px;
    border: 2px solid #e9ecef;
    transition: border-color 0.2s ease;
}

.form-control-mobile:focus {
    border-color: #0d6efd;
    box-shadow: 0 0 0 0.2rem rgba(13, 110, 253, 0.25);
    outline: none;
}

.form-label {
    font-weight: 600;
    color: #2c3e50;
    margin-bottom: 8px;
    font-size: 0.9rem;
}

.form-section {
    margin-bottom: 24px;
    padding: 20px 0;
}

.form-section-title {
    color: #0d6efd;
    font-weight: 600;
    margin-bottom: 16px;
    padding-bottom: 8px;
    border-bottom: 2px solid #e9ecef;
}

.btn-mobile {
    min-height: 44px; /* Touch target compliance */
    font-size: 1rem;
    padding: 12px 24px;
    border-radius: 8px;
    font-weight: 600;
}

.form-actions {
    display: flex;
    gap: 12px;
    padding: 20px 0;
}

.form-actions .btn-mobile {
    flex: 1;
}

/* Touch-optimized buttons */
.btn-touch {
    min-height: 44px;
    min-width: 44px;
    padding: 12px 16px;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.2s ease;
}

.btn-touch:active {
    transform: scale(0.98);
}

/* Action button groups with proper spacing */
.action-group {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.action-group .btn {
    flex: 1;
    min-width: 120px;
}

/* Status badges with better touch targets */
.status-badge-touch {
    padding: 8px 12px;
    font-size: 0.85rem;
    font-weight: 500;
    border-radius: 20px;
    min-height: 32px;
    display: inline-flex;
    align-items: center;
}

/* Quick action buttons */
.quick-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin: 16px 0;
}

.quick-action-btn {
    flex: 1;
    min-width: 120px;
    min-height: 44px;
    white-space: nowrap;
}

/* Mobile dashboard stats */
.dashboard-stats {
    margin-bottom: 24px;
}

.stat-card {
    background: white;
    border-radius: 16px;
    padding: 20px;
    border: 1px solid #e9ecef;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    height: 100%;
    display: flex;
    align-items: center;
    gap: 16px;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(0,0,0,0.12);
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    flex-shrink: 0;
}

.stat-card-primary .stat-icon {
    background: rgba(13, 110, 253, 0.1);
    color: #0d6efd;
    color: var(--entity-color-clients);
}

.stat-card-warning .stat-icon {
    background: rgba(255, 193, 7, 0.1);
    color: #ffc107;
    color: var(--entity-color-quotes);
}

.stat-card-success .stat-icon {
    background: rgba(25, 135, 84, 0.1);
    color: #198754;
    color: var(--entity-color-jobs);
}

.stat-card-info .stat-icon {
    background: rgba(13, 202, 240, 0.1);
    color: #0dcaf0;
}

.stat-card-orange .stat-icon {
    background: rgba(253, 126, 20, 0.1);
    color: #fd7e14;
    color: var(--entity-color-invoices);
}

.stat-content {
    flex: 1;
    min-width: 0;
}

.stat-number {
    font-size: 1.75rem;
    font-weight: 700;
    color: #2c3e50;
    line-height: 1;
    margin-bottom: 4px;
}

.stat-label {
    font-size: 0.85rem;
    color: #6c757d;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Hide inline icons on desktop - shown on mobile only */
.stat-icon-inline {
    display: none;
}

/* Responsive typography system */
:root {
    /* Base font sizes */
    --font-size-xs: 0.75rem;   /* 12px */
    --font-size-sm: 0.875rem;  /* 14px */
    --font-size-base: 1rem;    /* 16px */
    --font-size-lg: 1.125rem;  /* 18px */
    --font-size-xl: 1.25rem;   /* 20px */
    --font-size-2xl: 1.5rem;   /* 24px */
    --font-size-3xl: 1.875rem; /* 30px */
    
    /* Line heights */
    --line-height-tight: 1.25;
    --line-height-normal: 1.5;
    --line-height-relaxed: 1.75;
}

/* Mobile-first typography */
body {
    font-size: var(--font-size-base);
    line-height: var(--line-height-normal);
}

h1, .h1 {
    font-size: var(--font-size-2xl);
    line-height: var(--line-height-tight);
    font-weight: 700;
}

h2, .h2 {
    font-size: var(--font-size-xl);
    line-height: var(--line-height-tight);
    font-weight: 600;
}

h3, .h3 {
    font-size: var(--font-size-lg);
    line-height: var(--line-height-tight);
    font-weight: 600;
}

h4, .h4, h5, .h5, h6, .h6 {
    font-size: var(--font-size-base);
    line-height: var(--line-height-normal);
    font-weight: 600;
}

/* Small text */
.text-sm {
    font-size: var(--font-size-sm);
}

.text-xs {
    font-size: var(--font-size-xs);
}

/* Improved readability */
.readable-text {
    font-size: var(--font-size-base);
    line-height: var(--line-height-relaxed);
    color: #2c3e50;
}

.help-text {
    font-size: var(--font-size-sm);
    color: #6c757d;
    line-height: var(--line-height-normal);
}

/* Adjust main content for bottom nav */
@media (max-width: 992px) {
    .container {
        padding-bottom: 80px; /* Space for bottom nav */
    }
}

/* Mobile modal adjustments */
@media (max-width: 768px) {
    .modal-dialog {
        margin: 0;
        width: 100%;
        max-height: 100%;
        max-width: 100%;
    }

    .modal-content {
        max-height: 100vh;
        border: none;
        border-radius: 0;
        display: flex;
        flex-direction: column;
        /* Add shadow to ensure visibility when stacked */
        box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    }

    .modal-body {
        padding: 20px 15px;
        overflow-y: auto;
        flex: 0 1 auto; /* Allow shrinking, don't force expansion */
    }

    .modal-header {
        padding: 15px 15px 10px;
        border-bottom: 1px solid #dee2e6;
        background-color: #fff;
        position: relative;
        z-index: 1;
    }

    .modal-footer {
        padding: 10px 15px 15px;
        background-color: #f8f9fa;
        border-top: 1px solid #dee2e6;
    }

    /* Ensure modal body has white background */
    .modal-body {
        background-color: #fff;
    }
}

/* Mobile adjustments */
@media (max-width: 576px) {
    /* Compact stat cards for mobile - single row of 3 */
    .dashboard-stats {
        margin-bottom: 12px;
    }

    .dashboard-stats .row.g-3 {
        --bs-gutter-y: 0.5rem;
        --bs-gutter-x: 0.5rem;
    }

    .stat-card {
        padding: 8px 6px;
        border-radius: 10px;
        flex-direction: column;
        align-items: center;
        text-align: center;
        gap: 2px;
    }

    /* Hide boxed icon on mobile */
    .stat-card > .stat-icon {
        display: none;
    }

    .stat-content {
        display: flex;
        flex-direction: column;
        align-items: center;
    }

    .stat-number {
        font-size: 1.15rem;
        margin-bottom: 0;
        display: flex;
        align-items: center;
        gap: 4px;
    }

    /* Show inline icon on mobile */
    .stat-icon-inline {
        display: inline !important;
        font-size: 1rem;
    }

    .stat-card-warning .stat-icon-inline { color: #ffc107; color: var(--entity-color-quotes); }
    .stat-card-success .stat-icon-inline { color: #198754; color: var(--entity-color-jobs); }
    .stat-card-info .stat-icon-inline { color: #0dcaf0; }
    .stat-card-orange .stat-icon-inline { color: #fd7e14; color: var(--entity-color-invoices); }

    .stat-label {
        font-size: 0.65rem;
        letter-spacing: 0.2px;
        margin-top: 2px;
    }

    .quick-action-btn {
        min-width: 100%;
        margin-bottom: 8px;
    }
}

/* Mobile table adjustments */
@media (max-width: 767px) {
    /* Transform tables into card list on mobile */
    .table-responsive {
        overflow: visible;
        border: none;
    }

    .table-responsive table {
        border: 0;
    }

    .table-responsive thead {
        display: none; /* Hide table headers on mobile */
    }

    .table-responsive tbody {
        display: block;
    }

    .table-responsive tr {
        display: block;
        margin-bottom: 1rem;
        border: 1px solid #dee2e6;
        border-radius: 12px;
        box-shadow: 0 2px 8px rgba(0,0,0,0.08);
        background: white;
        padding: 1rem;
        cursor: pointer;
        transition: box-shadow 0.3s ease, min-height 0.3s ease;
        position: relative;
        min-height: 80px;
    }

    .table-responsive tr.expanded {
        box-shadow: 0 8px 24px rgba(0,0,0,0.25);
    }

    .table-responsive td {
        display: block;
        text-align: left;
        padding: 0.5rem 0;
        border: none;
        position: relative;
    }

    /* First cell (ID) has no top padding */
    .table-responsive td:first-child {
        padding-top: 0;
    }

    /* Last visible cell before actions has reduced bottom padding */
    .table-responsive td:not(.table-actions):last-of-type {
        padding-bottom: 0.25rem;
    }

    /* Override d-none d-md-table-cell to show Description on mobile cards */
    /* But NOT the ID cell which should stay hidden */
    .table-responsive td.d-none.d-md-table-cell:not(.mobile-hide) {
        display: block !important;
    }

    /* Limit description to exactly 3 lines */
    .description-cell {
        display: -webkit-box;
        -webkit-line-clamp: 3;
        -webkit-box-orient: vertical;
        overflow: hidden;
        text-overflow: ellipsis;
        line-height: 1.4;
        max-height: calc(1.4em * 3); /* 3 lines */
    }

    /* Content extends full width - buttons overlay on top */
    .table-responsive tr td:not(.table-actions) {
        padding-right: 0;
    }

    /* Hide old mobile dropdown toggle */
    .table-responsive tr .mobile-actions-toggle,
    .table-responsive tr .mobile-actions-dropdown {
        display: none !important;
    }

    /* Mobile action buttons (Call, Email) - icon only when collapsed */
    .btn-mobile-action {
        font-size: 0; /* Hide text when collapsed */
    }

    .btn-mobile-action .bi {
        font-size: 1rem;
    }

    /* Show text when expanded */
    tr.expanded .btn-mobile-action {
        font-size: 0.75rem;
    }

    tr.expanded .btn-mobile-action .bi {
        margin-right: 0.25rem;
    }

    /* Actions container - positioned absolutely on the right side, overlaying content */
    .table-actions {
        position: absolute !important;
        top: 0.5rem;
        right: 0.5rem;
        width: auto;
        height: auto;
        padding: 0 !important;
        margin: 0 !important;
        display: flex !important;
        flex-direction: column;
        align-items: center;
        justify-content: flex-start;
        gap: 0.5rem;
        z-index: 10;
        pointer-events: auto; /* Buttons are clickable */
    }

    /* Make sure action buttons don't affect content flow */
    .table-responsive td.table-actions {
        position: absolute !important;
        display: flex !important;
    }

    /* View button - icon only when collapsed */
    .table-actions .btn-view {
        display: flex !important;
        width: 44px;
        height: 44px;
        padding: 0;
        align-items: center;
        justify-content: center;
        border-radius: 8px;
        font-size: 0; /* Hide text when collapsed */
        box-shadow: 0 2px 4px rgba(0,0,0,0.1);
        white-space: nowrap;
        transition: width 0.3s ease;
    }

    /* Show icon only when collapsed */
    .table-actions .btn-view .bi {
        margin: 0;
        font-size: 1.2rem;
    }

    /* View button - show text when expanded */
    tr.expanded .table-actions .btn-view {
        width: auto;
        padding: 0.5rem 1rem;
        font-size: 0.875rem;
    }

    tr.expanded .table-actions .btn-view .bi {
        margin-right: 0.5rem;
        font-size: 1rem;
    }

    /* Hide desktop inline buttons by default */
    .table-actions .d-none.d-md-inline {
        display: none;
    }

    /* Show desktop actions on mobile when expanded */
    tr.expanded .table-actions .d-none.d-md-inline {
        display: flex !important;
        flex-direction: column;
        gap: 0.5rem;
        width: 100%;
        align-items: stretch;
    }

    /* Stack action buttons vertically when expanded - show text */
    tr.expanded .table-actions .d-none.d-md-inline .btn,
    tr.expanded .table-actions .d-none.d-md-inline form {
        display: block;
        width: auto;
        min-width: 120px;
        opacity: 0;
        transform: translateX(20px);
        animation: slideIn 0.3s ease forwards;
    }

    /* Stagger animation for each button */
    tr.expanded .table-actions .d-none.d-md-inline > *:nth-child(1) {
        animation-delay: 0s;
    }

    tr.expanded .table-actions .d-none.d-md-inline > *:nth-child(2) {
        animation-delay: 0.05s;
    }

    tr.expanded .table-actions .d-none.d-md-inline > *:nth-child(3) {
        animation-delay: 0.1s;
    }

    tr.expanded .table-actions .d-none.d-md-inline > *:nth-child(4) {
        animation-delay: 0.15s;
    }

    tr.expanded .table-actions .d-none.d-md-inline > *:nth-child(5) {
        animation-delay: 0.2s;
    }

    @keyframes slideIn {
        from {
            opacity: 0;
            transform: translateX(20px);
        }
        to {
            opacity: 1;
            transform: translateX(0);
        }
    }

    tr.expanded .table-actions .btn {
        min-height: 44px;
        width: auto;
        min-width: 120px;
        text-align: left;
        font-size: 0.875rem; /* Show text */
        padding: 0.5rem 1rem;
        border-radius: 8px;
        box-shadow: 0 2px 4px rgba(0,0,0,0.1);
        display: flex;
        align-items: center;
        justify-content: flex-start;
        white-space: nowrap;
    }

    /* Show icons with text */
    tr.expanded .table-actions .btn .bi {
        margin-right: 0.5rem;
        font-size: 1rem;
    }

    /* Status badge adjustments for card view */
    .status-badge {
        max-width: 100%;
        word-wrap: break-word;
        line-height: 1.2;
        padding: 0.5rem 0.75rem;
        text-align: center;
        display: inline-block;
    }

    .status-badge[data-short="true"] {
        white-space: nowrap;
    }

    .status-badge:not([data-short]) {
        white-space: normal;
    }

    /* Client info styling in card */
    .table td small {
        font-size: 0.85rem;
        line-height: 1.3;
        color: #6c757d;
    }


    /* Chevron indicator removed - actions are always visible on right side */
}

/* Mobile dropdown menu for actions */
.mobile-actions-dropdown {
    position: absolute;
    left: 0;
    top: 100%;
    background: white;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    z-index: 9999;
    min-width: 180px;
    display: none;
    overflow: hidden;
    margin-top: 4px;
}

.mobile-actions-dropdown.show {
    display: block;
}

.mobile-actions-dropdown .dropdown-item {
    display: flex;
    align-items: center;
    padding: 10px 16px;
    color: #212529;
    text-decoration: none;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
    font-size: 0.9rem;
    transition: background-color 0.2s ease;
}

.mobile-actions-dropdown .dropdown-item:hover {
    background-color: #f8f9fa;
}

.mobile-actions-dropdown .dropdown-item i {
    margin-right: 8px;
    width: 16px;
}

.mobile-actions-dropdown .dropdown-divider {
    height: 0;
    margin: 0.5rem 0;
    border-top: 1px solid #dee2e6;
}

/* Tablet and desktop scaling */
@media (min-width: 768px) {
    :root {
        --font-size-xs: 0.8rem;
        --font-size-sm: 0.9rem;
        --font-size-base: 1rem;
        --font-size-lg: 1.2rem;
        --font-size-xl: 1.35rem;
        --font-size-2xl: 1.75rem;
        --font-size-3xl: 2.25rem;
    }
}

@media (min-width: 1200px) {
    :root {
        --font-size-xs: 0.875rem;
        --font-size-sm: 1rem;
        --font-size-base: 1.125rem;
        --font-size-lg: 1.25rem;
        --font-size-xl: 1.5rem;
        --font-size-2xl: 2rem;
        --font-size-3xl: 2.5rem;
    }
}
