@tailwind base;
@tailwind components;
@tailwind utilities;

/* Print helpers */
@media print {

  /* Print settings */
  html {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
    font-size: 12px;
  }

  /* Hide elements marked with print:hidden */
  .print\:hidden {
    display: none !important;
  }

  /* Keep each page intact; margins handled by @page */
  .archive-page {
    page-break-inside: avoid !important;
    break-inside: avoid !important;
    margin: 0 !important;
    padding: 0mm !important;
    /* Maximized space */
    width: 100% !important;
    max-width: none !important;
    box-sizing: border-box !important;
    border: none !important;
    box-shadow: none !important;
  }

  /* Remove forced page breaks */
  .archive-page+.archive-page {
    page-break-before: auto !important;
  }

  /* Force proper 2-column layout for contract grid */
  .contract-grid {
    display: grid !important;
    grid-template-columns: 2fr 1fr !important;
    gap: 0.5rem !important;
    width: 100% !important;
    align-items: start !important;
  }

  .contract-details {
    grid-column: 1 !important;
    width: 100% !important;
    min-width: 0 !important;
  }

  .contract-photo {
    grid-column: 2 !important;
    width: 100% !important;
    min-width: 0 !important;
    display: flex !important;
    flex-direction: column !important;
  }

  /* Remove ALL borders from images */
  .contract-photo img {
    width: 100% !important;
    height: 45mm !important;
    object-fit: cover !important;
    object-position: center !important;
    border: none !important;
    border-radius: 0 !important;
  }

  /* Print area positioning - full width */
  #print-area-archive {
    position: static !important;
    width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  /* Clean print layout */
  body {
    margin: 0 !important;
    padding: 0 !important;
    background: white !important;
    color: black !important;
    /* Force black text for quality */
  }

  /* Ensure text doesn't break awkwardly */
  .contract-details dl {
    width: 100% !important;
  }

  /* Fix text sizing for mobile PDF generation */
  .text-xs {
    font-size: 10px !important;
    line-height: 1.2 !important;
    color: black !important;
  }

  .text-sm {
    font-size: 12px !important;
    line-height: 1.3 !important;
    color: black !important;
  }

  .text-slate-500,
  .text-slate-600,
  .text-slate-700 {
    color: black !important;
  }

  /* High contrast override */

  /* Remove borders from detail rows */
  .contract-details dl>div {
    display: grid !important;
    grid-template-columns: 1.2fr 1.8fr !important;
    gap: 2mm !important;
    align-items: start !important;
    padding: 1mm 0 !important;
    border: none !important;
    min-height: 5mm !important;
  }

  .contract-details dt {
    color: black !important;
    font-weight: 700 !important;
  }

  .contract-details dd {
    text-align: right !important;
    font-weight: 700 !important;
    color: black !important;
  }
}

/* Mobile-specific improvements for better PDF generation */
@media screen and (max-width: 640px) {
  .contract-grid {
    gap: 0.25rem !important;
  }

  .contract-photo {
    min-width: 0;
    /* Prevent photo from overflowing */
  }

  .contract-photo img {
    max-width: 100%;
    height: auto;
    min-height: 120px;
    /* Ensure minimum height on mobile */
  }

  /* Improve text readability on mobile */
  .text-xs {
    font-size: 11px !important;
  }

  /* Stack signatures on mobile for better balance */
  .signature-grid {
    grid-template-columns: 1fr !important;
    gap: 0.75rem !important;
  }
}

/* Ensure consistent layout across all screen sizes */
.contract-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  align-items: start;
  width: 100%;
}

.contract-details {
  min-width: 0;
  /* Prevent text overflow */
}

.contract-photo {
  min-width: 0;
  /* Prevent photo overflow */
  display: flex;
  flex-direction: column;
}

/* Improve DetailRow responsiveness */
.contract-details dl>div {
  display: grid;
  grid-template-columns: 1.2fr 1.8fr;
  gap: 0.5rem;
  align-items: start;
  word-break: break-word;
  min-height: 1.5rem;
}

.contract-details dt {
  flex-shrink: 0;
  margin-right: 0.5rem;
  max-width: 40%;
}

.contract-details dd {
  flex-grow: 1;
  text-align: right;
  word-break: break-word;
  overflow-wrap: break-word;
}

