.vial-calc-back-btn:focus-visible,
.vial-calc-disclosure-toggle:focus-visible,
.vial-calc-cta-btn:focus-visible,
.vial-calc-syringe-btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--field-ring);
}

.vial-calc-overlay {
  position: fixed;
  inset: 0;
  z-index: 1001;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.vial-calc-overlay[hidden] {
  display: none;
}

.vial-calc-backdrop {
  position: absolute;
  inset: 0;
  background: var(--modal-backdrop);
}

.vial-calc-panel {
  position: relative;
  width: 100%;
  max-height: 90vh;
  max-height: 90dvh;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  background: var(--surface);
  box-shadow: var(--modal-shadow-premium);
  display: flex;
  flex-direction: column;
  transform: translateY(100%);
  transition: transform 300ms cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.vial-calc-panel--open {
  transform: translateY(0);
}

.vial-calc-handle {
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.15);
  margin: 12px auto 0;
}

.vial-calc-panel-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 16px 24px 0;
}

.vial-calc-panel-title {
  flex: 1;
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text);
}

.vial-calc-back-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0;
  transition: color 150ms ease, background 150ms ease;
}

.vial-calc-back-btn:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.vial-calc-step-dots {
  display: flex;
  justify-content: center;
  gap: 8px;
  padding-top: 16px;
}

.vial-calc-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--border);
  transition: background 200ms ease;
}

.vial-calc-dot--active {
  background: var(--primary);
}

.vial-calc-body {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 0;
}

.vial-calc-steps-wrapper {
  display: block;
}

.vial-calc-step {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.vial-calc-section {
  display: flex;
  flex-direction: column;
}

.vial-calc-label {
  margin-bottom: 8px;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-muted);
}

.vial-calc-helper-text {
  margin-top: 8px;
  font-size: 0.75rem;
  line-height: 1.5;
  color: var(--text-muted);
}

.vial-calc-compound-select-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--field-border);
  border-radius: var(--radius-sm);
  background: var(--field-surface);
  padding: 12px 14px;
  cursor: pointer;
  transition: border-color 200ms ease, box-shadow 200ms ease;
}

.vial-calc-compound-select-wrapper:hover {
  border-color: var(--field-border-strong);
}

.vial-calc-compound-select-wrapper:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--field-ring);
}

.vial-calc-compound-display {
  flex: 1;
  font-size: 0.9375rem;
  color: var(--text);
  pointer-events: none;
}

.vial-calc-compound-display.is-placeholder {
  color: var(--text-muted);
}

.vial-calc-select-chevron {
  flex-shrink: 0;
  color: var(--text-muted);
  pointer-events: none;
}

.vial-calc-compound-select-wrapper select {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
  color: #111827;
  color-scheme: dark;
}

.vial-calc-input-row,
.vial-calc-slider-row,
.vial-calc-syringe-custom {
  display: flex;
  align-items: center;
  gap: 8px;
}

.vial-calc-slider-row {
  align-items: flex-start;
  gap: 8px;
}

.vial-calc-field,
.vial-calc-unit-select {
  width: 100%;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--field-border);
  background: var(--field-surface);
  color: var(--text);
  font-size: 0.9375rem;
  font-weight: 400;
  outline: none;
  transition: border-color 200ms ease, box-shadow 200ms ease, background 150ms ease, opacity 150ms ease;
}

.vial-calc-field:hover,
.vial-calc-unit-select:hover {
  border-color: var(--field-border-strong);
}

.vial-calc-field:focus,
.vial-calc-unit-select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--field-ring);
}

.vial-calc-field:disabled,
.vial-calc-unit-select:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.vial-calc-field::placeholder {
  color: var(--text-muted);
  opacity: 0.5;
}

.vial-calc-field--narrow {
  width: 96px;
  text-align: center;
}

#vial-calc-vial-amount::-webkit-inner-spin-button,
#vial-calc-vial-amount::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

#vial-calc-vial-amount[type=number] {
  -moz-appearance: textfield;
}

.vial-calc-stepper-btn {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--primary);
  background: var(--primary-dim);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  transition: background 150ms ease, transform 150ms ease;
}

.vial-calc-stepper-btn:hover {
  background: rgba(139, 92, 246, 0.20);
}

.vial-calc-stepper-btn:active {
  transform: scale(0.93);
}

.vial-calc-stepper-btn:disabled {
  opacity: 0.4;
  pointer-events: none;
}

.vial-calc-stepper-btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--field-ring);
}

