/* ============================================
   MedBot — Design System & Global Styles
   Light Medical Theme
   ============================================ */

/* ---- CSS Custom Properties ---- */
:root {
  /* User-Defined Palette */
  --deep-twilight: #03045e;
  --bright-teal-blue: #0077b6;
  --turquoise-surf: #00b4d8;
  --frosted-blue: #90e0ef;
  --light-cyan: #caf0f8;

  /* Primary Tonal Scale (Derived from Bright Teal Blue & Deep Twilight) */
  --primary-50: #f0faff;
  --primary-100: #caf0f8;
  --primary-200: #90e0ef;
  --primary-300: #48cae4;
  --primary-400: #00b4d8;
  --primary-500: #0077b6;
  --primary-600: #026094;
  --primary-700: #034870;
  --primary-800: #03045e;
  --primary-900: #02033b;

  /* Accent - Turquoise & Cyan */
  --accent-400: #00b4d8;
  --accent-500: #0077b6;
  --accent-600: #03045e;

  /* Light Medical Backgrounds */
  --bg-primary: #f4fbfe;
  --bg-secondary: #e9f7fc;
  --bg-tertiary: #d7f1f9;
  --bg-card: #ffffff;
  --bg-card-hover: #f0faff;
  --bg-glass: rgba(255, 255, 255, 0.85);

  /* Medical Text (Deep Twilight hierarchy) */
  --text-primary: #03045e;
  --text-secondary: #1d3557;
  --text-tertiary: #457b9d;
  --text-muted: #6c92af;

  /* Borders */
  --border-primary: #caebf5;
  --border-hover: #00b4d8;
  --border-focus: #0077b6;

  /* Gradients */
  --gradient-primary: linear-gradient(135deg, #0077b6, #00b4d8);
  --gradient-accent: linear-gradient(135deg, #03045e, #0077b6);
  --gradient-warm: linear-gradient(135deg, #f59e0b, #ef4444);
  --gradient-success: linear-gradient(135deg, #10b981, #00b4d8);
  --gradient-bg: linear-gradient(180deg, #f4fbfe 0%, #e9f7fc 100%);
  --gradient-card: linear-gradient(135deg, #ffffff 0%, #f6fcfe 100%);

  /* Shadows (Soft light medical elevation) */
  --shadow-sm: 0 1px 3px rgba(3, 4, 94, 0.05);
  --shadow-md: 0 4px 16px rgba(3, 4, 94, 0.07);
  --shadow-lg: 0 8px 30px rgba(3, 4, 94, 0.09);
  --shadow-xl: 0 16px 48px rgba(3, 4, 94, 0.12);
  --shadow-glow: 0 0 35px rgba(0, 180, 216, 0.22);
  --shadow-glow-strong: 0 0 50px rgba(0, 119, 182, 0.28);

  /* Typography */
  --font-primary: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-display: 'DM Sans', 'Inter', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  /* Spacing */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;
  --space-2xl: 48px;
  --space-3xl: 64px;

  /* Radii */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --radius-full: 9999px;

  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-base: 250ms ease;
  --transition-slow: 400ms ease;
  --transition-spring: 500ms cubic-bezier(0.34, 1.56, 0.64, 1);

  /* Layout */
  --header-height: 64px;
  --max-width: 1200px;
  --content-width: 800px;
}

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

html {
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-primary);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
  position: relative;
}

/* ---- Background Effects ---- */
.bg-grid {
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgba(0, 180, 216, 0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0, 180, 216, 0.05) 1px, transparent 1px);
  background-size: 60px 60px;
  z-index: 0;
  pointer-events: none;
}

.bg-glow {
  position: fixed;
  border-radius: 50%;
  filter: blur(120px);
  opacity: 0.55;
  pointer-events: none;
  z-index: 0;
  animation: glowFloat 15s ease-in-out infinite;
}

.bg-glow-1 {
  width: 550px;
  height: 550px;
  background: radial-gradient(circle, rgba(144, 224, 239, 0.45), transparent 70%);
  top: -150px;
  right: -100px;
  animation-delay: 0s;
}

.bg-glow-2 {
  width: 450px;
  height: 450px;
  background: radial-gradient(circle, rgba(202, 240, 248, 0.6), transparent 70%);
  bottom: -100px;
  left: -100px;
  animation-delay: -5s;
}

.bg-glow-3 {
  width: 400px;
  height: 400px;
  background: radial-gradient(circle, rgba(0, 180, 216, 0.18), transparent 70%);
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  animation-delay: -10s;
}

@keyframes glowFloat {
  0%, 100% { transform: translate(0, 0) scale(1); }
  33% { transform: translate(30px, -20px) scale(1.08); }
  66% { transform: translate(-20px, 15px) scale(0.96); }
}

/* ---- App Container ---- */
#app {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---- Header ---- */
#app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--header-height);
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border-primary);
  box-shadow: 0 2px 10px rgba(3, 4, 94, 0.04);
}

.header-inner {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 var(--space-lg);
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  cursor: pointer;
  text-decoration: none;
  transition: opacity var(--transition-fast);
}

.logo:hover {
  opacity: 0.85;
}

.logo-icon svg {
  width: 36px;
  height: 36px;
  filter: drop-shadow(0 2px 6px rgba(0, 119, 182, 0.25));
}

.logo-text {
  display: flex;
  flex-direction: column;
}

.logo-name {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.3rem;
  background: var(--gradient-primary);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  line-height: 1.15;
}

.logo-tagline {
  font-size: 0.7rem;
  color: var(--text-tertiary);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  font-weight: 600;
}

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-sm);
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius-md);
  font-family: var(--font-primary);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-base);
  line-height: 1;
  text-decoration: none;
  white-space: nowrap;
}

