/* Mobile Responsiveness Enhancements */

.mobile-only {
    display: none !important;
}

.desktop-only {
    display: block !important;
}

/* Base mobile styles */
@media (max-width: 768px) {
    body {
        overflow-x: hidden;
    }

    body.has-mobile-nav {
        padding-bottom: 72px;
    }

    .max-w-7xl,
    .max-w-6xl,
    .max-w-4xl,
    .max-w-md {
        padding-left: 12px !important;
        padding-right: 12px !important;
    }

    nav .flex.items-center.space-x-4 {
        flex-direction: column;
        align-items: flex-end;
        flex-wrap: wrap;
        gap: 6px;
        justify-content: flex-end;
    }

    nav .flex.items-center.space-x-4 > * {
        margin-left: 0 !important;
    }

    nav .flex.items-center.space-x-4 a,
    nav .flex.items-center.space-x-4 button {
        font-size: 12px;
    }

    nav .h-16 {
        height: auto;
        min-height: 4rem;
    }

    nav .flex.justify-between.h-16 {
        align-items: flex-start;
        padding-top: 0.5rem;
        padding-bottom: 0.5rem;
    }

    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }

    .page-header-actions {
        width: 100%;
        flex-wrap: wrap;
        gap: 8px;
    }

    .page-header-actions > * {
        margin-left: 0 !important;
        width: 100%;
    }

    .page-header-actions a,
    .page-header-actions button {
        justify-content: center;
    }

    .page-header-actions form,
    .page-toolbar-actions form,
    .email-accounts-actions form {
        width: 100%;
        display: block;
    }

    .page-header-actions button,
    .page-toolbar-actions button,
    .page-toolbar-actions select,
    .email-accounts-actions button {
        width: 100%;
    }

    .page-toolbar {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }

    .page-toolbar-actions {
        width: 100%;
        flex-wrap: wrap;
        gap: 8px;
    }

    .page-toolbar-actions > * {
        margin-left: 0 !important;
        width: 100%;
    }

    .page-toolbar-actions a,
    .page-toolbar-actions button {
        justify-content: center;
    }

    .card-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }

    .card-actions {
        width: 100%;
        flex-wrap: wrap;
        gap: 8px;
        justify-content: flex-start;
    }

    .card-actions > * {
        width: 100%;
    }

    .card-actions a,
    .card-actions button {
        justify-content: center;
    }

    .page-footer-actions {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }

    .page-footer-actions > * {
        width: 100%;
    }

    .page-footer-actions a,
    .page-footer-actions button {
        justify-content: center;
        width: 100%;
    }

    .page-footer-group {
        width: 100%;
        flex-direction: column;
        gap: 8px;
    }

    .page-footer-group > * {
        width: 100%;
    }

    .form-actions {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }

    .form-actions > * {
        width: 100%;
    }

    .field-actions {
        flex-wrap: wrap;
        gap: 8px;
    }

    .field-actions > * {
        margin-left: 0 !important;
    }

    .email-accounts-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }

    .email-accounts-actions {
        flex-wrap: wrap;
        width: 100%;
        gap: 8px;
    }

    .email-accounts-actions > * {
        margin-left: 0 !important;
        width: 100%;
    }

    .email-accounts-actions a,
    .email-accounts-actions button {
        justify-content: center;
    }

    .email-accounts-empty-actions {
        display: flex;
        flex-direction: column;
        gap: 10px;
        align-items: stretch;
    }

    .email-accounts-empty-actions a {
        width: 100%;
        justify-content: center;
    }

    .email-accounts-empty-actions span {
        display: none;
    }

    .review-card-mobile .flex.space-x-2,
    .review-card-mobile .flex.items-center.space-x-2 {
        flex-wrap: wrap;
        gap: 8px;
    }

    .review-card-mobile .flex.space-x-2 > *,
    .review-card-mobile .flex.items-center.space-x-2 > * {
        margin-left: 0 !important;
    }

    .review-card-mobile .flex.space-x-2 button,
    .review-card-mobile .flex.space-x-2 a,
    .review-card-mobile .flex.items-center.space-x-2 button,
    .review-card-mobile .flex.items-center.space-x-2 a {
        width: 100%;
        justify-content: center;
    }

    .review-card-mobile .flex.items-center.justify-between {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }

    .review-card-mobile .flex.items-center.justify-between > .flex.space-x-2,
    .review-card-mobile .flex.items-center.justify-between > .flex.items-center.space-x-2 {
        width: 100%;
    }

    .review-card-mobile .flex.items-center.justify-between > .flex.space-x-2 + .flex.space-x-2,
    .review-card-mobile .flex.items-center.justify-between > .flex.items-center.space-x-2 + .flex.items-center.space-x-2 {
        margin-top: 6px;
    }

    .email-item-mobile .flex.items-start.justify-between {
        flex-direction: column;
        gap: 10px;
    }

    .email-item-mobile .flex.items-start.justify-between > .flex-1 {
        width: 100%;
    }

    .email-item-mobile .flex.items-start.justify-between > .flex.items-center,
    .email-item-mobile .flex.items-start.justify-between > .flex.flex-wrap {
        width: 100%;
        justify-content: flex-start;
    }

    .email-item-mobile .flex.flex-wrap.items-center.justify-end {
        width: 100%;
        justify-content: flex-start;
        gap: 8px;
    }

    .email-item-mobile .flex.flex-wrap.items-center.justify-end > * {
        width: 100%;
    }

    .email-item-mobile .flex.flex-wrap.items-center.justify-end a,
    .email-item-mobile .flex.flex-wrap.items-center.justify-end button {
        justify-content: center;
    }
    /* Navigation improvements */
    .mobile-nav {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: white;
        border-top: 1px solid #e5e7eb;
        padding: 8px 0;
        z-index: 50;
    }
    
    .mobile-nav-item {
        display: flex;
        flex-direction: column;
        align-items: center;
        padding: 8px 12px;
        text-decoration: none;
        color: #6b7280;
        font-size: 12px;
    }
    
    .mobile-nav-item.active {
        color: #3b82f6;
    }
    
    .mobile-nav-icon {
        width: 20px;
        height: 20px;
        margin-bottom: 4px;
    }

    /* Email list mobile optimization */
    .email-list-mobile {
        padding-bottom: 80px; /* Space for mobile nav */
    }
    
    .email-item-mobile {
        padding: 12px 16px;
        background: #ffffff !important;
        border: 1px solid #e5e7eb;
        border-radius: 12px;
        margin-bottom: 12px;
    }

    .email-item-mobile:active {
        background: #f9fafb !important;
    }

    .email-list-mobile {
        background: transparent;
    }

    .email-list-mobile > li {
        border-bottom: none !important;
    }
    
    .email-subject-mobile {
        font-size: 16px;
        font-weight: 600;
        color: #111827;
        margin-bottom: 4px;
        line-height: 1.3;
    }
    
    .email-preview-mobile {
        font-size: 14px;
        color: #6b7280;
        line-height: 1.4;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
    }
    
    .email-meta-mobile {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-top: 8px;
        font-size: 12px;
        color: #9ca3af;
    }

    /* Email editor mobile */
    .email-editor-mobile {
        padding: 16px;
        background: white;
        min-height: calc(100vh - 60px);
    }
    
    .email-editor-mobile .form-group {
        margin-bottom: 20px;
    }
    
    .email-editor-mobile input,
    .email-editor-mobile textarea {
        font-size: 16px; /* Prevents zoom on iOS */
        border-radius: 8px;
        border: 1px solid #d1d5db;
        padding: 12px;
    }
    
    .email-editor-mobile textarea {
        min-height: 200px;
        resize: vertical;
    }

    /* TinyMCE mobile optimization */
    .tinymce-mobile {
        border-radius: 8px;
        border: 1px solid #d1d5db;
    }
    
    .tinymce-mobile .tox-toolbar {
        padding: 8px;
        flex-wrap: wrap;
    }
    
    .tinymce-mobile .tox-tbtn {
        margin: 2px;
    }

    /* Action buttons mobile */
    .action-buttons-mobile {
        position: fixed;
        bottom: 80px;
        left: 16px;
        right: 16px;
        display: flex;
        gap: 12px;
        z-index: 40;
    }
    
    .action-btn-mobile {
        flex: 1;
        padding: 12px 16px;
        border-radius: 8px;
        font-weight: 600;
        text-align: center;
        text-decoration: none;
        border: none;
        font-size: 16px;
    }
    
    .action-btn-mobile.primary {
        background: #3b82f6;
        color: white;
    }
    
    .action-btn-mobile.secondary {
        background: #f3f4f6;
        color: #374151;
    }
    
    .action-btn-mobile.danger {
        background: #ef4444;
        color: white;
    }

    /* Modal mobile optimization */
    .modal-mobile {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 100;
        display: flex;
        align-items: flex-end;
    }
    
    .modal-content-mobile {
        background: white;
        border-radius: 16px 16px 0 0;
        padding: 24px;
        width: 100%;
        max-height: 80vh;
        overflow-y: auto;
    }

    /* Thread view mobile */
    .thread-mobile {
        padding: 16px;
        background: white;
    }
    
    .thread-header-mobile {
        margin-bottom: 20px;
        padding-bottom: 16px;
        border-bottom: 1px solid #e5e7eb;
    }
    
    .thread-subject-mobile {
        font-size: 18px;
        font-weight: 600;
        color: #111827;
        margin-bottom: 8px;
    }
    
    .thread-meta-mobile {
        font-size: 14px;
        color: #6b7280;
    }

    /* Message mobile */
    .message-mobile {
        margin-bottom: 20px;
        padding: 16px;
        background: #f9fafb;
        border-radius: 8px;
    }
    
    .message-header-mobile {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 12px;
    }
    
    .message-sender-mobile {
        font-weight: 600;
        color: #111827;
    }
    
    .message-time-mobile {
        font-size: 12px;
        color: #9ca3af;
    }
    
    .message-content-mobile {
        line-height: 1.6;
        color: #374151;
    }

    /* Signature management mobile */
    .signature-mobile {
        padding: 16px;
        background: white;
        border-radius: 8px;
        margin-bottom: 12px;
        border: 1px solid #e5e7eb;
    }
    
    .signature-name-mobile {
        font-weight: 600;
        color: #111827;
        margin-bottom: 8px;
    }
    
    .signature-content-mobile {
        color: #6b7280;
        font-size: 14px;
        line-height: 1.5;
    }

    /* Review cards mobile */
    .review-card-mobile {
        padding: 16px;
        background: white;
        border-radius: 8px;
        margin-bottom: 12px;
        border: 1px solid #e5e7eb;
    }
    
    .review-header-mobile {
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        margin-bottom: 12px;
    }
    
    .review-rating-mobile {
        display: flex;
        gap: 2px;
    }
    
    .review-content-mobile {
        line-height: 1.6;
        color: #374151;
        margin-bottom: 12px;
    }
    
    .review-meta-mobile {
        font-size: 12px;
        color: #9ca3af;
    }

    /* Utility classes */
    .mobile-hidden {
        display: none !important;
    }
    
    .mobile-only {
        display: block !important;
    }
    
    .desktop-only {
        display: none !important;
    }
    
    .text-mobile {
        font-size: 14px;
        line-height: 1.5;
    }
    
    .text-mobile-sm {
        font-size: 12px;
        line-height: 1.4;
    }
    
    .text-mobile-lg {
        font-size: 16px;
        line-height: 1.6;
    }
}

/* Tablet styles */
@media (min-width: 769px) and (max-width: 1024px) {
    .tablet-grid {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 16px;
    }
    
    .tablet-full {
        grid-column: 1 / -1;
    }
}

/* Touch-friendly improvements */
@media (hover: none) and (pointer: coarse) {
    .touch-target {
        min-height: 44px;
        min-width: 44px;
    }
    
    .btn-touch {
        padding: 12px 20px;
        font-size: 16px;
        border-radius: 8px;
    }
    
    .input-touch {
        padding: 12px;
        font-size: 16px;
        border-radius: 8px;
    }
}

/* Keep mobile surfaces light even when OS uses dark mode */
@media (prefers-color-scheme: dark) and (max-width: 768px) {
    .mobile-nav {
        background: #ffffff;
        border-top-color: #e5e7eb;
    }

    .mobile-nav-item {
        color: #6b7280;
    }

    .mobile-nav-item.active {
        color: #3b82f6;
    }

    .email-item-mobile {
        background: #ffffff;
        border-bottom-color: #f3f4f6;
    }

    .email-item-mobile:active {
        background: #f9fafb;
    }

    .email-subject-mobile {
        color: #111827;
    }

    .email-preview-mobile {
        color: #6b7280;
    }
}
