/* Comprehensive Responsive Design Fixes */

/* ============================================
   MOBİL: Genel ölçeklendirme (yazı ve boşluklar küçültme)
   ============================================ */
@media (max-width: 768px) {
    html {
        font-size: 14px;
    }
    body {
        font-size: 0.9375rem;
    }
}

@media (max-width: 480px) {
    html {
        font-size: 13px;
    }
    body {
        font-size: 0.875rem;
    }
}

/* ============================================
   HYPOTHESIS A: Fixed viewport units (100vw) causing horizontal scroll
   ============================================ */
/* Replace 100vw with 100% to prevent horizontal scrollbars */
/* Only apply to containers that explicitly use 100vw - be less aggressive */
.container[style*="100vw"] {
    width: 100%;
    max-width: 100vw;
    box-sizing: border-box;
}

/* Prevent horizontal overflow - but allow vertical scroll */
/* Fix for full-screen mode: use 100% instead of 100vw to avoid scrollbar width issues */
html {
    box-sizing: border-box;
    width: 100%;
    max-width: 100%;
    overflow-x: hidden; /* Prevent horizontal scroll in all modes */
    overflow-y: auto;
}

/* Don't override body overflow if page has specific overflow settings */
/* Only apply if body doesn't have inline overflow styles */
body:not([style*="overflow"]) {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden; /* Critical: prevent horizontal scroll */
    overflow-y: auto;
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* Fix for full-screen mode: ensure container doesn't exceed viewport */
.container,
.container-fluid {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    padding-left: 1rem;
    padding-right: 1rem;
}

/* Only apply box-sizing to elements that don't already have it set */
/* Be very selective to avoid conflicts */

/* ============================================
   HYPOTHESIS B: Fixed positioned elements overlapping on small screens
   ============================================ */
/* Floating toolbar adjustments */
.floating-toolbar {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 1000;
}

@media (max-width: 768px) {
    .floating-toolbar {
        bottom: 80px; /* Move up to avoid overlap with navigation */
        right: 10px;
        gap: 8px;
    }
    
    .tool-btn {
        width: 50px !important;
        height: 50px !important;
        font-size: 18px !important;
    }
}

/* Page navigation adjustments */
.page-navigation {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
}

@media (max-width: 768px) {
    .page-navigation {
        bottom: 10px;
        padding: 8px 15px;
        gap: 10px;
        flex-wrap: wrap;
        max-width: calc(100% - 20px);
    }
    
    .nav-btn {
        width: 40px !important;
        height: 40px !important;
        font-size: 16px !important;
    }
    
    .page-info {
        font-size: 14px !important;
        padding: 0 10px !important;
        min-width: 80px !important;
    }
}

/* Drawing tools adjustments */
.drawing-tools {
    position: absolute;
    top: 15px;
    left: 15px;
    z-index: 100;
}

@media (max-width: 768px) {
    .drawing-tools {
        top: 10px;
        left: 10px;
        padding: 8px;
        flex-wrap: wrap;
        gap: 6px;
    }
    
    .drawing-tools button {
        width: 36px !important;
        height: 36px !important;
        font-size: 14px !important;
    }
    
    .color-picker {
        width: 36px !important;
        height: 36px !important;
    }
    
    .line-width {
        width: 50px !important;
        padding: 4px !important;
    }
}

/* ============================================
   HYPOTHESIS C: Tables not wrapped in responsive containers
   ============================================ */
/* Ensure all tables are responsive */
.table-responsive {
    display: block;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.table-responsive table {
    width: 100%;
    margin-bottom: 0;
}

/* Table responsive adjustments */
@media (max-width: 768px) {
    table {
        font-size: 0.875rem;
    }
    
    table th,
    table td {
        padding: 0.5rem 0.25rem;
        white-space: nowrap;
    }
    
    /* Stack table cells on very small screens */
    @media (max-width: 480px) {
        .table-responsive table,
        .table-responsive thead,
        .table-responsive tbody,
        .table-responsive th,
        .table-responsive td,
        .table-responsive tr {
            display: block;
        }
        
        .table-responsive thead tr {
            position: absolute;
            top: -9999px;
            left: -9999px;
        }
        
        .table-responsive tr {
            border: 1px solid #ccc;
            margin-bottom: 10px;
        }
        
        .table-responsive td {
            border: none;
            position: relative;
            padding-left: 50%;
            text-align: left;
        }
        
        .table-responsive td:before {
            content: attr(data-label);
            position: absolute;
            left: 6px;
            width: 45%;
            padding-right: 10px;
            white-space: nowrap;
            font-weight: bold;
        }
    }
}

/* ============================================
   HYPOTHESIS D: Forms and modals not responsive
   ============================================ */
/* Modal responsive adjustments */
.modal-dialog {
    margin: 1rem;
    max-width: calc(100% - 2rem);
}

@media (max-width: 576px) {
    .modal-dialog {
        margin: 0.5rem;
        max-width: calc(100% - 1rem);
    }
    
    .modal-content {
        border-radius: 0.5rem;
    }
    
    .modal-header,
    .modal-body,
    .modal-footer {
        padding: 1rem 0.75rem;
    }
}

/* Form controls responsive */
.form-control,
.form-select {
    width: 100%;
    max-width: 100%;
}

@media (max-width: 768px) {
    .form-control,
    .form-select {
        font-size: 16px; /* Prevents zoom on iOS */
    }
    
    .btn-group {
        flex-wrap: wrap;
    }
    
    .btn-group .btn {
        flex: 1 1 auto;
        min-width: 0;
    }
}

/* Input groups responsive */
.input-group {
    flex-wrap: wrap;
}

@media (max-width: 576px) {
    .input-group > .form-control,
    .input-group > .form-select {
        width: 100%;
        margin-bottom: 0.5rem;
    }
    
    .input-group > .btn {
        width: 100%;
    }
}

/* ============================================
   HYPOTHESIS E: Navigation - always mobile-style layout
   ============================================ */
/* Main content - always full width (topbar fixed, sidebar overlay) */
#main-content {
    margin-left: 0;
    width: 100%;
    max-width: 100vw;
    box-sizing: border-box;
    overflow-x: hidden;
}

@media (max-width: 991px) {
    #main-content {
        padding: 0.5rem;
    }
    
    /* Prevent sales page from overflowing */
    .sales-container {
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 !important;
        padding: 10px !important;
        box-sizing: border-box !important;
    }
}

