/* ============================================================
   LaTeX Master – Stylesheet
   Vanilla CSS, no external dependencies
   ============================================================ */

/* ---------- Reset & base ---------- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --color-bg:        #f5f7fa;
  --color-surface:   #ffffff;
  --color-border:    #d1d9e6;
  --color-primary:   #2563eb;
  --color-primary-h: #1d4ed8;
  --color-secondary: #64748b;
  --color-secondary-h: #475569;
  --color-text:      #1e293b;
  --color-muted:     #64748b;
  --color-success:   #16a34a;
  --color-header-bg: #1e293b;
  --color-header-fg: #f8fafc;
  --radius:          10px;
  --shadow:          0 2px 12px rgba(0,0,0,.08);
  --font-main:       'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-mono:       'Consolas', 'Cascadia Code', 'Fira Mono', monospace;
  --transition:      .18s ease;
}

html { font-size: 16px; }

body {
  font-family: var(--font-main);
  background: var(--color-bg);
  color: var(--color-text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---------- Accessibility ---------- */
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

:focus-visible {
  outline: 3px solid var(--color-primary);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ---------- Header ---------- */
.app-header {
  background: var(--color-header-bg);
  color: var(--color-header-fg);
  padding: .85rem 1.25rem;
  box-shadow: 0 2px 8px rgba(0,0,0,.25);
}

.header-inner {
  max-width: 760px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 1rem;
}

.logo {
  flex-shrink: 0;
  border-radius: 8px;
}

.header-text { flex: 1; }

.app-title {
  font-size: 1.35rem;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -.3px;
}

.app-subtitle {
  font-size: .85rem;
  color: #94a3b8;
  margin-top: .15rem;
}

/* Language toggle */
.lang-btn {
  background: rgba(255,255,255,.12);
  color: var(--color-header-fg);
  border: 1px solid rgba(255,255,255,.25);
  border-radius: 6px;
  padding: .35rem .75rem;
  font-size: .8rem;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition);
  white-space: nowrap;
}
.lang-btn:hover { background: rgba(255,255,255,.22); }

