/* PharmLoop UI — Bootstrap 5 theme layer.
   --pl-primary / --pl-accent are injected from Settings in the layout <style>. */
:root {
  --pl-primary: #1F3A5F;
  --pl-accent: #1E9E8F;
  --pl-bg: #F4F6F9;
  --pl-surface: #FFFFFF;
  --pl-border: #E3E8EF;
  --pl-text: #1C2733;
  --pl-muted: #6B7785;
  --pl-sidebar-w: 256px;
  --pl-topbar-h: 64px;
  --pl-radius: 10px;
  --pl-shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 1px 3px rgba(16, 24, 40, .06);
  --bs-body-font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --bs-body-color: var(--pl-text);
  --bs-body-bg: var(--pl-bg);
  --bs-border-color: var(--pl-border);
  --bs-primary: var(--pl-primary);
  --bs-link-color: var(--pl-primary);
  --bs-link-hover-color: var(--pl-accent);
}

body { font-size: .9rem; -webkit-font-smoothing: antialiased; background: var(--pl-bg); }
a { text-decoration: none; }
.text-muted, .text-secondary { color: var(--pl-muted) !important; }
.fw-semibold { font-weight: 600 !important; }
.small-caps { font-size: .7rem; letter-spacing: .08em; text-transform: uppercase; font-weight: 600; color: var(--pl-muted); }

