/* ============================================================
   Multi-Language Pharmacy Label System — Apple HIG UI Design
   Standard Human Interface Guidelines (HIG) · SF Pro & Sarabun
   ============================================================ */

/* ============================================================
   Authentication Gate — Store Passcode Login
   ============================================================ */
.auth-gate {
  position: fixed;
  inset: 0;
  z-index: 99999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 40%, #0f172a 100%);
  font-family: 'Inter', 'Sarabun', -apple-system, BlinkMacSystemFont, sans-serif;
  animation: authFadeIn 0.4s ease;
}
.auth-gate::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 600px 400px at 30% 20%, rgba(56, 189, 248, 0.08) 0%, transparent 70%),
    radial-gradient(ellipse 500px 300px at 70% 80%, rgba(99, 102, 241, 0.06) 0%, transparent 70%);
  pointer-events: none;
}
@keyframes authFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
.auth-gate.auth-exit {
  animation: authFadeOut 0.35s ease forwards;
}
@keyframes authFadeOut {
  to { opacity: 0; pointer-events: none; }
}

.auth-card {
  position: relative;
  width: min(400px, 90vw);
  background: rgba(255, 255, 255, 0.06);
  backdrop-filter: blur(24px) saturate(1.4);
  -webkit-backdrop-filter: blur(24px) saturate(1.4);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 20px;
  padding: 40px 32px 32px;
  text-align: center;
  box-shadow:
    0 8px 32px rgba(0, 0, 0, 0.3),
    0 0 0 1px rgba(255, 255, 255, 0.05) inset;
  animation: authCardSlide 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes authCardSlide {
  from { opacity: 0; transform: translateY(20px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.auth-logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 72px;
  height: 72px;
  border-radius: 18px;
  background: linear-gradient(135deg, #3b82f6, #6366f1);
  color: #fff;
  margin-bottom: 16px;
  box-shadow: 0 4px 16px rgba(99, 102, 241, 0.35);
}

.auth-title {
  color: #f1f5f9;
  font-size: 22px;
  font-weight: 700;
  margin: 0 0 4px;
  letter-spacing: -0.02em;
}
.auth-subtitle {
  color: #94a3b8;
  font-size: 14px;
  margin: 0 0 28px;
}

.auth-input-wrap {
  position: relative;
  margin-bottom: 12px;
}
.auth-input-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: #64748b;
  pointer-events: none;
}
.auth-input {
  width: 100%;
  padding: 14px 46px;
  font-size: 15px;
  font-family: inherit;
  color: #f1f5f9;
  background: rgba(255, 255, 255, 0.07);
  border: 1.5px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
  box-sizing: border-box;
}
.auth-input::placeholder {
  color: #64748b;
}
.auth-input:focus {
  border-color: #6366f1;
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
  background: rgba(255, 255, 255, 0.1);
}
.auth-input.auth-shake {
  animation: authShake 0.4s ease;
}
@keyframes authShake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-8px); }
  40% { transform: translateX(8px); }
  60% { transform: translateX(-5px); }
  80% { transform: translateX(5px); }
}

.auth-toggle-vis {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: #64748b;
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s;
}
.auth-toggle-vis:hover {
  color: #94a3b8;
}

.auth-error {
  font-size: 13px;
  color: #f87171;
  background: rgba(248, 113, 113, 0.1);
  border: 1px solid rgba(248, 113, 113, 0.2);
  border-radius: 8px;
  padding: 8px 12px;
  margin-bottom: 12px;
  text-align: left;
  display: flex;
  align-items: center;
  gap: 6px;
}
.auth-error::before {
  content: '';
  display: inline-block;
  width: 16px;
  height: 16px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23f87171' stroke-width='2'%3E%3Ccircle cx='12' cy='12' r='10'/%3E%3Cline x1='12' y1='8' x2='12' y2='12'/%3E%3Cline x1='12' y1='16' x2='12.01' y2='16'/%3E%3C/svg%3E") no-repeat center / contain;
  flex-shrink: 0;
}

.auth-submit {
  width: 100%;
  padding: 13px 20px;
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  color: #fff;
  background: linear-gradient(135deg, #3b82f6, #6366f1);
  border: none;
  border-radius: 12px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: opacity 0.2s, transform 0.15s, box-shadow 0.2s;
  box-shadow: 0 2px 12px rgba(99, 102, 241, 0.3);
}
.auth-submit:hover {
  opacity: 0.92;
  box-shadow: 0 4px 20px rgba(99, 102, 241, 0.4);
}
.auth-submit:active {
  transform: scale(0.98);
}
.auth-submit:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.auth-footer {
  color: #475569;
  font-size: 12px;
  margin: 20px 0 0;
}

:root {
  /* Apple System Palette */
  --bg: #f5f5f7;
  --surface: #ffffff;
  --surface-secondary: #fbfbfd;
  --surface-tertiary: #f2f2f7;

  --line: rgba(0, 0, 0, 0.08);
  --line-strong: rgba(0, 0, 0, 0.15);
  --line-soft: rgba(0, 0, 0, 0.04);

  /* Apple Accent Colors */
  --blue: #0071e3;
  --blue-hover: #0077ed;
  --blue-active: #0068d6;
  --blue-dark: #0056b3;
  --blue-deep: #003e80;
  --blue-soft: #f0f6ff;
  --blue-ring: rgba(0, 113, 227, 0.20);

  --green: #34c759;
  --green-dark: #28a745;
  --green-soft: #eafaf1;

  --red: #ff3b30;
  --red-hover: #d70015;
  --red-soft: #fff1f0;

  --amber: #ff9500;
  --amber-soft: #fff8eb;

  /* Apple Typography Colors */
  --ink: #1d1d1f;
  /* Apple Primary Label */
  --ink-2: #424245;
  /* Apple Secondary Label */
  --ink-3: #86868b;
  /* Apple Tertiary Label */
  --ink-4: #a1a1a6;
  /* Apple Quaternary Label */

  /* Apple Elevation Shadows */
  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.04), 0 1px 2px rgba(0, 0, 0, 0.02);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.06), 0 1px 4px rgba(0, 0, 0, 0.03);
  --shadow-lg: 0 12px 36px rgba(0, 0, 0, 0.10), 0 4px 12px rgba(0, 0, 0, 0.05);

  /* Apple Corner Radiuses (Squircle feel) */
  --r-xs: 6px;
  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 18px;
  --r-pill: 980px;

  /* Typography Stack */
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Sarabun", "Noto Sans SC", "Helvetica Neue", system-ui, sans-serif;
  --font-label: "Sarabun", "Noto Sans SC", -apple-system, BlinkMacSystemFont, "Inter", sans-serif;

  /* label sheet dimensions (print) */
  --ls-w: 80mm;
  --ls-h: 60mm;
}

