/* =========================================================
   Hakim ERP — Application Styles
   Light + Dark themes via CSS variables
   ========================================================= */

:root {
  --sidebar-width: 260px;
  --topbar-height: 60px;

  --brand-600: #0e6bb8;
  --brand-700: #0b5a9c;
  --brand-800: #094a82;

  --bg-body: #f4f6fb;
  --bg-sidebar: #0f1c2e;
  --bg-sidebar-hover: rgba(255,255,255,.06);
  --bg-topbar: #ffffff;
  --bg-card: #ffffff;
  --bg-input: #ffffff;
  --border: #e2e8f0;
  --text-primary: #1e293b;
  --text-muted: #64748b;
  --text-sidebar: #a7b8cc;
  --shadow-sm: 0 1px 2px rgba(16,24,40,.06);
  --shadow-md: 0 4px 16px rgba(16,24,40,.08);
}

[data-theme="dark"] {
  --bg-body: #0d1421;
  --bg-sidebar: #0a111c;
  --bg-topbar: #111a29;
  --bg-card: #131d2e;
  --bg-input: #0f1830;
  --border: #223049;
  --text-primary: #e5ecf5;
  --text-muted: #8fa3bd;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.3);
  --shadow-md: 0 4px 16px rgba(0,0,0,.35);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Inter", "Noto Sans Bengali", "SolaimanLipi", "Segoe UI", sans-serif;
  background: var(--bg-body);
  color: var(--text-primary);
  font-size: .875rem;
  transition: background .2s;
}

/* ---------- Layout ---------- */
.app-wrapper { display: flex; min-height: 100vh; }
.main-wrapper {
  flex: 1; min-width: 0; display: flex; flex-direction: column;
  margin-left: var(--sidebar-width);
  transition: margin-left .25s ease;
}
.main-content { padding: 1.25rem; flex: 1; }

/* ---------- Collapsed sidebar (desktop) ---------- */
body.sidebar-collapsed .sidebar { transform: translateX(-100%); }
body.sidebar-collapsed .main-wrapper { margin-left: 0; }

