.math-ai-dialog {
  width: min(880px, calc(100% - 24px));
  max-height: min(86vh, 760px);
  padding: 0;
  border: 1px solid #dbe3ee;
  border-radius: 12px;
  background: #fff;
  color: #1e293b;
  box-shadow: 0 24px 70px rgba(15, 23, 42, .18);
  overflow: hidden;
}

.math-ai-dialog::backdrop { background: rgba(30, 41, 59, .18); }

.math-ai-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 22px;
  border-bottom: 1px solid #e2e8f0;
}

.math-ai-head h2 { margin: 0; font-size: 20px; line-height: 1.3; }
.math-ai-head p { margin: 4px 0 0; color: #64748b; font-size: 12px; }
.math-ai-close { border: 0; background: transparent; color: #64748b; font: inherit; cursor: pointer; }

.math-ai-body { display: grid; gap: 16px; max-height: calc(86vh - 78px); overflow: auto; padding: 20px 22px 22px; }
.math-ai-fields { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.math-ai-field { display: grid; gap: 6px; min-width: 0; color: #475569; font-size: 13px; }
.math-ai-field-wide { grid-column: 1 / -1; }
.math-ai-field input,
.math-ai-field select,
.math-ai-field textarea {
  width: 100%;
  border: 1px solid #cbd5e1;
  border-radius: 7px;
  background: #fff;
  color: #1e293b;
  font: inherit;
}
.math-ai-field input,
.math-ai-field select { min-height: 38px; padding: 8px 10px; }
.math-ai-field textarea { min-height: 88px; padding: 10px; resize: vertical; line-height: 1.55; }
.math-ai-field input:focus,
.math-ai-field select:focus,
.math-ai-field textarea:focus { outline: 2px solid rgba(37, 99, 235, .18); border-color: #2563eb; }

.math-ai-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }
.math-ai-actions button { min-height: 38px; padding: 8px 15px; border: 1px solid #2563eb; border-radius: 7px; background: #fff; color: #2563eb; font: 600 13px/1.2 inherit; cursor: pointer; }
.math-ai-actions button.primary { background: #2563eb; color: #fff; }
.math-ai-actions button:disabled { opacity: .55; cursor: wait; }

.math-ai-status { min-height: 20px; color: #2563eb; font-size: 13px; }
.math-ai-status.error { color: #b91c1c; }
.math-ai-history { display: grid; gap: 8px; border-top: 1px solid #e2e8f0; padding-top: 14px; }
.math-ai-turn { padding: 8px 0; border-bottom: 1px solid #edf2f7; white-space: pre-wrap; line-height: 1.55; font-size: 13px; }
.math-ai-turn strong { color: #475569; }
.math-ai-preview { display: grid; gap: 10px; border-top: 1px solid #e2e8f0; padding-top: 14px; }
.math-ai-preview h3 { margin: 0; font-size: 15px; }
.math-ai-question { padding: 10px 0; border-bottom: 1px solid #edf2f7; line-height: 1.55; }
.math-ai-question:last-child { border-bottom: 0; }
.math-ai-question-title { font-weight: 650; }
.math-ai-question-detail { margin-top: 5px; color: #475569; font-size: 13px; white-space: pre-wrap; }
.math-ai-question-detail code { color: #1e3a5f; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; }
.math-ai-empty { color: #64748b; font-size: 13px; }

@media (max-width: 700px) {
  .math-ai-fields { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .math-ai-field-wide { grid-column: 1 / -1; }
}

@media (max-width: 480px) {
  .math-ai-dialog { width: calc(100% - 14px); }
  .math-ai-head { padding: 15px 16px; }
  .math-ai-body { padding: 16px; }
  .math-ai-fields { grid-template-columns: 1fr; }
  .math-ai-field-wide { grid-column: auto; }
  .math-ai-actions { display: grid; grid-template-columns: 1fr; }
  .math-ai-actions button { width: 100%; }
}