/* ============================================
   HYPOTHESIS F: Canvas/PDF viewer not scaling properly
   ============================================ */
.pdf-viewer-container {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    overflow-y: auto;
}

#pdf-viewer {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
}

#pdf-canvas-container {
    max-width: 100%;
    overflow-x: auto;
}

@media (max-width: 768px) {
    #pdf-canvas-container {
        transform: scale(0.8);
        transform-origin: top left;
    }
    
    @media (max-width: 480px) {
        #pdf-canvas-container {
            transform: scale(0.6);
        }
    }
}

/* ============================================
   HYPOTHESIS G: General responsive utilities
   ============================================ */
/* Responsive text */
@media (max-width: 768px) {
    h1 { font-size: 1.75rem; }
    h2 { font-size: 1.5rem; }
    h3 { font-size: 1.25rem; }
    h4 { font-size: 1.1rem; }
    h5 { font-size: 1rem; }
    h6 { font-size: 0.9rem; }
    
    .display-1 { font-size: 2.5rem; }
    .display-2 { font-size: 2rem; }
    .display-3 { font-size: 1.75rem; }
    .display-4 { font-size: 1.5rem; }
}

/* Responsive spacing */
@media (max-width: 768px) {
    .container-fluid {
        padding-left: 0.75rem;
        padding-right: 0.75rem;
    }
    
    .card {
        margin-bottom: 1rem;
    }
    
    .card-body {
        padding: 1rem;
    }
}

/* Responsive images */
img {
    max-width: 100%;
    height: auto;
}

/* Responsive iframes */
iframe {
    max-width: 100%;
}

