/* Modeltex AI API — sistema visual "Hilo": moldería + tecnología.
   Motivos: tapete de corte (grilla), costuras (líneas punteadas), muescas, hilo del tejido, nodos de datos. */

:root {
  color-scheme: dark;
  --bg: #0a0c10;
  --bg-2: #0e1116;
  --surface: #131720;
  --surface-2: #1a1f2a;
  --line: #262c39;
  --line-strong: #3a4354;
  --grid: rgba(255, 255, 255, 0.035);
  --grid-strong: rgba(255, 255, 255, 0.07);
  --text: #ece8df;
  --text-2: #b0b7c4;
  --text-3: #8a93a3;
  --accent: #d7f75b;
  --accent-ink: #11160a;
  --accent-text: #d7f75b;
  --accent-soft: rgba(215, 247, 91, 0.12);
  --cut: #ff6a4d;
  --data: #6cc4ff;
  --ok: #5ee0a0;
  --warn: #ffcf5c;
  --danger: #ff7a62;
  --focus: #d7f75b;
  --shadow: 0 1px 0 rgba(255, 255, 255, 0.04) inset, 0 20px 40px -24px rgba(0, 0, 0, 0.7);
  --radius: 14px;
  --radius-sm: 9px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --gutter: 16px;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    color-scheme: light;
    --bg: #f4f1ea;
    --bg-2: #ece8de;
    --surface: #fffdf8;
    --surface-2: #f8f4ea;
    --line: #ddd6c6;
    --line-strong: #bdb49f;
    --grid: rgba(20, 22, 27, 0.045);
    --grid-strong: rgba(20, 22, 27, 0.09);
    --text: #14161b;
    --text-2: #444b59;
    --text-3: #626a79;
    --accent-text: #3f5a00;
    --accent-soft: rgba(120, 160, 0, 0.14);
    --cut: #d6391b;
    --data: #0a6fb8;
    --ok: #0b7a46;
    --warn: #946200;
    --danger: #c42d12;
    --focus: #3f5a00;
    --shadow: 0 1px 0 rgba(255, 255, 255, 0.7) inset, 0 18px 36px -26px rgba(40, 30, 10, 0.35);
  }
}
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f4f1ea;
  --bg-2: #ece8de;
  --surface: #fffdf8;
  --surface-2: #f8f4ea;
  --line: #ddd6c6;
  --line-strong: #bdb49f;
  --grid: rgba(20, 22, 27, 0.045);
  --grid-strong: rgba(20, 22, 27, 0.09);
  --text: #14161b;
  --text-2: #444b59;
  --text-3: #626a79;
  --accent-text: #3f5a00;
  --accent-soft: rgba(120, 160, 0, 0.14);
  --cut: #d6391b;
  --data: #0a6fb8;
  --ok: #0b7a46;
  --warn: #946200;
  --danger: #c42d12;
  --focus: #3f5a00;
  --shadow: 0 1px 0 rgba(255, 255, 255, 0.7) inset, 0 18px 36px -26px rgba(40, 30, 10, 0.35);
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
img, svg { max-width: 100%; display: block; }
a { color: var(--accent-text); text-underline-offset: 3px; }
a:hover { text-decoration-thickness: 2px; }
h1, h2, h3, h4 { line-height: 1.12; letter-spacing: -0.02em; margin: 0 0 0.5em; font-weight: 650; }
h1 { font-size: clamp(2.2rem, 5.4vw, 4.1rem); }
h2 { font-size: clamp(1.7rem, 3.4vw, 2.5rem); }
h3 { font-size: 1.15rem; }
p { margin: 0 0 1em; }
code, kbd, pre, samp { font-family: var(--mono); font-size: 0.92em; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; border-radius: 4px; }
::selection { background: var(--accent); color: var(--accent-ink); }

.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip-link { position: absolute; left: 12px; top: -60px; background: var(--accent); color: var(--accent-ink); padding: 10px 14px; border-radius: 8px; z-index: 100; font-weight: 600; }
.skip-link:focus { top: 12px; }
.wrap { width: 100%; max-width: 1180px; margin-inline: auto; padding-inline: var(--gutter); }

/* ---------- Tapete de corte + costuras ---------- */
.mat {
  background-image:
    linear-gradient(var(--grid-strong) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-strong) 1px, transparent 1px),
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 120px 120px, 120px 120px, 24px 24px, 24px 24px;
  background-position: -1px -1px;
}
.stitch { border: 0; border-top: 2px dashed var(--line-strong); margin: 0; opacity: 0.7; }
.label {
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-3);
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.label::before { content: ""; width: 0; height: 0; border-left: 5px solid transparent; border-right: 5px solid transparent; border-bottom: 8px solid var(--accent); }
.muted { color: var(--text-2); }
.faint { color: var(--text-3); }
.mono { font-family: var(--mono); }
.nowrap { white-space: nowrap; }

