:root {
  --forest-950: #102e29;
  --forest-900: #173f36;
  --forest-800: #1f574a;
  --forest-700: #2b6d5d;
  --forest-100: #dff1ea;
  --forest-50: #edf8f4;
  --cream: #f7f6f0;
  --paper: #ffffff;
  --ink: #17201e;
  --muted: #66716e;
  --line: #dde3e0;
  --line-strong: #c9d2ce;
  --blue: #2563a8;
  --blue-bg: #e9f2fb;
  --amber: #a65d05;
  --amber-bg: #fff2d8;
  --purple: #6d4bb2;
  --purple-bg: #f0ebfb;
  --red: #ad3333;
  --red-bg: #fceaea;
  --green: #23714e;
  --green-bg: #e5f4eb;
  --gray-bg: #eef1f0;
  --shadow-sm: 0 1px 2px rgba(16, 46, 41, 0.05), 0 5px 16px rgba(16, 46, 41, 0.04);
  --shadow-lg: 0 24px 80px rgba(12, 36, 31, 0.22);
  --radius: 16px;
  --font: Pretendard, "Apple SD Gothic Neo", "Noto Sans KR", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  color-scheme: light;
  background: var(--cream);
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: var(--cream);
  color: var(--ink);
  font-family: var(--font);
  line-height: 1.5;
  letter-spacing: -0.02em;
}

body.no-scroll {
  overflow: hidden;
}

button,
input,
textarea,
select {
  color: inherit;
  font: inherit;
}

button {
  letter-spacing: inherit;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible,
[tabindex]:focus-visible {
  outline: 3px solid rgba(43, 109, 93, 0.32);
  outline-offset: 2px;
}

button:disabled {
  cursor: wait;
  opacity: 0.62;
}

[hidden] {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--forest-700);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

.muted {
  color: var(--muted);
}

.brand-symbol {
  display: grid;
  width: 58px;
  height: 58px;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.38);
  border-radius: 18px 18px 18px 5px;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font-family: Georgia, serif;
  font-size: 30px;
  font-style: italic;
  font-weight: 600;
  line-height: 1;
}

.brand-symbol-small {
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 12px 12px 12px 4px;
  background: var(--forest-900);
  font-size: 21px;
}

.button {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  border: 1px solid transparent;
  border-radius: 11px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 750;
  text-decoration: none;
  transition: background 160ms ease, border-color 160ms ease, transform 160ms ease;
}

.button:not(:disabled):active {
  transform: translateY(1px);
}

.button-primary {
  background: var(--forest-900);
  color: #fff;
}

.button-primary:hover {
  background: var(--forest-800);
}

.button-secondary {
  border-color: var(--line-strong);
  background: var(--paper);
  color: var(--forest-900);
}

.button-ghost {
  border-color: var(--line);
  background: transparent;
  color: var(--forest-900);
}

.button-danger {
  border-color: #e8bebe;
  background: var(--red-bg);
  color: var(--red);
}

.button-success {
  background: var(--green);
  color: #fff;
}

.button-small {
  min-height: 36px;
  padding: 7px 12px;
  font-size: 13px;
}

.button-wide {
  width: 100%;
}

.icon-button {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  cursor: pointer;
  font-size: 22px;
  line-height: 1;
}

.icon-button-light {
  border-color: var(--line);
  background: var(--paper);
  color: var(--ink);
}

/* Login */

.login-page {
  min-height: 100vh;
  grid-template-columns: minmax(420px, 0.92fr) minmax(520px, 1.08fr);
}

body[data-app-state="login"] .login-page {
  display: grid;
}

.login-brand {
  position: relative;
  display: flex;
  min-height: 100vh;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  overflow: hidden;
  padding: clamp(48px, 8vw, 112px);
  background:
    radial-gradient(circle at 8% 8%, rgba(255, 255, 255, 0.09), transparent 32%),
    linear-gradient(145deg, var(--forest-950), var(--forest-800));
  color: #fff;
}

.login-brand::after {
  position: absolute;
  right: -180px;
  bottom: -220px;
  width: 540px;
  height: 540px;
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: 50%;
  box-shadow: 0 0 0 70px rgba(255, 255, 255, 0.025), 0 0 0 140px rgba(255, 255, 255, 0.018);
  content: "";
}

.login-brand .eyebrow {
  margin-top: 42px;
  color: #a9d7c7;
}

.login-brand h1 {
  max-width: 620px;
  margin: 0;
  font-size: clamp(42px, 5vw, 72px);
  font-weight: 780;
  letter-spacing: -0.055em;
  line-height: 1.08;
  word-break: keep-all;
}

.login-lede {
  max-width: 560px;
  margin: 28px 0 0;
  color: rgba(255, 255, 255, 0.72);
  font-size: 17px;
  line-height: 1.72;
}

.privacy-note {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 56px;
  color: rgba(255, 255, 255, 0.78);
  font-size: 13px;
  font-weight: 650;
}

