@import url('https://fonts.googleapis.com/css2?family=Courier+Prime:wght@400;700&family=JetBrains+Mono:wght@400;500;600;700;800&family=Space+Mono:wght@400;700&display=swap');

@font-face {
  font-family: 'Thermal Sans Mono';
  src: local('Thermal Sans Mono'), local('ThermalSansMono'), local('Thermal-Sans-Mono'),
       local('JetBrains Mono'), local('Space Mono'), local('Courier Prime'), local('Consolas');
  font-weight: 400 800;
  font-display: swap;
}

:root {
  font-family: system-ui, -apple-system, sans-serif;
  line-height: 1.5;
  font-weight: 400;
  color: #1a1a1a;
  background-color: #f1f5f9;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;

  --bg-app: #f8fafc;
  --bg-card: #ffffff;
  --bg-header: rgba(255, 255, 255, 0.85);
  --bg-sidebar: linear-gradient(180deg, #ffffff 0%, #fafbff 100%);
  --border-color: #e8ecf4;
  --border-subtle: #f1f5f9;
  --text-main: #111827;
  --text-muted: #6b7280;
  --text-subtle: #9ca3af;
  --input-bg: #ffffff;
  --input-border: #e2e8f0;
}

[data-theme="dark"],
.dark {
  color: #f1f5f9;
  background-color: #0b0f19;

  --bg-app: #0b0f19;
  --bg-card: #1e293b;
  --bg-header: rgba(15, 23, 42, 0.88);
  --bg-sidebar: linear-gradient(180deg, #0f172a 0%, #1e293b 100%);
  --border-color: #334155;
  --border-subtle: #1e293b;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-subtle: #64748b;
  --input-bg: #0f172a;
  --input-border: #334155;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  background-color: var(--bg-app);
  color: var(--text-main);
  transition: background-color 0.2s ease, color 0.2s ease;
}

/* Dark Mode Universal Theme Adaptations */
[data-theme="dark"] body,
.dark body {
  background-color: #0b0f19;
  color: #f1f5f9;
}

/* Containers and Cards */
[data-theme="dark"] div[style*="background: white"],
[data-theme="dark"] div[style*="background: rgb(255, 255, 255)"],
[data-theme="dark"] div[style*="background-color: white"],
[data-theme="dark"] div[style*="background-color: rgb(255, 255, 255)"],
[data-theme="dark"] section[style*="background: white"],
[data-theme="dark"] section[style*="background: rgb(255, 255, 255)"],
[data-theme="dark"] section[style*="background-color: white"],
[data-theme="dark"] section[style*="background-color: rgb(255, 255, 255)"],
[data-theme="dark"] article[style*="background: white"],
[data-theme="dark"] article[style*="background-color: white"],
.dark div[style*="background: white"],
.dark div[style*="background: rgb(255, 255, 255)"],
.dark div[style*="background-color: white"],
.dark div[style*="background-color: rgb(255, 255, 255)"],
.dark section[style*="background: white"],
.dark section[style*="background: rgb(255, 255, 255)"],
.dark section[style*="background-color: white"],
.dark section[style*="background-color: rgb(255, 255, 255)"],
.dark article[style*="background: white"],
.dark article[style*="background-color: white"] {
  background: #1e293b !important;
  border-color: #334155 !important;
  color: #f1f5f9 !important;
}

/* Sub-cards and Gray/Light Backgrounds */
[data-theme="dark"] div[style*="background: #f8fafc"],
[data-theme="dark"] div[style*="background: #fafbfc"],
[data-theme="dark"] div[style*="background: #f1f5f9"],
[data-theme="dark"] div[style*="background: rgb(248, 250, 252)"],
[data-theme="dark"] div[style*="background: rgb(250, 251, 252)"],
[data-theme="dark"] div[style*="background: rgb(241, 245, 249)"],
[data-theme="dark"] section[style*="background: #f8fafc"],
[data-theme="dark"] section[style*="background: #f1f5f9"],
.dark div[style*="background: #f8fafc"],
.dark div[style*="background: #fafbfc"],
.dark div[style*="background: #f1f5f9"],
.dark div[style*="background: rgb(248, 250, 252)"],
.dark div[style*="background: rgb(250, 251, 252)"],
.dark div[style*="background: rgb(241, 245, 249)"],
.dark section[style*="background: #f8fafc"],
.dark section[style*="background: #f1f5f9"] {
  background: #0f172a !important;
  border-color: #334155 !important;
  color: #f1f5f9 !important;
}

/* Universal Text Visibility in Dark Mode (Both Hex & RGB) */
[data-theme="dark"] [style*="color: rgb(17, 24, 39)"],
[data-theme="dark"] [style*="color: rgb(30, 41, 59)"],
[data-theme="dark"] [style*="color: rgb(31, 41, 55)"],
[data-theme="dark"] [style*="color: rgb(51, 65, 85)"],
[data-theme="dark"] [style*="color: rgb(55, 65, 81)"],
[data-theme="dark"] [style*="color: rgb(71, 85, 105)"],
[data-theme="dark"] [style*="color: #111827"],
[data-theme="dark"] [style*="color: #1f2937"],
[data-theme="dark"] [style*="color: #374151"],
[data-theme="dark"] [style*="color: #1e293b"],
[data-theme="dark"] [style*="color: #0f172a"],
[data-theme="dark"] [style*="color: #1e3a5f"],
[data-theme="dark"] [style*="color: #0f2b48"],
[data-theme="dark"] [style*="color: #1a1a1a"],
.dark [style*="color: rgb(17, 24, 39)"],
.dark [style*="color: rgb(30, 41, 59)"],
.dark [style*="color: rgb(31, 41, 55)"],
.dark [style*="color: rgb(51, 65, 85)"],
.dark [style*="color: rgb(55, 65, 81)"],
.dark [style*="color: rgb(71, 85, 105)"],
.dark [style*="color: #111827"],
.dark [style*="color: #1f2937"],
.dark [style*="color: #374151"],
.dark [style*="color: #1e293b"],
.dark [style*="color: #0f172a"],
.dark [style*="color: #1e3a5f"],
.dark [style*="color: #0f2b48"],
.dark [style*="color: #1a1a1a"] {
  color: #f8fafc !important;
}

[data-theme="dark"] [style*="color: rgb(100, 116, 139)"],
[data-theme="dark"] [style*="color: rgb(107, 114, 128)"],
[data-theme="dark"] [style*="color: rgb(148, 163, 184)"],
[data-theme="dark"] [style*="color: rgb(156, 163, 175)"],
[data-theme="dark"] [style*="color: #6b7280"],
[data-theme="dark"] [style*="color: #64748b"],
[data-theme="dark"] [style*="color: #9ca3af"],
[data-theme="dark"] [style*="color: #9ca3a0"],
[data-theme="dark"] [style*="color: #4b5563"],
.dark [style*="color: rgb(100, 116, 139)"],
.dark [style*="color: rgb(107, 114, 128)"],
.dark [style*="color: rgb(148, 163, 184)"],
.dark [style*="color: rgb(156, 163, 175)"],
.dark [style*="color: #6b7280"],
.dark [style*="color: #64748b"],
.dark [style*="color: #9ca3af"],
.dark [style*="color: #9ca3a0"],
.dark [style*="color: #4b5563"] {
  color: #94a3b8 !important;
}

[data-theme="dark"] [style*="color: #3730a3"],
[data-theme="dark"] [style*="color: #4338ca"],
[data-theme="dark"] [style*="color: rgb(55, 48, 163)"],
[data-theme="dark"] [style*="color: rgb(67, 56, 202)"],
.dark [style*="color: #3730a3"],
.dark [style*="color: #4338ca"],
.dark [style*="color: rgb(55, 48, 163)"],
.dark [style*="color: rgb(67, 56, 202)"] {
  color: #c7d2fe !important;
}

[data-theme="dark"] [style*="color: #6366f1"],
[data-theme="dark"] [style*="color: rgb(99, 102, 241)"],
.dark [style*="color: #6366f1"],
.dark [style*="color: rgb(99, 102, 241)"] {
  color: #a5b4fc !important;
}

/* Forms, Inputs, Selects, and Textareas */
[data-theme="dark"] input:not([type="button"]):not([type="submit"]):not([type="checkbox"]):not([type="radio"]),
[data-theme="dark"] select,
[data-theme="dark"] textarea,
.dark input:not([type="button"]):not([type="submit"]):not([type="checkbox"]):not([type="radio"]),
.dark select,
.dark textarea {
  background-color: #0f172a !important;
  color: #f8fafc !important;
  border-color: #334155 !important;
}

[data-theme="dark"] input::placeholder,
[data-theme="dark"] textarea::placeholder,
.dark input::placeholder,
.dark textarea::placeholder {
  color: #64748b !important;
}

[data-theme="dark"] label,
.dark label {
  color: #cbd5e1 !important;
}

/* Tables */
[data-theme="dark"] table,
.dark table {
  background-color: #1e293b !important;
  color: #e2e8f0 !important;
}

[data-theme="dark"] thead tr,
.dark thead tr {
  background-color: #0f172a !important;
  border-bottom-color: #334155 !important;
}

[data-theme="dark"] th,
.dark th {
  color: #94a3b8 !important;
}

[data-theme="dark"] td,
.dark td {
  border-bottom-color: #334155 !important;
  color: #e2e8f0 !important;
}

[data-theme="dark"] tr:hover,
.dark tr:hover {
  background-color: rgba(51, 65, 85, 0.3) !important;
}

/* Typography and Headings */
[data-theme="dark"] h1, [data-theme="dark"] h2, [data-theme="dark"] h3, [data-theme="dark"] h4, [data-theme="dark"] h5, [data-theme="dark"] h6,
.dark h1, .dark h2, .dark h3, .dark h4, .dark h5, .dark h6 {
  color: #f8fafc !important;
}

/* Modals and Popups */
[data-theme="dark"] .modal-content,
.dark .modal-content {
  background: #1e293b !important;
  border: 1px solid #334155 !important;
  color: #f8fafc !important;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.6) !important;
}

[data-theme="dark"] .modal-content h2,
.dark .modal-content h2 {
  color: #f8fafc !important;
}

/* Dropdowns and Search Menus */
[data-theme="dark"] div[style*="box-shadow: 0 10px 22px"],
[data-theme="dark"] div[style*="box-shadow: 0 4px 12px"],
.dark div[style*="box-shadow: 0 10px 22px"],
.dark div[style*="box-shadow: 0 4px 12px"] {
  background: #1e293b !important;
  border-color: #334155 !important;
  color: #f8fafc !important;
}

/* Light pastel pills in dark mode */
[data-theme="dark"] div[style*="background: #eef2ff"],
[data-theme="dark"] div[style*="background-color: #eef2ff"],
[data-theme="dark"] div[style*="background: rgb(238, 242, 255)"],
[data-theme="dark"] div[style*="background-color: rgb(238, 242, 255)"],
.dark div[style*="background: #eef2ff"],
.dark div[style*="background-color: #eef2ff"],
.dark div[style*="background: rgb(238, 242, 255)"],
.dark div[style*="background-color: rgb(238, 242, 255)"] {
  background: rgba(99, 102, 241, 0.15) !important;
  border-color: #4338ca !important;
}

[data-theme="dark"] div[style*="background: #f0f9ff"],
[data-theme="dark"] div[style*="background: rgb(240, 249, 255)"],
.dark div[style*="background: #f0f9ff"],
.dark div[style*="background: rgb(240, 249, 255)"] {
  background: rgba(2, 132, 199, 0.15) !important;
  border-color: #0369a1 !important;
}

[data-theme="dark"] div[style*="background: #fffbeb"],
[data-theme="dark"] div[style*="background: rgb(255, 251, 235)"],
.dark div[style*="background: #fffbeb"],
.dark div[style*="background: rgb(255, 251, 235)"] {
  background: rgba(217, 119, 6, 0.15) !important;
  border-color: #b45309 !important;
}

[data-theme="dark"] div[style*="background: #ecfdf5"],
[data-theme="dark"] div[style*="background: rgb(236, 253, 245)"],
.dark div[style*="background: #ecfdf5"],
.dark div[style*="background: rgb(236, 253, 245)"] {
  background: rgba(16, 185, 129, 0.15) !important;
  border-color: #047857 !important;
}

[data-theme="dark"] div[style*="background: #f0fdfa"],
[data-theme="dark"] div[style*="background: rgb(240, 253, 250)"],
.dark div[style*="background: #f0fdfa"],
.dark div[style*="background: rgb(240, 253, 250)"] {
  background: rgba(13, 148, 136, 0.15) !important;
  border-color: #0f766e !important;
}

[data-theme="dark"] div[style*="background: #fef2f2"],
[data-theme="dark"] div[style*="background: rgb(254, 242, 242)"],
.dark div[style*="background: #fef2f2"],
.dark div[style*="background: rgb(254, 242, 242)"] {
  background: rgba(239, 68, 68, 0.15) !important;
  border-color: #b91c1c !important;
}

/* Pagination & Secondary Buttons */
[data-theme="dark"] button[style*="background: white"],
[data-theme="dark"] button[style*="background: rgb(255, 255, 255)"],
.dark button[style*="background: white"],
.dark button[style*="background: rgb(255, 255, 255)"] {
  background: #0f172a !important;
  border-color: #334155 !important;
  color: #e2e8f0 !important;
}

/* Secondary action buttons (for example, modal Cancel) must not retain a
 * light surface or low-contrast text when the surrounding modal is dark. */
[data-theme="dark"] button[style*="background: rgb(241, 245, 249)"],
[data-theme="dark"] button[style*="background: #f1f5f9"],
[data-theme="dark"] button[style*="background: rgb(248, 250, 252)"],
[data-theme="dark"] button[style*="background: #f8fafc"],
.dark button[style*="background: rgb(241, 245, 249)"],
.dark button[style*="background: #f1f5f9"],
.dark button[style*="background: rgb(248, 250, 252)"],
.dark button[style*="background: #f8fafc"] {
  background: #334155 !important;
  border-color: #64748b !important;
  color: #f8fafc !important;
}

a {
  color: inherit;
  text-decoration: none;
}

button {
  font-family: inherit;
}

input, button, textarea, select {
  font: inherit;
}

/* Use one crisp, consistent chevron for every native select. Some browsers
 * render the platform arrow too close to the edge or as an unmatched glyph. */
select {
  appearance: none !important;
  -webkit-appearance: none !important;
  -moz-appearance: none !important;
  padding-inline-end: 2.5rem !important;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") !important;
  background-repeat: no-repeat !important;
  background-position: right 0.75rem center !important;
  background-size: 1rem !important;
}

[dir="rtl"] select {
  background-position: left 0.75rem center !important;
}

[data-theme="dark"] select,
.dark select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") !important;
}

[dir="rtl"] {
  text-align: right;
}

[dir="rtl"] th,
[dir="rtl"] td {
  text-align: right;
}

/* Dark Mode Scrollbars */
[data-theme="dark"] ::-webkit-scrollbar,
.dark ::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

[data-theme="dark"] ::-webkit-scrollbar-track,
.dark ::-webkit-scrollbar-track {
  background: #0f172a;
}

[data-theme="dark"] ::-webkit-scrollbar-thumb,
.dark ::-webkit-scrollbar-thumb {
  background: #334155;
  border-radius: 4px;
}

[data-theme="dark"] ::-webkit-scrollbar-thumb:hover,
.dark ::-webkit-scrollbar-thumb:hover {
  background: #475569;
}

@media print {
  aside, header, .no-print, .print-controls {
    display: none !important;
  }
  .main-content-wrapper, main {
    margin: 0 !important;
    padding: 0 !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    background: white !important;
    color: black !important;
  }
}
