* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html {
  font-size: 18px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: #f5f5f5;
  color: #333;
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-text-size-adjust: 100%;
}

.hidden { display: none !important; }

.screen { min-height: 100vh; min-height: 100dvh; }

.error {
  color: #d32f2f;
  font-size: 1rem;
  margin-top: 0.5rem;
}

/* ==========================================================
   AUTH SCREEN
   ========================================================== */
.auth-container {
  max-width: 440px;
  margin: 0 auto;
  padding: 3rem 1.25rem 2rem;
  text-align: center;
}

.auth-container h1 {
  font-size: 2rem;
  margin-bottom: 0.25rem;
}

.subtitle {
  color: #666;
  margin-bottom: 2rem;
  font-size: 1.05rem;
}

.auth-tabs {
  display: flex;
  margin-bottom: 1.5rem;
  border-radius: 12px;
  overflow: hidden;
  border: 2px solid #4a90d9;
}

.tab {
  flex: 1;
  padding: 1rem;
  border: none;
  background: #fff;
  color: #4a90d9;
  font-size: 1.1rem;
  font-weight: 600;
  cursor: pointer;
  min-height: 56px;
}

.tab.active {
  background: #4a90d9;
  color: #fff;
}

#auth-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

#auth-form input {
  padding: 1rem;
  border: 2px solid #ccc;
  border-radius: 12px;
  font-size: 1.1rem;
  min-height: 56px;
}

#auth-form input:focus {
  outline: none;
  border-color: #4a90d9;
  box-shadow: 0 0 0 3px rgba(74, 144, 217, 0.25);
}

.captcha-row {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.captcha-question {
  font-size: 1.1rem;
  font-weight: 600;
  color: #333;
  text-align: left;
}

.captcha-row input {
  padding: 1rem;
  border: 2px solid #ccc;
  border-radius: 12px;
  font-size: 1.1rem;
  min-height: 56px;
}

.captcha-row input:focus {
  outline: none;
  border-color: #4a90d9;
  box-shadow: 0 0 0 3px rgba(74, 144, 217, 0.25);
}

#auth-form button[type="submit"] {
  padding: 1rem;
  background: #4a90d9;
  color: #fff;
  border: none;
  border-radius: 12px;
  font-size: 1.2rem;
  font-weight: 600;
  cursor: pointer;
  min-height: 60px;
}

#auth-form button[type="submit"]:hover {
  background: #3a7bc8;
}

#auth-form button[type="submit"]:active {
  background: #2e6ab5;
  transform: scale(0.98);
}

/* ==========================================================
   HEADER
   ========================================================== */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  background: #4a90d9;
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 10;
}

header h1 { font-size: 1.2rem; }

.header-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

#user-display { font-size: 0.9rem; }

#logout-btn {
  padding: 0.6rem 1rem;
  background: rgba(255,255,255,0.2);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.4);
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.95rem;
  min-height: 44px;
  min-width: 44px;
}

#logout-btn:active {
  background: rgba(255,255,255,0.4);
}

/* ==========================================================
   CALENDAR NAVIGATION
   ========================================================== */
.calendar-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  padding: 1rem 0.75rem;
}

