/* Import Fonts */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');
@import url(https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css);

/* --- MODERN WEB THEME VARIABLES --- */
:root {
  --primary-color: #4F46E5; /* Vibrant Indigo */
  --accent-color: #10B981; /* Vibrant Emerald */
  --secondary-color: #6b7280; /* Gray */
  --background-color: #f3f4f6; /* Lighter gray */
  --surface-color: #ffffff;
  --text-color: #1f2937;
  --muted-text-color: #6b7280;
  --border-color: #e5e7eb;
  --danger-color: #ef4444;
  --warning-color: #f97316; /* Orange for moderate severity */
  --success-color: #22c55e;
  --font-family: 'Inter', sans-serif;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  --border-radius: 0.5rem; /* 8px for a "rounded square" look */
}

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

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

@keyframes pulse {
  0%, 100% { 
    transform: scale(1);
    opacity: 1;
  }
  50% { 
    transform: scale(1.05);
    opacity: 0.7; 
  }
}


@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

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

html, body {
  height: 100%;
}

/* Scoped body styles for the application view */
body.app-active {
  font-family: var(--font-family);
  background-color: var(--background-color);
  color: var(--text-color);
  /* Removed padding rule that was causing overlap with the fixed header */
}

/* --- APP CONTAINER --- */
#app {
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
  background-color: var(--surface-color);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--border-color);
}

/* --- HEADER --- */
.triage-header {
  text-align: center;
  padding: 2rem 1.5rem;
  background-color: var(--surface-color);
  color: var(--text-color);
  border-bottom: 1px solid var(--border-color);
}

.triage-header h1 {
  font-size: 1.875rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
}

.triage-header p {
  font-size: 1rem;
  opacity: 1;
  color: var(--muted-text-color);
  font-weight: 400;
}

/* --- MAIN CONTENT AREA --- */
.triage-content {
  flex-grow: 1;
  padding: 2.5rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  animation: fadeIn 0.4s ease-out;
}

.welcome-screen {
  justify-content: center;
}

.welcome-visual {
    margin-bottom: 2rem;
}

.welcome-screen p, .drug-input-form p {
  font-size: 1.125rem;
  max-width: 600px;
  margin-bottom: 2.5rem;
  line-height: 1.7;
  color: var(--muted-text-color);
}

.drug-input-form p {
    font-size: 1rem;
    margin-bottom: 1rem;
}

/* --- BUTTONS --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  font-size: 1rem;
  font-weight: 700;
  padding: 1rem 2.25rem;
  border-radius: var(--border-radius);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.2s ease-in-out;
  text-align: center;
  text-decoration: none;
}

.btn:disabled {
    background-color: var(--border-color);
    color: var(--muted-text-color);
    cursor: not-allowed;
}
.btn:disabled:hover {
    background-color: var(--border-color);
}


.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background-color: var(--primary-color);
  color: #fff;
}
.btn-primary:hover {
  background-color: #4338CA;
}

.btn-accent {
  background-color: var(--accent-color);
  color: #fff;
}
.btn-accent:hover {
  background-color: #059669;
}

.btn-secondary {
  background-color: var(--surface-color);
  border-color: var(--border-color);
  color: var(--text-color);
}
.btn-secondary:hover {
  background-color: #f3f4f6;
}

.symptom-btn {
  background-color: var(--surface-color);
  color: var(--text-color);
  border: 1px solid var(--border-color);
  width: 100%;
}
.symptom-btn:hover {
  background-color: #f1f3f5;
  border-color: var(--primary-color);
  color: var(--primary-color);
}

/* --- ACTION BUTTON CONTAINERS --- */
.welcome-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 1rem;
    width: 100%;
    margin-bottom: 1.5rem;
}

.result-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    width: 100%;
    gap: 1rem;
    margin-top: 1.5rem;
}

/* --- FORMS & INPUTS --- */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-bottom: 1rem;
  width: 100%;
  text-align: left;
}

.form-group-with-autocomplete {
  position: relative;
  z-index: 5; /* Needs to be higher than siblings to allow dropdown to show over them */
  width: 100%;
  max-width: 500px;
}

.form-group label {
  font-weight: 500;
  color: var(--muted-text-color);
  font-size: 0.85rem;
  margin-left: 0.1rem;
}

.form-input {
  width: 100%;
  padding: 0.75rem 1rem;
  font-size: 1rem;
  font-family: var(--font-family);
  border-radius: var(--border-radius);
  border: 1px solid var(--border-color);
  transition: border-color 0.2s, box-shadow 0.2s;
  background-color: var(--surface-color);
  color: var(--text-color);
}
.form-input::placeholder {
  color: #9ca3af;
}
.form-input:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.25);
}

