/* Profile Page Responsive Styles */

/* Ensure all profile elements use border-box */
.profile-container * {
    box-sizing: border-box;
}

/* Profile Container - Full width with flex layout */
.profile-container {
    background: rgba(255, 255, 255, 0.02);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 12px;
    padding: 1.5rem;
    margin-top: 1.5rem;
    width: 100% !important; /* Full width of parent container - override any restrictions */
    max-width: none !important; /* Remove any max-width constraints */
    display: flex; /* Flex layout for responsive boxes */
    flex-wrap: wrap; /* Allow items to wrap to next line */
    gap: 1.5rem; /* Space between flex items */
    box-sizing: border-box;
    align-items: flex-start; /* Align items to top so they can have different heights */
}

/* Profile Info Sections - Flexible height boxes that arrange responsively */
.profile-info {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 10px;
    padding: 1.5rem;
    width: calc(50% - 0.75rem); /* Two columns on desktop */
    min-width: 350px; /* Minimum width before wrapping */
    flex: 1 1 calc(50% - 0.75rem); /* Flexible but starts at 50% */
    height: auto !important; /* Height depends on content */
    min-height: unset; /* Remove any minimum height */
    overflow-x: hidden;
    box-sizing: border-box;
    align-self: flex-start; /* Each box starts at top and grows with content */
}

/* No need for margin-bottom since flex gap handles spacing */

.profile-info h2 {
    color: #00FF88;
    font-size: 1.3rem;
    margin: 0 0 1.5rem 0;
    font-family: 'Orbitron', monospace;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Info Groups */
.info-group {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    width: 100%;
    gap: 1rem;
    flex-wrap: wrap;
}

.info-group:last-child {
    border-bottom: none;
}

.info-group label {
    color: rgba(255, 255, 255, 0.6);
    font-size: 0.9rem;
    flex: 0 0 auto;
    min-width: fit-content;
}

.info-group p {
    color: white;
    font-family: 'JetBrains Mono', monospace;
    margin: 0;
    text-align: right;
    word-break: break-word;
    overflow-wrap: break-word;
    flex: 1 1 auto;
    max-width: 70%;
}

/* Trading Settings */
.trading-settings {
    width: 100%;
    padding: 0;
}

.trading-settings .setting-row {
    padding: 2rem;
    margin: 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    width: 100%;
    display: block;
    box-sizing: border-box;
}

.trading-settings .setting-row:last-child {
    border-bottom: none;
}

.setting-info {
    margin-bottom: 1.5rem;
    padding: 0;
}

.setting-info h3 {
    color: #00D4FF;
    font-size: 1.1rem;
    margin: 0 0 0.75rem 0;
    line-height: 1.4;
    font-weight: 600;
}

.setting-info p {
    color: rgba(255, 255, 255, 0.7);
    font-size: 0.9rem;
    margin: 0;
    line-height: 1.6;
}

/* Balance Input Group */
.balance-input-group {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap; /* Allow wrapping on small screens */
    width: 100%;
    padding: 1rem 1.25rem;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    box-sizing: border-box;
}

/* Balance input labels (Futures/Spot) */
.balance-input-group label {
    flex: 0 0 auto;
    min-width: fit-content;
    white-space: nowrap;
    color: rgba(255, 255, 255, 0.7);
    font-weight: 500;
    margin-right: 0.5rem;
}

/* Input with suffix container */
.input-with-suffix {
    flex: 1 1 auto;
    position: relative;
    display: flex;
    align-items: center;
    min-width: 150px;
}

/* Balance input fields within suffix container */
.input-with-suffix input[type="number"] {
    width: 100%;
    padding-right: 3.5rem; /* Make room for USDT text */
    padding-left: 1rem;
}

/* Currency suffix inside input */
.currency-suffix {
    position: absolute;
    right: 1rem;
    color: rgba(255, 255, 255, 0.6);
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.9rem;
    font-weight: 600;
    pointer-events: none; /* Can't click on it */
    user-select: none; /* Can't select it */
}

/* Balance Input Fields - Hide spinner arrows and improve width */
#initialBalanceInput,
#futuresBalanceInput,
#spotBalanceInput,
input[type="number"] {
    flex: 1 1 auto;
    min-width: 150px;
    width: 100%;
    max-width: none;
    padding: 0.85rem 1.25rem;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    color: white;
    font-family: 'JetBrains Mono', monospace;
    font-size: 1rem;
    box-sizing: border-box;
    transition: all 0.3s ease;
    /* Hide spinner arrows */
    -webkit-appearance: none;
    -moz-appearance: textfield;
}

/* Hide spinner arrows in WebKit browsers */
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
    display: none;
}

