/**
 * BIZNORA - Main SaaS Stylesheet, Modern Left Panel & Guaranteed Single-Page A4 Print Engine
 */

:root {
  --primary-navy: #002D62;
  --brand-navy: #002D62;
  --brand-green: #0E8218;
  --brand-blue: #2878C8;
  --bg-main: #F5F7FA;
  --brand-bg: #F5F7FA;
  --brand-card: #FFFFFF;
  --text-main: #182230;
  --brand-text: #182230;
  --brand-secondary: #64748B;
  --brand-border: #E2E8F0;
  --brand-muted: #F1F5F9;
  --color-success: #0E8218;
  --header-height: 64px;
  --sidebar-width: 260px;

  /* Global Spacing Tokens */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;

  /* Global Border Radius Tokens */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-full: 9999px;
}

html,
body {
  max-width: 100vw;
  overflow-x: clip;
}

body {
  background-color: var(--bg-main);
  color: var(--text-main);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Custom sleek scrollbar */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: #f1f5f9;
}

::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 9999px;
}

::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}

/* Animations */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: scale(0.98);
  }

  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.animate-fade-in {
  animation: fadeIn 0.15s ease-out forwards;
}

.animate-slide-down {
  animation: slideDown 0.2s ease-out forwards;
}

/* ==============================================================
   LEFT PANEL (SIDEBAR) HOVERING & ACTIVE STATES
   ============================================================== */
.nav-link {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 0.85rem;
  border-radius: 0.75rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: #334155 !important;
  /* High contrast slate */
  transition: all 0.18s cubic-bezier(0.4, 0, 0.2, 1);
  text-decoration: none;
  border: 1px solid transparent;
}

.nav-link i,
.nav-link svg {
  color: #64748B !important;
  transition: all 0.18s ease;
  flex-shrink: 0;
}

/* High contrast, beautiful left panel hovering effect */
.nav-link:hover {
  background-color: #EBF2FA !important;
  /* Soft navy tint */
  color: #002D62 !important;
  /* Crisp deep navy text */
  font-weight: 700 !important;
  transform: translateX(4px);
  border-color: #D3E2F4 !important;
  box-shadow: 0 2px 6px rgba(0, 45, 98, 0.08);
}

.nav-link:hover i,
.nav-link:hover svg {
  color: #0E8218 !important;
  /* Brand green icon highlight on hover */
  transform: scale(1.15);
}

/* Active Indicator */
.nav-link.active {
  background: #002D62 !important;
  color: #FFFFFF !important;
  font-weight: 700 !important;
  box-shadow: 0 4px 12px rgba(0, 45, 98, 0.25);
  transform: none !important;
  border-color: transparent !important;
}

.nav-link.active i,
.nav-link.active svg {
  color: #FFFFFF !important;
  transform: none !important;
}

/* Mobile Bottom Nav Active */
.mobile-nav-link.active {
  color: #002D62 !important;
  font-weight: 700;
}

.mobile-nav-link.active i,
.mobile-nav-link.active svg {
  color: #002D62 !important;
  transform: scale(1.1);
}

/* ==============================================================
   STICKY TOP BARS & HEADERS
   ============================================================== */
#app-header {
  position: sticky !important;
  top: 0 !important;
  z-index: 40 !important;
  background-color: rgba(255, 255, 255, 0.98);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid #E2E8F0;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.sticky-top-subbar {
  position: sticky;
  top: 57px;
  /* Heights matching header */
  z-index: 30;
  background-color: rgba(255, 255, 255, 0.98);
  backdrop-filter: blur(10px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

/* ==============================================================
   FULL-SCREEN INVOICE PREVIEW MODAL - SMOOTH VERTICAL SCROLL
   ============================================================== */
#modal-invoice-preview {
  overflow-y: scroll !important;
  overflow-x: hidden !important;
  -webkit-overflow-scrolling: touch !important;
  overscroll-behavior: contain;
}

/* High visibility custom scrollbar for modal on dark backdrop */
#modal-invoice-preview::-webkit-scrollbar {
  width: 10px;
}

#modal-invoice-preview::-webkit-scrollbar-track {
  background: rgba(15, 23, 42, 0.7);
}

#modal-invoice-preview::-webkit-scrollbar-thumb {
  background: #2878C8;
  border-radius: 9999px;
  border: 2px solid rgba(15, 23, 42, 0.7);
}

