/* Compatibility fixes for the 2026-07-29 RD feedback.
   Kept separate from the unreproducible Vite bundle for safe rollback. */

:root {
  color-scheme: light;
  --font: "Leelawadee UI", "Noto Sans Thai", Tahoma, Arial, sans-serif;
  --bg: #f4f7fb;
  --bg-card: #ffffff;
  --bg-hover: #f1f5f9;
  --bg-input: #ffffff;
  --bg-section: #f8fafc;
  --bg-station-header: #eef2ff;
  --surface: #ffffff;
  --surface2: #f8fafc;
  --card-bg: #ffffff;
  --input-bg: #ffffff;
  --hover-bg: #f1f5f9;
  --table-head-bg: #eef2f6;
  --border: #d8e0ea;
  --border-light: #e8edf3;
  --border-divider: #dbe3ec;
  --border-table: #cbd5e1;
  --text: #1e293b;
  --text2: #475569;
  --text3: #64748b;
  --text-primary: #1e293b;
  --text-secondary: #475569;
  --text-label: #334155;
  --text-muted: #64748b;
  --text-placeholder: #94a3b8;
  --c-dark: #172033;
  --c-muted: #64748b;
  --c-blue: #2563eb;
  --c-teal: #0f766e;
  --c-red: #dc2626;
  --accent-blue: #2563eb;
  --accent-blue-light: #dbeafe;
  --accent-green: #059669;
  --accent-green-light: #d1fae5;
  --accent-orange: #ea580c;
  --accent-orange-hover: #c2410c;
  --accent-orange-light: #ffedd5;
  --result-pass-bg: #dcfce7;
  --result-pass-text: #166534;
  --result-fail-bg: #fee2e2;
  --result-fail-text: #991b1b;
  --sb-bg: #ffffff;
  --sb-border: #dbe3ec;
  --sb-divider: #e8edf3;
  --sb-brand-bg: #4f46e5;
  --sb-brand-name: #172033;
  --sb-brand-sub: #64748b;
  --sb-text: #475569;
  --sb-text-hover: #172033;
  --sb-bottom-text: #64748b;
  --sb-hover-bg: #f1f5f9;
  --sb-active-bg: #eef2ff;
  --sb-active-text: #3730a3;
  --sb-active-border: #4f46e5;
  --sb-role-bg: #ffffff;
  --sb-role-border: #d8e0ea;
  --dp-bg: #ffffff;
  --dp-surface: #ffffff;
  --dp-text: #1e293b;
  --dp-muted: #64748b;
  --dp-border: #cbd5e1;
  --dp-accent: #4f46e5;
  --r-sm: 7px;
  --r-md: 10px;
  --r-lg: 14px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-card: 0 8px 24px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 20px 50px rgba(15, 23, 42, 0.18);
}

html,
body,
button,
input,
select,
textarea {
  font-family: var(--font);
}

html.dark {
  color-scheme: dark;
  --bg: #0f172a;
  --bg-card: #172033;
  --bg-hover: #263249;
  --bg-input: #111c30;
  --bg-section: #172033;
  --bg-station-header: #242f48;
  --surface: #172033;
  --surface2: #202b40;
  --card-bg: #172033;
  --input-bg: #111c30;
  --hover-bg: #263249;
  --table-head-bg: #202b40;
  --border: #334155;
  --border-light: #2b394f;
  --border-divider: #334155;
  --border-table: #475569;
  --text: #f1f5f9;
  --text2: #cbd5e1;
  --text3: #94a3b8;
  --text-primary: #f1f5f9;
  --text-secondary: #cbd5e1;
  --text-label: #e2e8f0;
  --text-muted: #94a3b8;
  --text-placeholder: #64748b;
  --sb-bg: #111827;
  --sb-border: #263249;
  --sb-divider: #263249;
  --sb-brand-name: #f8fafc;
  --sb-brand-sub: #94a3b8;
  --sb-text: #cbd5e1;
  --sb-text-hover: #ffffff;
  --sb-bottom-text: #94a3b8;
  --sb-hover-bg: #202b40;
  --sb-active-bg: #312e81;
  --sb-active-text: #e0e7ff;
  --sb-active-border: #818cf8;
  --sb-role-bg: #172033;
  --sb-role-border: #334155;
  --dp-bg: #111c30;
  --dp-surface: #172033;
  --dp-text: #f1f5f9;
  --dp-muted: #94a3b8;
  --dp-border: #475569;
}