.privacy-dot {
  width: 9px;
  height: 9px;
  border: 2px solid #aee9d2;
  border-radius: 50%;
  box-shadow: 0 0 0 4px rgba(174, 233, 210, 0.1);
}

.login-panel {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 48px;
  background: var(--cream);
}

.login-card {
  width: min(100%, 480px);
  padding: 42px;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--paper);
  box-shadow: var(--shadow-lg);
}

.login-card h2 {
  margin: 0;
  font-size: 30px;
  letter-spacing: -0.04em;
}

.login-card > div > p:last-child {
  margin: 10px 0 0;
  color: var(--muted);
}

.login-form {
  display: grid;
  gap: 18px;
  margin-top: 30px;
}

.login-form label,
.stacked-field {
  display: grid;
  gap: 8px;
}

.login-form label > span,
.stacked-field > span {
  color: #48514f;
  font-size: 13px;
  font-weight: 750;
}

.login-form input,
.stacked-field input,
.stacked-field textarea,
.stacked-field select,
.inline-edit input {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: #fff;
}

.login-form input {
  min-height: 50px;
  padding: 12px 14px;
}

.stacked-field textarea,
.stacked-field select,
.stacked-field input {
  padding: 11px 12px;
}

.form-error {
  margin: -4px 0 0;
  padding: 11px 12px;
  border-radius: 9px;
  background: var(--red-bg);
  color: var(--red);
  font-size: 13px;
  font-weight: 650;
}

.role-preview {
  display: grid;
  gap: 12px;
  margin-top: 30px;
  padding-top: 24px;
  border-top: 1px solid var(--line);
}

.role-preview div {
  display: grid;
  grid-template-columns: 66px 1fr;
  align-items: baseline;
}

.role-preview strong {
  color: var(--forest-800);
  font-size: 13px;
}

.role-preview span {
  color: var(--muted);
  font-size: 12px;
}

/* App shell */

.app-shell {
  min-height: 100vh;
}

.topbar {
  position: sticky;
  z-index: 40;
  top: 0;
  display: flex;
  min-height: 64px;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  background: rgba(255, 255, 255, 0.96);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(18px);
}

.topbar-brand,
.topbar-actions,
.identity-chip,
.internal-chip {
  display: flex;
  align-items: center;
}

.topbar-brand {
  gap: 12px;
}

.topbar-brand > div:last-child {
  display: grid;
  line-height: 1.2;
}

.topbar-brand strong {
  font-size: 16px;
}

.topbar-brand span {
  color: var(--muted);
  font-size: 11px;
}

.topbar-actions {
  gap: 10px;
}

.internal-chip {
  gap: 7px;
  margin-right: 6px;
  color: var(--forest-800);
  font-size: 12px;
  font-weight: 750;
}

.internal-chip > span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #2fa36f;
  box-shadow: 0 0 0 4px rgba(47, 163, 111, 0.12);
}

.identity-chip {
  gap: 9px;
  min-height: 38px;
  padding: 5px 6px 5px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fafbf9;
}

.identity-chip span {
  font-size: 13px;
  font-weight: 650;
}

.identity-chip strong {
  padding: 4px 8px;
  border-radius: 7px;
  background: var(--forest-100);
  color: var(--forest-800);
  font-size: 11px;
}

.safety-strip {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-height: 40px;
  padding: 8px 20px;
  background: var(--forest-950);
  color: rgba(255, 255, 255, 0.7);
  font-size: 12px;
  text-align: center;
}

.safety-strip strong {
  color: #bfe8d9;
}

.workspace {
  width: min(100%, 1500px);
  margin: 0 auto;
  padding: 38px 30px 60px;
}

.page-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 30px;
}

.page-heading h1 {
  margin: 0;
  font-size: clamp(30px, 3vw, 42px);
  letter-spacing: -0.055em;
  line-height: 1.15;
}

.page-heading > div > p:last-child {
  margin: 9px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.heading-actions {
  display: flex;
  gap: 9px;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 12px;
  margin-top: 28px;
}

.summary-card {
  display: grid;
  min-height: 126px;
  grid-template-rows: auto 1fr auto;
  padding: 17px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--paper);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  text-align: left;
}

.summary-card:hover,
.summary-card.is-active {
  border-color: var(--forest-700);
  box-shadow: 0 0 0 2px rgba(43, 109, 93, 0.1), var(--shadow-sm);
}

.summary-card > span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.summary-card > strong {
  align-self: center;
  font-size: 32px;
  letter-spacing: -0.04em;
}

.summary-card > small {
  overflow: hidden;
  color: #88918e;
  font-size: 10px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.summary-card-needs_attention > strong {
  color: var(--red);
}

.summary-card-ready_for_review > strong {
  color: var(--purple);
}

.summary-card-approved > strong {
  color: var(--green);
}

.queue-layout {
  display: grid;
  grid-template-columns: 212px minmax(0, 1fr);
  gap: 16px;
  margin-top: 18px;
}

.filter-panel,
.queue-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
  box-shadow: var(--shadow-sm);
}