/* ---------- Botones ---------- */
.btn {
  --btn-bg: var(--surface-2);
  --btn-fg: var(--text);
  --btn-bd: var(--line-strong);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 18px;
  background: var(--btn-bg); color: var(--btn-fg);
  border: 1px solid var(--btn-bd); border-radius: 999px;
  font: inherit; font-weight: 600; font-size: 0.95rem; line-height: 1;
  text-decoration: none; cursor: pointer;
  transition: transform 0.12s ease, background-color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}
.btn:hover { border-color: var(--text-3); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn[disabled], .btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn-primary { --btn-bg: var(--accent); --btn-fg: var(--accent-ink); --btn-bd: var(--accent); }
.btn-primary:hover { box-shadow: 0 0 0 4px var(--accent-soft); border-color: var(--accent); }
.btn-ghost { --btn-bg: transparent; }
.btn-danger { --btn-bg: transparent; --btn-fg: var(--danger); --btn-bd: color-mix(in srgb, var(--danger) 50%, transparent); }
.btn-sm { min-height: 36px; padding: 0 14px; font-size: 0.85rem; }
.btn-block { width: 100%; }
.btn .spinner { width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Formularios ---------- */
.field { display: grid; gap: 6px; margin-bottom: 16px; }
.field > label, .field > .field-label { font-size: 0.85rem; font-weight: 600; color: var(--text-2); }
.hint { font-size: 0.82rem; color: var(--text-3); }
.input, select.input, textarea.input {
  width: 100%; min-height: 44px; padding: 10px 14px;
  background: var(--bg-2); color: var(--text);
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  font: inherit;
}
textarea.input { min-height: 120px; resize: vertical; line-height: 1.5; }
.input::placeholder { color: var(--text-3); }
.input:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; border-color: transparent; }
.input[aria-invalid="true"] { border-color: var(--danger); }
.field-error { color: var(--danger); font-size: 0.85rem; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.row > .grow { flex: 1 1 200px; }
.checkbox { display: flex; align-items: flex-start; gap: 10px; font-size: 0.92rem; }
.checkbox input { width: 18px; height: 18px; margin-top: 3px; accent-color: var(--accent); }

/* ---------- Tarjetas / piezas de molde ---------- */
.card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
}
/* muescas de la pieza de molde */
.card.notched::before, .card.notched::after {
  content: ""; position: absolute; top: -1px; width: 0; height: 0;
  border-left: 5px solid transparent; border-right: 5px solid transparent; border-top: 7px solid var(--bg);
}
.card.notched::before { left: 28px; }
.card.notched::after { right: 28px; }
.card h3 { margin-bottom: 0.35em; }
.card-grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr)); }

.badge { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: 0.75rem; font-weight: 600; border: 1px solid var(--line-strong); color: var(--text-2); white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, transparent); }
.badge.warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 40%, transparent); }
.badge.err { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, transparent); }
.badge.plain::before { display: none; }

.notice { border: 1px dashed var(--line-strong); border-radius: var(--radius-sm); padding: 14px 16px; background: var(--surface-2); font-size: 0.92rem; color: var(--text-2); }
.notice.warn { border-color: color-mix(in srgb, var(--warn) 55%, transparent); }
.notice.err { border-color: color-mix(in srgb, var(--danger) 55%, transparent); color: var(--text); }
.notice strong { color: var(--text); }

