/**
 * Task Marketplace - Responsive CSS
 * Mobile-first responsive design implementation
 */

/* ========================================
   MOBILE NAVIGATION (Mobile Only)
   ======================================== */
.tm-bottom-nav {
    display: none;
    position: fixed;
    bottom: 14px;
    left: 50%;
    right: auto;
    width: min(420px, calc(100% - 24px));
    transform: translateX(-50%);
    background: #ffffff;
    border: 1px solid rgba(15, 23, 42, 0.08);
    height: 70px;
    z-index: var(--tm-z-bottom-nav);
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.18);
    border-radius: 18px;
    padding: 0 8px;
}

.tm-bottom-nav {
    display: flex;
    justify-content: space-around;
    align-items: center;
}

.tm-nav-item-mobile {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 8px 4px;
    text-decoration: none;
    color: var(--tm-color-text-secondary);
    font-size: 12px;
    flex: 1;
    height: 100%;
    border-radius: 12px;
    transition: background-color 0.2s, color 0.2s;
}

.tm-nav-item-mobile:hover,
.tm-nav-item-mobile.active {
    color: var(--tm-color-primary);
    background-color: var(--tm-color-bg-light);
}

@media (max-width: 768px) {
    .tm-content {
        padding-bottom: 100px;
    }

    .tm-bottom-nav {
        bottom: max(14px, env(safe-area-inset-bottom));
    }
}

.tm-nav-item-mobile .tm-nav-icon {
    font-size: 24px;
    line-height: 1;
}

/* ========================================
   RESPONSIVE BREAKPOINTS
   ======================================== */

/* Tablet Layout (768px to 1024px) */
@media (max-width: 1024px) {
    .tm-sidebar {
        width: 240px;
    }

    .tm-logo-icon {
        font-size: 28px;
    }

    .tm-brand-name {
        font-size: 14px;
    }

    .tm-nav-icon {
        font-size: 18px;
    }

    .tm-nav span:not(.tm-nav-icon) {
        font-size: 13px;
    }

    .tm-header {
        height: 65px;
        padding-top: 0;
        padding-bottom: 0;
    }

    .tm-header-title {
        font-size: 20px;
    }

    .tm-stat-card {
        padding: 15px;
    }

    .tm-stat-label {
        font-size: 12px;
    }

    .tm-stat-value {
        font-size: 24px;
        margin-top: 5px;
    }

    .tm-content {
        padding: 20px;
    }

    .tm-card {
        padding: 15px;
    }

    .tm-input,
    .tm-textarea,
    .tm-select {
        font-size: 14px;
        padding: 10px;
    }

    .tm-btn {
        padding: 10px 16px;
        font-size: 14px;
    }

    .tm-btn-lg {
        padding: 12px 20px;
    }
}

