/* =====================================================================
   MunimBook Pro - Theme & Layout
   Light + Dark via [data-bs-theme]; mobile responsive sidebar.
   ===================================================================== */

:root {
  --mb-primary: #4f46e5;
  --mb-sidebar-w: 260px;
  --mb-radius: 12px;
}

[data-bs-theme="light"] {
  --mb-bg: #f4f6fb;
  --mb-surface: #ffffff;
  --mb-sidebar-bg: #1e293b;
  --mb-sidebar-text: #cbd5e1;
  --mb-border: #e5e7eb;
  --mb-text: #1f2937;
}
[data-bs-theme="dark"] {
  --mb-bg: #0f172a;
  --mb-surface: #1e293b;
  --mb-sidebar-bg: #0b1220;
  --mb-sidebar-text: #94a3b8;
  --mb-border: #334155;
  --mb-text: #e2e8f0;
}

body {
  background: var(--mb-bg);
  color: var(--mb-text);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
}

/* ----------------------------- Login ----------------------------- */
.login-page {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
  padding: 20px;
}
.login-card {
  background: var(--mb-surface); width: 100%; max-width: 400px;
  padding: 36px 32px; border-radius: 16px; box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.brand-logo {
  width: 64px; height: 64px; margin: 0 auto; border-radius: 16px;
  background: var(--mb-primary); color: #fff; font-size: 30px;
  display: flex; align-items: center; justify-content: center;
}

/* ----------------------------- Layout ----------------------------- */
.app-wrapper { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--mb-sidebar-w); background: var(--mb-sidebar-bg);
  color: var(--mb-sidebar-text); position: fixed; top: 0; left: 0; bottom: 0;
  display: flex; flex-direction: column; z-index: 1040; transition: transform .25s ease;
}
.sidebar-brand {
  padding: 20px 22px; font-size: 19px; font-weight: 700; color: #fff;
  display: flex; align-items: center; gap: 10px; border-bottom: 1px solid rgba(255,255,255,.08);
}
.sidebar-brand i { color: var(--mb-primary); font-size: 24px; }
.sidebar-nav { flex: 1; padding: 14px 12px; overflow-y: auto; }
.sidebar-nav .nav-link {
  display: flex; align-items: center; gap: 12px; padding: 11px 14px;
  color: var(--mb-sidebar-text); border-radius: 8px; margin-bottom: 4px;
  font-size: 14.5px; transition: all .15s;
}
.sidebar-nav .nav-link i { font-size: 18px; width: 22px; }
.sidebar-nav .nav-link:hover { background: rgba(255,255,255,.07); color: #fff; }
.sidebar-nav .nav-link.active { background: var(--mb-primary); color: #fff; }
.sidebar-footer { padding: 14px 22px; border-top: 1px solid rgba(255,255,255,.08); }

.main-content { flex: 1; margin-left: var(--mb-sidebar-w); display: flex; flex-direction: column; }

.topbar {
  height: 62px; background: var(--mb-surface); border-bottom: 1px solid var(--mb-border);
  display: flex; align-items: center; gap: 14px; padding: 0 20px;
  position: sticky; top: 0; z-index: 1030;
}
.topbar-title { margin: 0; font-weight: 600; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }

.btn-icon {
  width: 40px; height: 40px; border-radius: 8px; border: 1px solid var(--mb-border);
  background: transparent; color: var(--mb-text); display: inline-flex;
  align-items: center; justify-content: center; font-size: 18px;
}
.btn-icon:hover { background: var(--mb-bg); }

.user-menu { width: auto; padding: 4px 10px; gap: 8px; }
.avatar {
  width: 30px; height: 30px; border-radius: 50%; background: var(--mb-primary);
  color: #fff; display: inline-flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 14px;
}

.page-content { padding: 22px; flex: 1; }

/* -------------------------- Quick search -------------------------- */
.quick-search { position: relative; }
.quick-search input {
  border: 1px solid var(--mb-border); background: var(--mb-bg); color: var(--mb-text);
  border-radius: 20px; padding: 7px 14px 7px 36px; width: 280px; font-size: 14px;
}
.quick-search > i { position: absolute; left: 13px; top: 9px; color: #9ca3af; }
.quick-search-results {
  position: absolute; top: 44px; left: 0; right: 0; background: var(--mb-surface);
  border: 1px solid var(--mb-border); border-radius: 10px; box-shadow: 0 12px 30px rgba(0,0,0,.15);
  max-height: 360px; overflow-y: auto; display: none; z-index: 1050;
}
.quick-search-results a {
  display: block; padding: 10px 14px; border-bottom: 1px solid var(--mb-border);
  color: var(--mb-text); text-decoration: none; font-size: 13.5px;
}
.quick-search-results a:hover { background: var(--mb-bg); }

/* ----------------------------- Cards ------------------------------ */
.card {
  background: var(--mb-surface); border: 1px solid var(--mb-border);
  border-radius: var(--mb-radius); box-shadow: 0 1px 3px rgba(0,0,0,.04);
}
.card-header {
  background: transparent; border-bottom: 1px solid var(--mb-border);
  font-weight: 600; padding: 14px 18px;
}
.card-footer { background: transparent; border-top: 1px solid var(--mb-border); }

/* --------------------------- Dashboard ---------------------------- */
.dashboard-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px;
}
.stat-card {
  background: var(--mb-surface); border: 1px solid var(--mb-border);
  border-radius: var(--mb-radius); padding: 20px; display: flex; align-items: center; gap: 16px;
}
.stat-icon {
  width: 54px; height: 54px; border-radius: 12px; display: flex;
  align-items: center; justify-content: center; font-size: 24px; color: #fff; flex-shrink: 0;
}
.stat-primary .stat-icon { background: #4f46e5; }
.stat-success .stat-icon { background: #16a34a; }
.stat-danger  .stat-icon { background: #dc2626; }
.stat-info    .stat-icon { background: #0ea5e9; }
.stat-warning .stat-icon { background: #f59e0b; }
.stat-dark    .stat-icon { background: #475569; }
.stat-label { display: block; font-size: 13px; color: #9ca3af; }
.stat-value { display: block; font-size: 22px; font-weight: 700; }

/* --------------------------- Toolbar ------------------------------ */
.page-toolbar {
  display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap;
}

/* ---------------------------- Tables ------------------------------ */
.table { color: var(--mb-text); margin-bottom: 0; }
.table > :not(caption) > * > * { background: transparent; }
.ledger-table tfoot td { font-weight: 700; border-top: 2px solid var(--mb-border); }
.balance-pos { color: #16a34a; font-weight: 600; }
.balance-neg { color: #dc2626; font-weight: 600; }

.badge-type {
  font-size: 11px; padding: 4px 9px; border-radius: 20px; font-weight: 600; text-transform: capitalize;
}
.t-udhari   { background: #fee2e2; color: #b91c1c; }
.t-jama     { background: #dcfce7; color: #15803d; }
.t-naqd     { background: #dbeafe; color: #1d4ed8; }
.t-purchase { background: #fef3c7; color: #b45309; }
.t-expense  { background: #ede9fe; color: #6d28d9; }

/* ------------------------- Empty / states ------------------------- */
.empty-state {
  text-align: center; padding: 70px 20px; color: #9ca3af;
}
.empty-state i { font-size: 54px; display: block; margin-bottom: 14px; opacity: .5; }

/* --------------------------- Daily Bahi --------------------------- */
.closing-list { list-style: none; margin: 0; padding: 0; }
.closing-list li {
  display: flex; justify-content: space-between; padding: 9px 0;
  border-bottom: 1px dashed var(--mb-border);
}
.closing-list li.divider { border-bottom: 2px solid var(--mb-border); padding: 0; }
.closing-list li.total { font-size: 18px; font-weight: 700; color: var(--mb-primary); border: none; }

/* --------------------------- Reports ------------------------------ */
.report-card { transition: transform .15s, box-shadow .15s; height: 100%; }
.report-card:hover { transform: translateY(-3px); box-shadow: 0 8px 24px rgba(0,0,0,.1); }
.report-icon {
  width: 50px; height: 50px; border-radius: 12px; display: flex;
  align-items: center; justify-content: center; font-size: 24px; margin-bottom: 12px;
}

/* ----------------------------- Toasts ----------------------------- */
.toast-container { z-index: 1090; }

/* --------------------------- Responsive --------------------------- */
@media (max-width: 992px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.show { transform: translateX(0); }
  .main-content { margin-left: 0; }
}
.sidebar-backdrop {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 1035;
}
.sidebar-backdrop.show { display: block; }

/* =====================================================================
   TRADITIONAL BAHI KHATA THEME
   Red ledger border + cream paper + Hindi labels + print-friendly
   ===================================================================== */

/* ---- Bahi Khata Card ---- */
.bahi-khata {
  background: #fffdf7;
  border: 2px solid #8b0000;
  border-radius: 6px;
  box-shadow: 0 3px 12px rgba(139,0,0,.08);
}
[data-bs-theme="dark"] .bahi-khata {
  background: #1a1410;
  border-color: #a52a2a;
}

.bahi-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 3px double #8b0000;
  background: linear-gradient(135deg, #fef3e2 0%, #fffdf7 100%);
  flex-wrap: wrap;
  gap: 10px;
}
[data-bs-theme="dark"] .bahi-header {
  background: linear-gradient(135deg, #2d1f10 0%, #1a1410 100%);
  border-color: #a52a2a;
}

.bahi-party-name {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  color: #8b0000;
}
[data-bs-theme="dark"] .bahi-party-name { color: #f87171; }

.bahi-party-meta { color: #8b6914; }
[data-bs-theme="dark"] .bahi-party-meta { color: #d4a06a; }

.bahi-balance-box {
  text-align: right;
  padding: 8px 14px;
  background: #8b0000;
  border-radius: 6px;
  min-width: 180px;
}
.bahi-balance-label {
  display: block;
  font-size: 11px;
  color: #fecdd3;
  letter-spacing: 0.5px;
}
.bahi-balance-value {
  display: block;
  font-size: 20px;
  font-weight: 800;
  color: #fff;
}
.bahi-balance-value.naame { color: #fbbf24; }
.bahi-balance-value.jama { color: #86efac; }

/* ---- Bahi Table ---- */
.bahi-table-wrapper {
  overflow-x: auto;
}
.bahi-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}
.bahi-table thead tr {
  background: #8b0000;
}
.bahi-table thead th {
  color: #fff;
  padding: 10px 12px;
  font-weight: 600;
  text-align: left;
  border: none;
  white-space: nowrap;
}
[data-bs-theme="dark"] .bahi-table thead tr { background: #7f1d1d; }
.bahi-table thead th small { font-weight: 400; opacity: .8; }

.bahi-th-naame, .bahi-th-jama, .bahi-th-balance { text-align: right; }

.bahi-table tbody td {
  padding: 9px 12px;
  border-bottom: 1px solid #f0e6d6;
  vertical-align: middle;
}
[data-bs-theme="dark"] .bahi-table tbody td { border-color: #3d2d1a; }

.bahi-table .bahi-row-even td { background: #fef9f0; }
[data-bs-theme="dark"] .bahi-table .bahi-row-even td { background: #1f1610; }

.bahi-date { color: #6b5e4e; font-size: 12.5px; white-space: nowrap; }
[data-bs-theme="dark"] .bahi-date { color: #a08c6d; }

.bahi-desc { max-width: 300px; }

.bahi-naame {
  text-align: right;
  color: #dc2626;
  font-weight: 600;
  font-family: "Consolas", "SF Mono", monospace;
}
.bahi-jama {
  text-align: right;
  color: #16a34a;
  font-weight: 600;
  font-family: "Consolas", "SF Mono", monospace;
}
.bahi-bal {
  text-align: right;
  font-weight: 700;
  font-family: "Consolas", "SF Mono", monospace;
}
.bahi-bal.naame { color: #b91c1c; }
.bahi-bal.jama { color: #15803d; }

/* Opening row */
.bahi-opening-row td {
  background: #fef3e2 !important;
  font-weight: 700;
  border-bottom: 2px solid #e8c06a !important;
}
[data-bs-theme="dark"] .bahi-opening-row td { background: #2a1f0c !important; border-color: #8b6914 !important; }

/* Totals row */
.bahi-total-row td {
  background: #8b0000 !important;
  color: #fff !important;
  font-weight: 700;
  font-size: 14px;
  border: none;
}
.bahi-total-row .bahi-naame,
.bahi-total-row .bahi-jama,
.bahi-total-row .bahi-bal { color: #fff !important; }

/* ---- Cash Book Cards ---- */
.cash-card {
  border-radius: 10px;
  padding: 16px 18px;
  text-align: center;
  border: 1px solid var(--mb-border);
}
.cash-label {
  font-size: 13px;
  color: #6b7280;
  margin-bottom: 6px;
}
.cash-value { font-size: 22px; font-weight: 700; }

.cash-opening { background: #f3f4f6; }
.cash-opening .cash-value { color: #4b5563; }
.cash-received { background: #dcfce7; }
.cash-received .cash-value { color: #16a34a; }
.cash-paid { background: #fee2e2; }
.cash-paid .cash-value { color: #dc2626; }
.cash-closing { background: #dbeafe; border: 2px solid #60a5fa; }
.cash-closing .cash-value { color: #1d4ed8; }

[data-bs-theme="dark"] .cash-opening { background: #1f2937; }
[data-bs-theme="dark"] .cash-received { background: #052e16; }
[data-bs-theme="dark"] .cash-paid { background: #310a0a; }
[data-bs-theme="dark"] .cash-closing { background: #0c1929; border-color: #3b82f6; }
[data-bs-theme="dark"] .cash-opening .cash-value { color: #9ca3af; }
[data-bs-theme="dark"] .cash-received .cash-value { color: #4ade80; }
[data-bs-theme="dark"] .cash-paid .cash-value { color: #f87171; }
[data-bs-theme="dark"] .cash-closing .cash-value { color: #60a5fa; }

/* ---- Aging Bar & Legend ---- */
.aging-bar {
  display: flex;
  height: 28px;
  border-radius: 6px;
  overflow: hidden;
  background: #e5e7eb;
}
.aging-segment { transition: width .4s ease; }
.aging-current { background: #16a34a; }
.aging-30 { background: #f59e0b; }
.aging-60 { background: #ea580c; }
.aging-90 { background: #dc2626; }

.aging-legend {
  display: flex;
  gap: 18px;
  font-size: 12px;
  color: #6b7280;
}
.aging-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  margin-right: 4px;
}
i.aging-dot.aging-current { background: #16a34a; }
i.aging-dot.aging-30 { background: #f59e0b; }
i.aging-dot.aging-60 { background: #ea580c; }
i.aging-dot.aging-90 { background: #dc2626; }

.bg-orange { background-color: #ea580c !important; }

/* ---- Print Styles ---- */
@media print {
  .sidebar, .topbar, .page-toolbar, .toast-container, .sidebar-backdrop { display: none !important; }
  .main-content { margin-left: 0 !important; }
  .page-content { padding: 0 !important; }
  .bahi-khata { border: 1px solid #8b0000; box-shadow: none; }
  .card { box-shadow: none; border: 1px solid #ddd; }
  body { background: #fff !important; }
}

/* =================== Searchable Party Picker =================== */
.party-picker {
  position: relative;
  min-width: 180px;
}
.party-picker .pp-input {
  border-radius: 6px;
}
.party-picker .pp-input.pp-selected {
  border-color: #16a34a;
  background: #f0fdf4;
  font-weight: 600;
}
[data-bs-theme="dark"] .party-picker .pp-input.pp-selected {
  background: #052e16;
  border-color: #4ade80;
}
.party-picker-list {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 1060;
  background: var(--mb-surface, #fff);
  border: 1px solid var(--mb-border, #e5e7eb);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,.15);
  max-height: 220px;
  overflow-y: auto;
  margin-top: 4px;
}
.party-picker-list.show { display: block; }
.party-picker-list .pp-item {
  padding: 8px 12px;
  cursor: pointer;
  font-size: 13px;
  border-bottom: 1px solid var(--mb-border, #f3f4f6);
  transition: background .1s;
}
.party-picker-list .pp-item:hover,
.party-picker-list .pp-item.active {
  background: var(--mb-bg, #f4f6fb);
}
[data-bs-theme="dark"] .party-picker-list .pp-item:hover,
[data-bs-theme="dark"] .party-picker-list .pp-item.active {
  background: #334155;
}
.party-picker-list .pp-item:last-child { border-bottom: none; }
.party-picker-list .pp-item mark {
  background: #fef08a;
  padding: 0;
  border-radius: 2px;
}
.party-picker-list .pp-empty {
  padding: 12px;
  text-align: center;
  color: #9ca3af;
  font-size: 13px;
}

/* ---- Searchable Party Selector (Quick Entry) ---- */
.party-search-wrapper { position: relative; }
.party-search-wrapper .qe-party-search {
  width: 100%;
}
.party-search-wrapper .qe-party-search.selected {
  border-color: #16a34a;
  background: #f0fdf4;
}
[data-bs-theme="dark"] .party-search-wrapper .qe-party-search.selected {
  background: #052e16;
  border-color: #4ade80;
}
.party-search-dropdown {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 1060;
  max-height: 220px;
  overflow-y: auto;
  background: var(--mb-surface);
  border: 1px solid var(--mb-border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,.15);
  margin-top: 2px;
}
.party-search-item {
  padding: 8px 12px;
  cursor: pointer;
  font-size: 13px;
  border-bottom: 1px solid var(--mb-border);
}
.party-search-item:hover, .party-search-item.active {
  background: var(--mb-bg);
  color: var(--mb-primary);
}
.party-search-item:last-child { border-bottom: none; }
.party-search-empty {
  padding: 12px;
  text-align: center;
  color: #9ca3af;
  font-size: 13px;
}

/* ---- Attachment Widget ---- */
.att-panel { margin-top: 12px; padding: 12px; background: var(--mb-bg); border-radius: 8px; border: 1px dashed var(--mb-border); }
.att-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.att-upload-btn { cursor: pointer; font-size: 12px; }
.att-list { display: flex; flex-direction: column; gap: 6px; }
.att-item { display: flex; justify-content: space-between; align-items: center; padding: 6px 8px; background: var(--mb-surface); border-radius: 6px; border: 1px solid var(--mb-border); }
.att-info { display: flex; align-items: center; gap: 8px; min-width: 0; flex: 1; }
.att-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 13px; }
.att-actions { display: flex; gap: 4px; flex-shrink: 0; }

/* ---- Attachment Widget ---- */
.att-widget { border: 1px dashed var(--mb-border); border-radius: 8px; padding: 12px; margin-top: 10px; }
.att-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.att-upload-btn { cursor: pointer; font-size: 12px; }
.att-list { display: flex; flex-direction: column; gap: 6px; }
.att-item { display: flex; align-items: center; gap: 8px; padding: 6px 8px; background: var(--mb-bg);
  border-radius: 6px; font-size: 13px; }
.att-item .att-link { display: flex; align-items: center; gap: 6px; flex: 1; text-decoration: none; color: var(--mb-text); }
.att-item .att-link:hover { color: var(--mb-primary); }
.att-thumb { width: 40px; height: 40px; object-fit: cover; border-radius: 4px; border: 1px solid var(--mb-border); }
.att-del { flex-shrink: 0; }

/* 5-column grid helper for settlement dashboard */
@media (min-width: 992px) { .col-lg-2dot4 { flex: 0 0 20%; max-width: 20%; } }

/* ---- Total Sales Widget (show/hide) ---- */
.total-sales-widget {
  margin-top: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 22px 26px;
  border-radius: var(--mb-radius);
  background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 60%, #9333ea 100%);
  color: #fff;
  box-shadow: 0 8px 28px rgba(79,70,229,.35);
  position: relative;
  overflow: hidden;
}
.total-sales-widget::after {
  content: '';
  position: absolute;
  right: -40px; top: -40px;
  width: 160px; height: 160px;
  background: rgba(255,255,255,.08);
  border-radius: 50%;
}
.ts-left { display: flex; align-items: center; gap: 18px; z-index: 1; }
.ts-icon {
  width: 60px; height: 60px; border-radius: 14px;
  background: rgba(255,255,255,.18);
  display: flex; align-items: center; justify-content: center;
  font-size: 28px;
}
.ts-label {
  display: block; font-size: 14px; opacity: .9; letter-spacing: .3px; margin-bottom: 4px;
}
.ts-value-row { display: flex; align-items: baseline; gap: 12px; }
.ts-value {
  font-size: 30px; font-weight: 800; letter-spacing: 1px;
  font-family: "Consolas", "SF Mono", monospace;
  transition: filter .2s;
}
.ts-value.ts-hidden { letter-spacing: 4px; opacity: .8; }
.ts-sub { font-size: 13px; opacity: .85; }
.ts-toggle {
  z-index: 1;
  width: 48px; height: 48px; flex-shrink: 0;
  border-radius: 50%; border: 2px solid rgba(255,255,255,.4);
  background: rgba(255,255,255,.15); color: #fff;
  font-size: 20px; cursor: pointer;
  transition: all .2s;
}
.ts-toggle:hover { background: rgba(255,255,255,.3); transform: scale(1.08); }
@media (max-width: 576px) {
  .total-sales-widget { flex-direction: row; padding: 18px; }
  .ts-value { font-size: 24px; }
  .ts-icon { width: 48px; height: 48px; font-size: 22px; }
}
