:root {
  --primary: #0F766E;
  --accent: #D97706;
  --bg: #F3F6F6;
  --surface: #FFFFFF;
  --ink: #10201F;
  --muted: #5B6B6A;
  --line: #DCE4E3;
  --danger: #B91C1C;
  --ok: #15803D;
  --font: 'Plus Jakarta Sans', system-ui, sans-serif;
  --r: 14px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: var(--font); background: var(--bg); color: var(--ink); line-height: 1.45; font-size: 15px; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 1.45rem; }
h2 { font-size: 1.12rem; }
h3 { font-size: .95rem; }
.muted { color: var(--muted); font-size: .84rem; margin: 2px 0 0; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.error { color: var(--danger); font-size: .9rem; margin: 0; }
.num { font-variant-numeric: tabular-nums; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
#view:focus, #view:focus-visible { outline: none; }

.logo { width: 46px; height: 46px; flex: none; }
.logo svg, .logo img { width: 100%; height: 100%; border-radius: 12px; object-fit: cover; display: block; }
.logo-sm { width: 34px; height: 34px; }

.auth { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.auth-card { width: 100%; max-width: 410px; background: var(--surface); border: 1px solid var(--line); border-radius: 20px; padding: 28px; }
.brand { display: flex; gap: 14px; align-items: center; margin-bottom: 24px; }
.brand h1 { font-size: 1.6rem; letter-spacing: -.01em; }
.auth-card.is-busy input { background: #F7FAFA; }
.auth-card.is-leaving { animation: authOut .22s ease-in forwards; }
.auth-card.is-error { animation: cardShake .28s ease; }
#login-submit { min-width: 132px; }
.btn-spinner { display: none; width: 14px; height: 14px; border: 2px solid rgba(255,255,255,.45); border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite; }
.btn.is-busy .btn-spinner { display: inline-block; }
.btn.is-success { background: var(--ok); border-color: var(--ok); }
.login-transition { position: fixed; inset: 0; z-index: 90; display: grid; place-items: center; padding: 24px; background: var(--primary); color: #fff; opacity: 0; visibility: hidden; transition: opacity .2s ease, visibility .2s ease; }
.login-transition.show { opacity: 1; visibility: visible; }
.login-transition-card { width: 100%; max-width: 360px; text-align: center; }
.login-transition-card .logo { width: 74px; height: 74px; margin: 0 auto 16px; padding: 8px; border-radius: 50%; background: rgba(255,255,255,.14); }
.login-transition-card .logo svg, .login-transition-card .logo img { border-radius: 50%; }
.login-transition-card h2 { font-size: 1.5rem; margin-bottom: 6px; }
.login-transition-card p { margin: 0; color: rgba(255,255,255,.82); }
.login-progress { width: 180px; max-width: 80%; height: 4px; margin: 18px auto 0; border-radius: 999px; background: rgba(255,255,255,.22); overflow: hidden; }
.login-progress span { display: block; width: 40%; height: 100%; border-radius: inherit; background: #fff; animation: loginProgress 1.1s ease-in-out infinite; }
#shell.is-entering { animation: shellIn .3s ease-out both; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes authOut { to { opacity: 0; transform: scale(.97) translateY(-8px); } }
@keyframes cardShake { 25% { transform: translateX(-5px); } 50% { transform: translateX(5px); } 75% { transform: translateX(-3px); } }
@keyframes loginProgress { 0% { transform: translateX(-100%); } 100% { transform: translateX(250%); } }
@keyframes shellIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes bannerIn { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: translateY(0); } }
@keyframes viewIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }
@keyframes panelIn { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }
@keyframes tabPulse { 0% { transform: scale(1); } 45% { transform: scale(.96); } 100% { transform: scale(1); } }

.topbar { background: var(--surface); border-bottom: 1px solid var(--line); padding: 10px 16px; display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.top-left, .top-center, .top-right { display: flex; align-items: center; gap: 10px; min-width: 0; }
.top-left { flex: 0 1 auto; }
.top-center { display: none; flex: 1 1 auto; }
.top-right { flex: 0 0 auto; }
.top-left .btn, .top-right .btn, .top-right .pill { flex: 0 0 auto; white-space: nowrap; }
.who { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
#nav-company { display: block; max-width: min(28vw, 320px); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { background: #EEF3F2; color: var(--muted); border-radius: 999px; padding: 1px 9px; font-size: .75rem; width: fit-content; }
.setup-state-icon { width: 16px; height: 16px; vertical-align: -3px; color: var(--muted); flex: 0 0 16px; }
.pill { border-radius: 999px; padding: 4px 10px; font-size: .8rem; font-weight: 600; }
.pill.warn { background: #FEF3C7; color: #92400E; }
.offline-banner { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 16px; background: #FFFBEB; border-bottom: 1px solid #FDE68A; color: #92400E; font-size: .85rem; font-weight: 600; }
.offline-banner:not(.hidden) { animation: bannerIn 150ms ease-out; }
.offline-banner-text { flex: 1 1 auto; min-width: 0; }
.offline-dot { width: 9px; height: 9px; border-radius: 999px; background: #D97706; flex: 0 0 auto; box-shadow: 0 0 0 3px rgba(217, 119, 6, .16); }
.offline-banner-close { flex: 0 0 auto; display: inline-flex; align-items: center; justify-content: center; width: 26px; height: 26px; padding: 0; border: 1px solid #FCD34D; border-radius: 8px; background: rgba(255,255,255,.55); color: inherit; cursor: pointer; transition: background 120ms ease, transform 120ms ease; }
.offline-banner-close:hover { background: rgba(255,255,255,.9); }
.offline-banner-close:active { transform: scale(.94); }
.offline-banner-close svg { width: 14px; height: 14px; }
html[data-theme="dark"] .offline-banner { background: #2A210C; border-bottom-color: #7C5F16; color: #FDE68A; }
html[data-theme="dark"] .offline-dot { background: #FBBF24; box-shadow: 0 0 0 3px rgba(251, 191, 36, .18); }
html[data-theme="dark"] .offline-banner-close { border-color: #7C5F16; background: rgba(0,0,0,.24); }
html[data-theme="dark"] .offline-banner-close:hover { background: rgba(0,0,0,.42); }

/* ---- Desktop nav toggle and global search ---- */
.nav-toggle.btn { display: none; }
#nav-toggle .nav-icon-collapsed { display: none; }
html.nav-collapsed #nav-toggle .nav-icon-expanded { display: none; }
html.nav-collapsed #nav-toggle .nav-icon-collapsed { display: inline-flex; }
.global-search { display: none; position: relative; width: 100%; min-width: 0; }
.global-search-field { display: flex; align-items: center; gap: 8px; height: 36px; width: 100%; min-width: 0; padding: 0 8px; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; }
.global-search-field > svg { width: 16px; height: 16px; flex: none; color: var(--muted); }
.global-search-field input { flex: 1; min-width: 0; border: 0; background: transparent; padding: 6px 0; font-size: .88rem; }
.global-search-field input:focus { outline: none; }
.global-search-field input::-webkit-search-cancel-button { display: none; }
.global-search-clear { display: inline-flex; align-items: center; justify-content: center; border: 0; background: transparent; color: var(--muted); padding: 4px; cursor: pointer; line-height: 0; }
.global-search-clear svg { width: 14px; height: 14px; }
.global-search-results { position: absolute; top: calc(100% + 6px); right: 0; width: min(380px, 80vw); max-height: 420px; overflow-y: auto; padding: 6px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 14px 34px rgba(16, 32, 31, .16); z-index: 40; }
.gs-group { padding: 8px 10px 4px; font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.gs-item { width: 100%; display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 0; border-radius: 9px; background: transparent; color: var(--ink); font: inherit; text-align: left; cursor: pointer; }
.gs-item:hover, .gs-item.active { background: color-mix(in srgb, var(--primary) 10%, var(--surface)); }
.gs-badge { flex: none; }
.gs-text { display: flex; flex-direction: column; min-width: 0; }
.gs-text strong, .gs-text small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gs-text strong { font-size: .88rem; }
.gs-text small { font-size: .76rem; color: var(--muted); }
.gs-empty, .gs-status { padding: 12px; font-size: .84rem; color: var(--muted); }
.search-detail { display: grid; gap: 8px; }
.search-detail-row { display: grid; grid-template-columns: minmax(110px, 34%) 1fr; gap: 10px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); font-size: .86rem; }
.search-detail-row span { color: var(--muted); }
.search-detail-row strong { font-weight: 600; overflow-wrap: anywhere; }
html[data-theme="dark"] .global-search-field { background: var(--surface); }
html[data-theme="dark"] .global-search-results { box-shadow: 0 14px 34px rgba(0, 0, 0, .45); }

@media (min-width: 900px) {
  .topbar { flex-wrap: nowrap; }
  .nav-toggle.btn { display: inline-flex; }
  .top-center { display: flex; justify-content: center; }
  .global-search { display: block; flex: 1 1 auto; }
  .btn { padding: 8px 14px; }
  .btn-sm { padding: 4px 10px; font-size: .82rem; }
  .nav-group { margin: 6px 0; }
  .nav-group > summary { list-style: none; cursor: pointer; padding: 6px 8px; border-radius: 8px; font-size: .78rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
  .nav-group > summary::-webkit-details-marker { display: none; }
  .nav-group-items { display: grid; gap: 4px; margin-top: 4px; }
  .nav-group .tab { width: 100%; }
}

.tabs { display: flex; gap: 8px; overflow-x: auto; padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--line); scrollbar-width: none; position: sticky; top: 0; z-index: 19; }
.tabs::-webkit-scrollbar { width: 0; height: 0; display: none; }
.tab { flex: none; display: inline-flex; align-items: center; justify-content: flex-start; gap: 8px; white-space: nowrap; border: 1px solid var(--line); background: transparent; color: var(--ink); padding: 7px 13px; border-radius: 999px; font: inherit; font-weight: 600; font-size: .88rem; cursor: pointer; transition: background 120ms ease, border-color 120ms ease, color 120ms ease, transform 120ms ease; }
.tab:hover { background: color-mix(in srgb, var(--primary) 8%, var(--surface)); }
.tab[aria-current="page"] { background: var(--primary); border-color: var(--primary); color: #fff; }
.tab.tab-pressed { animation: tabPulse 150ms ease-out; }
.tab span { max-width: 170px; opacity: 1; overflow: hidden; transition: max-width 140ms ease, opacity 110ms ease; }
.view-swap { animation: viewIn 140ms ease-out; }

.container { max-width: 1100px; margin: 0 auto; padding: 18px 16px 80px; }
@media (min-width: 900px) {
  .container { max-width: none; width: 100%; margin: 0; padding: 16px 20px 60px; }
  .card { padding: 14px 16px; }
}
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 18px; margin-bottom: 16px; }
.card > h2 + .muted { margin-bottom: 12px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.between { justify-content: space-between; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }

.figures { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin: 12px 0 14px; }
.figures > div { min-width: 0; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); }
.figures b { display: block; font-size: 1.05rem; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.figures span { display: block; margin-top: 4px; font-size: .78rem; color: var(--muted); line-height: 1.35; }
h3 + .figures { margin-top: 8px; }
.figures + h3 { margin-top: 14px; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 14px 16px; min-width: 0; }
.kpi .v { font-size: 1.35rem; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.kpi.alert { border-color: #F3C7C7; background: #FEF5F5; }
.kpi.alert .v { color: var(--danger); }

label { display: flex; flex-direction: column; gap: 5px; font-size: .86rem; font-weight: 600; }
input, select, textarea { font: inherit; font-weight: 400; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--ink); min-width: 0; }
input[type=checkbox] { width: 18px; height: 18px; padding: 0; accent-color: var(--primary); }
input[type=color] { padding: 2px; height: 42px; }

.btn { font: inherit; font-weight: 600; border: 1px solid transparent; border-radius: 10px; padding: 10px 16px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.btn svg { width: 1em; height: 1em; flex: none; }
.cust-photo svg { width: 44%; height: 44%; color: var(--muted); }
.tab svg { width: 1em; height: 1em; flex: none; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-accent { background: var(--accent); color: #fff; }
.btn-ghost { background: #fff; color: var(--ink); border-color: var(--line); }
.btn-danger { background: #fff; color: var(--danger); border-color: #F3C7C7; }
.btn-sm { padding: 6px 12px; font-size: .86rem; }
.btn[disabled] { opacity: .55; cursor: wait; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: 10px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: .8rem; white-space: nowrap; }
td.r, th.r { text-align: right; font-variant-numeric: tabular-nums; }
tr.click:hover { background: #F6FAF9; cursor: pointer; }

.tag { display: inline-block; border-radius: 999px; padding: 2px 9px; font-size: .75rem; font-weight: 600; background: #EEF3F2; color: var(--muted); }
.tag.good, .tag.active, .tag.completed { background: #DCFCE7; color: var(--ok); }
.tag.slow_payer, .tag.pending { background: #FEF3C7; color: #92400E; }
.tag.defaulter, .tag.defaulted, .tag.rejected, .tag.written_off, .tag.suspended { background: #FEE2E2; color: var(--danger); }

.loan { border: 1px solid var(--line); border-radius: var(--r); padding: 14px; margin-bottom: 12px; background: var(--surface); }
.loan .figures { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin: 10px 0 12px; }
.loan .figures > div { padding: 8px 10px; background: transparent; }
.loan .figures b { font-size: 1rem; }
.loan .figures span { font-size: .74rem; }
.loan .figures .bad b { color: var(--danger); }
.loan-actions { margin-top: 12px; padding-top: 10px; border-top: 1px dashed var(--line); }
.payrow { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.payrow input[type=number] { width: 120px; }
.payrow input.txn { width: 140px; }
.zone { margin: 18px 0 8px; font-weight: 700; font-size: .95rem; color: var(--muted); }
.search { width: 100%; padding: 13px 14px; font-size: 1rem; margin-bottom: 12px; }

.backdrop { position: fixed; inset: 0; background: rgba(16, 32, 31, .55); display: grid; place-items: center; padding: 14px; z-index: 50; }
.panel { background: var(--surface); border-radius: 18px; width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto; padding: 22px; }
.panel.wide { max-width: 860px; }
.toggles { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 8px; }
.toggle { display: flex; flex-direction: row; align-items: center; gap: 10px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; font-weight: 600; cursor: pointer; transition: background 120ms ease, border-color 120ms ease, transform 120ms ease; }
.toggle:active { transform: scale(.99); }
.toggle.is-on { border-color: var(--primary); background: color-mix(in srgb, var(--primary) 9%, var(--surface)); }
.toggle small { font-weight: 400; color: var(--muted); display: block; }
.loan-type-panel { animation: panelIn 140ms ease-out; }
.register-card { max-width: 1040px; }
.loan-type-note { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: var(--bg); margin-top: 8px; }
hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }

.toast { position: fixed; left: 50%; bottom: 20px; transform: translate(-50%, 30px); background: var(--ink); color: #fff; padding: 11px 18px; border: 1px solid transparent; border-radius: 12px; font-size: .92rem; line-height: 1.35; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 60; max-width: 92vw; overflow-wrap: anywhere; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.bad { background: var(--danger); }
.dev-credit { position: fixed; right: 10px; bottom: 6px; z-index: 10; font-size: .62rem; letter-spacing: .01em; color: var(--muted); opacity: .72; pointer-events: none; }
.empty { text-align: center; color: var(--muted); padding: 34px 12px; }
.spinner { text-align: center; color: var(--muted); padding: 40px 0; }

@media (max-width: 640px) {
  .container { padding: 14px 12px 80px; }
  .card { padding: 14px; }
  /* Ensure touch targets are at least 44px on mobile */
  .btn, .tab, button { min-height: 44px; }
  .btn-sm { min-height: 36px; padding: 6px 12px; }
  input, select, textarea { min-height: 44px; font-size: 16px; }
}
/* ---- Layout: sidebar on desktop ---- */
.layout { display: block; }
@media (min-width: 900px) {
  .layout { display: grid; grid-template-columns: 210px 1fr; gap: 0; min-height: calc(100vh - 56px); }
  .tabs { flex-direction: column; position: static; border-bottom: 0; border-right: 1px solid var(--line); padding: 12px 10px; gap: 4px; overflow-x: hidden; overflow-y: auto; overscroll-behavior: contain; scrollbar-width: none; -ms-overflow-style: none; background: var(--surface); }
  .tab { width: 100%; flex: none; text-align: left; border-radius: 10px; }
  .nav-foot { position: sticky; bottom: 0; z-index: 1; flex: none; margin-top: auto; padding: 12px 0; background: var(--surface); }
  .container { max-width: none; width: 100%; margin: 0; padding: 16px 24px 60px; }
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .kpis.kpis-8 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
/* ---- Mobile text sizing for tables ---- */
@media (max-width: 640px) {
  table { font-size: .78rem; }
  th, td { padding: 6px 6px; }
  .kpi .v { font-size: 1.15rem; }
  .muted { font-size: .8rem; }
}
/* ---- Cashbook KPI grid: 8 cards ---- */
.kpis-8 { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
/* ---- Styled file inputs ---- */
input[type=file] { display: none; }
.pay-details { margin-top: 12px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px; background: #F8FBFA; }
.file-btn { display: inline-flex; align-items: center; gap: 8px; padding: 10px 14px; border: 1px dashed var(--line); border-radius: 10px; background: #F8FBFA; cursor: pointer; font-weight: 600; font-size: .88rem; color: var(--muted); }
.file-btn:hover { border-color: var(--primary); color: var(--primary); }
.img-preview { margin-top: 8px; max-width: 100%; max-height: 160px; border-radius: 10px; border: 1px solid var(--line); object-fit: cover; display: none; }
.img-preview.show { display: block; }
/* ---- Customer card with photo ---- */
.cust-card { display: flex; gap: 12px; align-items: flex-start; }
.cust-photo { width: 52px; height: 52px; border-radius: 10px; object-fit: cover; background: #EEF3F2; flex: none; display: grid; place-items: center; color: var(--muted); font-size: 1.2rem; }
.cust-photo img { width: 100%; height: 100%; border-radius: 10px; object-fit: cover; }
/* ---- Modal detail tabs ---- */
.detail-tabs { display: flex; gap: 6px; margin-bottom: 12px; flex-wrap: wrap; }
.detail-tabs button { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 6px 12px; font: inherit; font-size: .82rem; font-weight: 600; cursor: pointer; }
.detail-tabs button.active { background: var(--primary); color: #fff; border-color: var(--primary); }
/* ---- Handover detail ---- */
.handover-detail { font-size: .82rem; color: var(--muted); margin-top: 4px; }
/* ---- Agent receipts ---- */
.agent-group { border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); margin-bottom: 12px; overflow: hidden; }
.agent-group > summary { list-style: none; cursor: pointer; padding: 14px 16px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.agent-group > summary::-webkit-details-marker { display: none; }
.agent-group > summary::after { content: '▾'; color: var(--muted); font-size: 1rem; }
.agent-group:not([open]) > summary::after { content: '▸'; }
.agent-summary { display: flex; flex: 1; align-items: center; justify-content: space-between; gap: 12px; min-width: 0; }
.agent-summary strong { display: inline-flex; align-items: center; gap: 6px; }
.agent-total { text-align: right; white-space: nowrap; }
.agent-total span, .agent-metric span { display: block; font-size: .76rem; color: var(--muted); }
.agent-total strong { font-variant-numeric: tabular-nums; }
.agent-metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(128px, 1fr)); gap: 8px; padding: 0 16px 12px; }
.agent-metric { border: 1px solid var(--line); border-radius: 10px; background: var(--bg); padding: 8px 10px; min-width: 0; }
.agent-metric b { display: block; margin-top: 2px; font-size: .95rem; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.agent-metric.alert { border-color: #F3C7C7; background: #FEF5F5; }
.agent-metric.alert b { color: var(--danger); }
.agent-receipts { padding: 0 16px 14px; }
.btn-link { border: 0; background: transparent; color: var(--primary); font: inherit; font-weight: 600; padding: 0; cursor: pointer; text-decoration: underline; }
/* ---- Document placeholders ---- */
.doc-slot { display: flex; align-items: center; gap: 10px; margin: 6px 0; flex-wrap: wrap; }
.doc-placeholder { display: inline-flex; align-items: center; justify-content: center; min-width: 120px; min-height: 64px; padding: 8px 12px; border: 1px dashed var(--line); border-radius: 10px; background: var(--bg); color: var(--muted); font-size: .82rem; text-align: center; }
.doc-thumb { max-width: 160px; max-height: 120px; border-radius: 8px; border: 1px solid var(--line); object-fit: cover; cursor: zoom-in; }
/* ---- Inline documents ---- */
.doc-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin: 10px 0 14px; }
.doc-card { display: flex; flex-direction: column; gap: 8px; min-width: 0; margin: 0; padding: 10px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); color: var(--ink); font: inherit; text-align: left; cursor: zoom-in; }
.doc-card:hover { border-color: var(--primary); }
.doc-card img, .doc-card iframe { width: 100%; height: 150px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); object-fit: cover; pointer-events: none; }
.doc-card iframe { height: 170px; }
.doc-card-label { font-size: .78rem; font-weight: 600; color: var(--muted); }
.doc-grid .doc-placeholder { width: 100%; min-height: 150px; }
/* ---- Multiple photo upload previews ---- */
.preview-strip, .thumb-row, .photo-editor { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.preview-strip .img-preview, .thumb-row .doc-thumb { margin-top: 0; width: 96px; height: 96px; min-width: 0; }
.photo-item { position: relative; display: inline-flex; }
.photo-item .doc-thumb { width: 96px; height: 96px; margin-top: 0; }
.photo-item .btn { position: absolute; top: 4px; right: 4px; padding: 3px 7px; font-size: .72rem; }
.preview-strip:empty, .thumb-row:empty, .photo-editor:empty { display: none; }
/* ---- Full-screen document viewer ---- */
body.viewer-open { overflow: hidden; }
.viewer { position: fixed; inset: 0; z-index: 70; display: flex; flex-direction: column; padding: 14px; background: rgba(8, 14, 13, .94); color: #fff; }
.viewer-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.viewer-bar strong { font-size: 1rem; }
.viewer .btn-ghost { background: rgba(255, 255, 255, .12); color: #fff; border-color: rgba(255, 255, 255, .35); }
.viewer-stage { flex: 1; min-height: 0; display: grid; place-items: center; }
.viewer-image { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 8px; }
.viewer-frame { width: 100%; height: 100%; border: 0; border-radius: 8px; background: #fff; }

/* ---- Mobile: stack tables ---- */
@media (max-width: 640px) {
  .table-wrap table, .table-wrap thead, .table-wrap tbody, .table-wrap tr, .table-wrap th, .table-wrap td { display: block; width: 100%; }
  .table-wrap thead { display: none; }
  .table-wrap tr { margin-bottom: 10px; border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; background: var(--surface); }
  .table-wrap td { border: none; padding: 3px 0; }
  .table-wrap td::before { content: attr(data-label) " "; font-weight: 600; color: var(--muted); font-size: .78rem; }
}
/* ---- Mobile modal: full-screen-ish ---- */
@media (max-width: 640px) {
  .backdrop { padding: 0; }
  .panel { max-width: 100%; max-height: 100vh; border-radius: 0; padding: 16px; }
  .panel.wide { max-width: 100%; }
  .cust-card { flex-direction: column; }
  .cust-photo { width: 72px; height: 72px; }
  .figures, .loan .figures { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
/* ---- Dark mode ---- */
html[data-theme="dark"] {
  --bg: #0F1716;
  --surface: #182322;
  --ink: #E6F0EE;
  --muted: #9FB3B1;
  --line: #2A3A38;
  --danger: #F87171;
  --ok: #4ADE80;
}
html[data-theme="dark"] .badge { background: #1F2E2C; color: var(--muted); }
html[data-theme="dark"] input, html[data-theme="dark"] select, html[data-theme="dark"] textarea { background: var(--surface); color: var(--ink); border-color: var(--line); }
html[data-theme="dark"] .btn-ghost, html[data-theme="dark"] .btn-danger { background: var(--surface); color: var(--ink); border-color: var(--line); }
html[data-theme="dark"] tr.click:hover { background: #1F2E2C; cursor: pointer; }
html[data-theme="dark"] .tag { background: #1F2E2C; color: var(--muted); }
html[data-theme="dark"] .pay-details { background: #1F2E2C; border-color: var(--line); }
html[data-theme="dark"] .file-btn { background: #1F2E2C; border-color: var(--line); color: var(--muted); }
html[data-theme="dark"] .detail-tabs button { background: var(--surface); color: var(--ink); border-color: var(--line); }
html[data-theme="dark"] .backdrop { background: rgba(0, 0, 0, .65); }
html[data-theme="dark"] .kpi.alert, html[data-theme="dark"] .agent-metric.alert { background: #3A1F1F; border-color: #5A2A2A; }
html[data-theme="dark"] .auth-card.is-busy input { background: #1F2E2C; }
html[data-theme="dark"] .file-btn:hover { border-color: var(--primary); color: var(--primary); }
html[data-theme="dark"] .toast { background: #1F2E2C; color: #E6F0EE; border-color: var(--line); box-shadow: 0 10px 28px rgba(0, 0, 0, .45); }
html[data-theme="dark"] .toast.bad { background: #3A1F1F; color: #FCA5A5; border-color: #7F1D1D; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
  .btn-spinner { border-top-color: #fff; }
}

/* ---- Mobile compact ---- */
@media (max-width: 640px) {
  body { font-size: 14px; }
  h2 { font-size: 1.05rem; }
  h3 { font-size: .95rem; }
  .container { padding: 10px 10px 70px; }
  .card { padding: 10px 12px; margin-bottom: 10px; }
  .kpi { padding: 8px 10px; }
  .kpi .v { font-size: 1.05rem; }
  .agent-group > summary { padding: 10px 12px; align-items: flex-start; }
  .agent-summary { align-items: flex-start; }
  .agent-total { font-size: .88rem; }
  .agent-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); padding: 0 12px 10px; }
  .agent-receipts { padding: 0 12px 12px; }
  .figures { gap: 8px; margin: 10px 0 12px; }
  .figures > div { padding: 8px 10px; }
  .figures b { font-size: 1rem; }
  .loan-actions { margin-top: 10px; padding-top: 8px; }
  .loan-actions .btn { flex: 1 1 calc(50% - 8px); }
  .btn { padding: 7px 12px; font-size: .82rem; }
  .btn-sm { padding: 4px 9px; font-size: .78rem; }
  input, select, textarea { padding: 7px 9px; font-size: .9rem; }
  label { font-size: .8rem; gap: 3px; }
  .muted { font-size: .78rem; }
  .loan { padding: 10px; margin-bottom: 8px; }
  .badge { font-size: .7rem; padding: 1px 7px; }
  .tag { font-size: .7rem; padding: 1px 7px; }
  .topbar { padding: 8px 10px; }
  .top-right { gap: 8px; }
  .tabs { padding: 6px 10px; gap: 6px; }
  .tab { padding: 6px 11px; font-size: .82rem; gap: 6px; }
  .doc-grid { grid-template-columns: 1fr; }
  .doc-card img, .doc-card iframe { height: 180px; }
  .viewer { padding: 8px; }
}

/* ---- Notifications, install, attendance and settings ---- */
.topbar { position: sticky; top: 0; z-index: 30; }
.notif-btn { position: relative; }
.notif-badge { position: absolute; top: -5px; right: -5px; min-width: 17px; height: 17px; padding: 0 4px; border-radius: 999px; background: var(--accent); color: #fff; font-size: .65rem; font-weight: 700; line-height: 17px; text-align: center; }
.nav-foot { margin-top: auto; padding-top: 12px; border-top: 1px solid var(--line); }
.nav-foot .btn { width: 100%; justify-content: flex-start; }
.notif-filters { display: flex; gap: 6px; flex-wrap: wrap; margin: 10px 0; }
.notif-filters button { border: 1px solid var(--line); background: #fff; color: var(--ink); border-radius: 999px; padding: 5px 11px; font: inherit; font-size: .8rem; font-weight: 600; cursor: pointer; }
.notif-filters button.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.notif-list { display: flex; flex-direction: column; gap: 8px; max-height: 48vh; overflow-y: auto; }
.notif-item { border: 1px solid var(--line); border-radius: 12px; padding: 11px 12px; background: var(--surface); cursor: pointer; }
.notif-item.unread { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); background: color-mix(in srgb, var(--accent) 6%, var(--surface)); }
.notif-item strong { display: block; font-size: .9rem; }
.notif-item p { margin: 3px 0 0; color: var(--muted); font-size: .82rem; }
.notif-item .muted { font-size: .72rem; }
.attendance-clock { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.clock-card { border: 1px solid var(--line); border-radius: var(--r); padding: 16px; background: var(--surface); text-align: center; }
.clock-card .btn { width: 100%; min-height: 54px; font-size: 1.05rem; }
.clock-time { font-size: 1.8rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.attendance-card { border: 1px solid var(--line); border-radius: 12px; padding: 12px; margin-bottom: 8px; background: var(--surface); }
.attendance-card .row { justify-content: space-between; }
.settings-section { border-top: 1px solid var(--line); margin-top: 16px; padding-top: 14px; }
.settings-section h3 { margin-bottom: 10px; }

@media (min-width: 900px) {
  .tabs { position: sticky; top: 56px; height: calc(100vh - 56px); display: flex; flex-direction: column; }
  .nav-foot { display: block; }
  .notif-list { max-height: 60vh; }
}
@media (max-width: 899px) {
  .nav-foot { display: none; }
}
/* ---- Collapsed desktop sidebar (mobile navigation stays untouched) ---- */
@media (min-width: 900px) {
  .layout { transition: grid-template-columns 160ms ease; }
  .nav-toggle.btn { transition: transform 140ms ease, background 120ms ease; }
  .nav-toggle.btn:active { transform: scale(.94); }
  html.nav-collapsed .layout { grid-template-columns: 72px 1fr; }
  html.nav-collapsed .tabs { align-items: center; padding: 12px 10px; }
  html.nav-collapsed .tab { position: relative; width: 48px; height: 44px; padding: 0; justify-content: center; gap: 0; }
  html.nav-collapsed .tab span { position: absolute; width: 1px; height: 1px; max-width: 0; opacity: 0; overflow: hidden; clip-path: inset(50%); pointer-events: none; }
  html.nav-collapsed .tab i, html.nav-collapsed .tab svg,
  html.nav-collapsed .nav-foot .btn i, html.nav-collapsed .nav-foot .btn svg { flex: 0 0 auto; display: block; margin: 0 auto; }
  html.nav-collapsed .nav-foot .btn { position: relative; width: 48px; padding: 8px 0; justify-content: center; gap: 0; }
  html.nav-collapsed .nav-foot .btn span { position: absolute; width: 1px; height: 1px; max-width: 0; opacity: 0; overflow: hidden; clip-path: inset(50%); pointer-events: none; }
}
@media (max-width: 640px) {
  .topbar { gap: 6px; }
  .top-right .btn span { display: none; }
  .notif-btn { padding: 9px; }
  .notif-list { max-height: none; }
  .notif-filters button { flex: 1 1 auto; }
  .attendance-card .row { gap: 4px; }
}
html[data-theme="dark"] .notif-filters button { background: var(--surface); color: var(--ink); }
html[data-theme="dark"] .notif-filters button.active { background: var(--primary); color: #fff; }
html[data-theme="dark"] .notif-item { background: var(--surface); }
html[data-theme="dark"] .clock-card, html[data-theme="dark"] .attendance-card { background: var(--surface); }

/* ---- Owner sales, pricing and diagnostics ---- */
.owner-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.issue-list { display: flex; flex-direction: column; gap: 10px; }
.issue-card { border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; background: var(--surface); }
.issue-card .row { gap: 8px; }
.issue-card strong { font-size: .92rem; }
.issue-body { margin: 8px 0; font-size: .86rem; white-space: pre-wrap; overflow-wrap: anywhere; }
.issue-reply { border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; margin: 8px 0; background: color-mix(in srgb, var(--primary) 4%, var(--surface)); font-size: .84rem; color: var(--muted); }
.log-details { margin-top: 8px; }
.log-details summary { cursor: pointer; font-size: .8rem; font-weight: 600; color: var(--primary); }
.log-details pre { max-height: 220px; overflow: auto; margin: 8px 0 0; padding: 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); font-size: .74rem; white-space: pre-wrap; overflow-wrap: anywhere; }
html[data-theme="dark"] .issue-card { background: var(--surface); }
@media (max-width: 640px) {
  .owner-actions .btn { flex: 1 1 auto; }
  .issue-card { padding: 10px 11px; }
  .issue-card .row { flex-direction: column; align-items: flex-start; }
  .log-details pre { font-size: .7rem; }
}

/* ---- Data retention, repeat clients and danger zones ---- */
.danger-zone { border: 1px solid #F3C7C7; border-radius: var(--r); padding: 16px; background: #FFF7F7; }
.danger-zone h2, .danger-zone h3 { color: var(--danger); }
.danger-zone .muted { color: #8A4141; }
.danger-note { border: 1px solid #F3C7C7; border-radius: 10px; padding: 9px 11px; margin: 10px 0; background: color-mix(in srgb, var(--danger) 5%, #fff); font-size: .86rem; color: #8A4141; }
.cleanup-result { margin-top: 12px; }
.cleanup-summary { border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; background: var(--surface); }
.cleanup-summary.blocked { border-color: #F3C7C7; background: #FFF7F7; }
.cleanup-summary strong { display: block; margin-bottom: 6px; }
.cleanup-stats { display: flex; flex-wrap: wrap; gap: 8px 16px; font-size: .84rem; color: var(--muted); }
.cleanup-stats b { color: var(--ink); font-size: 1rem; }
.cleanup-sample { margin-top: 10px; border-top: 1px solid var(--line); padding-top: 8px; font-size: .78rem; color: var(--muted); max-height: 160px; overflow-y: auto; }
.cleanup-sample div { padding: 2px 0; }
.repeat-client-panel { border: 1px solid var(--line); border-radius: 12px; padding: 12px; background: color-mix(in srgb, var(--primary) 4%, var(--surface)); }
.repeat-client-panel .row { gap: 8px; }
.repeat-client-panel .row input { flex: 1; }
.repeat-results { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; max-height: 220px; overflow-y: auto; }
.repeat-result { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; background: var(--surface); color: var(--ink); text-align: left; font: inherit; cursor: pointer; }
.repeat-result:hover, .repeat-result.selected { border-color: var(--primary); background: color-mix(in srgb, var(--primary) 8%, var(--surface)); }
.repeat-result span { font-size: .8rem; color: var(--muted); }
.repeat-result small { font-size: .72rem; color: var(--muted); }
html[data-theme="dark"] .danger-zone, html[data-theme="dark"] .cleanup-summary.blocked { background: #2A1717; border-color: #7F1D1D; }
html[data-theme="dark"] .danger-zone .muted, html[data-theme="dark"] .danger-note { color: #FCA5A5; }
html[data-theme="dark"] .repeat-client-panel { background: var(--surface); }
@media (max-width: 640px) {
  .danger-zone { padding: 12px; }
  .cleanup-stats { gap: 6px 12px; }
  .repeat-client-panel .row { flex-direction: column; }
  .repeat-client-panel .row .btn { width: 100%; }
}

/* ---- About system guide ---- */
.guide-shell { max-width: 1120px; }
.guide-hero { border: 1px solid var(--line); border-radius: var(--r); padding: 18px; background: linear-gradient(135deg, color-mix(in srgb, var(--primary) 7%, var(--surface)), var(--surface)); }
.guide-hero h2 { margin: 0 0 6px; }
.guide-hero p { margin: 0; color: var(--muted); line-height: 1.5; }
.guide-brand { margin-top: 10px; font-size: .76rem; font-weight: 700; letter-spacing: .02em; color: var(--primary); }
.guide-toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0 10px; }
.guide-toolbar input[type="search"] { flex: 1 1 260px; min-width: 180px; }
.guide-toc { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.guide-toc button { border: 1px solid var(--line); background: var(--surface); color: var(--muted); border-radius: 999px; padding: 5px 11px; font: inherit; font-size: .78rem; font-weight: 600; cursor: pointer; }
.guide-toc button:hover, .guide-toc button:focus-visible { border-color: var(--primary); color: var(--primary); }
.guide-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(310px, 1fr)); gap: 12px; }
.guide-section { border: 1px solid var(--line); border-radius: 14px; padding: 16px; background: var(--surface); scroll-margin-top: 80px; }
.guide-section-head { display: flex; gap: 10px; align-items: flex-start; }
.guide-mark { width: 34px; height: 34px; flex: none; display: grid; place-items: center; border-radius: 10px; background: color-mix(in srgb, var(--primary) 10%, var(--surface)); color: var(--primary); font-size: .76rem; font-weight: 800; letter-spacing: .03em; }
.guide-section h3 { margin: 0; font-size: 1rem; }
.guide-intro { margin: 6px 0 10px; color: var(--muted); font-size: .86rem; line-height: 1.5; }
.guide-steps { margin: 0; padding-left: 18px; }
.guide-steps li { margin: 7px 0; font-size: .86rem; line-height: 1.45; }
.guide-steps b { display: block; color: var(--ink); }
.guide-steps span { color: var(--muted); }
.guide-tips { margin-top: 10px; padding-top: 9px; border-top: 1px solid var(--line); font-size: .8rem; color: var(--muted); }
.guide-tips div { margin-top: 4px; }
.guide-empty { padding: 18px; text-align: center; color: var(--muted); }
.guide-footer { margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--line); font-size: .78rem; color: var(--muted); }
html[data-theme="dark"] .guide-hero { background: var(--surface); }
html[data-theme="dark"] .guide-mark { color: #99F6E4; background: color-mix(in srgb, var(--primary) 20%, var(--surface)); }
@media (max-width: 640px) {
  .guide-grid { grid-template-columns: 1fr; }
  .guide-toolbar .btn { flex: 1 1 auto; }
}
@media print {
  .topbar, #tabs, .nav-foot, .guide-toolbar, .guide-toc, .no-print, .toast, #notif-btn { display: none !important; }
  html, body, #shell, main, #view { background: #fff !important; color: #000 !important; }
  #shell, main, #view { display: block !important; overflow: visible !important; }
  .guide-shell { max-width: none; }
  .guide-hero { border: 0; padding: 0 0 12px; background: #fff !important; }
  .guide-grid { display: block; }
  .guide-section { break-inside: avoid; page-break-inside: avoid; border: 1px solid #ddd; background: #fff !important; margin-bottom: 10px; box-shadow: none; }
  .guide-mark { background: #eee !important; color: #000 !important; }
  .guide-intro, .guide-steps span, .guide-tips, .guide-footer { color: #444 !important; }
  .guide-section h3, .guide-steps b { color: #000 !important; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}
