/* Mobile Responsive Styles */
/* This file MUST be loaded AFTER main.css to properly override desktop styles */

/* Reset and viewport settings */
* {
    box-sizing: border-box;
}

/* Mobile Ask AI Button Adjustments */
@media (max-width: 768px) {
    .floating-ask-ai-btn {
        bottom: 90px;
        right: 24px;
        padding: 12px 18px;
        font-size: 14px;
    }

    .floating-ask-ai-btn svg {
        width: 18px;
        height: 18px;
    }

    .ask-ai-content {
        width: 95%;
        max-height: 90vh;
    }

    .ask-ai-header {
        padding: 20px 24px;
    }

    .ask-ai-title {
        font-size: 20px;
    }

    .ask-ai-body {
        padding: 20px 24px;
    }

    .ask-ai-textarea {
        min-height: 120px;
        font-size: 13px;
    }

    .ai-service-links {
        grid-template-columns: 1fr;
    }

    .ai-service-link {
        padding: 12px 16px;
        font-size: 14px;
    }
}

/* Ensure proper viewport on all mobile devices */
html {
    -webkit-text-size-adjust: none;
    -moz-text-size-adjust: none;
    -ms-text-size-adjust: none;
    text-size-adjust: none;
    /* Prevent horizontal scrolling */
    overflow-x: hidden;
    width: 100%;
    max-width: 100%;
}

