/* 
 * RappoDEV Tools - Small Device Support
 * Enhanced responsive design for all tools across mobile devices
 * To be included by all tools for consistent mobile experience
 */

/* Hide back button text on all screen sizes - show only the icon */
.back-button-text {
    display: none;
}

/* Additional adjustment for back button to center the icon */
.back-button {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px;
    width: 36px;
    height: 36px;
    transition: background-color 0.2s ease;
    position: relative;
}

/* Add hover effect that doesn't move the button itself */
.back-button:hover {
    background-color: rgba(0, 0, 0, 0.05);
}

.back-button svg {
    transition: transform 0.2s ease;
}

.back-button:hover svg {
    transform: translateX(-2px);
}

body.dark-theme .back-button:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

/* Make result values wrap properly on all screen sizes - ensure they're fully visible */
.result-value {
    word-break: break-word;
    overflow-wrap: break-word;
    max-width: 100%;
    display: inline-block;
    font-size: 0.95em; /* Slightly smaller font for better fit */
}

/* Ensure tables can be scrolled horizontally */
.interpretation-table, .table-container {
    max-width: 100%;
    overflow-x: auto;
    display: block;
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
}

/* Fix for calculator sections to prevent overflow */
.calculator {
    width: 100%;
    max-width: 100%;
    overflow: hidden;
}

/* Output section fixes to ensure results always visible */
.output-section {
    width: 100%;
    overflow-x: auto;
}

/* Result container improvements */
.result-group, #resultsContainer {
    display: flex;
    flex-direction: column;
    width: 100%;
    gap: 8px;
}

/* Improved iteration controls for all screen sizes */
.iteration-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin: 12px 0;
    width: 100%;
    justify-content: flex-start;
}

.iteration-question {
    display: flex;
    width: 100%;
    margin-bottom: 8px;
    font-weight: 500;
}

.iterate-button, .iteration-button {
    min-width: 80px;
    flex: 0 1 auto;
    text-align: center;
}

/* Ensure calculator expressions and results are always visible */
.calculator-display .expression,
.calculator-display .result {
    overflow-x: auto;
    white-space: nowrap;
    scrollbar-width: thin;
    -ms-overflow-style: none;
}

.calculator-display .expression::-webkit-scrollbar,
.calculator-display .result::-webkit-scrollbar {
    height: 3px;
}

.calculator-display .expression::-webkit-scrollbar-thumb,
.calculator-display .result::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 3px;
}

body.dark-theme .calculator-display .expression::-webkit-scrollbar-thumb,
body.dark-theme .calculator-display .result::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
}

/* Global responsive improvements for all tool pages */
@media (max-width: 768px) {
    /* Standard padding for all containers on tablets */
    main.container,
    body .container,
    [class*="calc"] .container,
    [class*="tool"] .container {
        padding: 16px !important;
    }
    
    /* Improve header legibility and layout on tablets */
    .header-container {
        padding-top: 16px;
        padding-bottom: 12px;
        flex-wrap: wrap;
    }
    
    .header-container h1 {
        font-size: 1.5rem;
        width: 100%;
        text-align: center;
        margin: 8px 0;
        order: 2;
    }
    
    .header-left {
        order: 1;
    }
    
    .settings-container {
        order: 3;
    }
    
    /* Description text better spacing */
    .description {
        margin-bottom: 16px;
        text-align: center;
    }
    
    /* Standard calculator layout for tablets */
    .calculator {
        display: flex;
        flex-direction: column;
    }
    
    /* Input and output sections should be full width and properly aligned */
    .input-section, 
    .output-section {
        width: 100%;
        padding: 16px;
    }
    
    /* Ensure form controls have enough space */
    .form-group {
        margin-bottom: 16px;
    }
    
    /* Unit toggles should be properly sized */
    .input-with-units {
        display: flex;
        width: 100%;
    }
    
    .input-with-units input {
        flex: 1;
    }
    
    /* Make all tables responsive on tablets */
    .interpretation-table {
        font-size: 0.9rem;
    }

    /* Better visibility for calculator displays */
    .calculator-display {
        padding: var(--space-md);
    }
}

