/* ============================================================
   MedEx Mirror — Complete UI Stylesheet v2.0
   Inspired by OverseasMedFinder / MedEx clean card layout
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:ital,wght@0,300;0,400;0,500;0,600;0,700;1,400&display=swap');

/* ── Reset + Box Model ──────────────────────────────────────── */
#medex-wrapper,
#medex-wrapper * {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* ── Design Tokens ──────────────────────────────────────────── */
#medex-wrapper {
  --mx-teal:          #00a8b5;
  --mx-teal-dark:     #007f8c;
  --mx-teal-light:    #e6f7f9;
  --mx-teal-mid:      #b3e8ec;
  --mx-green:         #28a745;
  --mx-green-light:   #e8f5eb;
  --mx-orange:        #f57c00;
  --mx-orange-light:  #fff3e0;
  --mx-red:           #dc3545;
  --mx-red-light:     #ffeaea;
  --mx-blue:          #1565c0;
  --mx-blue-light:    #e3f0ff;

  --mx-bg:            #f4f7f8;
  --mx-surface:       #ffffff;
  --mx-border:        #dde5e8;
  --mx-border-light:  #eef2f4;

  --mx-text:          #2c3e50;
  --mx-text-mid:      #4a5568;
  --mx-text-muted:    #718096;
  --mx-text-light:    #a0aec0;

  --mx-radius:        8px;
  --mx-radius-lg:     12px;
  --mx-shadow-sm:     0 1px 4px rgba(0,0,0,.08);
  --mx-shadow:        0 2px 12px rgba(0,0,0,.10);
  --mx-shadow-lg:     0 6px 32px rgba(0,0,0,.12);

  --mx-font:          'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;

  font-family: var(--mx-font);
  color: var(--mx-text);
  background: transparent;
}

/* ── Wrapper ─────────────────────────────────────────────────── */
#medex-wrapper {
  max-width: 860px;
  margin: 0 auto;
  padding: 0 16px 40px;
}

/* ════════════════════════════════════════════════════════════
   SEARCH BOX
════════════════════════════════════════════════════════════ */
#medex-search-wrap {
  background: var(--mx-teal);
  background: linear-gradient(135deg, #007f8c 0%, #00a8b5 60%, #00bcd4 100%);
  border-radius: var(--mx-radius-lg);
  padding: 28px 28px 24px;
  margin-bottom: 20px;
  box-shadow: var(--mx-shadow);
}

#medex-search-wrap h2 {
  color: #fff;
  font-size: 1.2rem;
  font-weight: 600;
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 9px;
  letter-spacing: .01em;
}

#medex-search-wrap h2 svg {
  opacity: .9;
}

#medex-search-inner {
  display: flex;
  align-items: stretch;
  gap: 0;
  background: #fff;
  border-radius: var(--mx-radius);
  overflow: hidden;
  box-shadow: 0 2px 12px rgba(0,0,0,.18);
}

.medex-search-icon-wrap {
  display: flex;
  align-items: center;
  padding: 0 14px;
  background: #fff;
  color: var(--mx-teal);
  flex-shrink: 0;
}

/* Tom Select override — must sit inside the flex row */
#medex-search-inner .ts-wrapper {
  flex: 1;
  background: transparent;
}

#medex-search-inner .ts-control {
  border: none !important;
  box-shadow: none !important;
  border-radius: 0 !important;
  background: transparent !important;
  min-height: 50px !important;
  padding: 0 12px 0 0 !important;
  display: flex !important;
  align-items: center !important;
}

#medex-search-inner .ts-control input {
  font-size: 1rem !important;
  font-family: var(--mx-font) !important;
  color: var(--mx-text) !important;
  height: 50px !important;
  width: 100% !important;
  padding: 0 !important;
}

#medex-search-inner .ts-control input::placeholder {
  color: var(--mx-text-muted);
  font-size: .97rem;
}