.symptom-search-container {
  width: 100%;
  margin-bottom: 1.5rem;
  position: relative; /* Crucial for autocomplete and mic button positioning */
}

#symptom-search-input {
    padding-right: 3.5rem; /* Space for the mic button */
}

.mic-btn {
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    cursor: pointer;
    color: var(--muted-text-color);
    font-size: 1.25rem;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s, background-color 0.2s;
}
.mic-btn:hover {
    color: var(--primary-color);
    background-color: #eef2ff; /* A light primary color tint */
}
.mic-btn.recording {
    color: var(--danger-color);
    animation: pulse 1.5s ease-in-out infinite;
}
.mic-btn.recording:hover {
    background-color: #fee2e2;
}

/* --- AUTOCOMPLETE LIST --- */
.autocomplete-container {
    position: relative;
}
.autocomplete-list {
  position: absolute;
  top: 100%; /* Position right below the input */
  left: 0;
  right: 0;
  z-index: 1000;
  background-color: var(--surface-color);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  max-height: 180px;
  overflow-y: auto;
  text-align: left;
  display: none;
  box-shadow: var(--shadow);
  margin-top: 4px; /* Small gap from input */
}
.autocomplete-item {
  padding: 0.75rem 1rem;
  cursor: pointer;
  font-size: 0.9rem;
  transition: background-color 0.15s ease;
}
.autocomplete-item:hover {
  background-color: #f1f3f5;
  color: var(--primary-color);
}
.autocomplete-item:not(:last-child) {
  border-bottom: 1px solid #f1f3f5;
}
.add-symptom {
  color: var(--primary-color);
  font-style: italic;
}

/* --- LAB INPUT FORM --- */
.lab-input-form {
  width: 100%;
}
.form-divider {
  width: 100%;
  border: 0;
  border-top: 1px solid var(--border-color);
  margin: 1.5rem 0;
}
.lab-entry-row {
  display: flex;
  gap: 0.75rem;
  align-items: flex-end;
  margin-bottom: 0.75rem;
}
.lab-entry-row > .form-group {
  flex-grow: 1;
  margin-bottom: 0;
}
.remove-btn {
  background-color: #f8f9fa;
  border: 1px solid var(--border-color);
  color: var(--danger-color);
  cursor: pointer;
  border-radius: 50%;
  width: 36px;
  height: 36px;
  font-weight: 400;
  font-size: 1.5rem;
  line-height: 1;
  text-align: center;
  flex-shrink: 0;
  transition: all 0.2s ease;
}
.remove-btn:hover {
  background-color: var(--danger-color);
  color: #fff;
  border-color: var(--danger-color);
}
.btn-add-entry {
  background: none;
  border: 1px dashed var(--border-color);
  color: var(--muted-text-color);
  padding: 0.6rem;
  margin: 0.5rem 0 1.5rem 0;
  font-size: 0.9rem;
  width: 100%;
}
.btn-add-entry:hover {
  border-color: var(--primary-color);
  color: var(--primary-color);
}

.form-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    width: 100%;
    gap: 1rem;
    margin-top: 1.5rem;
}


/* --- DRUG INTERACTION FLOW --- */
.drug-input-form {
    width: 100%;
    max-width: 500px;
    display: flex;
    flex-direction: column;
    align-items: center;
}
.drug-input-wrapper {
    display: flex;
    gap: 0.5rem;
    width: 100%;
    align-items: center;
}
.drug-input-wrapper .form-input {
    flex-grow: 1;
    height: 42px; /* Match default input height */
}
.drug-input-wrapper .btn {
    padding: 1rem;
    min-width: 46px; 
    font-size: 1.5rem;
    line-height: 1;
    height: 42px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.drug-list-container {
    width: 100%;
    margin-top: 1.5rem;
    padding: 1rem;
    min-height: 80px;
    background-color: var(--background-color);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-content: flex-start;
}
.drug-tag {
    background-color: var(--surface-color);
    border: 1px solid var(--border-color);
    color: var(--primary-color);
    padding: 0.5rem 0.5rem 0.5rem 1rem;
    border-radius: 99px;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 500;
}
.remove-drug-btn {
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    cursor: pointer;
    font-size: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    transition: background-color 0.2s ease;
}
.remove-drug-btn:hover {
    background-color: #4338CA;
}
.interaction-card {
    border-left-width: 5px;
}
.interaction-card.severity-ciddi {
    border-left-color: var(--danger-color);
}
.interaction-card.severity-orta {
    border-left-color: var(--warning-color);
}
.interaction-card.severity-hafif {
    border-left-color: var(--primary-color);
}
.interaction-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 1.1rem !important;
}
.severity-badge {
    display: inline-block;
    padding: 0.25rem 0.7rem;
    border-radius: 99px;
    font-size: 0.8rem;
    font-weight: 600;
    color: white;
}
.interaction-card.severity-ciddi .severity-badge { background-color: var(--danger-color); }
.interaction-card.severity-orta .severity-badge { background-color: var(--warning-color); }
.interaction-card.severity-hafif .severity-badge { background-color: var(--primary-color); }



