/* Mobile Responsive Overrides - Applied to all pages */

/* Prevent horizontal overflow globally */
* {
    max-width: 100%;
    box-sizing: border-box;
}

html, body {
    overflow-x: hidden;
    max-width: 100vw;
    position: relative;
}

/* Base Mobile Fixes */
@media (max-width: 1024px) {
    /* App layout fixes */
    .app-layout {
        flex-direction: column;
        overflow-x: hidden;
    }

    .content {
        padding: 1rem;
        width: 100%;
        overflow-x: hidden;
    }

    header {
        padding: 1rem 1.5rem;
    }

    header h1 {
        font-size: 1.2rem;
    }

    nav ul {
        gap: 1.5rem;
    }

    nav a {
        font-size: 0.85rem;
    }

    main {
        padding: 0 1rem;
        width: 100%;
        overflow-x: hidden;
    }

    section {
        padding: 1.5rem 1rem;
        margin: 1rem 0;
        border-radius: 12px;
        width: 100%;
        overflow-x: hidden;
    }

    section h2 {
        font-size: 1.5rem;
        margin-bottom: 1rem;
        word-wrap: break-word;
    }

    section h3 {
        font-size: 1.2rem;
        word-wrap: break-word;
    }

    /* Fix grid layouts */
    .dashboard-grid,
    .price-grid,
    .form-row {
        grid-template-columns: 1fr !important;
        gap: 1rem !important;
    }
}