/* ---------- Main layout ---------- */
.container {
  max-width: 760px;
  width: 100%;
  margin: 1.5rem auto;
  padding: 0 1rem;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* ---------- Hero / intro section ---------- */
.hero-section {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-left: 4px solid var(--color-primary);
  border-radius: var(--radius);
  padding: 1.1rem 1.25rem;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: .9rem;
}

.hero-desc {
  font-size: .97rem;
  line-height: 1.65;
  color: var(--color-text);
}

.hero-desc code {
  font-family: var(--font-mono);
  background: #f0f4ff;
  border: 1px solid #d1d9e6;
  border-radius: 4px;
  padding: .05em .35em;
  font-size: .9em;
}

.hero-example {
  display: flex;
  align-items: center;
  gap: .75rem;
  flex-wrap: wrap;
}

.hero-col {
  flex: 1;
  min-width: 170px;
  display: flex;
  flex-direction: column;
  gap: .4rem;
}

.hero-tag {
  font-size: .68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  padding: .15rem .5rem;
  border-radius: 4px;
  align-self: flex-start;
}

.hero-tag--before {
  background: #fef3c7;
  color: #92400e;
}

.hero-tag--after {
  background: #dcfce7;
  color: #166534;
}

.hero-code {
  font-family: var(--font-mono);
  font-size: .82rem;
  background: #f8fafc;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  padding: .5rem .75rem;
  line-height: 1.55;
  color: var(--color-text);
  word-break: break-all;
}

.hero-code--result {
  background: #f0fdf4;
  border-color: #86efac;
  color: #166534;
}

.hero-arrow {
  font-size: 1.4rem;
  color: var(--color-primary);
  font-weight: 700;
  flex-shrink: 0;
}

/* ---------- Mode selector ---------- */
.mode-fieldset {
  border: none;
  display: flex;
  gap: .6rem 1.5rem;
  flex-wrap: nowrap;   /* always single line on desktop */
  overflow-x: auto;    /* safety scroll if viewport very narrow */
}

.mode-label {
  display: flex;
  align-items: flex-start;
  gap: .45rem;
  font-size: .92rem;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

.mode-label input[type="radio"] {
  accent-color: var(--color-primary);
  width: 1rem;
  height: 1rem;
  cursor: pointer;
  margin-top: .15rem;
  flex-shrink: 0;
}

.mode-label-text {
  display: flex;
  flex-direction: column;
  gap: .1rem;
  white-space: normal; /* description can wrap inside its column */
}

.mode-desc {
  font-size: .78rem;
  color: var(--color-muted);
  font-weight: 400;
  line-height: 1.3;
}

/* ---------- Two-column panels layout ---------- */
.panels-row {
  display: flex;
  gap: 1rem;
  align-items: stretch;
}

.panels-row > .panel {
  flex: 1;
  min-width: 0;  /* prevent flex overflow */
}

/* textarea and output box grow to fill panel height */
.panels-row > .panel > .text-area {
  flex: 1;
  min-height: 220px;
}

.panels-row > .panel > .output-box {
  flex: 1;
  min-height: 120px;
}

/* ---------- Formula style panel ---------- */
.formula-style-panel {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: .65rem 1rem;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 1.1rem;
  flex-wrap: wrap;
}
.formula-style-panel[hidden] { display: none; }

.style-label {
  font-size: .8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--color-muted);
  white-space: nowrap;
}

.style-control {
  display: flex;
  align-items: center;
  gap: .4rem;
  font-size: .875rem;
  color: var(--color-text);
  cursor: pointer;
}
.style-control--check { gap: .35rem; }

.style-control input[type="number"] {
  width: 3.5rem;
  padding: .25rem .4rem;
  border: 1px solid var(--color-border);
  border-radius: 5px;
  font-size: .875rem;
  text-align: center;
  color: var(--color-text);
  background: #fafbfc;
}
.style-control input[type="number"]:focus {
  border-color: var(--color-primary);
  outline: none;
}

.style-control input[type="color"] {
  width: 2rem; height: 1.75rem;
  padding: 0;
  border: 1px solid var(--color-border);
  border-radius: 5px;
  cursor: pointer;
  background: none;
}

.style-control input[type="checkbox"] {
  accent-color: var(--color-primary);
  width: 1rem; height: 1rem;
  cursor: pointer;
}

.style-control select {
  padding: .25rem .4rem;
  border: 1px solid var(--color-border);
  border-radius: 5px;
  font-size: .875rem;
  color: var(--color-text);
  background: #fafbfc;
  cursor: pointer;
}

.style-unit {
  font-size: .78rem;
  color: var(--color-muted);
  min-width: 2.5rem;
}

/* ---------- Panels ---------- */
.panel {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: .75rem;
}

/* ---------- Input area (contenteditable) ---------- */
.text-area {
  width: 100%;
  min-height: 160px;
  font-family: var(--font-mono);
  font-size: .9rem;
  line-height: 1.55;
  border: 1px solid var(--color-border);
  border-radius: 7px;
  padding: .7rem .85rem;
  color: var(--color-text);
  background: #fafbfc;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-word;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.text-area:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.15);
  outline: none;
  background: #fff;
}
/* Placeholder for contenteditable */
.text-area[contenteditable]:empty::before {
  content: attr(data-placeholder);
  color: var(--color-muted);
  pointer-events: none;
  display: block;
  font-style: italic;
}

/* ---------- Output box ---------- */
.output-box {
  min-height: 80px;
  font-family: var(--font-main);
  font-size: .95rem;
  line-height: 1.8;
  word-break: break-word;
  background: #f8fafc;
  border: 1px solid var(--color-border);
  border-radius: 7px;
  padding: .9rem 1rem;
  color: var(--color-text);
  overflow-x: auto;
}
/* Preserve rich formatting */
.output-box b, .output-box strong { font-weight: 700; }
.output-box i, .output-box em     { font-style: italic; }
.output-box u                      { text-decoration: underline; }
.output-box s                      { text-decoration: line-through; }
.output-box p, .output-box div     { margin: .25em 0; }

/* Formula images (PNG rendered) */
.fml-img--inline {
  display: inline-block;
  vertical-align: middle;
  max-width: 100%;
}
.fml-img--block {
  display: block;
  margin: .8em auto;
  max-width: 100%;
}

/* Fórmulas que no se pudieron renderizar */
.latex-fallback {
  background: #fef3c7;
  border: 1px solid #fcd34d;
  border-radius: 4px;
  padding: .1em .35em;
  font-family: var(--font-mono);
  font-size: .85em;
  color: #92400e;
}

/* Loading indicator */
.loading-msg {
  display: flex;
  align-items: center;
  gap: .65rem;
  color: var(--color-muted);
  font-style: italic;
  font-size: .9rem;
  padding: .4rem 0;
}
.loading-spinner {
  flex-shrink: 0;
  width: 1.1rem; height: 1.1rem;
  border: 2px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.output-box.empty {
  color: var(--color-muted);
  font-style: italic;
}

/* ---------- Output action buttons ---------- */
.output-actions {
  display: flex;
  gap: .6rem;
  flex-wrap: wrap;
}

.result-label {
  font-size: .8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--color-muted);
}

/* ---------- Buttons ---------- */
.btn {
  align-self: flex-start;
  border: none;
  border-radius: 7px;
  padding: .55rem 1.25rem;
  font-size: .92rem;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition), transform var(--transition), opacity var(--transition);
}

