/* Inventory & Accounts – app styles
   Palette: ink blue sidebar, paper background, marigold "price tag" accent for money totals. */
:root {
  --ink: #14304a;
  --ink-2: #1d4264;
  --ink-soft: #2b5a86;
  --paper: #f3f5f8;
  --surface: #ffffff;
  --line: #dde3ea;
  --text: #1b2733;
  --muted: #5d6b7a;
  --tag: #f2b632;
  --tag-soft: #fff4d6;
  --ok: #1e7f5c;
  --danger: #b83227;
  --radius-lg: 12px;
  --radius: 8px;
  --sidebar-w: 236px;

  --bs-body-bg: var(--paper);
  --bs-body-color: var(--text);
  --bs-body-font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Helvetica Neue", Arial, sans-serif;
  --bs-body-font-size: .9375rem;
  --bs-border-color: var(--line);
  --bs-link-color: var(--ink-soft);
  --bs-link-color-rgb: 43, 90, 134;
  --bs-link-hover-color: var(--ink);
  --bs-primary: var(--ink-2);
  --bs-primary-rgb: 29, 66, 100;
  --bs-focus-ring-color: rgba(242, 182, 50, .45);
}

.btn-primary {
  --bs-btn-bg: var(--ink-2); --bs-btn-border-color: var(--ink-2);
  --bs-btn-hover-bg: var(--ink); --bs-btn-hover-border-color: var(--ink);
  --bs-btn-active-bg: var(--ink); --bs-btn-active-border-color: var(--ink);
  --bs-btn-disabled-bg: var(--ink-soft); --bs-btn-disabled-border-color: var(--ink-soft);
}
.btn-outline-primary {
  --bs-btn-color: var(--ink-2); --bs-btn-border-color: #b9c7d6;
  --bs-btn-hover-bg: var(--ink-2); --bs-btn-hover-border-color: var(--ink-2);
  --bs-btn-active-bg: var(--ink); --bs-btn-active-border-color: var(--ink);
}
.form-control:focus, .form-select:focus, .btn:focus-visible, .form-check-input:focus {
  border-color: #d9a12a;
  box-shadow: 0 0 0 .2rem rgba(242, 182, 50, .35);
}
a:focus-visible, .nav-link:focus-visible { outline: 3px solid var(--tag); outline-offset: 2px; }

.num, .table td.num, .table th.num { font-variant-numeric: tabular-nums; }
.table { --bs-table-bg: transparent; }

