/* Loan Desk CRM — design system, ported 1:1 from the prototype's
   embedded <style> block (techchase.in/loandesk/loandesk.html). */

:root {
  --bg: #F5F6F8;
  --surface: #FFFFFF;
  --surface-alt: #FAFBFC;
  --border: #E3E5E9;
  --border-strong: #CBCED4;
  --text: #1E2230;
  --text-muted: #6B7280;
  --text-faint: #9AA0AC;
  --primary: #2F6FED;
  --primary-dark: #1D4FBF;
  --primary-light: #EAF1FF;
  --success: #2E9E5B;
  --success-light: #E8F7EE;
  --warning: #C9880F;
  --warning-light: #FCF3DF;
  --danger: #D64545;
  --danger-light: #FBEAEA;
  --grey-50: #FAFAFB;
  --grey-100: #F2F3F5;
  --grey-200: #E5E7EB;
  --grey-300: #D1D5DB;
  --grey-500: #6B7280;
  --grey-700: #374151;
  --grey-900: #111827;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --sp-8: 32px;
  --sp-10: 40px;
  --shadow-sm: 0 1px 2px rgba(16,24,40,.06);
  --shadow-md: 0 4px 12px rgba(16,24,40,.08);
  --shadow-lg: 0 12px 32px rgba(16,24,40,.14);
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Inter, Roboto, sans-serif;
  --sidebar-w: 232px;
  --topbar-h: 60px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
a.link { color: var(--primary); font-weight: 600; }
a.link:hover { text-decoration: underline; }
h1, h2, h3, p { margin: 0; }
img { max-width: 100%; }

/* ---------------- App shell ---------------- */
#app { display: flex; min-height: 100vh; }

#sidebar {
  width: var(--sidebar-w);
  background: var(--grey-900);
  color: #fff;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 20;
}
.sidebar-brand { display: flex; align-items: center; gap: 10px; padding: 18px 20px; }
.sidebar-brand .logo-mark {
  width: 32px; height: 32px; border-radius: var(--radius-sm);
  background: var(--primary); display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px;
}
.sidebar-brand .brand-name { font-weight: 700; font-size: 14px; }
.sidebar-brand .brand-sub { font-size: 10px; color: #9AA0AC; letter-spacing: .04em; }

.sidebar-nav { flex: 1; overflow-y: auto; padding: 8px 0; }
.side-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 20px; font-size: 13px; color: #C6C9D2; cursor: pointer;
  border-left: 3px solid transparent;
}
.side-item:hover { background: rgba(255,255,255,.05); color: #fff; }
.side-item.active { background: rgba(47,111,237,.16); color: #fff; border-left-color: var(--primary); }
.side-item .ic { width: 18px; text-align: center; opacity: .9; }
.side-item .count {
  margin-left: auto; background: var(--primary); color: #fff; font-size: 10px;
  border-radius: 999px; padding: 1px 7px; font-weight: 700;
}
.sidebar-section-label {
  padding: 14px 20px 6px; font-size: 10px; text-transform: uppercase;
  letter-spacing: .06em; color: #6B7280;
}
.sidebar-foot { padding: 14px 20px; border-top: 1px solid rgba(255,255,255,.08); }
.role-pill {
  display: inline-block; font-size: 10px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .04em; color: #C6C9D2; background: rgba(255,255,255,.08);
  padding: 3px 8px; border-radius: 999px;
}

#main { flex: 1; margin-left: var(--sidebar-w); display: flex; flex-direction: column; min-height: 100vh; }

#topbar {
  height: var(--topbar-h); background: var(--surface); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; padding: 0 24px;
  position: sticky; top: 0; z-index: 10;
}
.search-mini {
  display: flex; align-items: center; gap: 8px; background: var(--grey-100);
  border-radius: var(--radius-md); padding: 7px 12px; width: 320px; max-width: 40vw;
}
.search-mini .sic { color: var(--text-faint); font-size: 13px; }
.search-mini input {
  border: none; background: transparent; outline: none; font-size: 13px; width: 100%; color: var(--text);
}
.topbar-actions { display: flex; align-items: center; gap: 14px; }
.icon-btn {
  width: 34px; height: 34px; border-radius: 999px; display: flex; align-items: center; justify-content: center;
  background: var(--grey-100); cursor: pointer; font-size: 15px; position: relative; border: none;
}
.icon-btn .dot-badge {
  position: absolute; top: 4px; right: 4px; width: 8px; height: 8px; border-radius: 999px; background: var(--danger);
}
.profile-chip { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.profile-chip .avatar {
  width: 32px; height: 32px; border-radius: 999px; background: var(--primary-light); color: var(--primary-dark);
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 12px;
}
.profile-chip .pname { font-size: 12.5px; font-weight: 600; line-height: 1.2; }
.profile-chip .prole { font-size: 10.5px; color: var(--text-faint); }

#viewport { padding: 24px 28px 60px; flex: 1; }

/* ---------------- Page structure ---------------- */
.breadcrumb { font-size: 12px; color: var(--text-faint); margin-bottom: 6px; display: flex; align-items: center; gap: 6px; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 20px; gap: 16px; flex-wrap: wrap; }
.page-title { font-size: 21px; font-weight: 700; letter-spacing: -.01em; }
.page-desc { font-size: 12.5px; color: var(--text-muted); margin-top: 4px; }
.page-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

/* ---------------- Buttons ---------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 16px; border-radius: var(--radius-md); border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text); font-size: 13px; font-weight: 600;
  cursor: pointer; line-height: 1.2;
}
.btn:hover { background: var(--grey-50); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--grey-100); }
.btn.danger { background: var(--danger-light); border-color: var(--danger-light); color: var(--danger); }
.btn.danger:hover { background: #f6d5d5; }
.btn.sm { padding: 5px 11px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------------- Cards / form cards ---------------- */
.card, .form-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 22px; margin-bottom: 18px;
}
.two-col { display: grid; grid-template-columns: 1.4fr 1fr; gap: 18px; align-items: start; }
.section-title { font-size: 14px; font-weight: 700; margin: 0 0 14px; display: flex; align-items: center; gap: 8px; color: var(--text); }
.section-title .n {
  width: 20px; height: 20px; border-radius: 50%; background: var(--grey-200); color: var(--grey-700);
  font-size: 11px; display: flex; align-items: center; justify-content: center; font-weight: 700;
}
.sep { border: none; border-top: 1px solid var(--border); margin: 12px 0; }
.empty-ph { text-align: center; color: var(--text-faint); font-size: 12.5px; padding: 28px 0; }

/* ---------------- Forms ---------------- */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12px; font-weight: 600; color: var(--grey-700); margin-bottom: 6px; }
.field .hint, .hint { font-size: 11px; color: var(--text-faint); margin-top: 4px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.field-row.c3 { grid-template-columns: 1fr 1fr 1fr; }
.input, select.input, textarea.input {
  width: 100%; border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  padding: 9px 11px; font-size: 13px; font-family: var(--font); color: var(--text); background: var(--surface);
  outline: none;
}
.input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }
textarea.input { resize: vertical; }

