/* DILItool Custom Styles */

:root {
  --primary: #0891b2; /* cyan-600 */
  --primary-dark: #0e7490; /* cyan-700 */
  --primary-light: #06b6d4; /* cyan-500 */
  --accent: #0284c7; /* sky-600 */
  --success: #059669; /* emerald-600 */
  --warning: #d97706; /* amber-600 */
  --danger: #dc2626; /* red-600 */
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-700: #374151;
  --gray-900: #111827;
}

/* Base Styles */
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: linear-gradient(to bottom, #f0f9ff, #ffffff);
  min-height: 100vh;
}

/* Header Enhancement */
header {
  backdrop-filter: blur(10px);
  background: rgba(255, 255, 255, 0.95);
  border-bottom: 2px solid var(--gray-200);
}

header h1 a {
  background: linear-gradient(135deg, var(--primary), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  font-weight: 700;
  transition: all 0.3s ease;
}

header h1 a:hover {
  transform: scale(1.02);
}

/* Card Styles */
.card {
  background: white;
  border-radius: 12px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05), 0 4px 12px rgba(0, 0, 0, 0.05);
  transition: all 0.3s ease;
}

.card:hover {
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.07), 0 8px 20px rgba(0, 0, 0, 0.08);
}

/* Search Input Enhancement */
input[type="text"] {
  transition: all 0.2s ease;
  border: 2px solid var(--gray-200);
}

input[type="text"]:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(8, 145, 178, 0.1);
  transform: translateY(-1px);
}

/* Camera Button */
#camera-btn svg {
  flex-shrink: 0;
}

/* Search Results */
.search-result-item {
  transition: all 0.2s ease;
  border-left: 3px solid transparent;
  position: relative;
}

.search-result-item:hover {
  background: linear-gradient(to right, #ecfeff, #ffffff);
  border-left-color: var(--primary);
}

.search-result-item.selected {
  background: #f9fafb;
  opacity: 0.7;
  cursor: not-allowed;
  border-left-color: #10b981;
}

.search-result-item.selected:hover {
  background: #f9fafb;
  border-left-color: #10b981;
}

.checkmark-indicator {
  display: inline-flex;
  align-items: center;
  vertical-align: middle;
  margin-left: 0.375rem;
}

/* Likelihood Score Badges */
.likelihood-badge {
  display: inline-block;
  padding: 0.25rem 0.75rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.025em;
}

.likelihood-a {
  background: #fee2e2;
  color: #991b1b;
}

.likelihood-b {
  background: #fed7aa;
  color: #9a3412;
}

.likelihood-c {
  background: #fef3c7;
  color: #92400e;
}

.likelihood-d {
  background: #dbeafe;
  color: #1e3a8a;
}

.likelihood-e, .likelihood-e-star {
  background: #d1fae5;
  color: #065f46;
}

.likelihood-x {
  background: #f3f4f6;
  color: #374151;
}

/* Category Cards */
.category-card {
  position: relative;
  overflow: hidden;
}

.category-card::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  background: currentColor;
  opacity: 0.5;
}

.category-card:hover::before {
  opacity: 1;
}

/* Button Styles */
.btn {
  padding: 0.5rem 1rem;
  border-radius: 8px;
  font-weight: 500;
  transition: all 0.2s ease;
  cursor: pointer;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white;
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(8, 145, 178, 0.3);
}

/* Loading Spinner */
.htmx-indicator {
  opacity: 0;
  transition: opacity 0.2s ease;
}

.htmx-request .htmx-indicator {
  opacity: 1;
}

/* Footer */
footer {
  border-top: 1px solid var(--gray-200);
  background: rgba(255, 255, 255, 0.8);
}

/* Smooth Scrollbar */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--gray-100);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb {
  background: var(--gray-200);
  border-radius: 4px;
  transition: background 0.1s ease;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--primary);
}

/* Custom scrollbar for selected meds container */
#selected-meds {
  scrollbar-width: thin;
  scrollbar-color: #d1d5db transparent;
}

#selected-meds::-webkit-scrollbar {
  width: 8px;
}

#selected-meds::-webkit-scrollbar-track {
  background: transparent;
}

#selected-meds::-webkit-scrollbar-thumb {
  background: #d1d5db;
  border-radius: 4px;
  transition: background 0.1s ease;
}

#selected-meds::-webkit-scrollbar-thumb:hover {
  background: var(--primary);
}

/* Responsive adjustments */
@media (max-width: 768px) {
  .card {
    border-radius: 8px;
  }

  #selected-meds::-webkit-scrollbar {
    width: 6px;
  }

  /* Improve touch targets for mobile */
  .search-result-item {
    padding: 0.875rem 1rem;
    min-height: 56px;
  }

  /* Better spacing for medication cards on mobile */
  .card p-3 {
    padding: 0.875rem;
  }

  /* Ensure remove buttons are large enough for touch */
  button[aria-label*="Remove"] {
    min-width: 44px;
    min-height: 44px;
    padding: 0.625rem;
  }

  /* Improve likelihood badge readability on mobile */
  .likelihood-badge {
    font-size: 0.813rem;
    padding: 0.313rem 0.625rem;
    white-space: nowrap;
  }

  /* Better footer spacing on mobile */
  footer .text-center {
    padding-left: 0.5rem;
    padding-right: 0.5rem;
  }
}