.filter-panel {
  align-self: start;
  overflow: hidden;
  padding: 18px 12px 12px;
}

.filter-panel h2 {
  margin: 0 10px 12px;
  font-size: 13px;
}

.filter-list {
  display: grid;
  gap: 3px;
}

.filter-button {
  display: flex;
  min-height: 40px;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: #52605c;
  cursor: pointer;
  font-size: 13px;
  font-weight: 650;
}

.filter-button:hover {
  background: #f4f6f4;
}

.filter-button.is-active {
  background: var(--forest-50);
  color: var(--forest-800);
}

.filter-button strong {
  min-width: 25px;
  padding: 2px 7px;
  border-radius: 99px;
  background: #eff2f0;
  font-size: 10px;
  text-align: center;
}

.filter-button.is-active strong {
  background: var(--forest-100);
}

.filter-help {
  margin-top: 14px;
  padding: 14px 11px;
  border-radius: 10px;
  background: #f7f8f5;
}

.filter-help strong {
  color: var(--forest-800);
  font-size: 11px;
}

.filter-help p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.55;
}

.queue-panel {
  min-width: 0;
  overflow: hidden;
}

.queue-toolbar {
  display: flex;
  min-height: 76px;
  align-items: center;
  justify-content: space-between;
  gap: 22px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}

.queue-toolbar > div {
  display: flex;
  align-items: baseline;
  gap: 9px;
}

.queue-toolbar h2 {
  margin: 0;
  font-size: 16px;
}

.queue-toolbar p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.search-field {
  display: flex;
  width: min(360px, 45%);
  min-height: 42px;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fafbf9;
  color: #7a8581;
}

.search-field input {
  min-width: 0;
  flex: 1;
  border: 0;
  outline: 0;
  background: transparent;
  font-size: 13px;
}

.queue-table-wrap {
  overflow-x: auto;
}

.queue-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.queue-table th {
  padding: 11px 16px;
  border-bottom: 1px solid var(--line);
  background: #fafbf9;
  color: #7c8683;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-align: left;
  text-transform: uppercase;
}

.queue-table th:nth-child(1) { width: 15%; }
.queue-table th:nth-child(2) { width: 20%; }
.queue-table th:nth-child(3) { width: 27%; }
.queue-table th:nth-child(4) { width: 14%; }
.queue-table th:nth-child(5) { width: 18%; }
.queue-table th:nth-child(6) { width: 6%; }

.queue-table tbody tr {
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  transition: background 120ms ease;
}

.queue-table tbody tr:last-child {
  border-bottom: 0;
}

.queue-table tbody tr:hover {
  background: #fbfcfa;
}

.queue-table td {
  overflow: hidden;
  padding: 16px;
  font-size: 13px;
  vertical-align: middle;
}

.queue-table td > strong,
.queue-table td > small,
.med-summary > strong,
.med-summary > small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.queue-table td > strong,
.med-summary > strong {
  font-size: 13px;
  font-weight: 750;
}

.queue-table td > small,
.med-summary > small {
  margin-top: 4px;
  color: var(--muted);
  font-size: 10px;
}

.route-chip {
  display: inline-flex;
  width: fit-content;
  align-items: center;
  margin-top: 7px;
  padding: 4px 7px;
  border-radius: 999px;
  font-size: 9px;
  font-weight: 800;
  white-space: nowrap;
}

.route-chip-home {
  background: var(--forest-50);
  color: var(--forest-800);
}

.route-chip-pharmacy {
  background: var(--purple-bg);
  color: var(--purple);
}

.row-open {
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 8px;
  background: #f1f4f2;
  color: var(--forest-800);
  cursor: pointer;
  font-size: 22px;
}

.status-badge {
  display: inline-flex;
  min-height: 27px;
  align-items: center;
  gap: 6px;
  padding: 5px 8px;
  border-radius: 8px;
  font-size: 10px;
  font-weight: 800;
  white-space: nowrap;
}

.status-badge > span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.status-blue { background: var(--blue-bg); color: var(--blue); }
.status-amber { background: var(--amber-bg); color: var(--amber); }
.status-purple { background: var(--purple-bg); color: var(--purple); }
.status-red { background: var(--red-bg); color: var(--red); }
.status-green { background: var(--green-bg); color: var(--green); }
.status-gray { background: var(--gray-bg); color: #65706d; }

.queue-card-list {
  display: none;
}

.empty-state {
  padding: 80px 24px;
  text-align: center;
}

.empty-state > div {
  display: grid;
  width: 46px;
  height: 46px;
  place-items: center;
  margin: 0 auto 14px;
  border-radius: 50%;
  background: var(--forest-50);
  color: var(--forest-800);
  font-size: 22px;
}

.empty-state h3 {
  margin: 0;
  font-size: 16px;
}

.empty-state p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 12px;
}