/* ---------- Código ---------- */
.code {
  position: relative; background: #07090c; color: #e7e3d8; border: 1px solid var(--line);
  border-radius: var(--radius-sm); overflow: hidden;
}
:root[data-theme="light"] .code { background: #14161b; }
@media (prefers-color-scheme: light) { :root:not([data-theme="dark"]) .code { background: #14161b; } }
.code pre { margin: 0; padding: 18px 16px; overflow-x: auto; font-size: 0.85rem; line-height: 1.65; tab-size: 2; }
.code .code-bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 8px 6px 14px; border-bottom: 1px solid rgba(255, 255, 255, 0.08); font-family: var(--mono); font-size: 0.72rem; color: #8a93a3; letter-spacing: 0.08em; text-transform: uppercase; }
.code .tok-k { color: #d7f75b; }
.code .tok-s { color: #9fe3b9; }
.code .tok-c { color: #6b7587; }
.code .tok-n { color: #6cc4ff; }
.copy-btn {
  display: inline-flex; align-items: center; gap: 6px; min-height: 32px; padding: 0 12px;
  background: rgba(255, 255, 255, 0.08); color: #e7e3d8; border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 999px; font: inherit; font-family: var(--font); font-size: 0.78rem; font-weight: 600; cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease, transform 0.12s ease;
}
.copy-btn:hover { background: rgba(255, 255, 255, 0.16); }
.copy-btn:focus-visible { outline-color: #d7f75b; }
.copy-btn.copied { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); animation: pop 0.25s ease; }
@keyframes pop { 0% { transform: scale(0.94); } 60% { transform: scale(1.05); } 100% { transform: scale(1); } }
.inline-code { background: var(--surface-2); border: 1px solid var(--line); border-radius: 6px; padding: 1px 6px; font-family: var(--mono); font-size: 0.88em; }

.tabs { display: flex; gap: 4px; flex-wrap: wrap; border-bottom: 1px solid var(--line); margin-bottom: 14px; }
.tab {
  background: none; border: 0; border-bottom: 2px solid transparent; color: var(--text-3);
  font: inherit; font-weight: 600; font-size: 0.9rem; padding: 10px 14px; min-height: 44px; cursor: pointer; margin-bottom: -1px;
}
.tab:hover { color: var(--text); }
.tab[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }
.codetabs .tabs { margin-bottom: 0; border-bottom: 0; }

/* ---------- Tablas ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th { text-align: left; font-family: var(--mono); font-size: 0.7rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--text-3); font-weight: 500; padding: 12px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.empty { padding: 36px 20px; text-align: center; color: var(--text-3); }

/* ---------- Diálogos y avisos ---------- */
dialog {
  background: var(--surface); color: var(--text); border: 1px solid var(--line-strong); border-radius: var(--radius);
  padding: 0; width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 32px); box-shadow: 0 40px 80px -30px rgba(0, 0, 0, 0.8);
}
dialog::backdrop { background: rgba(5, 7, 10, 0.72); backdrop-filter: blur(3px); }
.dialog-body { padding: 24px; overflow-y: auto; max-height: calc(100vh - 120px); }
.dialog-actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; margin-top: 20px; }

.toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 200; max-width: calc(100vw - 32px); }
.toast { background: var(--surface-2); border: 1px solid var(--line-strong); border-left: 3px solid var(--accent); border-radius: 10px; padding: 12px 16px; box-shadow: var(--shadow); font-size: 0.92rem; animation: toast-in 0.2s ease; }
.toast.err { border-left-color: var(--danger); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- Ayuda en lenguaje simple ---------- */
details.help { display: inline-block; vertical-align: baseline; }
details.help > summary {
  list-style: none; cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
  width: 20px; height: 20px; border-radius: 50%; border: 1px solid var(--line-strong); color: var(--text-3);
  font-size: 0.72rem; font-weight: 700; user-select: none;
}
details.help > summary::-webkit-details-marker { display: none; }
details.help[open] > summary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
details.help > p { margin: 8px 0 0; padding: 10px 12px; max-width: 340px; background: var(--surface-2); border: 1px dashed var(--line-strong); border-radius: 8px; font-size: 0.85rem; color: var(--text-2); font-weight: 400; line-height: 1.5; }

/* ---------- Indicadores ---------- */
.meter { display: inline-flex; gap: 3px; vertical-align: middle; }
.meter i { width: 14px; height: 6px; border-radius: 2px; background: var(--line-strong); }
.meter i.on { background: var(--accent-text); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; scroll-behavior: auto !important; }
}

/* utilidades (sin estilos en línea por la CSP) */
.mt-s { margin-top: 10px; }
.mt-m { margin-top: 20px; }
.mb-0 { margin-bottom: 0 !important; }
.narrow { max-width: 860px !important; }
.hidden { display: none !important; }
.btn svg { width: 16px; height: 16px; flex: none; }
details.adv > summary::after { content: "▾"; margin-left: 8px; color: var(--text-3); transition: transform 0.15s ease; }
details.adv:not([open]) > summary::after { transform: rotate(-90deg); }
details.adv > summary { list-style: none; }
details.adv > summary::-webkit-details-marker { display: none; }
.icon-btn { width: 44px; height: 44px; display: inline-grid; place-items: center; background: transparent; color: var(--text-2); border: 1px solid var(--line); border-radius: 999px; font-size: 1.05rem; cursor: pointer; font-family: inherit; }
.icon-btn:hover { color: var(--text); border-color: var(--text-3); }
main:focus { outline: none; }
dialog h2.dlg-h { font-size: 1.35rem; margin-bottom: 0.6em; }
