:root {
  --bg-primary: #0b1120;
  --bg-secondary: #131c31;
  --bg-card: rgba(23, 33, 56, 0.75);
  --bg-card-hover: rgba(30, 43, 73, 0.85);
  --border-color: rgba(255, 255, 255, 0.08);
  --border-highlight: rgba(56, 189, 248, 0.3);
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --accent-primary: #3b82f6;
  --accent-hover: #2563eb;
  --accent-cyan: #06b6d4;
  --accent-rose: #f43f5e;
  --accent-amber: #f59e0b;
  --accent-emerald: #10b981;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
  height: 100dvh;
  width: 100%;
  overflow-x: hidden;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  -webkit-text-size-adjust: 100%;
}

/* APP CONTAINER */
.app-container {
  display: flex;
  flex-direction: column;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  width: 100%;
}

/* LOGIN OVERLAY */
.login-overlay {
  position: fixed;
  inset: 0;
  background: rgba(11, 17, 32, 0.95);
  backdrop-filter: blur(12px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 16px;
}

.login-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 28px 24px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.7);
}

.login-header {
  text-align: center;
  margin-bottom: 24px;
}

.shield-icon {
  font-size: 40px;
  margin-bottom: 10px;
}

.login-header h2 {
  font-size: 22px;
  color: var(--text-primary);
  margin-bottom: 6px;
  font-weight: 700;
}

.login-header p {
  font-size: 13px;
  color: var(--text-secondary);
}

.form-group {
  margin-bottom: 18px;
}

.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.form-group input {
  width: 100%;
  height: 48px;
  padding: 0 16px;
  background: rgba(11, 17, 32, 0.7);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  color: white;
  font-size: 16px; /* Prevents auto-zoom on iOS */
  outline: none;
  transition: all 0.2s;
}

.form-group input:focus {
  border-color: var(--accent-cyan);
  box-shadow: 0 0 0 3px rgba(6, 182, 212, 0.2);
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-cyan));
  color: white;
  border: none;
  height: 48px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
  transition: opacity 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-primary:active {
  opacity: 0.85;
}

.btn-block {
  width: 100%;
}

.error-msg {
  background: rgba(244, 63, 94, 0.15);
  border: 1px solid var(--accent-rose);
  color: #fda4af;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 16px;
}

.login-footer {
  text-align: center;
  margin-top: 20px;
  font-size: 11px;
  color: var(--text-muted);
}

