/* =================================================================
   Ask Your Surgeon - Main Stylesheet
   NHS-compliant design system with dark mode & full responsiveness
   ================================================================= */

/* =================================================================
   CSS VARIABLES - NHS Design System + Dark Mode Support
   ================================================================= */
:root {
  /* Modern Brand Colors */
  --nhs-blue: #0F766E;
  --nhs-dark-blue: #065F46;
  --nhs-bright-blue: #14B8A6;
  --nhs-light-blue: #5EEAD4;
  --nhs-aqua-blue: #2DD4BF;
  --nhs-green: #059669;
  --nhs-dark-green: #047857;
  --nhs-purple: #330072;
  --nhs-dark-pink: #7C2855;
  --nhs-orange: #ED8B00;
  --nhs-warm-yellow: #FFB81C;
  --nhs-red: #DA291C;

  /* Greyscale */
  --nhs-black: #212b32;
  --nhs-dark-grey: #425563;
  --nhs-mid-grey: #768692;
  --nhs-pale-grey: #E8EDEE;
  --nhs-light-grey: #F0F4F5;
  --nhs-white: #FFFFFF;

  /* Semantic Colors - Light Mode */
  --bg-primary: #F0F4F5;
  --bg-secondary: #FFFFFF;
  --bg-tertiary: #E8EDEE;
  --text-primary: #212b32;
  --text-secondary: #425563;
  --text-tertiary: #768692;
  --border-color: #d8dde0;
  --border-color-hover: #0F766E;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
  --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.12);
  --focus-ring: 0 0 0 3px rgba(15, 118, 110, 0.15);

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

  /* Typography */
  --font-family: "Frutiger W01", -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  --font-size-xs: 12px;
  --font-size-sm: 14px;
  --font-size-base: 16px;
  --font-size-lg: 18px;
  --font-size-xl: 20px;
  --font-size-2xl: 24px;
  --font-size-3xl: 28px;
  --font-size-4xl: 32px;

  /* Border Radius */
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;
  --radius-xl: 12px;
  --radius-full: 9999px;

  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-base: 200ms ease;
  --transition-slow: 300ms ease;
}

/* Dark Mode Variables */
[data-theme="dark"] {
  --bg-primary: #1a1f26;
  --bg-secondary: #252b35;
  --bg-tertiary: #2d3440;
  --text-primary: #e8edee;
  --text-secondary: #b8c1ca;
  --text-tertiary: #8896a3;
  --border-color: #3d4756;
  --border-color-hover: #41B6E6;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.5);
  --focus-ring: 0 0 0 3px rgba(65, 182, 230, 0.25);
}

/* =================================================================
   RESET & BASE STYLES
   ================================================================= */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

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

body {
  font-family: var(--font-family);
  font-size: var(--font-size-base);
  line-height: 1.6;
  color: var(--text-primary);
  background: var(--bg-primary);
  min-height: 100vh;
  margin: 0;
  padding: var(--space-lg);
  transition: background-color var(--transition-base), color var(--transition-base);
}

/* =================================================================
   TYPOGRAPHY
   ================================================================= */
h1, h2, h3, h4, h5, h6 {
  font-weight: 600;
  line-height: 1.2;
  color: var(--text-primary);
  margin-bottom: var(--space-md);
}

h1 { font-size: var(--font-size-4xl); }
h2 { font-size: var(--font-size-3xl); }
h3 { font-size: var(--font-size-2xl); }
h4 { font-size: var(--font-size-xl); }
h5 { font-size: var(--font-size-lg); }
h6 { font-size: var(--font-size-base); }

p {
  margin-bottom: var(--space-md);
  color: var(--text-secondary);
}

a {
  color: var(--nhs-blue);
  text-decoration: none;
  transition: color var(--transition-fast);
}

[data-theme="dark"] a {
  color: var(--nhs-light-blue);
}

a:hover {
  color: var(--nhs-dark-blue);
  text-decoration: underline;
}

[data-theme="dark"] a:hover {
  color: var(--nhs-aqua-blue);
}

strong, b {
  font-weight: 600;
  color: var(--text-primary);
}

/* =================================================================
   LAYOUT COMPONENTS
   ================================================================= */

/* Container */
.container {
  max-width: 450px;
  margin: 0 auto;
  padding: var(--space-xl);
  background: var(--bg-secondary);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  transition: all var(--transition-base);
}

