/* ──────────────────────────────────────────────
   UK Drug Details — main.css
   Design tokens match hub.medmanagement.co.uk
   ────────────────────────────────────────────── */

/* ── Reset & base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary:      #0f4c75;
  --primary-dark: #0a3558;
  --primary-light:#e8f0f8;
  --amber:        #d97706;
  --amber-light:  #fef3c7;
  --red:          #dc2626;
  --red-light:    #fef2f2;
  --green:        #16a34a;
  --green-light:  #f0fdf4;
  --blue:         #2563eb;
  --blue-light:   #eff6ff;

  --grey-50:  #f8fafc;
  --grey-100: #f1f5f9;
  --grey-200: #e2e8f0;
  --grey-300: #cbd5e1;
  --grey-400: #94a3b8;
  --grey-500: #64748b;
  --grey-600: #475569;
  --grey-700: #334155;
  --grey-800: #1e293b;

  --font: 'Inter', system-ui, -apple-system, sans-serif;
  --radius: 8px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --shadow:    0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.05);
}

body {
  font-family: var(--font);
  font-size: 14px;
  color: var(--grey-800);
  background: var(--grey-50);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Layout ── */
.app-nav {
  background: var(--primary);
  padding: 0 24px;
  display: flex;
  align-items: center;
  height: 52px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}

.nav-brand {
  font-size: 15px;
  font-weight: 700;
  color: #fff;
  letter-spacing: -.01em;
  margin-right: 32px;
  white-space: nowrap;
}

.nav-links {
  display: flex;
  gap: 4px;
  flex: 1;
}

.nav-link {
  color: rgba(255,255,255,.8);
  padding: 6px 12px;
  border-radius: 5px;
  font-size: 13px;
  font-weight: 500;
  transition: background .15s, color .15s;
}
.nav-link:hover { background: rgba(255,255,255,.12); color: #fff; text-decoration: none; }
.nav-link--active { background: rgba(255,255,255,.18); color: #fff; }

.nav-user {
  color: rgba(255,255,255,.7);
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.nav-user a { color: rgba(255,255,255,.7); font-size: 12px; }
.nav-user a:hover { color: #fff; text-decoration: none; }

.main-content {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 24px 48px;
}

/* ── Page header ── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.page-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--grey-800);
  letter-spacing: -.02em;
  line-height: 1.2;
}

.page-subtitle {
  font-size: 13px;
  color: var(--grey-500);
  margin-top: 3px;
}

.breadcrumb {
  font-size: 12px;
  color: var(--grey-500);
  display: inline-block;
  margin-bottom: 4px;
}
.breadcrumb:hover { color: var(--primary); text-decoration: none; }

.section-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--grey-400);
}

/* ── Cards ── */
.card {
  background: #fff;
  border: 1px solid var(--grey-200);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.card-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--grey-100);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.card-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--grey-700);
}

.card-body {
  padding: 16px;
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background .15s, border-color .15s, opacity .15s;
  white-space: nowrap;
  text-decoration: none;
  line-height: 1;
}
.btn:hover { text-decoration: none; opacity: .9; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn--primary   { background: var(--primary); color: #fff; }
.btn--primary:hover { background: var(--primary-dark); }
.btn--secondary { background: #fff; color: var(--grey-700); border-color: var(--grey-200); }
.btn--secondary:hover { background: var(--grey-50); }
.btn--amber     { background: var(--amber); color: #fff; }
.btn--amber:hover { background: #b45309; }
.btn--full      { width: 100%; }

/* ── Alerts ── */
.alert {
  padding: 10px 14px;
  border-radius: 6px;
  font-size: 13px;
  border: 1px solid transparent;
}
.alert--error   { background: var(--red-light);   color: #991b1b; border-color: #fecaca; }
.alert--success { background: var(--green-light);  color: #166534; border-color: #bbf7d0; }
.alert--warn    { background: var(--amber-light);  color: #92400e; border-color: #fde68a; }

/* ── Badges ── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .02em;
  white-space: nowrap;
}
.badge--green  { background: var(--green-light);  color: #166534; }
.badge--amber  { background: var(--amber-light);  color: #92400e; }
.badge--blue   { background: var(--blue-light);   color: #1e40af; }
.badge--grey   { background: var(--grey-100);     color: var(--grey-600); }
.badge--red    { background: var(--red-light);    color: #991b1b; }

/* ── Forms ── */
.form-group    { margin-bottom: 14px; }
.form-label    {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--grey-600);
  text-transform: uppercase;
  letter-spacing: .04em;
  margin-bottom: 5px;
}
.form-input, .form-select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--grey-200);
  border-radius: 6px;
  font-size: 13px;
  font-family: var(--font);
  color: var(--grey-800);
  background: #fff;
  transition: border-color .15s, box-shadow .15s;
  outline: none;
}
.form-input:focus, .form-select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(15,76,117,.12);
}
textarea.form-input { resize: vertical; min-height: 60px; }
.form-hint { font-size: 11px; color: var(--grey-400); margin-top: 4px; }

.form-row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
.form-row-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 14px;
}

@media (max-width: 480px) {
  .form-row-2, .form-row-3 { grid-template-columns: 1fr; }
}

/* ── Tables ── */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
th {
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--grey-400);
  padding: 10px 12px;
  border-bottom: 1px solid var(--grey-100);
}
td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--grey-50);
  vertical-align: middle;
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--grey-50); }

/* ── Login page ── */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; }

