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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #f5f7fa;
  color: #333;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.container {
  max-width: 640px;
  margin-left: auto;
  margin-right: auto;
  padding: 0 16px 16px;
  width: 100%;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

header {
  margin: 0 -16px 16px;
  width: calc(100% + 32px);
}

.header-bg {
  background: linear-gradient(135deg, #1a365d 0%, #2b6cb0 100%);
  padding: 28px 20px 36px;
  text-align: center;
  border-radius: 0 0 20px 20px;
}

header h1 {
  font-size: 1.4rem;
  font-weight: 700;
  color: #fff;
  letter-spacing: -0.02em;
}

.header-year {
  color: #90cdf4;
}

.header-sub {
  font-size: 0.75rem;
  color: #bee3f8;
  font-weight: 400;
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.search-wrapper {
  position: sticky;
  top: 0;
  z-index: 10;
  padding: 12px 12px;
  margin-top: -22px;
  background: #f5f7fa;
}

#searchInput {
  width: 100%;
  padding: 14px 16px;
  font-size: 1rem;
  border: none;
  border-radius: 12px;
  outline: none;
  background: #fff;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
  -webkit-appearance: none;
  appearance: none;
  transition: box-shadow 0.2s;
}

#searchInput:focus {
  box-shadow: 0 4px 20px rgba(66, 153, 225, 0.25);
}

#searchInput::-webkit-search-cancel-button {
  -webkit-appearance: none;
  height: 20px;
  width: 20px;
  background: #cbd5e0;
  border-radius: 50%;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%234a5568'%3E%3Cpath d='M18.3 5.7a1 1 0 0 0-1.4 0L12 10.6 7.1 5.7a1 1 0 1 0-1.4 1.4L10.6 12l-4.9 4.9a1 1 0 1 0 1.4 1.4L12 13.4l4.9 4.9a1 1 0 0 0 1.4-1.4L13.4 12l4.9-4.9a1 1 0 0 0 0-1.4z'/%3E%3C/svg%3E");
  background-size: 14px;
  background-position: center;
  background-repeat: no-repeat;
}

.status {
  text-align: center;
  font-size: 0.8rem;
  color: #a0aec0;
  margin-top: 6px;
  min-height: 1.2em;
}

.results {
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: 1;
}

.drug-card {
  background: #fff;
  border-radius: 10px;
  padding: 14px 16px;
  border: 1px solid #e2e8f0;
  cursor: pointer;
  transition: box-shadow 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.drug-card:active {
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.drug-card.discharge {
  border-left: 4px solid #ed8936;
  background: #fffaf5;
}

.drug-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}

.drug-generic {
  font-weight: 600;
  font-size: 0.95rem;
  color: #1a202c;
  flex: 1;
}

.drug-trade {
  font-size: 0.875rem;
  color: #718096;
  margin-bottom: 6px;
}

.drug-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  margin-top: 8px;
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.badge-category {
  background: #ebf4ff;
  color: #2b6cb0;
}

.badge-discharge {
  background: #feebc8;
  color: #c05621;
}

.drug-section {
  font-size: 0.75rem;
  color: #a0aec0;
  margin-top: 6px;
}

.drug-pregnancy {
  font-size: 0.75rem;
  color: #718096;
  margin-top: 2px;
}

.drug-comments {
  font-size: 0.8rem;
  color: #4a5568;
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px solid #f0f0f0;
  white-space: pre-line;
}

.no-results {
  text-align: center;
  color: #a0aec0;
  padding: 40px 0;
  font-size: 0.9rem;
}

/* Detail panel */
.detail-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.detail-panel {
  background: #fff;
  border-radius: 16px 16px 0 0;
  width: 100%;
  max-width: 640px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  animation: slideUp 0.25s ease-out;
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.detail-close {
  width: 44px;
  height: 44px;
  border: none;
  background: #f0f0f0;
  border-radius: 50%;
  font-size: 1.5rem;
  color: #4a5568;
  cursor: pointer;
  flex-shrink: 0;
  line-height: 44px;
  text-align: center;
}

.detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px 12px;
  border-bottom: 1px solid #e2e8f0;
  flex-shrink: 0;
}

.detail-header h2 {
  font-size: 1rem;
  font-weight: 700;
  color: #1a365d;
  flex: 1;
  margin-right: 12px;
}

.detail-content {
  padding: 16px 20px;
  padding-bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.detail-section {
  margin-bottom: 16px;
}

.detail-section:last-child {
  margin-bottom: 0;
}

.detail-label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #a0aec0;
  margin-bottom: 4px;
}

.detail-value {
  font-size: 0.85rem;
  color: #2d3748;
  line-height: 1.5;
  white-space: pre-line;
}

.detail-category {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 600;
  background: #ebf4ff;
  color: #2b6cb0;
}

.detail-nomatch {
  text-align: center;
  color: #a0aec0;
  font-size: 0.85rem;
  padding: 20px 0;
}

/* Footer */
footer {
  margin-top: auto;
  padding: 24px 0 20px;
  border-top: 1px solid #e2e8f0;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 6px;
  font-size: 0.75rem;
  color: #a0aec0;
}

.footer-info {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: center;
}

.footer-sep {
  color: #cbd5e0;
}

.credits {
  font-size: 0.7rem;
  color: #a0aec0;
}

.refresh-link {
  font-size: 0.65rem;
  color: #cbd5e0;
  text-decoration: none;
}

.refresh-link:active {
  color: #4299e1;
}

/* Mobile */
@media (max-width: 768px) {
  .container {
    padding: 0 12px 12px;
    padding-bottom: env(safe-area-inset-bottom, 12px);
  }

  header {
    margin: 0 -12px 16px;
    width: calc(100% + 24px);
  }

  .drug-card {
    padding: 12px 14px;
  }

  .detail-panel {
    max-height: 90vh;
  }

}
