/* ------------------------------------------------------------------------
   SugarCARE Rx Audit — application layer.
   Extends the prototype design system (tokens / layout / components) with
   the components v1 introduces. No token is redefined here.
   ------------------------------------------------------------------------ */

/* ------------------------------------------------------------------ login */

.auth-page {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1.05fr .95fr;
  background: var(--canvas);
}

.auth-aside {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 44px 48px;
  overflow: hidden;
  background:
    radial-gradient(120% 90% at 12% 8%, rgba(232, 106, 26, .16), transparent 58%),
    linear-gradient(158deg, var(--purple) 0%, var(--purple-strong) 62%, #2c1866 100%);
  color: #fff;
}
.auth-aside::after {
  content: '';
  position: absolute;
  inset: auto -20% -46% -20%;
  height: 62%;
  background: radial-gradient(60% 100% at 50% 0%, rgba(255, 255, 255, .11), transparent 70%);
  pointer-events: none;
}
.auth-aside .brand-mark {
  background: rgba(255, 255, 255, .1);
  border-color: rgba(255, 255, 255, .26);
  color: #fff;
}
.auth-aside .brand-name { color: #fff; }
.auth-aside .brand-name em { color: #ffb37a; }
.auth-aside .brand-product { color: rgba(255, 255, 255, .62); }

.auth-pitch { position: relative; z-index: 1; max-width: 460px; }
.auth-pitch .eyebrow { color: #ffb37a; }
.auth-pitch h2 {
  margin: 0 0 14px;
  font-size: clamp(26px, 2.6vw, 38px);
  line-height: 1.14;
  letter-spacing: -.045em;
  color: #fff;
}
.auth-pitch p { margin: 0; color: rgba(255, 255, 255, .74); font-size: 15px; line-height: 1.7; }

.auth-points { position: relative; z-index: 1; display: grid; gap: 11px; margin-top: 26px; padding: 0; list-style: none; }
.auth-points li {
  display: flex; gap: 11px; align-items: flex-start;
  color: rgba(255, 255, 255, .84); font-size: 16px;
}
.auth-points li::before {
  content: ''; flex: 0 0 auto; width: 6px; height: 6px; margin-top: 6px;
  border-radius: 50%; background: var(--orange);
}
.auth-foot {
  position: relative; z-index: 1;
  color: rgba(255, 255, 255, .46);
  font: 13px var(--font-mono); letter-spacing: .08em; text-transform: uppercase;
}

.auth-main { display: grid; place-items: center; padding: 40px 32px; }
.auth-card { width: min(392px, 100%); }
.auth-card h1 { margin-bottom: 6px; font-size: 25px; }
.auth-card .lede { margin-bottom: 26px; color: var(--muted); font-size: 16px; }

.auth-form { display: grid; gap: 15px; }
.auth-form .field label { margin-bottom: 7px; }
.auth-form .input { min-height: 44px; font-size: 16px; }
.auth-form .btn { min-height: 46px; width: 100%; font-size: 16px; }

.auth-error {
  display: none;
  gap: 10px; align-items: flex-start;
  padding: 11px 13px;
  border-left: 3px solid var(--danger);
  border-radius: 0 8px 8px 0;
  background: var(--danger-bg);
  color: var(--danger);
  font-size: 15px; line-height: 1.5;
}
.auth-error.show { display: flex; }

.demo-creds {
  margin-top: 24px; padding: 15px 16px;
  border: 1px dashed var(--border-strong); border-radius: var(--radius-md);
  background: var(--purple-faint);
}
.demo-creds h4 {
  margin: 0 0 10px;
  color: var(--muted); font: 600 12px var(--font-mono);
  letter-spacing: .1em; text-transform: uppercase;
}
.demo-cred {
  width: 100%; display: flex; align-items: center; gap: 10px;
  padding: 8px 9px; margin-bottom: 6px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); cursor: pointer; text-align: left;
  transition: .16s var(--ease);
}
.demo-cred:last-child { margin-bottom: 0; }
.demo-cred:hover { border-color: var(--purple); transform: translateX(2px); }
.demo-cred .avatar { width: 28px; height: 28px; font-size: 13px; }
.demo-cred b { display: block; color: var(--deep); font-size: 14px; }
.demo-cred span { color: var(--muted); font: 13px var(--font-mono); }
.demo-cred .use { margin-left: auto; color: var(--purple); font: 600 13px var(--font-mono); }

@media (max-width: 940px) {
  .auth-page { grid-template-columns: 1fr; }
  .auth-aside { display: none; }
}

/* ------------------------------------------------------------- shell extras */

/* The mark holds two inline glyphs ("S" + "C"); grid would stack them as rows. */
.brand-mark { display: flex; align-items: center; justify-content: center; letter-spacing: -.02em; }
.brand-mark em { color: var(--orange); font-style: normal; }

.role-chip {
  display: inline-flex; align-items: center; min-height: 26px; padding: 0 10px;
  border: 1px solid var(--border-strong); border-radius: 999px;
  background: var(--purple-faint); color: var(--purple);
  font: 600 13px var(--font-mono); letter-spacing: .05em; white-space: nowrap;
}
.btn.signout { width: 100%; margin-top: 12px; font-size: 14px; }
@media (max-width: 660px) { .role-chip { display: none; } }

/* -------------------------------------------------------- loading / empty */

.skeleton-row {
  height: 42px; margin-bottom: 8px; border-radius: 8px;
  background: linear-gradient(90deg, var(--purple-faint) 25%, var(--purple-soft) 37%, var(--purple-faint) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.35s ease-in-out infinite;
}
.skeleton-row:last-child { margin-bottom: 0; }
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }

.empty-state {
  display: grid; justify-items: center; gap: 8px;
  padding: 34px 20px; text-align: center;
}
.empty-state .empty-icon {
  display: grid; place-items: center; width: 40px; height: 40px; margin-bottom: 3px;
  border: 1px solid var(--border); border-radius: 11px;
  background: var(--purple-faint); color: var(--purple);
}
.empty-state .empty-icon svg { width: 19px; height: 19px; }
.empty-state b { color: var(--deep); font-size: 16px; }
.empty-state p { max-width: 380px; margin: 0; color: var(--muted); font-size: 14px; line-height: 1.6; }
.empty-state .btn { margin-top: 6px; }

.toast.success { border-left: 3px solid var(--success); }
.toast.danger  { border-left: 3px solid var(--danger); }
.toast.warning { border-left: 3px solid var(--orange); }
.toast { transition: opacity .2s var(--ease), transform .2s var(--ease); }

/* -------------------------------------------------------------- dashboard */

.quick-card { text-align: left; }
.activity-empty { padding: 18px 0; color: var(--muted); font-size: 14px; }

/* ------------------------------------------------------------------ queue */

.queue-tools {
  position: sticky; top: var(--topbar); z-index: 20;
  padding: 14px; margin: 0 -14px 15px;
  background: color-mix(in srgb, var(--canvas) 92%, transparent);
  backdrop-filter: blur(12px);
}
.filters { display: grid; grid-template-columns: 1.3fr repeat(4, minmax(118px, .7fr)); gap: 8px; }
.queue-meta {
  display: flex; justify-content: space-between; gap: 16px;
  margin: 12px 2px 0; color: var(--muted); font: 13px var(--font-mono);
}
.queue-meta b { color: var(--deep); }
.pager { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 14px; }
.pager .pages { display: flex; gap: 6px; }
.table tbody tr.row-link { cursor: pointer; }

/* `.table strong` is block, so a following `small` drops to its own line. Cells
   without a `strong` need the same treatment or the sub-label runs inline. */
#queueTable td small { display: block; margin-top: 2px; }
#queueTable td:last-child { text-align: right; }

/* Explicit widths: without them the patient/UHID cell wraps to three lines
   while the wider text columns keep all the slack. */
/* 900px is the narrowest the nine columns stay legible; below that the wrapper
   scrolls horizontally rather than crushing the chips. */
#queueTable { min-width: 900px; table-layout: fixed; }
#queueTable td, #queueTable th { padding-inline: 11px; }
#queueTable td { font-size: 14px; }
/* These must sum to exactly 100% — anything over overflows the last column. */
#queueTable th:nth-child(1), #queueTable td:nth-child(1) { width: 15%; }
#queueTable th:nth-child(2), #queueTable td:nth-child(2) { width: 10%; }
#queueTable th:nth-child(3), #queueTable td:nth-child(3) { width: 13%; }
#queueTable th:nth-child(4), #queueTable td:nth-child(4) { width: 14%; }
#queueTable th:nth-child(5), #queueTable td:nth-child(5) { width:  6%; }
#queueTable th:nth-child(6), #queueTable td:nth-child(6) { width: 13%; }
#queueTable th:nth-child(7), #queueTable td:nth-child(7) { width: 13%; }
#queueTable th:nth-child(8), #queueTable td:nth-child(8) { width:  7%; }
#queueTable th:nth-child(9), #queueTable td:nth-child(9) { width:  9%; }
#queueTable .chip { max-width: 100%; }
#queueTable .chip, #queueTable .badge { overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 1100px) { .filters { grid-template-columns: repeat(3, 1fr); } .filters .search { grid-column: span 3; } }
@media (max-width: 660px)  { .filters { grid-template-columns: 1fr 1fr; } .filters .search { grid-column: span 2; }
                             .queue-meta { flex-direction: column; align-items: flex-start; gap: 4px; } }

/* -------------------------------------------------------------- workspace */

.casebar { display: flex; align-items: center; gap: 18px; padding: 13px 16px; margin-bottom: 16px; overflow-x: auto; }
.case-id { min-width: max-content; }
.case-id span { display: block; color: var(--muted); font: 12px var(--font-mono); letter-spacing: .06em; text-transform: uppercase; }
.case-id b { font-size: 15px; }
.vline { align-self: stretch; border-left: 1px solid var(--border); }

.workspace { display: grid; grid-template-columns: 340px minmax(0, 1fr); gap: 16px; align-items: start; }
.context { position: sticky; top: calc(var(--topbar) + 14px); display: grid; gap: 12px; }

.kv { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.kv:last-child { border-bottom: 0; }
.kv span { color: var(--muted); }
.kv b { text-align: right; }
.kv b.missing { color: var(--warning) !important; font: 600 12px var(--font-mono); letter-spacing: .04em; }

.med { padding: 8px 0; border-bottom: 1px solid var(--border); }
.med:last-child { border-bottom: 0; }
.med b { display: block; font-size: 14px; }
.med small { color: var(--muted); font: 12px var(--font-mono); }

.compare { display: grid; grid-template-columns: 1fr 1fr; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.rxcol { padding: 14px; }
.rxcol + .rxcol { border-left: 1px solid var(--border); background: var(--purple-faint); }
.rxcol h4 { margin: 0 0 10px; color: var(--muted); font: 600 12px var(--font-mono); letter-spacing: .07em; text-transform: uppercase; }
.rxcol + .rxcol h4 { color: var(--purple); }
.rxline { padding: 6px 0; border-bottom: 1px dashed var(--border); font-size: 14px; line-height: 1.55; }
.rxline:last-child { border-bottom: 0; }
.rxline.add    { color: var(--success); }
.rxline.change { color: var(--warning); }
.rxline.remove { color: var(--danger); }

.finding { margin-top: 10px; overflow: hidden; scroll-margin-top: calc(var(--topbar) + 20px); }
.finding-head { display: flex; align-items: center; gap: 9px; padding: 11px 13px; background: var(--purple-faint); border-bottom: 1px solid var(--border); }
.fnum { width: 23px; height: 23px; flex: 0 0 auto; display: grid; place-items: center; border-radius: 6px; background: var(--surface); color: var(--purple); font: 600 13px var(--font-mono); }
.finding-head h3 { flex: 1; margin: 0; font-size: 15px; }
.finding-body { padding: 13px; }
.finding-copy { margin: 0; color: var(--text); font-size: 14px; line-height: 1.65; }
.ai-label { margin-right: 8px; color: var(--purple); font: 600 12px var(--font-mono); letter-spacing: .05em; text-transform: uppercase; }
.dependency { margin-top: 9px; color: var(--warning); font: 12px var(--font-mono); letter-spacing: .03em; }

.verdict { display: flex; gap: 5px; margin-top: 12px; }
.verdict button {
  min-height: 31px; padding: 0 12px;
  border: 1px solid var(--border); border-radius: 7px;
  background: var(--surface); color: var(--muted);
  font-size: 13px; font-weight: 700; cursor: pointer;
  transition: .15s var(--ease);
}
.verdict button:hover:not(.active) { border-color: var(--border-strong); color: var(--deep); }
.verdict button.active[data-value="confirm"] { background: var(--success-bg); border-color: var(--success); color: var(--success); }
.verdict button.active[data-value="modify"]  { background: var(--warning-bg); border-color: var(--warning); color: var(--warning); }
.verdict button.active[data-value="dismiss"] { background: var(--purple-faint); border-color: var(--muted); color: var(--muted); }

.notes { display: none; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 9px; }
.finding.decided .notes { display: grid; }
.notes textarea { min-height: 66px; font-size: 14px; }
.finding.human { border-left: 3px solid var(--purple); }
.finding.human textarea { min-height: 92px; }
.finding.flagged     { border-left: 2.5px solid var(--orange); }
.finding.unauditable { border-left: 2.5px solid var(--danger); }
.finding.reported    { border-left: 2.5px solid var(--danger); }
.finding.needs-verdict { box-shadow: 0 0 0 2px var(--warning-bg); }

.actionbar {
  position: sticky; bottom: 0; z-index: 25;
  display: flex; align-items: center; gap: 10px;
  padding: 13px 0; margin-top: 16px;
  background: color-mix(in srgb, var(--canvas) 94%, transparent);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--border);
}
.actionbar .summary { margin-right: auto; color: var(--muted); font-size: 13px; }
.actionbar .summary b { color: var(--deep); }
.actionbar .btn[disabled] { opacity: .5; cursor: not-allowed; transform: none; }
.readonly-note {
  display: flex; gap: 10px; align-items: center;
  padding: 11px 14px; margin-bottom: 14px;
  border-left: 3px solid var(--success); border-radius: 0 9px 9px 0;
  background: var(--success-bg); color: var(--success); font-size: 15px;
}
.workspace.locked textarea,
.workspace.locked .verdict button { pointer-events: none; opacity: .82; }

@media (max-width: 1080px) {
  .workspace { grid-template-columns: 1fr; }
  .context { position: static; grid-template-columns: 1fr 1fr; }
  .context .clinical { grid-column: span 2; }
}
@media (max-width: 660px) {
  .context { grid-template-columns: 1fr; }
  .context .clinical { grid-column: auto; }
  .compare { grid-template-columns: 1fr; }
  .rxcol + .rxcol { border-left: 0; border-top: 1px solid var(--border); }
  .finding-head { align-items: flex-start; flex-wrap: wrap; }
  .notes { grid-template-columns: 1fr; }
  .actionbar { flex-wrap: wrap; }
  .actionbar .summary { width: 100%; }
}

/* --------------------------------------------------------------- feedback */

.fb-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.08fr); gap: 16px; align-items: start; }

.pattern {
  padding: 12px 13px; margin-bottom: 9px;
  border: 1px solid var(--border); border-radius: 9px; background: var(--surface);
}
.pattern:last-child { margin-bottom: 0; }
.pattern .pt { display: flex; justify-content: space-between; align-items: center; gap: 10px; font-weight: 600; font-size: 15px; color: var(--deep); }
.pattern .n { padding: 2px 9px; border-radius: 999px; background: var(--purple-soft); color: var(--purple); font: 600 13px var(--font-mono); }
.pattern .cases { margin-top: 6px; color: var(--muted); font: 13px var(--font-mono); }

.mail { border: 1px solid var(--border-strong); border-radius: var(--radius-md); background: var(--surface); overflow: hidden; }
.mail .mh { padding: 12px 15px; border-bottom: 1px solid var(--border); background: var(--purple-faint); }
.mail .mrow { display: flex; gap: 10px; padding: 3px 0; font-size: 15px; }
.mail .mrow .mk { flex: 0 0 52px; padding-top: 2px; color: var(--muted); font: 13px var(--font-mono); text-transform: uppercase; }
.mail .mrow .mv { color: var(--deep); }
.mail .mbody {
  padding: 16px; margin: 0;
  font: 15px/1.75 var(--font-sans); color: var(--text);
  white-space: pre-wrap; word-break: break-word;
}
.mail .mbody:focus-visible { background: var(--purple-faint); }
.mail .mfoot {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 12px 15px; border-top: 1px solid var(--border); background: var(--purple-faint);
}
.draftbadge { padding: 3px 9px; border-radius: 5px; background: var(--warning-bg); color: var(--warning); font: 700 13px var(--font-mono); }

.dpdp-note {
  display: flex; gap: 11px; align-items: flex-start;
  padding: 12px 14px; margin-top: 14px;
  border-left: 3px solid var(--purple); border-radius: 0 9px 9px 0;
  background: var(--purple-faint);
}
.dpdp-note b { display: block; color: var(--deep); font-size: 14px; }
.dpdp-note p { margin: 3px 0 0; color: var(--muted); font-size: 13px; line-height: 1.6; }

@media (max-width: 1000px) { .fb-grid { grid-template-columns: 1fr; } }

/* ----------------------------------------------------------------- print */

@media print {
  .actionbar, .queue-tools, .signout, .role-chip { display: none !important; }
  .mail { border-color: #ccc; }
}