/* 80×50mm (8×5 cm) standard label mode */
html.size-80x50 {
  --ls-w: 80mm;
  --ls-h: 50mm;
}

/* 80×60mm (8×6 cm) standard label mode */
html.size-80x60 {
  --ls-w: 80mm;
  --ls-h: 60mm;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  height: 100%;
}

body {
  font-family: var(--font);
  background-color: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  letter-spacing: -0.011em;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  font-size: 13px;
  -webkit-tap-highlight-color: transparent;
}

input,
textarea,
select {
  font-family: inherit;
  -webkit-appearance: none;
}

kbd {
  font-family: var(--font);
  font-size: 11px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.04);
  color: var(--ink-2);
}

/* ================= App Bar (Apple Translucent Header) ================= */

.app-bar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border-bottom: 1px solid var(--line);
  transition: background 0.2s ease, border-color 0.2s ease;
}

.app-bar-inner {
  max-width: 1240px;
  margin: 0 auto;
  padding: 11px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-icon {
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  display: grid;
  place-items: center;
  font-size: 20px;
  border-radius: 10px;
  background: linear-gradient(145deg, #0071e3, #0056b3);
  box-shadow: 0 3px 10px rgba(0, 113, 227, 0.35);
}

.brand-text h1 {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.015em;
  color: var(--ink);
  white-space: nowrap;
}

.brand-sub {
  font-size: 12px;
  color: var(--ink-3);
  display: flex;
  align-items: center;
  gap: 6px;
}

.brand-sub .ver {
  font-size: 10.5px;
  font-weight: 600;
  color: var(--blue);
  background: var(--blue-soft);
  padding: 1px 7px;
  border-radius: var(--r-pill);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.btn-settings {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-2);
  background: var(--surface-tertiary);
  border: 1px solid transparent;
  border-radius: var(--r-pill);
  cursor: pointer;
  transition: all .15s cubic-bezier(0.25, 0.1, 0.25, 1);
}

.btn-settings svg {
  width: 16px;
  height: 16px;
  color: var(--ink-3);
  transition: color .15s;
}

.btn-settings:hover {
  background: var(--blue-soft);
  color: var(--blue);
  border-color: rgba(0, 113, 227, 0.15);
}

.btn-settings:hover svg {
  color: var(--blue);
}

.btn-settings:active {
  transform: scale(0.97);
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 14px 4px 5px;
  border-radius: var(--r-pill);
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow-xs);
  flex: 0 0 auto;
  cursor: pointer;
  transition: all .15s cubic-bezier(0.25, 0.1, 0.25, 1);
}

.user-chip:hover {
  border-color: rgba(0, 113, 227, 0.3);
  box-shadow: 0 2px 10px rgba(0, 113, 227, 0.08);
}

.user-chip:active {
  transform: scale(0.98);
}

.avatar {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: linear-gradient(145deg, #0071e3, #0056b3);
  color: #fff;
  font-weight: 600;
  font-size: 15px;
}

.user-name {
  font-size: 13px;
  font-weight: 600;
  line-height: 1.15;
  color: var(--ink);
}

.user-role {
  font-size: 11px;
  color: var(--ink-3);
}

/* ================= Cards / Workspace ================= */

.workspace {
  max-width: 1240px;
  margin: 0 auto;
  padding: 24px 24px 48px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.2s ease;
}

/* ----- Patient strip (Clean Apple Form Card) ----- */

.strip {
  padding: 16px 20px 18px;
}

.strip-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  gap: 12px;
  flex-wrap: wrap;
}

.strip-title {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: -0.012em;
  color: var(--ink);
  display: flex;
  align-items: baseline;
}

.strip-title .hint {
  font-size: 11.5px;
  font-weight: 400;
  color: var(--ink-3);
  margin-left: 6px;
}

.strip-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-strip-action {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 12px;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-2);
  background: var(--surface-tertiary);
  border: 1px solid var(--line);
  border-radius: var(--r-pill);
  cursor: pointer;
  transition: all .15s ease;
}

.btn-strip-action:hover {
  background: var(--blue-soft);
  color: var(--blue);
  border-color: rgba(0, 113, 227, 0.25);
}

.btn-strip-action.danger:hover {
  background: var(--red-soft);
  color: var(--red);
  border-color: rgba(255, 59, 48, 0.25);
}

.btn-strip-action:active {
  transform: scale(0.96);
}

.strip-grid {
  display: grid;
  grid-template-columns: 2fr 0.9fr 1.1fr 1.1fr 2fr;
  gap: 16px;
  align-items: end;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.field.grow2 {
  grid-column: span 1;
}

.field>span {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--ink-2);
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.field>span i {
  font-style: normal;
  font-size: 10.5px;
  font-weight: 400;
  color: var(--ink-3);
}

.field input {
  width: 100%;
  font-size: 14px;
  font-weight: 500;
  color: var(--ink);
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--surface-tertiary);
  outline: none;
  transition: all .15s ease;
}

.field input:hover {
  border-color: rgba(0, 0, 0, 0.18);
  background: #ffffff;
}

.field input:focus {
  background: #ffffff;
  border-color: var(--blue);
  box-shadow: 0 0 0 3.5px var(--blue-ring);
}

/* ----- Toolbar (Apple Pro Command Bar) ----- */

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 18px;
  position: relative;
  z-index: 30;
  flex-wrap: wrap;
}

.toolbar-left {
  flex: 1 1 220px;
}

.toolbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1 1 auto;
  flex-wrap: wrap;
  justify-content: flex-end;
}

@media (max-width: 680px) {
  .toolbar-right .btn-print {
    width: 100%;
    justify-content: center;
    margin-left: 0;
  }
}

/* ---- Print guide modal ---- */
.guide-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 150;
  display: grid;
  place-items: center;
  padding: 16px;
  animation: fadeIn .18s ease;
}

.guide-card {
  background: #ffffff;
  border-radius: var(--r-lg);
  max-width: 540px;
  width: 100%;
  max-height: 86vh;
  overflow-y: auto;
  padding: 24px 26px;
  box-shadow: var(--shadow-lg);
  animation: popIn .2s cubic-bezier(.16, 1, .3, 1);
}