body {
    overflow-x: hidden;
    width: 100%;
    max-width: 100%;
    min-height: 100vh;
    margin: 0;
    padding: 0;
    /* Base font size for mobile */
    font-size: clamp(15px, 1.6vw + 0.5rem, 17px);
    line-height: 1.45;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* Force mobile styles for all touch devices and small screens */
@media (hover: none) and (pointer: coarse), (max-width: 768px) {
    /* These styles apply to ALL touch devices including iPhone */
    body {
        font-size: clamp(1rem, 1.2vw + 0.55rem, 1.15rem) !important;
        line-height: 1.5;
    }

    .main-content {
        width: 100vw !important;
        max-width: 100vw !important;
        padding: 0 !important;
        margin: 0 !important;
    }

    /* Force all text elements to use consistent scale */
    p, div, span, label, td, th, li {
        font-size: inherit !important;
        line-height: 1.5;
    }

    /* Ensure interactive controls remain readable and tappable */
    input, select, textarea, button {
        font-size: clamp(0.9rem, 2.2vw, 1.05rem) !important;
        min-height: clamp(38px, 9vw, 48px) !important;
        padding: 8px 12px !important;
    }

    /* Add buttons - larger for mobile touch */
    .btn-add {
        font-size: clamp(1.05rem, 2.8vw, 1.2rem) !important;
        min-height: 44px !important;
        padding: 12px 20px !important;
        font-weight: 500 !important;
    }

    /* Headers */
    h1 { font-size: clamp(1.2rem, 3.4vw, 1.5rem) !important; }
    h2 { font-size: clamp(1.05rem, 2.8vw, 1.3rem) !important; }
    h3 { font-size: clamp(1rem, 2.4vw, 1.2rem) !important; }
    h4 { font-size: clamp(0.95rem, 2vw, 1.1rem) !important; }

    /* Specific overrides - align section headings with totals */
    .column-header {
        font-size: clamp(1.1rem, 3.2vw, 1.35rem) !important;
        font-weight: 600 !important;
        padding: clamp(8px, 2vw, 12px) 0 !important;
    }

    .section-title {
        font-size: clamp(1.05rem, 2.8vw, 1.25rem) !important;
        font-weight: 500 !important;
        padding: clamp(6px, 1.8vw, 10px) 0 !important;
    }

    /* Match total amounts with headers */
    .column-header .total-amount,
    .section-title .total-amount,
    .total-amount {
        font-size: clamp(1.05rem, 2.8vw, 1.3rem) !important;
        font-weight: 600 !important;
        display: block;
    }

    .cash-input {
        font-size: inherit !important;
        min-height: clamp(36px, 8vw, 44px) !important;
    }
}

/* iPhone specific adjustments */
@supports (-webkit-touch-callout: none) {
    body {
        font-size: clamp(1rem, 1.2vw + 0.55rem, 1.15rem) !important;
        line-height: 1.5;
    }

    .main-content {
        width: 100vw;
        max-width: 100vw;
    }
}

/* Prevent horizontal overflow from all containers */
.main-content,
.container,
.main-container {
    max-width: 100%;
    overflow-x: hidden;
}

@media (max-width: 1200px) {
    .main-container {
        grid-template-columns: 1fr;
        padding: 0 15px;
    }
}

/* Tablet and mobile devices */
@media (max-width: 968px) {
    /* Keep desktop font size for tablets */
    body {
        font-size: clamp(1rem, 1.1vw + 0.6rem, 1.1rem) !important;
        line-height: 1.5;
    }

    /* Hide desktop navigation on tablets/mobile */
    .top-controls {
        display: none !important;
    }

    /* Hide mobile navigation bar - use floating buttons instead */
    .mobile-nav {
        display: none !important;
    }

    .mobile-nav-left {
        flex-shrink: 0;
    }

    /* Hide desktop sidebar toggle - we use floating button */
    .desktop-sidebar-toggle {
        display: none !important;
    }

    /* Make sure the mobile toggle shows */
    #sidebarToggleMobile {
        display: flex !important;
    }

    /* Show mobile controls in sidebar */
    .mobile-controls {
        display: block !important;
        margin-bottom: 20px;
    }

    .sidebar-section {
        margin-bottom: 15px;
    }

    .sidebar-label {
        display: block;
        font-size: clamp(0.9rem, 2.2vw, 1rem);
        font-weight: 600;
        color: #666;
        margin-bottom: 4px;
    }

    .sidebar-select {
        width: 100%;
        padding: 6px 10px;
        font-size: clamp(0.9rem, 2.2vw, 1.05rem);
        border: 1px solid #ddd;
        border-radius: 4px;
        background: white;
        margin-bottom: 6px;
        height: 26px;
    }

    .sidebar-settings {
        display: flex;
        flex-direction: column;
        gap: 8px;
    }

    .sidebar-divider {
        border: none;
        border-top: 1px solid #e0e0e0;
        margin: 20px 0;
    }

    /* Floating sidebar toggle button - match settings button */
    .sidebar-toggle {
        display: flex !important;
        position: fixed !important;
        top: 12px !important;
        left: 12px !important;
        width: clamp(44px, 10vw, 56px) !important;
        height: clamp(44px, 10vw, 56px) !important;
        min-width: 44px !important;
        min-height: 44px !important;
        background: rgba(255, 255, 255, 0.9) !important;
        backdrop-filter: blur(10px) !important;
        border: 1px solid var(--apple-border) !important;
        border-radius: 50% !important;
        align-items: center !important;
        justify-content: center !important;
        z-index: 150 !important;
        box-shadow: 0 2px 8px rgba(0,0,0,0.1) !important;
        padding: 0 !important;
        color: #333 !important;
        font-size: clamp(1rem, 2.4vw, 1.15rem) !important;
    }

    .sidebar-toggle:hover {
        transform: scale(1.05);
        box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    }

    .sidebar-toggle svg {
        width: clamp(22px, 4.5vw, 28px) !important;
        height: clamp(22px, 4.5vw, 28px) !important;
    }

    /* Adjust main content - no menu bar needed */
    .main-content {
        padding-top: 20px !important;
    }

    /* Sidebar for mobile */
    .sidebar {
        transform: translateX(-100%);
        width: 85%;
        max-width: 320px;
        padding-top: 0; /* No menu bar to avoid */
    }

    /* Sidebar header normal padding */
    .sidebar-header {
        padding-top: 32px !important;
    }

    /* Larger sidebar buttons on mobile */
    .sidebar .btn,
    .sidebar button,
    .new-save-btn {
        font-size: clamp(0.9rem, 2.2vw, 1.05rem) !important;
        min-height: 44px !important;
        padding: 12px 20px !important;
        width: 100%;
    }

    .sidebar.active {
        transform: translateX(0);
    }

    /* Sidebar overlay for mobile */
    .sidebar-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 99;
    }

    .sidebar-overlay.active {
        display: block;
    }


    .main-content {
        margin-left: 0;
    }

    .header {
        padding-top: 80px;
    }

    .main-container {
        grid-template-columns: 1fr;
        max-width: 100%;
        padding: 0 10px;
    }

    .column {
        padding: 15px;
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
    }

    /* Navigation adjustments */
    .locale-selectors {
        flex-direction: row;
        gap: 4px;
        flex: 0 0 auto;
    }

    .locale-select {
        min-width: 50px;
        font-size: clamp(0.9rem, 2.2vw, 1.05rem);
        padding: 2px 4px;
        min-height: 22px;
        height: 22px;
    }

    /* Tablet input sizing - match desktop */
    .item-row {
        overflow-x: visible;
    }

    .item-row input,
    .item-row select {
        font-size: clamp(0.9rem, 2.1vw, 1.05rem) !important;
        padding: 8px 10px;
        min-height: clamp(34px, 8vw, 42px);
        height: auto;
        -webkit-appearance: none;
        appearance: none;
    }

    /* Make financial inputs expand to fill available width */
    .item-row input:not([type='checkbox']),
    .item-row select,
    .item-row .gross-profit {
        flex: 1 1 0 !important;
        min-width: 0 !important;
        max-width: none !important;
    }


    /* Income fields mobile layout - use percentage for better responsiveness */
    .platform-name {
        flex: 1 1 0 !important;
        min-width: 140px;
        max-width: none;
    }

    .revenue {
        flex: 1 1 0 !important;
        min-width: 120px;
        max-width: none;
        text-align: right;
    }

    /* Margin field - just for 2 digits + % */
    .margin {
        flex: 0 0 56px !important;
        min-width: 56px !important;
        max-width: 56px !important;
        text-align: center;
    }

    .income-source {
        flex: 1 1 0 !important;
        min-width: 140px;
        max-width: none;
    }

    .income-amount {
        flex: 1 1 0 !important;
        min-width: 120px;
        max-width: none;
        text-align: right;
    }

    .gross-profit {
        flex: 1 1 0 !important;
        min-width: 120px;
        max-width: none;
        text-align: center;
    }

    /* Expense fields mobile layout */
    .expense-name,
    .debt-name {
        flex: 1 1 0 !important;
        min-width: 140px;
        max-width: none;
    }

    .expense-amount,
    .debt-amount {
        flex: 1 1 0 !important;
        min-width: 120px;
        max-width: none;
        text-align: right;
    }

    .debt-months {
        flex: 0 0 60px !important;
        min-width: 60px !important;
        max-width: 60px !important;
        text-align: center;
    }

    /* Show floating calculate button on tablet/mobile - twice as large */
    .floating-calculate-btn {
        display: flex;
        align-items: center;
        gap: 8px;
        font-size: clamp(1.1rem, 3.2vw, 1.4rem) !important;
        padding: clamp(14px, 4.2vw, 20px) clamp(20px, 6vw, 28px) !important;
        min-height: clamp(52px, 14vw, 60px) !important;
        font-weight: 600 !important;
        background: linear-gradient(135deg, #0071e3 0%, #0051c3 100%) !important;
        box-shadow: 0 4px 12px rgba(0, 113, 227, 0.4) !important;
    }

    /* Add line chart icon before text */
    .floating-calculate-btn::before {
        content: "\1F4C8";
        font-size: clamp(1.1rem, 3vw, 1.4rem);
        margin-right: 4px;
    }

    /* Hide desktop calculate button */
    #calculateBtn {
        display: none;
    }
}