/* ---------- Sidebar ---------- */
.sidebar {
  width: var(--sidebar-width);
  background: linear-gradient(180deg, var(--bg-sidebar) 0%, #0b1526 100%);
  color: var(--text-sidebar);
  display: flex;
  flex-direction: column;
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 1040;
  transition: transform .25s ease;
}
.sidebar-brand {
  height: var(--topbar-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1rem;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.brand-icon {
  width: 34px; height: 34px;
  display: inline-flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--brand-600), #28a0e0);
  color: #fff; border-radius: 9px; font-size: 1.05rem;
  margin-right: .6rem;
}
.brand-text { color: #fff; font-weight: 700; font-size: 1rem; white-space: nowrap; }
.sidebar-close { color: var(--text-sidebar); }

.sidebar-search { padding: .75rem .9rem; }
.sidebar-search .input-group-text {
  background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.08);
  color: var(--text-sidebar); border-right: 0;
}
.sidebar-search .form-control {
  background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.08);
  color: #fff; border-left: 0; font-size: .8rem;
}
.sidebar-search .form-control::placeholder { color: #6b7c93; }
.sidebar-search .form-control:focus { box-shadow: none; background: rgba(255,255,255,.12); }

.sidebar-nav { flex: 1; overflow-y: auto; padding: .35rem .6rem 1rem; }
.sidebar-nav::-webkit-scrollbar { width: 5px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,.15); border-radius: 3px; }

.menu-item { margin-bottom: .15rem; }
.menu-link {
  display: flex; align-items: center; gap: .65rem;
  color: var(--text-sidebar); text-decoration: none;
  padding: .55rem .7rem; border-radius: 8px;
  font-size: .84rem; transition: background .15s, color .15s;
}
.menu-link:hover { background: var(--bg-sidebar-hover); color: #fff; }
.menu-link.active { background: var(--brand-600); color: #fff; }
.menu-link i:first-child { font-size: 1rem; width: 18px; text-align: center; }
.menu-arrow { transition: transform .2s; font-size: .7rem !important; width: auto !important; }
.menu-item.open > .menu-link .menu-arrow { transform: rotate(180deg); }

.submenu { display: none; padding-left: .4rem; }
.submenu.show { display: block; }
.submenu-link {
  display: flex; align-items: center; gap: .6rem;
  color: var(--text-sidebar); text-decoration: none;
  padding: .42rem .7rem .42rem 1.55rem; border-radius: 7px;
  font-size: .8rem; border-left: 2px solid transparent;
}
.submenu-link:hover { background: var(--bg-sidebar-hover); color: #fff; }
.submenu-link.active { color: #fff; border-left-color: var(--brand-600); background: rgba(255,255,255,.05); }
.submenu-link i { font-size: .85rem; width: 14px; text-align: center; }

.sidebar-footer { padding: .7rem 1rem; border-top: 1px solid rgba(255,255,255,.08); }
.sidebar-version { font-size: .72rem; color: #5c6f8a; }

.sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 1039; }

/* ---------- Topbar ---------- */
.topbar {
  height: var(--topbar-height);
  background: var(--bg-topbar);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: .75rem;
  padding: 0 1.25rem; position: sticky; top: 0; z-index: 1020;
}
.topbar-btn {
  color: var(--text-primary); border: 1px solid var(--border);
  border-radius: 9px; width: 38px; height: 38px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 1.05rem; background: var(--bg-input);
}
.topbar-btn:hover { color: var(--brand-600); }
.topbar-user { text-decoration: none; color: var(--text-primary); border: 1px solid var(--border); border-radius: 9px; padding: .3rem .55rem; background: var(--bg-input); }
.avatar { width: 34px; height: 34px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-weight: 700; }

/* ---------- Cards & KPI ---------- */
.card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 14px; box-shadow: var(--shadow-sm);
}
.card-header {
  background: transparent; border-bottom: 1px solid var(--border);
  font-weight: 600; padding: .85rem 1.1rem;
}
.card-header .card-title { margin: 0; font-size: .95rem; }
.card-body { padding: 1.1rem; }

.kpi-card { position: relative; overflow: hidden; transition: transform .15s, box-shadow .15s; }
.kpi-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.kpi-card .kpi-icon {
  width: 48px; height: 48px; border-radius: 12px;
  display: inline-flex; align-items: center; justify-content: center; font-size: 1.4rem;
}
.kpi-card .kpi-value { font-size: 1.35rem; font-weight: 700; line-height: 1.2; }
.kpi-card .kpi-label { font-size: .76rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .02em; }
.kpi-card .kpi-trend { font-size: .72rem; }
.kpi-card .kpi-trend.up { color: #16a34a; }
.kpi-card .kpi-trend.down { color: #dc2626; }

.bg-soft-primary { background: rgba(14,107,184,.12); color: var(--brand-700); }
.bg-soft-success { background: rgba(22,163,74,.12); color: #16a34a; }
.bg-soft-danger { background: rgba(220,38,38,.12); color: #dc2626; }
.bg-soft-warning { background: rgba(234,179,8,.15); color: #b45309; }
.bg-soft-info { background: rgba(6,182,212,.12); color: #0891b2; }
.bg-soft-purple { background: rgba(139,92,246,.12); color: #7c3aed; }

/* ---------- Tables ---------- */
.table { --bs-table-bg: transparent; color: var(--text-primary); }
.table thead th {
  background: var(--bg-body); color: var(--text-muted);
  font-size: .72rem; text-transform: uppercase; letter-spacing: .03em;
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
.table td { vertical-align: middle; border-color: var(--border); }
.dataTables_wrapper .dataTables_filter input, .dataTables_wrapper .dataTables_length select {
  background: var(--bg-input); border: 1px solid var(--border); color: var(--text-primary);
  border-radius: 8px; padding: .3rem .5rem; font-size: .85rem;
}
.table-responsive { border-radius: 10px; }

/* ---------- Forms ---------- */
.form-label { font-size: .8rem; font-weight: 600; color: var(--text-primary); margin-bottom: .3rem; }
.form-control, .form-select {
  background: var(--bg-input); border: 1px solid var(--border);
  color: var(--text-primary); border-radius: 9px; font-size: .875rem;
  padding: .42rem .7rem;
}
.form-control:focus, .form-select:focus {
  border-color: var(--brand-600); box-shadow: 0 0 0 .18rem rgba(14,107,184,.15);
  background: var(--bg-input); color: var(--text-primary);
}
.form-control::placeholder { color: var(--text-muted); opacity: .7; }
.required-mark { color: #dc2626; }
.form-section-title {
  font-size: .82rem; font-weight: 700; color: var(--brand-700);
  text-transform: uppercase; letter-spacing: .04em;
  border-bottom: 1px solid var(--border); padding-bottom: .45rem; margin-bottom: 1rem;
  display: flex; align-items: center; gap: .5rem;
}

/* ---------- Select2 ---------- */
.select2-container--bootstrap-5 .select2-selection {
  background: var(--bg-input); border: 1px solid var(--border);
  border-radius: 9px; min-height: 36px;
}
.select2-container--bootstrap-5 .select2-selection--single .select2-selection__rendered { line-height: 34px; color: var(--text-primary); }
.select2-container--bootstrap-5 .select2-selection__placeholder { color: var(--text-muted); }
.select2-dropdown { background: var(--bg-card); border-color: var(--border); color: var(--text-primary); }
.select2-container--bootstrap-5 .select2-results__option--highlighted { background: var(--brand-600); }

/* ---------- Badges ---------- */
.badge { font-weight: 600; padding: .4em .65em; }

/* ---------- Page header ---------- */
.page-header { display: flex; flex-wrap: wrap; align-items: center; gap: .75rem; margin-bottom: 1.1rem; }
.page-header h4 { margin: 0; font-weight: 700; }
.page-header .breadcrumb { margin: 0; font-size: .78rem; }

/* ---------- Buttons ---------- */
.btn { border-radius: 9px; font-size: .85rem; font-weight: 600; }
.btn-primary { background: var(--brand-600); border-color: var(--brand-600); }
.btn-primary:hover { background: var(--brand-700); border-color: var(--brand-700); }
.btn-outline-primary { color: var(--brand-600); border-color: var(--brand-600); }
.btn-outline-primary:hover { background: var(--brand-600); border-color: var(--brand-600); }

/* ---------- Invoice line editor ---------- */
.invoice-editor .inv-row input, .invoice-editor .inv-row select { min-width: 0; }

/* ---------- Misc ---------- */
.text-muted { color: var(--text-muted) !important; }
.page-title { font-size: 1.05rem; font-weight: 700; }
.empty-state { text-align: center; padding: 3rem 1rem; color: var(--text-muted); }
.empty-state i { font-size: 3rem; opacity: .35; display: block; margin-bottom: .75rem; }
.pagination .page-link { background: var(--bg-card); border-color: var(--border); color: var(--text-primary); }
.pagination .page-item.active .page-link { background: var(--brand-600); border-color: var(--brand-600); }
.dropdown-menu { background: var(--bg-card); border-color: var(--border); }
.dropdown-item { color: var(--text-primary); }
.dropdown-item:hover { background: var(--bg-body); }
.modal-content { background: var(--bg-card); color: var(--text-primary); }
.table-dark { --bs-table-bg: var(--bg-sidebar); }
a { color: var(--brand-600); }

/* ---------- Print ---------- */
@media print {
  .sidebar, .topbar, .no-print, .sidebar-overlay { display: none !important; }
  .main-wrapper { margin-left: 0; }
  .main-content { padding: 0; }
  body { background: #fff; }
  .card { border: none; box-shadow: none; }
}

/* ---------- Responsive ---------- */
@media (max-width: 991.98px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.show { display: block; }
  .main-wrapper { margin-left: 0; }
}

@media (max-width: 767.98px) {
  .main-content { padding: .85rem; }
  .kpi-value { font-size: 1.1rem !important; }
}