#modal-invoice-preview::-webkit-scrollbar-thumb:hover {
  background: #3b82f6;
}

/* Modal A4 Sheet styling */
#modal-invoice-body {
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.45);
}

/* ==============================================================
   GLOBAL FORM CONTROLS & INPUT TEXTBOX POLISH (HIGH CONTRAST CRISP BORDERS)
   Guarantees clear, visible, accessible borders on all textboxes across all views
   ============================================================== */
input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="file"]):not([type="range"]):not([type="submit"]):not([type="button"]):not([type="reset"]),
select,
textarea {
  border: 1.5px solid #94a3b8 !important;
  /* High contrast Slate-400: clearly visible on ANY screen */
  background-color: #ffffff !important;
  color: #0f172a !important;
  border-radius: 0.5rem !important;
  padding: 0.5rem 0.75rem !important;
  font-size: 0.8125rem !important;
  line-height: 1.25rem !important;
  outline: none !important;
  transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out, background-color 0.15s ease-in-out !important;
  box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05) !important;
  box-sizing: border-box !important;
}

/* Hover state */
input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="file"]):not([type="range"]):not([type="submit"]):not([type="button"]):not([type="reset"]):hover,
select:hover,
textarea:hover {
  border-color: #64748b !important;
  background-color: #f8fafc !important;
}

/* Focus state: High-Visibility Navy Focus Ring & Sharp Contrast */
input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="file"]):not([type="range"]):not([type="submit"]):not([type="button"]):not([type="reset"]):focus,
select:focus,
textarea:focus {
  outline: none !important;
  border-color: #002D62 !important;
  background-color: #ffffff !important;
  box-shadow: 0 0 0 3px rgba(0, 45, 98, 0.28), 0 1px 3px 0 rgba(0, 45, 98, 0.15) !important;
}

/* Clear, readable placeholder text */
input::placeholder,
textarea::placeholder {
  color: #64748b !important;
  opacity: 1 !important;
}

/* Readonly & Disabled styling */
input:disabled,
select:disabled,
textarea:disabled,
input[readonly]:not([id="inv-num-input"]) {
  background-color: #f1f5f9 !important;
  border-color: #cbd5e1 !important;
  color: #64748b !important;
  cursor: not-allowed !important;
}

/* Table item inputs in Invoice Builder */
.items-table input,
.item-row input,
.item-row select {
  padding: 0.375rem 0.5rem !important;
  font-size: 0.75rem !important;
  border: 1.5px solid #94a3b8 !important;
  background-color: #ffffff !important;
}

.items-table input:focus,
.item-row input:focus,
.item-row select:focus {
  border-color: #002D62 !important;
  box-shadow: 0 0 0 2px rgba(0, 45, 98, 0.22) !important;
}

/* ==============================================================
   GLOBAL FORM CONTROLS & HIGH-VISIBILITY FOCUS STATE
   Ensures crystal-clear focus ring in all text boxes across the app
   ============================================================== */
input[type="text"]:focus,
input[type="number"]:focus,
input[type="email"]:focus,
input[type="password"]:focus,
input[type="tel"]:focus,
input[type="url"]:focus,
input[type="date"]:focus,
input[type="search"]:focus,
select:focus,
textarea:focus {
  outline: none !important;
  border-color: #002D62 !important;
  background-color: #ffffff !important;
  box-shadow: 0 0 0 3px rgba(0, 45, 98, 0.28), 0 1px 3px 0 rgba(0, 45, 98, 0.15) !important;
}

/* ==============================================================
   GSTIN INPUT FIELD & STATUS ARCHITECTURE
   Prevents text clipping, provides dedicated clear button & clean non-overlapping status row
   ============================================================== */
.gstin-input-wrapper {
  position: relative;
  width: 100%;
  display: block;
}

.gstin-input-wrapper input.gstin-input,
input.gstin-input {
  width: 100%;
  padding-right: 2.25rem !important; /* Ample room for clear button, never obscures text */
  letter-spacing: 0.04em;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  text-transform: uppercase;
}

.gstin-clear-btn {
  position: absolute;
  right: 0.5rem;
  top: 50%;
  transform: translateY(-50%);
  width: 1.35rem;
  height: 1.35rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #94a3b8;
  cursor: pointer;
  border-radius: 9999px;
  background: transparent;
  border: none;
  padding: 0;
  transition: all 0.15s ease;
  z-index: 5;
}