/* Old currency-label class - kept for backward compatibility if needed elsewhere */
.currency-label {
    color: rgba(255, 255, 255, 0.9);
    font-weight: 600;
    font-family: 'JetBrains Mono', monospace;
    font-size: 1rem;
    padding: 0 0.75rem;
}

.btn-save-balance {
    margin-left: auto;
    padding: 0.85rem 2rem;
    background: linear-gradient(135deg, #00FF88 0%, #00D4FF 100%);
    color: #0A0A0B;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.95rem;
    transition: all 0.3s ease;
    white-space: nowrap;
    flex-shrink: 0;
}

.btn-save-balance:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(0, 255, 136, 0.3);
}

.btn-save-balance:active {
    transform: translateY(0);
}

/* Focus and hover states for all number inputs */
input[type="number"]:focus,
#initialBalanceInput:focus,
#futuresBalanceInput:focus,
#spotBalanceInput:focus {
    outline: none;
    border-color: #00FF88;
    background: rgba(255, 255, 255, 0.1);
    box-shadow: 0 0 0 2px rgba(0, 255, 136, 0.2);
}

input[type="number"]:hover,
#initialBalanceInput:hover,
#futuresBalanceInput:hover,
#spotBalanceInput:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.3);
}

/* Balance Status */
#balanceStatus {
    margin-top: 0.75rem;
    font-size: 0.9rem;
    padding: 0.5rem;
    border-radius: 6px;
    display: none;
}

#balanceStatus.success {
    background: rgba(0, 255, 136, 0.1);
    color: #00FF88;
    border: 1px solid rgba(0, 255, 136, 0.3);
    display: block;
}

#balanceStatus.error {
    background: rgba(255, 59, 48, 0.1);
    color: #FF3B30;
    border: 1px solid rgba(255, 59, 48, 0.3);
    display: block;
}

/* Lock Message */
#balanceLockMessage {
    display: none;
    margin-top: 1rem;
    padding: 1rem;
    background: rgba(255, 215, 0, 0.1);
    border: 1px solid #FFD700;
    border-radius: 8px;
}

#balanceLockMessage p {
    color: #FFD700;
    margin: 0;
    font-size: 0.9rem;
}

.upgrade-link {
    color: #00FF88;
    text-decoration: underline;
    margin-left: 0.5rem;
    transition: all 0.3s ease;
}

.upgrade-link:hover {
    color: #00D4FF;
    text-decoration: none;
}

/* Notification Settings */
.notification-settings {
    width: 100%;
    padding: 0;
}

.notification-settings .setting-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1.5rem;
    width: 100%;
    padding: 1.5rem;
    margin: 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    box-sizing: border-box;
}

.notification-settings .setting-row:last-child {
    border-bottom: none;
}

/* Toggle Switch */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 60px;
    height: 30px;
    flex-shrink: 0;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(255, 255, 255, 0.2);
    transition: .4s;
    border-radius: 34px;
}

.toggle-slider:before {
    position: absolute;
    content: "";
    height: 24px;
    width: 24px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}

input:checked + .toggle-slider {
    background: linear-gradient(135deg, #00FF88 0%, #00D4FF 100%);
}

input:checked + .toggle-slider:before {
    transform: translateX(30px);
}

/* Notification Status */
.notification-status {
    margin-top: 0.75rem;
    padding: 0.75rem;
    border-radius: 6px;
    font-size: 0.85rem;
    display: none;
}

.notification-status.show {
    display: block;
}

.notification-status.success {
    background: rgba(0, 255, 136, 0.1);
    color: #00FF88;
    border: 1px solid rgba(0, 255, 136, 0.3);
}

.notification-status.error {
    background: rgba(255, 59, 48, 0.1);
    color: #FF3B30;
    border: 1px solid rgba(255, 59, 48, 0.3);
}

/* Active Devices */
#activeDevices {
    margin-top: 1rem;
    padding: 1rem;
    background: rgba(0, 255, 136, 0.05);
    border-radius: 8px;
    border: 1px solid rgba(0, 255, 136, 0.2);
}

#activeDevices h4 {
    color: #00FF88;
    margin: 0 0 0.75rem 0;
    font-size: 1rem;
}

#devicesList {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.device-item {
    padding: 0.5rem;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 6px;
    font-size: 0.85rem;
    color: rgba(255, 255, 255, 0.8);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* PWA Push Section */
#pwa-push-section {
    margin-top: 1rem;
    padding: 1rem;
    background: rgba(0, 212, 255, 0.05);
    border-radius: 8px;
    border: 1px solid rgba(0, 212, 255, 0.2);
}