/* Mobile Layout (≤768px) */
@media (max-width: 768px) {
    #tm-worker-portal .tm-header {
        display: grid;
        grid-template-columns: minmax(0, 1fr);
        grid-template-rows: auto auto;
        align-items: center;
        justify-content: stretch;
        min-height: 104px;
        height: auto;
        padding: 0 12px;
        gap: 8px;
        box-sizing: border-box;
        overflow: visible;
    }

    #tm-worker-portal .tm-header-left {
        display: flex;
        grid-column: 1;
        grid-row: 1;
        width: 100%;
        flex: none;
        min-width: 0;
    }

    #tm-worker-portal .tm-header-title {
        max-width: 100%;
        font-size: 18px !important;
        letter-spacing: 0;
    }

    #tm-worker-portal .tm-header-right {
        display: flex;
        grid-column: 1;
        grid-row: 2;
        width: 100% !important;
        flex: none;
        min-width: 0;
        gap: 8px;
        margin-left: 0;
        justify-content: flex-start;
    }

    #tm-worker-portal .tm-language-menu {
        flex: 1 1 auto;
        min-width: 0;
        width: auto;
        max-width: 150px;
        min-height: 42px;
        padding: 0 28px 0 10px;
        gap: 6px;
        box-sizing: border-box;
    }

    #tm-worker-portal .tm-language-menu::after {
        right: 10px;
        font-size: 16px;
    }

    #tm-worker-portal .tm-language-icon {
        font-size: 16px;
    }

    #tm-worker-portal .pt-worker-language-select {
        min-width: 0;
        width: 100%;
        font-size: 14px;
    }

    #tm-worker-portal .tm-notifications-badge {
        display: grid;
        flex: 0 0 44px;
        place-items: center;
        width: 44px;
        height: 44px;
        padding: 0;
    }

    #tm-worker-portal .tm-profile-menu-trigger {
        display: flex;
        flex: 0 0 44px;
        justify-content: center;
        width: 44px;
        min-height: 44px;
        padding: 4px;
        box-sizing: border-box;
    }

    #tm-worker-portal #tm-user-name,
    #tm-worker-portal .tm-profile-menu-trigger .tm-caret {
        display: none;
    }

    #tm-worker-portal .tm-header-avatar {
        width: 32px;
        height: 32px;
    }

    #tm-worker-portal .ptm-theme-toggle {
        flex: 0 0 44px;
        width: 44px;
        min-width: 44px;
        min-height: 44px;
        margin: 0;
        padding: 8px;
        box-sizing: border-box;
    }

    #tm-admin-portal .tm-header {
        display: grid;
        grid-template-columns: minmax(0, 1fr);
        grid-template-rows: auto auto;
        align-items: center;
        justify-content: stretch;
        min-height: 104px;
        height: auto;
        padding: 0 12px;
        gap: 8px;
        box-sizing: border-box;
        overflow: visible;
    }

    #tm-admin-portal .tm-header-left {
        display: flex;
        grid-column: 1;
        grid-row: 1;
        width: 100%;
        flex: none;
        min-width: 0;
    }

    #tm-admin-portal .tm-header-title {
        max-width: 100%;
        font-size: 18px !important;
        letter-spacing: 0;
    }

    #tm-admin-portal .tm-header-right {
        display: flex;
        grid-column: 1;
        grid-row: 2;
        width: 100% !important;
        flex: none;
        min-width: 0;
        gap: 8px;
        margin-left: 0;
        justify-content: flex-start;
    }

    #tm-admin-portal .tm-language-menu {
        display: flex;
        flex: 1 1 auto;
        min-width: 0;
        width: auto;
        max-width: 150px;
        min-height: 42px;
        padding: 0 28px 0 10px;
        gap: 6px;
        box-sizing: border-box;
    }

    #tm-admin-portal #tm-user-name,
    #tm-admin-portal .tm-profile-menu-trigger .tm-caret {
        display: none;
    }

    #tm-admin-portal .tm-profile-menu-trigger {
        justify-content: center;
        width: 44px;
        flex: 0 0 44px;
    }

    #tm-admin-portal .tm-language-menu::after {
        right: 10px;
        font-size: 16px;
    }

    #tm-admin-portal .tm-language-icon {
        font-size: 16px;
    }

    #tm-admin-portal .tm-language-select {
        min-width: 0;
        width: 100%;
        font-size: 14px;
    }

    #tm-admin-portal .tm-notifications-badge {
        display: grid;
        flex: 0 0 44px;
        place-items: center;
        width: 44px;
        height: 44px;
        padding: 0;
    }

    #tm-admin-portal .tm-profile-menu-trigger {
        display: flex;
        flex: 0 1 auto;
        min-width: 44px;
        min-height: 44px;
        padding: 4px 8px;
        box-sizing: border-box;
    }

    #tm-admin-portal .ptm-theme-toggle {
        flex: 0 0 44px;
        width: 44px;
        min-width: 44px;
        min-height: 44px;
        margin: 0;
        padding: 8px;
        box-sizing: border-box;
    }

    #tm-admin-portal .tm-content h1,
    #tm-admin-portal .tm-content h2,
    #tm-admin-portal .tm-content h3 {
        font-size: 18px !important;
    }

    #tm-admin-portal .tm-content h4,
    #tm-admin-portal .tm-content h5,
    #tm-admin-portal .tm-content h6 {
        font-size: 16px !important;
    }

    #tm-admin-portal .tm-content p,
    #tm-admin-portal .tm-content li,
    #tm-admin-portal .tm-content label,
    #tm-admin-portal .tm-content small {
        font-size: 14px !important;
    }

    #tm-worker-portal .tm-content h1,
    #tm-worker-portal .tm-content h2,
    #tm-worker-portal .tm-content h3 {
        font-size: 18px !important;
    }

    #tm-worker-portal .tm-content h4,
    #tm-worker-portal .tm-content h5,
    #tm-worker-portal .tm-content h6 {
        font-size: 16px !important;
    }

    #tm-worker-portal .tm-content p,
    #tm-worker-portal .tm-content li,
    #tm-worker-portal .tm-content label,
    #tm-worker-portal .tm-content small {
        font-size: 14px !important;
    }

    #tm-worker-portal #tm-page-home > #tm-affiliate-program-card > div > div:last-child,
    #tm-worker-portal #tm-page-home > #tm-company-rules-card > div > div:last-child,
    #tm-worker-portal #tm-page-home > #tm-platform-profile-card > div > div:last-child,
    #tm-worker-portal #tm-page-home > #tm-instructions-card > div > div:last-child {
        width: 56px !important;
        height: 56px !important;
        border-radius: 16px !important;
        font-size: 24px !important;
        flex: 0 0 56px;
    }

    #tm-worker-portal .tm-support-actions {
        display: grid;
        grid-template-columns: minmax(0, 1fr);
        gap: 12px;
        width: 100%;
    }

    #tm-worker-portal .tm-support-actions .tm-btn {
        width: 100%;
        min-width: 0;
        min-height: 48px;
        padding: 10px 14px;
        font-size: 14px;
        line-height: 1.3;
        white-space: normal;
        text-align: center;
    }

    #tm-worker-portal .tm-support-actions .tm-btn-primary {
        background: var(--dd-primary);
        color: #fff !important;
    }

    #tm-worker-portal .tm-support-actions .tm-btn-secondary {
        background: #fff;
        color: var(--tm-text) !important;
        border-color: var(--tm-border);
    }

    /* Show bottom navigation, hide sidebar */
    .tm-sidebar {
        display: none;
    }

    .tm-bottom-nav {
        display: flex;
    }

    .tm-main-container {
        margin-left: 0;
        padding-bottom: 70px;
    }

    .tm-header {
        height: 60px;
        min-height: 60px;
        padding: 0 12px;
        flex-wrap: nowrap;
        position: relative;
    }

    .tm-header-left {
        flex: 1;
        min-width: 0;
    }

    .tm-header-title {
        font-size: 18px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .tm-header-right {
        gap: 8px;
        margin-left: 8px;
    }

    .tm-notifications-badge {
        font-size: 16px;
    }

    .tm-avatar {
        width: 36px;
        height: 36px;
        font-size: 14px;
    }

    .tm-user-name {
        display: none;
    }

    .tm-profile-menu {
        gap: 0;
    }

    .tm-content {
        padding: 15px 15px 15px 15px;
        margin-top: 0;
    }

    .tm-portal-worker #tm-page-home > div:first-child {
        grid-template-columns: minmax(0, 1fr) !important;
        gap: 14px !important;
    }

    .tm-portal-worker #tm-page-home .tm-stat-card {
        min-width: 0;
        min-height: 170px !important;
    }

    .tm-level-banner {
        grid-template-columns: minmax(0, 1fr) !important;
        gap: 18px !important;
        min-height: 0 !important;
        padding: 28px 20px !important;
    }

    .tm-level-emblem {
        min-height: 0 !important;
    }

    .tm-level-emblem > div {
        width: 112px !important;
        height: 112px !important;
    }

    .tm-level-emblem svg {
        width: 68px !important;
        height: 68px !important;
    }

    .tm-level-divider {
        width: 100% !important;
        height: 2px !important;
    }

    .tm-level-copy h3 {
        font-size: clamp(28px, 9vw, 42px) !important;
        line-height: 1 !important;
    }

    .tm-level-copy > div {
        font-size: clamp(24px, 7vw, 34px) !important;
    }

    .tm-level-copy > div:last-child {
        width: 100% !important;
    }

    .tm-level-metrics {
        grid-template-columns: minmax(0, 1fr) !important;
    }

    .tm-level-metrics strong,
    .tm-level-metrics small,
    .tm-level-banner + .tm-level-metrics,
    .tm-level-banner ~ p {
        font-size: 12px !important;
    }

    .tm-page {
        margin-top: 0;
        padding-top: 0;
        animation: fadeIn 0.2s ease-in-out;
    }

    @keyframes fadeIn {
        from { opacity: 0; }
        to { opacity: 1; }
    }

    .tm-stat-card {
        padding: 12px;
        min-height: 100px;
        display: flex;
        flex-direction: column;
        justify-content: center;
    }

    .tm-stat-label {
        font-size: 11px;
        font-weight: 500;
        opacity: 0.9;
        margin-bottom: 4px;
    }

    .tm-stat-value {
        font-size: 20px;
        font-weight: bold;
    }

    .tm-card {
        border-radius: 8px;
        padding: 12px;
        margin-bottom: 12px;
    }

    /* Forms on mobile */
    .tm-form-group {
        margin-bottom: 12px;
    }

    .tm-label {
        font-size: 12px;
        font-weight: 500;
        margin-bottom: 6px;
    }

    .tm-input,
    .tm-textarea,
    .tm-select {
        font-size: 14px;
        padding: 10px;
        border-radius: 6px;
        width: 100%;
    }

    .tm-textarea {
        min-height: 80px;
    }

    .tm-btn {
        width: 100%;
        padding: 12px;
        font-size: 14px;
        border-radius: 6px;
        font-weight: 500;
    }

    .tm-btn-lg {
        padding: 14px;
        font-size: 15px;
    }

    /* Grid layouts on mobile */
    [style*="grid-template-columns: repeat"] {
        grid-template-columns: 1fr !important;
    }

    .tm-nav {
        display: none;
    }

    /* Stacked layout for form rows */
    div[style*="display: grid"][style*="grid-template-columns: repeat(auto-fit"] {
        grid-template-columns: 1fr !important;
    }

    /* Flex layouts on mobile */
    .tm-form-row {
        flex-direction: column;
    }

    /* Button groups on mobile */
    div[style*="display: flex"] {
        flex-wrap: wrap;
        gap: 8px;
    }

    .tm-btn {
        flex: 1;
        min-width: 100px;
    }

    /* Modal/Dialog adjustments */
    .tm-modal {
        left: 0;
        right: 0;
        width: 100%;
        padding: 12px;
        margin: 0;
        max-height: 90vh;
    }

    .tm-modal-content {
        width: min(100%, calc(100vw - 24px));
    }

    /* Table adjustments */
    .tm-table {
        font-size: 12px;
    }

    .tm-table th,
    .tm-table td {
        padding: 8px 6px;
    }

    /* Lists on mobile */
    .tm-list-item {
        padding: 10px 0;
        border-bottom: 1px solid var(--tm-color-border);
    }

    .tm-list-item:last-child {
        border-bottom: none;
    }
}

