:root {
  --bg: #0f172a; /* slate-900 */
  --card: #111827; /* gray-900  */
  --muted: #64748b; /* slate-500 */
  --text: #e5e7eb; /* gray-200  */
  --accent: #22d3ee; /* cyan-400  */
  --btn: #1f2937; /* gray-800  */
  --border: #334155; /* slate-700 */
  --good: #22c55e; /* green-500 */
  --warn: #f59e0b; /* amber-500 */
}
* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell,
    Noto Sans, "Helvetica Neue", Arial, "Apple Color Emoji", "Segoe UI Emoji";
}

header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(15, 23, 42, 0.75);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--border);
}

.wrap {
  max-width: 1300px;
  margin: 0 auto;
  padding: 12px 16px;
}

.toolbar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}
.toolbar .spacer { flex: 1; }

button,
label.btn {
  background: var(--btn);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 10px 12px;
  border-radius: 12px;
  cursor: pointer;
  font: inherit;
}
button:hover,
label.btn:hover { outline: 1px solid var(--accent); }

/* Control propio del focus para evitar punteado del navegador */
button:focus { outline: none; }
button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

input[type="file"] { display: none; }

main {
  max-width: 1300px;
  margin: 16px auto;
  padding: 0 16px;
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 16px;
  align-items: stretch;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  min-height: 0;              /* permite que los hijos con overflow se compriman */
}

h2 {
  margin: 4px 0 10px 0;
  font-size: 16px;
  color: var(--accent);
  letter-spacing: 0.2px;
}

textarea {
  width: 100%;
  min-height: 240px;
  background: #0b1023;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px;
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas,
    "Liberation Mono", "Courier New", monospace;
  line-height: 1.4;
}

.small {
  font-size: 12px;
  color: var(--muted);
  flex: 0 0 auto;
}

/* ========== Lista de plantillas ========== */
.list{
  display:flex;
  flex-direction:column;
  gap:8px;
  border:1px solid var(--border);
  border-radius:12px;
  padding:8px;

  flex:1;
  min-height:0;
  overflow-y:auto;
  overflow-x:hidden;
}

.list .tpl-row{
  display:grid;
  grid-template-columns: 1fr;         /* una sola columna */
  grid-template-rows: auto auto;      /* nombre, luego acciones */
  grid-template-areas:
    "name"
    "actions";
  gap:6px;
  align-items:start;
  padding:10px 12px;
  border:1px dashed var(--border);
  border-radius:10px;
}

.list .tpl-row:hover{
  border-color: var(--accent);
  background: rgba(34,211,238,0.06);
}

.list .tpl-row .name{
  grid-area:name;
  min-width:0;
  overflow:hidden;
  text-overflow:ellipsis;
  white-space:nowrap;
  font-weight:500;
}

/* Acciones debajo del nombre */
.list .tpl-actions{
  grid-area:actions;
  display:flex;
  gap:8px;
  flex-wrap:wrap;                 /* si no caben, saltan de línea */
  justify-content:flex-end;       /* botones a la derecha */
}

.list .tpl-actions button{
  padding:6px 10px;
  border-radius:8px;
  line-height:1;
  font-size:12px;
  white-space:nowrap;
}

.list .tpl-row:hover {
  border-color: var(--accent);
  background: rgba(34, 211, 238, 0.06);
}

/* Botón icónico opcional */
.btn-icon {
  width: 32px; height: 32px;
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0;
}

.metrics {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 8px;
}
.pill {
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 10px;
}
.pill.good { border-color: var(--good); color: var(--good); }
.pill.warn { border-color: var(--warn); color: var(--warn); }

footer {
  max-width: 1300px;
  margin: 6px auto 24px;
  padding: 0 16px;
  color: var(--muted);
  text-align: right;
}

.output { min-height: 260px; }