/* Read-only field board */

body[data-view-mode="board"] {
  background: #edf2ee;
}

body[data-view-mode="board"] .topbar {
  display: none;
}

.field-board {
  min-height: 100vh;
  background:
    radial-gradient(circle at 8% 0%, rgba(72, 142, 117, 0.18), transparent 28%),
    #edf2ee;
}

.field-board-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 28px;
  padding: 28px 38px;
  background: var(--forest-950);
  color: #fff;
}

.field-board-brand,
.field-board-tools,
.field-board-actions {
  display: flex;
  align-items: center;
}

.field-board-brand {
  gap: 20px;
}

.field-board-brand .eyebrow {
  margin-bottom: 5px;
  color: #8fd0b8;
}

.field-board-brand h1 {
  margin: 0;
  font-size: clamp(28px, 3vw, 46px);
  letter-spacing: -0.055em;
  line-height: 1.05;
}

.field-board-brand p:last-child {
  margin: 8px 0 0;
  color: rgba(255, 255, 255, 0.66);
  font-size: 14px;
}

.field-board-tools {
  align-items: flex-end;
  flex-direction: column;
  gap: 10px;
}

.field-board-tools time {
  font-variant-numeric: tabular-nums;
  font-size: clamp(24px, 3vw, 38px);
  font-weight: 760;
  letter-spacing: -0.04em;
}

.field-board-actions {
  gap: 8px;
}

.board-button {
  min-height: 36px;
  padding: 7px 12px;
  border-color: rgba(255, 255, 255, 0.24);
  background: rgba(255, 255, 255, 0.09);
  color: #fff;
  font-size: 12px;
}

.board-sync-status {
  display: flex;
  min-height: 48px;
  align-items: center;
  justify-content: center;
  gap: 9px;
  padding: 10px 24px;
  border-bottom: 1px solid #cee0d7;
  background: #e3f4eb;
  color: #315b4d;
  font-size: 13px;
}

.board-sync-status strong {
  color: var(--forest-900);
}

.board-sync-status.sync-error {
  border-color: #e8c3c3;
  background: #fff0f0;
  color: #8b3737;
}

.board-sync-status.sync-error strong {
  color: #7d2929;
}

.sync-pulse {
  width: 9px;
  height: 9px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: #2d9a68;
  box-shadow: 0 0 0 5px rgba(45, 154, 104, 0.12);
}

.sync-syncing .sync-pulse {
  animation: sync-pulse 1.2s ease-in-out infinite;
}

.sync-error .sync-pulse {
  background: var(--red);
  box-shadow: 0 0 0 5px rgba(173, 51, 51, 0.11);
}

.sync-disabled .sync-pulse {
  background: #7b8984;
  box-shadow: 0 0 0 5px rgba(123, 137, 132, 0.12);
}

@keyframes sync-pulse {
  50% { opacity: 0.38; transform: scale(0.78); }
}

.board-body {
  width: min(100%, 1800px);
  margin: 0 auto;
  padding: 24px 30px 54px;
}

.board-summary {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
}

.board-summary-card {
  display: flex;
  min-height: 82px;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 15px 18px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  box-shadow: var(--shadow-sm);
}

.board-summary-card span {
  color: var(--muted);
  font-size: 14px;
  font-weight: 760;
}

.board-summary-card strong {
  font-size: 34px;
  letter-spacing: -0.05em;
}

.board-summary-ready_for_review strong { color: var(--purple); }
.board-summary-approved strong { color: var(--green); }
.board-summary-needs_attention strong { color: var(--red); }

.board-list-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  margin: 28px 2px 14px;
}

.board-list-heading h2 {
  margin: 0;
  font-size: 23px;
  letter-spacing: -0.04em;
}

.board-list-heading > p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.board-list-heading > p strong {
  color: var(--forest-900);
  font-size: 18px;
}

.board-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(520px, 100%), 1fr));
  gap: 14px;
}

.board-patient-card {
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-left: 7px solid var(--blue);
  border-radius: 16px;
  background: #fff;
  box-shadow: 0 4px 18px rgba(16, 46, 41, 0.06);
}

.board-tone-amber { border-left-color: var(--amber); }
.board-tone-purple { border-left-color: var(--purple); }
.board-tone-green { border-left-color: var(--green); }
.board-tone-red { border-left-color: var(--red); }
.board-tone-gray { border-left-color: #78827f; }

.board-patient-header {
  display: flex;
  min-height: 84px;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfb;
}

.board-patient-header > div > span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 780;
}

.board-patient-header h3 {
  margin: 3px 0 0;
  font-size: clamp(23px, 2vw, 31px);
  letter-spacing: -0.045em;
}

.board-patient-header .status-badge {
  min-height: 34px;
  padding: 7px 11px;
  font-size: 12px;
}

