/* ============================================================================
   RESPONSIVE FIXES FOR CLIENT ANALYSIS PAGE
   Comprehensive responsive design for mobile, tablet, iPad, and desktop
   ============================================================================ */

/* Base Viewport Settings */
* {
    -webkit-tap-highlight-color: transparent;
}

html {
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
}

/* ============================================================================
   TABS NAVIGATION - RESPONSIVE FIXES
   ============================================================================ */

.tabs-container {
    width: 100%;
    overflow-x: visible;
    position: relative;
}

.tabs-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: var(--color-primary-tint-30) transparent;
    padding: 8px 4px;
    margin-bottom: var(--spacing-xl);
    border-bottom: 3px solid var(--color-primary);
    background: linear-gradient(180deg, var(--color-primary-tint-05) 0%, transparent 100%);
    border-radius: var(--radius-md) var(--radius-md) 0 0;
}

/* Hide scrollbar but keep functionality */
.tabs-nav::-webkit-scrollbar {
    height: 6px;
}

.tabs-nav::-webkit-scrollbar-track {
    background: transparent;
}

.tabs-nav::-webkit-scrollbar-thumb {
    background: var(--color-primary-tint-30);
    border-radius: 3px;
}

.tabs-nav::-webkit-scrollbar-thumb:hover {
    background: var(--color-primary-border-strong);
}