.login-container { width: 100%; max-width: 380px; padding: 24px; }

.login-card {
  background: #fff;
  border: 1px solid var(--grey-200);
  border-radius: 12px;
  padding: 32px 28px;
  box-shadow: var(--shadow);
}

.login-header { text-align: center; margin-bottom: 24px; }
.login-logo   { font-size: 36px; margin-bottom: 10px; }
.login-title  { font-size: 20px; font-weight: 700; color: var(--grey-800); }
.login-subtitle { font-size: 12px; color: var(--grey-400); margin-top: 4px; }
.login-form .form-group:last-of-type { margin-bottom: 20px; }

/* ── Search page ── */
.search-wrap {
  display: flex;
  gap: 8px;
  margin-bottom: 6px;
  align-items: stretch;
}
.search-input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid var(--grey-200);
  border-radius: 6px;
  font-size: 14px;
  font-family: var(--font);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.search-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(15,76,117,.12);
}
.search-scan-btn, .search-go-btn {
  padding: 10px 16px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid var(--grey-200);
  white-space: nowrap;
}
.search-scan-btn { background: #fff; color: var(--grey-700); }
.search-scan-btn:hover { background: var(--grey-50); text-decoration: none; }
.search-go-btn { background: var(--primary); color: #fff; border-color: var(--primary); }
.search-go-btn:hover { background: var(--primary-dark); }

.search-hint { font-size: 12px; color: var(--grey-400); }

.results-list { display: flex; flex-direction: column; gap: 6px; }

.result-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #fff;
  border: 1px solid var(--grey-200);
  border-radius: var(--radius);
  padding: 12px 16px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow .15s, border-color .15s;
  color: var(--grey-800);
}
.result-card:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow);
  text-decoration: none;
}
.result-name { font-weight: 600; font-size: 14px; }
.result-meta { font-size: 12px; color: var(--grey-400); margin-top: 2px; }
.result-arrow { font-size: 20px; color: var(--grey-300); }

.empty-state { text-align: center; padding: 48px 20px; }
.empty-state__icon { font-size: 36px; margin-bottom: 10px; }
.empty-state__text { color: var(--grey-500); font-size: 14px; }

/* ── Search results — compact row layout ──
   .result-card is still used by the VMPP search page; .result-row is
   the new search-results layout (thumbnail + name + chips + chevron). */
.result-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: #fff;
  border: 1px solid var(--grey-200);
  border-radius: var(--radius);
  padding: 10px 14px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow .15s, border-color .15s;
  color: var(--grey-800);
}
.result-row:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow);
  text-decoration: none;
}

/* Thumbnail block — 44px square, optional corner badge for non-dm+d */
.result-thumb {
  position: relative;
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  border-radius: 6px;
  background: var(--grey-100);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}
.result-thumb__img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #dde3eb;
}
.result-thumb__placeholder {
  font-size: 22px;
  line-height: 1;
}
.result-thumb--dmd-empty   { background: var(--grey-100);  color: var(--grey-400); }
.result-thumb--local-empty { background: var(--amber-light); color: var(--amber); }

