/* ==========================================================================
   LoanLogic™ — Sovereign Obsidian, Bullion Gold & Emerald Mint Design System
   Global Font: Alegreya Sans | Modern Web Guidance (`slider`, `light-dismiss-a-dialog`)
   ========================================================================== */

:root {
  --bg-obsidian: #06090F;
  --bg-card: #0B111E;
  --bg-elevated: #111A2E;
  --gold-primary: #EAB308;
  --gold-bright: #FACC15;
  --gold-soft: #FEF08A;
  --bronze-deep: #78552B;
  --emerald-primary: #10B981;
  --emerald-bright: #34D399;
  --emerald-dark: #064E3B;
}

*, *::before, *::after, body, html, input, select, textarea, button, code, pre {
  font-family: 'Alegreya Sans', system-ui, -apple-system, sans-serif !important;
  box-sizing: border-box;
}

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

body {
  background-color: var(--bg-obsidian);
  color: #F8FAFC;
  font-family: 'Alegreya Sans', system-ui, -apple-system, sans-serif;
  overflow-x: hidden;
  overflow-wrap: anywhere;
}

.font-serif-luxury,
.font-mono-code {
  font-family: 'Alegreya Sans', system-ui, -apple-system, sans-serif !important;
}

/* Luxury Ambient Mesh Background */
.sovereign-mesh {
  background-image:
    radial-gradient(circle at 12% 14%, rgba(16, 185, 129, 0.10) 0%, transparent 36%),
    radial-gradient(circle at 86% 18%, rgba(234, 179, 8, 0.11) 0%, transparent 40%),
    radial-gradient(circle at 50% 85%, rgba(234, 179, 8, 0.06) 0%, transparent 45%);
}

/* Gold & Emerald Hairline Cards */
.card-sovereign {
  background: linear-gradient(180deg, rgba(15, 23, 42, 0.88) 0%, rgba(9, 13, 22, 0.96) 100%);
  border: 1px solid rgba(234, 179, 8, 0.24);
  box-shadow: 0 20px 50px -15px rgba(0, 0, 0, 0.75);
}

.card-emerald {
  background: linear-gradient(180deg, rgba(6, 78, 59, 0.28) 0%, rgba(9, 13, 22, 0.95) 100%);
  border: 1px solid rgba(16, 185, 129, 0.32);
}

/* ==========================================================================
   Modern Web Guidance: Squircle Small Cards & Badges (`css` — Shapes)
   ========================================================================== */
.ll-squircle-badge {
  border-radius: 0.625rem;
  corner-shape: squircle;
}

/* ==========================================================================
   Modern Web Guidance: Post-Interaction Form Validation (`validate-input-after-interaction`)
   ========================================================================== */
input:user-invalid,
select:user-invalid,
textarea:user-invalid,
input.user-invalid-fallback,
select.user-invalid-fallback,
textarea.user-invalid-fallback {
  border-color: #EF4444 !important;
  background-color: rgba(239, 68, 68, 0.08) !important;
}

input:user-valid,
select:user-valid,
textarea:user-valid,
input.user-valid-fallback,
select.user-valid-fallback,
textarea.user-valid-fallback {
  border-color: rgba(16, 185, 129, 0.55);
}

/* ==========================================================================
   Modern Web Guidance: Brand-Consistent Native Range Slider (`slider`)
   ========================================================================== */
input[type="range"].ll-slider {
  --slider-track-size: 0.55rem;
  --slider-thumb-size: 1.45rem;
  --slider-track-radius: 999px;
  --slider-thumb-radius: 50%;
  --slider-track-color: #1E293B;
  --slider-fill-color: #EAB308;
  --slider-thumb-color: #FACC15;
  --slider-direction: to right;

  &:dir(rtl) {
    --slider-direction: to left;
  }

  --attr-min: attr(min type(<number>), 0);
  --attr-max: attr(max type(<number>), 100);
  --control-value: attr(value type(<number>), 50);
  --slider-progress: calc(
    progress(var(--control-value), var(--attr-min), var(--attr-max)) * 100%
  );

  appearance: none;
  inline-size: 100%;
  block-size: 2.5rem;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  cursor: pointer;
}