.board-medication-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.board-medication {
  display: grid;
  grid-template-columns: 30px minmax(160px, 1.3fr) minmax(190px, 1fr) auto;
  align-items: center;
  gap: 12px;
  min-height: 78px;
  padding: 13px 18px;
  border-bottom: 1px solid var(--line);
}

.board-medication:last-child {
  border-bottom: 0;
}

.board-medication.is-prepared {
  background: #f5fbf7;
}

.board-medication-check {
  display: grid;
  width: 26px;
  height: 26px;
  place-items: center;
  border: 2px solid var(--line-strong);
  border-radius: 7px;
  color: #fff;
  font-size: 16px;
  font-weight: 900;
}

.board-medication.is-prepared .board-medication-check {
  border-color: var(--green);
  background: var(--green);
}

.board-medication-name {
  min-width: 0;
}

.board-medication-name strong,
.board-medication-name small {
  display: block;
}

.board-medication-name strong {
  overflow: hidden;
  font-size: 17px;
  text-overflow: ellipsis;
}

.board-medication-name small {
  margin-top: 3px;
  color: #6c5b31;
  font-size: 12px;
}

.board-medication-dose {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.board-medication-dose span {
  padding: 5px 7px;
  border-radius: 6px;
  background: #f0f3f1;
  color: #45504c;
  font-size: 12px;
  font-weight: 720;
}

.board-medication-location {
  min-width: 72px;
  padding: 8px 10px;
  border-radius: 9px;
  background: var(--amber-bg);
  color: var(--amber);
  font-size: 15px;
  text-align: center;
}

.board-patient-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 20px;
  border-top: 1px solid var(--line);
  background: #f7f9f7;
  color: var(--muted);
  font-size: 12px;
}

.board-route-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 10px 20px;
  border-top: 1px solid var(--line);
  font-size: 12px;
}

.board-route-line span {
  color: var(--muted);
  font-weight: 700;
}

.board-route-line strong {
  font-size: 14px;
}

.board-route-pharmacy {
  background: #f8f5ff;
  color: var(--purple);
}

.board-route-home {
  background: var(--forest-50);
  color: var(--forest-800);
}

.board-patient-footer strong {
  color: var(--forest-800);
}

.board-empty {
  display: flex;
  min-height: 220px;
  align-items: center;
  justify-content: center;
  gap: 18px;
  border: 1px dashed var(--line-strong);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.72);
}

.board-empty > span {
  display: grid;
  width: 48px;
  height: 48px;
  place-items: center;
  border-radius: 50%;
  background: var(--green-bg);
  color: var(--green);
  font-size: 23px;
  font-weight: 900;
}

.board-empty strong {
  font-size: 18px;
}

.board-empty p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 13px;
}

/* Overlay and detail */

.overlay {
  position: fixed;
  z-index: 100;
  inset: 0;
  display: flex;
  justify-content: flex-end;
  background: rgba(10, 29, 25, 0.42);
  backdrop-filter: blur(3px);
}

.overlay-centered {
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.detail-drawer {
  display: flex;
  width: min(720px, 100%);
  height: 100%;
  flex-direction: column;
  background: var(--cream);
  box-shadow: var(--shadow-lg);
  animation: drawer-in 180ms ease-out;
}

@keyframes drawer-in {
  from { transform: translateX(28px); opacity: 0.4; }
  to { transform: translateX(0); opacity: 1; }
}

.drawer-header,
.modal-header {
  display: flex;
  min-height: 80px;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 17px 22px;
  border-bottom: 1px solid var(--line);
  background: var(--paper);
}

.drawer-header h2,
.modal-header h2 {
  margin: 0;
  font-size: 22px;
  letter-spacing: -0.04em;
}

.drawer-content {
  overflow-y: auto;
}

.drawer-section {
  padding: 24px;
  border-bottom: 1px solid var(--line);
  background: var(--paper);
}

.drawer-section + .drawer-section {
  margin-top: 10px;
}

.drawer-action-section {
  padding-bottom: 40px;
}

.detail-status-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}

.detail-status-line > span:last-child {
  color: var(--muted);
  font-size: 10px;
}

.notice {
  margin-bottom: 16px;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 12px;
  line-height: 1.6;
}

.notice strong {
  margin-right: 6px;
}

.notice ul {
  margin: 8px 0 0;
  padding-left: 20px;
}

.notice-danger {
  border-color: #eccaca;
  background: var(--red-bg);
  color: #7e2a2a;
}

.notice-safe {
  border-color: #bcdccc;
  background: var(--forest-50);
  color: var(--forest-900);
}

.info-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--line);
}

.info-pair {
  display: grid;
  gap: 4px;
  min-height: 68px;
  align-content: center;
  padding: 12px 14px;
  background: #fff;
}

.info-pair span {
  color: var(--muted);
  font-size: 10px;
}

