/* ============================================================
   Loan-IFY — Dashboard
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');

/* ---- Tokens ---- */
:root {
  --bg:               #f0f5ff;
  --surface:          #ffffff;
  --surface-2:        #f8faff;
  --text:             #0f172a;
  --muted:            #64748b;
  --border:           #e2e8f0;
  --primary:          #0d6efd;
  --primary-600:      #0b5ed7;
  --success:          #16a34a;
  --warning:          #d97706;
  --danger:           #dc2626;
  --grad:             linear-gradient(135deg, #0d6efd 0%, #6610f2 100%);
  --card-shadow:      0 4px 16px rgba(15,23,42,0.07);
  --card-shadow-md:   0 8px 28px rgba(15,23,42,0.10);
  --radius:           14px;
  --radius-sm:        9px;
  --t:                180ms ease;
  --max-w:            1200px;
}

body.dark-mode {
  --bg:             #0a0f1a;
  --surface:        #111827;
  --surface-2:      #1a2235;
  --text:           #f1f5f9;
  --muted:          #94a3b8;
  --border:         rgba(255,255,255,0.08);
  --card-shadow:    0 4px 16px rgba(0,0,0,0.45);
  --card-shadow-md: 0 8px 28px rgba(0,0,0,0.60);
}

/* ---- Reset & base ---- */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }

body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-size: 15px;
  line-height: 1.5;
  transition: background var(--t), color var(--t);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ---- Bootstrap dark mode text overrides ---- */
body.dark-mode h1, body.dark-mode h2, body.dark-mode h3,
body.dark-mode h4, body.dark-mode h5, body.dark-mode h6,
body.dark-mode p, body.dark-mode label,
body.dark-mode span:not(.badge):not(.info-status) { color: var(--text) !important; }

body.dark-mode section { background: var(--surface) !important; }

body.dark-mode #loan-history-table thead th,
body.dark-mode #loan-history-table td { background: var(--surface) !important; color: var(--text) !important; }

/* ---- Layout ---- */
#dashboard-container {
  flex: 1;
  max-width: var(--max-w);
  width: 100%;
  margin: 0 auto;
  padding: clamp(1.25rem, 3vw, 2rem);
}

/* ---- Dashboard Header ---- */
.dash-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 1.5rem;
}
.dash-greeting {
  font-size: 0.83rem;
  font-weight: 500;
  color: var(--muted);
  margin-bottom: 3px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.dash-username {
  font-size: clamp(1.3rem, 2.5vw, 1.75rem);
  font-weight: 800;
  letter-spacing: -0.025em;
  color: var(--text);
  margin: 0;
  line-height: 1.15;
}

/* ---- Header right side ---- */
.dash-header-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
  min-width: 260px;
}

/* ---- Loan Limit Widget ---- */
.loan-limit-widget {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
}
.llw-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 7px;
}
.llw-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}
.llw-pct {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text);
}
.llw-track {
  width: 100%;
  height: 7px;
  background: var(--border);
  border-radius: 99px;
  overflow: hidden;
}
.llw-fill {
  height: 100%;
  border-radius: 99px;
  background: var(--success);
  transition: width 0.6s ease, background 0.4s ease;
  width: 0%;
}
.llw-fill.warning { background: var(--warning); }
.llw-fill.danger  { background: var(--danger); }

.llw-bottom {
  display: flex;
  justify-content: space-between;
  margin-top: 5px;
  font-size: 0.72rem;
  color: var(--muted);
}

/* ---- Action buttons ---- */
.dash-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

#apply-loan-button {
  background: var(--grad);
  color: #fff;
  border: none;
  padding: 9px 18px;
  font-size: 0.875rem;
  font-weight: 700;
  font-family: inherit;
  border-radius: var(--radius-sm);
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(13,110,253,0.25);
  transition: transform var(--t), box-shadow var(--t), opacity var(--t);
  white-space: nowrap;
}
#apply-loan-button:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 8px 22px rgba(13,110,253,0.35); }
#apply-loan-button:disabled,
#apply-loan-button.limit-reached {
  background: rgba(100,116,139,0.15);
  color: var(--muted);
  cursor: not-allowed;
  box-shadow: none;
  transform: none;
}