/* Small Mobile Layout (≤414px) */
@media (max-width: 414px) {
    .tm-header {
        height: 56px;
        padding: 0 10px;
    }

    .tm-header-title {
        font-size: 16px;
    }

    .tm-content {
        padding: 12px;
    }

    .tm-stat-card {
        padding: 10px;
        min-height: 90px;
    }

    .tm-stat-label {
        font-size: 10px;
    }

    .tm-stat-value {
        font-size: 18px;
    }

    .tm-card {
        padding: 10px;
        margin-bottom: 10px;
    }

    .tm-badge {
        width: 20px;
        height: 20px;
        font-size: 11px;
        line-height: 20px;
    }

    .tm-avatar {
        width: 32px;
        height: 32px;
        font-size: 12px;
    }

    /* Ensure no horizontal overflow */
    body,
    html,
    .tm-app,
    .tm-main-container,
    .tm-content {
        overflow-x: hidden;
    }

    /* Make inputs full width and properly sized */
    .tm-input,
    .tm-textarea,
    .tm-select,
    .tm-btn {
        font-size: 16px; /* Prevent zoom on iOS */
        width: 100%;
    }

    .tm-input,
    .tm-textarea,
    .tm-select {
        padding: 10px;
        box-sizing: border-box;
    }

    .tm-btn {
        padding: 12px;
        box-sizing: border-box;
    }

    /* Grid adjustments */
    [style*="grid"] {
        grid-template-columns: 1fr !important;
    }

    /* Flex adjustments */
    div[style*="display: flex"] {
        flex-direction: column;
    }

    /* Typography on small screens */
    h1, .tm-header-title {
        font-size: 16px;
    }

    h2 {
        font-size: 14px;
        margin-bottom: 12px;
    }

    h3 {
        font-size: 12px;
    }

    p {
        font-size: 12px;
        line-height: 1.4;
    }

    /* Bottom nav on small screens */
    .tm-bottom-nav {
        height: 64px;
    }

    .tm-nav-item-mobile {
        font-size: 10px;
    }

    .tm-nav-item-mobile .tm-nav-icon {
        font-size: 20px;
    }

    .tm-main-container {
        padding-bottom: 64px;
    }
}