.info-pair strong {
  overflow: hidden;
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.source-note {
  margin-top: 14px;
  padding: 13px 14px;
  border-left: 3px solid var(--forest-700);
  background: #f7f9f7;
}

.route-flow {
  display: grid;
  grid-template-columns: minmax(130px, auto) 1fr;
  align-items: center;
  gap: 12px;
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: 10px;
  font-size: 11px;
}

.route-flow strong {
  font-size: 12px;
}

.route-flow span {
  color: var(--muted);
}

.route-flow-pharmacy {
  background: var(--purple-bg);
  color: var(--purple);
}

.route-flow-home {
  background: var(--forest-50);
  color: var(--forest-800);
}

.source-note strong {
  color: var(--forest-800);
  font-size: 10px;
}

.source-note p {
  margin: 4px 0 0;
  font-size: 12px;
}

.section-title {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 15px;
}

.section-title h3 {
  margin: 0;
  font-size: 17px;
}

.regular-count {
  padding: 5px 8px;
  border-radius: 7px;
  background: var(--gray-bg);
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
}

.medication-list {
  display: grid;
  gap: 10px;
}

.medication-card {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: #fff;
}

.medication-card.is-prepared {
  border-color: #aad2c0;
  background: #fbfefc;
}

.medication-check {
  display: grid;
  place-items: start center;
  padding-top: 18px;
  border-right: 1px solid var(--line);
  background: #f8faf8;
}

.medication-check input,
.check-line input {
  width: 19px;
  height: 19px;
  accent-color: var(--forest-800);
}

.med-check-mark {
  display: grid;
  width: 20px;
  height: 20px;
  place-items: center;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  color: var(--green);
  font-size: 13px;
  font-weight: 900;
}

.medication-main {
  min-width: 0;
  padding: 15px;
}

.medication-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.medication-heading h4 {
  margin: 5px 0 0;
  font-size: 15px;
}

.category-tag,
.location-tag {
  display: inline-flex;
  align-items: center;
  border-radius: 6px;
  font-size: 9px;
  font-weight: 800;
}

.category-tag {
  padding: 3px 6px;
  background: var(--forest-50);
  color: var(--forest-800);
}

.location-tag {
  max-width: 130px;
  padding: 5px 7px;
  background: var(--amber-bg);
  color: var(--amber);
  text-align: right;
}

.ingredient {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 10px;
}

.dose-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  margin-top: 13px;
}

.dose-grid > span {
  display: grid;
  gap: 2px;
  padding: 8px;
  border-radius: 8px;
  background: #f6f8f6;
}

.dose-grid small {
  color: var(--muted);
  font-size: 9px;
}

.dose-grid strong {
  font-size: 12px;
}

.instruction {
  display: flex;
  gap: 7px;
  margin: 9px 0 0;
  color: #5d512d;
  font-size: 10px;
}

.instruction strong {
  flex: 0 0 auto;
}

.inline-edit {
  display: grid;
  grid-template-columns: 64px 1fr;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
}

.inline-edit span {
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
}

.inline-edit input {
  min-height: 34px;
  padding: 6px 9px;
  font-size: 11px;
}

.prepared-by {
  margin: 11px 0 0;
  color: var(--muted);
  font-size: 10px;
  text-align: right;
}

.action-panel {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: #f8faf8;
}

.action-panel h3 {
  margin: 0;
  font-size: 15px;
}

.action-panel > p {
  margin: 6px 0 14px;
  color: var(--muted);
  font-size: 11px;
}

.action-panel .stacked-field {
  margin: 14px 0;
}

.action-panel-danger {
  border-color: #e9c5c5;
  background: #fff8f8;
}

.action-panel-purple {
  border-color: #d8cef0;
  background: #fbf9ff;
}

.action-panel-green {
  border-color: #bddccb;
  background: #f7fcf9;
}

.action-row {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 8px;
}

.check-line {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 11px 0;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}

.check-line span {
  color: var(--muted);
  font-size: 11px;
}

.check-line strong {
  display: block;
  color: var(--ink);
  font-size: 12px;
}

.completion-panel {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 17px;
  border: 1px solid #b7dac7;
  border-radius: 13px;
  background: var(--green-bg);
}

.completion-panel > span {
  display: grid;
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 50%;
  background: var(--green);
  color: #fff;
  font-weight: 900;
}

.completion-panel strong {
  font-size: 14px;
}

.completion-panel p {
  margin: 2px 0 0;
  color: #4f685d;
  font-size: 10px;
}

/* Modals and audit */

.modal {
  width: min(100%, 620px);
  max-height: min(90vh, 860px);
  overflow: hidden;
  border-radius: 18px;
  background: var(--paper);
  box-shadow: var(--shadow-lg);
}

.modal-wide {
  width: min(100%, 760px);
}

.modal-body {
  max-height: calc(90vh - 80px);
  overflow-y: auto;
  padding: 22px;
}