.btn-emi-link {
  padding: 9px 16px;
  font-size: 0.875rem;
  font-weight: 600;
  font-family: inherit;
  border-radius: var(--radius-sm);
  border: 1.5px solid rgba(13,110,253,0.25);
  background: rgba(13,110,253,0.07);
  color: var(--primary);
  text-decoration: none;
  white-space: nowrap;
  transition: background var(--t), border-color var(--t), transform var(--t);
  display: inline-block;
}
.btn-emi-link:hover { background: rgba(13,110,253,0.13); transform: translateY(-1px); }
body.dark-mode .btn-emi-link { color: #60a5fa; border-color: rgba(96,165,250,0.25); background: rgba(96,165,250,0.08); }

/* ---- Stat Tiles ---- */
#loan-stats-container {
  display: flex;
  gap: 1rem;
  margin-bottom: 1.25rem;
}
.stat-tile {
  flex: 1;
  padding: 20px 22px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--card-shadow);
  position: relative;
  overflow: hidden;
  transition: box-shadow var(--t), transform var(--t), background var(--t), border-color var(--t);
}
.stat-tile::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; height: 3px;
  background: var(--grad);
  border-radius: var(--radius) var(--radius) 0 0;
}
@media (hover: hover) {
  .stat-tile:hover { box-shadow: var(--card-shadow-md); transform: translateY(-2px); }
}
.stat-tile-label {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 10px;
}
.stat-tile-value {
  font-size: 1.75rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--text);
  line-height: 1.1;
  margin: 0;
}

/* Active loan detail inside stat tile — full-width info card */
.stat-tile-loan-detail {
  margin-top: 10px;
  font-size: 0.875rem;
  color: var(--text);
}

/* ---- Section Cards ---- */
section {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 22px 24px;
  margin-bottom: 1rem;
  border-radius: var(--radius);
  box-shadow: var(--card-shadow);
  transition: background var(--t), border-color var(--t), box-shadow var(--t);
}

section h2 {
  font-size: 1rem !important;
  font-weight: 700 !important;
  letter-spacing: -0.01em;
  color: var(--text) !important;
  margin: 0 0 16px 0 !important;
  line-height: 1.3;
}