/* ---------- Buttons ---------- */
.btn { font-weight: 500; border-radius: 8px; }
.btn-primary { --bs-btn-bg: var(--pl-primary); --bs-btn-border-color: var(--pl-primary);
  --bs-btn-hover-bg: color-mix(in srgb, var(--pl-primary) 88%, #000); --bs-btn-hover-border-color: color-mix(in srgb, var(--pl-primary) 88%, #000);
  --bs-btn-active-bg: color-mix(in srgb, var(--pl-primary) 80%, #000); --bs-btn-disabled-bg: var(--pl-primary); --bs-btn-disabled-border-color: var(--pl-primary); }
.btn-accent { --bs-btn-color: #fff; --bs-btn-bg: var(--pl-accent); --bs-btn-border-color: var(--pl-accent);
  --bs-btn-hover-color: #fff; --bs-btn-hover-bg: color-mix(in srgb, var(--pl-accent) 88%, #000); --bs-btn-hover-border-color: color-mix(in srgb, var(--pl-accent) 88%, #000);
  --bs-btn-active-color: #fff; --bs-btn-active-bg: color-mix(in srgb, var(--pl-accent) 80%, #000); }
.btn-outline-primary { --bs-btn-color: var(--pl-primary); --bs-btn-border-color: var(--pl-primary);
  --bs-btn-hover-bg: var(--pl-primary); --bs-btn-hover-border-color: var(--pl-primary); --bs-btn-active-bg: var(--pl-primary); }
.btn-light { --bs-btn-bg: #fff; --bs-btn-border-color: var(--pl-border); --bs-btn-hover-bg: #F1F4F8; --bs-btn-hover-border-color: #D5DCE5; }

/* ---------- Forms ---------- */
.form-label { font-weight: 500; font-size: .825rem; margin-bottom: .35rem; }
.form-control, .form-select { border-radius: 8px; border-color: #D5DCE5; padding: .55rem .8rem; font-size: .9rem; }
.form-control:focus, .form-select:focus, .form-check-input:focus {
  border-color: var(--pl-accent); box-shadow: 0 0 0 .2rem color-mix(in srgb, var(--pl-accent) 20%, transparent); }
.form-check-input:checked { background-color: var(--pl-accent); border-color: var(--pl-accent); }
.form-text { color: var(--pl-muted); font-size: .78rem; }
.input-group-text { background: #F7F9FB; border-color: #D5DCE5; color: var(--pl-muted); }

/* ---------- App shell ---------- */
.app-sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--pl-sidebar-w); z-index: 1040;
  background: var(--pl-primary); color: rgba(255,255,255,.78);
  display: flex; flex-direction: column; transition: transform .25s ease;
}
.app-sidebar .brand { height: var(--pl-topbar-h); display: flex; align-items: center; gap: .7rem; padding: 0 1.25rem;
  border-bottom: 1px solid rgba(255,255,255,.08); color: #fff; }
.brand-mark { width: 36px; height: 36px; border-radius: 9px; display: grid; place-items: center; flex-shrink: 0;
  background: var(--pl-accent); color: #fff; font-size: 1.15rem; }
.brand-mark img { width: 100%; height: 100%; object-fit: contain; border-radius: 9px; background: #fff; }
.brand-name { font-weight: 700; font-size: 1.05rem; letter-spacing: -.01em; line-height: 1.1; }
.brand-sub { font-size: .7rem; color: rgba(255,255,255,.55); font-weight: 500; }
.app-sidebar nav { flex: 1; overflow-y: auto; padding: .75rem .75rem 1.5rem; }
.nav-section { font-size: .66rem; letter-spacing: .1em; text-transform: uppercase; font-weight: 600;
  color: rgba(255,255,255,.42); padding: 1rem .75rem .4rem; }
.side-link { display: flex; align-items: center; gap: .7rem; padding: .55rem .75rem; border-radius: 8px;
  color: rgba(255,255,255,.78); font-weight: 500; margin-bottom: 2px; }
.side-link i { font-size: 1.05rem; width: 20px; text-align: center; opacity: .85; }
.side-link:hover { background: rgba(255,255,255,.07); color: #fff; }
.side-link.active { background: rgba(255,255,255,.12); color: #fff; box-shadow: inset 3px 0 0 var(--pl-accent); }
.side-link .badge-soon { margin-left: auto; font-size: .6rem; font-weight: 600; padding: .15rem .4rem; border-radius: 4px;
  background: rgba(255,255,255,.1); color: rgba(255,255,255,.55); letter-spacing: .04em; }
.sidebar-foot { padding: .9rem 1.25rem; border-top: 1px solid rgba(255,255,255,.08); font-size: .72rem; color: rgba(255,255,255,.5); }

.app-main { margin-left: var(--pl-sidebar-w); min-height: 100vh; display: flex; flex-direction: column; }
.app-topbar { height: var(--pl-topbar-h); background: var(--pl-surface); border-bottom: 1px solid var(--pl-border);
  display: flex; align-items: center; gap: 1rem; padding: 0 1.5rem; position: sticky; top: 0; z-index: 1020; }
.page-title { font-size: 1.1rem; font-weight: 600; margin: 0; letter-spacing: -.01em; }
.page-crumb { font-size: .75rem; color: var(--pl-muted); }
.app-content { padding: 1.5rem; flex: 1; }
.app-footer { padding: 1rem 1.5rem; font-size: .75rem; color: var(--pl-muted); border-top: 1px solid var(--pl-border); background: var(--pl-surface); }

.avatar { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; font-weight: 600; font-size: .8rem;
  background: color-mix(in srgb, var(--pl-accent) 16%, #fff); color: color-mix(in srgb, var(--pl-accent) 70%, #000); flex-shrink: 0; }
.avatar-lg { width: 56px; height: 56px; font-size: 1.1rem; }
.user-menu-btn { display: flex; align-items: center; gap: .6rem; background: none; border: 0; padding: .25rem .5rem; border-radius: 8px; }
.user-menu-btn:hover { background: #F4F6F9; }
.user-menu-btn .u-name { font-weight: 600; font-size: .85rem; line-height: 1.1; color: var(--pl-text); }
.user-menu-btn .u-role { font-size: .72rem; color: var(--pl-muted); }
.dropdown-menu { border-color: var(--pl-border); box-shadow: 0 10px 30px rgba(16,24,40,.12); border-radius: 10px; padding: .4rem; font-size: .875rem; }
.dropdown-item { border-radius: 6px; padding: .45rem .7rem; }
.dropdown-item i { width: 18px; margin-right: .4rem; color: var(--pl-muted); }

.env-pill { font-size: .68rem; font-weight: 700; letter-spacing: .06em; padding: .25rem .55rem; border-radius: 99px;
  background: #FFF4E5; color: #B54708; border: 1px solid #FEDF89; }
.portal-pill { font-size: .7rem; font-weight: 600; padding: .25rem .6rem; border-radius: 99px;
  background: color-mix(in srgb, var(--pl-accent) 12%, #fff); color: color-mix(in srgb, var(--pl-accent) 75%, #000); }

.sidebar-toggle { display: none; }
.sidebar-backdrop { display: none; }
@media (max-width: 991.98px) {
  .app-sidebar { transform: translateX(-100%); }
  body.sidebar-open .app-sidebar { transform: none; }
  body.sidebar-open .sidebar-backdrop { display: block; position: fixed; inset: 0; background: rgba(16,24,40,.45); z-index: 1035; }
  .app-main { margin-left: 0; }
  .sidebar-toggle { display: inline-flex; }
  .app-content { padding: 1rem; }
  .app-topbar { padding: 0 1rem; }
}

/* ---------- Cards & stats ---------- */
.card { border: 1px solid var(--pl-border); border-radius: var(--pl-radius); box-shadow: var(--pl-shadow); }
.card-header { background: transparent; border-bottom: 1px solid var(--pl-border); padding: .9rem 1.15rem; }
.card-header h2, .card-header h3, .card-title { font-size: .95rem; font-weight: 600; margin: 0; }
.card-body { padding: 1.15rem; }
.stat-card { padding: 1.1rem 1.2rem; display: flex; gap: 1rem; align-items: flex-start; height: 100%; }
.stat-icon { width: 42px; height: 42px; border-radius: 10px; display: grid; place-items: center; font-size: 1.2rem; flex-shrink: 0; }
.stat-value { font-size: 1.6rem; font-weight: 700; letter-spacing: -.02em; line-height: 1.1; }
.stat-label { font-size: .8rem; color: var(--pl-muted); font-weight: 500; }
.tone-primary { background: color-mix(in srgb, var(--pl-primary) 10%, #fff); color: var(--pl-primary); }
.tone-accent  { background: color-mix(in srgb, var(--pl-accent) 12%, #fff); color: color-mix(in srgb, var(--pl-accent) 80%, #000); }
.tone-warning { background: #FFF6E6; color: #B54708; }
.tone-danger  { background: #FEF0EF; color: #B42318; }
.tone-info    { background: #EEF4FF; color: #3538CD; }
.tone-muted   { background: #F2F4F7; color: #475467; }

.pipeline { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: .5rem; }
.pipeline-step { border: 1px solid var(--pl-border); border-radius: 8px; padding: .75rem; background: #FAFBFC; }
.pipeline-step .count { font-size: 1.3rem; font-weight: 700; }
.pipeline-step .lbl { font-size: .74rem; color: var(--pl-muted); display: flex; align-items: center; gap: .35rem; }
@media (max-width: 767.98px) { .pipeline { grid-template-columns: repeat(3, minmax(0, 1fr)); } }

.empty-state { text-align: center; padding: 2rem 1rem; color: var(--pl-muted); }
.empty-state .icon { width: 52px; height: 52px; border-radius: 50%; display: grid; place-items: center; margin: 0 auto .75rem;
  font-size: 1.4rem; background: #F2F4F7; color: #667085; }
.empty-state h4 { font-size: .95rem; font-weight: 600; color: var(--pl-text); margin-bottom: .25rem; }

.list-row { display: flex; align-items: center; gap: .75rem; padding: .7rem 0; border-bottom: 1px solid #EEF1F5; }
.list-row:last-child { border-bottom: 0; }

.badge-soft { font-weight: 600; font-size: .7rem; padding: .3em .6em; border-radius: 6px; }
.badge-soft.success { background: #ECFDF3; color: #067647; }
.badge-soft.warning { background: #FFFAEB; color: #B54708; }
.badge-soft.danger  { background: #FEF3F2; color: #B42318; }
.badge-soft.info    { background: #EFF8FF; color: #175CD3; }
.badge-soft.muted   { background: #F2F4F7; color: #475467; }
.badge-soft.primary { background: color-mix(in srgb, var(--pl-primary) 10%, #fff); color: var(--pl-primary); }

.welcome-banner { border-radius: var(--pl-radius); padding: 1.4rem 1.5rem; color: #fff; position: relative; overflow: hidden;
  background: linear-gradient(120deg, var(--pl-primary) 0%, color-mix(in srgb, var(--pl-primary) 60%, var(--pl-accent)) 100%); }
.welcome-banner::after { content: ""; position: absolute; right: -60px; top: -60px; width: 220px; height: 220px; border-radius: 50%;
  background: rgba(255,255,255,.07); }
.welcome-banner h2 { font-size: 1.25rem; font-weight: 700; margin-bottom: .25rem; }
.welcome-banner p { margin: 0; color: rgba(255,255,255,.8); }

/* ---------- Tables / DataTables ---------- */
.table { --bs-table-color: var(--pl-text); margin-bottom: 0; font-size: .86rem; }
.table > thead th { font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--pl-muted);
  font-weight: 600; background: #F8FAFC; border-bottom: 1px solid var(--pl-border) !important; white-space: nowrap; }
.table > :not(caption) > * > * { padding: .7rem .9rem; vertical-align: middle; }
.table-hover > tbody > tr:hover > * { --bs-table-bg-state: #F8FAFC; }
div.dt-container .dt-search input, div.dt-container .dt-length select { border-radius: 8px; }
div.dt-container .dt-paging .page-link { border-radius: 6px; margin: 0 2px; }
.page-item.active .page-link { background: var(--pl-primary); border-color: var(--pl-primary); }
.filter-bar { display: flex; flex-wrap: wrap; gap: .5rem; align-items: end; }
.filter-bar .form-select, .filter-bar .form-control { min-width: 160px; }

/* ---------- Auth ---------- */
.auth-wrap { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); background: #fff; }
.auth-brand { position: relative; color: #fff; padding: 3rem 3.5rem; display: flex; flex-direction: column; overflow: hidden;
  background: radial-gradient(1200px 600px at -10% 110%, color-mix(in srgb, var(--pl-accent) 55%, transparent), transparent 60%),
              linear-gradient(160deg, var(--pl-primary) 0%, color-mix(in srgb, var(--pl-primary) 75%, #000) 100%); }
.auth-brand::before { content: ""; position: absolute; inset: 0; opacity: .07;
  background-image: radial-gradient(#fff 1px, transparent 1px); background-size: 22px 22px; }
.auth-brand > * { position: relative; }
.auth-brand .headline { font-size: 2.1rem; font-weight: 700; letter-spacing: -.02em; line-height: 1.15; max-width: 30rem; }
.auth-brand .lead-text { color: rgba(255,255,255,.75); font-size: 1rem; max-width: 30rem; }
.auth-feature { display: flex; gap: .85rem; align-items: flex-start; margin-bottom: 1.1rem; }
.auth-feature .ic { width: 38px; height: 38px; border-radius: 9px; display: grid; place-items: center; flex-shrink: 0;
  background: rgba(255,255,255,.1); border: 1px solid rgba(255,255,255,.14); }
.auth-feature .t { font-weight: 600; }
.auth-feature .d { color: rgba(255,255,255,.65); font-size: .84rem; }
.auth-form-side { display: flex; flex-direction: column; justify-content: center; padding: 2.5rem; background: #fff; }
.auth-card { width: 100%; max-width: 420px; margin: 0 auto; }
.auth-card h1 { font-size: 1.55rem; font-weight: 700; letter-spacing: -.02em; }
.portal-switch { display: grid; grid-template-columns: 1fr 1fr; background: #F2F4F7; border-radius: 10px; padding: 4px; gap: 4px; }
.portal-switch a { text-align: center; padding: .5rem; border-radius: 7px; font-weight: 600; font-size: .82rem; color: var(--pl-muted); }
.portal-switch a.active { background: #fff; color: var(--pl-primary); box-shadow: var(--pl-shadow); }
.demo-panel { border: 1px dashed #F5C26B; background: #FFFBF2; border-radius: 10px; font-size: .8rem; }
.demo-panel .demo-row { display: flex; align-items: center; gap: .5rem; padding: .4rem .75rem; border-top: 1px solid #FBE7C0; }
.demo-panel .demo-row:hover { background: #FFF5DF; }
.demo-panel code { color: #7A4B00; font-size: .78rem; }
.otp-input { font-size: 1.75rem; letter-spacing: .6em; text-align: center; font-weight: 600; font-variant-numeric: tabular-nums; padding-left: 1.2rem; }
@media (max-width: 991.98px) {
  .auth-wrap { grid-template-columns: 1fr; }
  .auth-brand { padding: 1.5rem; }
  .auth-brand .hide-sm { display: none !important; }
  .auth-brand .headline { font-size: 1.3rem; }
  .auth-form-side { padding: 1.5rem 1rem 2.5rem; }
}

/* Landing */
.portal-choice { border: 1px solid var(--pl-border); border-radius: 14px; padding: 1.75rem; background: #fff; display: block; height: 100%;
  color: var(--pl-text); transition: border-color .15s, box-shadow .15s, transform .15s; }
.portal-choice:hover { border-color: var(--pl-accent); box-shadow: 0 12px 32px rgba(16,24,40,.1); transform: translateY(-2px); color: var(--pl-text); }
.portal-choice .ic { width: 52px; height: 52px; border-radius: 12px; display: grid; place-items: center; font-size: 1.5rem; margin-bottom: 1rem; }

/* Toasts */
.toast-stack { position: fixed; top: 1rem; right: 1rem; z-index: 1090; display: flex; flex-direction: column; gap: .5rem; }
.toast { border: 0; border-radius: 10px; box-shadow: 0 10px 30px rgba(16,24,40,.16); }
.toast .toast-body { display: flex; gap: .6rem; align-items: flex-start; font-weight: 500; }

/* Module placeholder */
.soon-hero { max-width: 640px; margin: 2rem auto; text-align: center; }
.soon-hero .ic { width: 72px; height: 72px; border-radius: 18px; display: grid; place-items: center; margin: 0 auto 1.25rem; font-size: 2rem; }

.btn .spinner-border { width: 1rem; height: 1rem; border-width: .15em; }
.json-block { background: #0F172A; color: #E2E8F0; border-radius: 8px; padding: .75rem 1rem; font-size: .78rem; max-height: 320px; overflow: auto; }
.color-swatch { width: 44px; height: 38px; padding: 3px; }

/* ---------- Orders / workflow ---------- */
.side-link .badge-count { margin-left: auto; font-size: .68rem; font-weight: 700; min-width: 22px; text-align: center;
  padding: .15rem .45rem; border-radius: 99px; background: var(--pl-accent); color: #fff; }
.status-tabs { display: flex; gap: .4rem; flex-wrap: wrap; }
.status-tab { display: inline-flex; align-items: center; gap: .4rem; padding: .4rem .75rem; border-radius: 99px; border: 1px solid var(--pl-border);
  background: #fff; font-size: .8rem; font-weight: 500; color: var(--pl-text); cursor: pointer; }
.status-tab .n { font-weight: 700; color: var(--pl-muted); font-size: .75rem; }
.status-tab:hover { border-color: #C9D2DD; }
.status-tab.active { background: var(--pl-primary); border-color: var(--pl-primary); color: #fff; }
.status-tab.active .n { color: rgba(255,255,255,.75); }
.flag { display: inline-flex; align-items: center; gap: .2rem; font-size: .66rem; font-weight: 700; letter-spacing: .03em;
  padding: .12rem .4rem; border-radius: 4px; text-transform: uppercase; }
.flag.urgent { background: #FEF3F2; color: #B42318; }
.flag.cii { background: #F4F3FF; color: #5925DC; }
.flag.cold { background: #EFF8FF; color: #175CD3; }
.lines-cell { font-size: .8rem; line-height: 1.35; max-width: 320px; }
.lines-cell div { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.order-no { font-weight: 600; font-variant-numeric: tabular-nums; }

.kv { display: grid; grid-template-columns: 140px 1fr; gap: .45rem .75rem; font-size: .86rem; }
.kv dt { color: var(--pl-muted); font-weight: 500; }
.kv dd { margin: 0; }
@media (max-width: 575.98px) { .kv { grid-template-columns: 1fr; } .kv dt { margin-top: .4rem; } }

.check-list { list-style: none; margin: 0; padding: 0; }
.check-list li { display: flex; gap: .75rem; padding: .7rem 0; border-bottom: 1px solid #EEF1F5; }
.check-list li:last-child { border-bottom: 0; }
.check-list .ic { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; flex-shrink: 0; font-size: .85rem; }
.check-list .pass .ic { background: #ECFDF3; color: #067647; }
.check-list .warn .ic { background: #FFFAEB; color: #B54708; }
.check-list .fail .ic { background: #FEF3F2; color: #B42318; }
.check-list .lbl { font-weight: 600; font-size: .85rem; }
.check-list .det { font-size: .8rem; color: var(--pl-muted); }

.timeline { list-style: none; padding: 0; margin: 0; position: relative; }
.timeline::before { content: ""; position: absolute; left: 13px; top: 6px; bottom: 6px; width: 2px; background: #E9EDF2; }
.timeline li { position: relative; padding: 0 0 1rem 2.4rem; }
.timeline li:last-child { padding-bottom: 0; }
.timeline .dot { position: absolute; left: 0; top: 0; width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center;
  font-size: .8rem; border: 2px solid #fff; }
.timeline .t { font-weight: 600; font-size: .84rem; }
.timeline .m { font-size: .76rem; color: var(--pl-muted); }
.timeline .n { font-size: .8rem; margin-top: .15rem; }

.msg { border-radius: 10px; padding: .65rem .85rem; margin-bottom: .6rem; font-size: .85rem; background: #F7F9FB; border: 1px solid var(--pl-border); }
.msg.internal { background: #FFFBF0; border-color: #FBE7C0; }
.msg.client { background: color-mix(in srgb, var(--pl-accent) 7%, #fff); border-color: color-mix(in srgb, var(--pl-accent) 25%, #fff); }
.msg .who { font-size: .74rem; color: var(--pl-muted); margin-bottom: .2rem; }

.patient-card { border-left: 4px solid var(--pl-accent); }
.allergy-chip { display: inline-block; padding: .15rem .5rem; border-radius: 99px; font-size: .74rem; font-weight: 600; background: #FEF3F2; color: #B42318; margin: 0 .25rem .25rem 0; }
.allergy-chip.none { background: #ECFDF3; color: #067647; }

.worksheet-table td, .worksheet-table th { vertical-align: middle; }
.lot-opt-expired { color: #B42318; }
.sticky-actions { position: sticky; top: calc(var(--pl-topbar-h) + 1rem); }
.action-card .btn { justify-content: center; }
.tabular { font-variant-numeric: tabular-nums; }