.btn:active { transform: scale(.97); }

.btn-primary {
  background: var(--color-primary);
  color: #fff;
}
.btn-primary:hover { background: var(--color-primary-h); }

.btn-secondary {
  background: var(--color-secondary);
  color: #fff;
}
.btn-secondary:hover:not(:disabled) { background: var(--color-secondary-h); }
.btn-secondary:disabled {
  opacity: .45;
  cursor: not-allowed;
}

.btn.copied {
  background: var(--color-success);
}

.btn-outline {
  background: transparent;
  color: var(--color-secondary);
  border: 1.5px solid var(--color-border);
}
.btn-outline:hover:not(:disabled) {
  background: var(--color-bg);
  border-color: var(--color-secondary);
}
.btn-outline:disabled { opacity: .4; cursor: not-allowed; }

/* ---------- Help panel ---------- */
.help-panel {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  box-shadow: var(--shadow);
}

.help-heading {
  font-size: .92rem;
  font-weight: 700;
  margin-bottom: .6rem;
  color: var(--color-muted);
  text-transform: uppercase;
  letter-spacing: .05em;
}

.help-links {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: .5rem 1.25rem;
}

.help-links a {
  font-size: .9rem;
  color: var(--color-primary);
  text-decoration: none;
  transition: color var(--transition);
}
.help-links a:hover { color: var(--color-primary-h); text-decoration: underline; }

/* ---------- Footer ---------- */
.app-footer {
  text-align: center;
  font-size: .8rem;
  color: var(--color-muted);
  padding: 1rem;
  border-top: 1px solid var(--color-border);
}
.app-footer a {
  color: var(--color-primary);
  text-decoration: none;
}
.app-footer a:hover { text-decoration: underline; }

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
  /* Stack panels vertically on mobile/tablet */
  .panels-row {
    flex-direction: column;
  }

  /* Allow modes to wrap on small screens */
  .mode-fieldset {
    flex-wrap: wrap;
    gap: .6rem 1.25rem;
  }
  .mode-label { white-space: normal; }
}

@media (max-width: 500px) {
  .app-title    { font-size: 1.1rem; }
  .header-inner { gap: .65rem; }
  .logo         { width: 32px; height: 32px; }
}