.vial-calc-unit-select {
  width: auto;
  min-width: 72px;
  color-scheme: dark;
}

.vial-calc-compound-select-wrapper option,
.vial-calc-unit-select option {
  color: #111827;
  background: #ffffff;
}

.vial-calc-unit-label {
  font-size: 0.8125rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.vial-calc-bac-recommended {
  border-left: 3px solid var(--success) !important;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.vial-calc-bac-control {
  flex: 1;
  min-width: 0;
}

.vial-calc-bac-slider-wrap {
  position: relative;
  display: flex;
  align-items: center;
  width: 100%;
}

.vial-calc-bac-slider-wrap .vial-calc-slider {
  width: 100%;
  flex: none;
}

.vial-calc-bac-input-wrap {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 6px;
}

.vial-calc-bac-input {
  width: 78px;
  flex: 0 0 78px;
  padding-left: 10px;
  padding-right: 10px;
  text-align: center;
}

.vial-calc-bac-input-unit {
  min-width: 24px;
}

.vial-calc-slider {
  --slider-fill: 15%;
  flex: 1;
  position: relative;
  z-index: 2;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  border-radius: 999px;
  outline: none;
  background: linear-gradient(
    90deg,
    var(--primary) 0%,
    var(--primary) var(--slider-fill),
    var(--border) var(--slider-fill),
    var(--border) 100%
  );
}

.vial-calc-slider::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 999px;
  background: transparent;
}

.vial-calc-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid var(--primary);
  background: var(--primary);
  cursor: pointer;
  margin-top: -7px;
  transition: transform 150ms ease, box-shadow 150ms ease;
}

.vial-calc-slider:active::-webkit-slider-thumb {
  transform: scale(1.22);
  box-shadow: 0 0 0 4px rgba(139, 92, 246, 0.2);
}

.vial-calc-slider::-moz-range-track {
  height: 4px;
  border-radius: 999px;
  background: transparent;
}

.vial-calc-slider::-moz-range-progress {
  height: 4px;
  border-radius: 999px;
  background: var(--primary);
}

.vial-calc-slider::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid var(--primary);
  background: var(--primary);
  cursor: pointer;
  transition: transform 150ms ease, box-shadow 150ms ease;
}

.vial-calc-slider:active::-moz-range-thumb {
  transform: scale(1.22);
  box-shadow: 0 0 0 4px rgba(139, 92, 246, 0.2);
}

.vial-calc-bac-rec-marker {
  position: absolute;
  width: 2px;
  height: 10px;
  background: var(--success);
  border-radius: 1px;
  top: 50%;
  transform: translateY(-50%);
  opacity: 0.5;
  transition: opacity 150ms ease;
  z-index: 1;
  pointer-events: none !important;
  user-select: none;
  -webkit-user-drag: none;
}

.vial-calc-bac-rec-label {
  position: absolute;
  font-size: 0.5625rem;
  font-weight: 400;
  color: var(--success);
  bottom: calc(50% + 7px);
  transform: translateX(-50%);
  white-space: nowrap;
  opacity: 0.5;
  transition: opacity 150ms ease;
  z-index: 3;
  pointer-events: none !important;
  user-select: none;
  -webkit-user-drag: none;
}

.vial-calc-bac-ticks {
  display: flex;
  justify-content: space-between;
  min-height: 30px;
  padding: 8px 9px 10px;
}

.vial-calc-tick {
  position: relative;
  background: var(--border);
  border-radius: 1px;
  opacity: 0.55;
  transition: background 150ms ease, opacity 150ms ease, transform 150ms ease;
}

.vial-calc-tick--minor {
  width: 3px;
  height: 8px;
}

.vial-calc-tick--major {
  width: 3px;
  height: 12px;
}

.vial-calc-tick::after {
  content: attr(data-unit-label);
  position: absolute;
  top: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.625rem;
  color: var(--primary-glow);
  white-space: nowrap;
  opacity: 0;
  transition: opacity 150ms ease;
}

.vial-calc-tick.is-active {
  background: rgba(139, 92, 246, 0.45);
  opacity: 1;
}

.vial-calc-tick.is-current {
  background: var(--primary);
  transform: scaleY(1.1);
}

.vial-calc-tick.is-current::after {
  opacity: 1;
}

.vial-calc-tick.is-edge-start::after {
  left: 0;
  transform: translateX(0);
}

.vial-calc-tick.is-edge-end::after {
  left: 100%;
  transform: translateX(-100%);
}