/* Extra Small Mobile Layout (≤375px) */
@media (max-width: 375px) {
    .tm-header {
        height: 52px;
        padding: 0 8px;
    }

    .tm-header-right {
        gap: 6px;
    }

    .tm-content {
        padding: 10px;
    }

    .tm-stat-card {
        padding: 8px;
        min-height: 80px;
    }

    .tm-stat-value {
        font-size: 16px;
    }

    .tm-card {
        padding: 8px;
        margin-bottom: 8px;
    }

    .tm-btn {
        padding: 10px;
        font-size: 13px;
    }

    .tm-avatar {
        width: 28px;
        height: 28px;
        font-size: 11px;
    }
}

/* Large Desktop Layout (≥1440px) */
@media (min-width: 1440px) {
    .tm-main-container {
        max-width: 1400px;
        margin: 0 auto;
    }

    .tm-content {
        padding: 30px;
    }

    .tm-card {
        max-width: 100%;
    }
}

/* Landscape Orientation Mobile */
@media (max-width: 768px) and (orientation: landscape) {
    .tm-sidebar {
        display: none;
    }

    .tm-bottom-nav {
        display: flex;
        height: 60px;
    }

    .tm-main-container {
        margin-left: 0;
        padding-bottom: 60px;
    }

    .tm-header {
        height: 50px;
        padding: 0 10px;
    }

    .tm-header-title {
        font-size: 16px;
    }

    .tm-content {
        padding: 12px;
    }

    .tm-nav {
        display: none;
    }

    [style*="grid-template-columns: repeat(auto-fit"] {
        grid-template-columns: repeat(2, 1fr) !important;
    }
}