@media (max-width: 768px) {
    /* Prevent all overflow */
    * {
        margin: 0;
        padding: 0;
        box-sizing: border-box;
        max-width: 100%;
    }

    html, body {
        font-size: 16px;
        overflow-x: hidden;
        width: 100vw;
        position: relative;
    }

    /* App layout - stack vertically */
    .app-layout {
        flex-direction: column;
        overflow-x: hidden;
    }

    /* Sidebar becomes top bar on mobile */
    .sidebar {
        width: 100% !important;
        position: sticky;
        top: 0;
        z-index: 1000;
        padding: 0.75rem;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    }

    /* Content area */
    .content {
        width: 100%;
        padding: 1rem;
        overflow-x: hidden;
    }

    .main-container {
        padding: 1rem;
        width: 100%;
    }

    /* Header adjustments */
    header {
        flex-wrap: wrap;
        padding: 1rem;
        gap: 0.5rem;
        position: sticky;
        top: 0;
        z-index: 100;
    }

    header h1 {
        font-size: 1.1rem;
        flex: 1;
        min-width: 150px;
        word-wrap: break-word;
    }

    /* Navigation */
    nav {
        width: 100%;
        order: 3;
    }

    nav ul {
        flex-direction: column;
        gap: 0.5rem;
    }

    nav a {
        display: block;
        padding: 0.5rem 0;
        font-size: 0.9rem;
    }

    /* Main content */
    main {
        padding: 0 1rem;
        width: 100%;
        overflow-x: hidden;
    }

    section {
        padding: 1.5rem 1rem;
        margin: 1rem 0;
        border-radius: 10px;
        width: calc(100% - 2rem);
        max-width: calc(100vw - 2rem);
        overflow-x: hidden;
        box-sizing: border-box;
    }

    section h2 {
        font-size: 1.3rem;
        margin-bottom: 1rem;
        word-wrap: break-word;
        overflow-wrap: break-word;
        width: 100%;
    }

    section h3 {
        font-size: 1.1rem;
        margin: 1.5rem 0 0.75rem 0;
        word-wrap: break-word;
        overflow-wrap: break-word;
        width: 100%;
    }

    section p {
        font-size: 0.95rem;
        margin-bottom: 1rem;
        word-wrap: break-word;
        overflow-wrap: break-word;
        width: 100%;
    }

    /* Forms */
    .form-group {
        margin-bottom: 1.25rem;
        width: 100%;
        box-sizing: border-box;
    }

    .form-row {
        display: flex !important;
        flex-direction: column !important;
        gap: 1rem !important;
        width: 100% !important;
        box-sizing: border-box !important;
    }

    label {
        font-size: 0.85rem;
        margin-bottom: 0.5rem;
        word-wrap: break-word;
    }

    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="number"],
    input[type="tel"],
    select,
    textarea {
        width: 100% !important;
        max-width: 100% !important;
        padding: 0.75rem 0.875rem !important;
        font-size: 16px !important; /* Prevents zoom on iOS */
        border-radius: 8px;
        box-sizing: border-box !important;
    }
    
    /* Form containers */
    form {
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
    }
    
    .withdrawal-form,
    .deposit-form,
    .form-container {
        width: 100% !important;
        max-width: 100% !important;
        padding: 1rem !important;
        box-sizing: border-box !important;
    }
    
    /* Ensure divs with inline styles don't overflow */
    div[style*="background: var(--surface)"],
    div[style*="background: rgba"] {
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
        overflow-x: hidden !important;
    }
    }

    textarea {
        min-height: 120px;
        resize: vertical;
    }

    /* Button styling on tablet and below */
    .button-group,
    div[style*="display: flex; gap: 1rem"] {
        display: flex !important;
        flex-direction: column !important;
        gap: 0.75rem !important;
        width: 100% !important;
    }

    .button-group .btn,
    div[style*="display: flex; gap: 1rem"] .btn {
        width: 100% !important;
        flex: none !important;
        min-width: 100% !important;
        padding: 1rem !important;
        height: 44px !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
    }

    .button-group a.btn,
    div[style*="display: flex; gap: 1rem"] a.btn {
        text-decoration: none !important;
        text-align: center !important;
    }

    button,
    .btn {
        padding: 1rem;
        font-size: 0.95rem;
        border-radius: 8px;
        border: none;
        cursor: pointer;
        transition: all 0.3s ease;
        height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
        white-space: nowrap;
    }

    .button-group,
    div[style*="display: flex; gap: 1rem"] {
        display: flex !important;
        gap: 1rem !important;
        flex-direction: row !important;
        flex-wrap: wrap !important;
        width: 100% !important;
    }

    .button-group .btn,
    div[style*="display: flex; gap: 1rem"] .btn {
        flex: 1 1 auto !important;
        width: auto !important;
        max-width: 100% !important;
        min-width: 120px !important;
    }

    .button-group a.btn,
    div[style*="display: flex; gap: 1rem"] a.btn {
        text-align: center;
        text-decoration: none;
    }

    /* Grid layouts - force single column */
    .dashboard-grid,
    .price-grid,
    .transaction-list,
    [style*="grid-template-columns"],
    [style*="display: grid"] {
        display: flex !important;
        flex-direction: column !important;
        gap: 1rem !important;
        width: 100% !important;
    }

    .price-card,
    .card,
    .transaction-item {
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 !important;
    }

    /* Tables */
    table {
        width: 100%;
        font-size: 0.85rem;
        overflow-x: auto;
        display: block;
    }

    thead {
        display: none;
    }

    tbody {
        display: block;
    }

    tr {
        display: block;
        border-bottom: 1px solid var(--border-light);
        margin-bottom: 1rem;
        padding: 1rem 0;
    }

    td {
        display: block;
        text-align: right;
        padding: 0.5rem 0;
        position: relative;
        padding-left: 50%;
        word-wrap: break-word;
    }

    td:before {
        content: attr(data-label);
        position: absolute;
        left: 0;
        width: 45%;
        font-weight: 600;
        text-align: left;
        color: var(--text-secondary);
    }

    /* Dashboard fixes */
    .account-summary {
        display: flex !important;
        flex-direction: column !important;
        gap: 1rem !important;
    }

    .balance-card {
        width: 100% !important;
    }

    /* Flex containers */
    .flex-container,
    .button-group,
    [style*="display: flex"],
    [style*="display:flex"] {
        flex-direction: column !important;
        gap: 1rem !important;
        width: 100% !important;
    }

    .flex-container > *,
    [style*="display: flex"] > * {
        width: 100% !important;
        max-width: 100% !important;
    }

    /* Modals and overlays */
    .modal {
        width: 95vw !important;
        max-width: 95vw !important;
        border-radius: 12px;
        padding: 1.5rem 1rem;
        left: 50% !important;
        transform: translateX(-50%) !important;
    }

    .modal-content {
        width: 100%;
    }

    /* Spacing utilities */
    .container {
        padding: 0 1rem;
        max-width: 100%;
        width: 100%;
    }

    /* Registration/Login containers */
    .register-container,
    .login-container {
        max-width: 100% !important;
        margin: 0 !important;
        padding: 1.5rem 1rem !important;
    }

    /* Images */
    img {
        max-width: 100% !important;
        height: auto;
        display: block;
    }

    /* Lists */
    ul, ol {
        margin-left: 1rem;
        margin-bottom: 1rem;
        word-wrap: break-word;
    }

    li {
        margin-bottom: 0.5rem;
        word-wrap: break-word;
    }

    /* Text overflow fixes */
    h1, h2, h3, h4, h5, h6, p, span, div, a {
        word-wrap: break-word;
        overflow-wrap: break-word;
        hyphens: auto;
    }
}