/* Dropdown */
.ts-dropdown {
  border: 1.5px solid var(--mx-border) !important;
  border-radius: var(--mx-radius) !important;
  box-shadow: var(--mx-shadow-lg) !important;
  margin-top: 4px !important;
  font-family: var(--mx-font) !important;
  font-size: .93rem !important;
  overflow: hidden !important;
  z-index: 9999 !important;
}

.ts-dropdown .option {
  padding: 0 !important;
  border-bottom: 1px solid var(--mx-border-light);
  cursor: pointer;
  transition: background .1s;
}

.ts-dropdown .option:last-child { border-bottom: none; }

.ts-dropdown .option:hover,
.ts-dropdown .option.active {
  background: var(--mx-teal-light) !important;
}

/* Custom option layout */
.mx-option {
  padding: 10px 16px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.mx-option-brand {
  font-weight: 600;
  color: var(--mx-text);
  font-size: .95rem;
}

.mx-option-meta {
  font-size: .8rem;
  color: var(--mx-text-muted);
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.mx-option-generic { color: var(--mx-teal-dark); }
.mx-option-company { color: var(--mx-text-muted); }

.mx-option-price {
  color: var(--mx-green);
  font-weight: 600;
  margin-left: auto;
}

.ts-dropdown .no-results {
  color: var(--mx-text-muted) !important;
  padding: 14px 16px !important;
  font-style: italic;
}

.medex-hint {
  color: rgba(255,255,255,.75);
  font-size: .8rem;
  margin-top: 10px;
  display: flex;
  align-items: center;
  gap: 5px;
}

/* ════════════════════════════════════════════════════════════
   RESULT CARD
════════════════════════════════════════════════════════════ */
#medex-result-panel {
  background: var(--mx-surface);
  border: 1px solid var(--mx-border);
  border-radius: var(--mx-radius-lg);
  box-shadow: var(--mx-shadow);
  overflow: hidden;
  animation: mx-slide-in .22s ease;
}

@keyframes mx-slide-in {
  from { opacity: 0; transform: translateY(-10px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Drug Header ─────────────────────────────────────────────── */
.mx-drug-header {
  padding: 24px 28px 20px;
  border-bottom: 2px solid var(--mx-border);
  background: var(--mx-surface);
}

.mx-breadcrumb {
  font-size: .75rem;
  color: var(--mx-text-muted);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 5px;
}

.mx-breadcrumb a {
  color: var(--mx-teal);
  text-decoration: none;
}

.mx-breadcrumb a:hover { text-decoration: underline; }
.mx-breadcrumb-sep { color: var(--mx-text-light); }

/* Title row */
.mx-title-row {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 14px;
}

.mx-med-icon {
  width: 52px;
  height: 52px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  background: var(--mx-teal-light);
  color: var(--mx-teal);
}

.mx-med-icon svg { width: 28px; height: 28px; }

/* Icon variants by type */
.mx-icon-tablet    { background: #e3f0ff; color: #1565c0; }
.mx-icon-capsule   { background: #fce4ec; color: #c62828; }
.mx-icon-syrup,
.mx-icon-suspension,
.mx-icon-solution,
.mx-icon-drops     { background: #e8f5e9; color: #2e7d32; }
.mx-icon-injection,
.mx-icon-infusion  { background: #f3e5f5; color: #6a1b9a; }
.mx-icon-cream,
.mx-icon-ointment,
.mx-icon-gel,
.mx-icon-lotion    { background: #fff8e1; color: #e65100; }
.mx-icon-inhaler   { background: #e0f7fa; color: #00838f; }
.mx-icon-powder,
.mx-icon-sachet    { background: #fafafa; color: #546e7a; }

.mx-title-text { flex: 1; }

h1.mx-drug-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--mx-text);
  line-height: 1.3;
  margin-bottom: 4px;
}

.mx-type-badge {
  display: inline-block;
  font-size: .72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  padding: 2px 10px;
  border-radius: 20px;
  background: var(--mx-teal-light);
  color: var(--mx-teal-dark);
  margin-top: 4px;
}

/* Price row */
.mx-price-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 16px;
  padding: 12px 16px;
  background: #f8fffe;
  border: 1px solid var(--mx-teal-mid);
  border-radius: var(--mx-radius);
  margin-bottom: 14px;
}

.mx-price-label {
  font-size: .78rem;
  font-weight: 600;
  color: var(--mx-text-muted);
  text-transform: uppercase;
  letter-spacing: .05em;
}

.mx-unit-price {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--mx-green);
  background: var(--mx-green-light);
  padding: 4px 14px;
  border-radius: 20px;
  letter-spacing: .01em;
}

.mx-strip-price {
  font-size: .88rem;
  color: var(--mx-orange);
  background: var(--mx-orange-light);
  font-weight: 600;
  padding: 4px 12px;
  border-radius: 20px;
}

.mx-source-link {
  margin-left: auto;
  font-size: .75rem;
  color: var(--mx-teal);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}

.mx-source-link:hover { text-decoration: underline; }

/* Meta info: generic + manufacturer */
.mx-meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 24px;
  font-size: .88rem;
}

.mx-meta-item {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--mx-text-mid);
}

.mx-meta-item svg { color: var(--mx-teal); flex-shrink: 0; }

.mx-meta-item strong {
  color: var(--mx-teal-dark);
  font-weight: 500;
}

/* ── Table of Contents ───────────────────────────────────────── */
.mx-toc {
  background: var(--mx-bg);
  border-bottom: 1px solid var(--mx-border);
  padding: 14px 28px;
}

.mx-toc-label {
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--mx-text-muted);
  margin-bottom: 10px;
}

.mx-toc-list {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.mx-toc-list li a {
  display: inline-block;
  padding: 4px 12px;
  font-size: .8rem;
  color: var(--mx-teal-dark);
  background: var(--mx-teal-light);
  border: 1px solid var(--mx-teal-mid);
  border-radius: 20px;
  text-decoration: none;
  font-weight: 500;
  transition: background .15s, color .15s;
}

.mx-toc-list li a:hover {
  background: var(--mx-teal);
  color: #fff;
  border-color: var(--mx-teal);
}

/* ── Sections Accordion ──────────────────────────────────────── */
.mx-sections {
  padding: 0;
}

.mx-section {
  border-bottom: 1px solid var(--mx-border-light);
}

.mx-section:last-child { border-bottom: none; }

.mx-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0;
  cursor: pointer;
  user-select: none;
  background: none;
  border: none;
  width: 100%;
  text-align: left;
  transition: background .12s;
}

.mx-section-header:hover {
  background: var(--mx-teal-light);
}

.mx-section-header:hover .mx-section-title-text {
  color: var(--mx-teal-dark);
}

.mx-section-title-bar {
  display: flex;
  align-items: center;
  gap: 0;
  width: 100%;
  padding: 14px 28px;
}

.mx-section-number {
  width: 26px;
  height: 26px;
  background: var(--mx-teal);
  color: #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .7rem;
  font-weight: 700;
  flex-shrink: 0;
  margin-right: 12px;
}

.mx-section-title-text {
  font-size: .95rem;
  font-weight: 600;
  color: var(--mx-text-mid);
  flex: 1;
  transition: color .12s;
}

.mx-section-chevron {
  margin-left: 8px;
  color: var(--mx-teal);
  flex-shrink: 0;
  transition: transform .2s ease;
}

.mx-section.is-open .mx-section-chevron {
  transform: rotate(180deg);
}

.mx-section.is-open .mx-section-header {
  background: var(--mx-teal-light);
}

.mx-section.is-open .mx-section-title-text {
  color: var(--mx-teal-dark);
}

/* Section body */
.mx-section-body {
  display: none;
  padding: 18px 28px 20px 66px;
  background: var(--mx-surface);
  font-size: .9rem;
  line-height: 1.8;
  color: var(--mx-text-mid);
  border-top: 1px solid var(--mx-teal-light);
  animation: mx-body-in .18s ease;
}

@keyframes mx-body-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.mx-section.is-open .mx-section-body { display: block; }

.mx-section-body p { margin-bottom: 10px; }
.mx-section-body p:last-child { margin-bottom: 0; }
.mx-section-body ul,
.mx-section-body ol { padding-left: 20px; margin: 8px 0; }
.mx-section-body li { margin-bottom: 5px; }
.mx-section-body strong, .mx-section-body b { color: var(--mx-text); }
.mx-section-body table {
  width: 100%;
  border-collapse: collapse;
  font-size: .85rem;
  margin: 10px 0;
}
.mx-section-body td, .mx-section-body th {
  border: 1px solid var(--mx-border);
  padding: 6px 10px;
  text-align: left;
}
.mx-section-body th {
  background: var(--mx-bg);
  font-weight: 600;
}

/* ── Disclaimer ──────────────────────────────────────────────── */
.mx-disclaimer {
  padding: 14px 28px;
  background: var(--mx-bg);
  border-top: 1px solid var(--mx-border);
  font-size: .75rem;
  color: var(--mx-text-muted);
  display: flex;
  align-items: flex-start;
  gap: 7px;
  line-height: 1.5;
}

.mx-disclaimer svg { flex-shrink: 0; margin-top: 1px; color: var(--mx-orange); }
.mx-disclaimer a { color: var(--mx-teal); text-decoration: none; }
.mx-disclaimer a:hover { text-decoration: underline; }

/* ── No sections fallback ────────────────────────────────────── */
.mx-no-sections {
  padding: 28px;
  color: var(--mx-text-muted);
  font-style: italic;
  font-size: .9rem;
}

/* ── Error State ─────────────────────────────────────────────── */
.mx-error {
  margin: 20px 0;
  background: var(--mx-red-light);
  border: 1px solid #f5c6cb;
  border-radius: var(--mx-radius);
  padding: 18px 20px;
  display: flex;
  gap: 12px;
  align-items: flex-start;
  color: #721c24;
  font-size: .9rem;
  line-height: 1.5;
}

.mx-error svg { flex-shrink: 0; margin-top: 2px; color: var(--mx-red); }

/* ── Skeleton Loader ─────────────────────────────────────────── */
#medex-skeleton { padding: 28px; }

.sk-shimmer {
  background: linear-gradient(90deg, #f0f4f5 25%, #e2ebec 50%, #f0f4f5 75%);
  background-size: 200% 100%;
  animation: sk-shine 1.5s infinite;
  border-radius: 6px;
  display: block;
}

@keyframes sk-shine {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.sk-row { margin-bottom: 14px; }
.sk-h1  { height: 32px; width: 65%; }
.sk-h2  { height: 14px; width: 40%; margin-top: 6px; }
.sk-price-bar {
  height: 42px; width: 100%;
  border-radius: 8px;
  margin: 14px 0;
}
.sk-meta { height: 13px; width: 55%; }
.sk-divider { height: 1px; background: var(--mx-border); margin: 16px 0; }
.sk-section { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.sk-circle  { width: 26px; height: 26px; border-radius: 50%; flex-shrink: 0; }
.sk-line    { height: 14px; flex: 1; }

/* ── Bottom disclaimer (below search) ───────────────────────── */
.medex-footer-note {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: .75rem;
  color: rgba(255,255,255,.7);
  margin-top: 12px;
}

.medex-footer-note a { color: rgba(255,255,255,.9); }

/* ── Responsive ──────────────────────────────────────────────── */
@media (max-width: 640px) {
  #medex-search-wrap { padding: 18px 16px 16px; }

  .mx-drug-header { padding: 18px 16px 16px; }
  .mx-toc         { padding: 12px 16px; }
  .mx-section-title-bar { padding: 12px 16px; }
  .mx-section-body { padding: 14px 16px 16px 54px; }
  .mx-disclaimer  { padding: 12px 16px; }

  h1.mx-drug-title { font-size: 1.2rem; }
  .mx-title-row   { gap: 10px; }
  .mx-med-icon    { width: 42px; height: 42px; border-radius: 8px; }
  .mx-med-icon svg { width: 22px; height: 22px; }

  .mx-price-row   { padding: 10px 12px; }
  .mx-meta-row    { gap: 6px 12px; }

  #medex-skeleton { padding: 18px; }
}
