/* EscribIQ — estilos. Todos los colores salen de variables: cada cliente puede tunearlas
   desde el panel de admin (tema por cliente). Valores base: paleta Tierra Firme, tenue. */

:root {
  --bg: #faf6ef;          /* fondo de página (sand-50) */
  --surface: #ffffff;     /* tarjetas */
  --text: #1d1c1b;        /* texto principal (stone-900) */
  --muted: #6a645c;       /* texto secundario (stone-500) */
  --border: #e9e5e0;      /* bordes (stone-100) */
  --accent: #b5571a;      /* botón principal (clay-700) */
  --accentText: #ffffff;  /* texto sobre el acento */
  --soft: #f3ebdd;        /* fondos suaves, pestaña activa (sand-100) */
  --danger: #b3261e;
  --radius: 14px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-mode="light"]) {
    --bg: #1d1c1b; --surface: #2d2c2a; --text: #faf6ef; --muted: #b3aca1;
    --border: #403f3d; --accent: #f6953f; --accentText: #1d1c1b; --soft: #403f3d;
    color-scheme: dark;
  }
}
:root[data-mode="dark"] {
  --bg: #1d1c1b; --surface: #2d2c2a; --text: #faf6ef; --muted: #b3aca1;
  --border: #403f3d; --accent: #f6953f; --accentText: #1d1c1b; --soft: #403f3d;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--font); font-size: 16px; line-height: 1.45;
  background: var(--bg); color: var(--text);
  min-height: 100dvh; display: flex; flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button, textarea, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }

.wrap { width: 100%; max-width: 640px; margin: 0 auto; padding: 0 14px; }

/* Encabezado */
.top { display: flex; align-items: center; justify-content: space-between; padding: 14px 0 10px; }
.brand { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.logo { font-size: 22px; font-weight: 700; letter-spacing: -0.3px; }
.logo b { color: var(--accent); }
.tenant { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ver { font-size: 11px; color: var(--muted); opacity: .8; }
.top-right { display: flex; align-items: center; gap: 6px; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--border); background: var(--surface);
  display: inline-flex; align-items: center; justify-content: center; color: var(--muted); padding: 0;
}
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn[aria-pressed="true"] { background: var(--soft); color: var(--text); }

/* Ayuda */
.help-doc h3 { font-size: 15px; margin: 16px 0 6px; }
.help-doc h3:first-child { margin-top: 0; }
.help-doc ul { margin: 0; padding-left: 18px; }
.help-doc li { margin: 4px 0; color: var(--text); }
.help-doc p { margin: 6px 0; color: var(--muted); }
.help-answer { white-space: pre-wrap; background: var(--soft); border-radius: 10px; padding: 12px; margin-top: 12px; }
.help-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.help-head h2 { font-size: 17px; margin: 0; }

/* Pestañas */
.tabs { display: flex; gap: 4px; background: var(--surface); border: 1px solid var(--border); border-radius: 999px; padding: 4px; margin-bottom: 12px; }
.tabs button { flex: 1; border: 0; background: transparent; padding: 9px 6px; border-radius: 999px; font-size: 14px; color: var(--muted); }
.tabs button[aria-selected="true"] { background: var(--soft); color: var(--text); font-weight: 600; }

/* Tarjetas */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.label { display: block; font-size: 13px; color: var(--muted); margin: 0 0 6px 2px; }
.label + .label { margin-top: 12px; }

textarea {
  width: 100%; resize: vertical; min-height: 110px; max-height: 60vh;
  border: 1px solid var(--border); border-radius: 10px; background: var(--bg);
  padding: 12px; font-size: 16px; line-height: 1.45; outline: none;
}
textarea:focus { border-color: var(--accent); }
textarea.small { min-height: 80px; }
.field + .field { margin-top: 12px; }

/* Herramientas bajo la caja */
.tools { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.tool {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--border); background: transparent; border-radius: 999px;
  padding: 7px 12px; font-size: 14px; color: var(--muted);
}
.tool svg { width: 16px; height: 16px; }
.tool.rec { border-color: var(--danger); color: var(--danger); font-weight: 600; }
.tool.rec .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--danger); animation: pulse 1s infinite; }
.tool.busy { opacity: .6; pointer-events: none; }
@keyframes pulse { 50% { opacity: .25; } }