.container-wide {
  max-width: 900px;
}

.container-full {
  max-width: 1200px;
}

/* Header */
.header {
  max-width: 900px;
  margin: 0 auto var(--space-lg);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--nhs-blue);
  padding: var(--space-lg) var(--space-xl);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  animation: slideDown 0.4s ease;
}

[data-theme="dark"] .header {
  background: linear-gradient(135deg, var(--nhs-dark-blue) 0%, var(--nhs-blue) 100%);
}

.header-left {
  display: flex;
  align-items: center;
  gap: var(--space-md);
}

.header h2 {
  margin: 0;
  color: var(--nhs-white);
  font-size: var(--font-size-2xl);
  font-weight: 600;
}

.header-actions {
  display: flex;
  gap: var(--space-md);
  flex-wrap: wrap;
}

.header-actions a,
.header-actions button {
  padding: 10px 20px;
  text-decoration: none;
  color: var(--nhs-white);
  border: 2px solid var(--nhs-white);
  border-radius: var(--radius-md);
  background: transparent;
  cursor: pointer;
  font-size: var(--font-size-sm);
  font-weight: 600;
  transition: all var(--transition-base);
}

.header-actions a:hover,
.header-actions button:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: none;
}

/* Logo */
.logo {
  width: 100px;
  height: 100px;
  border-radius: var(--radius-lg);
  object-fit: contain;
  margin: 0 auto var(--space-lg);
  display: block;
  transition: transform var(--transition-base);
}

.logo:hover {
  transform: scale(1.05);
}

.header .logo {
  width: 50px;
  height: 50px;
  background: var(--nhs-white);
  padding: 2px;
  margin: 0;
}

/* =================================================================
   FORM ELEMENTS
   ================================================================= */

/* Input Fields */
input, textarea, select {
  width: 100%;
  padding: 14px 16px;
  font-size: var(--font-size-base);
  font-family: var(--font-family);
  color: var(--text-primary);
  background: var(--bg-secondary);
  border: 2px solid var(--border-color);
  border-radius: var(--radius-md);
  outline: none;
  transition: all var(--transition-base);
  margin: var(--space-sm) 0;
}

input:focus, textarea:focus, select:focus {
  border-color: var(--border-color-hover);
  box-shadow: var(--focus-ring);
}

input::placeholder, textarea::placeholder {
  color: var(--text-tertiary);
}

input:disabled, textarea:disabled, select:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  background: var(--bg-tertiary);
}

/* Buttons */
button, .button, .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  padding: 12px 24px;
  font-size: var(--font-size-base);
  font-weight: 600;
  font-family: var(--font-family);
  color: var(--text-primary);
  background: var(--bg-secondary);
  border: 2px solid var(--border-color);
  border-radius: var(--radius-md);
  cursor: pointer;
  text-decoration: none;
  transition: all var(--transition-base);
  white-space: nowrap;
}

button:hover, .button:hover, .btn:hover {
  border-color: var(--border-color-hover);
  background: var(--bg-tertiary);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

button:active, .button:active, .btn:active {
  transform: translateY(0);
}

button:focus, .button:focus, .btn:focus {
  outline: none;
  box-shadow: var(--focus-ring);
}

button:disabled, .button:disabled, .btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

/* Button Variants */
.btn-primary, .submit-btn {
  background: var(--nhs-green);
  color: var(--nhs-white);
  border: none;
}

.btn-primary:hover, .submit-btn:hover {
  background: var(--nhs-dark-green);
  border: none;
}

.btn-secondary {
  background: var(--nhs-blue);
  color: var(--nhs-white);
  border: none;
}

.btn-secondary:hover {
  background: var(--nhs-dark-blue);
  border: none;
}

.btn-danger {
  background: var(--nhs-red);
  color: var(--nhs-white);
  border: none;
}

.btn-danger:hover {
  background: #b81f16;
  border: none;
}

.btn-ghost {
  background: transparent;
  border: 2px solid var(--border-color);
}

.btn-icon {
  padding: 8px;
  min-width: 40px;
  min-height: 40px;
}

/* =================================================================
   CHAT INTERFACE
   ================================================================= */
#chat {
  max-width: 900px;
  margin: var(--space-lg) auto;
  background: var(--bg-secondary);
  padding: var(--space-xl);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  max-height: 550px;
  overflow-y: auto;
  scroll-behavior: smooth;
  animation: fadeIn 0.5s ease;
}

