/* ========================================
   AltMol – Enterprise Glassmorphism Theme
   Mobile-first, teal/green pharma palette
   ======================================== */

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

:root {
  --bg-primary: #0f172a;
  --bg-elevated: #1e293b;
  --glass-bg: rgba(255, 255, 255, 0.05);
  --glass-border: rgba(255, 255, 255, 0.08);
  --glass-shadow: 0 4px 24px rgba(0, 0, 0, 0.25);
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --accent: #0d9488;
  --accent-light: #14b8a6;
  --accent-surface: rgba(13, 148, 136, 0.1);
  --accent-border: rgba(13, 148, 136, 0.2);
  --green: #10b981;
  --green-surface: rgba(16, 185, 129, 0.08);
  --red: #ef4444;
  --red-surface: rgba(239, 68, 68, 0.08);
  --red-border: rgba(239, 68, 68, 0.2);
  --radius: 16px;
  --radius-sm: 10px;
  --radius-xs: 6px;
  --blur: 24px;
  --transition: 0.2s ease;
  --font: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'SF Pro Text',
    'Helvetica Neue', 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font);
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Subtle gradient bg */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse at 30% 0%, rgba(13, 148, 136, 0.08) 0%, transparent 60%),
    radial-gradient(ellipse at 70% 100%, rgba(16, 185, 129, 0.05) 0%, transparent 60%),
    var(--bg-primary);
  z-index: -1;
}

#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  padding: 16px;
  gap: 14px;
}

/* --- Glass Card --- */
.glass-card {
  background: var(--glass-bg);
  backdrop-filter: blur(var(--blur));
  -webkit-backdrop-filter: blur(var(--blur));
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  box-shadow: var(--glass-shadow);
}

.row { width: 100%; }

/* ========================================
   Row 1 – Header
   ======================================== */
.row-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding-top: 8px;
}

.logo-container {
  display: flex;
  justify-content: center;
}

.logo-img {
  height: 52px;
  width: auto;
  object-fit: contain;
}

/* Search Bar */
.search-container {
  display: flex;
  align-items: center;
  gap: 0;
  padding: 4px;
  width: 100%;
}

.search-icon-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 10px 0 12px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.medicine-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 0.95rem;
  padding: 13px 4px;
  min-height: 48px;
}

.medicine-input::placeholder {
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  cursor: pointer;
  font-family: var(--font);
  font-weight: 600;
  font-size: 0.85rem;
  transition: all var(--transition);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  letter-spacing: 0.01em;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius-sm);
  padding: 11px 18px;
  min-height: 44px;
  white-space: nowrap;
}

.btn-primary:hover { background: var(--accent-light); }
.btn-primary:active { transform: scale(0.96); }

.btn-action {
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius-sm);
  padding: 12px 20px;
  font-size: 0.9rem;
  flex: 1;
  min-height: 48px;
}

.btn-action:hover { background: var(--accent-light); }
.btn-action:active { transform: scale(0.97); }
.btn-action:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-outline {
  background: transparent;
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  padding: 12px 18px;
  font-size: 0.85rem;
  border: 1px solid var(--glass-border);
  cursor: pointer;
  min-height: 48px;
  white-space: nowrap;
}

.btn-outline:hover { border-color: var(--text-muted); color: var(--text-primary); }
.btn-outline:active { background: rgba(255,255,255,0.04); }

.btn-sm {
  padding: 6px 14px;
  font-size: 0.78rem;
  min-height: auto;
}

/* ========================================
   Row 2 – Camera
   ======================================== */
.camera-container {
  padding: 16px;
}

.section-label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 12px;
}

.camera-preview-wrapper {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--bg-primary);
  border: 1px solid var(--glass-border);
}

#camera-preview {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.camera-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

/* Corner brackets scan frame */
.scan-frame {
  position: relative;
  width: 72%;
  height: 58%;
}

.corner {
  position: absolute;
  width: 20px;
  height: 20px;
  border-color: var(--accent-light);
  border-style: solid;
  border-width: 0;
}

.corner.tl { top: 0; left: 0; border-top-width: 2.5px; border-left-width: 2.5px; border-top-left-radius: 6px; }
.corner.tr { top: 0; right: 0; border-top-width: 2.5px; border-right-width: 2.5px; border-top-right-radius: 6px; }
.corner.bl { bottom: 0; left: 0; border-bottom-width: 2.5px; border-left-width: 2.5px; border-bottom-left-radius: 6px; }
.corner.br { bottom: 0; right: 0; border-bottom-width: 2.5px; border-right-width: 2.5px; border-bottom-right-radius: 6px; }

.camera-hint {
  margin-top: 16px;
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.5);
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.6);
}

/* Thumbnail Preview */
.camera-thumbnail-wrapper {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 0;
}

#capture-thumbnail {
  width: 88px;
  height: 66px;
  object-fit: cover;
  border-radius: var(--radius-xs);
  border: 1px solid var(--glass-border);
}