/* Screen centering for archive pages */
#print-area-archive {
  width: 210mm;
  max-width: 100%;
  margin: 0 auto;
  display: block;
}

.archive-preview {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.archive-page {
  background: white !important;
  color: black !important;
  width: 170mm;
  max-width: 100%;
  margin: 0 auto;
  padding: 10mm;
  box-sizing: border-box;
}

/* Mobile tweaks for preview */
@media screen and (max-width: 640px) {
  .archive-page {
    width: auto;
    max-width: 100%;
    padding: 6mm;
  }
}

/* Removed global img image-rendering to preserve favicon transparency */
.contract-photo img {
  image-rendering: -webkit-optimize-contrast;
  image-rendering: crisp-edges;
}

/* Force consistent font rendering */
* {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}


/* Global centering container */
.page-container {
  max-width: 960px;
  margin: 0 auto;
  padding: 1rem;
}

/* Centered control bar utility */
.controls-center {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

/* Print page margins and centering */
@media print {

  /* Use normal document flow to avoid phantom pages */
  #print-area-archive {
    position: static !important;
    left: auto !important;
    top: auto !important;
    width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  .archive-preview> :not([hidden])~ :not([hidden]) {
    margin-top: 0 !important;
  }
}

@page {
  size: A4;
  margin: 0 !important;
  /* Removed 20mm margin for full-page print */
}

/* --- Premium Custom Scrollbar --- */
::-webkit-scrollbar {
  width: 14px;
  height: 14px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background-color: rgba(156, 163, 175, 0.4);
  /* slate-400 */
  border-radius: 9999px;
  border: 4px solid rgba(0, 0, 0, 0);
  /* Transparent border for clipping */
  background-clip: padding-box;
}

::-webkit-scrollbar-thumb:hover {
  background-color: rgba(156, 163, 175, 0.7);
}

/* For Firefox */
* {
  scrollbar-width: thin;
  scrollbar-color: rgba(156, 163, 175, 0.4) transparent;
}

/* Sidebar / Dark Container specific scrollbar */
.bg-emerald-900::-webkit-scrollbar-thumb,
.bg-brand-900::-webkit-scrollbar-thumb,
aside::-webkit-scrollbar-thumb,
[class*="emerald-950"]::-webkit-scrollbar-thumb {
  background-color: rgba(16, 185, 129, 0.2);
  /* emerald-500 low opacity */
}

.bg-emerald-900::-webkit-scrollbar-thumb:hover,
.bg-brand-900::-webkit-scrollbar-thumb:hover,
aside::-webkit-scrollbar-thumb:hover,
[class*="emerald-950"]::-webkit-scrollbar-thumb:hover {
  background-color: rgba(16, 185, 129, 0.4);
}

aside,
.bg-emerald-900,
.bg-brand-900 {
  scrollbar-color: rgba(16, 185, 129, 0.2) transparent;
}

/* --- Premium Custom Scrollbar --- */
::-webkit-scrollbar {
  width: 14px;
  height: 14px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background-color: rgba(156, 163, 175, 0.4);
  /* slate-400 */
  border-radius: 9999px;
  border: 4px solid rgba(0, 0, 0, 0);
  /* Transparent border for clipping */
  background-clip: padding-box;
}

::-webkit-scrollbar-thumb:hover {
  background-color: rgba(156, 163, 175, 0.7);
}

/* For Firefox */
* {
  scrollbar-width: thin;
  scrollbar-color: rgba(156, 163, 175, 0.4) transparent;
}

/* Sidebar / Dark Container specific scrollbar */
.bg-emerald-900::-webkit-scrollbar-thumb,
.bg-brand-900::-webkit-scrollbar-thumb,
aside::-webkit-scrollbar-thumb,
[class*="emerald-950"]::-webkit-scrollbar-thumb {
  background-color: rgba(16, 185, 129, 0.2);
  /* emerald-500 low opacity */
}

.bg-emerald-900::-webkit-scrollbar-thumb:hover,
.bg-brand-900::-webkit-scrollbar-thumb:hover,
aside::-webkit-scrollbar-thumb:hover,
[class*="emerald-950"]::-webkit-scrollbar-thumb:hover {
  background-color: rgba(16, 185, 129, 0.4);
}

aside,
.bg-emerald-900,
.bg-brand-900 {
  scrollbar-color: rgba(16, 185, 129, 0.2) transparent;
}