:root {
  --lfe-navy: #0f3b5c;
  --lfe-navy-dark: #0a2a42;
  --lfe-teal: #2c7da0;
  --lfe-teal-light: #e8f4fa;
  --lfe-bg: #f0f4f9;
  --lfe-surface: #ffffff;
  --lfe-border: #e2e8f0;
  --lfe-text: #1e293b;
  --lfe-muted: #64748b;
  --lfe-success: #059669;
  --lfe-success-bg: #ecfdf5;
  --lfe-warning: #d97706;
  --lfe-warning-bg: #fffbeb;
  --lfe-danger: #dc2626;
  --lfe-danger-bg: #fef2f2;
  --radius-lg: 20px;
  --radius-xl: 28px;
  --shadow-sm: 0 1px 3px rgba(15, 59, 92, 0.06);
  --shadow-md: 0 8px 24px rgba(15, 59, 92, 0.1);
  --shadow-lg: 0 20px 50px rgba(15, 59, 92, 0.15);
  --header-h: 64px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

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

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--lfe-bg);
  color: var(--lfe-text);
  line-height: 1.5;
  min-height: 100dvh;
  padding: 0;
  padding-bottom: calc(12px + var(--safe-bottom));
}

.app-shell {
  max-width: 1200px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.app-container {
  flex: 1;
  background: var(--lfe-surface);
  box-shadow: var(--shadow-lg);
  overflow-x: hidden;
  overflow-y: visible;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

@media (min-width: 768px) {
  body { padding: 16px; }
  .app-container { border-radius: 24px; margin-top: 0; }
}

/* Header */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: linear-gradient(135deg, var(--lfe-navy-dark), var(--lfe-navy));
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.15);
}

.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.logo-wrap { display: flex; align-items: center; gap: 10px; min-width: 0; }

.logo-icon {
  width: 36px; height: 36px;
  background: linear-gradient(135deg, #67e8f9, var(--lfe-teal));
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; flex-shrink: 0;
}

.logo {
  font-size: 1.1rem;
  font-weight: 800;
  color: #fff;
  letter-spacing: -0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.logo-sub { font-size: 10px; color: #94a3b8; font-weight: 500; display: block; }

.header-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

.lang-btn {
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.2);
  color: #fff;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 12px;
  min-height: 40px;
  transition: background 0.2s;
}
.lang-btn:hover { background: rgba(255,255,255,0.2); }

.role-tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding-bottom: 2px;
}
.role-tabs::-webkit-scrollbar { display: none; }

.role-tab {
  flex: 1 0 auto;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.12);
  color: #cbd5e1;
  font-weight: 600;
  padding: 10px 16px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 13px;
  min-height: 44px;
  white-space: nowrap;
  transition: all 0.2s;
}
.role-tab.active {
  background: var(--lfe-teal);
  border-color: var(--lfe-teal);
  color: #fff;
  box-shadow: 0 4px 12px rgba(44, 125, 160, 0.4);
}
.role-tab.role-tab-disabled,
.role-tab:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  pointer-events: none;
}

/* Panels */
.panel { display: none; padding: 16px; flex: 1; background: #f8fafc; }
.panel.active { display: block; }
@media (min-width: 768px) { .panel { padding: 24px 28px; } }

/* Cards */
.card {
  background: var(--lfe-surface);
  border-radius: var(--radius-lg);
  padding: 18px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--lfe-border);
}

.card-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--lfe-navy);
  margin-bottom: 14px;
}

.card-narrow { max-width: 440px; margin-left: auto; margin-right: auto; }

.demo-banner {
  background: var(--lfe-teal-light);
  border: 1px solid #bae6fd;
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 13px;
  color: var(--lfe-navy);
  margin-bottom: 16px;
}
.demo-banner strong { display: block; margin-bottom: 4px; }

/* Sub tabs */
.sub-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 18px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding: 4px;
  background: #fff;
  border-radius: 999px;
  border: 1px solid var(--lfe-border);
  box-shadow: var(--shadow-sm);
}
.sub-tabs::-webkit-scrollbar { display: none; }