/* ---------- Shell ---------- */
.app { display: flex; min-height: 100vh; }
@media (min-width: 992px) { .app { background: linear-gradient(to right, var(--ink) var(--sidebar-w), transparent 0); } }
.sidebar {
  width: var(--sidebar-w); flex: 0 0 var(--sidebar-w);
  background: var(--ink); color: #c9d6e3;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  padding: 1rem .75rem 2rem;
}
.brand { display: flex; align-items: center; gap: .6rem; color: #fff; text-decoration: none; padding: .25rem .5rem 1rem; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 9px; flex: none;
  display: grid; place-items: center; background: var(--tag); color: var(--ink); font-size: 1.1rem;
}
.brand-name { font-weight: 650; line-height: 1.15; overflow: hidden; text-overflow: ellipsis; }
.nav-group { font-size: .78rem; color: #8ea4ba; padding: 1rem .6rem .3rem; font-weight: 600; }
.sidebar .nav-link {
  display: flex; align-items: center; gap: .65rem;
  color: #d3dee9; padding: .45rem .6rem; border-radius: var(--radius); font-size: .92rem;
}
.sidebar .nav-link i { font-size: 1.05rem; opacity: .8; }
.sidebar .nav-link:hover { background: rgba(255, 255, 255, .07); color: #fff; }
.sidebar .nav-link.active { background: var(--ink-2); color: #fff; box-shadow: inset 3px 0 0 var(--tag); }
.sidebar .nav-link.active i { color: var(--tag); opacity: 1; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: .75rem;
  padding: .7rem 1.5rem; background: var(--surface); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.page-title { font-size: 1.2rem; font-weight: 650; margin: 0; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-right { display: flex; align-items: center; gap: .6rem; }
.loc-switch { display: flex; align-items: center; gap: .35rem; }
.loc-switch label { color: var(--muted); }
.loc-switch select { min-width: 150px; font-weight: 600; }
.loc-badge { font-size: .85rem; font-weight: 600; color: var(--ink-2); background: #eaf0f6; border-radius: 99px; padding: .3rem .75rem; }
.btn-user { display: flex; align-items: center; gap: .45rem; border: 0; font-size: .9rem; }
.avatar { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: #e5ecf3; color: var(--ink-2); font-weight: 700; font-size: .85rem; }
.btn-icon { border: 0; background: transparent; color: var(--muted); padding: .25rem .45rem; font-size: 1.15rem; line-height: 1; }
.btn-icon:hover { color: var(--text); background: #eef2f6; }
.content { padding: 1.5rem; max-width: 1480px; width: 100%; }

.sidebar-backdrop { display: none; }
@media (max-width: 991.98px) {
  .sidebar { position: fixed; left: 0; top: 0; z-index: 1040; transform: translateX(-100%); transition: transform .2s ease; }
  .sidebar.open { transform: none; }
  .sidebar-backdrop.show { display: block; position: fixed; inset: 0; background: rgba(10, 25, 40, .45); z-index: 1030; }
  .topbar { padding: .6rem 1rem; }
  .content { padding: 1rem; }
  .loc-switch select { min-width: 0; max-width: 140px; }
}

/* ---------- Building blocks ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); }
.panel > .table-responsive > .table, .panel > .table { margin-bottom: 0; }
.panel .table > :not(caption) > * > * { padding-left: 1rem; padding-right: 1rem; }
.panel .table thead th { font-size: .8rem; font-weight: 600; color: var(--muted); background: #f8fafc; border-bottom-color: var(--line); }
.panel .table tfoot th { background: #f8fafc; }
.panel-pad { padding: 1.25rem; }
.panel-head { display: flex; justify-content: space-between; align-items: baseline; padding: 1rem 1rem .6rem; }
.panel-head h2 { font-size: 1rem; font-weight: 650; margin: 0; }
.empty-note { color: var(--muted); padding: 1.5rem 1rem; margin: 0; }
.empty-state { text-align: center; padding: 4rem 1rem; }
.empty-state i { font-size: 2.4rem; color: var(--ink-soft); }
.empty-state h2 { font-size: 1.25rem; margin: .75rem 0 .35rem; }
.empty-state p { color: var(--muted); }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .75rem; margin-bottom: 1rem; }
.filters { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }
.filters .form-control, .filters .form-select { width: auto; min-width: 140px; }
.filters input[name=q] { min-width: 200px; }

.quick-actions { display: flex; flex-wrap: wrap; gap: .6rem; margin-bottom: 1.25rem; }
.quick-actions .btn-lg { font-size: 1rem; padding: .6rem 1.1rem; }

.stat-strip {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg);
  margin-bottom: 1.25rem; overflow: hidden;
}
.stat { display: flex; flex-direction: column; gap: .15rem; padding: 1rem 1.25rem; border-right: 1px solid var(--line); color: inherit; text-decoration: none; }
.stat:last-child { border-right: 0; }
.stat-lead { background: var(--ink); color: #fff; }
.stat-lead .stat-label, .stat-lead .stat-sub { color: #aac0d5; }
.stat-lead .stat-value { color: var(--tag); }
.stat-link:hover { background: #f7f9fb; }
.stat-label { font-size: .82rem; color: var(--muted); }
.stat-value { font-size: 1.35rem; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.stat-value small { font-size: .8rem; font-weight: 500; color: var(--muted); }
.stat-sub { font-size: .8rem; color: var(--muted); }
.stat-strip-sm .stat-value { font-size: 1.1rem; }
@media (max-width: 575.98px) { .stat { border-right: 0; border-bottom: 1px solid var(--line); } }

.low-list { list-style: none; padding: 0 1rem 1rem; margin: 0; }
.low-list li { display: flex; justify-content: space-between; gap: 1rem; padding: .45rem 0; border-bottom: 1px dashed var(--line); }
.low-list li:last-child { border-bottom: 0; }

.badge-wholesale { background: var(--tag-soft); color: #7a5300; border: 1px solid #f0d58f; }
.master-list { list-style: none; padding: 0; margin: 0; }
.master-list li { padding: .35rem 0; border-top: 1px solid var(--line); }
.pack-row { border: 1px solid var(--line); border-radius: var(--radius); padding: .75rem; margin-bottom: .75rem; background: #fafbfc; }
.form-actions { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; margin-top: 1.25rem; }

/* ---------- Sale / purchase / transfer screen ---------- */
.doc-grid { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 1.25rem; align-items: start; }
.doc-side { display: flex; flex-direction: column; gap: 1rem; position: sticky; top: 76px; }
@media (max-width: 1099.98px) { .doc-grid { grid-template-columns: minmax(0, 1fr); } .doc-side { position: static; } }
.doc-main { min-height: 420px; }

.item-search { position: relative; padding: 1rem; border-bottom: 1px solid var(--line); }
.item-search > i { position: absolute; left: 1.85rem; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 1.2rem; pointer-events: none; }
.item-search input { padding-left: 2.75rem; padding-right: 3.2rem; font-size: 1.05rem; }
.item-search kbd { position: absolute; right: 1.75rem; top: 50%; transform: translateY(-50%); background: #eef2f6; color: var(--muted); font-size: .72rem; }
.search-results {
  position: absolute; left: 1rem; right: 1rem; top: calc(100% - .6rem); z-index: 30;
  max-height: 340px; overflow-y: auto; display: none; box-shadow: 0 12px 28px rgba(20, 48, 74, .16); border-radius: var(--radius);
}
.search-results.show { display: block; }
.search-results .list-group-item { display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
.search-results .list-group-item small { display: block; color: var(--muted); font-size: .78rem; }
.search-results .list-group-item.active { background: var(--ink-2); border-color: var(--ink-2); }
.search-results .list-group-item.active small, .search-results .list-group-item.active .res-stock { color: #cfe0f0; }
.res-stock { font-size: .82rem; color: var(--ok); white-space: nowrap; font-variant-numeric: tabular-nums; }
.res-stock.out { color: var(--danger); }

.lines-table th { white-space: nowrap; }
.lines-table .col-unit { width: 150px; }
.lines-table .col-qty { width: 105px; }
.lines-table .col-price { width: 125px; }
.lines-table .col-amount { width: 120px; }
.lines-table .col-rm { width: 44px; }
.lines-table td { vertical-align: middle; }
.line-name { font-weight: 600; }
.line-meta { font-size: .8rem; color: var(--muted); }
.line-meta .short { color: var(--danger); font-weight: 600; }
.line-short { background: #fff6f5; }
.lines-table input.num { text-align: right; }
.lines-table .rm:hover { color: var(--danger); }
.bump { animation: bump .5s ease; }
@keyframes bump { from { background: var(--tag-soft); } to { background: transparent; } }
.empty-lines { color: var(--muted); text-align: center; padding: 3rem 1rem; margin: 0; }

.customer-info { font-size: .82rem; color: var(--muted); margin-top: .4rem; min-height: 1.2em; }
.level-pill { display: inline-block; font-size: .82rem; font-weight: 600; border-radius: 99px; padding: .28rem .7rem; background: #eaf0f6; color: var(--ink-2); }
.level-pill.wholesale { background: var(--tag-soft); color: #7a5300; }

/* The tally: the one loud element – a price-tag panel with the running total */
.tally {
  background: var(--ink); color: #dbe6f0; border-radius: var(--radius-lg);
  padding: 1.6rem 1.15rem 1rem; position: relative;
}
.tally::before {
  content: ""; position: absolute; top: 9px; left: 50%; margin-left: -6px; width: 12px; height: 12px; border-radius: 50%;
  background: var(--paper); box-shadow: inset 0 0 0 2px rgba(0, 0, 0, .15);
}
.tally-row { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: .3rem 0; font-size: .9rem; }
.tally-row label { margin: 0; }
.tally-row .form-control, .tally-row .form-select { width: 150px; background: rgba(255, 255, 255, .95); }
.tally-row[hidden] { display: none; }
.tally-total {
  display: flex; justify-content: space-between; align-items: baseline;
  margin: .5rem -1.15rem; padding: .7rem 1.15rem; background: var(--tag); color: var(--ink);
}
.tally-total span:first-child { font-weight: 600; }
.tally-total .num { font-size: 1.9rem; font-weight: 800; letter-spacing: -.02em; }
.save-btn { padding: .8rem; font-weight: 600; }
.save-btn kbd { background: rgba(255, 255, 255, .18); font-size: .7rem; margin-left: .4rem; }

.transfer-route { display: flex; flex-direction: column; align-items: flex-start; gap: .4rem; }
.transfer-route > i { color: var(--muted); padding-left: .2rem; }

/* ---------- Invoices & statements ---------- */
.invoice { max-width: 900px; }
.invoice-head { display: flex; justify-content: space-between; gap: 1rem; padding-bottom: 1rem; border-bottom: 3px solid var(--ink); margin-bottom: 1rem; }
.invoice-company { font-size: 1.35rem; font-weight: 750; color: var(--ink); }
.invoice-title { font-size: 1.05rem; font-weight: 600; color: var(--muted); }
.invoice-parties { display: flex; justify-content: space-between; gap: 1rem; margin-bottom: 1.25rem; }
.invoice-table thead th { font-size: .8rem; color: var(--muted); border-bottom: 2px solid var(--line); }
.invoice-foot { display: flex; justify-content: space-between; gap: 1.5rem; flex-wrap: wrap; }
.invoice-totals { min-width: 260px; margin-left: auto; }
.invoice-totals td { padding: .25rem 0; }
.invoice-totals td.num { text-align: right; padding-left: 2rem; }
.invoice-totals .grand td { font-size: 1.15rem; font-weight: 750; border-top: 2px solid var(--ink); padding-top: .5rem; }
.signatures { display: flex; justify-content: space-between; gap: 3rem; margin-top: 4rem; }
.signatures div { flex: 1; border-top: 1px solid #000; padding-top: .3rem; font-size: .85rem; }
.print-only { display: none; }

.report-tabs { margin-bottom: 1rem; }
.report-tabs .nav-link { color: var(--muted); }
.report-tabs .nav-link.active { color: var(--ink); font-weight: 600; }
.pl-statement { max-width: 640px; }
.pl-net th { font-size: 1.15rem; border-top: 2px solid var(--ink); background: var(--tag-soft); }

/* ---------- Login ---------- */
.login-page {
  min-height: 100vh; display: grid; place-items: center; padding: 1rem;
  background: var(--ink) linear-gradient(135deg, var(--ink) 0%, var(--ink-2) 100%);
}
.login-card { width: 100%; max-width: 400px; background: var(--surface); border-radius: 16px; padding: 2rem; box-shadow: 0 24px 60px rgba(0, 0, 0, .25); }
.login-brand { display: flex; align-items: center; gap: .75rem; margin-bottom: .5rem; }
.login-brand h1 { font-size: 1.35rem; font-weight: 700; margin: 0; }

/* ---------- Print ---------- */
@media print {
  @page { margin: 12mm; }
  body { background: #fff; font-size: 12px; }
  .sidebar, .topbar, .toolbar, .filters, .report-tabs, .alert, .btn { display: none !important; }
  .content { padding: 0; max-width: none; }
  .panel { border: 0; }
  .panel-pad { padding: 0; }
  .print-only { display: block; }
  .signatures.print-only { display: flex; }
  .stat-strip { border: 1px solid #999; }
  .stat-lead { background: #fff; color: #000; }
  .stat-lead .stat-value { color: #000; }
  a { color: #000; text-decoration: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