/* Accessibility - Reduced Motion */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Shared mobile marketplace navigation */
.tm-mobile-bottom-nav {
    display: none;
}

@media (max-width: 768px) {
    .tm-mobile-bottom-nav {
        display: block;
        position: fixed;
        left: 50%;
        right: auto;
        bottom: max(14px, env(safe-area-inset-bottom));
        width: min(420px, calc(100% - 24px));
        transform: translateX(-50%);
        height: 64px;
        padding: 0 8px;
        background: #ffffff;
        border: 1px solid rgba(15, 23, 42, 0.08);
        border-radius: 18px;
        box-shadow: 0 8px 24px rgba(15, 23, 42, 0.18);
        z-index: 1000;
    }

    .tm-mobile-bottom-nav-list {
        display: grid;
        grid-template-columns: repeat(5, minmax(0, 1fr));
        align-items: stretch;
        width: 100%;
        height: 100%;
        margin: 0;
        padding: 0;
        list-style: none;
    }

    .tm-mobile-bottom-nav-item {
        display: block;
        width: 100%;
        min-width: 0;
        margin: 0;
        padding: 0;
    }

    .tm-mobile-bottom-nav-link,
    .tm-mobile-bottom-nav-link.tm-nav-item-mobile {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        width: 100%;
        min-width: 0;
        max-width: 100%;
        overflow: hidden;
        min-height: 64px;
        gap: 4px;
        padding: 6px 3px;
        color: #64748b;
        background: transparent;
        border: 0;
        border-radius: 12px;
        font-family: 'Poppins', sans-serif;
        font-size: 11px;
        font-weight: 500;
        line-height: 1.15;
        text-align: center;
        text-decoration: none;
        transition: color 150ms ease;
    }

    .tm-mobile-bottom-nav-link:hover,
    .tm-mobile-bottom-nav-link.active,
    .tm-mobile-bottom-nav-link.tm-nav-item-mobile.active {
        color: #ff6b35;
        background: #fff1e9;
    }

    .tm-mobile-bottom-nav-icon {
        width: 21px;
        height: 21px;
        flex: 0 0 21px;
    }

    .tm-mobile-bottom-nav-link > span {
        display: block;
        width: 100%;
        max-width: 100%;
        white-space: normal;
        overflow-wrap: anywhere;
        word-break: break-all;
    }

    .tm-portal-customer .tm-content,
    .tm-portal-worker .tm-content,
    .tm-portal-admin .tm-content {
        padding-bottom: 84px;
    }
}

@media (max-width: 430px) {
    .tm-mobile-bottom-nav-link,
    .tm-mobile-bottom-nav-link.tm-nav-item-mobile {
        gap: 3px;
        padding-right: 2px;
        padding-left: 2px;
        font-size: 10px;
    }

    .tm-mobile-bottom-nav-icon {
        width: 20px;
        height: 20px;
        flex-basis: 20px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .tm-mobile-bottom-nav-link,
    .tm-mobile-bottom-nav-link:hover {
        transition: none;
    }
}

/* Print styles */
@media print {
    .tm-sidebar,
    .tm-header,
    .tm-bottom-nav,
    .tm-mobile-bottom-nav,
    .tm-btn,
    .tm-profile-menu {
        display: none;
    }

    .tm-main-container {
        margin: 0;
        padding: 0;
    }

    .tm-content {
        padding: 0;
    }

    .tm-card {
        page-break-inside: avoid;
    }
}