/* Responsive buttons */
@media (max-width: 576px) {
    .btn {
        padding: 0.5rem 1rem;
        font-size: 0.875rem;
    }
    
    .btn-group-vertical {
        width: 100%;
    }
    
    .btn-group-vertical .btn {
        width: 100%;
    }
}

/* Filters panel responsive */
.filters-panel {
    max-width: 100%;
}

@media (max-width: 991px) {
    .filters-panel {
        width: 100% !important;
        max-width: 100% !important;
        right: 0 !important;
        left: 0 !important;
    }
}

/* Floating action button responsive */
.floating-btn {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 1000;
}

@media (max-width: 768px) {
    .floating-btn {
        bottom: 80px;
        right: 15px;
        width: 56px;
        height: 56px;
    }
}

/* Calendar responsive */
@media (max-width: 991px) {
    .calendar-wrapper {
        padding: 0.5rem;
    }
}

/* Signature instructions responsive */
#signature-instructions {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 2000;
}

@media (max-width: 768px) {
    #signature-instructions {
        padding: 10px;
        font-size: 0.875rem;
    }
}

/* Debug info responsive */
.debug-info {
    position: fixed;
    top: 10px;
    right: 10px;
    z-index: 1000;
}

@media (max-width: 768px) {
    .debug-info {
        top: 5px;
        right: 5px;
        padding: 6px 10px;
        font-size: 10px;
        max-width: calc(100% - 10px);
    }
}

/* ============================================
   RAPORLAR SAYFASI - Mobile görünüm düzeltmeleri
   ============================================ */
@media (max-width: 768px) {
    /* Sayfa başlığı - mobilde alt alta, ortala */
    #main-content .d-flex.justify-content-between.align-items-center.mb-4 {
        flex-direction: column;
        align-items: stretch !important;
        gap: 1rem;
        text-align: center;
    }
    #main-content .d-flex.justify-content-between.align-items-center.mb-4 h2 {
        font-size: 1.35rem;
        margin-bottom: 0 !important;
    }
    #main-content #btn-refresh {
        align-self: center;
    }

    /* Dönem butonları - mobilde ortala ve sıkı yerleşim */
    .period-buttons {
        padding: 0.75rem 1rem;
        margin-bottom: 1rem;
    }
    .period-buttons .d-flex.flex-wrap {
        justify-content: center;
        gap: 0.35rem !important;
    }
    .period-buttons .text-muted.fw-bold {
        width: 100%;
        text-align: center;
        margin-bottom: 0.5rem !important;
        margin-right: 0 !important;
    }
    .period-btn {
        padding: 0.4rem 0.65rem;
        font-size: 0.8rem;
        margin: 0.15rem !important;
    }
    .period-btn i {
        margin-right: 0.3rem;
    }

    /* Özel tarih alanı - mobilde tam genişlik */
    .custom-date-range .row {
        margin-left: 0;
        margin-right: 0;
    }
    .custom-date-range .col-md-4 {
        flex: 0 0 100%;
        max-width: 100%;
        margin-bottom: 0.75rem;
    }
    .custom-date-range .col-md-4:last-child {
        margin-bottom: 0;
    }

    /* Period info badge */
    .period-info {
        padding: 0.5rem 1rem;
        font-size: 0.9rem;
        justify-content: center;
        flex-wrap: wrap;
    }

    /* Özet kartları - mobilde 2x2 grid */
    .summary-card .card-body {
        padding: 1rem;
    }
    .summary-card .amount {
        font-size: 1.35rem;
    }
    .summary-card .d-flex.justify-content-between.align-items-start .text-success i,
    .summary-card .d-flex.justify-content-between.align-items-start .text-danger i,
    .summary-card .d-flex.justify-content-between.align-items-start [style*="color: #17a2b8"] i {
        font-size: 1.25rem !important;
    }
}

@media (max-width: 576px) {
    .period-btn {
        font-size: 0.75rem;
        padding: 0.35rem 0.5rem;
    }
}

