:root {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --text: #172033;
  --muted: #667085;
  --line: #d9e1ec;
  --primary: #1769aa;
  --primary-dark: #104c7c;
  --success: #18794e;
  --warning: #b54708;
  --warning-bg: #fff4e5;
  --danger: #b42318;
  --danger-bg: #fff1f0;
  --radius: 8px;
}

* { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background: var(--bg);
  font-family: "Google Sans", "Noto Sans Thai", "Sarabun", Arial, sans-serif;
  display: flex;
  align-items: stretch;
  overflow-x: hidden;
}

.mobile-appbar,
.menu-backdrop,
.menu-state {
  display: none;
}

.sidebar {
  flex: 0 0 240px;
  width: 240px;
  min-height: 100vh;
  position: sticky;
  top: 0;
  align-self: flex-start;
  background: #111827;
  color: #fff;
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 28px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: var(--radius);
  background: #2f80ed;
  font-weight: 700;
}

.brand small {
  display: block;
  margin-top: 4px;
  color: #b8c2d6;
}

.nav { display: grid; gap: 8px; }

.nav-item {
  width: 100%;
  border: 0;
  border-radius: var(--radius);
  padding: 11px 12px;
  color: #d7deea;
  background: transparent;
  text-align: left;
  cursor: pointer;
  font-weight: 700;
}

.nav-item.active,
.nav-item:hover {
  color: #fff;
  background: #253044;
}

.sidebar-account {
  margin-top: auto;
  border-top: 1px solid #253044;
  padding-top: 14px;
  display: grid;
  gap: 6px;
}

.sidebar-account small,
.sidebar-account span {
  color: #b8c2d6;
}

.test-user-switch {
  display: grid;
  gap: 6px;
  color: #dbe6f8;
  font-size: 12px;
  font-weight: 700;
}

.test-user-switch select {
  width: 100%;
  min-height: 36px;
  border: 1px solid #34425a;
  border-radius: var(--radius);
  background: #172235;
  color: #fff;
  padding: 0 10px;
}

.logout-button {
  margin-top: 8px;
  border: 0;
  border-radius: var(--radius);
  min-height: 38px;
  color: #fff;
  background: #b42318;
  font-weight: 700;
  cursor: pointer;
}

.status-switch-group {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-width: 230px;
}