.tab-button {
    padding: 10px 16px;
    background: transparent;
    border: none;
    border-bottom: 4px solid transparent;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    color: var(--color-text-secondary);
    transition: all 0.2s ease;
    position: relative;
    bottom: -3px;
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
    white-space: nowrap;
    flex-shrink: 0;
    min-width: fit-content;
    min-height: 44px; /* Touch target size */
    touch-action: manipulation;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.tab-button:hover {
    color: var(--color-primary);
    background: linear-gradient(180deg, var(--color-info-bg) 0%, var(--color-secondary-tint) 100%);
}

.tab-button.active {
    color: var(--color-primary);
    background: linear-gradient(180deg, var(--color-primary-tint-15) 0%, var(--color-secondary-tint-strong) 100%);
    font-weight: 700;
    border-bottom-color: var(--color-primary);
}

.tab-button.active::after {
    content: '';
    position: absolute;
    bottom: -3px;
    left: 0;
    right: 0;
    height: 4px;
    background: var(--gradient-primary);
    transform: scaleX(1);
    border-radius: 2px 2px 0 0;
    box-shadow: 0 -2px 8px var(--color-primary-border-mid);
}

/* ============================================================================
   RESPONSIVE BREAKPOINTS
   ============================================================================ */

/* Mobile Phones (320px - 480px) */
@media (max-width: var(--bp-mobile)) {
    .tabs-nav {
        gap: 2px;
        padding: 6px 2px;
        margin-bottom: var(--spacing-md);
    }

    .tab-button {
        padding: 10px 12px; /* Increased padding for better touch target */
        font-size: 12px;
        font-weight: 600;
        min-height: 44px; /* Ensure touch target size */
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .content-area {
        margin: 8px;
        padding: 12px;
        border-radius: var(--radius-sm);
    }

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

    .header-left {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
        width: 100%;
    }

    .amivra-logo {
        font-size: 20px;
        height: 44px;
        line-height: 1;
    }

    .client-name-inline {
        font-size: 18px !important;
    }

    .client-info {
        flex-direction: column;
        align-items: flex-start;
        gap: 4px;
        font-size: 12px;
    }

    .back-link {
        font-size: 14px;
        padding: 8px 12px;
        width: 100%;
        text-align: center;
    }

    .main-container {
        padding: 0;
    }

    /* Hide on mobile if needed */
    .mobile-hide {
        display: none !important;
    }
}

/* Small Tablets / Large Phones (481px - 768px) */
@media (min-width: calc(var(--bp-mobile) + 1px)) and (max-width: var(--bp-tablet)) {
    .tabs-nav {
        gap: 3px;
        padding: 8px 4px;
        margin-bottom: var(--spacing-lg);
    }

    .tab-button {
        padding: 10px 14px;
        font-size: 13px;
        min-height: 44px; /* Touch target size */
    }

    .content-area {
        margin: 12px;
        padding: 16px;
    }

    .client-header {
        padding: 16px;
        flex-wrap: wrap;
    }

    .header-left {
        flex-wrap: wrap;
        gap: 12px;
    }

    .amivra-logo {
        font-size: 24px;
        height: 44px;
        line-height: 1;
    }

    .client-name-inline {
        font-size: 20px !important;
    }
}

/* Tablets / iPad (769px - 1024px) */
@media (min-width: calc(var(--bp-tablet) + 1px)) and (max-width: var(--bp-desktop)) {
    .tabs-nav {
        gap: 4px;
        padding: 10px 6px;
    }

    .tab-button {
        padding: 12px 18px;
        font-size: 14px;
    }

    .content-area {
        margin: 16px;
        padding: 20px;
    }

    .client-header {
        padding: 20px;
    }

    .amivra-logo {
        font-size: 28px;
        height: 44px;
        line-height: 1;
    }

    .client-name-inline {
        font-size: 22px !important;
    }
}

/* Desktop / Large Screens (1025px+) */
@media (min-width: calc(var(--bp-desktop) + 1px)) {
    .tabs-nav {
        gap: 0;
        padding: var(--spacing-xs) 0;
    }

    .tab-button {
        padding: var(--spacing-sm) var(--spacing-xl);
        font-size: var(--font-size-base);
    }

    .content-area {
        margin: var(--spacing-lg);
        padding: var(--spacing-xl);
    }
}

/* ============================================================================
   TAB CONTENT RESPONSIVE FIXES
   ============================================================================ */

.tab-content {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.tab-content.active {
    display: block;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ============================================================================
   CONTENT AREA RESPONSIVE FIXES
   ============================================================================ */

.content-area {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    overflow-x: hidden;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

/* Prevent content overflow on mobile - do not apply to table/table-container to avoid breaking tables */
@media (max-width: var(--bp-tablet)) {
    /* Ensure images don't overflow */
    img {
        max-width: 100%;
        height: auto;
    }

    /* Ensure pre and code blocks wrap or scroll */
    pre,
    code {
        overflow-x: auto;
        word-wrap: break-word;
        white-space: pre-wrap;
    }

    /* Ensure long URLs and text wrap */
    a {
        word-break: break-word;
        overflow-wrap: break-word;
    }
}

/* ============================================================================
   HEADER RESPONSIVE FIXES
   ============================================================================ */

.client-header {
    width: 100%;
    box-sizing: border-box;
}

.header-right {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    flex-shrink: 0;
}

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

.table-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    width: 100%;
    max-width: 100%;
    white-space: nowrap;
}

@media (max-width: var(--bp-tablet)) {
    .table-container {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        white-space: nowrap;
    }

    table {
        min-width: var(--bp-smm); /* Ensure table doesn't get too narrow */
    }
}

/* ============================================================================
   CARDS AND GRIDS RESPONSIVE FIXES
   ============================================================================ */

@media (max-width: var(--bp-tablet)) {
    .card {
        padding: var(--spacing-md);
        margin-bottom: var(--spacing-md);
        overflow-x: hidden; /* Prevent horizontal overflow */
        word-wrap: break-word; /* Ensure text wraps */
    }

    /* Opt-in: add class .stack-on-mobile to a grid to force single column on small screens.
       Grids using repeat(auto-fit, minmax(...)) already reflow; use this only when needed. */
    .stack-on-mobile {
        grid-template-columns: 1fr !important;
        gap: var(--spacing-md) !important;
    }

    /* Number cards grid */
    .number-cards-grid {
        grid-template-columns: 1fr !important;
        gap: var(--spacing-md) !important;
    }

    /* General card overflow prevention */
    .card * {
        max-width: 100%;
        box-sizing: border-box;
    }

    /* Card images and media */
    .card img,
    .card video,
    .card iframe {
        max-width: 100%;
        height: auto;
    }
}

/* Very small screens */
@media (max-width: var(--bp-mobile)) {
    .card {
        padding: var(--spacing-sm);
        margin-bottom: var(--spacing-sm);
    }

    .stack-on-mobile {
        gap: var(--spacing-sm) !important;
    }

    .number-cards-grid {
        gap: var(--spacing-sm) !important;
    }
}

/* ============================================================================
   FORM ELEMENTS RESPONSIVE FIXES
   ============================================================================ */

/* Base form element styles for mobile */
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="tel"],
input[type="date"],
input[type="search"],
select,
textarea {
    font-size: 16px; /* Prevents zoom on iOS - critical for mobile UX */
    box-sizing: border-box;
}

@media (max-width: var(--bp-tablet)) {
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="number"],
    input[type="tel"],
    input[type="date"],
    input[type="search"],
    select,
    textarea {
        font-size: 16px; /* Prevents zoom on iOS */
        padding: 12px;
        width: 100%;
        box-sizing: border-box;
        min-height: 44px; /* Touch target size */
    }

    button,
    .btn,
    input[type="submit"],
    input[type="button"] {
        padding: 12px 24px;
        font-size: 16px;
        width: 100%;
        min-height: 44px; /* Touch target size */
        box-sizing: border-box;
    }

    /* Form groups should stack on mobile */
    .form-group {
        width: 100%;
        margin-bottom: var(--spacing-md);
    }

    /* Labels should be properly sized */
    label {
        font-size: 14px;
        margin-bottom: var(--spacing-xs);
        display: block;
    }
}

/* Very small screens */
@media (max-width: var(--bp-mobile)) {
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="number"],
    input[type="tel"],
    input[type="date"],
    input[type="search"],
    select,
    textarea {
        padding: 10px;
        font-size: 16px; /* Keep 16px to prevent iOS zoom */
    }

    button,
    .btn,
    input[type="submit"],
    input[type="button"] {
        padding: 10px 20px;
        font-size: 16px;
    }
}

/* ============================================================================
   TOUCH TARGETS - Ensure all interactive elements meet 44px minimum
   ============================================================================ */

/* Base touch target sizes for mobile */
@media (max-width: var(--bp-tablet)) {
    /* Buttons and clickable elements */
    button,
    .btn,
    input[type="button"],
    input[type="submit"],
    input[type="reset"],
    a.btn,
    .action-card,
    .tab-button,
    .app-header-menu-btn,
    .app-nav-link {
        min-height: 44px;
        min-width: 44px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    /* Links that act as buttons */
    a[role="button"],
    a.button {
        min-height: 44px;
        padding: 12px 16px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    /* Form controls */
    input[type="checkbox"],
    input[type="radio"] {
        min-width: 44px;
        min-height: 44px;
        margin: 0;
    }

    /* Select dropdowns */
    select {
        min-height: 44px;
    }

    /* Icon buttons */
    .icon-button,
    button.icon-only,
    [class*="icon-btn"] {
        min-width: 44px;
        min-height: 44px;
        padding: 10px;
    }
}

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

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

.desktop-only {
    display: block !important;
}

@media (max-width: var(--bp-tablet)) {
    .mobile-only {
        display: block !important;
    }

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

/* ============================================================================
   LANDSCAPE ORIENTATION FIXES
   ============================================================================ */

@media (max-width: var(--bp-tablet)) and (orientation: landscape) {
    .tabs-nav {
        max-height: 60px;
        overflow-y: hidden;
    }

    .tab-button {
        padding: 8px 12px;
        font-size: 12px;
        min-height: 44px; /* Maintain touch target even in landscape */
    }

    .content-area {
        padding: 12px;
    }
}

/* Very small screens (320px and below) - extra optimization */
@media (max-width: var(--bp-xs)) {
    .tab-button {
        padding: 8px 10px;
        font-size: 11px;
        min-height: 44px; /* Critical: maintain touch target */
    }

    .tabs-nav {
        gap: 1px;
        padding: 4px 1px;
    }
}

/* ============================================================================
   TEXT SIZING OPTIMIZATION FOR MOBILE
   ============================================================================ */

@media (max-width: var(--bp-tablet)) {
    /* Base font size adjustments */
    body {
        font-size: 14px;
        line-height: 1.5;
    }

    /* Headings - ensure readable but not too large */
    h1 {
        font-size: 1.75rem;
        line-height: 1.3;
    }

    h2 {
        font-size: 1.5rem;
        line-height: 1.3;
    }

    h3 {
        font-size: 1.25rem;
        line-height: 1.4;
    }

    h4 {
        font-size: 1.1rem;
        line-height: 1.4;
    }

    h5,
    h6 {
        font-size: 1rem;
        line-height: 1.4;
    }

    /* Paragraphs and text */
    p {
        font-size: 14px;
        line-height: 1.6;
    }

    /* Small text - ensure it's still readable */
    small,
    .text-sm {
        font-size: 12px;
        line-height: 1.5;
    }

    /* Labels - ensure they're readable */
    label {
        font-size: 14px;
        line-height: 1.5;
    }
}

/* Very small screens */
@media (max-width: var(--bp-mobile)) {
    body {
        font-size: 13px;
    }

    h1 {
        font-size: 1.5rem;
    }

    h2 {
        font-size: 1.35rem;
    }

    h3 {
        font-size: 1.15rem;
    }

    p {
        font-size: 13px;
    }

    small,
    .text-sm {
        font-size: 11px;
    }
}

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

@media print {
    .tabs-nav {
        display: none;
    }

    .tab-content {
        display: block !important;
    }

    .content-area {
        margin: 0;
        padding: 0;
        box-shadow: none;
        border: none;
    }
}