@media (max-width: 768px) {
    /* Transaction panel başlıkları - mobilde wrap */
    .transaction-panel .panel-header {
        padding: 0.75rem 1rem;
        flex-wrap: wrap;
        gap: 0.5rem;
    }
    .transaction-panel .panel-header h5 {
        font-size: 0.95rem;
        flex: 1 1 auto;
    }
    .transaction-panel .panel-header .badge {
        font-size: 0.8rem;
        padding: 0.35rem 0.5rem;
    }

    /* Transaction item - mobilde daha sıkı */
    .transaction-item {
        padding: 0.75rem 1rem;
    }
    .transaction-item .transaction-details {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 0.25rem;
    }
    .transaction-item .amount-info {
        text-align: left !important;
    }
    .transaction-item .total-amount {
        font-size: 1rem;
    }

    /* Panel footer */
    .transaction-panel .panel-footer {
        padding: 0.75rem 1rem !important;
    }
    .transaction-panel .panel-footer .fs-5 {
        font-size: 1.1rem !important;
    }

    /* Section nav wrapper - mobilde taşma önleme */
    .section-nav-wrapper {
        width: 100%;
        max-width: 100%;
        overflow-x: hidden;
    }
    /* Section nav - mobilde düzgün hizalama */
    .section-nav {
        padding: 0.5rem 0.75rem;
        justify-content: center;
        gap: 0.35rem;
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
    }
    .section-nav .nav-btn {
        padding: 0.5rem 0.85rem;
        font-size: 0.85rem;
        flex: 1 1 auto;
        min-width: 0;
        justify-content: center;
        display: inline-flex;
        align-items: center;
    }
    .section-nav .nav-btn i {
        margin-right: 0.35rem;
        flex-shrink: 0;
    }

    /* Report section başlıkları */
    .report-section {
        padding: 1rem;
        margin-bottom: 1rem;
    }
    .report-section h4 {
        font-size: 1rem;
        padding-bottom: 0.5rem;
        margin-bottom: 1rem;
        flex-wrap: wrap;
    }

    /* Stat kartları - randevu/gider raporlarında */
    .report-section .card.stat-card .card-body {
        padding: 0.75rem;
    }
    .report-section .card.stat-card .card-body h3 {
        font-size: 1.25rem;
    }
    .report-section .card.stat-card .card-body h6 {
        font-size: 0.75rem;
    }

    /* Chart container - mobilde daha kısa */
    .chart-container {
        height: 250px;
    }
    .chart-container-small {
        height: 220px;
    }

    /* Table - mobil scroll ve hücre padding */
    .report-section .table-responsive {
        margin-left: -1rem;
        margin-right: -1rem;
        padding: 0 1rem;
    }
    .report-section .table th,
    .report-section .table td {
        padding: 0.5rem 0.4rem;
        font-size: 0.8rem;
    }
    .report-section .table .text-end {
        text-align: right !important;
    }

    /* Daily overview - panel max height mobilde */
    .transaction-panel .panel-body {
        max-height: 350px;
    }
}

@media (max-width: 576px) {
    .chart-container {
        height: 220px;
    }
    .chart-container-small {
        height: 200px;
    }
}

/* Prevent text overflow */
.text-truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

@media (max-width: 768px) {
    .text-truncate {
        max-width: 100%;
    }
}

/* Responsive grid adjustments */
@media (max-width: 768px) {
    .row {
        margin-left: -0.5rem;
        margin-right: -0.5rem;
    }
    
    .row > * {
        padding-left: 0.5rem;
        padding-right: 0.5rem;
    }
}

/* Print styles */
@media print {
    .floating-toolbar,
    .page-navigation,
    .drawing-tools,
    .filters-panel,
    .floating-btn,
    .debug-info {
        display: none !important;
    }
    
    #main-content {
        margin-left: 0 !important;
    }
}

/* Emergency fallback - ensure main content is visible (only if not already set) */
#main-content:not([style*="min-height"]),
.container:not([style*="min-height"]),
body:not([style*="min-height"]) {
    min-height: 100px;
}

/* Ensure nothing accidentally hides the entire page (only if not explicitly hidden) */
body:not([style*="display: none"]):not([style*="display:none"]) {
    display: block;
}

html:not([style*="display: none"]):not([style*="display:none"]) {
    display: block;
}

