/* ===========================================
   RESPONSIVE STYLES FOR MOBILE DEVICES
   =========================================== */

/* 
 * Breakpoints:
 * - Tablet landscape and below: 1024px
 * - Tablet portrait: 768px  
 * - Mobile: 480px
 */

/* ==========================================
   TABLET PORTRAIT AND BELOW (768px)
   ========================================== */
@media screen and (max-width: 768px) {
    /* Base layout */
    body {
        padding: 15px;
        font-size: 14px;
    }

    h1 {
        font-size: 1.5em;
    }

    h2 {
        font-size: 1.3em;
    }

    h3 {
        font-size: 1.1em;
    }

    /* Header - stack on mobile */
    .header {
        flex-direction: column;
        gap: 10px;
        text-align: center;
    }

    .header button {
        width: 100%;
    }

    /* Page header (used on some tool pages) */
    .page-header {
        flex-direction: column;
        gap: 10px;
        text-align: center;
    }

    .page-header button {
        width: 100%;
    }

    /* Navigation buttons - full width stack */
    .nav-buttons {
        flex-direction: column;
    }

    .nav-buttons button {
        width: 100%;
        padding: 15px;
    }

    /* Input groups - stack label above input */
    .input-group {
        display: flex;
        flex-direction: column;
        align-items: stretch;
    }

    .input-group label {
        width: 100% !important;
        margin-bottom: 5px;
    }

    .input-group input,
    .input-group select {
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box;
    }

    /* Form groups */
    .form-group input,
    .form-group select,
    .form-group textarea {
        width: 100% !important;
        box-sizing: border-box;
    }

    /* Button rows - wrap nicely */
    .button-row {
        flex-direction: column;
        width: 100%;
    }

    .button-row button {
        width: 100%;
    }

    /* Tables - horizontal scroll wrapper */
    .table-wrapper {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    table {
        min-width: 500px;
        font-size: 12px;
    }

    th, td {
        padding: 6px 4px;
    }

    /* Summary boxes */
    .summary-box {
        padding: 12px;
    }

    .summary-amount {
        font-size: 22px;
    }

    /* Account boxes */
    .account-box {
        padding: 12px;
    }

    .account-box h4 {
        flex-direction: column;
        gap: 10px;
        text-align: center;
    }

    .account-box h4 > div {
        display: flex;
        flex-direction: column;
        gap: 5px;
    }

    /* Sections */
    .section {
        padding: 12px;
    }

    /* Ad containers - responsive */
    .ad-container {
        margin: 15px auto;
    }

    .ad-container.ad-header,
    .ad-container.ad-footer {
        max-width: 100%;
        min-height: 60px;
    }

    /* Modals */
    .modal-content {
        margin: 20px;
        padding: 20px;
        max-width: calc(100% - 40px);
    }

    /* Footer */
    .site-footer {
        padding: 20px 10px;
    }

    .footer-links {
        display: flex;
        flex-direction: column;
        gap: 10px;
    }

    .footer-links a {
        margin: 0;
    }

    /* ==========================================
       PAGE-SPECIFIC: INDEX
       ========================================== */
    .welcome-banner {
        padding: 12px;
    }

    .welcome-banner p {
        font-size: 13px;
    }

    /* ==========================================
       PAGE-SPECIFIC: PORTFOLIO REBALANCER
       ========================================== */
    .setup-row {
        grid-template-columns: 1fr !important;
        gap: 15px;
    }

    .main-content {
        grid-template-columns: 1fr !important;
    }

    .results-grid {
        grid-template-columns: 1fr !important;
    }

    /* Chart container */
    .chart-container {
        max-width: 100%;
        height: 250px;
    }

    /* ==========================================
       PAGE-SPECIFIC: WITHDRAWAL ASSISTANT  
       ========================================== */
    .container {
        grid-template-columns: 1fr !important;
    }

    .summary-row {
        grid-template-columns: 1fr !important;
    }

    /* Tax bracket visualization */
    .tax-bracket {
        padding: 8px;
    }

    /* ==========================================
       PAGE-SPECIFIC: PORTFOLIO PROJECTIONS
       ========================================== */
    .main-layout {
        grid-template-columns: 1fr !important;
    }

    .projection-controls {
        flex-direction: column;
        gap: 10px;
    }

    /* ==========================================
       PAGE-SPECIFIC: RATE OF RETURN
       ========================================== */
    .input-column {
        width: 100% !important;
    }

    .results-column {
        width: 100% !important;
    }

    .input-row {
        flex-direction: column;
        gap: 10px;
    }

    .input-row .input-group {
        width: 100%;
    }

    /* ==========================================
       PAGE-SPECIFIC: LEGAL PAGES
       ========================================== */
    .legal-content section {
        padding: 15px;
    }

    .tool-description,
    .faq-item {
        padding: 15px;
    }

    .contact-form {
        padding: 20px;
    }

    .google-form-container iframe {
        height: 800px;
    }
}

/* ==========================================
   MOBILE PHONES (480px and below)
   ========================================== */
@media screen and (max-width: 480px) {
    body {
        padding: 10px;
    }

    h1 {
        font-size: 1.3em;
    }

    .section {
        padding: 10px;
        margin: 8px 0;
    }

    .summary-amount {
        font-size: 20px;
    }

    /* Even smaller tables */
    table {
        font-size: 11px;
    }

    th, td {
        padding: 4px 3px;
    }

    /* Buttons - slightly smaller padding */
    button {
        padding: 10px 12px;
        font-size: 13px;
    }

    /* Investment tables - allow scroll */
    .account-box table {
        display: block;
        overflow-x: auto;
    }

    /* Input sizing */
    input, select {
        font-size: 16px; /* Prevents zoom on iOS */
    }

    /* Ad containers */
    .ad-container.ad-header,
    .ad-container.ad-footer {
        min-height: 50px;
    }

    /* Footer copyright text */
    .site-footer p {
        font-size: 11px;
    }
}

/* ==========================================
   PREVENT iOS ZOOM ON INPUT FOCUS
   ========================================== */
@media screen and (max-width: 768px) {
    input[type="text"],
    input[type="number"],
    input[type="email"],
    input[type="date"],
    select,
    textarea {
        font-size: 16px;
    }
}

/* ==========================================
   UTILITY: RESPONSIVE TABLE WRAPPER
   Use: <div class="table-responsive"><table>...</table></div>
   ========================================== */
.table-responsive {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* ==========================================
   UTILITY: HIDE ON MOBILE / SHOW ON MOBILE
   ========================================== */
@media screen and (max-width: 768px) {
    .hide-mobile {
        display: none !important;
    }
}

@media screen and (min-width: 769px) {
    .hide-desktop {
        display: none !important;
    }
}

/* ==========================================
   INLINE STYLE OVERRIDES FOR GRIDS
   (handles inline styles in HTML)
   ========================================== */
@media screen and (max-width: 768px) {
    [style*="grid-template-columns: 1fr 1fr"] {
        grid-template-columns: 1fr !important;
    }

    [style*="display: grid"][style*="gap"] {
        gap: 15px !important;
    }

    /* Fix inline flex layouts */
    [style*="display: flex"][style*="justify-content: space-between"] {
        flex-direction: column;
        gap: 10px;
    }
}