#pwa-push-section button {
    background: linear-gradient(135deg, #00FF88 0%, #00D4FF 100%);
    color: #0A0A0B;
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.3s ease;
    width: 100%;
    max-width: 300px;
}

#pwa-push-section button:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(0, 255, 136, 0.3);
}

#pwa-push-section p {
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.6);
    margin: 0.5rem 0 0 0;
}

/* Responsive Styles */

/* Large Desktop - Above 1400px */
@media (min-width: 1400px) {
    .profile-info {
        width: calc(33.333% - 1rem); /* Three columns on large screens */
        flex: 1 1 calc(33.333% - 1rem);
        min-width: 320px; /* Slightly smaller min-width for 3-column layout */
    }
}

/* Tablet - 768px to 1024px */
@media (max-width: 1024px) {
    .profile-container {
        padding: 1.25rem;
        gap: 1.25rem;
    }

    .profile-info {
        padding: 1.25rem;
        width: 100%; /* Full width on tablets */
        flex: 1 1 100%;
        min-width: unset;
    }

    .profile-info h2 {
        font-size: 1.2rem;
    }
}

/* Mobile - 480px to 768px */
@media (max-width: 768px) {
    .profile-container {
        padding: 1rem;
        margin-top: 1rem;
        gap: 1rem;
    }

    .profile-info {
        padding: 1rem;
        width: 100%; /* Full width on mobile */
        flex: 1 1 100%;
    }

    .profile-info h2 {
        font-size: 1.1rem;
        margin-bottom: 1rem;
    }

    .info-group {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
        padding: 0.75rem 0;
    }

    .info-group label {
        width: 100%;
        margin-bottom: 0.25rem;
        font-size: 0.85rem;
    }

    .info-group p {
        text-align: left;
        max-width: 100%;
        width: 100%;
        word-wrap: break-word;
        font-size: 0.95rem;
    }

    .trading-settings .setting-row,
    .notification-settings .setting-row {
        padding: 1.25rem;
        flex-direction: column;
        align-items: stretch;
        gap: 1rem;
    }

    .setting-info {
        padding-right: 0;
        margin-bottom: 1.25rem;
    }

    .setting-info h3 {
        font-size: 1rem;
    }

    .setting-info p {
        padding-right: 0;
        font-size: 0.85rem;
    }

    .balance-input-group {
        flex-direction: row; /* Keep horizontal even on mobile */
        align-items: center;
        gap: 0.5rem;
        padding: 1rem;
        flex-wrap: nowrap; /* Don't wrap on mobile */
    }

    /* Input with suffix container on mobile */
    .input-with-suffix {
        flex: 1 1 auto;
        min-width: 100px;
    }

    /* Adjust input padding on mobile */
    .input-with-suffix input[type="number"],
    #futuresBalanceInput,
    #spotBalanceInput {
        padding: 0.75rem 3rem 0.75rem 0.75rem; /* Room for USDT on right */
        font-size: 0.95rem;
    }

    /* Keep label inline on mobile */
    .balance-input-group label {
        flex: 0 0 auto;
        width: auto;
        margin-bottom: 0;
        margin-right: 0.5rem;
        font-size: 0.9rem;
    }

    /* Currency suffix positioning on mobile */
    .currency-suffix {
        right: 0.75rem;
        font-size: 0.85rem;
    }

    .btn-save-balance {
        width: 100%;
        padding: 0.85rem;
        margin-left: 0;
        font-size: 0.95rem;
    }

    .toggle-switch {
        align-self: flex-start;
        margin-top: 0.5rem;
    }

    #pwa-push-section button {
        max-width: 100%;
    }
}

