/* ==========================================================================
   FahamAcc v1.3 - Comprehensive UI/UX & RTL Quality Fixes (v1.0.1)
   Scope: Pure CSS layout, contrast, table, responsive, dark-mode & print fixes
   Zero JS / accounting logic modifications.
   ========================================================================== */

/* 1. Custom Thin Scrollbars (RTL-friendly & subtle) */
* {
  scrollbar-width: thin;
  scrollbar-color: rgba(148, 163, 184, 0.45) transparent;
}
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background-color: rgba(148, 163, 184, 0.45);
  border-radius: 9999px;
}
::-webkit-scrollbar-thumb:hover {
  background-color: rgba(100, 116, 139, 0.7);
}

/* 2. Prevent Floating Calculator Button from Overlapping Bottom Cards & Tables */
#root main,
#root .overflow-y-auto {
  padding-bottom: 84px !important;
}

/* 3. Dark Mode Modal, Dialog & Alert Contrast Fixes */
html.dark .fixed.inset-0 > div.bg-white,
html.dark .fixed.inset-0 > div > div.bg-white,
html.dark [role="dialog"].bg-white,
html.dark [role="dialog"] .bg-white,
html.dark .popup-box-global {
  background-color: var(--popup-bg, #111827) !important;
  color: var(--popup-text, #f8fafc) !important;
  border-color: var(--popup-border, rgba(255, 255, 255, 0.14)) !important;
}

html.dark .fixed.inset-0 .bg-slate-50,
html.dark .fixed.inset-0 .bg-slate-100,
html.dark .fixed.inset-0 .bg-gray-50 {
  background-color: #1e293b !important;
  color: #e2e8f0 !important;
  border-color: rgba(255, 255, 255, 0.1) !important;
}

html.dark .fixed.inset-0 .bg-amber-50,
html.dark .fixed.inset-0 .bg-amber-50\/50 {
  background-color: rgba(245, 158, 11, 0.14) !important;
  color: #fcd34d !important;
  border-color: rgba(245, 158, 11, 0.3) !important;
}

html.dark .fixed.inset-0 .bg-rose-50,
html.dark .fixed.inset-0 .bg-red-50 {
  background-color: rgba(244, 63, 94, 0.14) !important;
  color: #fda4af !important;
  border-color: rgba(244, 63, 94, 0.3) !important;
}

html.dark .fixed.inset-0 .bg-emerald-50 {
  background-color: rgba(16, 185, 129, 0.14) !important;
  color: #6ee7b7 !important;
  border-color: rgba(16, 185, 129, 0.3) !important;
}

html.dark .fixed.inset-0 input,
html.dark .fixed.inset-0 select,
html.dark .fixed.inset-0 textarea {
  background-color: #0f172a !important;
  color: #f8fafc !important;
  border-color: rgba(255, 255, 255, 0.18) !important;
}

html.dark .fixed.inset-0 .text-slate-800,
html.dark .fixed.inset-0 .text-slate-700,
html.dark .fixed.inset-0 .text-slate-900,
html.dark .fixed.inset-0 .text-gray-800,
html.dark .fixed.inset-0 .text-gray-900 {
  color: #f1f5f9 !important;
}

html.dark .fixed.inset-0 .text-slate-500,
html.dark .fixed.inset-0 .text-slate-600,
html.dark .fixed.inset-0 .text-gray-500 {
  color: #94a3b8 !important;
}

/* 4. Dark Sidebar Bottom Zoom Control Contrast Fix */
aside .text-slate-900:not(.bg-white):not(.bg-white *),
aside .text-slate-800:not(.bg-white):not(.bg-white *) {
  color: #f1f5f9 !important;
}
aside .text-slate-500:not(.bg-white):not(.bg-white *),
aside .text-slate-400:not(.bg-white):not(.bg-white *) {
  color: #cbd5e1 !important;
}
aside .bg-white,
aside .bg-white * {
  color: #0f172a !important;
}

/* 5. Tables: Clean Alignment, Padding, Header Separation & Overflow Control */
.overflow-x-auto {
  scrollbar-gutter: stable;
}
table {
  border-collapse: collapse;
}
table thead th {
  vertical-align: middle !important;
  line-height: 1.45;
  padding-top: 10px !important;
  padding-bottom: 10px !important;
  white-space: nowrap;
}
table tbody td {
  vertical-align: middle !important;
  line-height: 1.5;
}
table tbody td.px-4,
table thead th.px-4,
table tbody td.px-6,
table thead th.px-6 {
  padding-left: 12px !important;
  padding-right: 12px !important;
}

/* 6. Filter Bars & Search Inputs: Clean Wrapping Without Overlap */
.flex:has(> input[placeholder*="جستجو"]),
.flex:has(> div > input[placeholder*="جستجو"]) {
  flex-wrap: wrap !important;
  gap: 8px !important;
}
select {
  min-height: 36px;
  padding-left: 26px !important;
}

/* 7. Settings Cards: Prevent Action Button Wrapping ("باز کردن") */
button[class*="rounded-lg"][class*="text-xs"],
button[class*="rounded-xl"][class*="text-xs"] {
  white-space: nowrap;
}

/* 8. Disabled Buttons & Inputs Readability */
button:disabled {
  opacity: 0.65 !important;
  cursor: not-allowed !important;
}

/* 9. Login Page English Copyright LTR Isolation */
footer,
.login-copyright,
div[class*="text-slate-400"][class*="text-center"] {
  unicode-bidi: plaintext;
}

/* 10. Dashboard Bank/Cash Cards: Prevent Amount & Account Name Clipping */
.grid.grid-cols-2 > div > .truncate,
.grid.grid-cols-2 > button > .truncate {
  white-space: normal !important;
  overflow: visible !important;
  text-overflow: clip !important;
  line-height: 1.35;
}

/* 11. Personnel Performance Gradient Banner Contrast */
.bg-gradient-to-r.from-indigo-600,
.bg-gradient-to-l.from-indigo-600,
[class*="from-violet-600"][class*="to-indigo-600"],
[class*="from-indigo-600"][class*="to-purple-600"] {
  color: #ffffff !important;
}
[class*="from-violet-600"] p,
[class*="from-indigo-600"] p {
  color: rgba(255, 255, 255, 0.92) !important;
}

/* 12. Numeric Tabular Alignment for Financial Figures */
.font-mono {
  font-variant-numeric: tabular-nums;
}

/* 13. Responsive Mobile & Tablet Refinements */
@media (max-width: 768px) {
  #root main {
    padding-left: 12px !important;
    padding-right: 12px !important;
    padding-bottom: 92px !important;
  }
  .grid.grid-cols-2 {
    grid-template-columns: 1fr !important;
  }
}

/* 14. Print Media Optimization */
@media print {
  #pwa-install-btn,
  .fixed:not(.print-area):not(#print-section),
  aside,
  nav {
    display: none !important;
  }
  #root main,
  #root .overflow-y-auto {
    padding: 0 !important;
    margin: 0 !important;
    overflow: visible !important;
  }
  table {
    width: 100% !important;
    border-collapse: collapse !important;
  }
  thead {
    display: table-header-group !important;
  }
  tr {
    break-inside: avoid !important;
    page-break-inside: avoid !important;
  }
}

/* 15. Invoice Archive Search Inputs & Jalali Date Inputs Width Fixes (FAH-BUG-11) */
div:has(> input[placeholder*="جستجوی طرف حساب"]),
div:has(> input[placeholder*="جستجوی محصول"]),
div:has(> input[placeholder*="جستجوی شماره فاکتور"]) {
  min-width: 185px !important;
  flex: 1 1 185px !important;
}

/* 16. Stage 2 Localized UI Fixes (FAH-BUG-20, 21, 22) */
table td .flex.items-center.gap-1,
table td .flex.items-center.gap-1\.5 {
  flex-wrap: nowrap !important;
  white-space: nowrap !important;
}
#root main {
  padding-bottom: 108px !important;
}