/* --- OTHER UI ELEMENTS --- */
.separator-text {
  font-size: 0.85rem;
  color: var(--muted-text-color);
  margin: 1.5rem 0;
}
.symptom-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 1rem;
  width: 100%;
}
.question-container h2 {
  font-size: 1.375rem;
  font-weight: 500;
  margin-bottom: 2rem;
  line-height: 1.5;
}
.question-options {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.city-input-container {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  max-width: 400px;
}
.city-input-wrapper {
    position: relative;
    width: 100%;
}
#city-autocomplete-list {
    z-index: 1001; /* Ensure it's above other elements */
}

.loader {
  border: 4px solid #e9ecef;
  border-top: 4px solid var(--primary-color);
  border-radius: 50%;
  width: 40px;
  height: 40px;
  animation: spin 1s linear infinite;
  margin-bottom: 1rem;
}
.loading-text {
  font-size: 1rem;
  color: var(--muted-text-color);
}
.loading-tip {
    margin-top: 1.5rem;
    font-style: italic;
    color: var(--muted-text-color);
    font-size: 0.9rem;
    max-width: 400px;
    transition: opacity 0.3s ease-in-out;
}
.results-container {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
    width: 100%;
    text-align: left;
}
.history-container {
  width: 100%;
  text-align: left;
}
.result-card {
  background: var(--surface-color);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  padding: 1.5rem;
  margin-bottom: 1rem;
  width: 100%;
}
.result-card h3 {
  font-size: 1rem;
  color: var(--text-color);
  margin-bottom: 0.5rem;
  display: flex;
  align-items: center;
  font-weight: 600;
}
.result-card h3 i {
  margin-right: 0.75rem;
  width: 20px;
  text-align: center;
  color: var(--primary-color);
}
.result-card p, .result-card ul {
  font-size: 0.95rem;
  line-height: 1.6;
  color: var(--muted-text-color);
}
.result-card ul {
  list-style-position: inside;
  padding-left: 0.25rem;
}
.disclaimer {
  font-size: 0.8rem;
  color: var(--muted-text-color);
  margin-top: 1.5rem;
  padding: 1rem;
  background-color: var(--background-color);
  border-radius: var(--border-radius);
  width: 100%;
  border: 1px solid var(--border-color);
  text-align: left;
}
.history-list {
  list-style: none;
  width: 100%;
  margin-bottom: 1.5rem;
}
.history-list li {
  background: var(--surface-color);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  padding: 1.25rem;
  margin-bottom: 0.75rem;
  line-height: 1.5;
  font-size: 1rem;
}
.history-list li strong {
  color: var(--text-color);
  display: block;
  margin-bottom: 0.25rem;
  font-weight: 600;
}
.answer-pill {
  display: inline-block;
  padding: 0.25rem 0.7rem;
  border-radius: 99px;
  background-color: #e0e7ff;
  color: #4338ca;
  font-size: 0.85rem;
  font-weight: 500;
  margin-top: 0.5rem;
}
.animated-item {
  opacity: 0;
  animation: slideUpFadeIn 0.5s cubic-bezier(0.25, 1, 0.5, 1) forwards;
  animation-delay: var(--animation-delay, 0s);
}

/* --- TOOLTIP STYLES --- */
.tooltip-trigger {
  border-bottom: 1px dotted var(--muted-text-color);
  cursor: help;
  position: relative;
  display: inline-block;
}

.tooltip-trigger::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: 125%;
  left: 50%;
  transform: translateX(-50%);
  background-color: var(--primary-color);
  color: #fff;
  padding: 0.5rem 0.8rem;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 400;
  line-height: 1.4;
  white-space: pre-wrap;
  width: max-content;
  max-width: 280px;
  text-align: left;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0.2s ease;
  z-index: 1001; /* Must be higher than other elements */
}

.tooltip-trigger::before {
  content: '';
  position: absolute;
  bottom: calc(125% - 5px);
  left: 50%;
  transform: translateX(-50%);
  border-width: 5px;
  border-style: solid;
  border-color: var(--primary-color) transparent transparent transparent;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0.2s ease;
  z-index: 1001;
}

.tooltip-trigger:hover::after,
.tooltip-trigger:hover::before {
  opacity: 1;
  visibility: visible;
}

/* --- HOSPITAL RESULTS --- */
.hospital-list-container {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
    width: 100%;
}
.hospital-card {
    background-color: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 1rem;
}
.hospital-card h4 {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-color);
}
.hospital-card-details {
    margin-bottom: 1rem;
}