.btn-primary {
  background: var(--gradient-primary);
  color: #ffffff;
  box-shadow: 0 3px 12px rgba(0, 119, 182, 0.25);
}

.btn-primary:hover {
  box-shadow: 0 6px 20px rgba(0, 119, 182, 0.4);
  transform: translateY(-1px);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-glow {
  animation: btnGlow 2.5s ease-in-out infinite;
}

@keyframes btnGlow {
  0%, 100% { box-shadow: 0 3px 12px rgba(0, 119, 182, 0.25); }
  50% { box-shadow: 0 5px 26px rgba(0, 180, 216, 0.45); }
}

.btn-outline {
  background: #ffffff;
  color: var(--bright-teal-blue);
  border: 1px solid var(--border-primary);
  box-shadow: var(--shadow-sm);
}

.btn-outline:hover {
  border-color: var(--turquoise-surf);
  color: var(--deep-twilight);
  background: var(--light-cyan);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  padding: 8px 16px;
}

.btn-ghost:hover {
  color: var(--bright-teal-blue);
  background: var(--light-cyan);
}

.btn-accent {
  background: linear-gradient(135deg, #0077b6, #03045e);
  color: #ffffff;
  box-shadow: 0 3px 12px rgba(3, 4, 94, 0.22);
}

.btn-accent:hover {
  box-shadow: 0 5px 20px rgba(3, 4, 94, 0.35);
  transform: translateY(-1px);
}

.btn-danger {
  background: linear-gradient(135deg, #ef4444, #dc2626);
  color: white;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none !important;
}

/* ---- View System ---- */
.view {
  display: none;
  flex: 1;
  animation: viewEnter 0.45s ease forwards;
}

.view.active {
  display: flex;
  flex-direction: column;
}

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

/* ---- Utility Classes ---- */
.gradient-text {
  background: linear-gradient(135deg, #03045e 0%, #0077b6 50%, #00b4d8 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.required {
  color: #e63946;
}

.field-hint {
  display: block;
  font-size: 0.75rem;
  color: var(--text-tertiary);
  margin-top: var(--space-xs);
}

.field-error {
  display: block;
  font-size: 0.75rem;
  color: #e63946;
  margin-top: var(--space-xs);
  min-height: 1rem;
  font-weight: 500;
}

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

::-webkit-scrollbar-track {
  background: #f0faff;
}

::-webkit-scrollbar-thumb {
  background: #b2e6f4;
  border-radius: var(--radius-full);
}

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

/* ---- Loading Spinner ---- */
.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid rgba(0, 119, 182, 0.2);
  border-top-color: var(--bright-teal-blue);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

/* ---- Toast Notifications ---- */
.toast-container {
  position: fixed;
  top: calc(var(--header-height) + var(--space-md));
  right: var(--space-lg);
  z-index: 10000;
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.toast {
  background: #ffffff;
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-md);
  padding: var(--space-md) var(--space-lg);
  box-shadow: var(--shadow-lg);
  animation: toastIn 0.3s ease, toastOut 0.3s ease 3.7s forwards;
  max-width: 360px;
  font-size: 0.875rem;
  color: var(--text-primary);
}

.toast.error {
  border-color: rgba(239, 68, 68, 0.4);
  background: #fff5f5;
}

.toast.success {
  border-color: rgba(16, 185, 129, 0.4);
  background: #f0fdf9;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateX(100%); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes toastOut {
  from { opacity: 1; transform: translateX(0); }
  to { opacity: 0; transform: translateX(100%); }
}

/* ---- Responsive ---- */
@media (max-width: 768px) {
  :root {
    --header-height: 56px;
  }

  .header-inner {
    padding: 0 var(--space-md);
  }

  .logo-tagline {
    display: none;
  }

  .btn {
    padding: 8px 14px;
    font-size: 0.8125rem;
  }
}

@media (max-width: 480px) {
  .logo-icon svg {
    width: 30px;
    height: 30px;
  }

  .logo-name {
    font-size: 1.15rem;
  }
}

/* ---- Print Styles ---- */
@media print {
  body {
    background: white !important;
    color: #000 !important;
  }

  .bg-grid, .bg-glow, #app-header, .chat-input-area,
  .btn-new-consultation, .btn-end-consultation,
  .form-nav, .toast-container {
    display: none !important;
  }

  .view {
    display: block !important;
  }

  #view-prescription {
    display: block !important;
  }
}