@media (max-width: 480px) {
    html {
        font-size: 14px;
    }

    body {
        overflow-x: hidden;
        max-width: 100vw;
    }

    /* Extra small screen adjustments */
    .app-layout {
        overflow-x: hidden;
    }

    .sidebar {
        padding: 0.5rem;
    }

    .content {
        padding: 0.75rem;
    }

    header {
        padding: 0.75rem 0.5rem;
        gap: 0.25rem;
    }

    header h1 {
        font-size: 0.95rem;
    }

    main {
        padding: 0 0.75rem;
    }

    section {
        padding: 1.25rem 0.75rem;
        margin: 0.75rem 0;
    }

    section h2 {
        font-size: 1.2rem;
        margin-bottom: 0.75rem;
    }

    section h3 {
        font-size: 1rem;
    }

    .form-group {
        margin-bottom: 1rem;
    }

    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="number"],
    input[type="tel"],
    select,
    textarea {
        padding: 0.625rem 0.75rem;
        font-size: 16px;
    }

    button, .btn {
        padding: 0.625rem 0.75rem;
        font-size: 0.9rem;
    }

    table {
        font-size: 0.8rem;
    }

    td {
        padding: 0.375rem 0;
        padding-left: 40%;
    }

    td:before {
        width: 40%;
    }

    /* Transaction cards on small screens */
    .transaction-item {
        flex-direction: column !important;
        align-items: flex-start !important;
        padding: 1rem 0.75rem !important;
    }

    .transaction-item > div {
        width: 100% !important;
        text-align: left !important;
    }

    /* Price cards */
    .price-card {
        padding: 1rem !important;
    }

    .price-value {
        font-size: 1.25rem !important;
    }

    /* Wallet balance */
    [style*="font-size: 3rem"] {
        font-size: 2rem !important;
    }

    /* Ensure no element exceeds viewport */
    * {
        max-width: 100vw !important;
    }

    img, table, pre, code {
        max-width: 100% !important;
        overflow-x: auto;
    }

    /* Touch-friendly targets */
    a, button {
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* Register/Login forms on very small screens */
    .register-container,
    .login-container {
        padding: 1rem 0.75rem !important;
        border-radius: 8px;
    }
}

/* Tablet Specific */
@media (min-width: 769px) and (max-width: 1024px) {
    .dashboard-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    section {
        padding: 2.5rem 2rem;
    }

    nav ul {
        gap: 1.5rem;
    }
}

/* Landscape orientation */
@media (max-height: 600px) and (orientation: landscape) {
    header {
        padding: 0.75rem 1rem;
    }

    header h1 {
        font-size: 1rem;
    }

    section {
        padding: 1.5rem 1rem;
        margin: 0.5rem 0;
    }

    section h2 {
        font-size: 1.4rem;
        margin-bottom: 0.75rem;
    }
}