.guide-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 16px;
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 16px;
}

.guide-close {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: var(--surface-tertiary);
  color: var(--ink-3);
  font-size: 14px;
  cursor: pointer;
  transition: all .15s ease;
}

.guide-close:hover {
  background: var(--red-soft);
  color: var(--red);
}

.guide-step {
  display: flex;
  gap: 12px;
  margin-bottom: 12px;
  font-size: 13.5px;
  line-height: 1.55;
  color: var(--ink-2);
}

.guide-step b {
  color: var(--ink);
  font-weight: 600;
}

.guide-num {
  flex: 0 0 22px;
  height: 22px;
  display: grid;
  place-items: center;
  background: var(--blue-soft);
  color: var(--blue);
  font-weight: 700;
  border-radius: 50%;
  font-size: 12px;
  margin-top: 1px;
}

.guide-note {
  background: var(--amber-soft);
  border: 1px solid rgba(255, 149, 0, 0.25);
  border-radius: var(--r-sm);
  padding: 12px 14px;
  font-size: 12.5px;
  color: #944b00;
  line-height: 1.5;
  margin-top: 6px;
}

/* Search input (Apple Spotlight Style) */
.search-wrap {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
  min-width: 260px;
}

.search-icon {
  width: 17px;
  height: 17px;
  color: var(--ink-3);
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
}

#drugSearch {
  width: 100%;
  font-size: 14px;
  padding: 10px 46px 10px 42px;
  border: 1px solid var(--line);
  border-radius: var(--r-pill);
  background: var(--surface-tertiary);
  outline: none;
  color: var(--ink);
  transition: all .15s ease;
}

#drugSearch:hover {
  border-color: rgba(0, 0, 0, 0.18);
  background: #ffffff;
}

#drugSearch:focus {
  background: #ffffff;
  border-color: var(--blue);
  box-shadow: 0 0 0 3.5px var(--blue-ring);
}

.search-wrap .kbd {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
  background: rgba(0, 0, 0, 0.05);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 20px;
  min-width: 20px;
  padding: 0 4px;
  box-sizing: border-box;
  line-height: 1;
}

.search-drop {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  z-index: 60;
  animation: popIn .16s ease;
}

.search-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 10px 16px;
  border: 0;
  background: transparent;
  text-align: left;
  border-bottom: 1px solid var(--line-soft);
  cursor: pointer;
  transition: background .12s;
}

.search-item:last-child {
  border-bottom: 0;
}

.search-item:hover,
.search-item.sel {
  background: var(--blue-soft);
}

.search-item .si-main {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ink);
  display: flex;
  align-items: center;
  gap: 8px;
}

.search-item .si-sub {
  font-size: 12px;
  color: var(--ink-3);
}

.search-item .si-bc {
  margin-left: auto;
  font-size: 11px;
  font-weight: 500;
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
  letter-spacing: .3px;
  background: rgba(0, 0, 0, 0.04);
  padding: 2px 8px;
  border-radius: 6px;
  white-space: nowrap;
}

.search-item .si-match {
  font-size: 10px;
  font-weight: 600;
  color: var(--green);
  background: var(--green-soft);
  padding: 1px 7px;
  border-radius: var(--r-pill);
}

.search-empty {
  padding: 18px;
  font-size: 13px;
  color: var(--ink-3);
  text-align: center;
}

/* Primary Print Button (Apple Call to Action) */
.btn-print {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
  font-size: 13.5px;
  font-weight: 600;
  color: #ffffff;
  background: #34c759;
  border: 0;
  border-radius: var(--r-pill);
  padding: 10px 20px;
  min-height: 40px;
  box-shadow: 0 3px 12px rgba(52, 199, 89, 0.35);
  cursor: pointer;
  transition: all .15s cubic-bezier(0.25, 0.1, 0.25, 1);
}

.btn-print svg {
  width: 16px;
  height: 16px;
}

.btn-print:hover {
  background: #28a745;
  box-shadow: 0 4px 16px rgba(52, 199, 89, 0.45);
}

.btn-print:active {
  transform: scale(0.97);
}

.btn-print:disabled,
.btn-print.disabled {
  opacity: 0.45;
  cursor: not-allowed;
  filter: grayscale(0.6);
  box-shadow: none;
  transform: none !important;
  pointer-events: none;
}

.badge {
  background: rgba(0, 0, 0, 0.15);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  border-radius: 999px;
  padding: 1px 7px;
  transition: transform .2s;
}

/* ================= Toolbar Segmented Controls (High-Contrast Apple Style) ================= */

.view-size-wrap {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-tertiary);
  border: 1px solid var(--line);
  border-radius: var(--r-pill);
  padding: 4px 10px;
  flex: 0 0 auto;
}

.vsw-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-2);
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.vsw-label .tb-icon {
  color: var(--ink-3);
  display: block;
}

.global-lang-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-2);
  margin-right: 8px;
}

.gl-label {
  display: none;
}

@media (min-width: 900px) {
  .gl-label {
    display: inline;
  }
}

.s-select {
  font-size: 12px;
  font-weight: 600;
  padding: 4px 24px 4px 10px;
  border-radius: var(--r-pill);
  border: 1px solid var(--line);
  background-color: var(--surface-tertiary);
  color: var(--ink);
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' stroke='%23737373' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' viewBox='0 0 24 24'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  background-size: 12px;
  cursor: pointer;
  outline: none;
  transition: all 0.15s ease;
}

.s-select:hover {
  background-color: #fff;
  border-color: rgba(0, 0, 0, 0.15);
}

.vsw-select {
  font-size: 12.5px;
  font-weight: 600;
  padding: 6px 28px 6px 14px;
  border-radius: var(--r-pill);
  border: 1px solid var(--line);
  background-color: var(--surface-tertiary);
  color: var(--ink);
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' stroke='%23737373' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' viewBox='0 0 24 24'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 14px;
  cursor: pointer;
  outline: none;
  transition: all 0.15s ease;
}

.vsw-select:hover {
  background-color: #fff;
  border-color: rgba(0, 0, 0, 0.15);
}

.vsw-select.highlight-blue {
  background-color: var(--blue-soft);
  color: var(--blue);
  border-color: rgba(0, 113, 227, 0.25);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' stroke='%230071e3' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' viewBox='0 0 24 24'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
}

.batch-select-wrap {
  display: inline-flex;
  align-items: center;
  background: var(--surface-tertiary);
  border: 1px solid var(--line);
  border-radius: var(--r-pill);
  padding: 6px 14px;
  min-height: 38px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-2);
  white-space: nowrap;
}