.sub-tab {
  flex: 1 0 auto;
  background: transparent;
  border: none;
  padding: 10px 16px;
  font-weight: 600;
  color: var(--lfe-muted);
  cursor: pointer;
  border-radius: 999px;
  font-size: 13px;
  min-height: 44px;
  transition: all 0.2s;
}
.sub-tab.active { background: var(--lfe-teal); color: #fff; }

/* Forms */
.input-group { margin-bottom: 16px; }

label {
  font-weight: 600;
  font-size: 13px;
  color: #334155;
  display: block;
  margin-bottom: 6px;
}

input, select, textarea {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid #cbd5e1;
  border-radius: 12px;
  font-size: 16px;
  font-family: inherit;
  background: #fff;
  transition: border-color 0.2s, box-shadow 0.2s;
  min-height: 48px;
}
input:focus, select:focus {
  outline: none;
  border-color: var(--lfe-teal);
  box-shadow: 0 0 0 3px rgba(44, 125, 160, 0.15);
}

.checkbox-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin: 14px 0;
  font-size: 13px;
  line-height: 1.4;
}
.checkbox-row input[type="checkbox"] { width: 20px; height: 20px; min-height: 20px; margin-top: 2px; flex-shrink: 0; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--lfe-navy);
  color: #fff;
  border: none;
  padding: 14px 20px;
  border-radius: 12px;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
  font-size: 15px;
  min-height: 48px;
  transition: transform 0.15s, background 0.2s, box-shadow 0.2s;
  font-family: inherit;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--lfe-navy); }