/* Corner badge sits over the photo to flag non-dm+d drugs. */
.result-thumb__badge {
  position: absolute;
  top: -3px;
  right: -3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--amber-light);
  color: var(--amber);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  border: 1.5px solid #fff;
  line-height: 1;
}

/* Middle text column — must allow ellipsis on long drug names. */
.result-text {
  flex: 1;
  min-width: 0;
}
.result-row .result-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Right-side characteristic chips */
.result-chips {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}
.result-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px;
  background: var(--grey-100);
  border-radius: 12px;
  font-size: 11px;
  color: var(--grey-600);
  white-space: nowrap;
}
.result-swatch {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 1px solid rgba(0,0,0,.15);
  display: inline-block;
  flex-shrink: 0;
}
.result-swatch--clear {
  background: transparent;
  border: 1px dashed var(--grey-400);
}
.result-swatch--multi {
  background: conic-gradient(from 0deg, #ef4444, #f59e0b, #10b981, #3b82f6, #8b5cf6, #ef4444);
  border-color: transparent;
}

.result-no-details {
  font-size: 11px;
  color: var(--grey-400);
  font-style: italic;
}

/* ── Search results — VMPP grouping ──
   Each VMPP is a native <details>; the <summary> is the clickable header
   row that reveals the AMPPs inside on expand. Local AMPPs group with
   their dm+d siblings under the same VMPP header.
*/
.result-group + .result-group {
  margin-top: 4px;
}

.result-group__header {
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: var(--grey-50);
  border: 1px solid var(--grey-200);
  border-radius: var(--radius);
  list-style: none;
  user-select: none;
  transition: background .15s, border-color .15s;
}
.result-group__header::-webkit-details-marker { display: none; }
.result-group__header::marker                 { display: none; }
.result-group__header:hover {
  background: var(--grey-100);
  border-color: var(--grey-300);
}

.result-group[open] .result-group__header {
  background: var(--grey-100);
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
}

.result-group__name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
  font-size: 14px;
  color: var(--grey-800);
}
.result-group__meta {
  flex-shrink: 0;
  font-size: 12px;
  color: var(--grey-500);
}
.result-group__chevron {
  flex-shrink: 0;
  width: 16px;
  text-align: center;
  color: var(--grey-400);
  font-size: 14px;
  transition: transform .2s;
}
.result-group[open] .result-group__chevron {
  transform: rotate(180deg);
}

.result-group__body {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-top: 6px;
}

/* ── Import status strip ── */
.import-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}
.import-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  background: #fff;
  border: 1px solid var(--grey-200);
  border-radius: 99px;
  padding: 4px 12px;
  font-size: 12px;
  color: var(--grey-600);
}
.dot {
  width: 7px; height: 7px;
  border-radius: 50%;
}
.dot--ok   { background: var(--green); }
.dot--warn { background: var(--amber); }
.dot--none { background: var(--grey-300); }

/* ── Drug detail ── */
.detail-grid {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 20px;
  align-items: start;
}

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

.drug-img-box {
  background: #fff;
  border: 1px solid var(--grey-200);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
  box-shadow: var(--shadow-sm);
}
.drug-img-real {
  width: 100%;
  max-width: 160px;
  height: 160px;
  object-fit: contain;
  background: #dde3eb;
  border-radius: 6px;
}
.drug-img-none {
  width: 100%;
  height: 140px;
  background: var(--grey-100);
  border: 2px dashed var(--grey-200);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--grey-400);
  font-size: 12px;
}
.drug-img-caption { font-size: 11px; color: var(--grey-400); margin-top: 6px; }

/* Characteristics grid */
.char-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  border-top: 1px solid var(--grey-100);
}
.char-cell {
  padding: 12px 16px;
  border-right: 1px solid var(--grey-100);
  border-bottom: 1px solid var(--grey-100);
}
.char-cell:nth-child(even) { border-right: none; }
.char-key { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--grey-400); margin-bottom: 3px; }
.char-val { font-size: 14px; color: var(--grey-800); font-weight: 500; }