/* Mobile specific improvements */
@media (max-width: 480px) {
    /* Reduce padding for mobile */
    main.container,
    body .container,
    [class*="calc"] .container,
    [class*="tool"] .container {
        padding: 12px !important;
    }
    
    /* Smaller header on mobile */
    .header-container h1 {
        font-size: 1.3rem;
    }
    
    /* Optimize input styling for mobile */
    input[type="number"],
    input[type="text"],
    select,
    .input-with-units input {
        font-size: 16px; /* Prevent iOS zoom on focus */
        height: 44px; /* Larger touch target */
        padding: 8px;
    }
    
    /* Optimize buttons for touch on mobile */
    button, 
    .primary-button,
    .secondary-button,
    .unit-btn {
        min-height: 44px; /* Larger touch target */
        padding: 10px 16px;
    }
    
    /* Button groups should be full width */
    .button-group {
        display: flex;
        flex-direction: column;
        width: 100%;
        gap: 8px;
    }
    
    .button-group button {
        width: 100%;
        margin: 0;
    }
    
    /* Ensure table cells have enough space */
    .table-cell {
        padding: 8px;
        font-size: 0.85rem;
    }
    
    /* Fix reference section on mobile */
    .reference-grid {
        display: flex;
        flex-direction: column;
        gap: 16px;
    }
    
    .reference-item {
        width: 100%;
    }
    
    /* Fix for specific tools */
    .tab-container,
    .tabs {
        display: flex;
        flex-direction: column;
        width: 100%;
    }
    
    /* Adjust form layout in mobile */
    label {
        display: block;
        margin-bottom: 6px;
    }
    
    /* Result values should be very clear */
    .result-value {
        font-size: 1rem;
        font-weight: 500;
    }
    
    /* Warning messages need proper display */
    .warning-message {
        padding: 12px;
        margin: 8px 0;
    }
    
    /* Enhanced iteration controls for mobile */
    .iteration-controls {
        flex-direction: column;
        width: 100%;
        gap: 8px;
        margin: 10px 0;
    }
    
    .iteration-question {
        font-size: 0.95rem;
        text-align: center;
    }
    
    .iterate-button, .iteration-button {
        width: 100%;
        min-height: 44px;
        display: flex;
        justify-content: center;
        align-items: center;
    }
    
    /* Fix for calculation history on mobile */
    .history-container {
        width: 100%;
        max-height: 300px;
        overflow-y: auto;
    }
    
    .history-item {
        padding: 10px;
        border-radius: 6px;
        margin-bottom: 8px;
    }
    
    /* Better handle very long result values */
    .result-value {
        font-size: 0.9rem;
        white-space: normal;
        line-height: 1.4;
    }
    
    /* Ensure result labels are clear */
    .result-label {
        display: block;
        margin-bottom: 4px;
        font-weight: 500;
    }
    
    /* Make sure result lines don't overflow */
    .result-line {
        display: flex;
        flex-wrap: wrap;
        margin-bottom: 8px;
    }

    /* Calculator specific mobile optimizations */
    .calculator-container {
        width: 100%;
        max-width: 100%;
        margin: 0;
    }

    .calculator-grid {
        grid-template-columns: repeat(4, 1fr);
        gap: 6px;
    }

    .calculator-key {
        height: 3rem;
        font-size: 1.1rem;
        padding: 0;
    }

    /* Ensure calculator display is properly visible */
    .calculator-display .expression {
        font-size: 1.2rem;
        overflow-x: auto;
    }

    .calculator-display .result {
        font-size: 1rem;
        overflow-x: auto;
    }

    /* Stack result items for better mobile viewing */
    .result-item {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .result-item .result-header {
        margin-bottom: 4px;
        width: 100%;
    }
    
    .result-item .result-value {
        width: 100%;
    }
}

/* Extra small devices (phones under 375px) */
@media (max-width: 375px) {
    .header-container h1 {
        font-size: 1.1rem;
    }
    
    /* Further reduced padding */
    .input-section, 
    .output-section {
        padding: 10px;
    }
    
    /* Smallest font size for table contents */
    .table-cell {
        padding: 6px;
        font-size: 0.8rem;
    }
    
    /* Extra handling for very small screens */
    .result-wrapper {
        font-size: 0.85rem;
    }
    
    /* Break long words if necessary */
    .result-value {
        word-break: break-all;
        hyphens: auto;
    }
    
    /* Stack iteration buttons vertically */
    .iteration-controls button {
        width: 100%;
        margin: 4px 0;
    }
    
    /* Make sure yes/no buttons are distinct */
    .iterate-yes {
        background-color: var(--primary-color, #4CAF50);
        color: white;
    }
    
    .iterate-no {
        background-color: var(--neutral-color, #9e9e9e);
        color: white;
    }

    /* Optimize calculator for tiny screens */
    .calculator-grid {
        gap: 4px;
    }

    .calculator-key {
        height: 2.8rem;
        font-size: 1rem;
    }

    /* Make input-with-units stack vertically on tiny screens */
    .input-with-units {
        flex-direction: column;
        align-items: flex-start;
        gap: 6px;
    }

    .unit-toggle {
        width: 100%;
    }

    /* Ensure values in tiny screens remain legible */
    .calculator-display {
        padding: 8px;
    }

    .calculator-display .expression {
        font-size: 1.1rem;
    }

    .calculator-display .result {
        font-size: 0.9rem;
    }
}