/* =========================================================
   Physics Helper — Styles v0.4.0
   ========================================================= */

.physics-helper-app {
  max-width: 860px;
  margin: 24px auto;
  font-family: inherit;
}

/* ----- Card shell ----- */
.ph-card {
  border: 1px solid #d7dde8;
  border-radius: 16px;
  padding: 22px;
  background: #ffffff;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.06);
}

/* ----- Header ----- */
.ph-hd-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 6px;
}

.ph-hd-row h2 {
  margin: 0;
  font-size: 1.8rem;
  line-height: 1.2;
}

.ph-header > p {
  margin: 0 0 4px;
  color: #4b5563;
}

/* Font size buttons */
.ph-font-btns {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.ph-font-dec,
.ph-font-inc {
  padding: 4px 10px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  background: #f9fafb;
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 700;
  color: #374151;
  line-height: 1.4;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}

.ph-font-dec:hover:not(:disabled),
.ph-font-inc:hover:not(:disabled) {
  background: #eff6ff;
  border-color: #2563eb;
  color: #2563eb;
}

.ph-font-dec:disabled,
.ph-font-inc:disabled {
  opacity: 0.38;
  cursor: default;
}

/* =========================================================
   PASSCODE GATE
   ========================================================= */

.ph-passcode-gate {
  padding: 8px 0 16px;
}

.ph-passcode-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 320px;
  margin-top: 20px;
}

.ph-passcode-input {
  padding: 10px 14px;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  font: inherit;
  font-size: 1rem;
  letter-spacing: 0.1em;
  width: 100%;
  box-sizing: border-box;
}

.ph-passcode-input:focus {
  outline: 2px solid #2563eb;
  outline-offset: 2px;
  border-color: #2563eb;
}

.ph-passcode-error {
  color: #dc2626;
  font-size: 0.9rem;
  min-height: 1.2em;
  margin: 0;
}

/* =========================================================
   MAIN CHAT UI
   ========================================================= */

.ph-controls {
  display: flex;
  gap: 12px;
  align-items: center;
  margin: 16px 0;
}

.ph-controls label {
  font-weight: 700;
}

.ph-unit-select {
  padding: 8px 10px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  min-width: 220px;
  font: inherit;
}

/* Chat window — resizable vertically by the student */
.ph-chat {
  min-height: 260px;
  max-height: 480px;
  overflow-y: auto;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  padding: 14px;
  background: #f8fafc;
  margin-bottom: 14px;
  resize: vertical;
}

.ph-message {
  padding: 10px 14px;
  border-radius: 12px;
  margin: 10px 0;
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: break-word;
}

.ph-assistant {
  background: #eef2ff;
  border: 1px solid #dbe4ff;
  margin-right: 56px;
}

.ph-user {
  background: #ecfeff;
  border: 1px solid #bae6fd;
  margin-left: 56px;
}

/* KaTeX inside chat messages */
.ph-message .katex-display {
  margin: 0.5em 0;
  overflow-x: auto;
}

.ph-message .katex {
  font-size: 1.05em;
}

/* Input form */
.ph-form {
  display: block;
}

.ph-input {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid #cbd5e1;
  border-radius: 12px;
  padding: 12px;
  font: inherit;
  resize: vertical;
}

.ph-input:focus {
  outline: 2px solid #2563eb;
  outline-offset: 2px;
  border-color: #2563eb;
}

/* Action buttons row */
.ph-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  flex-wrap: wrap;
  align-items: center;
}

.ph-send,
.ph-end {
  border: none;
  border-radius: 10px;
  padding: 10px 18px;
  cursor: pointer;
  font: inherit;
  font-weight: 700;
  transition: opacity 0.15s, background 0.15s;
}

.ph-send {
  background: #2563eb;
  color: #ffffff;
}