/* Mobile devices - includes iPhone 13 Pro Max (428px) and others */
@media (max-width: 768px) {
    /* Improve overall layout */
    body {
        font-size: clamp(1rem, 1.2vw + 0.55rem, 1.15rem);
        line-height: 1.5;
    }

    /* Ensure full width usage */
    .main-content {
        width: 100%;
        max-width: 100%;
        padding: 0;
        margin: 0;
    }

    /* Prevent any element from causing overflow */
    * {
        max-width: 100%;
    }

    /* Compact top controls for small screens */
    .top-controls {
        height: clamp(48px, 14vw, 56px);
        align-items: center;
    }

    .top-controls .btn,
    .mode-btn {
        font-size: clamp(0.9rem, 2.4vw, 1.05rem);
        padding: 8px 12px;
        min-height: clamp(34px, 9vw, 40px);
        height: auto;
    }

    .locale-select {
        font-size: clamp(0.9rem, 2.2vw, 1.05rem);
        padding: 6px 10px;
        min-height: clamp(32px, 8vw, 38px);
        height: auto;
    }

    /* Better cash input styling */
    .cash-input-container {
        padding: 10px 8px;
        width: 100%;
    }

    .cash-input-container label {
        font-size: clamp(1.05rem, 3.2vw, 1.3rem);
        font-weight: 600;
        margin-bottom: 6px;
        display: block;
    }

    .cash-input {
        width: calc(100% - 16px);
        max-width: 400px;
        font-size: clamp(0.9rem, 2.1vw, 1.05rem);
        padding: 8px 12px;
        min-height: clamp(36px, 8.5vw, 44px);
        height: auto;
        font-weight: 500;
    }

    /* Settings icon adjustments for mobile */
    .settings-icon {
        top: 8px;
        right: 8px;
        width: clamp(44px, 10vw, 56px);
        height: clamp(44px, 10vw, 56px);
        min-width: 44px;
        min-height: 44px;
    }

    .settings-icon svg {
        width: clamp(22px, 4.5vw, 28px);
        height: clamp(22px, 4.5vw, 28px);
    }

    .modal-close {
        width: clamp(44px, 10vw, 56px);
        height: clamp(44px, 10vw, 56px);
        min-width: 44px;
        min-height: 44px;
        font-size: clamp(1.4rem, 4.5vw, 1.8rem);
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* Larger headers for better readability */
    .column-header {
        font-size: clamp(1.1rem, 3.2vw, 1.35rem);
        padding: clamp(8px, 2.2vw, 12px) 0;
        font-weight: 600;
        line-height: 1.35;
    }

    .section-title {
        font-size: clamp(1.05rem, 2.8vw, 1.25rem);
        padding: clamp(6px, 1.8vw, 10px) 0;
        font-weight: 500;
        line-height: 1.35;
    }

    /* Compact item row spacing */
    .item-row {
        padding: 0;
        gap: 6px;
        flex-wrap: nowrap; /* Prevent wrapping to avoid height increase */
    }

    /* Responsive input fields */
    .item-row input,
    .item-row select {
        font-size: clamp(0.9rem, 2vw, 1.05rem);
        padding: 8px 10px;
        min-height: clamp(34px, 8vw, 42px);
        height: auto;
        border-radius: 4px;
        border: 1px solid #d0d5dd;
        width: 100%;
    }

    .gross-profit {
        font-size: clamp(0.95rem, 2.4vw, 1.1rem);
        padding: 8px 10px;
        min-height: clamp(34px, 8vw, 42px);
        display: flex;
        align-items: center;
        font-weight: 500;
    }

    .btn-remove {
        min-width: 40px;
        min-height: 40px;
        width: 40px;
        height: 40px;
        font-size: clamp(1.1rem, 3vw, 1.3rem);
        font-weight: 700;
        border-radius: 50%;
        background: rgba(255, 59, 48, 0.08);
        color: var(--apple-red, #ff3b30);
        border: none;
        display: flex;
        align-items: center;
        justify-content: center;
        line-height: 1;
    }

    .btn-add {
        font-size: clamp(1.05rem, 2.8vw, 1.2rem);
        padding: 12px 20px;
        min-height: 44px;
        height: 44px;
        font-weight: 500;
    }

    .action-buttons {
        flex-direction: column;
    }

    .action-buttons .btn {
        width: 100%;
    }
}


/* Touch-friendly adjustments */
@media (pointer: coarse) {
    /* Reduce touch target sizes for mobile phones */
    button,
    input,
    select,
    textarea,
    .btn,
    .mode-btn,
    .file-action-btn {
        min-height: 24px;
        min-width: 24px;
    }

    /* Mobile remove buttons - smaller button, large X */
    .btn-remove {
        width: 32px !important;
        height: 32px !important;
        min-width: 32px !important;
        min-height: 32px !important;
        font-size: clamp(1.2rem, 3.4vw, 1.5rem) !important;
        line-height: 1 !important;
    }

    /* Tighter spacing between elements */
    .item-row {
        gap: 4px;
    }

    .action-buttons {
        gap: 6px;
    }
}

/* Landscape orientation adjustments */
@media (max-width: 968px) and (orientation: landscape) {
    .header {
        padding-top: 60px;
        padding-bottom: 20px;
    }

    .cash-input-container {
        padding: 16px;
    }

    .column {
        padding: 16px;
    }
}

/* High DPI screens */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .sidebar {
        border-right-width: 0.5px;
    }

    .column {
        border-width: 0.5px;
    }

    .item-row {
        border-width: 0.5px;
    }
}

/* Additional adjustments for smaller phones */
@media (max-width: 480px) {
    body {
        font-size: clamp(0.98rem, 3.4vw, 1.05rem);
        line-height: 1.5;
    }

    .column-header {
        font-size: clamp(1.05rem, 4vw, 1.25rem);
        padding: clamp(6px, 2vw, 10px) 0;
    }

    .section-title {
        font-size: clamp(1rem, 3.6vw, 1.2rem);
        padding: clamp(4px, 1.8vw, 8px) 0;
    }

    .cash-input {
        font-size: inherit;
        min-height: clamp(34px, 10vw, 42px) !important;
        height: auto !important;
        padding: 6px 10px !important;
    }

    .cash-input-container label {
        font-size: clamp(0.95rem, 3.2vw, 1.1rem);
        font-weight: 500;
    }

    /* Adjust main content for new mobile nav */
    .main-content {
        padding-top: clamp(60px, 18vw, 80px) !important;
    }

    .header {
        padding-top: 12px !important;
    }

    .sidebar-toggle {
        position: fixed !important;
        top: 12px !important;
        left: 12px !important;
        padding: 0 !important;
        background: rgba(255, 255, 255, 0.9) !important;
        border: 1px solid var(--apple-border) !important;
        box-shadow: 0 2px 8px rgba(0,0,0,0.1) !important;
        display: flex !important;
        justify-content: center !important;
        align-items: center !important;
        min-width: 44px !important;
        min-height: 44px !important;
        width: clamp(44px, 10vw, 56px) !important;
        height: clamp(44px, 10vw, 56px) !important;
        font-size: clamp(1rem, 2.4vw, 1.15rem) !important;
        border-radius: 50% !important;
        color: #333 !important;
        z-index: 150 !important;
    }

    /* Hide spacer to push locale selectors to right */
    .top-controls > div[style*='flex: 1'] {
        display: block !important;
        flex: 1 !important;
    }

    /* Ensure locale selectors stay on right */
    .locale-selectors {
        margin-left: auto !important;
        flex: 0 0 auto !important;
    }
}
}