/* Small mobile devices (< 640px) */
@media (max-width: 640px) {
  /* Header adjustments for small screens */
  header h1 {
    font-size: 1.5rem;
  }

  header nav {
    gap: 0.25rem;
  }

  header nav a {
    padding: 0.5rem 0.625rem;
    font-size: 0.813rem;
  }

  /* Improve selected medications container on mobile */
  #selected-meds {
    max-height: 50vh !important;
    min-height: 200px;
  }

  /* Make category cards more compact on mobile */
  .category-card {
    padding: 1rem !important;
  }

  .category-card .likelihood-badge {
    font-size: 0.875rem;
    padding: 0.375rem 0.75rem;
  }

  .category-card h2 {
    font-size: 1rem;
  }

  .category-card p {
    font-size: 0.813rem;
    line-height: 1.5;
  }

  /* Stack medication name and badge on very small screens if needed */
  .search-result-item .flex {
    gap: 0.5rem;
  }

  /* Improve search input on mobile */
  input[type="text"] {
    font-size: 1rem; /* Prevents iOS zoom on focus */
    padding: 0.875rem 1rem;
  }

  /* Better spacing for page headers */
  .max-w-7xl > .text-center {
    padding-left: 0.75rem;
    padding-right: 0.75rem;
  }
}

/* Extra small devices (< 400px) */
@media (max-width: 400px) {
  /* Further condense header on very small screens */
  header h1 {
    font-size: 1.375rem;
  }

  header nav a {
    padding: 0.5rem;
    font-size: 0.75rem;
  }

  /* Stack footer links vertically on tiny screens */
  footer .space-y-2 {
    gap: 0.75rem;
  }

  footer .text-xs {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
  }

  footer .text-xs .mx-2 {
    display: none;
  }

  /* Reduce card padding on very small screens */
  .card {
    padding: 0.875rem !important;
  }

  /* Make selected med cards more compact */
  [data-med-id] {
    padding: 0.75rem !important;
  }

  [data-med-id] h3 {
    font-size: 0.938rem;
    line-height: 1.3;
  }

  [data-med-id] .text-xs {
    font-size: 0.75rem;
  }

  /* Improve likelihood score badge sizing */
  .likelihood-badge {
    font-size: 0.75rem;
    padding: 0.25rem 0.5rem;
  }
}

/* Landscape orientation on mobile */
@media (max-width: 768px) and (orientation: landscape) {
  /* Reduce vertical padding in landscape mode */
  .py-4, .py-6, .py-8 {
    padding-top: 1rem;
    padding-bottom: 1rem;
  }

  #selected-meds {
    max-height: 40vh !important;
  }

  .category-card {
    padding: 0.875rem !important;
  }
}

/* Mobile-specific improvements */
@media (max-width: 768px) {
  /* Camera button - ensure proper touch target on mobile */
  #camera-btn {
    min-width: 44px;
    min-height: 44px;
  }

  /* Improve text truncation on mobile */
  .truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
  }

  /* Better handling of long medication names */
  [data-med-id] h3 {
    word-wrap: break-word;
    overflow-wrap: break-word;
    hyphens: auto;
  }

  /* Improve drop overlay on mobile */
  #drop-overlay {
    border-width: 3px;
  }

  #drop-overlay svg {
    width: 3rem;
    height: 3rem;
  }

  #drop-overlay p {
    font-size: 0.938rem;
  }

  /* Better spacing for empty state on mobile */
  #empty-state {
    padding-top: 2rem !important;
    padding-bottom: 2rem !important;
  }

  /* Improve scroll behavior on mobile */
  #selected-meds {
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
  }

  /* Prevent text selection on interactive elements */
  .search-result-item,
  button,
  .likelihood-badge {
    -webkit-tap-highlight-color: rgba(8, 145, 178, 0.1);
    user-select: none;
    -webkit-user-select: none;
  }

  /* Better spacing between search icon and title */
  .flex.items-center.gap-2 svg {
    flex-shrink: 0;
  }
}

/* Accessibility: Ensure focus states are visible on mobile */
@media (max-width: 768px) {
  button:focus-visible,
  a:focus-visible,
  input:focus-visible {
    outline: 3px solid var(--primary);
    outline-offset: 2px;
  }

  /* Improve button press feedback on mobile */
  button:active:not(:disabled),
  .search-result-item:active:not(.selected) {
    transform: scale(0.98);
    transition: transform 0.1s ease;
  }
}

/* Prevent horizontal scroll on mobile */
@media (max-width: 768px) {
  body {
    overflow-x: hidden;
  }

  /* Ensure containers don't overflow */
  .max-w-7xl {
    max-width: 100%;
    overflow-x: hidden;
  }
}

/* Animations */
@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.animate-slide-in {
  animation: slideIn 0.1s ease;
}

/* Reduce animations on mobile for better performance */
@media (max-width: 768px) and (prefers-reduced-motion: no-preference) {
  .animate-slide-in {
    animation-duration: 0.05s;
  }

  .card,
  .search-result-item,
  input[type="text"] {
    transition-duration: 0.15s;
  }
}

/* Respect user's motion preferences */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