.upload-box {
  display: grid;
  min-height: 120px;
  place-items: center;
  align-content: center;
  gap: 6px;
  border: 1px dashed #9eb9ae;
  border-radius: 12px;
  background: #fafcfb;
  color: var(--forest-900);
  cursor: pointer;
  text-align: center;
}

.upload-box span {
  color: var(--muted);
  font-size: 11px;
}

.upload-box input {
  max-width: 260px;
  margin-top: 8px;
  font-size: 11px;
}

.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 18px 0;
  color: var(--muted);
  font-size: 10px;
}

.divider::before,
.divider::after {
  height: 1px;
  flex: 1;
  background: var(--line);
  content: "";
}

.contract-details {
  margin-top: 12px;
  color: var(--muted);
  font-size: 11px;
}

.contract-details code {
  display: block;
  margin-top: 8px;
  padding: 10px;
  border-radius: 8px;
  background: #f5f7f5;
  color: #41504c;
  font-size: 10px;
  line-height: 1.7;
  word-break: break-word;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
}

.modal-actions-split {
  justify-content: space-between;
}

.audit-list {
  display: grid;
  margin-top: 16px;
}

.audit-item {
  display: grid;
  grid-template-columns: 12px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 13px 3px;
  border-bottom: 1px solid var(--line);
}

.audit-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--forest-700);
}

.audit-item strong {
  font-size: 12px;
}

.audit-item p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 10px;
}

.audit-item time {
  color: var(--muted);
  font-size: 10px;
}