/* Force prevent zoom on inputs - Critical for iOS */
@media (max-width: 768px) {
    input[type="text"],
    input[type="number"],
    input[type="tel"],
    input[type="email"],
    select,
    textarea {
        font-size: clamp(1rem, 2.4vw, 1.15rem) !important;
        /* Prevent iOS zoom - must be at least 16px */
        transform: scale(1);
        -webkit-transform: scale(1);
        -webkit-appearance: none;
        -moz-appearance: none;
        appearance: none;
    }

    /* Prevent iOS from zooming on focus */
    input:focus,
    select:focus,
    textarea:focus {
        font-size: clamp(1rem, 2.4vw, 1.15rem) !important;
        outline: 2px solid var(--apple-blue);
        outline-offset: 2px;
    }

    /* Full width containers */
    .container,
    .main-container,
    .column {
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
    }

    /* Better button sizing */
    .btn,
    button {
        font-size: clamp(0.9rem, 2.1vw, 1.1rem);
        padding: 16px 24px;
        min-height: 54px;
        font-weight: 500;
    }

    /* Top controls adjustments - keep in single row */
    .top-controls {
        flex-wrap: nowrap;
        gap: 4px;
        padding: 8px 5px;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        -ms-overflow-style: none;
    }

    .top-controls::-webkit-scrollbar {
        display: none;
    }

    /* Hide the spacer div on mobile */
    .top-controls > div[style*="flex: 1"] {
        display: none !important;
    }

    .top-controls .btn {
        flex: 0 0 auto;
        min-width: auto;
        padding: 10px 12px;
        font-size: clamp(0.95rem, 2.4vw, 1.1rem);
        white-space: nowrap;
    }

    /* Mode selector mobile */
    .mode-selector {
        display: flex;
        flex: 0 0 auto;
        gap: 2px;
    }

    .mode-btn {
        font-size: clamp(0.85rem, 2.2vw, 1rem);
        padding: 6px 10px;
        min-height: 34px;
        height: auto;
        white-space: nowrap;
        letter-spacing: 0.01em;
    }

    /* Totals section */
    .total-row {
        font-size: clamp(0.85rem, 2vw, 0.95rem);
        padding: clamp(6px, 1.6vw, 10px);
    }

    .total-value {
        font-size: clamp(1.1rem, 3.4vw, 1.5rem);
        font-weight: 600;
    }

    /* Total amounts in headers - match header size */
    .total-amount {
        font-size: clamp(1.05rem, 3.2vw, 1.35rem);
        font-weight: 600;
        display: block;
        margin-top: 4px;
    }

    .section-total {
        font-size: clamp(1rem, 3vw, 1.3rem);
        font-weight: 600;
    }

    /* Modal adjustments for mobile */
    .modal-content {
        width: 95%;
        max-width: 100%;
        margin: 10px;
        max-height: 88vh;
        border-radius: 20px;
    }

    .modal-body {
        padding: clamp(16px, 4.5vw, 22px);
        line-height: 1.55;
    }

    /* Chart container for mobile */
    .chart-container {
        padding: clamp(12px, 4vw, 18px);
        height: clamp(220px, 55vw, 320px);
        position: relative;
        overflow: hidden;
    }

    /* Ensure chart canvas respects container */
    .chart-container canvas {
        max-width: 100% !important;
        height: auto !important;
    }

    /* Summary cards in modal */
    .summary-cards {
        flex-direction: column;
        gap: 10px;
    }

    .summary-card {
        width: 100%;
        padding: clamp(12px, 4vw, 18px);
    }

    /* Handle long amounts in summary */
    .card-value {
        font-size: clamp(1rem, 3vw + 0.4rem, 1.4rem);
        word-break: break-word;
        overflow-wrap: break-word;
        white-space: normal;
        line-height: 1.4;
        letter-spacing: 0.01em;
    }

    /* Month details table */
    .month-details table {
        font-size: clamp(0.9rem, 2.2vw, 1.05rem);
    }

    .month-details td {
        padding: clamp(6px, 1.8vw, 10px) clamp(4px, 1.2vw, 8px);
        white-space: normal;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: clamp(90px, 26vw, 140px);
    }

    /* Modal footer buttons */
    .modal-footer {
        padding: clamp(14px, 4vw, 20px) clamp(16px, 5vw, 24px);
        flex-direction: row;
        justify-content: flex-end;
        align-items: center;
        gap: clamp(10px, 4vw, 16px);
    }

    .modal-footer .btn {
        flex: 0 0 auto;
        min-width: clamp(44px, 28vw, 120px);
        max-width: 140px;
        min-height: 44px;
        font-size: clamp(0.9rem, 2.4vw, 1.05rem);
        padding: 12px 16px;
        margin-left: 0;
    }

    .modal-footer .btn:first-child {
        margin-left: 0;
    }

    .result-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 16px;
    }

    .summary-info {
        width: 100%;
    }

    .summary-row {
        justify-content: space-between;
        gap: 12px;
        margin-bottom: 6px;
    }

    .summary-label {
        margin-right: 8px;
        font-size: clamp(0.95rem, 2.4vw, 1.05rem);
    }

    .summary-value {
        font-size: clamp(1.1rem, 3.4vw, 1.4rem);
        text-align: right;
    }

    #selectedMonthDisplay {
        text-align: left !important;
        font-size: clamp(1.05rem, 2.8vw, 1.3rem);
    }

    .period-selector-panel {
        width: 100%;
        align-items: flex-start;
        min-width: 0;
        gap: 10px;
    }

    .period-label {
        width: 100%;
        text-align: left;
        margin-bottom: 4px;
    }

    .period-select {
        width: auto;
        min-width: 90px;
        align-self: flex-start;
    }

    .custom-period {
        align-items: center;
        gap: 8px;
    }

    .custom-period input {
        width: 80px;
        text-align: right;
    }

    .projection-note {
        text-align: left !important;
    }
}


@media (max-width: 768px) {
    .modal-content {
        width: 96vw;
        max-width: 96vw;
        border-radius: 18px;
    }

    .modal-body {
        padding: 24px 18px;
    }

    .projection-table-container {
        max-width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .projection-table {
        min-width: 420px;
        font-size: clamp(0.85rem, 2.6vw, 0.95rem);
    }

    .projection-table th,
    .projection-table td {
        padding: 8px 10px;
    }

    .custom-period {
        align-items: center;
        gap: 10px;
        flex-wrap: wrap;
        width: 100%;
    }

    .custom-period span {
        font-size: clamp(0.9rem, 2.4vw, 1rem);
    }

    .custom-period input {
        flex: 0 0 90px;
        text-align: right;
    }
}