/* 17. Stage 3 Localized UI Fixes (FAH-BUG-31, 32) */
.divide-y > div .flex.items-center.gap-2,
.divide-y > div .flex.items-center.gap-1\.5 {
  flex-wrap: wrap !important;
}

/* 18. Stage 5 Localized UI Fixes (FAH-BUG-48) */
select:has(option[value="lowstock"]),
select:has(option[value="khadamat"]) {
  min-width: 175px !important;
}

/* 19. Stage 7 Localized UI Fixes (FAH-BUG-63: prevent floating calc button from overlapping footer totals) */
.border-t.border-slate-100 > div.flex.flex-wrap.justify-between {
  padding-left: 72px !important;
}

/* 20. Stage 10 Localized UI Fixes (FAH-BUG-71, FAH-BUG-73: prevent tab/table/filter clipping in reports) */
#profit-loss-strategic-root .overflow-x-auto > div.flex {
  flex-wrap: wrap !important;
}
#profit-loss-strategic-root table th,
#profit-loss-strategic-root table td {
  padding-left: 0.65rem !important;
  padding-right: 0.65rem !important;
}

/* 21. Stage 12 Localized UI Fixes (FAH-BUG-83: safe bottom clearance for floating calculator button) */
main, .main-content-scroll {
  padding-bottom: 92px !important;
}