/* NAVBAR */
.navbar {
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  padding: 10px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
  z-index: 40;
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-avatar {
  width: 36px;
  height: 36px;
  min-width: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, #ec4899, #8b5cf6);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
  color: white;
  box-shadow: 0 2px 8px rgba(236, 72, 153, 0.3);
}

.brand-meta {
  min-width: 0;
}

.brand-title {
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand-subtitle {
  font-size: 10px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.btn-download {
  background: rgba(59, 130, 246, 0.15);
  border: 1px solid rgba(59, 130, 246, 0.4);
  color: #60a5fa;
  text-decoration: none;
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 4px;
}

.user-badge {
  background: rgba(16, 185, 129, 0.15);
  color: var(--accent-emerald);
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  max-width: 100px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
}

/* HORIZONTAL SCROLLABLE TABS */
.nav-tabs {
  background: rgba(19, 28, 49, 0.95);
  border-bottom: 1px solid var(--border-color);
  padding: 0 12px;
  display: flex;
  gap: 4px;
  flex-shrink: 0;
  overflow-x: auto;
  white-space: nowrap;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.nav-tabs::-webkit-scrollbar {
  display: none;
}

.tab-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.tab-btn.active {
  color: var(--accent-cyan);
  border-bottom-color: var(--accent-cyan);
  font-weight: 600;
}

/* MAIN CONTENT */
.main-content {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  width: 100%;
}

.tab-pane {
  display: none;
  height: 100%;
  width: 100%;
  min-height: 0;
}

.tab-pane.active {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* CHAT SECTION */
#tab-chat {
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

.mobile-context-bar {
  display: none;
  padding: 6px 14px;
  background: rgba(19, 28, 49, 0.6);
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}

.btn-toggle-info {
  width: 100%;
  background: rgba(59, 130, 246, 0.1);
  border: 1px solid rgba(59, 130, 246, 0.3);
  color: #93c5fd;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
}

.chat-layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 16px;
  height: 100%;
  overflow: hidden;
  padding: 16px 20px;
  max-width: 1240px;
  margin: 0 auto;
  width: 100%;
}

.chat-main {
  flex: 1;
  min-height: 0;
  background: #131c2e;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  position: relative;
}

.chat-messages {
  flex: 1;
  min-height: 0;
  padding: 16px 20px;
  overflow-y: scroll;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chat-messages::-webkit-scrollbar,
#tab-domino::-webkit-scrollbar,
#tab-journal::-webkit-scrollbar,
.chat-sidebar::-webkit-scrollbar {
  width: 6px;
}

.chat-messages::-webkit-scrollbar-track,
#tab-domino::-webkit-scrollbar-track,
#tab-journal::-webkit-scrollbar-track,
.chat-sidebar::-webkit-scrollbar-track {
  background: rgba(15, 23, 42, 0.3);
}

.chat-messages::-webkit-scrollbar-thumb,
#tab-domino::-webkit-scrollbar-thumb,
#tab-journal::-webkit-scrollbar-thumb,
.chat-sidebar::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.3);
  border-radius: 4px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
  background: rgba(148, 163, 184, 0.6);
}


.msg {
  display: flex;
  flex-direction: column;
  max-width: 85%;
  animation: fadeIn 0.2s ease-out;
}

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

.msg.user {
  align-self: flex-end;
}

.msg.assistant {
  align-self: flex-start;
}

.msg-bubble {
  padding: 12px 16px;
  border-radius: 12px;
  font-size: 14.5px;
  line-height: 1.5;
  word-break: break-word;
}

.msg.user .msg-bubble {
  background: #2563eb;
  color: #ffffff;
  border-bottom-right-radius: 3px;
}

.msg.assistant .msg-bubble {
  background: #1c2638;
  color: #f1f5f9;
  border-bottom-left-radius: 3px;
  border: 1px solid rgba(255, 255, 255, 0.07);
}

/* CHAT OPTIONS & MODEL BAR */
.chat-options-bar {
  padding: 6px 14px;
  background: #101726;
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  font-size: 12px;
}

.study-toggle-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  user-select: none;
  color: var(--text-secondary);
  font-size: 12px;
}

.study-toggle-label input[type="checkbox"] {
  accent-color: #3b82f6;
  cursor: pointer;
  width: 14px;
  height: 14px;
}

.study-badge {
  color: #94a3b8;
  font-weight: 500;
}


/* CHAT INPUT BAR */
.chat-input-bar {
  padding: 10px 14px;
  background: rgba(15, 23, 42, 0.95);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border-color);
  display: flex;
  gap: 10px;
  align-items: center;
  flex-shrink: 0;
}

.chat-input-bar input {
  flex: 1;
  height: 46px;
  background: rgba(30, 41, 59, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.12);
  padding: 0 16px;
  border-radius: 23px;
  color: white;
  font-size: 16px; /* Strict 16px to prevent iOS auto-zoom */
  outline: none;
  transition: all 0.2s;
}

.chat-input-bar input:focus {
  border-color: var(--accent-cyan);
  box-shadow: 0 0 0 3px rgba(6, 182, 212, 0.15);
}

.btn-send {
  height: 46px;
  min-width: 46px;
  background: linear-gradient(135deg, var(--accent-cyan), var(--accent-primary));
  border: none;
  color: white;
  padding: 0 18px;
  border-radius: 23px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  flex-shrink: 0;
  box-shadow: 0 2px 10px rgba(6, 182, 212, 0.3);
}

.btn-send:active {
  transform: scale(0.96);
}

/* SIDEBAR */
.chat-sidebar {
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.sidebar-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 16px;
}

.sidebar-card h3 {
  font-size: 13px;
  margin-bottom: 12px;
  color: var(--accent-cyan);
  display: flex;
  align-items: center;
  gap: 6px;
}

.fact-list {
  list-style: none;
  font-size: 12px;
  line-height: 1.8;
}

.fact-list li strong {
  color: var(--text-secondary);
}

.context-list {
  font-size: 12px;
  color: var(--text-secondary);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.context-item {
  background: rgba(11, 17, 32, 0.7);
  padding: 10px 12px;
  border-radius: 8px;
  border-left: 3px solid var(--accent-cyan);
  font-size: 12px;
}

.context-date {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.context-cat {
  color: var(--text-primary);
  font-weight: 500;
}

/* TYPING INDICATOR */
.typing-indicator {
  display: flex;
  gap: 4px;
  padding: 4px 0;
}

.typing-indicator span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent-cyan);
  animation: bounce 1.2s infinite ease-in-out;
}

.typing-indicator span:nth-child(1) { animation-delay: -0.32s; }
.typing-indicator span:nth-child(2) { animation-delay: -0.16s; }

@keyframes bounce {
  0%, 80%, 100% { transform: scale(0); opacity: 0.3; }
  40% { transform: scale(1); opacity: 1; }
}

/* DOMINO TAB & JOURNAL TAB */
#tab-domino, #tab-journal {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 20px 16px 40px 16px;
  max-width: 1200px;
  margin: 0 auto;
}