.batch-cb-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
}

.batch-cb-label input {
  display: none;
}

.batch-cb-box {
  width: 16px;
  height: 16px;
  border-radius: 4px;
  border: 2px solid var(--line);
  position: relative;
  transition: all 0.2s;
  background: #fff;
}

.batch-cb-label input:checked+.batch-cb-box {
  background: var(--blue);
  border-color: var(--blue);
}

.batch-cb-label input:checked+.batch-cb-box::after {
  content: '';
  position: absolute;
  left: 4px;
  top: 1px;
  width: 4px;
  height: 8px;
  border: solid white;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.btn-guide {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface-tertiary);
  border: 1px solid var(--line);
  border-radius: var(--r-pill);
  padding: 6px 14px;
  min-height: 38px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-2);
  cursor: pointer;
  transition: all .15s ease;
  white-space: nowrap;
}

.btn-guide svg {
  color: var(--ink-3);
}

.btn-guide:hover {
  background: #ffffff;
  color: var(--blue);
  border-color: rgba(0, 113, 227, 0.3);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.06);
}

.btn-guide:hover svg {
  color: var(--blue);
}

/* ================= Label Gallery (Apple Clean Responsive Grid) ================= */

.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 540px), 1fr));
  gap: 24px;
  width: 100%;
  max-width: 1300px;
  margin: 0 auto;
  align-items: start;
  padding: 8px 0 24px;
  transition: all .2s ease;
}

/* Full Width View (Extra Large Single Column) */
.gallery.view-full {
  grid-template-columns: 1fr;
  max-width: 860px;
}

/* Compact Grid View */
.gallery.view-compact {
  grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
  max-width: 100%;
}

.label-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 16px 16px 18px;
  box-shadow: var(--shadow-sm);
  transition: transform .18s cubic-bezier(0.25, 0.1, 0.25, 1), box-shadow .18s cubic-bezier(0.25, 0.1, 0.25, 1);
  animation: cardIn .25s ease both;
  width: 100%;
  box-sizing: border-box;
}

.label-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

@keyframes cardIn {
  from {
    opacity: 0;
    transform: translateY(8px) scale(.98);
  }

  to {
    opacity: 1;
    transform: none;
  }
}

.card-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
}

.card-bar-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-select-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
  background: var(--surface-tertiary);
  border: 1px solid var(--line);
  border-radius: var(--r-pill);
  padding: 6px 14px;
  min-height: 34px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-2);
  transition: all .15s ease;
}

.card-select-toggle input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.card-cb-box {
  width: 16px;
  height: 16px;
  border-radius: 4px;
  border: 1.5px solid var(--ink-4);
  background: #ffffff;
  display: grid;
  place-items: center;
  transition: all .15s ease;
  flex: 0 0 16px;
  position: relative;
}

.card-select-toggle input:checked+.card-cb-box {
  background: var(--blue);
  border-color: var(--blue);
  box-shadow: 0 2px 6px rgba(0, 113, 227, 0.35);
}

.card-select-toggle input:checked+.card-cb-box::after {
  content: '';
  width: 4px;
  height: 8px;
  border: solid white;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg) translate(-0.5px, -0.5px);
}

.card-select-toggle:hover {
  background: var(--blue-soft);
  border-color: rgba(0, 113, 227, 0.25);
  color: var(--blue);
}

.card-select-toggle:hover .card-cb-box {
  border-color: var(--blue);
}

.label-card.selected {
  border-color: rgba(0, 113, 227, 0.35);
  box-shadow: 0 0 0 1.5px var(--blue), var(--shadow-sm);
}

/* segmented language switcher (Apple iOS Segmented Control) */
.seg {
  display: inline-flex;
  background: rgba(118, 118, 128, 0.12);
  border-radius: 9px;
  padding: 3px;
  gap: 2px;
}

.seg-btn {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-2);
  background: transparent;
  border: 0;
  border-radius: 7px;
  padding: 5px 12px;
  min-height: 28px;
  transition: all .15s ease;
  letter-spacing: -0.01em;
  cursor: pointer;
  white-space: nowrap;
}

.seg-btn:hover {
  color: var(--ink);
}

.seg-btn.active {
  background: #ffffff;
  color: var(--blue);
  font-weight: 700;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.06);
}

.card-bar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.icon-btn {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--surface-tertiary);
  color: var(--ink-2);
  transition: all .15s cubic-bezier(0.25, 0.1, 0.25, 1);
  cursor: pointer;
}

.icon-btn svg {
  width: 16px;
  height: 16px;
  display: block;
}

.icon-btn:hover {
  background: #ffffff;
  color: var(--blue);
  border-color: rgba(0, 113, 227, 0.3);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
  transform: translateY(-1px);
}

.icon-btn.danger:hover {
  background: var(--red-soft);
  color: var(--red);
  border-color: rgba(255, 59, 48, 0.3);
  box-shadow: 0 2px 6px rgba(255, 59, 48, 0.15);
}

.icon-btn:active {
  transform: scale(0.95);
}

.icon-btn:hover {
  background: var(--blue-soft);
  color: var(--blue);
}

.icon-btn.danger:hover {
  background: var(--red-soft);
  color: var(--red);
}

.icon-btn:active {
  transform: scale(0.92);
}

/* ================= Large & High-Readability Screen Label Canvas ================= */

.label-sheet {
  position: relative;
  width: 100%;
  max-width: 100%;
  aspect-ratio: 80 / 60;
  min-height: 360px;
  margin: 0 auto;
  padding: 12px 16px 10px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  background: #ffffff;
  border: 1.5px solid #cbd5e1;
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 10px 24px -6px rgba(15, 23, 42, .14);
  font-family: var(--font-label);
  color: #111827;
  box-sizing: border-box;
}

/* thermal paper feel subtle overlay */
.label-sheet::before {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(148, 163, 184, .04), transparent 26px);
}

/* --- header --- */
.ls-head {
  border-bottom: 1.5px solid #111827;
  padding-bottom: 3px;
  margin-bottom: 4px;
}

.ls-pharmacy {
  font-size: 14.5px;
  font-weight: 800;
  line-height: 1.2;
  letter-spacing: .1px;
  display: flex;
  align-items: baseline;
  gap: 6px;
  white-space: nowrap;
  overflow: hidden;
  color: #000000;
}

.ls-pharmacy .sub {
  font-size: 11px;
  font-weight: 600;
  color: #475569;
}