.gstin-clear-btn:hover {
  color: #0f172a;
  background: #f1f5f9;
}

.gstin-status-row {
  margin-top: 0.35rem;
  min-height: 1.25rem;
  font-size: 11px;
  line-height: 1.35;
}


/* ==============================================================
   A4 SHEET PREVIEW (ON SCREEN)
   ============================================================== */
.invoice-a4-sheet {
  width: 100%;
  max-width: 794px;
  /* standard 210mm at 96 DPI */
  background: #ffffff;
  box-sizing: border-box;
}

/* ==============================================================
   GUARANTEED SINGLE-PAGE A4 PRINT ENGINE
   ============================================================== */
@media print {

  /* Strict 1-Page A4 Margins: 6mm top, 7mm left/right, 5mm bottom */
  @page {
    size: A4 portrait;
    margin: 6mm 7mm 5mm 7mm !important;
  }

  *,
  *::before,
  *::after {
    box-sizing: border-box !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  html,
  body {
    background: #ffffff !important;
    color: #000000 !important;
    padding: 0 !important;
    margin: 0 !important;
    width: 100% !important;
    height: auto !important;
    min-height: 0 !important;
    display: block !important;
    overflow: visible !important;
    font-size: 9pt !important;
    line-height: 1.25 !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  /* CRITICAL FIX: Hide all direct children of body EXCEPT #print-container so page 1 is NEVER blank */
  body>*:not(#print-container) {
    display: none !important;
    height: 0 !important;
    min-height: 0 !important;
    max-height: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: hidden !important;
  }

  /* Hide entire application shell and any stray elements */
  #app-sidebar,
  #app-header,
  #mobile-bottom-nav,
  #toast-container,
  #modal-invoice-preview,
  #sidebar-overlay,
  #modal-business-switcher,
  #modal-add-business,
  #modal-record-payment,
  #modal-customer-ledger,
  #modal-supplier-ledger,
  #modal-advance-receipt,
  #modal-auth,
  #modal-staff,
  #mobile-more-sheet,
  main,
  button,
  .no-print {
    display: none !important;
  }

  /* Show only clean print container starting strictly at top of Page 1 */
  #print-container {
    display: block !important;
    position: static !important;
    width: 100% !important;
    max-width: 100% !important;
    height: auto !important;
    min-height: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: visible !important;
    visibility: visible !important;
  }

  .invoice-a4-sheet,
  .receipt-a4-sheet,
  .statement-a4-sheet {
    box-shadow: none !important;
    border-radius: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    min-height: auto !important;
    height: auto !important;
    box-sizing: border-box !important;
    padding: 8mm 10mm 8mm 10mm !important;
    margin: 0 auto !important;
    border: none !important;
    /* No artificial page border on physical paper or PDF */
    background: #ffffff !important;
    page-break-after: auto !important;
    break-after: auto !important;
    page-break-inside: auto !important;
    break-inside: auto !important;
  }

  /* Classic template keeps its statutory formal boxed border */
  .invoice-a4-sheet.classic-template {
    border: 2px solid #000000 !important;
  }

  /* Single-page documents avoid trailing spillage */
  .receipt-a4-sheet,
  .invoice-a4-sheet.single-page {
    page-break-after: avoid !important;
    break-after: avoid !important;
    page-break-inside: avoid !important;
    break-inside: avoid !important;
  }

  /* Maintain elegant sheet padding in print even if browser Margins is set to None */
  .invoice-a4-sheet.p-5,
  .invoice-a4-sheet.p-6,
  .invoice-a4-sheet.p-7,
  .invoice-a4-sheet.p-8,
  .invoice-a4-sheet .p-5,
  .invoice-a4-sheet .p-6,
  .invoice-a4-sheet .p-7,
  .invoice-a4-sheet .p-8 {
    padding: 8mm 10mm 8mm 10mm !important;
  }

  /* Header spacing */
  .invoice-a4-sheet .border-b-2 {
    border-bottom: 2px solid #002D62 !important;
    padding-bottom: 8px !important;
  }

  .invoice-a4-sheet .pb-3,
  .invoice-a4-sheet .pb-4,
  .invoice-a4-sheet .pb-6 {
    padding-bottom: 6px !important;
  }

  /* Billed To / Party Cards */
  .invoice-a4-sheet .billed-to-box,
  .invoice-a4-sheet .my-2,
  .invoice-a4-sheet .my-2\.5,
  .invoice-a4-sheet .my-3,
  .invoice-a4-sheet .my-4,
  .invoice-a4-sheet .my-6,
  .invoice-a4-sheet .mb-3,
  .invoice-a4-sheet .mb-4,
  .invoice-a4-sheet .mb-6,
  .invoice-a4-sheet .mb-8 {
    margin-top: 6px !important;
    margin-bottom: 6px !important;
  }

  .invoice-a4-sheet .billed-to-box {
    padding: 6px 10px !important;
    border: 1px solid #cbd5e1 !important;
    border-radius: 6px !important;
    background: #f8fafc !important;
  }

  .invoice-a4-sheet .gap-2\.5,
  .invoice-a4-sheet .gap-3,
  .invoice-a4-sheet .gap-4,
  .invoice-a4-sheet .gap-6 {
    gap: 8px !important;
  }

  /* Items Table Sizing & Crisp Borders */
  .invoice-a4-sheet .items-table,
  .invoice-a4-sheet table {
    width: 100% !important;
    border-collapse: collapse !important;
    margin: 8px 0 !important;
    border: 1px solid #cbd5e1 !important;
  }

  .invoice-a4-sheet table th {
    padding: 4px 6px !important;
    font-size: 8pt !important;
    line-height: 1.25 !important;
    font-weight: 700 !important;
    background-color: #002D62 !important;
    color: #ffffff !important;
    border: 1px solid #002D62 !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  .invoice-a4-sheet table td {
    padding: 4px 6px !important;
    font-size: 8pt !important;
    line-height: 1.25 !important;
    border: 1px solid #cbd5e1 !important;
  }

  .invoice-a4-sheet table td div,
  .invoice-a4-sheet table td span {
    font-size: 8pt !important;
    line-height: 1.25 !important;
  }

  .invoice-a4-sheet table td .text-\[11px\],
  .invoice-a4-sheet table td .text-xs,
  .invoice-a4-sheet table td .text-\[10px\] {
    font-size: 7.5pt !important;
    line-height: 1.2 !important;
    margin-top: 1px !important;
  }

  .invoice-a4-sheet thead {
    display: table-header-group !important;
  }

  .invoice-a4-sheet tfoot {
    display: table-footer-group !important;
  }

  .invoice-a4-sheet tr {
    page-break-inside: avoid !important;
    break-inside: avoid !important;
  }

  /* Summary Section */
  .invoice-a4-sheet .summary-grid,
  .invoice-a4-sheet .mt-2,
  .invoice-a4-sheet .mt-2\.5,
  .invoice-a4-sheet .mt-3,
  .invoice-a4-sheet .mt-4,
  .invoice-a4-sheet .mt-6 {
    margin-top: 6px !important;
  }

  .invoice-a4-sheet .bank-box,
  .invoice-a4-sheet .bank-box>div {
    padding: 6px 10px !important;
    font-size: 7.5pt !important;
    line-height: 1.3 !important;
    border: 1px solid #cbd5e1 !important;
    border-radius: 6px !important;
    background: #f8fafc !important;
  }

  .invoice-a4-sheet .bank-box .grid {
    gap: 2px 6px !important;
  }

  .invoice-a4-sheet .hsn-summary-box,
  .invoice-a4-sheet .mt-4.pt-3 {
    margin-top: 6px !important;
    padding-top: 4px !important;
  }

  .invoice-a4-sheet .hsn-summary-box table {
    border: 1px solid #cbd5e1 !important;
  }

  .invoice-a4-sheet .hsn-summary-box table th {
    background-color: #f1f5f9 !important;
    color: #1e293b !important;
    border: 1px solid #cbd5e1 !important;
    font-size: 7pt !important;
    padding: 2.5px 4px !important;
  }

  .invoice-a4-sheet .hsn-summary-box table td {
    padding: 2.5px 4px !important;
    font-size: 7pt !important;
    line-height: 1.2 !important;
    border: 1px solid #cbd5e1 !important;
  }

  .invoice-a4-sheet .totals-box {
    padding: 6px 10px !important;
    font-size: 8pt !important;
    line-height: 1.3 !important;
    border: 1px solid #cbd5e1 !important;
    border-radius: 6px !important;
    background: #f8fafc !important;
  }

  .invoice-a4-sheet .totals-box .space-y-1>div,
  .invoice-a4-sheet .totals-box .space-y-1\.5>div,
  .invoice-a4-sheet .totals-box .space-y-2>div {
    margin-top: 1.5px !important;
    margin-bottom: 1.5px !important;
    font-size: 8pt !important;
  }

  .invoice-a4-sheet .totals-box .text-sm,
  .invoice-a4-sheet .totals-box .text-xs\.font-black {
    font-size: 10pt !important;
    font-weight: 800 !important;
  }

  #invoice-upi-qrcode,
  .invoice-a4-sheet #invoice-upi-qrcode {
    width: 52px !important;
    height: 52px !important;
    padding: 2px !important;
    border: 1px solid #cbd5e1 !important;
    border-radius: 4px !important;
  }

  #invoice-upi-qrcode img,
  #invoice-upi-qrcode canvas,
  .invoice-a4-sheet #invoice-upi-qrcode img,
  .invoice-a4-sheet #invoice-upi-qrcode canvas {
    width: 48px !important;
    height: 48px !important;
  }

  /* Signatory box */
  .invoice-a4-sheet .signatory-box {
    margin-top: 4px !important;
  }

  .invoice-a4-sheet .signatory-box .h-6,
  .invoice-a4-sheet .signatory-box .h-10 {
    height: 20px !important;
  }

  .invoice-a4-sheet .signatory-box img {
    max-height: 28px !important;
  }

  .invoice-a4-sheet .signatory-box .w-44,
  .invoice-a4-sheet .signatory-box .w-48 {
    width: 150px !important;
  }

  /* Footer & Terms */
  .invoice-a4-sheet .terms-footer {
    margin-top: 4px !important;
    padding-top: 4px !important;
    font-size: 7pt !important;
    line-height: 1.25 !important;
  }

  .software-footer-credit,
  .invoice-a4-sheet .software-footer-credit {
    margin-top: 4px !important;
    padding-top: 4px !important;
    font-size: 7pt !important;
    line-height: 1.25 !important;
  }

  /* Prevent page breaks across critical blocks */
  .totals-box,
  .bank-box,
  .signatory-box,
  .hsn-summary-box,
  .billed-to-box {
    page-break-inside: avoid !important;
    break-inside: avoid !important;
  }
}