.domino-header {
  margin-bottom: 20px;
}

.domino-header h2 {
  font-size: 20px;
  margin-bottom: 6px;
}

.domino-header p {
  color: var(--text-secondary);
  font-size: 13px;
}

.domino-cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 16px;
}

.domino-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 18px;
  position: relative;
  transition: transform 0.2s, border-color 0.2s;
}

.card-step {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 26px;
  height: 26px;
  background: var(--accent-primary);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: white;
}

.domino-card h3 {
  font-size: 15px;
  margin-bottom: 8px;
  color: var(--accent-cyan);
  padding-right: 32px;
}

.domino-card p {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.55;
  margin-bottom: 12px;
}

.tag {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
}

.tag-trigger {
  background: rgba(245, 158, 11, 0.15);
  color: var(--accent-amber);
}

.tag-symptom {
  background: rgba(244, 63, 94, 0.15);
  color: #fb7185;
}

/* SYNCHRONIZED OBSERVATIONS */
.obs-list-grid {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: 14px;
}

.synced-card {
  background: rgba(23, 33, 56, 0.85);
  border: 1px solid rgba(6, 182, 212, 0.3);
  border-left: 4px solid var(--accent-cyan);
  border-radius: 10px;
  padding: 16px;
}

.synced-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  flex-wrap: wrap;
  gap: 6px;
}

.synced-date {
  font-size: 12px;
  color: var(--text-muted);
}

.synced-user-msg {
  font-size: 14px;
  color: var(--accent-cyan);
  margin-bottom: 10px;
  background: rgba(11, 17, 32, 0.6);
  padding: 10px 14px;
  border-radius: 8px;
  line-height: 1.45;
}

.synced-analysis {
  font-size: 13px;
  color: var(--text-primary);
  line-height: 1.55;
}

.empty-state {
  padding: 28px 16px;
  text-align: center;
  color: var(--text-muted);
  background: var(--bg-card);
  border: 1px dashed var(--border-color);
  border-radius: 10px;
  font-size: 13px;
  line-height: 1.5;
}

/* JOURNAL TAB */
.journal-controls {
  margin-bottom: 16px;
}

.journal-controls input {
  width: 100%;
  height: 48px;
  padding: 0 16px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  color: white;
  font-size: 16px; /* Prevents auto-zoom on iOS */
  outline: none;
}

.journal-controls input:focus {
  border-color: var(--accent-cyan);
}

.journal-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.journal-item {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 16px;
}

.journal-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 10px;
  gap: 8px;
  flex-wrap: wrap;
}

.journal-date {
  font-size: 12px;
  font-weight: 700;
  color: var(--accent-cyan);
  margin-right: 8px;
}

.journal-clinic {
  font-size: 12px;
  color: var(--text-secondary);
}

.journal-doctor {
  font-size: 12px;
  color: var(--text-muted);
}

.journal-content {
  font-size: 13px;
  color: var(--text-primary);
  white-space: pre-wrap;
  line-height: 1.5;
}

