/* =============================================================
   chat.css — Organic Mechanic shared chat component styles
   Used by: index.html, embed.html
   Requires: variables.css loaded first
   Compatible with: Flask/Jinja2, .NET Razor, Bootstrap, plain HTML
   ============================================================= */

/* --- Message list container --- */
#messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* --- Message bubbles --- */
.msg {
  display: flex;
  flex-direction: column;
  max-width: 90%;
}
.msg.user { align-self: flex-end; }
.msg.bot  { align-self: flex-start; }

.bubble {
  padding: 10px 13px;
  border-radius: 16px;
  line-height: 1.5;
  font-size: 0.85rem;
  white-space: pre-wrap;
  word-break: break-word;
}
.msg.user .bubble {
  background: var(--green-mid);
  color: var(--cream);
  border-bottom-right-radius: 3px;
}
.msg.bot .bubble {
  background: var(--bot-bg);
  border: 1px solid var(--border);
  border-bottom-left-radius: 3px;
  box-shadow: 0 1px 3px var(--shadow);
}

/* --- Markdown tables --- */
.msg.bot .bubble table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
  margin: 8px 0;
  display: block;
  overflow-x: auto;
}
.msg.bot .bubble th,
.msg.bot .bubble td {
  padding: 5px 10px;
  border: 1px solid var(--border);
  text-align: left;
  white-space: nowrap;
}
.msg.bot .bubble th {
  background: var(--cream-dark);
  font-weight: 600;
}
.msg.bot .bubble tr:nth-child(even) td {
  background: rgba(0,0,0,0.02);
}

/* --- Sources --- */
.sources {
  margin-top: 6px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.source-tag {
  font-size: 0.68rem;
  background: var(--cream-dark);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 2px 8px;
  color: var(--text-light);
}

/* --- Snake loader typing indicator --- */
.snake-loader {
  width: 48px;
  height: 24px;
  display: inline-block;
  vertical-align: middle;
  flex-shrink: 0;
}

#typing-indicator .bubble {
  display: flex;
  align-items: center;
}
.snake-body {
  fill: #0D9A48;
  stroke: #5E00A4;
  stroke-width: 2.5;
  stroke-linejoin: round;
}
.snake-eye {
  fill: #FFCA00;
  offset-path: path("M40,20 C40,8 55,2 65,8 C75,14 75,26 65,32 C55,38 40,32 40,20 C40,8 25,2 15,8 C5,14 5,26 15,32 C25,38 40,32 40,20 Z");
  offset-rotate: 0deg;
  animation: snake-travel 2s linear infinite;
}
@keyframes snake-travel {
  0%   { offset-distance: 0%; }
  100% { offset-distance: 100%; }
}

/* --- Disclaimer --- */
.disclaimer {
  font-size: 0.65rem;
  color: var(--text-light);
  text-align: center;
  padding: 4px 8px;
  flex-shrink: 0;
}

/* --- Input area --- */
#input-area {
  background: var(--bot-bg);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: flex-end;
  padding: 8px;
  gap: 6px;
  flex-shrink: 0;
}
#user-input {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 8px 12px;
  outline: none;
  resize: none;
  font-size: 0.85rem;
  line-height: 1.4;
  max-height: 100px;
  font-family: inherit;
  background: var(--cream);
}
#user-input:focus { border-color: var(--green-mid); }

#send-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--green-dark);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s;
}
#send-btn:hover:not(:disabled) { background: var(--green-mid); }
#send-btn:disabled { opacity: 0.4; cursor: not-allowed; }
#send-btn svg { width: 15px; height: 15px; fill: var(--cream); }

/* --- Posture result card (shared) --- */
.posture-result-card {
  background: var(--bot-bg);
  border: 1.5px solid var(--green-light);
  border-radius: 12px;
  overflow: hidden;
}
.posture-result-card .card-header {
  background: var(--green-dark);
  color: var(--cream);
  padding: 8px 12px;
  font-size: 0.78rem;
  font-weight: 700;
}
.posture-result-card .bubble {
  border-radius: 0;
  border: none;
  box-shadow: none;
}