.ls-pharmacy-sub {
  font-size: 10px;
  color: #475569;
  margin-top: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* --- patient row --- */
.ls-patient {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 12px;
  padding-bottom: 3px;
  margin-bottom: 4px;
  border-bottom: 1.5px dotted #cbd5e1;
}

.ls-patient b {
  font-weight: 800;
  color: #000000;
  font-size: 12.5px;
}

/* --- drug section --- */
.ls-drug {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
  min-height: 42px;
}

.ls-drug-left {
  flex: 1;
  min-width: 0;
}

.ls-trade {
  font-size: 16.5px;
  font-weight: 800;
  line-height: 1.15;
  letter-spacing: .3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: #000000;
}

.ls-generic {
  font-size: 11px;
  font-weight: 600;
  color: #334155;
  margin-top: 1px;
  line-height: 1.2;
}

.ls-drug-right {
  flex: 0 0 145px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.ls-qty {
  display: flex;
  justify-content: space-between;
  width: 100%;
  font-size: 10.5px;
  line-height: 1.25;
}

.ls-qty .lab {
  color: #475569;
  font-weight: 600;
}

.ls-qty b {
  font-weight: 800;
  color: #000;
  font-variant-numeric: tabular-nums;
}

.ls-bc {
  margin-top: 2px;
  width: 100%;
  display: flex;
  justify-content: flex-end;
}

.ls-bc svg {
  display: block;
  width: 100%;
  max-width: 135px;
  height: 20px;
}

.ls-bc-digits {
  font-size: 9.5px;
  font-family: 'Courier New', Courier, monospace;
  font-weight: 700;
  letter-spacing: .5px;
  text-align: center;
  width: 100%;
  margin-top: 1px;
  font-variant-numeric: tabular-nums;
  color: #000000;
}

/* --- indication / dosage / warning --- */
.ls-ind {
  font-size: 11.5px;
  line-height: 1.28;
  margin-bottom: 4px;
  color: #1e293b;
  font-weight: 600;
}

.ls-lab {
  font-weight: 800;
  color: #000000;
}

.ls-dosage {
  font-size: 12px;
  font-weight: 600;
  line-height: 1.32;
  border: 1.5px solid #38bdf8;
  background: #f0f9ff;
  border-radius: 5px;
  padding: 4px 8px;
  margin-bottom: 4px;
  color: #0369a1;
}

.ls-dosage .ls-lab {
  color: #0369a1;
}

.ls-warn {
  font-size: 11px;
  font-weight: 600;
  line-height: 1.28;
  border: 1.5px solid #f87171;
  background: #fef2f2;
  border-radius: 5px;
  padding: 4px 8px;
  margin-bottom: 4px;
  color: #991b1b;
}

/* editable hover highlights */
.ls-editable {
  cursor: pointer;
  border-radius: 4px;
  transition: all .14s ease;
}

.ls-editable:hover {
  outline: 2px dashed var(--blue);
  outline-offset: 1px;
}

.ls-dosage.ls-editable:hover {
  background: #e0f2fe;
  border-color: #0284c7;
}

.ls-warn.ls-editable:hover {
  background: #fee2e2;
  border-color: #dc2626;
}

.ls-drug-right.ls-editable:hover {
  outline: 2px dashed var(--blue);
  outline-offset: 2px;
  border-radius: 4px;
}

.ls-drug-left.ls-editable:hover {
  outline: 2px dashed var(--blue);
  outline-offset: 2px;
  border-radius: 4px;
}

/* --- footer --- */
.ls-foot {
  margin-top: auto;
  border-top: 1.5px dotted #cbd5e1;
  padding-top: 4px;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 9.5px;
  font-weight: 600;
  color: #475569;
  white-space: nowrap;
  overflow: hidden;
}

.ls-foot b {
  color: #000000;
}

/* sub-language text on labels */
.ls-sheet .sub,
.label-sheet .sub {
  font-weight: 500;
}

/* ================= 8×5 cm (80×50 mm) standard label layout ================= */

.label-sheet.size-80x50 {
  aspect-ratio: 80 / 50;
  min-height: 290px;
  padding: 8px 14px 7px;
}

.label-sheet.size-80x50 .ls-head {
  padding-bottom: 2px;
  margin-bottom: 2px;
}

.label-sheet.size-80x50 .ls-pharmacy {
  font-size: 13.5px;
}

.label-sheet.size-80x50 .ls-patient {
  padding-bottom: 2px;
  margin-bottom: 2px;
  font-size: 11px;
}

.label-sheet.size-80x50 .ls-drug {
  min-height: 36px;
  margin-bottom: 2px;
}

.label-sheet.size-80x50 .ls-trade {
  font-size: 15px;
}

.label-sheet.size-80x50 .ls-generic {
  font-size: 10px;
}

.label-sheet.size-80x50 .ls-qty {
  font-size: 9.5px;
}

.label-sheet.size-80x50 .ls-bc svg {
  height: 16px;
}

.label-sheet.size-80x50 .ls-bc-digits {
  font-size: 8.5px;
}

.label-sheet.size-80x50 .ls-ind {
  font-size: 10.5px;
  margin-bottom: 2px;
  line-height: 1.2;
}

.label-sheet.size-80x50 .ls-dosage {
  font-size: 10.5px;
  padding: 3px 6px;
  margin-bottom: 2px;
  line-height: 1.22;
}

.label-sheet.size-80x50 .ls-warn {
  font-size: 9.5px;
  padding: 3px 6px;
  margin-bottom: 2px;
  line-height: 1.2;
}

.label-sheet.size-80x50 .ls-foot {
  font-size: 8.5px;
  padding-top: 2px;
}
}

.label-sheet.size-80x50 .ls-warn {
  font-size: 11.5px;
  padding: 4px 8px;
  line-height: 1.25;
}

.label-sheet.size-80x50 .ls-foot {
  font-size: 11px;
  padding-top: 3px;
}

/* ================= Empty state ================= */

.empty-state {
  grid-column: 1 / -1;
  border: 2px dashed #cbd5e1;
  border-radius: var(--r-lg);
  background: rgba(255, 255, 255, .7);
  padding: 56px 24px;
  text-align: center;
  color: var(--ink-3);
}

.empty-state .es-icon {
  font-size: 40px;
  margin-bottom: 10px;
}

.empty-state h3 {
  font-size: 17px;
  font-weight: 700;
  color: var(--ink-2);
  margin-bottom: 6px;
}

.empty-state p {
  font-size: 13.5px;
  margin-bottom: 18px;
}

.btn-ghost-blue {
  font-size: 13.5px;
  font-weight: 700;
  color: var(--blue);
  background: var(--blue-soft);
  border: 1px solid #bae6fd;
  border-radius: var(--r-sm);
  padding: 9px 16px;
  transition: background .12s, transform .12s;
}

.btn-ghost-blue:hover {
  background: #d3edfd;
  transform: translateY(-1px);
}

/* ================= Status bar ================= */

.status-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-2);
  background: var(--surface-secondary);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 10px 16px;
  flex-wrap: wrap;
  margin-top: auto;
}