/* Chips (idioma, tipo de texto) */
.chips { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin-top: 12px; }
.chips .chips-label { font-size: 13px; color: var(--muted); margin-right: 2px; }
.chip { border: 1px solid var(--border); background: transparent; border-radius: 999px; padding: 6px 12px; font-size: 14px; color: var(--muted); }
.chip[aria-pressed="true"] { background: var(--soft); color: var(--text); border-color: var(--soft); font-weight: 600; }
.chips.first { margin-top: 0; margin-bottom: 12px; }

/* Botones de acción */
.actions { display: flex; gap: 8px; margin-top: 14px; }
.actions button { flex: 1; }
.primary, .secondary {
  border-radius: 12px; padding: 13px 14px; font-size: 16px; font-weight: 600;
  display: inline-flex; justify-content: center; align-items: center; gap: 8px;
}
.primary { background: var(--accent); color: var(--accentText); border: 1px solid var(--accent); }
.secondary { background: transparent; color: var(--text); border: 1px solid var(--border); }
.primary:disabled, .secondary:disabled { opacity: .55; cursor: default; }
.primary svg, .secondary svg { width: 18px; height: 18px; }
.spin { width: 16px; height: 16px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: rot .7s linear infinite; }
@keyframes rot { to { transform: rotate(360deg); } }

/* Resultado */
.result .res-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.result .res-title { font-size: 13px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .4px; }
.result textarea { background: var(--surface); min-height: 60px; }
.res-block + .res-block { margin-top: 16px; padding-top: 14px; border-top: 1px dashed var(--border); }
.res-actions { display: flex; gap: 8px; margin-top: 10px; }
.res-actions button { flex: 1; }
.link-btn { border: 0; background: none; color: var(--muted); font-size: 13px; text-decoration: underline; padding: 2px; }

/* Sin acceso */
.center { text-align: center; padding: 26px 18px; }
.center h1 { font-size: 20px; margin: 0 0 8px; }
.center p { color: var(--muted); margin: 0 0 16px; }
.center input { width: 100%; border: 1px solid var(--border); border-radius: 10px; padding: 12px; background: var(--bg); margin-bottom: 10px; }

/* Aviso flotante */
#toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: .2s; max-width: 90vw; text-align: center; z-index: 10;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.err { background: var(--danger); color: #fff; }

/* Pie Tierra Firme — siempre visible */
.foot {
  margin-top: auto; padding: 18px 0 calc(16px + env(safe-area-inset-bottom));
  display: flex; align-items: center; justify-content: center; gap: 10px;
  font-size: 11.5px; color: var(--muted); flex-wrap: wrap; opacity: .85;
}
.foot a { color: inherit; text-decoration: none; }
.foot a:hover { text-decoration: underline; }
.foot img { height: 28px; border-radius: 3px; width: auto; display: block; }
.foot .sep { opacity: .5; }

/* Admin */
.admin table { width: 100%; border-collapse: collapse; font-size: 14px; }
.admin th, .admin td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.admin th { font-size: 12px; color: var(--muted); font-weight: 600; }
.admin input[type=text], .admin input[type=password], .admin input[type=number], .admin select {
  width: 100%; border: 1px solid var(--border); border-radius: 10px; padding: 10px; background: var(--bg);
}
.admin .row { display: flex; gap: 8px; align-items: end; flex-wrap: wrap; }
.admin .row > * { flex: 1; min-width: 140px; }
.admin .row > label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.admin .row > label input, .admin .row > label select { color: var(--text); font-size: 15px; }
.admin h2 { font-size: 16px; margin: 0 0 12px; }
.admin .mini { padding: 6px 10px; font-size: 13px; border-radius: 8px; }
.admin .muted { color: var(--muted); font-size: 13px; }
.admin .off td { opacity: .5; }
.colors { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.colors label { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.colors input[type=color] { width: 38px; height: 30px; border: 1px solid var(--border); border-radius: 6px; padding: 0; background: none; }
.linkbox { word-break: break-all; background: var(--soft); border-radius: 10px; padding: 10px; font-size: 13px; margin-top: 10px; }