/* MARKDOWN IN CHAT (Tight, elegant spacing) */
.md-p {
  margin: 0 0 6px 0;
  line-height: 1.5;
}

.md-p:last-child {
  margin-bottom: 0;
}

.md-h4 {
  font-size: 14px;
  color: #60a5fa;
  margin: 10px 0 4px 0;
  font-weight: 600;
}

.md-h3 {
  font-size: 15px;
  color: #f1f5f9;
  margin: 12px 0 6px 0;
  font-weight: 600;
}

.md-ul {
  margin: 4px 0 8px 18px;
  padding: 0;
}

.md-li {
  margin-bottom: 3px;
  line-height: 1.45;
  list-style-type: disc;
}


/* ==============================================================
   MOBILE RESPONSIVENESS OVERHAUL (Native App Experience)
   ============================================================== */
@media (max-width: 900px) {
  /* Remove outer margins so chat takes 100% of the screen */
  .chat-layout {
    display: flex;
    flex-direction: column;
    padding: 0;
    gap: 0;
    height: 100%;
    max-width: 100%;
  }

  .chat-main {
    border-radius: 0;
    border: none;
    border-top: 1px solid var(--border-color);
  }

  .quick-prompts {
    overflow-x: auto;
    flex-wrap: nowrap;
    padding-bottom: 4px;
    -webkit-overflow-scrolling: touch;
  }

  .prompt-chip {
    white-space: nowrap;
    flex-shrink: 0;
  }

  /* Show toggle bar for patient facts */
  .mobile-context-bar {
    display: block;
  }

  /* Sidebar becomes a collapsible drawer on mobile */
  .chat-sidebar {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 100;
    background: rgba(11, 17, 32, 0.98);
    backdrop-filter: blur(16px);
    padding: 20px 16px;
    overflow-y: auto;
  }

  .chat-sidebar.mobile-open {
    display: flex;
    animation: slideUp 0.25s ease-out;
  }

  @keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
  }

  /* Message bubbles take up more screen on mobile */
  .msg {
    max-width: 92%;
  }

  .msg-bubble {
    font-size: 15px;
    line-height: 1.6;
    padding: 12px 16px;
  }

  /* Sticky input bar with safe area padding for iPhone notch/home bar */
  .chat-input-bar {
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom, 0px)) 10px;
  }

  .chat-input-bar input {
    height: 44px;
    font-size: 16px;
    padding: 0 14px;
  }

  .btn-send {
    height: 44px;
    padding: 0 14px;
  }
}

@media (max-width: 768px) {
  /* Native App Bottom Tab Bar */
  .nav-tabs {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 99;
    background: rgba(15, 23, 42, 0.98);
    backdrop-filter: blur(20px);
    border-top: 1px solid rgba(255, 255, 255, 0.12);
    display: flex;
    justify-content: space-around;
    padding: 6px 0 calc(6px + env(safe-area-inset-bottom, 0px)) 0;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.5);
  }

  .tab-btn {
    flex-direction: column;
    gap: 2px;
    font-size: 11px;
    padding: 4px 10px;
    border-bottom: none;
    border-radius: 8px;
  }

  .tab-btn.active {
    background: rgba(56, 189, 248, 0.12);
    border-bottom: none;
  }

  .tab-icon {
    font-size: 18px;
  }

  /* Make room for fixed bottom tabs */
  .main-content {
    padding-bottom: calc(56px + env(safe-area-inset-bottom, 0px));
  }

  .navbar {
    padding: 8px 14px;
  }

  .brand-title {
    font-size: 14px;
  }

  .brand-subtitle {
    display: none;
  }

  .btn-download-text {
    display: none;
  }

  .btn-send-text {
    display: none;
  }

  .btn-send {
    width: 44px;
    min-width: 44px;
    padding: 0;
    border-radius: 50%;
  }

  .user-badge {
    display: none;
  }

  .domino-cards-grid {
    grid-template-columns: 1fr;
  }

  #tab-domino, #tab-journal {
    padding: 14px 12px calc(70px + env(safe-area-inset-bottom, 0px)) 12px;
  }
}