.status-bar .shortcuts {
  white-space: nowrap;
  font-weight: 600;
  color: var(--ink);
}

/* ================= Popover editors ================= */

.popover {
  position: fixed;
  z-index: 100;
  width: 440px;
  max-width: calc(100vw - 24px);
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  animation: popIn .18s cubic-bezier(.16, 1, .3, 1);
  padding: 16px 18px 14px;
}

.pop-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 14px;
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 12px;
}

.pop-title .pop-emoji {
  margin-right: 6px;
}

.pop-close {
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: var(--surface-tertiary);
  color: var(--ink-3);
  font-size: 14px;
  cursor: pointer;
  transition: all .12s ease;
}

.pop-close:hover {
  background: var(--red-soft);
  color: var(--red);
}

.ed-field {
  margin-bottom: 9px;
}

.ed-field>label,
.ed-field-label {
  display: block;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--ink-2);
  margin-bottom: 5px;
}

.ed-row {
  display: flex;
  gap: 10px;
}

.ed-row .grow {
  flex: 1;
  min-width: 0;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-2);
  background: var(--surface-tertiary);
  border: 1px solid var(--line);
  border-radius: var(--r-pill);
  padding: 5px 11px;
  cursor: pointer;
  transition: all .12s ease;
}

.chip:hover {
  background: #ffffff;
  border-color: rgba(0, 0, 0, 0.18);
}

.chip.active {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
  box-shadow: 0 2px 8px rgba(0, 113, 227, 0.35);
}

.ed-input {
  width: 100%;
  font-size: 13.5px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--surface-tertiary);
  outline: none;
  transition: all .15s ease;
}

.ed-input:focus {
  background: #ffffff;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px var(--blue-ring);
}

.ed-textarea {
  min-height: 64px;
  resize: vertical;
  line-height: 1.45;
}

.ed-hint {
  font-size: 11px;
  color: var(--ink-3);
  margin: 6px 0 10px;
}

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

.btn {
  font-size: 13.5px;
  font-weight: 600;
  border-radius: var(--r-pill);
  padding: 8px 18px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all .15s cubic-bezier(0.25, 0.1, 0.25, 1);
}

.btn.primary {
  background: var(--blue);
  color: #fff;
  box-shadow: 0 2px 8px rgba(0, 113, 227, 0.3);
}

.btn.primary:hover {
  background: var(--blue-hover);
  box-shadow: 0 4px 12px rgba(0, 113, 227, 0.4);
}

.btn.primary:active {
  transform: scale(0.97);
}

.btn.ghost {
  background: var(--surface-tertiary);
  color: var(--ink-2);
  border-color: var(--line);
}

.btn.ghost:hover {
  background: #ffffff;
  border-color: rgba(0, 0, 0, 0.2);
}

.btn.ghost:active {
  transform: scale(0.97);
}

/* drug swap list */
.ed-list {
  margin-top: 8px;
  max-height: 216px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: #ffffff;
}

.ed-list .search-item {
  padding: 9px 14px;
}

.ed-list .search-item.sel {
  background: var(--blue-soft);
}

/* ================= Settings & Master Data Modal (Apple macOS Window Style) ================= */
.settings-overlay {
  position: fixed;
  inset: 0;
  z-index: 150;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadeIn .18s ease;
}

.settings-modal {
  position: relative;
  width: min(1220px, 95vw);
  max-width: 100%;
  height: 88vh;
  max-height: 860px;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg), 0 25px 50px -12px rgba(0, 0, 0, .25);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: popIn .2s cubic-bezier(.16, 1, .3, 1);
}

.settings-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 22px;
  background: rgba(255, 255, 255, 0.9);
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}

.settings-head-title {
  display: flex;
  align-items: center;
  gap: 12px;
}

.settings-head-title .icon {
  font-size: 22px;
}

.settings-head-title h2 {
  font-size: 16px;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: -0.015em;
}

.settings-head-title p {
  font-size: 12px;
  color: var(--ink-3);
}

.settings-close {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  background: var(--surface-tertiary);
  color: var(--ink-3);
  font-size: 14px;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: all .15s ease;
}

.settings-close:hover {
  background: var(--red-soft);
  color: var(--red);
}

.settings-close:active {
  transform: scale(0.92);
}

.settings-nav {
  display: flex;
  gap: 4px;
  padding: 8px 18px 0;
  background: var(--surface-secondary);
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
  flex: 0 0 auto;
}

.s-nav-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-3);
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  white-space: nowrap;
  transition: all .15s ease;
}

.s-nav-btn:hover {
  color: var(--ink);
}

.s-nav-btn.active {
  color: var(--blue);
  border-bottom-color: var(--blue);
  background: rgba(0, 113, 227, 0.04);
}

.settings-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
  background: #ffffff;
}

.s-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.s-search {
  position: relative;
  flex: 1;
  max-width: 420px;
}

.s-btn-add {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  border-radius: 8px;
  background: var(--blue);
  color: white;
  border: none;
  cursor: pointer;
  transition: background .15s ease, transform .1s ease;
  white-space: nowrap;
}

.s-btn-add:hover {
  background: var(--blue-deep);
  transform: translateY(-1px);
}

.s-btn-add:active {
  transform: scale(0.97);
}

.s-search input {
  width: 100%;
  padding: 8px 12px 8px 34px;
  font-size: 13px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: #f8fafc;
  outline: none;
}

.s-search input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px var(--blue-ring);
  background: #fff;
}

.s-search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 15px;
  height: 15px;
  color: var(--ink-4);
  pointer-events: none;
}

/* Table styling */
.s-table-wrap {
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  overflow-x: auto;
  box-shadow: var(--shadow-sm);
  background: #fff;
}

.s-table {
  width: 100%;
  min-width: 860px;
  border-collapse: collapse;
  font-size: 12.5px;
  text-align: left;
}