/* ---- Shared key/value styles ---- */
.info-key {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  flex-shrink: 0;
  white-space: nowrap;
}
.info-val {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text);
  text-align: right;
  word-break: break-all;
}
.info-mono {
  font-family: 'SF Mono', 'Fira Code', 'Courier New', monospace;
  font-size: 0.78rem;
  letter-spacing: 0.01em;
}
.info-amount {
  font-weight: 800;
  font-size: 0.95rem;
  color: var(--primary);
}
body.dark-mode .info-amount { color: #60a5fa !important; }

/* ---- Status badges ---- */
.info-status {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: capitalize;
  line-height: 1.6;
}
.info-status.accepted  { background: rgba(22,163,74,0.12);   color: #15803d; }
.info-status.pending   { background: rgba(217,119,6,0.12);   color: #b45309; }
.info-status.rejected  { background: rgba(220,38,38,0.12);   color: #b91c1c; }
.info-status.cancelled { background: rgba(100,116,139,0.12); color: #475569; }
.info-status.completed { background: rgba(13,110,253,0.12);  color: #0b5ed7; }
body.dark-mode .info-status.accepted  { background: rgba(22,163,74,0.18);   color: #4ade80; }
body.dark-mode .info-status.pending   { background: rgba(217,119,6,0.18);   color: #fbbf24; }
body.dark-mode .info-status.rejected  { background: rgba(220,38,38,0.18);   color: #f87171; }
body.dark-mode .info-status.cancelled { background: rgba(100,116,139,0.18); color: #94a3b8; }
body.dark-mode .info-status.completed { background: rgba(13,110,253,0.18);  color: #60a5fa; }

/* ---- Loan Info Card (Active Loans tile) ---- */
.loan-info-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 9px;
}
.loan-info-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.loan-info-row + .loan-info-row {
  padding-top: 9px;
  border-top: 1px solid var(--border);
}

/* ---- Payment Card ---- */
.payment-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--warning);
  border-radius: var(--radius-sm);
  padding: 14px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 10px;
  transition: background var(--t), border-color var(--t);
}
.payment-card-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
  min-width: 0;
}
.payment-meta-row {
  display: flex;
  align-items: center;
  gap: 12px;
}
.payment-meta-row .info-key { min-width: 86px; }
.payment-type { font-size: 0.78rem; color: var(--muted); font-style: italic; }
.payment-card-action { flex-shrink: 0; }

.pay-now-btn {
  padding: 8px 16px;
  font-size: 0.83rem;
  font-weight: 700;
  font-family: inherit;
  border-radius: var(--radius-sm);
  border: none;
  background: var(--grad);
  color: #fff;
  cursor: pointer;
  white-space: nowrap;
  box-shadow: 0 4px 12px rgba(13,110,253,0.22);
  transition: transform var(--t), box-shadow var(--t);
}
.pay-now-btn:hover { transform: translateY(-2px); box-shadow: 0 8px 20px rgba(13,110,253,0.3); }

/* ---- Loan History Table ---- */
.table-responsive { overflow-x: auto; border-radius: var(--radius-sm); }

#loan-history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
  font-family: inherit;
}
#loan-history-table thead tr {
  background: var(--surface-2);
  border-bottom: 2px solid var(--border);
}
#loan-history-table thead th {
  padding: 10px 14px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  text-align: left;
  white-space: nowrap;
}
#loan-history-table td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  vertical-align: middle;
  background: var(--surface);
  font-size: 0.875rem;
}
#loan-history-table tbody tr:last-child td { border-bottom: none; }
#loan-history-table tbody tr:hover td { background: rgba(13,110,253,0.03); }
body.dark-mode #loan-history-table tbody tr:hover td { background: rgba(255,255,255,0.04) !important; }

.loan-id-cell {
  font-family: 'SF Mono', 'Fira Code', 'Courier New', monospace;
  font-size: 0.78rem;
  color: var(--muted);
}

/* Cancel button */
.cancel-loan-btn {
  padding: 5px 12px;
  font-size: 0.78rem;
  font-weight: 600;
  font-family: inherit;
  border-radius: 6px;
  border: 1.5px solid rgba(220,38,38,0.25);
  background: rgba(220,38,38,0.07);
  color: #b91c1c;
  cursor: pointer;
  transition: background var(--t), transform var(--t);
}
.cancel-loan-btn:hover { background: rgba(220,38,38,0.14); transform: translateY(-1px); }
body.dark-mode .cancel-loan-btn { color: #f87171; background: rgba(220,38,38,0.12); }

/* Empty state */
.dash-empty { font-size: 0.875rem; color: var(--muted); padding: 8px 0; }

/* ---- Logout ---- */
#logout-btn {
  display: block;
  margin: 1.75rem auto 0;
  padding: 9px 22px;
  font-size: 0.875rem;
  font-weight: 600;
  font-family: inherit;
  border-radius: var(--radius-sm);
  border: 1.5px solid rgba(220,38,38,0.25);
  background: rgba(220,38,38,0.07);
  color: #b91c1c;
  cursor: pointer;
  transition: background var(--t), transform var(--t);
}
#logout-btn:hover { background: rgba(220,38,38,0.14); transform: translateY(-1px); }
body.dark-mode #logout-btn { color: #f87171; background: rgba(220,38,38,0.12); }

/* ---- Footer ---- */
footer {
  background: var(--surface);
  color: var(--muted);
  text-align: center;
  padding: 20px 16px;
  font-size: 0.83rem;
  margin-top: 28px;
  border-top: 1px solid var(--border);
  transition: background var(--t), border-color var(--t);
}

/* ---- Responsive ---- */
@media (min-width: 992px) {
  #loan-stats-container { flex-direction: row; }
}
@media (max-width: 700px) {
  #loan-stats-container { flex-direction: column; gap: 0.75rem; }
  section { padding: 16px 18px; }
  .payment-card { flex-direction: column; align-items: flex-start; }
}

/* Card-style table on mobile */
@media (max-width: 640px) {
  .table-responsive { border-radius: var(--radius-sm); }
  #loan-history-table thead { display: none; }
  #loan-history-table,
  #loan-history-table tbody,
  #loan-history-table tr,
  #loan-history-table td { display: block; width: 100%; }
  #loan-history-table tr {
    border-bottom: 1px solid var(--border);
    padding: 12px 14px;
  }
  #loan-history-table tr:last-child { border-bottom: none; }
  #loan-history-table td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 5px 0;
    border-bottom: none;
    font-size: 0.87rem;
  }
  #loan-history-table td::before {
    content: attr(data-label);
    font-weight: 700;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
    flex-shrink: 0;
    margin-right: 12px;
  }
}

@media (max-width: 480px) {
  .dash-username { font-size: 1.15rem; }
}

/* ---- Motion ---- */
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