.mini-switch {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 30px;
  padding: 5px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.mini-switch input {
  width: 13px;
  height: 13px;
  margin: 0;
}

.mini-switch.is-selected {
  border-color: #93c5fd;
  background: #eff6ff;
  color: var(--primary-dark);
}

.page {
  flex: 1 1 auto;
  width: calc(100vw - 240px);
  max-width: calc(100vw - 240px);
  padding: 24px;
  min-width: 0;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  margin-bottom: 22px;
}

h1, h2, p { margin: 0; }
h1 { font-size: 28px; }
h2 { font-size: 18px; }

.topbar p,
.panel-heading p {
  margin-top: 6px;
  color: var(--muted);
  font-size: 14px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-chip {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  padding: 10px 14px;
  white-space: nowrap;
  display: grid;
  gap: 2px;
}

.user-chip small {
  color: var(--muted);
}

.view { display: none; }
.view.active { display: block; }

.login-screen {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  background: rgba(244, 246, 249, 0.96);
  padding: 24px;
}

.login-card {
  width: min(420px, 100%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  padding: 24px;
  display: grid;
  gap: 14px;
  text-align: center;
}

.login-actions {
  display: grid;
  gap: 10px;
  margin: 4px 0;
}

.login-field {
  display: grid;
  gap: 6px;
  text-align: left;
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
}

.login-field input,
.login-field select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  background: #fff;
  color: var(--ink);
  font-size: 15px;
}

body.logged-out .sidebar,
body.logged-out .topbar,
body.logged-out .view {
  filter: blur(1px);
  pointer-events: none;
}

body.public-apply-mode .sidebar,
body.public-apply-mode .topbar,
body.public-apply-mode .mobile-appbar,
body.public-apply-mode .menu-backdrop {
  display: none;
}

body.public-apply-mode {
  display: block;
  width: 100vw;
  min-height: 100dvh;
  overflow-x: hidden;
  background:
    linear-gradient(135deg, rgba(9, 40, 78, 0.92), rgba(23, 105, 170, 0.72)),
    linear-gradient(180deg, #eff6ff, #ffffff);
}

body.public-apply-mode .page {
  margin: 0;
  width: 100vw;
  max-width: 100vw;
  min-height: 100vh;
  min-height: 100dvh;
  padding: clamp(18px, 4vw, 48px);
  background:
    linear-gradient(135deg, rgba(9, 40, 78, 0.92), rgba(23, 105, 170, 0.72)),
    linear-gradient(180deg, #eff6ff, #ffffff);
}

.public-apply-panel {
  width: min(100%, 1040px);
  max-width: 1040px;
  margin: 0 auto;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.38);
  box-shadow: 0 24px 80px rgba(15, 23, 42, 0.28);
}

.public-apply-panel .panel-heading {
  position: relative;
  padding: clamp(24px, 4vw, 42px);
  color: #fff;
  background:
    linear-gradient(135deg, rgba(15, 23, 42, 0.96), rgba(23, 105, 170, 0.92)),
    #1769aa;
}

.public-apply-panel .panel-heading h2 {
  max-width: 760px;
  margin: 0 0 8px;
  font-size: clamp(30px, 5vw, 54px);
  line-height: 1.08;
}

.public-apply-panel .panel-heading p {
  max-width: 720px;
  color: rgba(255, 255, 255, 0.84);
  font-size: 16px;
}

.apply-stepper {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  padding: 18px;
  background: #f8fbff;
  border-bottom: 1px solid var(--line);
}

.apply-step {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  color: #475569;
  background: #fff;
  font-weight: 800;
}

.apply-step strong {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  color: var(--primary);
  background: #eaf4ff;
}

.apply-step.is-active {
  color: #fff;
  border-color: transparent;
  background: var(--primary);
  box-shadow: 0 12px 24px rgba(23, 105, 170, 0.22);
}

.apply-step.is-active strong {
  color: var(--primary-dark);
  background: #fff;
}

.apply-step-panel {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.apply-step-panel.hidden {
  display: none;
}

.public-success-panel {
  display: grid;
  justify-items: center;
  gap: 12px;
  padding: 42px 22px;
  text-align: center;
  border: 1px solid #bbf7d0;
  border-radius: 10px;
  background: #f0fdf4;
  color: #14532d;
}

.public-success-panel .success-icon {
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: #16a34a;
  color: #fff;
  font-size: 32px;
  font-weight: 800;
}

.public-success-panel h3 {
  margin: 0;
  color: #052e16;
  font-size: 26px;
}

.public-success-panel p {
  margin: 0;
  max-width: 520px;
}

.apply-hero-note {
  display: grid;
  gap: 6px;
  padding: 16px;
  border: 1px solid #bfdbfe;
  border-radius: 14px;
  color: #153e75;
  background: linear-gradient(135deg, #eff6ff, #ffffff);
}

.apply-hero-note strong {
  color: #0f2f57;
  font-size: 18px;
}

.apply-hero-note span {
  color: #475569;
}

.apply-actions {
  align-items: center;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}

.compact-grid {
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  padding: 18px;
  margin-bottom: 0;
}

.summary-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  min-width: 0;
}

.summary-card span {
  color: var(--muted);
  font-size: 14px;
}

.summary-card strong {
  display: block;
  margin-top: 10px;
  font-size: clamp(20px, 2.2vw, 24px);
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.summary-card.warning { background: var(--warning-bg); }
.summary-card.danger { background: var(--danger-bg); }

.two-column {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(320px, 0.8fr);
  gap: 16px;
  align-items: start;
}

.two-column.single-column {
  grid-template-columns: minmax(0, 880px);
}

#loansView .two-column {
  grid-template-columns: 1fr;
}

#loansView .panel {
  width: 100%;
}

#loansView table {
  table-layout: fixed;
  min-width: 0;
}

#loansView th,
#loansView td {
  padding: 12px 9px;
  overflow-wrap: anywhere;
}

#loansView th:nth-child(1), #loansView td:nth-child(1) { width: 10%; }
#loansView th:nth-child(2), #loansView td:nth-child(2) { width: 9%; }
#loansView th:nth-child(3), #loansView td:nth-child(3) { width: 8%; }
#loansView th:nth-child(4), #loansView td:nth-child(4),
#loansView th:nth-child(5), #loansView td:nth-child(5),
#loansView th:nth-child(6), #loansView td:nth-child(6),
#loansView th:nth-child(7), #loansView td:nth-child(7) { width: 8%; }
#loansView th:nth-child(8), #loansView td:nth-child(8) { width: 7%; }
#loansView th:nth-child(9), #loansView td:nth-child(9) { width: 8%; }
#loansView th:nth-child(10), #loansView td:nth-child(10) { width: 7%; }
#loansView th:nth-child(11), #loansView td:nth-child(11) { width: 13%; }
#loansView th:nth-child(12), #loansView td:nth-child(12) { width: 6%; }

#loansView .status-switch-group {
  display: grid;
  grid-template-columns: 1fr;
  min-width: 0;
  gap: 5px;
}

