/* PaCare Pharmacy — the PaCare v4 look: flat blue masthead, horizontal module strip, K2D, dense slate-headed tables.
   Mobile-first; phone < 576, tablet 576–991, desktop >= 992 (README MOB-1). */
:root {
  /* PaCare palette */
  --blue: #007DCC; --blue-dark: #0063a3; --blue-wash: #eaf4fc; --blue-line: #b9dcf3;
  --ink: #0f1923; --ink-2: #2d3a46; --ink-3: #5a6a7a; --ink-4: #8494a4; --ink-faint: #c3ced9;
  --bg: #eef1f6; --surface: #ffffff; --surface-2: #f8fafc; --line: #dde3ea; --line-soft: #eef1f6;
  --ok: #0f766e; --ok-bg: #e6f4f1; --ok-line: #99d5cd; --wait: #92400e; --wait-bg: #fef3c7; --wait-line: #f3c98b;
  --urgent: #9b2424; --urgent-bg: #fdecea; --urgent-line: #f5c6c2; --idle: #5a6a7a; --idle-bg: #f1f5f9;
  --topbar-bg: #1c4cc3; --topbar-line: #163c9c;
  --radius: 10px; --radius-sm: 6px; --shadow: 0 1px 2px rgba(15,25,35,.04); --shadow-pop: 0 18px 45px rgba(0,0,0,.18);
  --topbar-h: 56px; --tabs-h: 42px; --bottombar-h: 60px;
  /* names the components below still use */
  --brand: var(--blue); --brand-dark: var(--blue-dark); --brand-soft: var(--blue-wash); --surface: #fff;
  --bs-primary: #007DCC; --bs-primary-rgb: 0, 125, 204; --bs-link-color: #007DCC; --bs-link-hover-color: #0063a3;
  --bs-body-font-family: 'K2D', system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
html { -webkit-text-size-adjust: 100%; scroll-behavior: auto !important; }   /* Bootstrap's smooth scroll lags keyboard-driven screens (and WebDriver clicks) */
body { background: var(--bg); color: var(--ink); min-height: 100vh; font-family: 'K2D', system-ui, sans-serif; font-size: 15px; -webkit-font-smoothing: antialiased; }
a { color: var(--blue); } a:hover { color: var(--blue-dark); }
.btn { border-radius: var(--radius-sm); font-weight: 600; }
.btn-primary { --bs-btn-bg: var(--blue); --bs-btn-border-color: var(--blue); --bs-btn-hover-bg: var(--blue-dark); --bs-btn-hover-border-color: var(--blue-dark);
  --bs-btn-active-bg: var(--blue-dark); --bs-btn-disabled-bg: var(--blue); --bs-btn-disabled-border-color: var(--blue); font-weight: 700; }
.btn-outline-primary { --bs-btn-color: var(--blue); --bs-btn-border-color: var(--blue); --bs-btn-hover-bg: var(--blue); --bs-btn-hover-border-color: var(--blue); --bs-btn-active-bg: var(--blue); }
.btn-outline-secondary { --bs-btn-color: var(--ink-2); --bs-btn-border-color: var(--line); --bs-btn-hover-bg: var(--surface-2); --bs-btn-hover-color: var(--ink); --bs-btn-hover-border-color: #c3ced9; background: var(--surface); }
.text-brand { color: var(--blue) !important; } .bg-brand { background: var(--blue) !important; }
.form-control, .form-select { border-color: var(--line); border-radius: var(--radius-sm); }
.form-control:focus, .form-select:focus, .form-check-input:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(0,125,204,.15); }
.form-check-input:checked { background-color: var(--blue); border-color: var(--blue); }
.form-label { font-size: 12px; font-weight: 600; color: var(--ink-3); text-transform: uppercase; letter-spacing: .3px; margin-bottom: .25rem; }
.page-link { color: var(--blue); } .active > .page-link { background: var(--blue); border-color: var(--blue); }

/* ---- masthead (PaCare .topbar) ---- */
.topbar { display: flex; align-items: center; gap: 12px; height: var(--topbar-h); padding: 0 16px; background: var(--topbar-bg);
  border-bottom: 2px solid var(--topbar-line); position: sticky; top: 0; z-index: 1030; color: #fff; }
.topbar .mark { width: 32px; height: 32px; border-radius: 9px; flex-shrink: 0; background: rgba(255,255,255,.94); color: var(--topbar-bg);
  display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 700; letter-spacing: -.4px; }
.topbar .mark-img { background: none; border-radius: 0; width: auto; height: 34px; max-width: 48px; object-fit: contain; }
.topbar .brand { color: #fff; font-size: 14px; font-weight: 700; line-height: 1.15; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .brand small { display: block; font-size: 10px; font-weight: 400; color: rgba(255,255,255,.78); letter-spacing: .3px; }
.topbar .spacer { margin-left: auto; }
.topbar .who { display: flex; align-items: center; gap: 9px; color: #fff; font-size: 12px; }
.topbar .who .me { display: flex; align-items: center; gap: 9px; color: inherit; text-decoration: none; }
.topbar .avatar { width: 29px; height: 29px; border-radius: 50%; background: rgba(255,255,255,.22); border: 1px solid rgba(255,255,255,.4);
  display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700; color: #fff; }
.topbar .who .name { font-weight: 600; line-height: 1.2; } .topbar .who .role { font-size: 10px; color: rgba(255,255,255,.78); letter-spacing: .3px; }
.topbar .signout { color: #fff; font-size: 12px; font-weight: 600; padding: 5px 11px; border-radius: 20px; background: rgba(255,255,255,.16);
  border: 1px solid rgba(255,255,255,.3); text-decoration: none; white-space: nowrap; }
.topbar .signout:hover { background: rgba(255,255,255,.26); color: #fff; }

/* ---- horizontal module strip (PaCare .tabs) ---- */
.tabs { background: var(--surface); border-bottom: 1px solid var(--line); padding: 0 18px; display: flex; gap: 2px; overflow-x: auto; overflow-y: hidden;
  position: sticky; top: var(--topbar-h); z-index: 1020; scrollbar-width: thin; min-height: var(--tabs-h); }
.tabs::-webkit-scrollbar { height: 3px; }
.tab { display: inline-flex; align-items: center; gap: 7px; white-space: nowrap; padding: 12px 14px; font-size: 12px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .4px; color: var(--ink-3); border-bottom: 3px solid transparent; text-decoration: none; }
.tab i { font-size: 14px; color: var(--ink-4); }
.tab:hover { color: var(--ink); text-decoration: none; background: var(--surface-2); }
.tab.on { color: var(--blue); border-bottom-color: var(--blue); } .tab.on i { color: var(--blue); }
.tab-sep { width: 1px; margin: 10px 6px; background: var(--line); flex-shrink: 0; }
.tabs .none { padding: 12px 14px; font-size: 12px; color: var(--ink-4); }
@media (max-width: 575.98px) { .tabs { padding: 0 6px; } .tab { padding: 11px 10px; font-size: 11px; } }

.main { padding: 18px 22px calc(var(--bottombar-h) + 24px); min-width: 0; max-width: 1600px; margin: 0 auto; }
@media (max-width: 575.98px) { .main { padding: 12px 12px calc(var(--bottombar-h) + 20px); } }
@media (min-width: 992px) { .main { padding-bottom: 48px; } }
.appfoot { display: flex; justify-content: space-between; gap: 12px; padding: 10px 22px; font-size: 12px; color: var(--ink-4); }
.appfoot .ver { margin-left: auto; }
@media (max-width: 991.98px) { .appfoot { display: none; } }

/* phone bottom bar (MOB-2): scrolling an element into view must clear it */
@media (max-width: 991.98px) { html { scroll-padding-bottom: calc(var(--bottombar-h) + 12px); scroll-padding-top: calc(var(--topbar-h) + var(--tabs-h) + 8px); } }

.bottom-bar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 1029; height: var(--bottombar-h); background: var(--surface);
  border-top: 1px solid var(--line); display: flex; padding-bottom: env(safe-area-inset-bottom); }
.bottom-bar a, .bottom-bar button { flex: 1; min-width: 0; border: 0; background: none; color: var(--ink-3); text-decoration: none;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: .68rem; }
.bottom-bar i { font-size: 1.35rem; line-height: 1; }
.bottom-bar .active { color: var(--blue); font-weight: 600; }
.bottom-bar span { max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 0 2px; }

/* ---- page furniture ---- */
.page-head { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem .75rem; margin-bottom: 14px; }
.page-head h1 { font-size: 21px; font-weight: 700; letter-spacing: -.3px; line-height: 1.2; margin: 0; flex: 1; min-width: 0; }
.card { border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); background: var(--surface); }
.card-header { background: var(--surface); font-size: 14px; font-weight: 700; letter-spacing: -.1px; border-bottom: 1px solid var(--line); border-radius: var(--radius) var(--radius) 0 0 !important; padding: 11px 16px; }
.stat { display: flex; align-items: center; gap: .85rem; padding: 1rem; color: inherit; text-decoration: none; height: 100%; }
.stat .icon { width: 44px; height: 44px; border-radius: .7rem; display: flex; align-items: center; justify-content: center;
  font-size: 1.35rem; background: var(--blue-wash); color: var(--blue); flex: none; }
.stat .icon.warn { background: #fef3c7; color: #b45309; } .stat .icon.danger { background: #fee2e2; color: #b91c1c; }
.stat .value { font-size: 1.4rem; font-weight: 700; line-height: 1.1; }
.stat .label { color: #6b7280; font-size: .8rem; }
a.stat:hover { background: var(--surface); border-radius: .75rem; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.badge-soft { background: var(--blue-wash); color: var(--blue-dark); border: 1px solid var(--blue-line); font-weight: 700; }
.badge-rx { background: #ede9fe; color: #5b21b6; } .badge-cd { background: #fee2e2; color: #991b1b; }
.badge-review { background: #fef3c7; color: #92400e; }
.muted { color: #6b7280; }

/* touch ergonomics (MOB-4): nothing smaller than 44px on a touch screen */
@media (pointer: coarse) {
  .btn, .form-control, .form-select, .page-link, .dropdown-item { min-height: 44px; }
  .btn { display: inline-flex; align-items: center; justify-content: center; gap: .35rem; }
  .btn-sm { min-height: 40px; }
  .form-check-input { width: 1.35em; height: 1.35em; margin-top: .1em; }
  .form-check-label { padding-left: .35rem; padding-top: .15rem; }
}
/* 16px inputs stop iOS zooming the page on focus */
@media (max-width: 575.98px) { .form-control, .form-select { font-size: 16px; } }

/* sticky primary action on phones */
.action-bar { display: flex; gap: .5rem; flex-wrap: wrap; }
@media (max-width: 575.98px) {
  .action-bar.sticky-phone { position: sticky; bottom: calc(var(--bottombar-h) + .5rem); z-index: 5; background: rgba(238,241,246,.95);
    padding: .5rem 0; backdrop-filter: blur(4px); }
  .card .action-bar.sticky-phone { background: rgba(255,255,255,.95); }
  .action-bar.sticky-phone .btn { flex: 1; }
}

/* ---- tables: PaCare .data-table look (dark slate header, hairline borders, cream zebra) ----
   <table class="table table-cards"> with data-label on each <td> for the phone card view. */
:root { --dt-head-bg: #2f3e4d; --dt-head-fg: #fff; --dt-head-line: #1e2a35; --dt-row-alt: #fdfaf0; --dt-row-hover: #eaf2fb; --dt-border: #729ea5; --dt-border-out: #d7dbe0; }
.table-cards-wrap { overflow: hidden; }
.table { --bs-table-bg: #fff; --bs-table-hover-bg: var(--dt-row-hover); --bs-table-striped-bg: var(--dt-row-alt); font-size: 12px; line-height: 1.35; color: #333; margin-bottom: 0; }
.table > :not(caption) > * > * { padding: 6px 10px; vertical-align: middle; border-bottom: 1px solid var(--dt-border); border-right: 1px solid var(--dt-border); }
.table > :not(caption) > * > *:last-child { border-right: 0; }
.table > tbody > tr:last-child > * { border-bottom: 0; }
.table thead th { font-size: 11px; text-transform: uppercase; letter-spacing: .4px; color: var(--dt-head-fg); font-weight: 600;
  background: var(--dt-head-bg); border-bottom: 1px solid var(--dt-head-line); border-right: 1px solid var(--dt-head-line); white-space: nowrap; }
.table tbody tr:nth-child(even) > * { background: var(--dt-row-alt); }
.table-hover > tbody > tr:hover > * { background: var(--dt-row-hover); }
.table tfoot th, .table tfoot td { background: var(--surface-2); border-top: 2px solid var(--dt-head-bg); }
.table .fw-semibold { color: var(--ink); }
.row-link { cursor: pointer; }
@media (max-width: 767.98px) {
  .table-cards thead { display: none; }
  .table-cards, .table-cards tbody, .table-cards tr, .table-cards td { display: block; width: 100%; }
  .table-cards tr { background: #fff !important; border: 1px solid var(--dt-border-out); border-radius: var(--radius); margin-bottom: .6rem; padding: .6rem .8rem; font-size: 13px; }
  .table-cards tr > * { background: #fff !important; }
  .table-cards td { border: 0 !important; padding: .12rem 0; display: flex; justify-content: space-between; gap: 1rem; text-align: right; }
  .table-cards td::before { content: attr(data-label); color: #6b7280; font-size: .78rem; text-align: left; flex: none; }
  .table-cards td.card-title-cell { display: block; text-align: left; font-weight: 600; font-size: 1rem; padding-bottom: .3rem; }
  .table-cards td.card-title-cell::before { content: none; }
  .table-cards td.card-hide, .table-cards td:empty { display: none; }
  .table-cards-wrap { background: none !important; border: 0 !important; box-shadow: none !important; }
}

/* ---- branding ---- */
.topbar-mark { height: 34px; width: auto; max-width: 44px; object-fit: contain; }
.login-brand { max-width: 260px; max-height: 110px; width: auto; height: auto; }
.brand-preview { width: 84px; height: 56px; border: 1px dashed #d1d5db; border-radius: .5rem; display: flex; align-items: center; justify-content: center; background: #fff; flex: none; }
.brand-preview.dark { background: var(--topbar-bg); } .brand-preview img { max-width: 76px; max-height: 48px; }

/* ---- modal (PaCare .modal-card) ---- */
.modal-pc { display: none; position: fixed; inset: 0; z-index: 2000; background: rgba(15,25,35,.45); padding: 20px; overflow-y: auto; }
.modal-pc.open { display: flex; align-items: flex-start; justify-content: center; }
.modal-card { background: var(--surface); border-radius: var(--radius); width: 100%; max-width: 880px; margin: auto; box-shadow: var(--shadow-pop); overflow: hidden; }
.modal-card.sm { max-width: 420px; } .modal-card.lg { max-width: 1020px; }
.modal-hd { padding: 14px 18px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 10px; }
.modal-hd h2 { font-size: 15px; font-weight: 700; margin: 0; }
.modal-x { margin-left: auto; border: none; background: none; cursor: pointer; font-size: 24px; line-height: 1; color: var(--ink-4); padding: 0 4px; }
.modal-x:hover { color: var(--ink); }
.modal-bd { padding: 16px 18px; max-height: calc(100vh - 220px); overflow-y: auto; }
.modal-ft { padding: 12px 18px; border-top: 1px solid var(--line); background: var(--surface-2); display: flex; gap: 9px; justify-content: flex-end; }

/* ---- login ---- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1rem;
  background: linear-gradient(160deg, rgba(28,76,195,.55) 0%, rgba(22,60,156,.55) 60%, rgba(15,45,117,.65) 100%),
              url("/static/img/login-bg.jpg") center / cover no-repeat fixed, #163c9c; }
@supports (-webkit-touch-callout: none) { .login-wrap { background-attachment: scroll; } } /* iOS ignores fixed */
.login-card { width: 100%; max-width: 400px; border: 0; border-radius: 1rem; box-shadow: 0 20px 50px rgba(0,0,0,.35);
  background: rgba(255,255,255,.94); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
.login-card .card-footer { background: transparent !important; }
.login-logo { width: 64px; height: 64px; border-radius: 1rem; }

/* ---- stock ---- */
.chips { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; }
.chip { display: inline-flex; align-items: center; gap: .4rem; padding: .4rem .75rem; border-radius: 999px; background: #fff; border: 1px solid #e5e7eb;
  color: #374151; text-decoration: none; font-size: .85rem; min-height: 38px; }
.chip strong { font-variant-numeric: tabular-nums; }
.chip.active { background: var(--blue); border-color: var(--blue); color: #fff; }
.chip.warn:not(.active) strong { color: #b45309; } .chip.danger:not(.active) strong { color: #b91c1c; }
.chip.plain { border-style: dashed; }
.exp { display: inline-block; padding: .1rem .5rem; border-radius: .4rem; font-size: .8rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.exp-OK { background: #dcfce7; color: #166534; } .exp-NEAR { background: #fef3c7; color: #92400e; }
.exp-EXPIRED { background: #fee2e2; color: #991b1b; } .exp-NONE { background: #f3f4f6; color: #6b7280; }
.typeahead { position: absolute; left: 0; right: 0; top: 100%; z-index: 20; max-height: 50vh; overflow-y: auto; box-shadow: 0 10px 30px rgba(0,0,0,.15); border-radius: .5rem; }
.typeahead .list-group-item.active { background: var(--blue); border-color: var(--blue); }
.entry { border-top: 1px dashed #d1d5db; padding-top: 1rem; }
/* while a line is being typed on a phone, the Save bar must not float over its fields */
#receive.entering .action-bar.sticky-phone { position: static; }
.muted-kbd { font-size: .7rem; opacity: .75; border: 1px solid currentColor; border-radius: .3rem; padding: 0 .3rem; margin-left: .3rem; }
.camera { position: fixed; inset: 0; z-index: 2000; background: #000; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1rem; }
.camera video { max-width: 100%; max-height: 80vh; }

/* ---- counter and cashier ---- */
.pos-line { background: #fff; border: 1px solid #e5e7eb; border-radius: .75rem; padding: .7rem .85rem; margin-bottom: .5rem; }
.pos-line.over { border-color: #fca5a5; background: #fef2f2; }
.pos-summary { position: sticky; top: calc(var(--topbar-h) + var(--tabs-h) + 1rem); }
.pos-total { font-size: 2.6rem; font-weight: 800; line-height: 1.1; text-align: right; font-variant-numeric: tabular-nums; color: var(--blue-dark); margin-bottom: .75rem; }
#pos.wholesale .pos-total { color: #7c2d12; }
.typeahead .out { opacity: .55; }
.border-rx { border-color: #c4b5fd !important; }
.pay-result .change, .pay-result .owing { display: flex; justify-content: space-between; align-items: baseline; padding: .6rem .8rem; border-radius: .6rem; font-size: 1.05rem; }
.pay-result .change { background: #dcfce7; color: #14532d; } .pay-result .owing { background: #fef3c7; color: #78350f; }
.pay-result strong { font-size: 1.6rem; font-variant-numeric: tabular-nums; }
tr.removed td { opacity: .5; text-decoration: line-through; } tr.removed td:last-child, tr.removed td .small { text-decoration: none; opacity: 1; }
.denomination { min-width: 4.6rem; justify-content: flex-end; font-variant-numeric: tabular-nums; }
@media (max-width: 991.98px) { .pos-summary { position: static; } .pos-total { font-size: 2.1rem; } }
/* phones: the total and the main actions stay in reach, just above the navigation bar */
.pos-mobile-bar { position: fixed; left: 0; right: 0; bottom: var(--bottombar-h); z-index: 1028; background: #fff; border-top: 1px solid #e5e7eb;
  box-shadow: 0 -4px 12px rgba(0,0,0,.06); display: flex; align-items: center; gap: .5rem; padding: .5rem .75rem; }
@media (max-width: 991.98px) { #pos { padding-bottom: 4.5rem; } }

/* offline banner (MOB-9) */
.offline-banner { display: none; position: fixed; top: calc(var(--topbar-h) + var(--tabs-h)); left: 0; right: 0; z-index: 1040; background: #b91c1c;
  color: #fff; text-align: center; font-size: .85rem; padding: .35rem; }
body.is-offline .offline-banner { display: block; }

.perm-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: .25rem 1rem; }
pre.audit-json { font-size: .75rem; margin: 0; white-space: pre-wrap; word-break: break-word; background: none; }
@media print {
  .topbar, .tabs, .bottom-bar, .appfoot, .no-print, .btn, .chips, .alert, .drawer, .btn-close { display: none !important; }
  .main { margin: 0; padding: 0; } body { background: #fff; }
  .print-head { border-bottom: 2px solid #000; margin-bottom: 8px; padding-bottom: 6px; font-size: 11px; line-height: 1.3; color: #000; }
  .ph-row { display: flex; align-items: center; gap: 12px; } .ph-logo { max-height: 18mm; max-width: 60mm; }
  .ph-biz { flex: 1; } .ph-name { font-size: 16px; font-weight: 700; letter-spacing: .02em; }
  .ph-meta { text-align: right; } .ph-title { font-size: 13px; font-weight: 700; }
  .card { border: 0; box-shadow: none; } .table { font-size: 11px; } .page-head h1 { font-size: 16px; }
  /* Firefox clips or pushes scrollable wrappers to a new page: print them as plain blocks */
  .table-responsive, .table-responsive-md, .table-responsive-lg, .table-cards-wrap { overflow: visible !important; }
  details, .pos-summary form, .card-body > form { display: none !important; } tr { page-break-inside: avoid; }
  /* paper is a table, never the phone card view, whatever the print width */
  .table-cards thead { display: table-header-group !important; } .table-cards { display: table !important; width: 100% !important; }
  .table-cards tbody { display: table-row-group !important; } .table-cards tr { display: table-row !important; border: 0 !important; margin: 0 !important; padding: 0 !important; font-size: 10.5px; }
  .table-cards td, .table-cards th { display: table-cell !important; width: auto !important; text-align: inherit; padding: 3px 5px !important; border-bottom: 1px solid #ccc !important; vertical-align: top; }
  .table-cards td::before { content: none !important; } .table-cards td.card-title-cell { font-weight: 500; font-size: inherit; }
  .table-cards td:empty { display: table-cell !important; } .table-cards td.num, .table-cards th.num { text-align: right; }
  .table-cards thead th { background: #eee !important; color: #000 !important; border-bottom: 1px solid #000 !important; font-size: 10px; }
}

/* ---- stock list ---- */
.stock-table tr.row-out td { background: #fff7f7; }
.stock-table td { vertical-align: top; }
