/* Mitra Business CRM – application styles */
:root {
  --mc-primary: #1f4e9c;
  --mc-primary-dark: #163a75;
  --mc-sidebar-w: 240px;
  --mc-sidebar-w-collapsed: 68px;
  --mc-topbar-h: 58px;
  --mc-bg: #f3f5f9;
  --mc-card-bg: #ffffff;
  --mc-border: #e5e8ef;
  --mc-text-muted: #6b7a90;
  --mc-sidebar-bg: #ffffff;
  --mc-sidebar-link: #4a5568;
  --mc-sidebar-active: #eaf1fc;
}
[data-bs-theme="dark"] {
  --mc-bg: #0f1420;
  --mc-card-bg: #171d2b;
  --mc-border: #262f42;
  --mc-text-muted: #8a97ad;
  --mc-sidebar-bg: #121828;
  --mc-sidebar-link: #aab4c8;
  --mc-sidebar-active: #1e2a44;
  --bs-body-bg: #0f1420;
  --bs-body-color: #dde3ee;
  --bs-border-color: #262f42;
}
html, body { height: 100%; }
body { background: var(--mc-bg); font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif; font-size: .925rem; }
a { text-decoration: none; }
.text-muted { color: var(--mc-text-muted) !important; }

/* Topbar */
.topbar { height: var(--mc-topbar-h); background: var(--mc-card-bg); border-bottom: 1px solid var(--mc-border); z-index: 1040; }
.topbar .navbar-brand { font-weight: 700; color: var(--mc-primary); font-size: 1.05rem; }
.brand-logo { height: 40px; max-width: 190px; object-fit: contain; }
.brand-icon { width: 34px; height: 34px; border-radius: 9px; background: var(--mc-primary); color: #fff; display: inline-flex; align-items: center; justify-content: center; }
.btn-icon { width: 38px; height: 38px; display: inline-flex; align-items: center; justify-content: center; border-radius: 10px; color: var(--bs-body-color); background: transparent; border: 0; font-size: 1.1rem; }
.btn-icon:hover { background: var(--mc-sidebar-active); }
.avatar-sm { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; }
.avatar-initials { display: inline-flex; align-items: center; justify-content: center; background: var(--mc-primary); color: #fff; font-size: .75rem; font-weight: 700; }
.avatar-lg { width: 72px; height: 72px; border-radius: 50%; object-fit: cover; font-size: 1.4rem; }
.notif-badge { position: absolute; top: 2px; right: 2px; font-size: .6rem; }
.notif-menu { width: 360px; max-width: 92vw; padding: 0; }
.notif-list { max-height: 360px; overflow-y: auto; }
.notif-item { display: block; padding: .6rem 1rem; border-bottom: 1px solid var(--mc-border); color: inherit; }
.notif-item.unread { background: var(--mc-sidebar-active); }
.notif-item:hover { background: var(--mc-sidebar-active); }

/* Global search */
.global-search { width: 380px; max-width: 40vw; }
.global-search .form-control { padding-left: 2.2rem; border-radius: 10px; background: var(--mc-bg); border-color: transparent; }
.global-search .form-control:focus { background: var(--mc-card-bg); border-color: var(--mc-primary); box-shadow: none; }
.global-search .search-icon { position: absolute; left: .8rem; top: 50%; transform: translateY(-50%); color: var(--mc-text-muted); }
.search-results { width: 100%; max-height: 420px; overflow-y: auto; top: 100%; }
.search-results.show { display: block; }
.search-results .dropdown-item { white-space: normal; padding: .5rem 1rem; }
.search-results .dropdown-item small { display: block; color: var(--mc-text-muted); }

/* Sidebar (grouped navigation) */
.sidebar { position: fixed; top: var(--mc-topbar-h); left: 0; bottom: 0; width: var(--mc-sidebar-w); background: var(--mc-sidebar-bg); border-right: 1px solid var(--mc-border); display: flex; flex-direction: column; transition: width .2s, transform .2s; z-index: 1035; }
.sidebar-nav { flex: 1; overflow-y: auto; overflow-x: hidden; padding: .6rem .55rem; scrollbar-width: thin; }
.nav-group { margin-bottom: 2px; }
.nav-group-link, .nav-group-toggle { display: flex; align-items: center; gap: .7rem; width: 100%; border: 0; background: transparent; color: var(--mc-sidebar-link); padding: .6rem .75rem; border-radius: 10px; font-weight: 600; font-size: .86rem; text-align: left; white-space: nowrap; cursor: pointer; transition: background .15s, color .15s; }
.nav-group-link i:first-child, .nav-group-toggle i:first-child { font-size: 1.15rem; width: 22px; text-align: center; flex-shrink: 0; }
.nav-group-toggle span, .nav-group-link span { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.nav-group-toggle .caret { font-size: .7rem; transition: transform .2s; opacity: .6; }
.nav-group.open > .nav-group-toggle .caret { transform: rotate(180deg); }
.nav-group-link:hover, .nav-group-toggle:hover { background: var(--mc-sidebar-active); color: var(--mc-primary); }
.nav-group.active > .nav-group-toggle { color: var(--mc-primary); }
.nav-group-link.active { background: var(--mc-primary); color: #fff; }
.nav-submenu { display: grid; grid-template-rows: 0fr; transition: grid-template-rows .22s ease; }
.nav-group.open > .nav-submenu { grid-template-rows: 1fr; }
.nav-submenu-inner { overflow: hidden; min-height: 0; }
.flyout-title { display: none; }
.nav-sub-link { display: flex; align-items: center; gap: .6rem; padding: .45rem .75rem .45rem 1.1rem; margin: 1px 0 1px 1.4rem; border-radius: 8px; color: var(--mc-sidebar-link); font-size: .83rem; font-weight: 500; white-space: nowrap; position: relative; transition: background .15s, color .15s; }
.nav-sub-link::before { content: ""; position: absolute; left: -.55rem; top: 50%; width: 6px; height: 6px; border-radius: 50%; background: var(--mc-border); transform: translateY(-50%); transition: background .15s; }
.nav-sub-link i { font-size: .95rem; width: 18px; text-align: center; opacity: .8; }
.nav-sub-link:hover { background: var(--mc-sidebar-active); color: var(--mc-primary); }
.nav-sub-link.active { background: var(--mc-primary); color: #fff; }
.nav-sub-link.active::before, .nav-sub-link:hover::before { background: var(--mc-primary); }
.nav-sub-link.active i { opacity: 1; }
.sidebar-footer { padding: .5rem .75rem; border-top: 1px solid var(--mc-border); white-space: nowrap; display: flex; align-items: center; justify-content: space-between; }
.btn-collapse { width: 30px; height: 30px; font-size: .9rem; }
.main-content { margin-left: var(--mc-sidebar-w); padding-top: var(--mc-topbar-h); min-height: 100vh; transition: margin .2s; }
/* Icons-only mode (desktop) with hover flyouts */
html.sb-collapsed .sidebar { width: var(--mc-sidebar-w-collapsed); }
html.sb-collapsed .main-content { margin-left: var(--mc-sidebar-w-collapsed); }
html.sb-collapsed .sidebar-nav { overflow: visible; }
html.sb-collapsed .nav-group-toggle span, html.sb-collapsed .nav-group-link span, html.sb-collapsed .nav-group-toggle .caret, html.sb-collapsed .sidebar-footer span { display: none; }
html.sb-collapsed .nav-group-toggle, html.sb-collapsed .nav-group-link { justify-content: center; padding: .65rem; }
html.sb-collapsed .sidebar-footer { justify-content: center; }
html.sb-collapsed .btn-collapse i { transform: rotate(180deg); }
html.sb-collapsed .nav-group { position: relative; }
html.sb-collapsed .nav-group.active > .nav-group-toggle { background: var(--mc-sidebar-active); }
html.sb-collapsed .nav-submenu { display: none; position: absolute; left: calc(100% + 6px); top: 0; min-width: 230px; background: var(--mc-card-bg); border: 1px solid var(--mc-border); border-radius: 12px; box-shadow: 0 12px 30px rgba(0,0,0,.14); padding: .4rem; z-index: 1050; }
html.sb-collapsed .nav-submenu::before { content: ""; position: absolute; left: -8px; top: 0; bottom: 0; width: 8px; }
html.sb-collapsed .nav-group:hover > .nav-submenu { display: block; }
html.sb-collapsed .nav-submenu-inner { overflow: visible; }
html.sb-collapsed .flyout-title { display: block; font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--mc-text-muted); padding: .35rem .75rem .25rem; }
html.sb-collapsed .nav-sub-link { margin: 1px 0; padding: .45rem .75rem; }
html.sb-collapsed .nav-sub-link::before { display: none; }
/* Mobile: off-canvas */
.sidebar-backdrop { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 1034; }
@media (max-width: 991.98px) {
  .sidebar { transform: translateX(-100%); width: var(--mc-sidebar-w) !important; box-shadow: 0 0 30px rgba(0,0,0,.2); }
  html.sb-open .sidebar { transform: translateX(0); }
  html.sb-open .sidebar-backdrop { display: block; }
  html.sb-collapsed .nav-group-toggle span, html.sb-collapsed .nav-group-link span, html.sb-collapsed .nav-group-toggle .caret { display: inline; }
  html.sb-collapsed .nav-group-toggle, html.sb-collapsed .nav-group-link { justify-content: flex-start; padding: .6rem .75rem; }
  html.sb-collapsed .nav-submenu { display: grid; position: static; min-width: 0; background: transparent; border: 0; box-shadow: none; padding: 0; }
  html.sb-collapsed .nav-group:not(.open) > .nav-submenu { grid-template-rows: 0fr; }
  html.sb-collapsed .nav-submenu-inner { overflow: hidden; }
  html.sb-collapsed .flyout-title { display: none; }
  html.sb-collapsed .nav-sub-link { margin: 1px 0 1px 1.4rem; padding: .45rem .75rem .45rem 1.1rem; }
  html.sb-collapsed .nav-sub-link::before { display: block; }
  .main-content { margin-left: 0 !important; }
}
/* Cards */
.card { background: var(--mc-card-bg); border: 1px solid var(--mc-border); border-radius: 14px; box-shadow: 0 1px 2px rgba(16,24,40,.04); }
.card-header { background: transparent; border-bottom: 1px solid var(--mc-border); font-weight: 600; padding: .85rem 1.1rem; }
.card-header .card-title { margin: 0; font-size: 1rem; }
.stat-card { display: flex; align-items: center; gap: 1rem; padding: 1rem 1.1rem; height: 100%; }
.stat-card .stat-icon { width: 48px; height: 48px; border-radius: 12px; display: inline-flex; align-items: center; justify-content: center; font-size: 1.35rem; flex-shrink: 0; }
.stat-card .stat-label { font-size: .78rem; color: var(--mc-text-muted); text-transform: uppercase; letter-spacing: .03em; font-weight: 600; }
.stat-card .stat-value { font-size: 1.3rem; font-weight: 700; line-height: 1.2; }
.stat-card .stat-sub { font-size: .75rem; color: var(--mc-text-muted); }
.bg-soft-primary { background: rgba(31,78,156,.12); color: var(--mc-primary); }
.bg-soft-success { background: rgba(25,135,84,.12); color: #198754; }
.bg-soft-warning { background: rgba(255,153,0,.14); color: #c77700; }
.bg-soft-danger { background: rgba(220,53,69,.12); color: #dc3545; }
.bg-soft-info { background: rgba(13,110,253,.1); color: #0d6efd; }
.bg-soft-purple { background: rgba(111,66,193,.12); color: #6f42c1; }
.bg-soft-teal { background: rgba(32,201,151,.14); color: #138f6b; }
.bg-soft-dark { background: rgba(33,37,41,.1); color: #212529; }
[data-bs-theme="dark"] .bg-soft-dark { color: #dde3ee; }
.section-title { font-size: .8rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--mc-text-muted); margin: 1.25rem 0 .6rem; }

/* Page header */
.page-header { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .75rem; margin-bottom: 1rem; }
.page-header h1 { font-size: 1.35rem; font-weight: 700; margin: 0; }
.page-header .breadcrumb { margin: 0; font-size: .8rem; }

/* Tables */
.table { --bs-table-bg: transparent; margin-bottom: 0; }
.table thead th { font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--mc-text-muted); font-weight: 600; border-bottom: 1px solid var(--mc-border); white-space: nowrap; background: var(--mc-card-bg); }
.table td { vertical-align: middle; border-color: var(--mc-border); }
.table-hover tbody tr:hover { background: var(--mc-sidebar-active); }
.table-responsive { border-radius: 14px; }
.badge-status { font-weight: 600; font-size: .7rem; padding: .35em .6em; border-radius: 6px; letter-spacing: .02em; }
.badge.text-bg-warning { color: #5c3d00 !important; }
.amount { font-variant-numeric: tabular-nums; white-space: nowrap; }
.text-overdue { color: #dc3545; font-weight: 600; }
.text-due-soon { color: #c77700; font-weight: 600; }
.row-overdue td:first-child { box-shadow: inset 3px 0 0 #dc3545; }
.row-due-soon td:first-child { box-shadow: inset 3px 0 0 #ffc107; }

/* Forms */
.form-label { font-weight: 600; font-size: .8rem; color: var(--mc-text-muted); margin-bottom: .3rem; }
.form-control, .form-select { border-radius: 8px; border-color: var(--mc-border); }
.form-control:focus, .form-select:focus { border-color: var(--mc-primary); box-shadow: 0 0 0 .2rem rgba(31,78,156,.12); }
.required::after { content: " *"; color: #dc3545; }
.btn { border-radius: 8px; font-weight: 500; }
.btn-primary { background: var(--mc-primary); border-color: var(--mc-primary); }
.btn-primary:hover { background: var(--mc-primary-dark); border-color: var(--mc-primary-dark); }
.btn-outline-primary { color: var(--mc-primary); border-color: var(--mc-primary); }
.btn-outline-primary:hover { background: var(--mc-primary); border-color: var(--mc-primary); }
.btn-whatsapp { background: #25d366; border-color: #25d366; color: #fff; }
.btn-whatsapp:hover { background: #1ebe5a; border-color: #1ebe5a; color: #fff; }
.ts-wrapper .ts-control { border-radius: 8px; border-color: var(--mc-border); padding: .42rem .75rem; }
.ts-dropdown { border-radius: 10px; z-index: 1060; }
.filter-bar .form-control, .filter-bar .form-select { min-width: 140px; }

/* Items editor */
.items-table th { font-size: .72rem; }
.items-table td { padding: .35rem; }
.items-table .form-control, .items-table .form-select { padding: .35rem .5rem; font-size: .85rem; }
.items-table textarea.form-control { min-height: 38px; resize: vertical; }
.totals-box .row { padding: .35rem 0; border-bottom: 1px dashed var(--mc-border); }
.totals-box .row:last-child { border-bottom: 0; }
.totals-box .grand { font-size: 1.25rem; font-weight: 700; }

/* Timeline */
.timeline { position: relative; padding-left: 1.4rem; }
.timeline::before { content: ""; position: absolute; left: 6px; top: 4px; bottom: 4px; width: 2px; background: var(--mc-border); }
.timeline-item { position: relative; padding-bottom: 1rem; }
.timeline-item::before { content: ""; position: absolute; left: -1.4rem; top: 5px; width: 14px; height: 14px; border-radius: 50%; background: var(--mc-primary); border: 3px solid var(--mc-card-bg); }
.timeline-item .time { font-size: .75rem; color: var(--mc-text-muted); }

/* Misc */
.nav-tabs .nav-link { color: var(--mc-text-muted); font-weight: 500; border: 0; border-bottom: 2px solid transparent; }
.nav-tabs .nav-link.active { color: var(--mc-primary); background: transparent; border-bottom-color: var(--mc-primary); }
.nav-pills .nav-link { border-radius: 8px; color: var(--mc-text-muted); font-weight: 500; }
.nav-pills .nav-link.active { background: var(--mc-primary); }
.list-group-item { background: transparent; border-color: var(--mc-border); }
.kpi-mini { font-size: .8rem; }
.kpi-mini b { font-size: 1rem; }
.empty-state { text-align: center; padding: 2.5rem 1rem; color: var(--mc-text-muted); }
.empty-state i { font-size: 2.5rem; display: block; margin-bottom: .5rem; opacity: .5; }
.dropdown-menu { border-radius: 10px; border-color: var(--mc-border); }
.modal-content { border-radius: 14px; border: 0; }
.modal-header { border-bottom-color: var(--mc-border); }
.modal-footer { border-top-color: var(--mc-border); }
.toast { border-radius: 10px; }
.cursor-pointer { cursor: pointer; }
.fs-7 { font-size: .8rem; }
.w-120 { width: 120px; }
.mw-200 { max-width: 200px; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
pre.code { background: var(--mc-bg); padding: .75rem; border-radius: 8px; font-size: .78rem; white-space: pre-wrap; word-break: break-all; }
.placeholder-chip { display: inline-block; background: var(--mc-sidebar-active); color: var(--mc-primary); font-size: .72rem; padding: .15rem .45rem; border-radius: 5px; margin: .1rem; cursor: pointer; font-family: monospace; }
.att-cell { width: 26px; height: 26px; display: inline-flex; align-items: center; justify-content: center; border-radius: 6px; font-size: .68rem; font-weight: 700; }
.progress { height: 8px; border-radius: 6px; }
.checkin-card { background: linear-gradient(135deg, var(--mc-primary), #3a7bd5); color: #fff; border: 0; }
.checkin-card .btn-light { color: var(--mc-primary); font-weight: 600; }
.quick-actions .btn { display: flex; flex-direction: column; align-items: center; gap: .3rem; padding: .8rem .5rem; font-size: .78rem; height: 100%; }
.quick-actions .btn i { font-size: 1.3rem; }
@media (max-width: 575.98px) {
  .stat-card .stat-value { font-size: 1.05rem; }
  .page-header h1 { font-size: 1.15rem; }
  .hide-xs { display: none !important; }
}
@media print {
  .topbar, .sidebar, .page-header .btn, .no-print { display: none !important; }
  .main-content { margin: 0; padding: 0; }
}

/* ===== Navy sidebar theme (light & dark) ===== */
:root { --sb-bg: #0f1f3d; --sb-bg-2: #142a52; --sb-border: rgba(255,255,255,.08); --sb-text: #b9c6df; --sb-text-strong: #ffffff; --sb-hover: rgba(255,255,255,.07); --sb-active: #2f6fe4; --sb-muted: #7f90b3; }
[data-bs-theme="dark"] { --sb-bg: #0a1529; --sb-bg-2: #10203c; --sb-border: rgba(255,255,255,.07); --sb-text: #aab7d0; --sb-active: #2f6fe4; }
.sidebar { background: linear-gradient(180deg, var(--sb-bg) 0%, var(--sb-bg-2) 100%); border-right: 1px solid var(--sb-border); }
.sidebar-nav { scrollbar-color: rgba(255,255,255,.2) transparent; }
.nav-group-link, .nav-group-toggle, .nav-sub-link { color: var(--sb-text); }
.nav-group-link:hover, .nav-group-toggle:hover, .nav-sub-link:hover { background: var(--sb-hover); color: var(--sb-text-strong); }
.nav-group.open > .nav-group-toggle { color: var(--sb-text-strong); }
.nav-group.active > .nav-group-toggle { color: var(--sb-text-strong); background: var(--sb-hover); }
.nav-group-link.active, .nav-sub-link.active { background: var(--sb-active); color: #fff; box-shadow: 0 4px 12px rgba(47,111,228,.35); }
.nav-sub-link::before { background: rgba(255,255,255,.18); }
.nav-sub-link.active::before, .nav-sub-link:hover::before { background: #fff; }
.nav-group-toggle .caret { opacity: .5; }
.nav-group.open > .nav-submenu { border-left: 0; }
.sidebar-footer { border-top: 1px solid var(--sb-border); color: var(--sb-muted) !important; }
.sidebar-footer .btn-icon { color: var(--sb-text); }
.sidebar-footer .btn-icon:hover { background: var(--sb-hover); color: #fff; }
/* collapsed flyout stays navy */
html.sb-collapsed .nav-submenu { background: var(--sb-bg-2); border-color: var(--sb-border); box-shadow: 0 14px 34px rgba(0,0,0,.35); }
html.sb-collapsed .flyout-title { color: var(--sb-muted); }
html.sb-collapsed .nav-group.active > .nav-group-toggle { background: var(--sb-hover); }
/* topbar stays light; brand aligns with navy */
.topbar .navbar-brand { color: #0f1f3d; }
[data-bs-theme="dark"] .topbar .navbar-brand { color: #e6edf9; }

/* ===== Sidebar: show full menu names ===== */
:root { --mc-sidebar-w: 262px; }
.nav-group-link, .nav-group-toggle { font-size: .84rem; padding: .58rem .7rem; gap: .6rem; }
.nav-group-link span, .nav-group-toggle span { white-space: normal; overflow: visible; text-overflow: clip; line-height: 1.2; }
.nav-group-toggle .caret { flex-shrink: 0; margin-left: .25rem; }
.nav-sub-link { white-space: normal; line-height: 1.2; }
.nav-sub-link span { overflow: visible; }
html.sb-collapsed .sidebar { width: var(--mc-sidebar-w-collapsed); }
@media (max-width: 991.98px) { .sidebar { width: var(--mc-sidebar-w) !important; } }

/* ===== Sidebar logout item ===== */
.nav-logout { margin-top: .5rem; border-top: 1px solid var(--sb-border); border-radius: 0 0 10px 10px; padding-top: .9rem !important; color: #ffb4b4 !important; }
.nav-logout:hover { background: rgba(220,53,69,.18) !important; color: #fff !important; }
html.sb-collapsed .nav-logout { border-radius: 10px; }

/* ===== Compact horizontal stat cards (fix: .card forces column direction) ===== */
.card.stat-card { flex-direction: row; align-items: center; text-align: left; padding: .65rem .9rem; gap: .75rem; height: 100%; min-height: 0; }
.card.stat-card .stat-icon { width: 40px; height: 40px; font-size: 1.15rem; border-radius: 10px; }
.card.stat-card .stat-label { font-size: .7rem; letter-spacing: .02em; line-height: 1.2; }
.card.stat-card .stat-value { font-size: 1.15rem; line-height: 1.2; }
.card.stat-card .stat-sub { font-size: .72rem; line-height: 1.2; }
.section-title { margin: .9rem 0 .45rem; }