/* --- Deviation severity chips --- */
.deviation-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 8px 12px 4px;
  border-bottom: 1px solid var(--cream-dark);
}
.deviation-chip {
  font-size: 0.68rem;
  border-radius: 10px;
  padding: 2px 8px;
  font-weight: 600;
}
.deviation-chip.HIGH     { background: #fde8e8; color: #b91c1c; border: 1px solid #fca5a5; }
.deviation-chip.MODERATE { background: #fef3c7; color: #92400e; border: 1px solid #fcd34d; }
.deviation-chip.LOW      { background: #f0fdf4; color: #166534; border: 1px solid #bbf7d0; }

/* --- Muscle thumbnails grid (posture result) --- */
.muscle-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 12px 6px;
  border-bottom: 1px solid var(--cream-dark);
}
.muscle-thumb {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}
.muscle-thumb img {
  width: 60px;
  height: 60px;
  object-fit: cover;
  border-radius: 8px;
  border: 2px solid transparent;
}
.muscle-thumb.SHORT img { border-color: #fca5a5; }
.muscle-thumb.LONG  img { border-color: #bbf7d0; }
.muscle-thumb-label {
  font-size: 0.60rem;
  text-align: center;
  max-width: 60px;
  line-height: 1.2;
  color: var(--text-light);
}
.muscle-thumb-role {
  font-size: 0.56rem;
  font-weight: 700;
  text-transform: uppercase;
}
.muscle-thumb.SHORT .muscle-thumb-role { color: #b91c1c; }
.muscle-thumb.LONG  .muscle-thumb-role { color: #166534; }

/* --- Inline muscle image grid (inserted after each block that mentions muscles) --- */
.inline-muscle-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
  margin-bottom: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--cream-dark);
}
.inline-muscle-thumb {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}
.inline-muscle-thumb img {
  width: 52px;
  height: 52px;
  object-fit: cover;
  border-radius: 7px;
  border: 1.5px solid var(--border);
}
.inline-muscle-label {
  font-size: 0.58rem;
  text-align: center;
  max-width: 52px;
  color: var(--text-light);
  line-height: 1.2;
}

/* --- Photo upload slots (shared by index + embed posture panels) --- */
.photo-slot {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid var(--cream-dark);
}
.photo-slot:last-of-type { border-bottom: none; }
.photo-slot-label  { font-size: 0.76rem; font-weight: 600; flex: 1; }
.photo-slot-status { font-size: 0.72rem; color: var(--text-light); }
.photo-slot-status.ready { color: var(--green-light); font-weight: 600; }

.upload-photo-btn {
  background: var(--cream-dark);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 4px 10px;
  font-size: 0.74rem;
  cursor: pointer;
  font-family: inherit;
  flex-shrink: 0;
}
.upload-photo-btn:hover { background: var(--green-light); color: var(--cream); }

.retry-photo-btn { margin-top: 8px; padding: 10px 20px; background: var(--green-light); color: var(--cream); border: none; border-radius: 20px; font-size: 0.9rem; font-weight: 600; cursor: pointer; font-family: inherit; }
.retry-photo-btn:hover { background: var(--green-dark); }

/* --- Image lightbox overlay --- */
#om-lightbox {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.82);
  z-index: 9999;
  align-items: center;
  justify-content: center;
  padding: 20px;
  cursor: zoom-out;
}
#om-lightbox-img {
  max-width: min(90vw, 600px);
  max-height: 85vh;
  border-radius: 10px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.6);
  object-fit: contain;
  cursor: default;
}
#om-lightbox-close {
  position: fixed;
  top: 16px;
  right: 20px;
  background: rgba(255,255,255,0.15);
  border: none;
  color: #fff;
  font-size: 1.4rem;
  line-height: 1;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
#om-lightbox-close:hover { background: rgba(255,255,255,0.3); }

/* --- Protocol card --- */
.protocol-card {
  margin-top: 10px;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  font-size: 0.82rem;
  background: var(--cream);
  box-shadow: 0 1px 4px var(--shadow);
}
.protocol-card-title {
  background: var(--green-dark, #1b5e20);
  color: #fff;
  font-weight: 700;
  font-size: 0.78rem;
  letter-spacing: 0.03em;
  padding: 7px 12px;
}
.protocol-card-cols {
  display: flex;
  gap: 0;
}
.protocol-card-col {
  flex: 1;
  padding: 8px 12px;
  border-right: 1px solid var(--border);
}
.protocol-card-col:last-child { border-right: none; }
.protocol-card-col-header {
  font-weight: 700;
  font-size: 0.72rem;
  letter-spacing: 0.05em;
  color: var(--text-light);
  margin-bottom: 6px;
  text-transform: uppercase;
}
.protocol-card-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 3px 0;
  border-bottom: 1px solid var(--cream-dark, #e8dfd4);
  gap: 8px;
}
.protocol-card-row:last-child { border-bottom: none; }
.protocol-card-stretch { flex-direction: column; align-items: flex-start; }
.protocol-card-muscle {
  font-weight: 600;
  color: var(--text);
}
.protocol-card-plain {
  font-weight: 400;
  color: var(--text-light);
  font-size: 0.76rem;
}
.protocol-card-dose {
  font-family: monospace;
  font-size: 0.8rem;
  color: var(--green-dark, #1b5e20);
  white-space: nowrap;
  flex-shrink: 0;
}
.protocol-card-notes {
  font-size: 0.74rem;
  color: var(--text-light);
  margin-top: 1px;
}
.protocol-card-row {
  align-items: center;
}
.protocol-card-muscle-img {
  width: 52px;
  height: 52px;
  object-fit: cover;
  border-radius: 6px;
  flex-shrink: 0;
  margin-right: 8px;
  border: 1px solid var(--border);
}
.protocol-card-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  min-width: 0;
}

/* =============================================================
   My Plan page
   ============================================================= */

.my-plan-body {
  background: var(--cream, #f9f6f0);
  min-height: 100vh;
}

.my-plan-header .logo {
  width: 48px;
  height: 48px;
  border-radius: 8px;
  object-fit: contain;
  flex-shrink: 0;
}

.my-plan-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--green-dark, #1b5e20);
  color: #fff;
}

.my-plan-header h1 {
  font-size: 1.1rem;
  margin: 0;
  color: #fff;
}

.my-plan-header p {
  font-size: 0.75rem;
  margin: 0;
  opacity: 0.8;
}

.my-plan-header #header-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 12px;
}

.my-plan-chat-link {
  font-size: 0.8rem;
  color: rgba(255,255,255,0.85);
  text-decoration: none;
}

.my-plan-chat-link:hover { color: #fff; }

.my-plan-page {
  max-width: 680px;
  margin: 0 auto;
  padding: 24px 16px;
}

.my-plan-card {
  margin-bottom: 20px;
}

.my-plan-card-date {
  font-size: 0.72rem;
  color: var(--text-light, #666);
  margin-bottom: 4px;
}

.my-plan-print-btn {
  font-size: 0.75rem;
  padding: 4px 10px;
  margin-top: 8px;
  cursor: pointer;
  border: 1px solid var(--border, #ddd);
  border-radius: 6px;
  background: var(--cream-dark, #ede8df);
  color: var(--text-light, #555);
}

.my-plan-print-btn:hover {
  background: var(--cream, #f9f6f0);
}

.my-plan-auth-gate,
.my-plan-empty {
  text-align: center;
  padding: 48px 16px;
  color: var(--text-light, #666);
  font-size: 0.9rem;
}

.my-plan-loading {
  text-align: center;
  padding: 48px 16px;
  color: var(--text-light, #666);
  font-size: 0.85rem;
}

.my-plan-error {
  color: #c0392b;
  font-size: 0.85rem;
  text-align: center;
  padding: 24px;
}

/* Print — isolate the focused card */
@media print {
  body > *:not(main) { display: none !important; }
  .my-plan-page > *:not(.print-target) { display: none !important; }
  .print-target { display: block !important; }
  .my-plan-print-btn { display: none !important; }
  .print-target::before {
    content: "Organic Mechanic — Educational reference only. Not a substitute for clinical assessment.";
    display: block;
    font-size: 0.7rem;
    color: #666;
    margin-bottom: 12px;
    border-bottom: 1px solid #ddd;
    padding-bottom: 8px;
  }
}
