/* ===== CSS Variables & Theme ===== */
:root {
  --background: hsl(0 0% 98%);
  --foreground: hsl(0 0% 12%);
  --card: hsl(0 0% 100%);
  --card-foreground: hsl(0 0% 12%);
  --primary: hsl(152 44% 45%);
  --primary-hover: hsl(152 44% 38%);
  --secondary: hsl(152 20% 42%);
  --muted: hsl(0 0% 94%);
  --muted-foreground: hsl(0 0% 45%);
  --border: hsl(0 0% 89%);
  --destructive: hsl(0 84% 60%);
  --radius: 0.75rem;
  --glass-bg: rgba(255,255,255,0.7);
  --glass-border: rgba(0,0,0,0.08);
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-lg: 0 10px 25px rgba(0,0,0,0.08);
  --user-bubble: hsl(152 44% 45%);
  --user-bubble-text: #fff;
  --assistant-bubble: hsl(0 0% 94%);
  --assistant-bubble-text: hsl(0 0% 12%);
}

/* Dark mode disabled — always light theme */

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

html { font-size: 16px; scroll-behavior: smooth; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--background);
  color: var(--foreground);
  min-height: 100vh;
  line-height: 1.5;
}

/* ===== Header ===== */
.site-header {
  background: var(--glass-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--glass-border);
  padding: 1rem 1.5rem;
  position: sticky;
  top: 0;
  z-index: 100;
}

.site-header h1 {
  font-size: 1.5rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.site-header h1 span.wizard-hat { font-size: 1.6rem; }

/* ===== Main Layout ===== */
.main-container {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.25rem;
  padding: 1.25rem;
  max-width: 1600px;
  margin: 0 auto;
  height: calc(100vh - 65px);
}

@media (min-width: 1024px) {
  .main-container {
    grid-template-columns: 1fr 1fr;
  }
}

/* ===== Glass Card ===== */
.glass-card {
  background: var(--glass-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

.card-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.card-header h2 {
  font-size: 1.1rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.card-header .icon {
  width: 20px;
  height: 20px;
  opacity: 0.6;
}

/* ===== Form Panel ===== */
.form-body {
  padding: 1.25rem;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

.form-section {
  margin-bottom: 1.5rem;
}

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

.form-section-title {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted-foreground);
  margin-bottom: 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}

.form-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.form-row.two-col { grid-template-columns: 1fr 1fr; }
.form-row.three-col { grid-template-columns: 1fr 1fr 1fr; }

@media (max-width: 600px) {
  .form-row.two-col, .form-row.three-col { grid-template-columns: 1fr; }
}

.form-group { display: flex; flex-direction: column; gap: 0.3rem; }

.form-group label {
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--card-foreground);
}

.form-group label .required { color: var(--destructive); margin-left: 2px; }

input[type="text"],
input[type="number"],
input[type="date"],
input[type="email"],
select,
textarea {
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) - 4px);
  background: var(--card);
  color: var(--card-foreground);
  font-size: 0.9rem;
  font-family: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
  width: 100%;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px hsla(152, 44%, 45%, 0.15);
}

textarea { resize: vertical; min-height: 60px; }

/* Radio & Checkbox Groups */
.radio-group, .checkbox-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 0.25rem;
}

.radio-group label, .checkbox-group label {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.88rem;
  font-weight: 400;
  cursor: pointer;
}

.radio-group input, .checkbox-group input { width: auto; }