input[type="range"].ll-slider-emerald {
  --slider-fill-color: #10B981;
  --slider-thumb-color: #34D399;
}

@supports not (opacity: progress(1, 0, 100)) {
  input[type="range"].ll-slider {
    --slider-progress: calc(
      (var(--control-value) - var(--attr-min)) /
      (var(--attr-max) - var(--attr-min)) * 100%
    );
  }
}

/* WebKit/Blink separate rule blocks */
input[type="range"].ll-slider::-webkit-slider-runnable-track {
  block-size: var(--slider-track-size);
  border: 0;
  border-radius: var(--slider-track-radius);
  background: linear-gradient(
    var(--slider-direction),
    var(--slider-fill-color) var(--slider-progress),
    var(--slider-track-color) var(--slider-progress)
  );
}

input[type="range"].ll-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  inline-size: var(--slider-thumb-size);
  block-size: var(--slider-thumb-size);
  margin-block-start: calc(
    (var(--slider-track-size) - var(--slider-thumb-size)) / 2
  );
  border: 3px solid #070B12;
  border-radius: var(--slider-thumb-radius);
  background: var(--slider-thumb-color);
  box-shadow: 0 0 14px rgba(234, 179, 8, 0.55);
}

/* Firefox separate rule blocks */
input[type="range"].ll-slider::-moz-range-track {
  block-size: var(--slider-track-size);
  border: 0;
  border-radius: var(--slider-track-radius);
  background: var(--slider-track-color);
}

input[type="range"].ll-slider::-moz-range-progress {
  block-size: var(--slider-track-size);
  border-radius: var(--slider-track-radius);
  background: var(--slider-fill-color);
}

input[type="range"].ll-slider::-moz-range-thumb {
  inline-size: var(--slider-thumb-size);
  block-size: var(--slider-thumb-size);
  border: 3px solid #070B12;
  border-radius: var(--slider-thumb-radius);
  background: var(--slider-thumb-color);
}

input[type="range"].ll-slider:focus-visible {
  outline: 2px solid var(--slider-fill-color);
  outline-offset: 4px;
}

/* ==========================================================================
   Modern Web Guidance: Light-Dismiss Dialog (`light-dismiss-a-dialog`)
   ========================================================================== */
dialog.ll-dialog {
  background: #0B111E;
  color: #F8FAFC;
  border: 1px solid rgba(234, 179, 8, 0.45);
  border-radius: 1.25rem;
  padding: 0;
  max-width: min(48rem, calc(100vw - 1rem));
  width: calc(100vw - 1rem);
  margin: auto;
  box-shadow: 0 25px 70px rgba(0, 0, 0, 0.85);
}

dialog.ll-dialog::backdrop {
  background-color: rgba(3, 6, 12, 0.78);
  backdrop-filter: blur(6px);
}

/* Custom Scrollbar */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: #06090F;
}
::-webkit-scrollbar-thumb {
  background: #1E293B;
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: #EAB308;
}

/* ==========================================================================
   Luxury Printable Dossier & Paginated A4 Sheet Styling
   ========================================================================== */