.loading-line,
.empty-compact {
  padding: 30px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.toast-region {
  position: fixed;
  z-index: 300;
  top: 18px;
  right: 18px;
  display: grid;
  gap: 8px;
  pointer-events: none;
}

.toast {
  width: min(360px, calc(100vw - 36px));
  padding: 12px 14px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 10px;
  background: #24312e;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.2);
  color: #fff;
  font-size: 12px;
  font-weight: 650;
  opacity: 0;
  transform: translateY(-6px);
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.toast-error {
  background: #8d2f2f;
}

.toast-success {
  background: var(--forest-800);
}

@media (max-width: 1180px) {
  .summary-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .summary-card {
    min-height: 108px;
  }

  .queue-layout {
    grid-template-columns: 185px minmax(0, 1fr);
  }

  .queue-table th:nth-child(4),
  .queue-table td:nth-child(4) {
    display: none;
  }
}

@media (max-width: 840px) {
  .login-page,
  body[data-app-state="login"] .login-page {
    display: block;
  }

  .login-brand {
    min-height: auto;
    padding: 44px 26px 52px;
  }

  .login-brand h1 {
    font-size: clamp(36px, 10vw, 54px);
  }

  .login-brand .eyebrow {
    margin-top: 28px;
  }

  .login-lede br {
    display: none;
  }

  .privacy-note {
    margin-top: 32px;
  }

  .login-panel {
    min-height: auto;
    padding: 24px 18px 42px;
  }

  .login-card {
    padding: 28px 22px;
    border-radius: 18px;
    box-shadow: var(--shadow-sm);
  }

  .topbar {
    padding: 0 14px;
  }

  .internal-chip,
  .topbar-actions > .button-ghost,
  .identity-chip span {
    display: none;
  }

  .identity-chip {
    padding-left: 6px;
  }

  .safety-strip {
    align-items: flex-start;
    flex-direction: column;
    gap: 1px;
    padding: 8px 14px;
    text-align: left;
  }

  .workspace {
    padding: 26px 14px 50px;
  }

  .page-heading {
    align-items: stretch;
    flex-direction: column;
    gap: 18px;
  }

  .heading-actions {
    display: grid;
    grid-template-columns: 1fr 1.5fr;
  }

  .summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    margin-top: 20px;
  }

  .summary-card {
    min-height: 104px;
    padding: 13px;
  }

  .summary-card > strong {
    font-size: 28px;
  }

  .summary-card > small {
    display: none;
  }

  .queue-layout {
    display: block;
    margin-top: 12px;
  }

  .filter-panel {
    overflow-x: auto;
    padding: 8px;
    border-radius: 13px;
  }

  .filter-panel h2,
  .filter-help {
    display: none;
  }

  .filter-list {
    display: flex;
    width: max-content;
  }

  .filter-button {
    gap: 7px;
    white-space: nowrap;
  }

  .queue-panel {
    margin-top: 10px;
  }

  .queue-toolbar {
    align-items: stretch;
    flex-direction: column;
    gap: 12px;
    padding: 14px;
  }

  .search-field {
    width: 100%;
  }

  .queue-table-wrap {
    display: none;
  }

  .queue-card-list {
    display: grid;
    gap: 10px;
    padding: 10px;
  }

  .queue-card {
    display: block;
    width: 100%;
    padding: 15px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #fff;
    cursor: pointer;
    text-align: left;
  }

  .queue-card-top,
  .queue-card-bottom {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
  }

  .queue-card-top > span {
    color: var(--muted);
    font-size: 10px;
    font-weight: 750;
  }

  .queue-card h3 {
    margin: 12px 0 2px;
    font-size: 17px;
  }

  .queue-card > p {
    margin: 0;
    color: var(--muted);
    font-size: 11px;
  }

  .queue-card-meds {
    margin-top: 12px;
    padding: 10px;
    border-radius: 8px;
    background: #f7f9f7;
  }

  .queue-card-meds strong,
  .queue-card-meds small {
    display: block;
  }

  .queue-card-meds .route-chip {
    display: inline-flex;
  }

  .queue-card-meds strong {
    font-size: 12px;
  }

  .queue-card-meds small {
    margin-top: 2px;
    color: var(--muted);
    font-size: 9px;
  }

  .queue-card-bottom {
    margin-top: 13px;
    padding-top: 11px;
    border-top: 1px solid var(--line);
    color: var(--muted);
    font-size: 10px;
  }

  .queue-card-bottom strong {
    color: var(--forest-800);
  }

  .field-board-header {
    align-items: flex-start;
    flex-direction: column;
    padding: 24px 18px;
  }

  .field-board-brand {
    align-items: flex-start;
  }

  .field-board-brand .brand-symbol {
    width: 46px;
    height: 46px;
    border-radius: 14px 14px 14px 5px;
    font-size: 24px;
  }

  .field-board-tools {
    width: 100%;
    align-items: center;
    justify-content: space-between;
    flex-direction: row;
  }

  .board-sync-status {
    align-items: flex-start;
    justify-content: flex-start;
    flex-wrap: wrap;
    padding: 11px 16px;
  }

  .board-sync-status > span:last-child {
    width: calc(100% - 20px);
    margin-left: 18px;
  }

  .board-body {
    padding: 16px 14px 40px;
  }

  .board-summary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .board-summary-card {
    min-height: 66px;
    padding: 12px 14px;
  }

  .board-summary-card strong {
    font-size: 28px;
  }

  .board-list-heading {
    align-items: flex-start;
    flex-direction: column;
    gap: 5px;
    margin-top: 22px;
  }

  .board-grid {
    grid-template-columns: 1fr;
  }

  .board-medication {
    grid-template-columns: 28px minmax(0, 1fr) auto;
  }

  .board-medication-dose {
    grid-column: 2 / -1;
  }

  .overlay-centered {
    align-items: flex-end;
    padding: 0;
  }

  .modal {
    max-height: 94vh;
    border-radius: 18px 18px 0 0;
  }

  .detail-drawer {
    width: 100%;
  }
}

@media (max-width: 520px) {
  .topbar-brand span {
    display: none;
  }

  .topbar-brand strong {
    font-size: 14px;
  }

  .identity-chip strong {
    max-width: 70px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .page-heading h1 {
    font-size: 31px;
  }

  .drawer-header,
  .modal-header {
    min-height: 72px;
    padding: 14px 16px;
  }

  .drawer-section,
  .modal-body {
    padding: 16px;
  }

  .info-grid {
    grid-template-columns: 1fr;
  }

  .info-pair {
    min-height: 58px;
  }

  .medication-card {
    grid-template-columns: 36px minmax(0, 1fr);
  }

  .medication-main {
    padding: 13px;
  }

  .medication-heading {
    display: block;
  }

  .location-tag {
    margin-top: 8px;
  }

  .dose-grid {
    gap: 4px;
  }

  .dose-grid > span {
    padding: 7px 5px;
  }

  .action-row,
  .modal-actions-split {
    display: grid;
    grid-template-columns: 1fr;
  }

  .modal-actions-split .button-primary {
    order: -1;
  }

  .toast-region {
    top: 10px;
    right: 10px;
  }

  .field-board-brand h1 {
    font-size: 27px;
  }

  .field-board-brand p:last-child {
    font-size: 12px;
  }

  .field-board-tools time {
    font-size: 23px;
  }

  .board-button {
    min-height: 34px;
    padding: 6px 9px;
    font-size: 11px;
  }

  .board-summary-card span {
    font-size: 12px;
  }

  .board-patient-header {
    min-height: 74px;
    padding: 13px 14px;
  }

  .board-patient-header h3 {
    font-size: 22px;
  }

  .board-patient-header .status-badge {
    min-height: 29px;
    padding: 5px 8px;
    font-size: 10px;
  }

  .board-medication {
    gap: 9px;
    padding: 12px 13px;
  }

  .board-medication-name strong {
    font-size: 15px;
  }

  .board-medication-location {
    min-width: 60px;
    padding: 7px;
    font-size: 13px;
  }

  .board-patient-footer {
    align-items: flex-start;
    flex-direction: column;
    gap: 3px;
    padding: 10px 14px;
  }

  .board-route-line {
    padding: 10px 14px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