/* High DPI/Retina displays */
@media (min-width: 1920px) {
    header {
        padding: 2rem 3rem;
    }

    main {
        padding: 0 3rem;
    }

    section {
        padding: 4rem 3rem;
        margin: 2rem 0;
    }

    section h2 {
        font-size: 2.5rem;
    }
}

/* Print styles */
@media print {
    header, nav, .menu-toggle, footer {
        display: none;
    }

    main {
        padding: 0;
    }

    section {
        page-break-inside: avoid;
        box-shadow: none;
        border: 1px solid #ccc;
    }
}

/* Accessibility: Reduced motion */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    /* Already dark by default, but ensure consistency */
    body {
        background-color: var(--surface);
    }
}
/* ======================================
   DASHBOARD MOBILE FIXES (CRITICAL)
   ====================================== */

@media (max-width: 640px) {
    /* Override all width constraints for mobile */
    * {
        max-width: 100vw !important;
        box-sizing: border-box !important;
    }

    html, body {
        width: 100vw !important;
        overflow-x: hidden !important;
    }

    section {
        width: calc(100vw - 2rem) !important;
        max-width: calc(100vw - 2rem) !important;
        padding: 1rem !important;
        margin: 0.5rem 0 !important;
    }

    main {
        width: 100vw !important;
        padding: 0 !important;
    }

    /* Form styling for small screens */
    form,
    .withdrawal-form,
    .deposit-form {
        width: 100% !important;
        max-width: 100% !important;
        padding: 1rem !important;
        box-sizing: border-box !important;
    }

    .form-group {
        width: 100% !important;
        box-sizing: border-box !important;
    }

    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="number"],
    input[type="tel"],
    select,
    textarea {
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
        padding: 0.75rem !important;
    }

    /* Button groups - stack vertically on mobile */
    .button-group,
    div[style*="display: flex; gap: 1rem"],
    div[style*="display: flex; gap: 1.5rem"] {
        display: flex !important;
        flex-direction: column !important;
        gap: 0.75rem !important;
        width: 100% !important;
    }

    .button-group .btn,
    div[style*="display: flex; gap: 1rem"] .btn,
    div[style*="display: flex; gap: 1.5rem"] .btn {
        width: 100% !important;
        flex: none !important;
        min-width: 100% !important;
        padding: 1rem !important;
        height: 44px !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
    }

    .button-group a.btn,
    div[style*="display: flex; gap: 1rem"] a.btn,
    div[style*="display: flex; gap: 1.5rem"] a.btn {
        text-decoration: none !important;
        text-align: center !important;
    }

    /* Dashboard welcome section - fix username overlap */
    section > div[style*="flex"] {
        flex-direction: column !important;
        gap: 1rem !important;
        align-items: flex-start !important;
    }

    section h2 {
        font-size: 1.3rem !important;
        word-wrap: break-word !important;
        overflow-wrap: break-word !important;
        max-width: 90vw !important;
        line-height: 1.4 !important;
    }

    /* Dashboard welcome box - ensure proper spacing */
    div[style*="gradient"] {
        padding: 1.5rem !important;
        margin-bottom: 1.5rem !important;
    }

    /* Dashboard button grids - stack properly */
    div[style*="grid-template-columns: repeat(3"] {
        display: flex !important;
        flex-direction: column !important;
        width: 100% !important;
    }

    /* Fix button spacing in wallet balance section */
    div[style*="grid-template-columns: repeat(3"] a {
        width: 100% !important;
        padding: 0.8rem 1rem !important;
        min-height: 44px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
    }

    /* Price grid - ensure single column */
    .price-grid {
        grid-template-columns: 1fr !important;
        gap: 1rem !important;
        padding: 0 0.5rem !important;
    }

    .price-card {
        padding: 1rem !important;
        font-size: 0.9rem !important;
    }

    .price-symbol {
        font-size: 0.95rem !important;
    }

    .price-value {
        font-size: 1.3rem !important;
    }

    /* Security features grid - single column */
    section > div[style*="grid-template-columns: repeat(auto"] {
        display: flex !important;
        flex-direction: column !important;
        width: 100% !important;
        align-items: center !important;
    }

    /* Account history toggle proper sizing */
    #toggle-icon {
        font-size: 1.2rem !important;
        flex-shrink: 0 !important;
    }

    /* Transaction history table - fix text overlap */
    .transaction-table {
        font-size: 0.85rem !important;
    }

    .transaction-table td {
        padding: 0.75rem 0.5rem !important;
        word-wrap: break-word !important;
        overflow-wrap: break-word !important;
    }

    /* Account history content - ensure proper wrapping */
    #account-history-content {
        max-height: none !important;
    }

    #account-history-content.collapsed {
        max-height: 0 !important;
    }
}