.ph-send:hover:not(:disabled) { background: #1d4ed8; }

.ph-end {
  background: #e5e7eb;
  color: #111827;
}

.ph-end:hover:not(:disabled) { background: #d1d5db; }

.ph-send:disabled,
.ph-end:disabled {
  opacity: 0.55;
  cursor: wait;
}

/* Equation editor trigger button */
.ph-eq-open {
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  padding: 9px 14px;
  cursor: pointer;
  font: inherit;
  font-weight: 600;
  background: #f9fafb;
  color: #374151;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
  margin-left: auto; /* push to right side */
}

.ph-eq-open:hover {
  background: #eff6ff;
  border-color: #2563eb;
  color: #2563eb;
}

.ph-status {
  min-height: 1.2em;
  font-size: 0.92rem;
  color: #4b5563;
  margin-top: 6px;
}

.ph-note {
  font-size: 0.88rem;
  color: #6b7280;
  margin-bottom: 0;
  margin-top: 4px;
}

/* =========================================================
   EQUATION EDITOR OVERLAY
   ========================================================= */

.ph-eq-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  z-index: 99999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  backdrop-filter: blur(2px);
}

.ph-eq-dialog {
  background: #ffffff;
  border-radius: 18px;
  box-shadow: 0 32px 80px rgba(0, 0, 0, 0.22);
  width: 100%;
  max-width: 600px;
  max-height: 90vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  animation: ph-eq-in 0.18s ease;
}

@keyframes ph-eq-in {
  from { opacity: 0; transform: translateY(12px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0)    scale(1);    }
}

/* Dialog header */
.ph-eq-dialog-hd {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px 14px;
  border-bottom: 1px solid #e5e7eb;
  position: sticky;
  top: 0;
  background: #fff;
  border-radius: 18px 18px 0 0;
  z-index: 1;
}

.ph-eq-dialog-title {
  font-weight: 700;
  font-size: 1.05rem;
  color: #111827;
}

.ph-eq-close {
  background: none;
  border: none;
  font-size: 1rem;
  cursor: pointer;
  padding: 5px 9px;
  border-radius: 7px;
  color: #6b7280;
  line-height: 1;
  transition: background 0.12s;
}

.ph-eq-close:hover { background: #f3f4f6; color: #111827; }

/* Dialog body */
.ph-eq-dialog-bd {
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  flex: 1;
}

/* LaTeX text input */
.ph-eq-lbl {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: #374151;
  margin-bottom: 6px;
}

.ph-eq-latex {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid #cbd5e1;
  border-radius: 9px;
  padding: 10px 13px;
  font-family: 'Fira Mono', 'Courier New', monospace;
  font-size: 0.95rem;
  color: #1e40af;
  background: #f8faff;
}

.ph-eq-latex:focus {
  outline: 2px solid #2563eb;
  outline-offset: 2px;
  border-color: #2563eb;
  background: #fff;
}

/* Live preview */
.ph-eq-preview-row {
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  padding: 10px 14px;
  background: #f8fafc;
  min-height: 60px;
}

.ph-eq-preview-lbl {
  display: block;
  font-size: 0.75rem;
  font-weight: 700;
  color: #9ca3af;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 6px;
}

.ph-eq-preview-out {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  overflow-x: auto;
}

.ph-eq-preview-out .katex-display {
  margin: 0;
}

.ph-eq-preview-empty {
  color: #9ca3af;
  font-size: 0.88rem;
  font-style: italic;
}

/* Symbol categories */
.ph-eq-sym-area {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.ph-eq-cat-name {
  display: block;
  font-size: 0.75rem;
  font-weight: 700;
  color: #6b7280;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin-bottom: 6px;
}

.ph-eq-sym-row {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.ph-eq-sym-btn {
  min-width: 38px;
  height: 38px;
  padding: 2px 7px;
  border: 1px solid #d1d5db;
  border-radius: 7px;
  background: #ffffff;
  cursor: pointer;
  font-size: 1rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.1s, border-color 0.1s, color 0.1s;
  color: #374151;
}

.ph-eq-sym-btn:hover {
  background: #eff6ff;
  border-color: #2563eb;
  color: #2563eb;
}

.ph-eq-sym-btn:active {
  background: #dbeafe;
}

/* KaTeX inside symbol buttons */
.ph-eq-sym-btn .katex {
  font-size: 0.9rem;
  pointer-events: none;
}

/* Dialog footer */
.ph-eq-dialog-ft {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 20px;
  border-top: 1px solid #e5e7eb;
  background: #f9fafb;
  border-radius: 0 0 18px 18px;
  position: sticky;
  bottom: 0;
  flex-wrap: wrap;
}

.ph-eq-hint {
  font-size: 0.78rem;
  color: #9ca3af;
  margin-left: auto;
}

/* Responsive */
@media (max-width: 520px) {
  .ph-hd-row { flex-wrap: wrap; }
  .ph-eq-open { margin-left: 0; }
  .ph-actions { gap: 6px; }
  .ph-eq-hint { display: none; }
}