/* --- Toast --- */
#toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 9999;
  pointer-events: none;
}
.toast-bubble {
  pointer-events: auto;
  padding: 10px 12px;
  margin-top: 8px;
  background: rgba(17, 24, 39, 0.95);
  color: #e5e7eb;
  border: 1px solid #334155;
  border-radius: 10px;
  font-size: 14px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.35);
  opacity: 0;
  transform: translateY(10px);
  transition: opacity .2s ease, transform .2s ease;
}
.toast-bubble.show {
  opacity: 1;
  transform: translateY(0);
}

/* ===== Modal Editor ===== */
.modal{ position:fixed; inset:0; display:none; z-index:9998; }
.modal[aria-hidden="false"]{ display:block; }
.modal-backdrop{ position:absolute; inset:0; background:rgba(0,0,0,.45); }
.modal-card{
  position:relative; z-index:1; max-width:1100px; width:calc(100% - 32px);
  max-height:90vh; margin:5vh auto; background:var(--card);
  border:1px solid var(--border); border-radius:14px; box-shadow:0 20px 60px rgba(0,0,0,.45);
  display:flex; flex-direction:column;
}
.modal-head{ display:flex; align-items:center; gap:8px; padding:12px 14px; border-bottom:1px solid var(--border); }
.modal-head h2{ margin:0; font-size:18px; }
.icon-btn{ background:transparent; border:1px solid var(--border); border-radius:8px; padding:6px 10px; color:var(--text); cursor:pointer; }
.icon-btn:hover{ border-color:var(--accent); }
.modal-toolbar{
  display:flex; align-items:center; gap:10px; padding:10px 14px; border-bottom:1px solid var(--border);
}
.modal-toolbar .spacer{ flex:1; }
.modal-card button.primary{
  background:var(--accent); color:#081318; border:none; border-radius:10px;
  padding:8px 12px; font-weight:600; cursor:pointer;
}
.modal-card button.primary:hover{ filter:brightness(1.05); }

.editor{
  margin:12px 14px; padding:12px; background:#0b1023; border:1px solid var(--border);
  border-radius:12px; min-height:320px; overflow:auto; white-space:pre-wrap; font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas,"Liberation Mono","Courier New",monospace;
  line-height:1.4;
}
.editor strong{ font-weight:700; }

/* --- MODIFICADO: Estilo de resaltado mejorado --- */
.editor mark.add{ 
  background: rgba(34, 211, 238, 0.3); /* Usa el color --accent (cyan) con opacidad */
  color: inherit; /* Mantiene el color del texto normal */
  text-decoration: none; /* Quita cualquier subrayado por defecto del <mark> */
  box-decoration-break: clone; /* Asegura que el fondo se dibuje correctamente en saltos de línea */
  /* Se eliminaron 'border-radius' y 'padding' para lograr el efecto de línea continua */
}
.editor del.del{ color:#94a3b8; text-decoration:line-through; }

/* --- Mic button / state --- */
.mic-btn {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--btn); border: 1px solid var(--border);
  padding: 8px 10px; border-radius: 10px; cursor: pointer;
}
.mic-btn.active { outline: 2px solid var(--accent); }
.mic-dot {
  width: 8px; height: 8px; border-radius: 999px;
  background: var(--accent); box-shadow: 0 0 0 0 rgba(34, 211, 238, 0.7);
  animation: mic-pulse 1.1s infinite;
}
@keyframes mic-pulse {
  0% { box-shadow: 0 0 0 0 rgba(34, 211, 238, 0.7); }
  70% { box-shadow: 0 0 0 8px rgba(34, 211, 238, 0); }
  100% { box-shadow: 0 0 0 0 rgba(34, 211, 238, 0); }
}
.mic-hint { font-size: 12px; color: var(--muted); margin-left: 8px; }


/* Responsive: acciones abajo en móviles */
@media (max-width: 640px){
  .list .tpl-row{ grid-template-columns: 1fr !important; }
  .list .tpl-actions{ justify-content: flex-end; }
}