/* 22. Stage 14 Localized UI Fixes (FAH-BUG-90: crisp Light Mode restoration after Dark Mode; FAH-BUG-91: Popup opacity presets wrap) */
html:not(.dark) table tbody tr {
  background-color: #ffffff !important;
  color: #0f172a !important;
}
html:not(.dark) table tbody tr:nth-child(even) {
  background-color: #f8fafc !important;
}
html:not(.dark) table tbody tr:hover {
  background-color: #f1f5f9 !important;
}
html:not(.dark) table tbody td {
  color: #1e293b !important;
}
html:not(.dark) label,
html:not(.dark) .text-slate-500,
html:not(.dark) .text-slate-600,
html:not(.dark) .text-slate-700 {
  color: #334155;
}
.flex.items-center.gap-1\.5,
.flex.items-center.gap-2 {
  flex-wrap: wrap;
}

/* 23. Executive Management Dashboard Grid Layout (Guaranteed Desktop/Tablet/Mobile widths) */
.faham-exec-kpi-grid {
  display: grid !important;
  grid-template-columns: repeat(1, minmax(0, 1fr)) !important;
  gap: 1rem !important;
  width: 100% !important;
}
@media (min-width: 640px) {
  .faham-exec-kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }
}
@media (min-width: 1180px) {
  .faham-exec-kpi-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
  }
}
.faham-exec-two-col {
  display: grid !important;
  grid-template-columns: repeat(1, minmax(0, 1fr)) !important;
  gap: 1.5rem !important;
  width: 100% !important;
}
@media (min-width: 1024px) {
  .faham-exec-two-col {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }
}

.faham-7day-chart {
  display: grid !important;
  grid-template-columns: repeat(7, minmax(0, 1fr)) !important;
  gap: 0.5rem !important;
  align-items: end !important;
  width: 100% !important;
  padding: 0.75rem 0.25rem 0.25rem !important;
}
.faham-7day-col {
  display: flex !important;
  flex-direction: column !important;
  align-items: center !important;
  justify-content: flex-end !important;
  min-width: 0 !important;
  gap: 0.4rem !important;
}
.faham-7day-track {
  width: 100% !important;
  height: 260px !important;
  display: flex !important;
  align-items: flex-end !important;
  justify-content: center !important;
}

/* 24. Option 3 (ثبت و انبار) UI Polish */
/* Compact archive table cells so action column stays visible on desktop without horizontal scroll */
table th, table td {
  padding-left: 0.4rem !important;
  padding-right: 0.4rem !important;
}
.overflow-x-auto {
  padding-bottom: 12px;
}
/* Ensure bottom floating calculator button never overlaps footer counters */
#root > div, main {
  padding-bottom: 96px !important;
}