.s-table th {
  background: #f8fafc;
  padding: 11px 16px;
  font-weight: 700;
  color: var(--ink-2);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

.s-table td {
  padding: 12px 16px;
  border-bottom: 1px solid #f1f5f9;
  color: var(--ink);
  vertical-align: middle;
}

.s-table th:last-child,
.s-table td:last-child {
  text-align: right;
  width: 140px;
  min-width: 140px;
  padding-right: 18px;
}

.s-table tr:last-child td {
  border-bottom: none;
}

.s-table tr:hover td {
  background: #f8fafc;
}

.s-table code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 11px;
  background: #f1f5f9;
  color: #334155;
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid #e2e8f0;
  letter-spacing: 0.3px;
  display: inline-block;
}

.s-table .t-actions {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  justify-content: flex-end;
  white-space: nowrap;
}

.s-act-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 9px;
  font-size: 12px;
  font-weight: 600;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink-2);
  cursor: pointer;
  transition: all .15s ease;
}

.s-act-btn svg {
  flex-shrink: 0;
}

.s-act-btn:hover {
  background: var(--blue-soft);
  color: var(--blue);
  border-color: #bae6fd;
}

.s-act-btn.danger:hover {
  background: var(--red-soft);
  color: var(--red);
  border-color: #fecaca;
}

.s-btn-add {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  border-radius: 8px;
  background: var(--blue);
  color: white;
  border: none;
  cursor: pointer;
  transition: background .15s ease, transform .1s ease;
  white-space: nowrap;
}

.s-btn-add:hover {
  background: var(--blue-deep);
}

.s-btn-add:active {
  transform: scale(0.98);
}

.s-btn-add svg {
  flex-shrink: 0;
}

.s-tag {
  display: inline-block;
  padding: 2px 7px;
  font-size: 11px;
  font-weight: 600;
  border-radius: 999px;
  background: #f1f5f9;
  color: var(--ink-2);
  border: 1px solid var(--line);
}

.s-tag.blue {
  background: var(--blue-soft);
  color: var(--blue-deep);
  border-color: #bae6fd;
}

.s-tag.red {
  background: var(--red-soft);
  color: #991b1b;
  border-color: #fecaca;
}

/* Sub editor dialog inside settings */
.s-submodal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .7);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 300;
  animation: fadeIn .15s ease;
}

.s-submodal {
  width: 720px;
  max-width: 100%;
  max-height: 85vh;
  background: #fff;
  border-radius: var(--r-md);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.s-submodal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px 18px;
  background: #f8fafc;
  border-bottom: 1px solid var(--line);
}

.s-submodal-head h3 {
  font-size: 14.5px;
  font-weight: 800;
}

.s-submodal-body {
  padding: 16px 20px;
  overflow-y: auto;
  flex: 1;
}

.s-submodal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 18px;
  background: #f8fafc;
  border-top: 1px solid var(--line);
}

.s-form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.s-form-grid .full {
  grid-column: 1 / -1;
}

.s-form-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.s-form-group label {
  font-size: 11.5px;
  font-weight: 700;
  color: var(--ink-2);
}

.s-form-group label small {
  font-weight: 500;
  color: var(--ink-4);
}

.s-input {
  width: 100%;
  padding: 8px 11px;
  font-size: 13px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: #f8fafc;
  outline: none;
  transition: all .12s;
}

.s-input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px var(--blue-ring);
  background: #fff;
}

.s-textarea {
  min-height: 58px;
  resize: vertical;
  line-height: 1.4;
}

/* Lang input group */
.s-lang-group {
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: 12px;
  background: #fafbfc;
  margin-bottom: 12px;
}