.luxury-certificate-sheet {
  background: linear-gradient(180deg, #090E1A 0%, #050811 100%);
  border: 2px solid #EAB308;
  box-shadow: inset 0 0 0 3px rgba(16, 185, 129, 0.22), 0 20px 50px rgba(0, 0, 0, 0.85);
}

.luxury-dossier-page {
  background: linear-gradient(180deg, #090E1A 0%, #060911 100%);
  border: 2px solid rgba(234, 179, 8, 0.82);
  border-radius: 1rem;
  padding: 1.5rem 1.85rem;
  box-shadow: inset 0 0 0 3px #06090F, inset 0 0 0 4px rgba(16, 185, 129, 0.28), 0 18px 45px rgba(0, 0, 0, 0.85);
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 0.85rem;
}

.luxury-page-header {
  padding-bottom: 0.75rem;
  border-bottom: 2px solid rgba(234, 179, 8, 0.65);
}

.luxury-page-body {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  gap: 0.75rem;
}

.luxury-page-footer {
  margin-top: auto;
  padding-top: 0.65rem;
  border-top: 1.5px solid rgba(234, 179, 8, 0.55);
  font-size: 0.68rem;
  color: #94A3B8;
}

.luxury-data-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  word-break: break-word;
}

.luxury-data-table th,
.luxury-data-table td {
  padding: 0.38rem 0.6rem;
  border: 1px solid rgba(255, 255, 255, 0.13);
  text-align: left;
  vertical-align: top;
  line-height: 1.32;
  overflow-wrap: anywhere;
}

.luxury-data-table th {
  background: rgba(13, 19, 31, 0.92);
  color: #FACC15;
  font-weight: 700;
  width: 22%;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.luxury-data-table td {
  background: rgba(6, 9, 15, 0.88);
  color: #F8FAFC;
  font-weight: 600;
  font-size: 0.74rem;
  width: 28%;
}

/* ==========================================================================
   Global Mobile Compliance Overrides (<= 640px)
   Ensures zero horizontal overflow across cards, tables, modals & forms
   ========================================================================== */
@media screen and (max-width: 640px) {
  .luxury-dossier-page {
    padding: 0.95rem 0.85rem;
    border-radius: 0.75rem;
  }

  /* Stack 4-column key/value dossier tables cleanly on narrow mobile screens */
  .luxury-data-table,
  .luxury-data-table tbody {
    display: block;
    width: 100%;
  }

  .luxury-data-table tr {
    display: grid;
    grid-template-columns: 1fr;
    border-bottom: 1px solid rgba(234, 179, 8, 0.25);
  }

  .luxury-data-table th,
  .luxury-data-table td {
    display: block;
    width: 100% !important;
    box-sizing: border-box;
  }

  .luxury-data-table th {
    padding: 0.35rem 0.55rem 0.15rem;
    border-bottom: none;
  }

  .luxury-data-table td {
    padding: 0.15rem 0.55rem 0.45rem;
  }

  /* Keep main LMWS table scrollable within its container without pushing page width */
  #view-lmws .overflow-x-auto {
    max-width: 100%;
    -webkit-overflow-scrolling: touch;
  }

  /* Prevent flex children and long codes/hashes from overflowing viewport */
  .card-sovereign,
  .card-emerald,
  main section,
  main > div {
    max-width: 100%;
    min-width: 0;
  }

  code, pre {
    word-break: break-all;
    white-space: pre-wrap;
  }
}

/* Remove Browser Print Header (Date/Title) & Footer (URL/Page No.) so custom luxury headers/footers shine */
@page {
  size: A4 portrait;
  margin: 0mm;
}

@media print {
  * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }
  html, body {
    margin: 0 !important;
    padding: 0 !important;
    background: #06090F !important;
    color: #F8FAFC !important;
  }
  body > header,
  body > footer,
  body > main,
  #toast-container,
  #loanlogic-ai-fab,
  #loanlogic-ai-panel,
  .no-print {
    display: none !important;
  }
  dialog#luxury-dossier-dialog[open] {
    position: static !important;
    display: block !important;
    max-width: 100% !important;
    width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    border: none !important;
    box-shadow: none !important;
    background: #06090F !important;
    overflow: visible !important;
  }
  dialog#luxury-dossier-dialog > div {
    padding: 0 !important;
    margin: 0 !important;
  }
  #luxury-dossier-content {
    margin: 0 !important;
    padding: 0 !important;
    gap: 0 !important;
  }
  .luxury-dossier-page {
    width: 210mm !important;
    min-height: 296mm !important;
    max-height: 296mm !important;
    padding: 9mm 12mm !important;
    margin: 0 auto !important;
    border-radius: 0 !important;
    border: 2px solid #EAB308 !important;
    box-sizing: border-box !important;
    page-break-after: always !important;
    break-after: page !important;
    page-break-inside: avoid !important;
    break-inside: avoid !important;
    overflow: hidden !important;
    display: flex !important;
    flex-direction: column !important;
    justify-content: space-between !important;
  }
  .luxury-dossier-page:last-child {
    page-break-after: auto !important;
    break-after: auto !important;
  }
}