#loansView .mini-switch {
  width: 100%;
  min-height: 28px;
  padding: 4px 7px;
  font-size: 11px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  min-width: 0;
  margin-bottom: 16px;
}

.panel-heading {
  padding: 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  border-bottom: 1px solid var(--line);
}

.panel-heading.compact { display: block; }

.filter-row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.quick-filter {
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  background: #fbfdff;
}

.quick-filter label {
  max-width: 520px;
}

.inline-date-filter {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.inline-date-filter input {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0 10px;
}

.pricing-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px;
  padding: 18px;
}

.plan-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  background: #fff;
  display: grid;
  gap: 10px;
}

.plan-card h3 {
  margin: 0;
  font-size: 18px;
}

.plan-card strong {
  font-size: 22px;
}

.plan-card.active-plan {
  border-color: var(--primary);
  background: #eef6ff;
}

.notification-list {
  display: grid;
  gap: 10px;
  padding: 18px;
}

.notification-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.notification-summary .summary-card {
  min-height: 92px;
}

.line-preview {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #f8fafc;
}

.line-preview pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text);
  font-family: "Google Sans", "Noto Sans Thai", "Sarabun", Arial, sans-serif;
  line-height: 1.5;
}

.notification {
  display: grid;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  background: #fff;
}

.notification.warning {
  border-color: #fed7aa;
  background: var(--warning-bg);
}

.notification.danger {
  border-color: #fecaca;
  background: var(--danger-bg);
}

.notification.success {
  border-color: #bbf7d0;
  background: #f0fdf4;
}

.web-reminder-toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 80;
  display: grid;
  gap: 8px;
  width: min(420px, calc(100vw - 36px));
  padding: 16px;
  border: 1px solid #bfdbfe;
  border-radius: var(--radius);
  background: #eff6ff;
  box-shadow: 0 18px 42px rgba(15, 23, 42, 0.18);
}

.web-reminder-toast strong {
  padding-right: 28px;
  font-size: 16px;
}

.web-reminder-toast span,
.web-reminder-toast small {
  color: var(--muted);
  line-height: 1.5;
}

.toast-close {
  position: absolute;
  top: 10px;
  right: 10px;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  font-size: 20px;
  cursor: pointer;
}

.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
}

th, td {
  padding: 13px 16px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

td { font-size: 14px; }

.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 5px 9px;
  font-size: 12px;
  font-weight: 700;
}