/* ---------------- Tabs / pills / filter bar ---------------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 18px; }
.tab { padding: 10px 4px; margin-right: 20px; font-size: 13px; font-weight: 600; color: var(--text-muted); border-bottom: 2px solid transparent; cursor: pointer; }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

.pills { display: flex; gap: 8px; margin-bottom: 18px; flex-wrap: wrap; }
.pill {
  padding: 7px 14px; border-radius: 999px; font-size: 12.5px; font-weight: 600;
  background: var(--grey-100); color: var(--text-muted); cursor: pointer; border: 1px solid transparent;
}
.pill.active { background: var(--primary-light); color: var(--primary-dark); border-color: var(--primary); }

.filter-bar { display: flex; gap: 10px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.filter-bar .search-mini { background: var(--surface); border: 1px solid var(--border-strong); width: 260px; }
.filter-bar select.input { width: auto; }

/* ---------------- Tables ---------------- */
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; margin-bottom: 18px; }
table { width: 100%; border-collapse: collapse; }
thead th {
  text-align: left; font-size: 10.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-faint);
  padding: 12px 16px; background: var(--surface-alt); border-bottom: 1px solid var(--border); font-weight: 700;
}
tbody td { padding: 13px 16px; font-size: 13px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr.row-click { cursor: pointer; }
tbody tr.row-click:hover { background: var(--surface-alt); }
.cell-name { font-weight: 600; }
.cell-sub { font-size: 11.5px; color: var(--text-faint); }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; opacity: 0; }
tbody tr:hover .row-actions { opacity: 1; }
.tbl-icon {
  width: 28px; height: 28px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface); display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer; font-size: 13px; color: var(--text-muted);
}
.tbl-icon:hover { background: var(--grey-100); }
.avatar {
  width: 30px; height: 30px; border-radius: 999px; background: var(--primary-light); color: var(--primary-dark);
  display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: 11px;
}

/* ---------------- Badges ---------------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px; font-size: 11.5px; font-weight: 600;
  padding: 4px 10px; border-radius: 999px; background: var(--grey-100); color: var(--grey-700);
}
.badge .dot { width: 7px; height: 7px; border-radius: 999px; display: inline-block; }
.badge.approved { background: var(--success-light); color: var(--success); }
.badge.pending { background: var(--warning-light); color: var(--warning); }
.badge.rejected { background: var(--danger-light); color: var(--danger); }
.badge.role { background: var(--primary-light); color: var(--primary-dark); }

/* ---------------- Stat grid (dashboard) ---------------- */
.stat-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 14px; margin-bottom: 22px; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 16px; cursor: pointer; }
.stat-card:hover { border-color: var(--border-strong); }
.stat-label { font-size: 11px; color: var(--text-muted); display: flex; align-items: center; justify-content: space-between; }
.stat-value { font-size: 24px; font-weight: 700; margin: 8px 0 4px; }
.stat-delta { font-size: 11px; color: var(--text-faint); }