/* Custom Scrollbar */
#chat::-webkit-scrollbar {
  width: 8px;
}

#chat::-webkit-scrollbar-track {
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm);
}

#chat::-webkit-scrollbar-thumb {
  background: var(--nhs-blue);
  border-radius: var(--radius-sm);
  transition: background var(--transition-base);
}

[data-theme="dark"] #chat::-webkit-scrollbar-thumb {
  background: var(--nhs-light-blue);
}

#chat::-webkit-scrollbar-thumb:hover {
  background: var(--nhs-dark-blue);
}

/* Chat Messages */
.msg {
  margin: var(--space-md) 0;
  padding: 14px 20px;
  border-radius: var(--radius-lg);
  line-height: 1.6;
  max-width: 80%;
  animation: slideIn 0.3s ease;
  word-wrap: break-word;
}

.msg.user {
  background: var(--nhs-blue);
  margin-left: auto;
  text-align: right;
  color: var(--nhs-white);
  border-bottom-right-radius: var(--radius-sm);
}

[data-theme="dark"] .msg.user {
  background: linear-gradient(135deg, var(--nhs-dark-blue) 0%, var(--nhs-blue) 100%);
}

.msg.consultant {
  background: var(--bg-tertiary);
  text-align: left;
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  margin-right: auto;
  border-bottom-left-radius: var(--radius-sm);
}

.msg strong {
  display: block;
  margin-bottom: var(--space-xs);
  font-weight: 600;
}

/* Input Area */
.input-area {
  max-width: 900px;
  margin: var(--space-lg) auto;
  display: flex;
  gap: var(--space-md);
  background: var(--bg-secondary);
  padding: var(--space-lg);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  animation: slideUp 0.4s ease;
}

.send-btn {
  padding: 14px 30px;
  background: var(--nhs-green);
  color: var(--nhs-white);
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: var(--font-size-base);
  font-weight: 600;
  transition: all var(--transition-base);
  white-space: nowrap;
}