.badge.daily {
  color: var(--primary-dark);
  background: #e8f2fb;
}

.badge.floating {
  color: var(--warning);
  background: var(--warning-bg);
}

.badge.success {
  color: var(--success);
  background: #ecfdf3;
}

.badge.danger {
  color: var(--danger);
  background: var(--danger-bg);
}

.badge.muted {
  color: var(--muted);
  background: #eef2f6;
}

.data-form {
  display: grid;
  gap: 13px;
  padding: 18px;
}

label {
  display: grid;
  gap: 6px;
  color: #334155;
  font-size: 13px;
  font-weight: 700;
}

input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 11px 12px;
  color: var(--text);
  background: #fff;
  font-size: 14px;
}

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

.settings-form {
  max-width: 720px;
}

input:focus, select:focus, textarea:focus {
  outline: 3px solid #d9ebff;
  border-color: var(--primary);
}

textarea {
  resize: vertical;
  min-height: 76px;
}

.form-section-title {
  margin-top: 6px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
  color: var(--primary-dark);
  font-weight: 700;
}

.data-form .form-section-title:first-child {
  margin-top: 0;
  padding-top: 0;
  border-top: 0;
}

td small {
  color: var(--muted);
}

.notice {
  border: 1px solid #fed7aa;
  border-radius: var(--radius);
  color: #7c2d12;
  background: var(--warning-bg);
  padding: 12px;
  font-size: 14px;
}

.loan-preview {
  display: grid;
  gap: 6px;
  border: 1px solid #bfdbfe;
  border-radius: var(--radius);
  background: #eff6ff;
  color: #1e3a8a;
  padding: 12px;
  font-size: 14px;
}

.loan-preview strong {
  color: #172033;
}

.hidden { display: none; }

.primary-button,
.ghost-button,
.danger-button {
  border: 0;
  border-radius: var(--radius);
  min-height: 42px;
  padding: 0 14px;
  font-weight: 700;
  cursor: pointer;
}

.primary-button {
  color: #fff;
  background: var(--primary);
}

.primary-button:hover { background: var(--primary-dark); }

.ghost-button {
  color: var(--primary-dark);
  background: #e8f2fb;
}

.danger-button {
  color: #fff;
  background: var(--danger);
}

.danger-button:hover {
  background: #8f1d14;
}

.compact-button {
  min-height: 32px;
  padding: 0 10px;
  font-size: 12px;
}

.link-button {
  border: 0;
  padding: 0;
  color: var(--primary-dark);
  background: transparent;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  text-align: left;
}

.link-button:hover {
  text-decoration: underline;
}

.form-panel {
  max-width: 980px;
}

.payment-form-panel {
  max-width: 720px;
}

.customer-form-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.wide-field {
  grid-column: 1 / -1;
}

.form-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.button-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.compact-actions {
  gap: 6px;
  justify-content: flex-start;
}

.muted-note {
  color: var(--muted);
  font-size: 14px;
}

.detail-body {
  padding: 18px;
}

.detail-edit-form {
  margin: 16px 0;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}

.detail-edit-form h3 {
  margin: 0;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}

.detail-box {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  padding: 16px;
}

.detail-box h3 {
  margin: 0 0 10px;
  font-size: 16px;
}

.detail-box p {
  margin: 7px 0;
  color: var(--muted);
  font-size: 14px;
}

.detail-box strong {
  color: var(--text);
}

.document-list {
  margin: 10px 0 0;
  padding-left: 18px;
  color: var(--text);
  font-size: 14px;
}

.document-list li {
  margin: 4px 0;
}

.document-preview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  margin-top: 10px;
}

.document-preview {
  margin: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: #f8fafc;
}

.document-preview img {
  display: block;
  width: 100%;
  height: 130px;
  object-fit: cover;
  background: #fff;
}

.document-preview-button {
  display: block;
  width: 100%;
  border: 0;
  padding: 0;
  background: transparent;
  cursor: zoom-in;
}