.s-lang-title {
  font-size: 12px;
  font-weight: 800;
  color: var(--ink-2);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.s-card-section {
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 16px;
  background: #ffffff;
  margin-bottom: 14px;
}

.s-card-title {
  font-size: 13.5px;
  font-weight: 800;
  color: var(--ink);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* Backup card */
.backup-box {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.backup-card {
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 18px;
  background: #f8fafc;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.backup-card h4 {
  font-size: 14px;
  font-weight: 800;
}

.backup-card p {
  font-size: 12px;
  color: var(--ink-3);
  line-height: 1.45;
  flex: 1;
}

/* ================= Toasts ================= */

#toastRoot {
  position: fixed;
  bottom: 22px;
  right: 22px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #0f172a;
  color: #f8fafc;
  font-size: 13px;
  font-weight: 600;
  padding: 11px 15px;
  border-radius: 12px;
  box-shadow: 0 12px 30px -8px rgba(15, 23, 42, .5);
  animation: toastIn .2s ease;
  max-width: 340px;
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: none;
  }
}

.toast .t-undo {
  margin-left: 4px;
  font-weight: 800;
  color: #7dd3fc;
  background: none;
  border: 0;
  font-size: 12.5px;
  padding: 2px 6px;
  border-radius: 6px;
}

.toast .t-undo:hover {
  background: rgba(255, 255, 255, .12);
}

.toast.out {
  animation: toastOut .2s ease forwards;
}

@keyframes toastOut {
  to {
    opacity: 0;
    transform: translateY(8px);
  }
}

/* ================= Print-only staging ================= */

.print-area {
  display: none;
}

/* ================= Print fidelity: thermal roll (80×60 or 60×80) =================
   NOTE: @page size is injected by JS (applyPageSize) as a single rule so browsers
   don't drop it — Safari ignores @page with custom-property values. */

@media print {

  *,
  *::before,
  *::after {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
    box-sizing: border-box !important;
  }

  html,
  body {
    margin: 0 !important;
    padding: 0 !important;
    background: #fff !important;
  }

  body>.app {
    display: none !important;
  }

  #popoverRoot,
  #settingsRoot,
  #toastRoot,
  .guide-overlay,
  .settings-overlay,
  .s-submodal-overlay {
    display: none !important;
  }

  .print-area {
    display: block !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  .print-area .label-sheet {
    width: 78mm !important;
    max-width: 78mm !important;
    height: 58mm !important;
    max-height: 58mm !important;
    min-height: unset !important;
    aspect-ratio: unset !important;
    margin: 0 auto !important;
    padding: 2pt 4pt 1.8pt !important;
    border: none !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    overflow: hidden !important;
    page-break-before: auto !important;
    break-before: auto !important;
    page-break-inside: avoid !important;
    break-inside: avoid !important;
    page-break-after: always !important;
    break-after: page !important;
    font-size: 6.2pt !important;
    display: flex !important;
    flex-direction: column !important;
    justify-content: space-between !important;
    background: #ffffff !important;
    box-sizing: border-box !important;
  }

  .print-area .ls-head {
    padding-bottom: 0.8pt !important;
    margin-bottom: 0.8pt !important;
    border-bottom: 1pt solid #000 !important;
  }

  .print-area .ls-pharmacy {
    font-size: 8.4pt !important;
    gap: 3pt !important;
    font-weight: 800 !important;
  }

  .print-area .ls-pharmacy .sub {
    font-size: 5.4pt !important;
    color: #333 !important;
  }

  .print-area .ls-pharmacy-sub {
    font-size: 4.8pt !important;
    margin-top: 0.3pt !important;
    color: #444 !important;
  }

  .print-area .ls-patient {
    font-size: 5.6pt !important;
    padding-bottom: 0.8pt !important;
    margin-bottom: 0.8pt !important;
    border-bottom: 0.8pt dotted #888 !important;
  }

  .print-area .ls-patient b {
    font-size: 5.8pt !important;
  }

  .print-area .ls-drug {
    gap: 3pt !important;
    margin-bottom: 0.8pt !important;
    min-height: 20pt !important;
  }

  .print-area .ls-trade {
    font-size: 9.2pt !important;
    font-weight: 800 !important;
  }

  .print-area .ls-generic {
    font-size: 5.4pt !important;
    margin-top: 0.3pt !important;
    color: #222 !important;
  }

  .print-area .ls-drug-right {
    flex: 0 0 74pt !important;
  }

  .print-area .ls-qty {
    font-size: 5.2pt !important;
  }

  .print-area .ls-bc {
    margin-top: 0.5pt !important;
  }

  .print-area .ls-bc svg {
    height: 9pt !important;
    width: 100% !important;
  }

  .print-area .ls-bc-digits {
    font-size: 4.6pt !important;
    margin-top: 0.3pt !important;
    font-family: monospace !important;
  }

  .print-area .ls-ind {
    font-size: 5.5pt !important;
    margin-bottom: 0.8pt !important;
    line-height: 1.15 !important;
  }

  .print-area .ls-dosage {
    font-size: 5.6pt !important;
    padding: 1pt 3pt !important;
    margin-bottom: 0.8pt !important;
    border-radius: 2pt !important;
    border: 0.8pt solid #0284c7 !important;
    background: #f0f9ff !important;
    color: #000 !important;
    line-height: 1.18 !important;
  }

  .print-area .ls-warn {
    font-size: 5.2pt !important;
    padding: 1pt 3pt !important;
    margin-bottom: 0.8pt !important;
    border-radius: 2pt !important;
    border: 0.8pt solid #dc2626 !important;
    background: #fef2f2 !important;
    color: #991b1b !important;
    line-height: 1.15 !important;
  }

  .print-area .ls-foot {
    font-size: 4.8pt !important;
    padding-top: 0.8pt !important;
    border-top: 0.8pt dotted #888 !important;
  }

  /* 80×50 mm (8×5 cm) print layout */
  .print-area .label-sheet.size-80x50 {
    width: 78mm !important;
    max-width: 78mm !important;
    height: 48mm !important;
    max-height: 48mm !important;
    padding: 1.4pt 3.5pt 1.2pt !important;
  }

  .print-area .label-sheet.size-80x50 .ls-head {
    padding-bottom: 0.6pt !important;
    margin-bottom: 0.6pt !important;
  }

  .print-area .label-sheet.size-80x50 .ls-pharmacy {
    font-size: 7.8pt !important;
  }

  .print-area .label-sheet.size-80x50 .ls-pharmacy .sub {
    font-size: 5pt !important;
  }

  .print-area .label-sheet.size-80x50 .ls-pharmacy-sub {
    font-size: 4.4pt !important;
  }

  .print-area .label-sheet.size-80x50 .ls-patient {
    font-size: 5.2pt !important;
    padding-bottom: 0.6pt !important;
    margin-bottom: 0.6pt !important;
  }

  .print-area .label-sheet.size-80x50 .ls-patient b {
    font-size: 5.4pt !important;
  }

  .print-area .label-sheet.size-80x50 .ls-drug {
    gap: 2pt !important;
    margin-bottom: 0.6pt !important;
    min-height: 17pt !important;
  }

  .print-area .label-sheet.size-80x50 .ls-trade {
    font-size: 8.4pt !important;
  }

  .print-area .label-sheet.size-80x50 .ls-generic {
    font-size: 4.8pt !important;
  }

  .print-area .label-sheet.size-80x50 .ls-drug-right {
    flex: 0 0 68pt !important;
  }

  .print-area .label-sheet.size-80x50 .ls-qty {
    font-size: 4.8pt !important;
  }

  .print-area .label-sheet.size-80x50 .ls-bc svg {
    height: 8pt !important;
  }

  .print-area .label-sheet.size-80x50 .ls-bc-digits {
    font-size: 4.2pt !important;
  }

  .print-area .label-sheet.size-80x50 .ls-ind {
    font-size: 5pt !important;
    margin-bottom: 0.6pt !important;
    line-height: 1.1 !important;
  }

  .print-area .label-sheet.size-80x50 .ls-dosage {
    font-size: 5.2pt !important;
    padding: 0.8pt 2.5pt !important;
    margin-bottom: 0.6pt !important;
    line-height: 1.12 !important;
  }

  .print-area .label-sheet.size-80x50 .ls-warn {
    font-size: 4.8pt !important;
    padding: 0.8pt 2.5pt !important;
    margin-bottom: 0.6pt !important;
    line-height: 1.1 !important;
  }

  .print-area .label-sheet.size-80x50 .ls-foot {
    font-size: 4.4pt !important;
    padding-top: 0.6pt !important;
  }

  .print-area .label-sheet:last-child {
    page-break-after: avoid !important;
    break-after: avoid !important;
  }

  .print-area .ls-editable {
    outline: none !important;
    cursor: default !important;
  }
}

/* ================= Responsive ================= */

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

  .strip-grid .grow2 {
    grid-column: span 2;
  }
}

@media (max-width: 640px) {
  .workspace {
    padding: 14px;
  }

  .gallery {
    grid-template-columns: 1fr;
    justify-content: center;
  }

  .label-sheet {
    margin: 0 auto;
  }

  .app-bar-inner {
    padding: 10px 14px;
  }

  .brand-text h1 {
    font-size: 15px;
  }

  .status-bar {
    justify-content: center;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
  }
}