.send-btn:hover {
  background: var(--nhs-dark-green);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.send-btn:disabled {
  background: var(--nhs-mid-grey);
  cursor: not-allowed;
  transform: none;
}

/* =================================================================
   TABLES
   ================================================================= */
table {
  width: 100%;
  margin: var(--space-lg) 0;
  border-collapse: collapse;
  font-size: var(--font-size-sm);
  box-shadow: var(--shadow-md);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

table th {
  background: linear-gradient(135deg, #1f3c58 0%, #2d5578 100%);
  color: var(--nhs-white);
  padding: 12px 15px;
  text-align: left;
  font-weight: 600;
  text-transform: uppercase;
  font-size: var(--font-size-xs);
  letter-spacing: 0.5px;
  border-bottom: 3px solid #0f2438;
}

table td {
  padding: 12px 15px;
  border-bottom: 1px solid var(--border-color);
  line-height: 1.5;
  color: var(--text-secondary);
}

table tr:last-child td {
  border-bottom: none;
}

table tr:nth-child(even) {
  background: var(--bg-tertiary);
}

table tr:hover {
  background: var(--nhs-pale-grey);
  transition: background var(--transition-fast);
}

[data-theme="dark"] table tr:hover {
  background: rgba(65, 182, 230, 0.1);
}

table td:first-child {
  font-weight: 500;
  color: var(--text-primary);
}

/* =================================================================
   LOADING INDICATOR
   ================================================================= */
.loading-indicator {
  display: none;
  padding: var(--space-lg);
  text-align: center;
  color: var(--text-primary);
  animation: fadeIn 0.3s ease;
}

.loading-indicator.active {
  display: block;
}

/* Bladder Animation */
.bladder-container {
  position: relative;
  width: 100px;
  height: 120px;
  margin: 0 auto var(--space-md);
}

.bladder-outline {
  position: absolute;
  width: 90px;
  height: 90px;
  left: 5px;
  top: 0;
  background: var(--bg-secondary);
  border: 3px solid var(--nhs-blue);
  border-radius: 45% 45% 50% 50% / 50% 50% 45% 45%;
  z-index: 2;
  overflow: hidden;
}

[data-theme="dark"] .bladder-outline {
  background: var(--bg-tertiary);
  border-color: var(--nhs-light-blue);
}

.bladder-outlet {
  position: absolute;
  width: 16px;
  height: 30px;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  background: var(--bg-secondary);
  border: 3px solid var(--nhs-blue);
  border-top: none;
  border-radius: 0 0 30% 30%;
  z-index: 1;
}

[data-theme="dark"] .bladder-outlet {
  background: var(--bg-tertiary);
  border-color: var(--nhs-light-blue);
}

.bladder-fill {
  position: absolute;
  bottom: 0;
  width: 100%;
  background: linear-gradient(180deg, #87CEEB 0%, #4A90E2 100%);
  animation: fillBladder 2.5s ease-in-out infinite;
  z-index: 1;
}

.bladder-wave {
  position: absolute;
  top: -10px;
  left: -50%;
  width: 200%;
  height: 20px;
  background: radial-gradient(ellipse at center, rgba(255, 255, 255, 0.4) 0%, transparent 70%);
  border-radius: 45%;
  animation: wave 2s ease-in-out infinite;
}

.bladder-shine {
  position: absolute;
  width: 25px;
  height: 35px;
  top: 15px;
  left: 20px;
  background: radial-gradient(ellipse at center, rgba(255, 255, 255, 0.6) 0%, transparent 70%);
  border-radius: 50%;
  z-index: 3;
  transform: rotate(-30deg);
}

/* =================================================================
   FLASH MESSAGES & ALERTS
   ================================================================= */
.flash-message, .alert {
  padding: 12px 16px;
  border-radius: var(--radius-md);
  margin: var(--space-md) auto;
  max-width: 450px;
  font-size: var(--font-size-sm);
  font-weight: 500;
  animation: slideDown 0.3s ease;
}

.flash-message, .alert-error {
  background: #ffebee;
  color: #c62828;
  border: 1px solid #ef9a9a;
}

.alert-success {
  background: #e8f5e9;
  color: #2e7d32;
  border: 1px solid #a5d6a7;
}

.alert-warning {
  background: #fff3e0;
  color: #e65100;
  border: 1px solid #ffcc80;
}

.alert-info {
  background: #e3f2fd;
  color: #1565c0;
  border: 1px solid #90caf9;
}

/* =================================================================
   DARK MODE TOGGLE
   ================================================================= */
.theme-toggle {
  position: fixed;
  bottom: var(--space-lg);
  right: var(--space-lg);
  width: 56px;
  height: 56px;
  background: var(--bg-secondary);
  border: 2px solid var(--border-color);
  border-radius: var(--radius-full);
  box-shadow: var(--shadow-lg);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  transition: all var(--transition-base);
  z-index: 1000;
  animation: fadeIn 0.5s ease 0.5s both;
}

.theme-toggle:hover {
  transform: scale(1.1) rotate(15deg);
  box-shadow: var(--shadow-lg);
}

.theme-toggle:active {
  transform: scale(0.95);
}

/* =================================================================
   UTILITY CLASSES
   ================================================================= */
.text-center { text-align: center; }
.text-left { text-align: left; }
.text-right { text-align: right; }

.mt-xs { margin-top: var(--space-xs); }
.mt-sm { margin-top: var(--space-sm); }
.mt-md { margin-top: var(--space-md); }
.mt-lg { margin-top: var(--space-lg); }
.mt-xl { margin-top: var(--space-xl); }

.mb-xs { margin-bottom: var(--space-xs); }
.mb-sm { margin-bottom: var(--space-sm); }
.mb-md { margin-bottom: var(--space-md); }
.mb-lg { margin-bottom: var(--space-lg); }
.mb-xl { margin-bottom: var(--space-xl); }

.p-xs { padding: var(--space-xs); }
.p-sm { padding: var(--space-sm); }
.p-md { padding: var(--space-md); }
.p-lg { padding: var(--space-lg); }
.p-xl { padding: var(--space-xl); }

.font-sm { font-size: var(--font-size-sm); }
.font-base { font-size: var(--font-size-base); }
.font-lg { font-size: var(--font-size-lg); }
.font-xl { font-size: var(--font-size-xl); }

.font-normal { font-weight: 400; }
.font-medium { font-weight: 500; }
.font-semibold { font-weight: 600; }
.font-bold { font-weight: 700; }

.rounded-sm { border-radius: var(--radius-sm); }
.rounded-md { border-radius: var(--radius-md); }
.rounded-lg { border-radius: var(--radius-lg); }
.rounded-full { border-radius: var(--radius-full); }

.shadow-sm { box-shadow: var(--shadow-sm); }
.shadow-md { box-shadow: var(--shadow-md); }
.shadow-lg { box-shadow: var(--shadow-lg); }

/* =================================================================
   ANIMATIONS
   ================================================================= */
@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateX(-20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

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

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fillBladder {
  0% { height: 15%; }
  50% { height: 85%; }
  100% { height: 15%; }
}

@keyframes wave {
  0%, 100% { transform: translateX(-25%) translateY(0); }
  50% { transform: translateX(0) translateY(-3px); }
}

/* =================================================================
   RESPONSIVE DESIGN
   ================================================================= */

/* Tablets and below (768px) */
@media (max-width: 768px) {
  body {
    padding: var(--space-md);
  }

  .container {
    padding: var(--space-lg);
  }

  .header {
    flex-direction: column;
    gap: var(--space-md);
    padding: var(--space-lg);
    text-align: center;
  }

  .header h2 {
    font-size: var(--font-size-xl);
  }

  .header-actions {
    width: 100%;
    justify-content: center;
  }

  .header-actions a,
  .header-actions button {
    flex: 1;
    min-width: 100px;
  }

  #chat {
    padding: var(--space-lg);
    max-height: 400px;
  }

  .msg {
    max-width: 90%;
    padding: 12px 16px;
  }

  .input-area {
    flex-direction: column;
    padding: var(--space-md);
  }

  .send-btn {
    width: 100%;
  }

  table {
    font-size: var(--font-size-xs);
  }

  table th,
  table td {
    padding: 8px 10px;
  }

  .theme-toggle {
    bottom: var(--space-md);
    right: var(--space-md);
    width: 48px;
    height: 48px;
    font-size: 20px;
  }
}

/* Mobile phones (480px and below) */
@media (max-width: 480px) {
  :root {
    --font-size-base: 14px;
    --font-size-2xl: 20px;
    --font-size-3xl: 24px;
    --font-size-4xl: 28px;
  }

  body {
    padding: var(--space-sm);
  }

  .container {
    padding: var(--space-md);
  }

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

  .header .logo {
    width: 40px;
    height: 40px;
  }

  .logo {
    width: 80px;
    height: 80px;
  }

  #chat {
    padding: var(--space-md);
    max-height: 350px;
  }

  .msg {
    max-width: 95%;
    padding: 10px 14px;
    font-size: var(--font-size-sm);
  }

  .input-area {
    padding: var(--space-sm);
    gap: var(--space-sm);
  }

  input, textarea, select {
    padding: 12px 14px;
    font-size: var(--font-size-sm);
  }

  button, .button, .btn {
    padding: 10px 20px;
    font-size: var(--font-size-sm);
  }

  .send-btn {
    padding: 12px 24px;
  }

  table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .theme-toggle {
    width: 44px;
    height: 44px;
    font-size: 18px;
  }
}

/* Larger screens (1200px and above) */
@media (min-width: 1200px) {
  .container-wide,
  .header,
  #chat,
  .input-area {
    max-width: 1100px;
  }
}

/* Print styles */
@media print {
  .header-actions,
  .input-area,
  .theme-toggle,
  .loading-indicator {
    display: none !important;
  }

  #chat {
    max-height: none;
    box-shadow: none;
    border: 1px solid #ddd;
  }

  .msg {
    page-break-inside: avoid;
  }
}

/* =================================================================
   ACCESSIBILITY ENHANCEMENTS
   ================================================================= */

/* Focus visible for keyboard navigation */
*:focus-visible {
  outline: 2px solid var(--nhs-blue);
  outline-offset: 2px;
}

[data-theme="dark"] *:focus-visible {
  outline-color: var(--nhs-light-blue);
}

/* Screen reader only */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* Reduced motion for users who prefer it */
@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;
  }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  button, .button, .btn {
    border-width: 3px;
  }

  input, textarea, select {
    border-width: 3px;
  }
}