/* Condition Groups */
.condition-group {
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.condition-group:last-child {
  border-bottom: none;
  margin-bottom: 0;
}

.condition-group-title {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 0.5rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.condition-group > .checkbox-group {
  margin-bottom: 0.5rem;
}

.condition-group-details {
  /* container for detail blocks within each group */
}

/* Heart Procedures */
.heart-procedure-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.4rem;
  flex-wrap: wrap;
}

.heart-procedure-item > label {
  font-size: 0.88rem;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  min-width: 160px;
  font-weight: 400;
  cursor: pointer;
}

.heart-procedure-item > label input { width: auto; }

.procedure-year {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.procedure-year label {
  font-size: 0.8rem;
  color: var(--muted-foreground);
  white-space: nowrap;
}

.procedure-year input {
  width: 85px;
  padding: 0.3rem 0.5rem;
  font-size: 0.85rem;
}

/* Condition detail blocks */
.condition-detail {
  background: var(--muted);
  border-radius: calc(var(--radius) - 4px);
  padding: 0.75rem;
  margin-top: 0.5rem;
  margin-bottom: 0.5rem;
}

.condition-detail h4 {
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
  color: var(--primary);
}

.condition-detail .form-row { margin-bottom: 0.5rem; }

/* Medication Chip UI */
.med-chips-container {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  min-height: 28px;
  margin-bottom: 0.4rem;
}

.med-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.2rem 0.55rem;
  background: var(--primary);
  color: #fff;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 500;
  line-height: 1.4;
  white-space: nowrap;
}

.med-chip-remove {
  background: none;
  border: none;
  color: rgba(255,255,255,0.8);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 0 0.1rem;
  margin-left: 0.1rem;
  font-weight: 700;
  transition: color 0.15s;
}

.med-chip-remove:hover {
  color: #fff;
}

.med-chip-select-wrapper {
  width: 100%;
}

.med-chip-select {
  width: 100%;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) - 4px);
  background: var(--card);
  color: var(--card-foreground);
  font-size: 0.9rem;
  font-family: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
  cursor: pointer;
}

.med-chip-select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px hsla(152, 44%, 45%, 0.15);
}

/* Condition sub-questions */
.sub-questions {
  margin-top: 0.6rem;
  padding-top: 0.5rem;
  border-top: 1px dashed var(--border);
}

/* Custom conditions section */
.custom-conditions-section {
  margin-top: 1rem;
}

.custom-conditions-separator {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
  margin-top: 0.5rem;
}

.custom-conditions-separator::before,
.custom-conditions-separator::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.custom-conditions-separator span {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted-foreground);
  white-space: nowrap;
}

.custom-condition-entry {
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
  margin-bottom: 0.5rem;
  flex-wrap: wrap;
}

.custom-condition-entry .form-group {
  flex: 1;
  min-width: 120px;
}

.btn-add-custom {
  margin-top: 0.5rem;
}

/* Legacy multi-select (hidden, replaced by chips) */
.med-select {
  min-height: 80px;
  max-height: 140px;
  display: none;
}

/* Repeating fields (surgery/hospitalization) */
.repeating-entry {
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
  margin-bottom: 0.5rem;
}

.repeating-entry .form-group { flex: 1; }

.btn-remove {
  padding: 0.55rem 0.6rem;
  background: var(--destructive);
  color: #fff;
  border: none;
  border-radius: calc(var(--radius) - 4px);
  cursor: pointer;
  font-size: 0.85rem;
  flex-shrink: 0;
}

.btn-add {
  padding: 0.4rem 0.75rem;
  background: transparent;
  color: var(--primary);
  border: 1px dashed var(--primary);
  border-radius: calc(var(--radius) - 4px);
  cursor: pointer;
  font-size: 0.82rem;
  margin-top: 0.25rem;
  transition: background 0.15s;
}

.btn-add:hover { background: hsla(152, 44%, 45%, 0.08); }

/* Submit Button */
.btn-submit {
  width: 100%;
  padding: 0.8rem;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  margin-top: 1rem;
}

.btn-submit:hover { background: var(--primary-hover); }
.btn-submit:active { transform: scale(0.99); }
.btn-submit:disabled { opacity: 0.6; cursor: not-allowed; }

/* ===== Chat Panel ===== */
.chat-panel { display: flex; flex-direction: column; min-height: 400px; }

.chat-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.chat-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 1.1rem;
  font-weight: 600;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--muted-foreground);
  flex-shrink: 0;
  transition: background 0.3s;
}

.status-dot.active {
  background: hsl(152, 70%, 50%);
  animation: pulse-dot 1.5s ease-in-out infinite;
}