.document-preview-button:focus {
  outline: 3px solid #d9ebff;
  outline-offset: 2px;
}

.document-preview figcaption {
  padding: 8px;
  font-size: 12px;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.inline-upload {
  margin: 0 8px 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  padding: 0 10px;
  border-radius: var(--radius);
  color: var(--primary-dark);
  background: #e8f2fb;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.inline-upload input {
  display: none;
}

.file-placeholder {
  height: 130px;
  display: grid;
  place-items: center;
  color: var(--muted);
  background: #eef2f7;
  font-weight: 700;
}

.inner-panel {
  margin-bottom: 0;
}

.empty-state {
  color: var(--muted);
  text-align: center;
  padding: 28px 16px;
}

.form-message {
  color: var(--success);
  font-size: 14px;
  min-height: 20px;
}

.image-modal {
  position: fixed;
  inset: 0;
  z-index: 120;
  display: grid;
  place-items: center;
  padding: 24px;
}

.image-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.72);
}

.image-modal-panel {
  position: relative;
  z-index: 1;
  width: min(960px, 100%);
  max-height: calc(100dvh - 48px);
  border-radius: var(--radius);
  background: #fff;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.image-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

.image-modal-header strong {
  min-width: 0;
  overflow-wrap: anywhere;
}

.image-modal-panel img {
  display: block;
  max-width: 100%;
  max-height: calc(100dvh - 118px);
  margin: auto;
  object-fit: contain;
  background: #0f172a;
}

@media (max-width: 900px) {
  .sidebar {
    flex-basis: 210px;
    width: 210px;
  }

  .page {
    width: calc(100vw - 210px);
    max-width: calc(100vw - 210px);
    padding: 18px;
  }

  .brand {
    align-items: flex-start;
  }

  .brand strong {
    font-size: 14px;
  }

  .nav-item {
    padding: 10px;
  }

  .two-column { grid-template-columns: 1fr; }
  .customer-form-grid, .detail-grid { grid-template-columns: 1fr; }
  .topbar { align-items: flex-start; flex-direction: column; }
  .topbar-actions { width: 100%; justify-content: space-between; }

  table {
    min-width: 100%;
  }

  th, td {
    padding: 9px 8px;
    font-size: 12px;
    overflow-wrap: anywhere;
  }

  .panel-heading {
    align-items: flex-start;
    flex-direction: column;
  }
}

@media (max-width: 900px) {
  body {
    display: block;
    min-height: 100dvh;
  }

  .mobile-appbar {
    position: sticky;
    top: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 56px;
    padding: 10px 14px;
    color: #fff;
    background: #111827;
    box-shadow: 0 8px 18px rgba(15, 23, 42, 0.16);
  }

  .menu-state {
    position: fixed;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
  }

  .mobile-appbar strong {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 15px;
  }

  .menu-toggle {
    display: inline-flex;
    align-items: center;
    flex: 0 0 auto;
    min-height: 40px;
    border: 1px solid #34425a;
    border-radius: var(--radius);
    padding: 0 12px;
    color: #fff;
    background: #172235;
    font-weight: 700;
    cursor: pointer;
  }

  .menu-backdrop {
    position: fixed;
    inset: 0;
    z-index: 55;
    display: block;
    border: 0;
    background: rgba(15, 23, 42, 0.52);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 160ms ease, visibility 160ms ease;
  }

  body.menu-open {
    overflow: hidden;
  }

  body.menu-open .menu-backdrop {
    display: block !important;
    opacity: 1 !important;
    visibility: visible !important;
    pointer-events: auto !important;
  }

  #menuState:checked ~ .menu-backdrop {
    display: block !important;
    opacity: 1 !important;
    visibility: visible !important;
    pointer-events: auto !important;
  }

  .menu-backdrop.is-open {
    display: block !important;
    opacity: 1 !important;
    visibility: visible !important;
    pointer-events: auto !important;
  }

  body:not(.menu-open) .menu-backdrop {
    opacity: 0 !important;
    visibility: hidden !important;
    pointer-events: none !important;
  }

  body:not(.menu-open) .sidebar {
    display: none !important;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 60;
    width: min(86vw, 320px);
    min-height: 100dvh;
    padding: 18px 14px;
    gap: 14px;
    display: none;
    overflow-y: auto;
    transform: none;
    transition: none;
    box-shadow: 18px 0 32px rgba(15, 23, 42, 0.24);
  }

  body.menu-open .sidebar {
    display: flex !important;
  }

  .sidebar.is-open {
    display: flex !important;
  }

  #menuState:checked ~ .sidebar {
    display: flex !important;
  }

  .brand {
    margin-bottom: 10px;
    gap: 10px;
  }

  .brand-mark {
    width: 38px;
    height: 38px;
    flex: 0 0 38px;
  }

  .brand strong {
    font-size: 14px;
    line-height: 1.25;
  }

  .brand small {
    font-size: 12px;
  }

  .nav {
    display: grid;
    gap: 8px;
    overflow: visible;
    padding: 0;
  }

  .nav-item {
    width: auto;
    min-height: 38px;
    padding: 9px 12px;
    white-space: normal;
  }

  .sidebar-account {
    margin-top: auto;
    padding-top: 10px;
    grid-template-columns: 1fr;
    align-items: stretch;
    column-gap: 0;
  }

  .sidebar-account small,
  .sidebar-account span {
    font-size: 12px;
  }

  .test-user-switch {
    grid-column: 1;
    grid-row: auto;
  }

  .logout-button {
    grid-column: 1 / -1;
    min-height: 40px;
  }

  .page {
    width: 100%;
    max-width: 100%;
    padding: 14px;
  }

  .topbar {
    gap: 12px;
    margin-bottom: 14px;
  }

  h1 {
    font-size: 24px;
    line-height: 1.2;
  }

  .topbar p,
  .panel-heading p {
    font-size: 13px;
  }

  .topbar-actions,
  .button-row,
  .form-actions,
  .filter-row {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .topbar-actions > *,
  .button-row > *,
  .form-actions > *,
  .filter-row > * {
    width: 100%;
  }

  .user-chip {
    width: 100%;
  }

  .summary-grid,
  .compact-grid,
  .pricing-grid,
  .notification-summary,
  .document-preview-grid,
  .apply-stepper,
  .apply-step-panel {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .compact-grid,
  .detail-body,
  .data-form,
  .panel-heading,
  .quick-filter,
  .pricing-grid,
  .notification-summary,
  .notification-list {
    padding: 14px;
  }

  .summary-card,
  .detail-box,
  .detail-edit-form,
  .panel,
  .plan-card,
  .notification {
    border-radius: 8px;
  }

  .summary-card {
    padding: 14px;
  }

  .summary-card strong {
    font-size: 22px;
  }

  .panel {
    margin-bottom: 12px;
  }

  body.public-apply-mode .page {
    width: 100vw;
    max-width: 100vw;
    padding: 12px;
  }

  .public-apply-panel {
    width: 100%;
    margin: 0;
    box-shadow: 0 16px 40px rgba(15, 23, 42, 0.22);
  }

  .public-apply-panel .panel-heading {
    padding: 22px 16px;
  }

  .public-apply-panel .panel-heading h2 {
    font-size: 30px;
  }

  .apply-stepper,
  .apply-step-panel {
    padding: 14px;
  }

  .apply-step {
    min-width: 0;
  }

  .payment-form-panel,
  .form-panel,
  .settings-form {
    max-width: none;
  }

  input,
  select,
  textarea {
    min-height: 44px;
    font-size: 16px;
  }

  textarea {
    min-height: 92px;
  }

  .primary-button,
  .ghost-button,
  .danger-button,
  .logout-button {
    min-height: 44px;
  }

  .table-wrap {
    width: 100%;
    overflow-x: visible;
    border-radius: var(--radius);
    -webkit-overflow-scrolling: touch;
  }

  table,
  thead,
  tbody,
  tr,
  th,
  td {
    display: block;
    width: 100%;
    min-width: 0;
  }

  thead {
    display: none;
  }

  tbody {
    display: grid;
    gap: 12px;
  }

  tr {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #fff;
    overflow: hidden;
  }

  td {
    display: grid;
    grid-template-columns: minmax(122px, 34%) minmax(0, 1fr);
    gap: 10px;
    align-items: start;
    min-height: 42px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--line);
    font-size: 13px;
    overflow-wrap: anywhere;
    word-break: normal;
  }

  #loansView table {
    table-layout: auto;
  }

  #loansView th,
  #loansView td {
    width: 100% !important;
  }

  td:last-child {
    border-bottom: 0;
  }

  td::before {
    content: attr(data-label);
    color: var(--muted);
    font-weight: 700;
  }

  td.empty-state {
    display: block;
    padding: 18px 12px;
    text-align: center;
  }

  td.empty-state::before {
    content: "";
    display: none;
  }

  .inline-date-filter {
    display: grid;
    width: 100%;
  }

  .quick-filter label {
    max-width: none;
  }

  .document-preview img,
  .file-placeholder {
    height: 180px;
  }

  .login-screen {
    padding: 14px;
  }

  .status-switch-group {
    min-width: 0;
    justify-content: flex-start;
  }

  .image-modal {
    padding: 12px;
  }

  .image-modal-panel {
    max-height: calc(100dvh - 24px);
  }

  .image-modal-panel img {
    max-height: calc(100dvh - 94px);
  }
}