/* Small Mobile - Below 480px */
@media (max-width: 480px) {
    .profile-container {
        padding: 0.75rem;
        border-radius: 8px;
    }

    .profile-info {
        padding: 0.75rem;
        border-radius: 8px;
    }

    .profile-info h2 {
        font-size: 1rem;
        margin-bottom: 0.75rem;
    }

    .info-group {
        padding: 0.5rem 0;
    }

    .info-group label {
        font-size: 0.85rem;
    }

    .info-group p {
        font-size: 0.9rem;
    }

    .trading-settings .setting-row,
    .notification-settings .setting-row {
        padding: 1rem;
    }

    .setting-info h3 {
        font-size: 0.95rem;
    }

    .setting-info p {
        font-size: 0.8rem;
        line-height: 1.5;
    }

    .balance-input-group {
        padding: 0.85rem;
        gap: 0.85rem;
    }

    #initialBalanceInput {
        padding: 0.75rem 1rem;
        font-size: 0.9rem;
    }

    .btn-save-balance {
        padding: 0.75rem 1.25rem;
        font-size: 0.9rem;
    }

    /* Currency suffix for smaller screens */
    .currency-suffix {
        font-size: 0.85rem;
        right: 0.6rem;
    }

    #balanceStatus {
        font-size: 0.85rem;
    }

    #balanceLockMessage {
        padding: 0.75rem;
    }

    #balanceLockMessage p {
        font-size: 0.85rem;
    }

    .notification-status {
        font-size: 0.8rem;
        padding: 0.5rem;
    }

    #activeDevices {
        padding: 0.75rem;
    }

    #activeDevices h4 {
        font-size: 0.9rem;
    }

    .device-item {
        font-size: 0.8rem;
        padding: 0.4rem;
    }

    #pwa-push-section {
        padding: 0.75rem;
    }

    #pwa-push-section button {
        padding: 0.6rem 1rem;
        font-size: 0.9rem;
    }

    #pwa-push-section p {
        font-size: 0.7rem;
    }

    /* Small toggle for mobile */
    .toggle-switch {
        width: 50px;
        height: 26px;
    }

    .toggle-slider:before {
        height: 20px;
        width: 20px;
    }

    input:checked + .toggle-slider:before {
        transform: translateX(24px);
    }
}

/* Landscape Mode */
@media (max-width: 896px) and (orientation: landscape) {
    .profile-container {
        padding: 0.75rem;
    }

    .profile-info {
        padding: 0.75rem;
        margin-bottom: 0.75rem;
    }

    .profile-info h2 {
        font-size: 1rem;
    }
}

/* Ensure buttons are always visible */
button {
    display: inline-block !important;
    visibility: visible !important;
    opacity: 1 !important;
}

/* Prevent horizontal scrolling */
#profile {
    max-width: 100%;
    overflow-x: hidden;
}

/* Desktop layout optimization */
@media (min-width: 769px) {
    .balance-input-group {
        justify-content: flex-start;
        align-items: center;
        padding: 1.25rem 1.5rem;
        gap: 1.5rem;
    }

    #initialBalanceInput {
        max-width: 220px;
        flex: 0 1 220px;
    }

    /* Currency suffix on desktop */
    .currency-suffix {
        font-size: 0.95rem;
    }

    .btn-save-balance {
        margin-left: auto;
        padding: 0.9rem 2.25rem;
    }
}

/* Large screens */
@media (min-width: 1200px) {
    .trading-settings .setting-row,
    .notification-settings .setting-row {
        padding: 2.25rem;
    }

    .setting-info {
        max-width: 65%;
        margin-bottom: 1.75rem;
    }

    .setting-info h3 {
        font-size: 1.2rem;
        margin-bottom: 0.85rem;
    }

    .setting-info p {
        font-size: 0.95rem;
        line-height: 1.7;
    }

    .balance-input-group {
        padding: 1.35rem 1.75rem;
        gap: 1.75rem;
    }

    #initialBalanceInput {
        padding: 1rem 1.5rem;
        font-size: 1.05rem;
        max-width: 250px;
    }

    /* Currency suffix on large screens */
    .currency-suffix {
        font-size: 1rem;
        right: 1.25rem;
    }

    .btn-save-balance {
        padding: 1rem 2.5rem;
        font-size: 1rem;
    }
}

/* Security: Prevent XSS in dynamic content */
.info-group p,
#balanceStatus,
.notification-status,
.device-item {
    /* Ensure text content is treated as text, not HTML */
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

/* Additional security for user inputs */
#initialBalanceInput {
    /* Prevent script injection via input */
    -webkit-user-modify: read-write-plaintext-only;
}

/* Accessibility improvements */
.toggle-switch input:focus + .toggle-slider {
    box-shadow: 0 0 0 3px rgba(0, 255, 136, 0.3);
}

button:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(0, 255, 136, 0.3);
}

input:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(0, 255, 136, 0.3);
}

/* Dark mode optimization */
@media (prefers-color-scheme: dark) {
    .profile-container {
        background: rgba(0, 0, 0, 0.5);
    }

    .profile-info {
        background: rgba(0, 0, 0, 0.6);
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .profile-container,
    .profile-info {
        border-width: 2px;
    }

    .info-group {
        border-bottom-width: 2px;
    }
}

/* Print styles */
@media print {
    .toggle-switch,
    button,
    #pwa-push-section {
        display: none !important;
    }

    .profile-container {
        background: white;
        color: black;
        border: 1px solid black;
    }

    .info-group label,
    .info-group p {
        color: black;
    }
}