@keyframes pulse-dot {
  0%, 100% { box-shadow: 0 0 0 0 hsla(152, 70%, 50%, 0.5); }
  50% { box-shadow: 0 0 0 6px hsla(152, 70%, 50%, 0); }
}

.btn-new-client {
  padding: 0.4rem 0.85rem;
  background: transparent;
  color: var(--foreground);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) - 2px);
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  transition: background 0.15s, border-color 0.15s;
}

.btn-new-client:hover {
  background: var(--muted);
  border-color: var(--muted-foreground);
}

.btn-new-client svg { width: 14px; height: 14px; }

/* Messages Area */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  min-height: 0;
}

.chat-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--muted-foreground);
  text-align: center;
  gap: 0.5rem;
}

.chat-empty .empty-icon { font-size: 2.5rem; opacity: 0.4; }
.chat-empty p { font-size: 0.9rem; }

.message {
  max-width: 85%;
  padding: 0.7rem 1rem;
  border-radius: var(--radius);
  font-size: 0.9rem;
  line-height: 1.6;
  word-wrap: break-word;
}

.message.user {
  align-self: flex-end;
  background: var(--user-bubble);
  color: var(--user-bubble-text);
  border-bottom-right-radius: 4px;
}

.message.assistant {
  align-self: flex-start;
  background: var(--assistant-bubble);
  color: var(--assistant-bubble-text);
  border-bottom-left-radius: 4px;
}

.message.assistant h1, .message.assistant h2, .message.assistant h3 {
  font-size: 1rem;
  font-weight: 700;
  margin: 0.6rem 0 0.3rem;
}

.message.assistant h1:first-child,
.message.assistant h2:first-child,
.message.assistant h3:first-child {
  margin-top: 0;
}

.message.assistant strong { font-weight: 700; }

.message.assistant ul, .message.assistant ol {
  padding-left: 1.3rem;
  margin: 0.3rem 0;
}

.message.assistant li { margin-bottom: 0.15rem; }

.message.assistant p { margin: 0.3rem 0; }
.message.assistant p:first-child { margin-top: 0; }
.message.assistant p:last-child { margin-bottom: 0; }

/* Loading bubble */
.message.loading {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--muted-foreground);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* Chat Input */
.chat-input-area {
  padding: 0.75rem 1.25rem;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 0.5rem;
  flex-shrink: 0;
}

.chat-input-area input {
  flex: 1;
  padding: 0.6rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) - 2px);
  background: var(--card);
  color: var(--card-foreground);
  font-size: 0.88rem;
  font-family: inherit;
}

.chat-input-area input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px hsla(152, 44%, 45%, 0.15);
}

.btn-send {
  padding: 0.6rem 0.85rem;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: calc(var(--radius) - 2px);
  cursor: pointer;
  font-size: 0.88rem;
  font-weight: 500;
  transition: background 0.15s;
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.btn-send:hover { background: var(--primary-hover); }
.btn-send:disabled { opacity: 0.5; cursor: not-allowed; }

/* ===== Toast ===== */
.toast-container {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.toast {
  background: var(--card);
  color: var(--card-foreground);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1.25rem;
  box-shadow: var(--shadow-lg);
  font-size: 0.88rem;
  animation: toast-in 0.3s ease-out;
  max-width: 360px;
}

.toast.toast-out { animation: toast-out 0.3s ease-in forwards; }

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

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

/* ===== Conditional visibility ===== */
.hidden { display: none !important; }

/* ===== Scrollbar ===== */
.form-body::-webkit-scrollbar,
.chat-messages::-webkit-scrollbar {
  width: 6px;
}

.form-body::-webkit-scrollbar-track,
.chat-messages::-webkit-scrollbar-track {
  background: transparent;
}

.form-body::-webkit-scrollbar-thumb,
.chat-messages::-webkit-scrollbar-thumb {
  background: var(--muted-foreground);
  border-radius: 3px;
}

/* ===== Responsive Mobile Fix ===== */
@media (max-width: 1023px) {
  .main-container {
    height: auto;
    min-height: calc(100vh - 65px);
  }
  .chat-panel { min-height: 500px; }
}