/* Price cards */
.price-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 10px;
}
.price-card {
  background: #fff;
  border: 1px solid var(--grey-200);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow-sm);
}
.price-card--active { border-color: var(--primary); }
.pc-country { font-size: 12px; font-weight: 600; color: var(--grey-500); margin-bottom: 6px; }
.pc-net     { font-size: 22px; font-weight: 700; color: var(--grey-800); letter-spacing: -.02em; }
.pc-label   { font-size: 11px; color: var(--grey-400); margin-bottom: 8px; }
.pc-row     { display: flex; justify-content: space-between; font-size: 12px; color: var(--grey-600); padding: 3px 0; border-top: 1px solid var(--grey-50); }
.conc-badge { background: var(--amber-light); color: var(--amber); font-weight: 600; padding: 1px 6px; border-radius: 4px; }

.price-up   { color: var(--red);   font-weight: 700; }
.price-down { color: var(--green); font-weight: 700; }

.history-tab         { }
.history-tab--active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ── Barcode scanner ── */
.barcode-scan-area {
  position: relative;
  width: 100%;
  height: 240px;
  background: #0f172a;
  border-radius: 6px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 12px;
}

.scan-corner {
  position: absolute;
  width: 20px; height: 20px;
  border-color: var(--primary);
  border-style: solid;
  border-width: 0;
}
.sc-tl { top: 12px; left: 12px; border-top-width: 3px; border-left-width: 3px; border-top-left-radius: 3px; }
.sc-tr { top: 12px; right: 12px; border-top-width: 3px; border-right-width: 3px; border-top-right-radius: 3px; }
.sc-bl { bottom: 12px; left: 12px; border-bottom-width: 3px; border-left-width: 3px; border-bottom-left-radius: 3px; }
.sc-br { bottom: 12px; right: 12px; border-bottom-width: 3px; border-right-width: 3px; border-bottom-right-radius: 3px; }

.scan-line {
  position: absolute;
  left: 12px; right: 12px;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--primary), transparent);
  animation: scanMove 2s ease-in-out infinite;
  top: 50%;
}
@keyframes scanMove {
  0%   { top: 20%; opacity: 1; }
  50%  { top: 80%; opacity: 1; }
  100% { top: 20%; opacity: 1; }
}

/* ── Webcam capture steps ── */
.step-bar {
  display: flex;
  align-items: center;
  margin-bottom: 20px;
  padding: 12px 16px;
  background: #fff;
  border: 1px solid var(--grey-200);
  border-radius: var(--radius);
}

.step-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--grey-400);
  font-weight: 500;
}
.step-item--active { color: var(--primary); }
.step-item--done   { color: var(--green); }

.step-dot {
  width: 22px; height: 22px;
  border-radius: 50%;
  border: 2px solid currentColor;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700;
  flex-shrink: 0;
}
.step-item--active .step-dot { background: var(--primary); color: #fff; border-color: var(--primary); }
.step-item--done .step-dot   { background: var(--green);   color: #fff; border-color: var(--green); }

.step-divider {
  flex: 1;
  height: 1px;
  background: var(--grey-200);
  margin: 0 8px;
  min-width: 16px;
}

.step-panel { }

/* ── Spinner ── */
.spinner {
  width: 40px; height: 40px;
  border: 3px solid var(--grey-100);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Form type toggle ── */
.form-toggle-wrap {
  display: inline-flex;
  border: 1px solid var(--grey-200);
  border-radius: 8px;
  overflow: hidden;
}
.form-toggle-option { display: flex; }
.form-toggle-option input[type="radio"] { display: none; }
.form-toggle-label {
  display: block;
  padding: 8px 28px;
  font-size: 14px;
  font-weight: 500;
  color: var(--grey-600);
  background: #fff;
  cursor: pointer;
  border-right: 1px solid var(--grey-200);
  transition: background .15s, color .15s;
  user-select: none;
}
.form-toggle-option:last-child .form-toggle-label { border-right: none; }
.form-toggle-option input[type="radio"]:checked + .form-toggle-label {
  background: var(--primary);
  color: #fff;
}
.form-toggle-label:hover { background: var(--grey-50); }
.form-toggle-option input[type="radio"]:checked + .form-toggle-label:hover {
  background: var(--primary-dark);
}

/* ── Utilities ── */
.text-muted { color: var(--grey-400); }
.font-mono  { font-family: 'SF Mono', 'Fira Code', monospace; }

/* ── Responsive nav ── */
@media (max-width: 600px) {
  .app-nav { padding: 0 14px; }
  .main-content { padding: 16px 14px 40px; }
  .page-header { flex-direction: column; align-items: flex-start; }
  .price-grid { grid-template-columns: 1fr 1fr; }
}