.hospital-card-details p {
    font-size: 0.9rem;
    color: var(--muted-text-color);
    margin: 0.25rem 0;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.hospital-card-details i {
    width: 16px;
    text-align: center;
    color: var(--secondary-color);
}
.map-link-btn {
    margin-top: auto; /* Pushes the button to the bottom */
    padding: 0.6rem 1rem;
    font-size: 0.9rem;
    align-self: flex-start;
}

/* --- PDF EXPORT STYLES --- */
#pdf-export-content {
    position: absolute;
    left: -9999px; /* Hide off-screen */
    top: auto;
    width: 800px;
    background: #fff;
    font-family: 'Inter', sans-serif;
    color: #1f2937;
    padding: 40px;
}
.pdf-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 2px solid #10B981;
    padding-bottom: 15px;
    margin-bottom: 30px;
}
.pdf-header h1 {
    font-size: 24px;
    color: #333;
    font-weight: 600;
}
.pdf-header span {
    font-size: 12px;
    color: #6b7280;
}
.pdf-section {
    margin-bottom: 30px;
}
.pdf-section h2 {
    font-size: 18px;
    font-weight: 600;
    color: #4F46E5;
    margin-bottom: 15px;
    border-bottom: 1px solid #e5e7eb;
    padding-bottom: 8px;
}
.pdf-history-list {
    list-style: none;
    padding: 0;
}
.pdf-history-list li {
    font-size: 14px;
    line-height: 1.6;
    margin-bottom: 10px;
}
.pdf-history-list li strong {
    font-weight: 600;
    color: #1f2937;
}
.pdf-result p {
    font-size: 14px;
    line-height: 1.6;
    margin-bottom: 10px;
}
.pdf-result strong {
    font-weight: 600;
}
.pdf-hospitals {
    padding: 0;
    list-style: none;
}
.pdf-hospital-card {
    border-top: 1px solid #e5e7eb;
    padding-top: 10px;
    margin-top: 10px;
}
.pdf-hospital-card h4 {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 5px;
}
.pdf-hospital-card p {
    font-size: 13px;
    color: #6b7280;
    margin: 2px 0;
}
.pdf-disclaimer {
    margin-top: 30px;
    padding: 15px;
    background-color: #f3f4f6;
    border-left: 4px solid #6b7280;
    font-size: 12px;
    color: #6b7280;
    line-height: 1.5;
}

/* --- MAP MODAL STYLES --- */
.map-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 2000;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 1rem;
}
.map-modal-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(31, 41, 55, 0.7);
  cursor: pointer;
  animation: fadeIn 0.3s ease;
}
.map-modal-content {
  position: relative;
  background-color: var(--surface-color);
  width: 100%;
  max-width: 900px;
  height: 90%;
  max-height: 700px;
  border-radius: var(--border-radius);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  padding: 1.5rem;
  animation: slideUpFadeIn 0.3s ease-out;
}
.map-modal-close {
  position: absolute;
  top: 10px;
  right: 15px;
  background: none;
  border: none;
  font-size: 2.5rem;
  color: var(--muted-text-color);
  cursor: pointer;
  line-height: 1;
  padding: 0;
  z-index: 10;
}
.map-modal-close:hover {
    color: var(--text-color);
}
#map-modal-title {
    font-size: 1.25rem;
    margin-bottom: 1rem;
    color: var(--text-color);
    padding-right: 30px; /* space for close button */
    font-weight: 600;
}
.map-iframe {
  flex-grow: 1;
  width: 100%;
  height: 100%;
  border-radius: calc(var(--border-radius) - 4px);
  border: 1px solid var(--border-color);
}


/* --- RESPONSIVENESS --- */
@media (min-width: 768px) {
    .results-container {
        grid-template-columns: repeat(2, 1fr);
    }
    .results-container > .card-full-width,
    .results-container > .result-actions,
    .results-container > .disclaimer,
    .results-container > .interaction-card {
        grid-column: span 2;
    }
}

@media (max-width: 600px) {
  body.app-active {
    padding: 0;
  }
  #app {
    border-radius: 0;
    border: none;
    box-shadow: none;
    max-width: 100%;
    min-height: 100vh;
    height: 100%;
  }
  .triage-content {
    padding: 1.5rem;
    flex-grow: 1;
  }
  .triage-header {
    padding: 1.5rem 1rem;
  }
  .triage-header h1 {
    font-size: 1.5rem;
  }
  .welcome-actions,
  .result-actions,
  .form-actions {
    flex-direction: column;
  }
  .welcome-actions .btn,
  .result-actions .btn,
  .form-actions .btn {
    width: 100%;
  }
  .form-actions {
    justify-content: center;
  }
}