.calendar-nav button {
  padding: 0.75rem 1.25rem;
  background: #fff;
  border: 2px solid #ccc;
  border-radius: 12px;
  font-size: 1.3rem;
  cursor: pointer;
  min-height: 56px;
  min-width: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.calendar-nav button:active {
  background: #e8e8e8;
  transform: scale(0.95);
}

.calendar-nav h2 {
  min-width: 0;
  flex: 1;
  text-align: center;
  font-size: 1.15rem;
}

/* ==========================================================
   LEGEND
   ========================================================== */
.legend {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.75rem 1.25rem;
  padding: 0.5rem 1rem 0.75rem;
  font-size: 0.9rem;
  color: #555;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

.dot.activity { background: #4caf50; }
.dot.food { background: #ff9800; }
.dot.medication { background: #2196f3; }
.dot.symptom { background: #f44336; }

/* ==========================================================
   CALENDAR GRID
   ========================================================== */
.calendar {
  max-width: 960px;
  margin: 0 auto;
  padding: 0 0.5rem 2rem;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 1px;
}

.day-header {
  padding: 0.5rem 0.25rem;
  text-align: center;
  font-weight: 600;
  font-size: 0.8rem;
  color: #666;
}

#calendar-days {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 3px;
}

.day-cell {
  background: #fff;
  min-height: 64px;
  padding: 0.4rem;
  border-radius: 8px;
  cursor: pointer;
  border: 2px solid #e0e0e0;
  transition: background 0.1s;
  /* large touch target */
  touch-action: manipulation;
}

.day-cell:active {
  background: #e3f0fc;
}

.day-cell.empty {
  background: transparent;
  border-color: transparent;
  cursor: default;
}

.day-cell.empty:active {
  background: transparent;
}

.day-cell.today {
  border-color: #4a90d9;
  border-width: 3px;
}

.day-number {
  font-size: 0.85rem;
  font-weight: 700;
  margin-bottom: 0.25rem;
  color: #333;
}

.day-dots {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
}

.day-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.day-dot.activity { background: #4caf50; }
.day-dot.food { background: #ff9800; }
.day-dot.medication { background: #2196f3; }
.day-dot.symptom { background: #f44336; }

/* ==========================================================
   MODALS — full-screen on mobile for easy reach
   ========================================================== */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
}

.modal-content {
  background: #fff;
  border-radius: 20px 20px 0 0;
  padding: 1.5rem 1.25rem 2rem;
  width: 100%;
  max-width: 600px;
  max-height: 92vh;
  max-height: 92dvh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.25rem;
}

.modal-header h3 {
  font-size: 1.2rem;
}

.modal-header button {
  background: #f0f0f0;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: #666;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.modal-header button:active {
  background: #ddd;
}

/* ==========================================================
   DAY ENTRIES LIST
   ========================================================== */
.entry-item {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 1rem;
  margin-bottom: 0.75rem;
  border-radius: 12px;
  border-left: 5px solid #ccc;
}

.entry-item.activity { border-left-color: #4caf50; background: #f1f8e9; }
.entry-item.food { border-left-color: #ff9800; background: #fff3e0; }
.entry-item.medication { border-left-color: #2196f3; background: #e3f2fd; }
.entry-item.symptom { border-left-color: #f44336; background: #ffebee; }

.entry-info { flex: 1; min-width: 0; }

.entry-category {
  font-size: 0.75rem;
  text-transform: uppercase;
  font-weight: 700;
  letter-spacing: 0.5px;
  margin-bottom: 0.2rem;
}

.entry-desc { font-size: 1.05rem; }

.entry-time {
  font-size: 0.9rem;
  color: #888;
  margin-top: 0.15rem;
}

.entry-notes {
  font-size: 0.9rem;
  color: #666;
  margin-top: 0.25rem;
}

.entry-actions {
  display: flex;
  gap: 0.5rem;
  margin-left: 0.75rem;
  flex-shrink: 0;
}

.entry-actions button {
  background: #f0f0f0;
  border: none;
  cursor: pointer;
  font-size: 1.2rem;
  width: 52px;
  height: 52px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.entry-actions button:active {
  background: #ddd;
  transform: scale(0.95);
}

.no-entries {
  color: #999;
  text-align: center;
  padding: 2rem 1rem;
  font-size: 1.05rem;
}

/* ==========================================================
   ENTRY FORM
   ========================================================== */
#entry-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

#entry-form label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 1rem;
  font-weight: 600;
}

#entry-form input,
#entry-form select,
#entry-form textarea {
  padding: 0.9rem 1rem;
  border: 2px solid #ccc;
  border-radius: 12px;
  font-size: 1.1rem;
  font-family: inherit;
  min-height: 56px;
  appearance: none;
  -webkit-appearance: none;
}

#entry-form select {
  background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23666' stroke-width='2' fill='none'/%3E%3C/svg%3E") no-repeat right 1rem center;
  padding-right: 2.5rem;
}

#entry-form input:focus,
#entry-form select:focus,
#entry-form textarea:focus {
  outline: none;
  border-color: #4a90d9;
  box-shadow: 0 0 0 3px rgba(74, 144, 217, 0.25);
}

#entry-form textarea {
  resize: vertical;
  min-height: 80px;
}

/* Subcategory selector (intensity / quantity) */
.subcategory-selector {
  display: flex;
  gap: 0.5rem;
}

.subcategory-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  padding: 0.75rem 0.5rem;
  border: 2px solid #ccc;
  border-radius: 12px;
  background: #fff;
  cursor: pointer;
  min-height: 56px;
  transition: border-color 0.15s, background 0.15s;
}

.subcategory-btn:active {
  transform: scale(0.97);
}

.subcategory-btn.selected {
  border-color: #4a90d9;
  background: #e3f0fc;
}

.subcategory-num {
  font-size: 1.2rem;
  font-weight: 700;
  color: #333;
}

.subcategory-desc {
  font-size: 0.75rem;
  color: #666;
  text-transform: uppercase;
  font-weight: 600;
  letter-spacing: 0.3px;
}

.subcategory-btn.selected .subcategory-num { color: #4a90d9; }
.subcategory-btn.selected .subcategory-desc { color: #4a90d9; }

/* Subcategory display in entry list */
.entry-subcategory {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.1rem 0.5rem;
  border-radius: 8px;
  background: rgba(0,0,0,0.06);
  color: #555;
  margin-left: 0.4rem;
  vertical-align: middle;
}

.form-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 0.5rem;
}

.btn-primary,
.btn-secondary {
  flex: 1;
  min-height: 60px;
  border: none;
  border-radius: 12px;
  font-size: 1.15rem;
  font-weight: 600;
  cursor: pointer;
}

.btn-primary {
  background: #4a90d9;
  color: #fff;
}

.btn-primary:hover { background: #3a7bc8; }
.btn-primary:active { background: #2e6ab5; transform: scale(0.98); }

.btn-secondary {
  background: #e0e0e0;
  color: #333;
}

.btn-secondary:hover { background: #d0d0d0; }
.btn-secondary:active { background: #c0c0c0; transform: scale(0.98); }

#add-entry-btn {
  width: 100%;
  margin-top: 0.75rem;
  min-height: 60px;
  font-size: 1.15rem;
  font-weight: 600;
  border-radius: 12px;
}

/* ==========================================================
   DAY MODAL ACTIONS
   ========================================================== */
.day-modal-actions {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.btn-interview {
  width: 100%;
  min-height: 60px;
  font-size: 1.15rem;
  font-weight: 600;
  border-radius: 12px;
  border: 3px solid #7c4dff;
  background: #f3edff;
  color: #5c2dd5;
  cursor: pointer;
}

.btn-interview:hover { background: #e8deff; }
.btn-interview:active { background: #d9ccff; transform: scale(0.98); }

/* ==========================================================
   INTERVIEW MODAL
   ========================================================== */
.interview-modal-content {
  display: flex;
  flex-direction: column;
  max-height: 95vh;
  max-height: 95dvh;
}

.interview-conversation {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0.5rem 0;
  min-height: 200px;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.interview-bubble {
  padding: 1rem 1.25rem;
  border-radius: 16px;
  max-width: 90%;
  line-height: 1.5;
  word-wrap: break-word;
}

.interview-bubble.assistant {
  background: #e8f0fe;
  color: #1a1a1a;
  align-self: flex-start;
  font-size: 1.25rem;
  border-bottom-left-radius: 4px;
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
}

.interview-bubble.assistant .bubble-text {
  flex: 1;
}

.bubble-speak-btn {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, 0.08);
  color: #555;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 0.1rem;
}

.bubble-speak-btn:active {
  background: rgba(0, 0, 0, 0.18);
  transform: scale(0.92);
}

.interview-bubble.user {
  background: #4a90d9;
  color: #fff;
  align-self: flex-end;
  font-size: 1.1rem;
  border-bottom-right-radius: 4px;
}

.interview-bubble.loading {
  opacity: 0.6;
  font-style: italic;
}

/* Auto-read toggle */
.interview-auto-read-row {
  padding: 0.4rem 0;
  display: flex;
  justify-content: flex-end;
}

.auto-read-label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.9rem;
  color: #555;
  cursor: pointer;
  user-select: none;
}

.auto-read-label input[type="checkbox"] {
  width: 20px;
  height: 20px;
  accent-color: #7c4dff;
  cursor: pointer;
}

/* Mic button */
.interview-input-area {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid #e0e0e0;
  margin-top: 0.5rem;
}

.interview-mic-btn {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: 3px solid #7c4dff;
  background: #fff;
  color: #7c4dff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.2s, transform 0.1s;
}

.interview-mic-btn:active {
  transform: scale(0.95);
}

.interview-mic-btn.recording {
  background: #f44336;
  border-color: #f44336;
  color: #fff;
  animation: mic-pulse 1.2s ease-in-out infinite;
}

@keyframes mic-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(244, 67, 54, 0.4); }
  50% { box-shadow: 0 0 0 12px rgba(244, 67, 54, 0); }
}

.interview-mic-btn.disabled {
  opacity: 0.4;
  pointer-events: none;
}

.interview-text-input {
  flex: 1;
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.interview-text-input input {
  flex: 1;
  padding: 0.8rem 1rem;
  border: 2px solid #ccc;
  border-radius: 12px;
  font-size: 1.05rem;
  min-height: 50px;
  font-family: inherit;
}

.interview-text-input input:focus {
  outline: none;
  border-color: #4a90d9;
  box-shadow: 0 0 0 3px rgba(74, 144, 217, 0.25);
}

.interview-send-btn {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  border: none;
  background: #4a90d9;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.interview-send-btn:active {
  background: #2e6ab5;
  transform: scale(0.95);
}

/* Confirmation card */
.interview-confirm {
  padding: 1rem;
}

.interview-confirm h4 {
  font-size: 1.1rem;
  margin-bottom: 0.75rem;
}

.interview-confirm-details {
  background: #f9f9f9;
  border: 2px solid #e0e0e0;
  border-radius: 12px;
  padding: 1rem;
  margin-bottom: 1rem;
}

.interview-confirm-details .confirm-field {
  margin-bottom: 0.5rem;
}

.interview-confirm-details .confirm-field:last-child {
  margin-bottom: 0;
}

.interview-confirm-details .confirm-label {
  font-size: 0.8rem;
  text-transform: uppercase;
  font-weight: 700;
  color: #666;
  letter-spacing: 0.5px;
}

.interview-confirm-details .confirm-value {
  font-size: 1.1rem;
  color: #1a1a1a;
}

/* ==========================================================
   SETTINGS BUTTON
   ========================================================== */
#settings-btn {
  padding: 0.6rem 0.8rem;
  background: rgba(255,255,255,0.2);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.4);
  border-radius: 8px;
  cursor: pointer;
  font-size: 1.2rem;
  min-height: 44px;
  min-width: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

#settings-btn:active {
  background: rgba(255,255,255,0.4);
}

/* ==========================================================
   SETTINGS MODAL — FITBIT
   ========================================================== */
.settings-section h4 {
  font-size: 1.1rem;
  margin-bottom: 0.75rem;
  color: #333;
}

.fitbit-status-loading {
  color: #888;
  font-style: italic;
}

.fitbit-status-card {
  border: 2px solid #e0e0e0;
  border-radius: 12px;
  padding: 1rem;
}

.fitbit-status-card.connected {
  border-color: #4caf50;
}

.fitbit-badge {
  display: inline-block;
  padding: 0.25rem 0.75rem;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.fitbit-badge.connected {
  background: #e8f5e9;
  color: #2e7d32;
}

.fitbit-badge.disconnected {
  background: #f5f5f5;
  color: #888;
}

.fitbit-detail {
  font-size: 0.9rem;
  color: #666;
  margin-top: 0.25rem;
}

.fitbit-setup-steps,
.fitbit-usage-steps {
  text-align: left;
  margin: 0.5rem 0;
}

.fitbit-setup-steps ol,
ol.fitbit-usage-steps {
  margin: 0.5rem 0 0.5rem 1.25rem;
  padding: 0;
}

.fitbit-setup-steps li,
.fitbit-usage-steps li {
  margin-bottom: 0.4rem;
  font-size: 0.9rem;
  line-height: 1.45;
}

.fitbit-setup-steps code {
  background: #f0f0f0;
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  font-size: 0.85rem;
}

.fitbit-setup-steps a {
  color: #00838f;
}

.fitbit-detail p {
  margin-bottom: 0.25rem;
}

.btn-fitbit-connect {
  width: 100%;
  min-height: 56px;
  border: none;
  border-radius: 12px;
  font-size: 1.1rem;
  font-weight: 600;
  cursor: pointer;
  background: #00B0B9;
  color: #fff;
  margin-top: 0.75rem;
}

.btn-fitbit-connect:hover { background: #009da6; }
.btn-fitbit-connect:active { background: #008a92; transform: scale(0.98); }

.btn-fitbit-disconnect {
  width: 100%;
  min-height: 48px;
  border: 2px solid #d32f2f;
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  background: #fff;
  color: #d32f2f;
  margin-top: 0.75rem;
}

.btn-fitbit-disconnect:hover { background: #ffebee; }
.btn-fitbit-disconnect:active { background: #ffcdd2; transform: scale(0.98); }

/* ==========================================================
   FITBIT SYNC BUTTON & RESULTS
   ========================================================== */
.btn-fitbit-sync {
  width: 100%;
  min-height: 56px;
  font-size: 1.1rem;
  font-weight: 600;
  border-radius: 12px;
  border: 3px solid #00B0B9;
  background: #e0f7fa;
  color: #00838f;
  cursor: pointer;
}

.btn-fitbit-sync:hover { background: #b2ebf2; }
.btn-fitbit-sync:active { background: #80deea; transform: scale(0.98); }
.btn-fitbit-sync:disabled { opacity: 0.6; cursor: not-allowed; }

.fitbit-sync-results {
  border: 2px solid #e0e0e0;
  border-radius: 12px;
  padding: 1rem;
  margin-bottom: 0.75rem;
  background: #fafafa;
}

.fitbit-sync-results h4 {
  font-size: 1rem;
  margin-bottom: 0.75rem;
  color: #00838f;
}

.fitbit-sync-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.fitbit-sync-item {
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  padding: 0.75rem;
  text-align: center;
}

.fitbit-sync-item.full-width {
  grid-column: 1 / -1;
}

.fitbit-sync-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  font-weight: 700;
  color: #888;
  letter-spacing: 0.5px;
  margin-bottom: 0.25rem;
}

.fitbit-sync-value {
  font-size: 1.3rem;
  font-weight: 700;
  color: #333;
}

.fitbit-sync-error {
  color: #d32f2f;
  font-size: 0.9rem;
  text-align: center;
  padding: 0.5rem;
}

/* ==========================================================
   RESPONSIVE — larger screens get slightly refined layout
   ========================================================== */
@media (min-width: 768px) {
  html { font-size: 16px; }

  .auth-container { padding-top: 5rem; }

  .modal {
    align-items: center;
  }

  .modal-content {
    border-radius: 16px;
    width: 90%;
    max-height: 80vh;
    padding: 2rem;
  }

  .calendar-nav h2 { font-size: 1.3rem; }

  .day-cell { min-height: 80px; }
}