/* ======================================
   ASSETS PAGE MOBILE FIXES (CRITICAL)
   ====================================== */

@media (max-width: 640px) {
    /* Assets header */
    main section h2 {
        font-size: 1.3rem !important;
        word-wrap: break-word !important;
        max-width: 90vw !important;
    }

    /* Total portfolio value box */
    div[style*="background: linear-gradient"][style*="border-radius: 16px"] {
        padding: 1.5rem !important;
        margin-bottom: 1.5rem !important;
    }

    div[style*="color: white"][style*="font-weight: 700"][style*="font-size: 2.5rem"] {
        font-size: 2rem !important;
        word-wrap: break-word !important;
        line-height: 1.3 !important;
    }

    /* Asset cards grid - responsive */
    div[style*="grid-template-columns: repeat(auto-fill"] {
        grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)) !important;
        gap: 0.75rem !important;
    }

    /* Asset card styling - mobile */
    .asset-row {
        padding: 1rem !important;
        gap: 0.5rem !important;
        min-height: auto !important;
    }

    .asset-card-icon {
        width: 40px !important;
        height: 40px !important;
        font-size: 1.2rem !important;
    }

    .asset-card-name {
        font-size: 0.85rem !important;
        word-wrap: break-word !important;
        max-width: 100% !important;
    }

    .asset-card-symbol {
        font-size: 0.7rem !important;
    }

    .asset-card-balance {
        font-size: 1.1rem !important;
        word-wrap: break-word !important;
        max-width: 100% !important;
        margin: 0.15rem 0 !important;
    }

    .asset-card-usd {
        font-size: 0.7rem !important;
        word-wrap: break-word !important;
    }

    /* Asset modal - responsive sizing */
    .asset-modal {
        padding: 1.5rem !important;
        max-width: 90vw !important;
        width: calc(100vw - 2rem) !important;
        margin: 0 1rem !important;
    }

    .asset-modal-icon {
        width: 60px !important;
        height: 60px !important;
        font-size: 1.8rem !important;
    }

    .asset-modal-name {
        font-size: 1.4rem !important;
        word-wrap: break-word !important;
    }

    .asset-modal-symbol {
        font-size: 0.9rem !important;
    }

    .asset-modal-balance {
        font-size: 1.5rem !important;
        word-wrap: break-word !important;
    }

    .asset-modal-value {
        font-size: 0.95rem !important;
    }
}

/* Extra small devices */
@media (max-width: 480px) {
    section h2 {
        font-size: 1.1rem !important;
    }

    div[style*="grid-template-columns: repeat(auto-fill"] {
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)) !important;
        gap: 0.6rem !important;
    }

    .asset-row {
        padding: 0.85rem !important;
        gap: 0.4rem !important;
    }

    .asset-card-balance {
        font-size: 1rem !important;
    }

    .asset-card-name {
        font-size: 0.8rem !important;
    }

    .asset-modal {
        padding: 1.25rem !important;
    }
}