/* ======================================================================
   print.css (CLEANED & CONSOLIDATED)
   ====================================================================== */

/* ----------------------------------------------------------------------
   1. SCREEN STYLES (Hide print-only elements on screen if needed)
   ---------------------------------------------------------------------- */
#tdToc,
#divContTabs,
.olToolbarContainer,
.olControlOverviewMapContainer,
#multiplePlanHint,
#ncAciklamaPanel {
  display: none;
}

#linkMainPage,
#linkPlanNote,
#linkPrint {
  visibility: hidden;
}

/* ----------------------------------------------------------------------
   2. PRINT MEDIA QUERIES
   ---------------------------------------------------------------------- */
@media print {
  /* ====================================================================
     2.1. CORE RESET & LAYOUT (CRITICAL FOR CHROME)
     ==================================================================== */
  html,
  body {
    height: auto !important;
    min-height: 100% !important;
    width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: visible !important;
    background: #fff !important;
    font-size: 11px !important; /* Reduced base font size */
  }

  /* Reset Bootstrap Containers */
  .container,
  .container-fluid,
  .row {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    padding: 0 !important;
    margin: 0 !important;
    overflow: visible !important;
  }

  /* Reset Absolute/Fixed Positioned Wrappers (Fixes Blank Pages) */
  #mycontainerdiv,
  #div_page,
  #bodycontainer,
  #contextcontainer,
  .query-wrapper,
  .map-wrapper {
    position: relative !important;
    height: auto !important;
    width: 100% !important;
    overflow: visible !important;
    box-shadow: none !important;
    background: transparent !important;
  }

  /* Align content with header: strip padding from wrappers so all elements
     share the same left/right edge in print. */
  #bodycontainer,
  #contextcontainer {
    padding: 0 !important;
    margin: 0 !important;
    gap: 2px !important;
  }

  .query-wrapper,
  #div_page {
    margin: 0 !important;
    padding: 0 !important;
    max-width: 100% !important;
  }

  /* ====================================================================
     2.2. MAP VISIBILITY (IMAGE SNAPSHOT STRATEGY)
     ==================================================================== */
  /* Hide Interactive Map & Controls */
  /* Hide Interactive Map Canvas */
  .maplibregl-canvas {
    display: none !important;
  }

  /* Control Container - MUST BE VISIBLE for custom text, but hide its generic children */
  .maplibregl-control-container {
    display: block !important;
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    z-index: 200 !important; /* Above static image */
    pointer-events: none !important;
  }

  /* Hide Standard Controls & Groups */
  .maplibregl-ctrl-group,
  .mapboxgl-ctrl-group,
  .maplibregl-ctrl-attrib,
  .maplibregl-ctrl-scale,
  .maplibregl-ctrl-bottom-right,
  .maplibregl-ctrl-bottom-left,
  .maplibregl-ctrl-top-right {
    display: none !important;
    border: none !important;
  }

  /* Allow Top-Left container for our text */
  .maplibregl-ctrl-top-left {
    display: block !important;
    position: absolute !important;
    top: 10px !important;
    left: 10px !important;
  }

  /* Show Custom Text Control */
  .custom-map-text {
    display: block !important;
    position: relative !important; /* Inside top-left container */
    background: rgba(255, 255, 255, 0.8) !important;
    padding: 3px 5px !important;
    border-radius: 4px !important;
    box-shadow: none !important;
    border: 1px solid #ccc !important;
    color: #000 !important;
    font-weight: normal !important;
    font-size: 10px !important;
    z-index: 201 !important;
  }

  /* Hide Old UI Elements */
  #ZoomBar,
  .zoombar,
  .scale,
  .navigation,
  #map-skeleton,
  .custom-text-control {
    display: none !important;
  }

  /* Map Container */
  #map,
  .map-container {
    height: 350px !important; /* Force a shorter, wider aspect ratio */
    min-height: 350px !important;
    max-height: 350px !important;
    width: 100% !important;
    margin-bottom: 2px !important;
    page-break-inside: avoid !important;
    position: relative !important;
    display: block !important;
    overflow: hidden !important; /* Clip any overflow */
    border: 1px solid #ccc !important; /* Optional border for clarity */
  }

  /* Show Static Map Image */
  #print-map-image,
  .print-only-map {
    display: block !important;
    width: 100% !important;
    height: 100% !important; /* Fill the 350px container */
    position: absolute !important; /* Absolute to fill container */
    top: 0 !important;
    left: 0 !important;
    visibility: visible !important;
    z-index: 1 !important;
    object-fit: cover !important; /* Cover to fill without whitespace, might crop slightly */
    /* object-fit: contain !important;  -- Alternative if full extent is required, but might leave white bars */
  }

  /* Fix Overlays (North Arrow & Watermark) */
  #northArrow {
    display: block !important;
    position: absolute !important;
    bottom: 10px !important; /* Moved up slightly */
    right: 10px !important;
    z-index: 100 !important; /* Above print image */
    width: 32px !important;
  }

  /* If the text "Örnektir" is #watermarkOverlay or another element */
  #watermarkOverlay,
  .watermarked-div {
    display: block !important;
    position: absolute !important;
    top: 50% !important;
    left: 50% !important;
    transform: translate(-50%, -50%) !important;
    z-index: 10000 !important;
    /* opacity: 0.5 !important; Adjust if needed */
  }

  /* Ensure the parent of the map and overlays is relative */
  #map {
    position: relative !important;
  }

  /* The wrapper div around map, arrow, etc. needs to be relative too */
  /* Targeting the inline-styled div if it doesn't have a class is hard, 
     but #map's parent usually clips them if not handled. 
     The structure in imar.aspx line 471 has no class. 
     We rely on the fact that they are siblings. */

  /* ====================================================================
     2.3. CONTENT & TEXT VISIBILITY
     ==================================================================== */
  /* Force text-wrap accessibility (Expand Accordions) */
  .text-wrap,
  .text-wrap.expanded {
    height: auto !important;
    max-height: none !important;
    overflow: visible !important;
    display: block !important;
    margin-bottom: 2px !important;
    background: #fff !important;
    border: 1px solid #ddd !important;
    cursor: default !important;
    padding: 3px !important;
    mask-image: none !important;
    -webkit-mask-image: none !important;
  }

  .text-wrap p {
    margin-bottom: 1px !important;
    font-size: 9px !important;
  }

  /* Table Adjustments */
  .table {
    margin-bottom: 2px !important;
  }

  /* Use #htmlOutput td with ID-level specificity to override imar.css's
     "#htmlOutput td { padding: 8px 16px !important; font-size: 14px !important; }" rule. */
  #htmlOutput td,
  #htmlOutput .divTableRow,
  #htmlOutput .divTableCell,
  #htmlOutput .divTableCellLabel,
  #htmlOutput .divTableContent,
  #htmlOutput .divTableBody,
  .divTable,
  .divTableRow,
  .divTableCell,
  .divTableCellLabel,
  .divTableContent,
  .table-bordered > tbody > tr > td {
    padding: 1px 3px !important;
    font-size: 9px !important;
    line-height: 1.2 !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    overflow: visible !important;
    white-space: normal !important;
    box-shadow: none !important;
  }

  /* Specific handling for content cells to ensure they don't clip text-wrap */
  #htmlOutput .divTableContent,
  .divTableContent {
    display: block !important;
    width: 100% !important;
  }

  /* Label column: keep proportional width but compact */
  #htmlOutput .divTableCellLabel,
  .divTableCellLabel {
    min-width: 35% !important;
    max-width: 35% !important;
    font-size: 9px !important;
  }

  /* Remove flex gap between rows in print */
  #htmlOutput .divTableBody,
  .divTableBody {
    gap: 0 !important;
  }

  /* Remove gap between table sections */
  .divTable {
    gap: 0 !important;
  }

  /* Header / Navbar Adjustments */
  .navbar-fixed-top,
  .nav-wrapper,
  .navbar-header {
    position: relative !important;
  }
  .navbar {
    display: block !important;
    margin-bottom: 2px !important;
  }
  .navbar-brand,
  .img-responsive {
    height: 45px !important;
    min-height: 45px !important;
  }

  .company-title {
    font-size: 20px !important;
  }
  .company-subtitle {
    font-size: 11px !important;
  }

  /* New header structure print overrides */
  .header {
    height: auto !important;
    padding: 2px 0 !important;
    margin-bottom: 2px !important;
  }

  .header-text {
    font-size: 16px !important;
    line-height: 1.2 !important;
  }

  .header-unit {
    font-size: 10px !important;
  }

  /* Footer info */
  #bilgiMetni,
  #baskanAdi {
    padding: 4px !important;
    font-size: 10px !important;
  }

  /* Section headers */
  h5 {
    margin-top: 6px !important;
    margin-bottom: 4px !important;
    font-size: 10px !important;
  }

  /* Hide mobile expand arrow in print */
  .text-wrap::after,
  .text-wrap.expanded::after {
    display: none !important;
    content: none !important;
  }

  /* Netcad logo: smaller and compact in print */
  .product-owner {
    margin-top: 2px !important;
    padding: 0 !important;
    line-height: 1 !important;
  }
  .product-owner img {
    height: 18px !important;
  }

  /* Table rows: tighter vertical spacing */
  .divTableRow {
    margin: 0 !important;
    border-bottom: none !important;
  }

  .divTableCellBorder {
    margin-bottom: 0 !important;
    padding-bottom: 0 !important;
  }

  /* ====================================================================
     2.4. HIDING ELEMENTS
     ==================================================================== */
  .no-print,
  .no-print *,
  .glass-filter,
  .glass-overlay,
  .glass-specular,
  a[href]:after,
  .print-hidden-row {
    display: none !important;
  }

  /* ====================================================================
     2.5. CHROME/WEBKIT SPECIFIC FIXES
     ==================================================================== */
  /* Remove filters/transforms that might confuse the print engine */
  *,
  *::before,
  *::after {
    -webkit-filter: none !important;
    filter: none !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    transform: none !important;
    -webkit-transform: none !important;
  }

  /* Bootstrap 3 grid fix for print:
     col-md-* floats live inside @media (min-width:992px) which Chrome does NOT
     match in print mode → columns stack. Force the floats here unconditionally. */
  .col-md-12 { float: left !important; width: 100% !important; box-sizing: border-box !important; padding: 0 !important; }
  .col-md-6  { float: left !important; width: 50%  !important; box-sizing: border-box !important; padding: 0 !important; }
  .col-md-4  { float: left !important; width: 33.333% !important; box-sizing: border-box !important; padding: 0 !important; }
  .col-md-3  { float: left !important; width: 25%  !important; box-sizing: border-box !important; padding: 0 !important; }

  /* Clearfix: ensure .row wraps its floated children */
  .row::after {
    content: "" !important;
    display: table !important;
    clear: both !important;
  }

  /* bilgiMetni & baskanAdi: rowBilgiBaskan flex row yap.
     #contextcontainer flex container → direkt çocuk .row float'tan etkilenmez.
     Güvenilir çözüm: rowBilgiBaskan'ı da flex container yapmak. */
  #rowBilgiBaskan {
    display: flex !important;
    flex-direction: row !important;
    width: 100% !important;
  }

  #colBilgiMetni,
  #colBaskanAdi {
    flex: 0 0 50% !important;
    max-width: 50% !important;
    float: none !important;
  }

  .no-break-full::after {
    content: "";
    display: table;
    clear: both;
  }

  /* ====================================================================
     2.6. MISC. UTILITIES
     ==================================================================== */
  .no-break {
    page-break-inside: avoid !important;
  }
  .no-break-full {
    page-break-after: avoid !important;
    page-break-inside: avoid !important;
  }
  .emptyrow-content {
    page-break-inside: avoid !important;
    break-inside: avoid !important;
    page-break-before: avoid !important;
    break-before: avoid !important;
  }
  .planfonksiyonseperator {
    visibility: visible;
  }

  /* Plan fonksiyon butonları */
  .fonksiyonalani,
  .nonefonksiyonalani,
  .map-link-btn {
    padding: 2px 7px !important;
    font-size: 8px !important;
    margin: 1px !important;
    border-radius: 20px !important;
    box-shadow: none !important;
    line-height: 1.3 !important;
  }

  .map-link-btn i {
    margin-right: 3px !important;
    font-size: 8px !important;
  }

  /* Fonksiyon detay tablosu */
  .fonksiyontable {
    border-spacing: 0 !important;
    padding: 1px !important;
  }

  .fonksiyontable > tbody > tr > th,
  .fonksiyontable > tbody > tr > td {
    padding: 1px 3px !important;
  }

  .fonksiyontable-label,
  .fonksiyontable-value {
    font-size: 8px !important;
  }

  /* Boş satır spacer'larını ve bölüm ayraç çizgilerini gizle */
  .divTableNoneRow {
    display: none !important;
    height: 0 !important;
  }

  .divTableCellBorder {
    border-bottom: none !important;
    margin-bottom: 0 !important;
  }

  /* Readability High Contrast */
  #htmlOutput,
  #htmlOutput .divTable,
  #htmlOutput .divTableCell,
  #htmlOutput * {
    color: #000 !important;
    border-color: #000 !important;
    text-shadow: none !important;
  }

  /* divTableParentRow (imarDurumuManager output) flex düzenini koru */
  .divTableParentRow {
    display: flex !important;
    flex-wrap: nowrap !important;
    width: 100% !important;
  }

  .divTableParentRow > [class*="col-"] {
    flex: 1 !important;
    float: none !important;
  }

  /* Tiled Watermark for Print (Black/Faint) - PLACED AT END TO AVOID OVERRIDES */
  #contextcontainer.watermarked {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
    background-size: 750px 750px !important;
  }

  #contextcontainer.watermarked::before {
    content: "" !important;
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    background-image: url("../images/do-not-copy-160137_1280-3.png") !important;
    background-repeat: repeat !important;
    background-size: 250px 250px !important;
    filter: grayscale(1) opacity(0.12) !important;
    display: block !important;
    z-index: 20000 !important; /* Always on top of table rows */
    pointer-events: none !important;
  }
}