/* ---------------- List row (dashboard feeds) ---------------- */
.list-row { display: flex; align-items: flex-start; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.list-row:last-child { border-bottom: none; }
.list-icon {
  width: 30px; height: 30px; border-radius: 999px; background: var(--grey-100); display: flex;
  align-items: center; justify-content: center; font-size: 13px; flex-shrink: 0;
}
.list-row .cell-name { font-size: 12.5px; }

/* ---------------- Timeline ---------------- */
.timeline { position: relative; padding-left: 22px; }
.timeline::before { content: ''; position: absolute; left: 6px; top: 4px; bottom: 4px; width: 2px; background: var(--border); }
.tl-item { position: relative; padding-bottom: 18px; }
.tl-item:last-child { padding-bottom: 0; }
.tl-dot {
  position: absolute; left: -22px; top: 2px; width: 14px; height: 14px; border-radius: 999px;
  background: var(--grey-200); color: transparent; font-size: 8px; display: flex; align-items: center; justify-content: center;
  border: 2px solid var(--surface);
}
.tl-item.done .tl-dot { background: var(--primary); }
.tl-title { font-size: 13px; font-weight: 600; }
.tl-meta { font-size: 11px; color: var(--text-faint); margin-top: 2px; }

/* ---------------- Kanban ---------------- */
.kanban-scroll { overflow-x: auto; padding-bottom: 12px; }
.kanban-board { display: flex; gap: 14px; min-width: max-content; }
.kanban-col { width: 260px; background: var(--surface-alt); border-radius: var(--radius-lg); border: 1px solid var(--border); padding: 10px; flex-shrink: 0; }
.kanban-col-head { font-size: 12px; font-weight: 700; padding: 6px 6px 10px; display: flex; align-items: center; gap: 6px; color: var(--grey-700); }
.kanban-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md);
  padding: 12px; margin-bottom: 10px; box-shadow: var(--shadow-sm);
}
.kc-name { font-size: 12.5px; font-weight: 700; margin-bottom: 2px; }
.kc-meta { font-size: 11px; color: var(--text-faint); margin-bottom: 8px; }
.kc-amount { font-size: 12.5px; font-weight: 700; color: var(--primary-dark); }
.kc-foot { display: flex; align-items: center; justify-content: space-between; margin-top: 8px; }

/* ---------------- Modal / overlay ---------------- */
.overlay-bg { display: none; position: fixed; inset: 0; background: rgba(17,24,39,.45); z-index: 40; }
.overlay-bg.open { display: block; }
.modal {
  display: none; position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: 480px; max-width: calc(100vw - 32px); max-height: calc(100vh - 64px); overflow-y: auto;
  background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); z-index: 41;
}
.modal.open { display: block; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px; border-bottom: 1px solid var(--border); }
.modal-body { padding: 20px; }
.modal-foot { padding: 16px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }
.close-x { background: none; border: none; font-size: 16px; cursor: pointer; color: var(--text-faint); }

/* ---------------- Flash messages ---------------- */
.flash { padding: 12px 16px; border-radius: var(--radius-md); font-size: 13px; margin-bottom: 16px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.flash.success { background: var(--success-light); color: var(--success); }
.flash.error { background: var(--danger-light); color: var(--danger); }
.flash.warning { background: var(--warning-light); color: var(--warning); }
.flash.info { background: var(--primary-light); color: var(--primary-dark); }
.flash .flash-close { cursor: pointer; background: none; border: none; font-size: 13px; color: inherit; opacity: .7; }

/* ---------------- Misc ---------------- */
.tag-swatch { display: flex; align-items: center; gap: 8px; padding: 10px; border: 1px solid var(--border); border-radius: var(--radius-md); font-size: 12.5px; }
.kbd-note { font-size: 11px; background: var(--grey-100); padding: 2px 6px; border-radius: 4px; font-family: monospace; }

/* ---------------- Responsive ---------------- */
@media (max-width: 980px) {
  .stat-grid { grid-template-columns: repeat(3, 1fr); }
  .two-col { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  #sidebar { transform: translateX(-100%); transition: transform .2s ease; }
  #sidebar.mobile-open { transform: translateX(0); }
  #main { margin-left: 0; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .field-row, .field-row.c3 { grid-template-columns: 1fr; }
  #viewport { padding: 16px; }
}