.btn-primary:hover { background: var(--lfe-navy-dark); }
.btn-secondary { background: #e2e8f0; color: var(--lfe-text); }
.btn-secondary:hover { background: #cbd5e1; }
.btn-outline {
  background: transparent;
  border: 1.5px solid var(--lfe-teal);
  color: var(--lfe-teal);
  width: auto;
  padding: 10px 18px;
  min-height: 44px;
  font-size: 14px;
}
.btn-sm { padding: 8px 14px; min-height: 40px; font-size: 13px; width: auto; }
.btn-group { display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }
@media (min-width: 480px) { .btn-group-row { flex-direction: row; } .btn-group-row .btn { flex: 1; } }

button { /* legacy compat */ }

.flex-between {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.page-title { font-size: 1.25rem; font-weight: 700; color: var(--lfe-navy); }

/* Application cards */
.application-card {
  border: 1px solid var(--lfe-border);
  border-radius: var(--radius-lg);
  padding: 16px;
  margin-bottom: 14px;
  background: #fff;
  transition: box-shadow 0.2s;
}
.application-card:hover { box-shadow: var(--shadow-md); }

.badge {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.badge-funded { background: var(--lfe-success-bg); color: var(--lfe-success); }
.badge-pending { background: var(--lfe-warning-bg); color: var(--lfe-warning); }
.badge-declined { background: var(--lfe-danger-bg); color: var(--lfe-danger); }
.badge-draft { background: #f1f5f9; color: var(--lfe-muted); }

.status-message {
  background: var(--lfe-warning-bg);
  padding: 12px 14px;
  border-radius: 12px;
  font-size: 13px;
  margin-top: 12px;
  border-left: 4px solid var(--lfe-warning);
  line-height: 1.45;
}

.progress-track {
  background: #e2e8f0;
  border-radius: 999px;
  height: 8px;
  margin-top: 10px;
  overflow: hidden;
}
.progress-fill { height: 100%; border-radius: 999px; transition: width 0.4s ease; }
.progress-fill.pending { background: var(--lfe-warning); }
.progress-fill.funded { background: var(--lfe-success); }
.progress-fill.declined { background: var(--lfe-danger); }
.progress-label { font-size: 11px; color: var(--lfe-muted); margin-top: 6px; display: block; }

.loan-detail-row { margin: 6px 0; font-size: 14px; }
.loan-detail-row strong { color: var(--lfe-muted); font-weight: 600; }

/* Social proof */
.social-proof { max-height: 280px; overflow-y: auto; margin-top: 16px; }
.social-item {
  background: #fff;
  border: 1px solid var(--lfe-border);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 8px;
  font-size: 13px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
@media (min-width: 480px) {
  .social-item { flex-direction: row; justify-content: space-between; align-items: center; }
}

.promo-text {
  background: linear-gradient(135deg, var(--lfe-navy-dark), var(--lfe-navy));
  color: #fff;
  border-radius: var(--radius-lg);
  padding: 18px;
  text-align: center;
  margin-top: 16px;
}
.promo-text p { margin: 6px 0; font-size: 13px; opacity: 0.95; }

/* Presets & slider */
.loan-presets { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0; }
.preset-btn {
  flex: 1;
  min-width: 60px;
  background: #fff;
  border: 1.5px solid var(--lfe-border);
  border-radius: 999px;
  padding: 10px;
  font-weight: 700;
  cursor: pointer;
  font-size: 13px;
  min-height: 44px;
  transition: all 0.2s;
}
.preset-btn:hover, .preset-btn.active { border-color: var(--lfe-teal); background: var(--lfe-teal-light); color: var(--lfe-navy); }

input[type="range"] {
  padding: 0;
  min-height: auto;
  accent-color: var(--lfe-teal);
  margin: 12px 0;
}

.amount-display {
  text-align: center;
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--lfe-navy);
  margin: 8px 0 16px;
}

.result-box {
  border-radius: var(--radius-lg);
  padding: 16px;
  margin-top: 14px;
}
.result-box.success { background: var(--lfe-success-bg); border: 1px solid #6ee7b7; }
.result-box.error { background: var(--lfe-danger-bg); border: 1px solid #fca5a5; }

/* Tables — mobile card layout */
.table-wrapper { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: var(--radius-lg); border: 1px solid var(--lfe-border); background: #fff; }

table { width: 100%; border-collapse: collapse; min-width: 600px; }
th, td { text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--lfe-border); font-size: 13px; vertical-align: middle; }
th { background: #f8fafc; font-weight: 700; color: var(--lfe-navy); font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; }

.admin-cards { display: none; }
@media (max-width: 767px) {
  .table-wrapper table { display: none; }
  .admin-cards { display: block; }
  .admin-card-item {
    border: 1px solid var(--lfe-border);
    border-radius: var(--radius-lg);
    padding: 14px;
    margin-bottom: 12px;
    background: #fff;
  }
  .admin-card-row { display: flex; justify-content: space-between; padding: 6px 0; font-size: 13px; border-bottom: 1px solid #f1f5f9; }
  .admin-card-row:last-child { border-bottom: none; }
  .admin-card-label { color: var(--lfe-muted); font-weight: 600; }
}

/* Lead links */
.lead-item {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 12px;
  background: #f8fafc;
  border-radius: 12px;
  margin-bottom: 8px;
  font-size: 13px;
}
.lead-item code { background: #e2e8f0; padding: 4px 8px; border-radius: 6px; font-size: 11px; }

/* File preview */
.file-preview {
  background: var(--lfe-success-bg);
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 12px;
  margin-top: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.repay-row { display: flex; flex-direction: column; gap: 12px; margin-top: 14px; }
@media (min-width: 640px) {
  .repay-row { flex-direction: row; align-items: flex-end; }
  .repay-row .input-group { flex: 2; margin-bottom: 0; }
  .repay-row .btn { flex: 1; width: auto; }
}

/* Footer */
.app-footer {
  text-align: center;
  padding: 16px;
  font-size: 11px;
  color: var(--lfe-muted);
  border-top: 1px solid var(--lfe-border);
  background: #fff;
}
.legal-links { margin-bottom: 8px; }
.legal-links a {
  color: var(--lfe-teal);
  margin: 0 8px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  text-decoration: none;
}
.legal-links a:hover { text-decoration: underline; }

.hidden { display: none !important; }

.form-error {
  background: var(--lfe-danger-bg);
  color: var(--lfe-danger);
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 13px;
  margin-top: 12px;
  font-weight: 600;
}

/* Legacy modal compat */
.modal { display: none; }

/* Dialog system */
.dialog-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 3000;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s, visibility 0.25s;
}
.dialog-overlay.open { opacity: 1; visibility: visible; }

@media (min-width: 640px) {
  .dialog-overlay { align-items: center; padding: 20px; }
}

.dialog {
  background: #fff;
  width: 100%;
  max-height: 92dvh;
  border-radius: 20px 20px 0 0;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
}
.dialog-overlay.open .dialog { transform: translateY(0); }

@media (min-width: 640px) {
  .dialog { max-width: 520px; border-radius: 20px; transform: translateY(16px) scale(0.96); }
  .dialog-overlay.open .dialog { transform: translateY(0) scale(1); }
}
.dialog.dialog-lg { max-width: 640px; }
.dialog.dialog-full { max-width: 720px; }

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--lfe-border);
  flex-shrink: 0;
}
.dialog-header h2 { font-size: 1.1rem; font-weight: 700; color: var(--lfe-navy); padding-right: 12px; }

.dialog-close {
  width: 40px; height: 40px;
  border: none;
  background: #f1f5f9;
  border-radius: 10px;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  color: var(--lfe-muted);
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
.dialog-close:hover { background: #e2e8f0; color: var(--lfe-text); }

.dialog-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
  -webkit-overflow-scrolling: touch;
  font-size: 14px;
  line-height: 1.55;
}
.dialog-body h3 { margin-bottom: 12px; color: var(--lfe-navy); }
.dialog-body p, .dialog-body li { margin-bottom: 10px; }
.dialog-body ul { padding-left: 20px; }

.dialog-text { color: var(--lfe-muted); margin-bottom: 4px; }

.dialog-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--lfe-border);
  display: flex;
  flex-direction: column-reverse;
  gap: 10px;
  flex-shrink: 0;
  padding-bottom: calc(16px + var(--safe-bottom));
}
@media (min-width: 480px) {
  .dialog-footer { flex-direction: row; justify-content: flex-end; }
  .dialog-footer .btn { width: auto; min-width: 120px; }
}

.detail-grid {
  display: grid;
  gap: 10px;
}
.detail-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid #f1f5f9;
  font-size: 14px;
}
.detail-row span:first-child { color: var(--lfe-muted); font-weight: 600; flex-shrink: 0; }
.detail-row span:last-child { text-align: right; word-break: break-word; }

/* Toasts */
.toast-root {
  position: fixed;
  top: calc(12px + env(safe-area-inset-top, 0px));
  left: 50%;
  transform: translateX(-50%);
  z-index: 4000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(420px, calc(100vw - 24px));
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 16px;
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 10px 40px rgba(0,0,0,0.15);
  border: 1px solid var(--lfe-border);
  opacity: 0;
  transform: translateY(-12px);
  transition: all 0.3s ease;
  pointer-events: auto;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast-success { border-left: 4px solid var(--lfe-success); }
.toast-error { border-left: 4px solid var(--lfe-danger); }
.toast-info { border-left: 4px solid var(--lfe-teal); }
.toast-warning { border-left: 4px solid var(--lfe-warning); }
.toast-icon { font-size: 18px; flex-shrink: 0; }
.toast-msg { font-size: 14px; font-weight: 500; color: var(--lfe-text); line-height: 1.4; }

/* Commission stat */
.stat-highlight {
  background: linear-gradient(135deg, var(--lfe-navy), var(--lfe-teal));
  color: #fff;
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 16px;
  text-align: center;
}
.stat-highlight .stat-value { font-size: 1.75rem; font-weight: 800; }
.stat-highlight .stat-label { font-size: 13px; opacity: 0.85; margin-top: 4px; }