/* Hide print container during normal browsing */
#print-container {
  display: none;
}

/* ==========================================================================
   MOBILE APP STYLING & TOUCH-FRIENDLY POLISH (Phase 6 & 9)
   Breakpoints: 320px-375px, 376px-430px, 431px-767px, 768px-1024px, >1024px
   ========================================================================== */

/* Safe area insets for iOS & modern bezel-less mobile devices */
#mobile-bottom-nav {
  padding-bottom: calc(0.375rem + env(safe-area-inset-bottom, 0px));
}

/* Touch targets >= 44px on mobile devices */
@media (max-width: 767px) {

  button:not(.btn-icon-tiny),
  select,
  input[type="text"],
  input[type="number"],
  input[type="date"],
  input[type="email"] {
    min-height: 40px;
  }

  .mobile-nav-link {
    min-height: 44px;
    min-width: 44px;
    justify-content: center;
  }

  /* Prevent awkward text selection on fast touch taps */
  #mobile-bottom-nav,
  #mobile-more-sheet {
    -webkit-tap-highlight-color: transparent;
    user-select: none;
  }

  /* Compact padding for smaller phones (320px - 375px) */
  @media (max-width: 375px) {
    .p-4 {
      padding: 0.75rem !important;
    }

    .p-5 {
      padding: 0.875rem !important;
    }
  }

  /* Smooth bottom sheet */
  #mobile-more-sheet {
    transition: opacity 0.2s ease-in-out;
  }

  #mobile-more-sheet-content {
    transition: transform 0.22s cubic-bezier(0.16, 1, 0.3, 1);
  }
}

/* ==========================================================================
   RESPONSIVE DATA TABLES & ACTION BUTTON SCROLLBAR STYLING
   ========================================================================== */
.overflow-x-auto {
  -webkit-overflow-scrolling: touch;
}

.overflow-x-auto::-webkit-scrollbar {
  height: 6px;
}

.overflow-x-auto::-webkit-scrollbar-track {
  background: #f1f5f9;
  border-radius: 9999px;
}

.overflow-x-auto::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 9999px;
}

.overflow-x-auto::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}