.thumbnail-actions {
  display: flex;
  gap: 8px;
}

/* Camera Action Buttons */
.camera-actions {
  display: flex;
  gap: 10px;
  margin-top: 12px;
}

/* Camera Denied State */
.camera-denied .btn-action { display: none; }

.camera-denied .btn-outline {
  flex: 1;
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.camera-denied .btn-outline:hover {
  background: var(--accent-light);
  border-color: var(--accent-light);
}

.camera-denied .camera-preview-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100px;
  aspect-ratio: unset;
}

.camera-denied-msg {
  text-align: center;
  padding: 16px;
}

.camera-denied-msg p {
  color: var(--text-muted);
  font-size: 0.82rem;
  margin-top: 10px;
  line-height: 1.5;
}

/* ========================================
   Loading
   ======================================== */
.loading-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 28px;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid rgba(255, 255, 255, 0.06);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.loading-text {
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* ========================================
   Row 3 – Output
   ======================================== */
.result-card {
  padding: 20px;
}

.result-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.result-header-left {
  flex: 1;
  min-width: 0;
}

.result-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.3;
  word-break: break-word;
}

.result-subtitle {
  color: var(--accent-light);
  font-size: 0.82rem;
  font-weight: 500;
  margin-top: 3px;
}

.result-badge {
  background: var(--accent-surface);
  color: var(--accent-light);
  font-size: 0.7rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 20px;
  border: 1px solid var(--accent-border);
  white-space: nowrap;
  flex-shrink: 0;
}

/* Medicine Detail Grid */
.medicine-details {
  margin-bottom: 20px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--glass-border);
}

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.detail-item {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.detail-label {
  color: var(--text-muted);
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.detail-value {
  color: var(--text-primary);
  font-size: 0.9rem;
  font-weight: 500;
  word-break: break-word;
}

.detail-price {
  color: var(--accent-light);
  font-weight: 700;
  font-size: 1rem;
}

/* Alternatives Section */
.alternatives-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.alternatives-title {
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--text-primary);
}

.alt-count {
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 500;
}

.alternatives-table-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0 -20px;
  padding: 0 20px;
}

.alternatives-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
  min-width: 480px;
}

.alternatives-table thead th {
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 8px 8px;
  text-align: left;
  border-bottom: 1px solid var(--glass-border);
  white-space: nowrap;
}

.alternatives-table tbody td {
  padding: 10px 8px;
  color: var(--text-secondary);
  border-bottom: 1px solid rgba(255, 255, 255, 0.03);
  vertical-align: middle;
}

.alternatives-table tbody tr {
  transition: background var(--transition);
}

/* Cheapest row */
.alternatives-table tbody tr.cheapest {
  background: var(--green-surface);
}

.alternatives-table tbody tr.cheapest td {
  color: var(--green);
  font-weight: 600;
}

.cheapest-badge {
  display: inline-block;
  background: var(--green-surface);
  color: var(--green);
  font-size: 0.6rem;
  font-weight: 700;
  padding: 2px 5px;
  border-radius: 4px;
  margin-left: 4px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  vertical-align: middle;
}

.savings-positive {
  color: var(--green) !important;
  font-weight: 600 !important;
}

.no-alternatives {
  color: var(--text-muted);
  font-size: 0.82rem;
  text-align: center;
  padding: 24px 0;
}

/* ========================================
   Error
   ======================================== */
.error-card {
  padding: 18px;
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--red-border);
  background: var(--red-surface);
}

.error-icon { color: var(--red); flex-shrink: 0; }

.error-text {
  color: var(--red);
  font-size: 0.85rem;
  flex: 1;
}

/* ========================================
   Footer
   ======================================== */
.app-footer {
  margin-top: auto;
  text-align: center;
  padding: 20px 16px;
  font-size: 0.78rem;
  color: var(--text-muted);
  border-top: 1px solid var(--glass-border);
}

.app-footer p { margin-bottom: 4px; }

.app-footer a {
  color: var(--accent-light);
  text-decoration: none;
  font-weight: 500;
}

.app-footer a:active { opacity: 0.7; }

/* ========================================
   Animations
   ======================================== */
.row-output,
.row-loading,
.row-error {
  animation: slideUp 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ========================================
   Responsive / Utilities
   ======================================== */
@media (min-width: 481px) {
  #app { padding: 24px; }
}

@supports (padding: env(safe-area-inset-bottom)) {
  .app-footer { padding-bottom: calc(20px + env(safe-area-inset-bottom)); }
  #app { padding-bottom: env(safe-area-inset-bottom); }
}

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

.alternatives-table-wrapper::-webkit-scrollbar { height: 3px; }
.alternatives-table-wrapper::-webkit-scrollbar-track { background: transparent; }
.alternatives-table-wrapper::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.08); border-radius: 2px; }