.rd-print-textarea-value {
  display: none;
}

.modal-backdrop {
  background: rgba(15, 23, 42, 0.58) !important;
  backdrop-filter: blur(2px);
}

.modal-backdrop .modal {
  overflow: hidden;
  background: var(--card-bg, #ffffff) !important;
  color: var(--text, #1e293b) !important;
  border-color: var(--border, #d8e0ea) !important;
  box-shadow: var(--shadow-lg) !important;
}

.modal-backdrop .modal-header,
.modal-backdrop .modal-form,
.modal-backdrop .modal-footer {
  background: var(--card-bg, #ffffff);
}

.modal-backdrop .modal-form .field {
  width: 100%;
}

.modal-backdrop .modal-form input,
.modal-backdrop .modal-form select {
  box-sizing: border-box;
  width: 100%;
  min-height: 42px;
  background: var(--input-bg, #ffffff) !important;
  color: var(--text, #1e293b) !important;
  border-color: var(--border, #cbd5e1) !important;
}

.modal-backdrop .modal-form input:focus,
.modal-backdrop .modal-form select:focus {
  border-color: #4f46e5 !important;
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.14);
}

.modal-backdrop .modal-footer {
  border-top: 1px solid var(--border-light, #e8edf3);
  padding-top: 16px !important;
}

.st-badge.st-pending,
.st-pending {
  color: #92400e !important;
  background: #fef3c7 !important;
  border: 1px solid #f59e0b !important;
}

.st-badge.st-in-progress,
.st-in-progress {
  color: #1e40af !important;
  background: #dbeafe !important;
  border: 1px solid #60a5fa !important;
}

.st-badge.st-pending-rd,
.st-pending-rd {
  color: #6b21a8 !important;
  background: #f3e8ff !important;
  border: 1px solid #c084fc !important;
}

.st-badge.st-complete,
.st-complete {
  color: #166534 !important;
  background: #dcfce7 !important;
  border: 1px solid #4ade80 !important;
}

.st-badge.st-cancelled,
.st-cancelled {
  color: #991b1b !important;
  background: #fee2e2 !important;
  border: 1px solid #f87171 !important;
}

.rd-medium-volume {
  display: inline-flex !important;
  align-items: baseline;
  gap: 0.5rem !important;
  flex-wrap: wrap;
}

main.rd-access-blocked-active > :not(#rd-access-blocked) {
  display: none !important;
}

#rd-access-blocked {
  max-width: 720px;
  margin: 48px auto;
  padding: 32px;
  border: 1px solid #fecaca;
  border-radius: 14px;
  background: #fff7f7;
  color: #7f1d1d;
  text-align: center;
  box-shadow: 0 8px 24px rgba(127, 29, 29, 0.08);
}

#rd-access-blocked h1 {
  margin: 0 0 12px;
  font-size: 1.5rem;
}

#rd-access-blocked p {
  margin: 0 0 20px;
  color: #991b1b;
}

#rd-access-blocked a {
  display: inline-block;
  padding: 10px 18px;
  border-radius: 8px;
  background: #7f1d1d;
  color: #fff;
  text-decoration: none;
  font-weight: 600;
}

@media print {
  @page {
    size: A4 portrait;
    margin: 10mm;
  }

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

  html,
  body,
  #app,
  .app-layout,
  .app-main,
  .app-main-full,
  main,
  .app-content {
    width: 100% !important;
    min-width: 0 !important;
    max-width: none !important;
    height: auto !important;
    min-height: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: visible !important;
    background: #ffffff !important;
    color: #000000 !important;
  }

  body {
    font-family: Tahoma, "Leelawadee UI", Arial, sans-serif !important;
    font-size: 10pt !important;
  }

  .sidebar,
  .no-print,
  .action-bar,
  .records-panel,
  .toast,
  #rd-access-blocked,
  #rd-evidence-lock-note {
    display: none !important;
  }

  .form-card {
    display: block !important;
    width: 100% !important;
    max-width: none !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: visible !important;
    border: 0 !important;
    border-radius: 0 !important;
    background: #ffffff !important;
    box-shadow: none !important;
    color: #000000 !important;
  }

  .form-header {
    display: grid !important;
    grid-template-columns: minmax(130px, 1.15fr) minmax(250px, 2.2fr) minmax(105px, 0.85fr) !important;
    width: 100% !important;
    break-inside: avoid;
  }

  .company-name,
  .form-title-block,
  .form-number-block,
  .form-title-th,
  .form-number {
    min-width: 0 !important;
    max-width: none !important;
    white-space: normal !important;
    word-break: normal !important;
    overflow-wrap: normal !important;
    line-height: 1.25 !important;
  }

  .form-title-th {
    font-size: 11pt !important;
  }

  .form-number-block,
  .form-number {
    font-size: 9pt !important;
  }

  input,
  textarea,
  select,
  .dp-field {
    color: #000000 !important;
    background: transparent !important;
    opacity: 1 !important;
  }

  select {
    appearance: none !important;
  }

  table {
    width: 100% !important;
    max-width: 100% !important;
    table-layout: fixed;
  }

  th,
  td {
    overflow-wrap: anywhere;
  }

  .grid-section,
  .station-grid,
  .table-wrap {
    width: 100% !important;
    max-width: 100% !important;
    overflow: visible !important;
  }

  .section-title,
  .field-section,
  .obs-section,
  .pdf-section {
    break-inside: avoid;
  }

  html.rd-print-dissolution body {
    font-size: 8.2pt !important;
  }

  html.rd-print-dissolution body .form-card {
    width: 108.7% !important;
    zoom: 0.92;
  }

  html.rd-print-dissolution body .form-header {
    grid-template-columns: minmax(120px, 1.15fr) minmax(260px, 2.2fr) minmax(100px, 0.85fr) !important;
  }

  html.rd-print-dissolution body .section-title {
    padding-top: 5px !important;
    padding-bottom: 5px !important;
    margin-top: 7px !important;
    margin-bottom: 6px !important;
  }

  html.rd-print-dissolution body .field-row {
    gap: 6px !important;
    margin-bottom: 5px !important;
  }

  html.rd-print-dissolution body .field-section,
  html.rd-print-dissolution body .obs-section,
  html.rd-print-dissolution body .pdf-section {
    margin-top: 5px !important;
    margin-bottom: 5px !important;
    padding-top: 5px !important;
    padding-bottom: 5px !important;
    break-inside: auto !important;
  }

  html.rd-print-dissolution body .divider {
    margin-top: 6px !important;
    margin-bottom: 6px !important;
  }

  html.rd-print-dissolution .rd-print-textarea-source {
    display: none !important;
  }

  html.rd-print-dissolution .rd-print-textarea-value {
    display: block !important;
    flex: 1 1 auto;
    min-height: 32px;
    padding: 5px 7px;
    border: 1px solid #777;
    border-radius: 3px;
    color: #000;
    background: #fff;
    font: inherit;
    line-height: 1.3;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
  }
}

#rd-evidence-lock-note {
  margin: 0 0 16px;
  padding: 12px 16px;
  border: 1px solid #f59e0b;
  border-radius: 8px;
  background: #fffbeb;
  color: #92400e;
  font-weight: 600;
}

.rd-evidence-locked input:disabled,
.rd-evidence-locked textarea:disabled,
.rd-evidence-locked select:disabled {
  cursor: not-allowed;
  opacity: 0.72;
}

.rd-appearance-result {
  flex: 1 1 100%;
  margin-top: 6px;
  padding: 8px 10px;
  border-radius: 6px;
  background: #f0fdf4;
  color: #166534;
  white-space: pre-wrap;
}