@media (max-width: 420px) {
  .page {
    padding: 10px;
  }

  body.public-apply-mode .page {
    padding: 8px;
  }

  .public-apply-panel {
    border-radius: 10px;
  }

  .public-apply-panel .panel-heading h2 {
    font-size: 26px;
  }

  .public-apply-panel .panel-heading p {
    font-size: 14px;
  }

  .apply-step {
    padding: 10px;
    font-size: 14px;
  }

.apply-step strong {
  width: 30px;
  height: 30px;
}

.apply-actions {
  gap: 8px;
}

  .sidebar {
    padding: 9px 10px;
  }

  .sidebar-account {
    grid-template-columns: 1fr;
  }

  .test-user-switch {
    grid-column: 1;
    grid-row: auto;
  }

  .brand small {
    max-width: 230px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  h1 {
    font-size: 22px;
  }

  .summary-card strong {
    font-size: 20px;
  }

  td {
    grid-template-columns: 1fr;
    gap: 4px;
  }
}

@media (max-width: 900px) {
  #menuState:checked ~ #menuBackdrop,
  #menuBackdrop.is-open {
    display: block !important;
    opacity: 1 !important;
    visibility: visible !important;
    pointer-events: auto !important;
  }

  #menuState:checked ~ #sidebar,
  #sidebar.is-open {
    display: flex !important;
  }
}

/* ── Change Password Modal ─────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  padding: 16px;
}
.modal-overlay.hidden {
  display: none;
}
.modal-box {
  background: var(--surface, #fff);
  border-radius: 12px;
  padding: 28px 24px 20px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.18);
}
.modal-box input[type="password"] {
  width: 100%;
  box-sizing: border-box;
  padding: 8px 12px;
  border: 1px solid var(--border, #d1d5db);
  border-radius: 6px;
  font-size: 1rem;
  margin-top: 4px;
}
.btn-primary {
  background: var(--primary, #2563eb);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 8px 20px;
  font-size: 1rem;
  cursor: pointer;
}
.btn-secondary {
  background: transparent;
  border: 1px solid var(--border, #d1d5db);
  border-radius: 6px;
  padding: 8px 20px;
  font-size: 1rem;
  cursor: pointer;
}
