/* =====================================================================
   Britix Sales - styles
   Works with Bootstrap 5.3 light & dark mode (data-bs-theme).
   ===================================================================== */

:root {
  --sidebar-w: 240px;
  --sidebar-bg: #1d2d3a;
  --sidebar-hover: #2a3f50;
  --brand: #1d2d3a;
  --bs-primary: #1d2d3a;
  --bs-primary-rgb: 29, 45, 58;
  --bs-link-color: #1d2d3a;
  --bs-link-color-rgb: 29, 45, 58;
}
[data-bs-theme="dark"] {
  --sidebar-bg: #1d2d3a;
  --sidebar-hover: #2a3f50;
  --bs-primary: #4f7391;
  --bs-primary-rgb: 79, 115, 145;
  --bs-link-color: #8fb0cb;
  --bs-link-color-rgb: 143, 176, 203;
}
.btn-primary {
  --bs-btn-bg: #1d2d3a; --bs-btn-border-color: #1d2d3a;
  --bs-btn-hover-bg: #2a3f50; --bs-btn-hover-border-color: #2a3f50;
  --bs-btn-active-bg: #15212b; --bs-btn-active-border-color: #15212b;
  --bs-btn-disabled-bg: #1d2d3a; --bs-btn-disabled-border-color: #1d2d3a;
}
.btn-outline-primary {
  --bs-btn-color: #1d2d3a; --bs-btn-border-color: #1d2d3a;
  --bs-btn-hover-bg: #1d2d3a; --bs-btn-hover-border-color: #1d2d3a;
  --bs-btn-active-bg: #1d2d3a; --bs-btn-active-border-color: #1d2d3a;
}
[data-bs-theme="dark"] .btn-outline-primary { --bs-btn-color: #8fb0cb; --bs-btn-border-color: #4f7391; }
.form-check-input:checked { background-color: #1d2d3a; border-color: #1d2d3a; }

body { background: var(--bs-tertiary-bg); font-size: .925rem; }

.app-wrap { display: flex; min-height: 100vh; }

/* ---------- Sidebar ---------- */
.sidebar {
  width: var(--sidebar-w); background: var(--sidebar-bg); color: #cbd5e1;
  position: fixed; inset: 0 auto 0 0; display: flex; flex-direction: column;
  z-index: 1040; transition: transform .2s ease;
}
.sidebar-brand {
  display: flex; align-items: center; gap: .6rem; padding: 1rem 1.1rem;
  color: #fff; text-decoration: none; border-bottom: 1px solid rgba(255,255,255,.07);
}
.sidebar-brand img { max-height: 34px; max-width: 60px; object-fit: contain; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 8px; background: var(--brand);
  display: inline-flex; align-items: center; justify-content: center; font-size: 1.1rem; flex: none;
}
.brand-text { font-weight: 700; line-height: 1.15; font-size: .95rem; }
.sidebar-nav { padding: .75rem .6rem; flex: 1; overflow-y: auto; }
.sidebar-nav a {
  display: flex; align-items: center; gap: .7rem; padding: .6rem .8rem; margin-bottom: 2px;
  color: #cbd5e1; text-decoration: none; border-radius: 8px;
}
.sidebar-nav a i { font-size: 1.05rem; width: 1.2rem; text-align: center; }
.sidebar-nav a:hover { background: var(--sidebar-hover); color: #fff; }
.sidebar-nav a.active { background: rgba(255,255,255,.14); color: #fff; }
.brand-mark { border: 1px solid rgba(255,255,255,.25); }
.sidebar-foot { padding: .9rem 1.1rem; border-top: 1px solid rgba(255,255,255,.07); font-size: .85rem; }

.main { flex: 1; margin-left: var(--sidebar-w); min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 1020; display: flex; align-items: center;
  padding: .6rem 1.25rem; background: var(--bs-body-bg); border-bottom: 1px solid var(--bs-border-color);
}
.topbar-title { font-size: 1rem; }
.content { padding: 1.25rem; }

.sidebar-backdrop { display: none; }
@media (max-width: 991.98px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .sidebar.open + .sidebar-backdrop {
    display: block; position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 1030;
  }
  .main { margin-left: 0; }
  .content { padding: 1rem .75rem; }
}

/* ---------- Notification bell ---------- */
.notif-menu { width: 360px; max-width: calc(100vw - 24px); }
.notif-list { max-height: 360px; overflow-y: auto; }
.notif-item:hover { background: var(--bs-tertiary-bg); }

/* ---------- Cards & stats ---------- */
.card { border: 1px solid var(--bs-border-color); box-shadow: 0 1px 2px rgba(0,0,0,.03); }
.card-header { background: transparent; font-weight: 600; }
.stat-card .stat-label { font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--bs-secondary-color); }
.stat-card .stat-value { font-size: 1.35rem; font-weight: 700; line-height: 1.2; }
.stat-card .stat-icon {
  width: 42px; height: 42px; border-radius: 10px; display: flex; align-items: center; justify-content: center;
  font-size: 1.2rem; flex: none;
}
.chart-box { position: relative; height: 260px; }

/* ---------- Tables ---------- */
.table-sm td, .table-sm th { white-space: nowrap; vertical-align: middle; }
.table thead th { font-size: .75rem; text-transform: uppercase; letter-spacing: .02em; color: var(--bs-secondary-color); }
.table tfoot td, .table tfoot th { font-weight: 700; background: var(--bs-secondary-bg); }
.conv { color: var(--bs-secondary-color); font-style: italic; }  /* converted (not original) currency */
.money-neg, .text-loss { color: var(--bs-danger) !important; }
.text-profit { color: var(--bs-success) !important; }

/* ---------- Forms ---------- */
.form-label { font-weight: 500; font-size: .85rem; margin-bottom: .25rem; }
.calc-box { background: var(--bs-secondary-bg); border-radius: 10px; padding: 1rem; }
.calc-box .calc-row { display: flex; justify-content: space-between; padding: .2rem 0; }
.calc-box .calc-row + .calc-row { border-top: 1px dashed var(--bs-border-color); }
.filter-bar .form-control, .filter-bar .form-select { font-size: .85rem; }
.flatpickr-input[readonly] { background-color: var(--bs-body-bg); }
[data-bs-theme="dark"] .flatpickr-calendar { background: #1e293b; box-shadow: 0 4px 16px rgba(0,0,0,.5); }
[data-bs-theme="dark"] .flatpickr-calendar .flatpickr-day,
[data-bs-theme="dark"] .flatpickr-calendar .flatpickr-weekday,
[data-bs-theme="dark"] .flatpickr-calendar .flatpickr-month,
[data-bs-theme="dark"] .flatpickr-calendar .cur-month,
[data-bs-theme="dark"] .flatpickr-calendar .numInput { color: #e2e8f0; fill: #e2e8f0; }
[data-bs-theme="dark"] .flatpickr-day:hover { background: #334155; }
[data-bs-theme="dark"] .flatpickr-months .flatpickr-prev-month svg,
[data-bs-theme="dark"] .flatpickr-months .flatpickr-next-month svg { fill: #e2e8f0; }

/* ---------- Mobile (phones) ---------- */
.filter-toggle { display: none; }
@media (max-width: 767.98px) {
  body { font-size: .9rem; }
  .content { padding: .75rem .6rem; }
  .content .row:not([class*="g-"]):not([class*="gx-"]) { --bs-gutter-x: 1rem; }
  .topbar { padding: .5rem .6rem; gap: .25rem; }
  .topbar-title { font-size: .95rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  /* Dashboard stat cards: smaller icon + text so long amounts fit */
  .stat-card .card-body { gap: .6rem !important; padding: .75rem; flex-direction: column; }
  .stat-card .stat-icon { width: 32px; height: 32px; font-size: 1rem; }
  .stat-card .stat-value { font-size: 1.05rem; word-break: break-word; }
  .stat-card .stat-label { font-size: .7rem; }
  .chart-box { height: 220px; }

  /* Filters folded behind a "Filters" button */
  .filter-toggle { display: flex; }
  form.filter-bar.filters-collapsed > .row { display: none; }

  /* Wide data tables become stacked cards (labels added by app.js) */
  table.table-cards thead { display: none; }
  table.table-cards, table.table-cards tbody, table.table-cards tr, table.table-cards td { display: block; width: 100%; }
  table.table-cards tr { border-bottom: 6px solid var(--bs-tertiary-bg); padding: .4rem .5rem; }
  table.table-cards td {
    display: flex; justify-content: space-between; align-items: center; gap: .75rem;
    white-space: normal !important; text-align: right !important; border: 0; padding: .2rem .25rem !important;
  }
  table.table-cards td::before {
    content: attr(data-label); flex: none; text-align: left; font-size: .72rem; font-weight: 600;
    text-transform: uppercase; color: var(--bs-secondary-color);
  }
  table.table-cards td:not([data-label])::before, table.table-cards td[data-label=""]::before { content: none; }
  table.table-cards td:not([data-label]), table.table-cards td[data-label=""] { justify-content: flex-end; }
  table.table-cards td[colspan] { justify-content: center; text-align: center !important; }
  table.table-cards tfoot { display: block; }

  /* Generic: let long text wrap instead of pushing the page wider */
  .table-wrap-mobile td, .table-wrap-mobile th { white-space: normal !important; }
  .nav-tabs { flex-wrap: nowrap; overflow-x: auto; overflow-y: hidden; scrollbar-width: none; }
  .nav-tabs::-webkit-scrollbar { display: none; }
  .btn-group { flex-wrap: wrap; }
  .modal-dialog { margin: .5rem; }
}

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1rem; }
.login-card { width: 100%; max-width: 400px; }

/* ---------- Print (reports as PDF via browser print) ---------- */
@media print {
  @page { size: A4; margin: 12mm; }
  body { background: #fff !important; color: #000 !important; font-size: 11px; }
  .sidebar, .topbar, .sidebar-backdrop, .no-print, .btn, form.filter-bar, .alert, .pagination { display: none !important; }
  .main { margin: 0 !important; }
  .content { padding: 0 !important; }
  .card { box-shadow: none !important; border: 1px solid #bbb !important; break-inside: avoid; }
  .table { color: #000 !important; }
  .table td, .table th { padding: .2rem .35rem !important; }
  .print-header { border-bottom: 2px solid #000; margin-bottom: 10px; padding-bottom: 6px; }
  a { color: #000 !important; text-decoration: none !important; }
  .chart-box { height: 200px; }
  .table-responsive { overflow: visible !important; }
  .col-print-6 { width: 50% !important; float: left; }
}