.vial-calc-syringe-group {
  display: flex;
  gap: 8px;
}

.vial-calc-syringe-btn {
  flex: 1;
  min-height: 36px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-hover);
  color: var(--text-muted);
  padding: 8px 16px;
  font-size: 0.8125rem;
  font-weight: 500;
  text-align: center;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  transition: transform 150ms ease, opacity 150ms ease, background 150ms ease, border-color 150ms ease, color 150ms ease;
}

.vial-calc-syringe-btn.selected {
  background: var(--primary-dim);
  border-color: var(--primary);
  color: var(--text);
}

.vial-calc-syringe-btn:active {
  opacity: 0.85;
  transform: scale(0.97);
}

.vial-calc-live-readout {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 18px;
  margin-top: 8px;
  padding-right: 4px;
}

.vial-calc-live-metrics-right {
  display: flex;
  justify-content: flex-end;
  gap: 18px;
  margin-left: auto;
}

.vial-calc-live-metric {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  min-width: 54px;
}

.vial-calc-live-metric--target {
  align-items: flex-start;
  min-width: 118px;
}

.vial-calc-live-value {
  font-size: 1.875rem;
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  color: var(--primary);
}

.vial-calc-live-unit-label {
  margin-top: 2px;
  font-size: 0.6875rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.vial-calc-live-unit-label--sentence {
  letter-spacing: 0;
  text-transform: none;
}

.vial-calc-result {
  border-left: 3px solid var(--accent);
  border-top: 1px solid var(--border);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  background: var(--surface);
  padding: 20px 24px;
  margin-top: 16px;
  transition: opacity 150ms ease;
}

.vial-calc-result-number {
  font-size: 2rem;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  transition: opacity 75ms ease;
}

.vial-calc-result-label {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-top: 4px;
}

.vial-calc-result-secondary {
  font-size: 0.875rem;
  font-weight: 400;
  color: var(--text-muted);
  margin-top: 4px;
}

.vial-calc-result-tertiary {
  font-size: 0.8125rem;
  font-weight: 400;
  color: var(--text-muted);
  margin-top: 4px;
}

.vial-calc-result-number--updating {
  opacity: 0.5;
}

.vial-calc-disclosure-toggle {
  display: block;
  border: none;
  background: none;
  padding: 0;
  margin-top: 8px;
  font-size: 0.8125rem;
  color: var(--text-muted);
  cursor: pointer;
}

.vial-calc-disclosure-toggle:hover {
  color: var(--text);
}

.vial-calc-disclosure {
  margin-top: 8px;
}

.vial-calc-sticky-cta {
  flex-shrink: 0;
  padding: 16px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom));
}

.vial-calc-cta-btn {
  width: 100%;
  height: 48px;
  border-radius: var(--radius-md);
  border: none;
  font-size: 0.9375rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 200ms ease, background 200ms ease, color 200ms ease, border-color 200ms ease;
}

.vial-calc-cta-btn--primary {
  background: var(--primary);
  color: var(--text);
}

.vial-calc-cta-btn--primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.vial-calc-cta-btn--primary:disabled {
  opacity: 0.4;
  cursor: default;
}

.vial-calc-cta-btn--secondary {
  background: var(--field-surface);
  border: 1px solid var(--field-border-strong);
  color: var(--primary);
}

.vial-calc-cta-btn--secondary:hover:not(:disabled) {
  background: var(--surface-hover);
}

.vial-calc-cta-btn--secondary:disabled {
  opacity: 0.45;
  cursor: default;
}

@keyframes vial-calc-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

.vial-calc-field--invalid {
  border-color: var(--danger) !important;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%23EF4444' stroke-width='2.5' stroke-linecap='round'%3E%3Cpath d='M18 6 6 18'/%3E%3Cpath d='M6 6l12 12'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 14px 14px;
  padding-right: 38px;
  animation: vial-calc-shake 200ms ease;
}

.vial-calc-inline {
  width: 100%;
}

.vial-calc-inline-card {
  width: 100%;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.vial-calc-inline-card .vial-calc-panel-header {
  padding-top: 24px;
}

.vial-calc-inline-card .vial-calc-sticky-cta {
  padding: 24px;
}

@media (min-width: 640px) {
  .vial-calc-overlay {
    align-items: center;
  }

  .vial-calc-panel {
    max-width: 480px;
    max-height: 85vh;
    border-radius: var(--radius-lg);
    align-self: center;
  }

  .vial-calc-handle {
    display: none;
  }
}
