: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 */
  --content-max: 1680px;
  --gutter: 20px;
}
* { box-sizing: border-box; }
:root{
  --org-width: 260px;
  --org-width-edit: 460px;
}

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: var(--content-max);
  margin: 0 auto;
  padding: 14px var(--gutter);
}

.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: var(--content-max);
  margin: 20px auto;
  padding: 0 var(--gutter);
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: 20px;
  align-items: stretch;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  position: relative;
}

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

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

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

#micReportBtn {
  position: absolute;
  bottom: 12px;   /* separación del borde inferior */
  right: 16px;    /* separación del borde derecho */
  z-index: 5;     /* encima del contenido */
}

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

  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;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.pill {
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 12px;
  font-size: 14px;
}
.pill.good { border-color: var(--good); color: var(--good); }
.pill.warn { border-color: var(--warn); color: var(--warn); }

footer {
  background: #0f172a;
  color: #e5e7eb;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 15px 30px;
  font-size: 0.9rem;
}

.footer-logo img {
  height: 32px;
  width: auto;
}

.footer-text {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 400;
}

.footer-text .brand {
  font-weight: 600;
  color: #22d3ee; /* cyan para resaltar */
  letter-spacing: 0.5px;
}

.footer-text .year {
  color: #94a3b8; /* gris suave */
}

.footer-text .author {
  font-style: italic;
  color: #cbd5e1;
}

.footer-text .version {
  color: #f59e0b; /* ámbar para resaltar la versión */
}

.output { min-height: 260px; }

div.output {
    background: #0b1023;
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 10px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
    line-height: 1.4;
    white-space: pre-wrap; /* Respeta los saltos de línea */
    word-wrap: break-word; /* Evita que el texto se desborde */
    overflow-y: auto;     /* Añade scroll si el contenido es largo */
    cursor: text;
}

/* Estilo para el placeholder del div */
div.output:empty:before {
    content: attr(placeholder);
    color: var(--muted);
    pointer-events: none;
}

/* --- NUEVO: Resaltado ámbar para las mayúsculas originales en la SALIDA --- */
.output .original-upper {
    color: var(--warn); /* color ámbar */
    font-weight: bold;
}

/* --- 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:1400px; width:calc(100% - 48px);
  max-height:92vh; margin:4vh 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:14px; background:#0b1023; border:1px solid var(--border);
  border-radius:12px; min-height: clamp(360px, 60vh, 740px);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas,"Liberation Mono","Courier New",monospace;
  overflow:auto; white-space:pre-wrap;
  line-height:1.55;
  font-size: 16px;
}
.editor strong{ font-weight:700; }

.editor .original-upper {
    color: var(--warn);
    font-weight: inherit;   /* <strong> ya no se ve en negrita */
    background: transparent;
    padding: 0;
    border-radius: 0;
    box-decoration-break: initial;
}


/* --- 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 */
  display: inline;
  white-space: pre-wrap;

}
.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;
}

/* --- Estilos para el Switch de Configuración --- */
.setting-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
}

.setting-row h4 {
    margin: 0 0 4px 0;
    color: var(--text);
}

.switch-container {
    display: flex;
    align-items: center;
    gap: 8px;
}

.switch-label {
    font-size: 14px;
    color: var(--muted);
}

.switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 28px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--btn);
    border: 1px solid var(--border);
    transition: .4s;
    border-radius: 28px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 20px;
    width: 20px;
    left: 3px;
    bottom: 3px;
    background-color: var(--muted);
    transition: .4s;
    border-radius: 50%;
}

input:checked + .slider {
    background-color: var(--accent);
}

input:checked + .slider:before {
    background-color: var(--card);
    transform: translateX(22px);
}

#helpBody h3 { margin: 12px 0 6px; color: var(--accent); }
#helpBody p, #helpBody li { color: var(--text); }
#helpBody code { background:#0b1023; padding:2px 6px; border-radius:6px; border:1px solid var(--border); }
#helpBody .kbd { border:1px solid var(--border); border-bottom-width:2px; padding:2px 6px; border-radius:6px; font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; }

.mic-hint { font-size: 12px; color: var(--muted); margin-left: 8px; }

#metrics > div {
  display: flex;
  align-items: center;  /* centra verticalmente texto con botón */
  gap: 8px;             /* espacio fijo entre botón y texto */
  margin-top: 6px;      /* un poco de separación respecto a las pills */
}

/* ===== Panel de �rganos (flyout izquierda) ===== */
:root{
  --org-width: 260px;
  --org-width-edit: 460px;
  --org-top: 98px;
}

.org-panel{
  position:absolute;
  top: var(--org-top);
  bottom: 14px;
  left: 14px;
  width: var(--org-width);
  background: var(--card);
  border:1px solid var(--border);
  border-radius:12px;
  box-shadow:0 10px 30px rgba(0,0,0,.35);
  padding:10px;
  z-index:5;
  display:none;
}
.modal-card.show-orgs .org-panel{ display:block; }
.modal-card.show-orgs .org-panel.editing{ width: var(--org-width-edit); }

.modal-card .editor-wrap{
  position:relative;
  margin-left:0;
  transition: margin .22s ease;
  flex:1; min-height:0;
  overflow-y:auto; overflow-x:hidden;
}
.modal-card.show-orgs .editor-wrap{ margin-left: calc(var(--org-width) + 20px); }
.modal-card.show-orgs.edit-mode .editor-wrap{ margin-left: calc(var(--org-width-edit) + 20px); }/* cabecera del panel / lista / editor diccionario (igual que antes) */
.org-head{ display:flex; align-items:center; gap:8px; padding:6px 4px 10px; border-bottom:1px solid var(--border); }
.org-head .spacer{ flex:1; }
.org-list{ margin-top:8px; display:flex; flex-direction:column; gap:6px; max-height: 55vh; overflow:auto; }
.org-item{ display:flex; align-items:center; gap:8px; border:1px solid var(--border); border-radius:10px; padding:8px 10px; cursor:pointer; background:#0c1226; }
.org-item:hover{ border-color: var(--accent); }
.org-item .dot{ width:10px; height:10px; border-radius:999px; flex:0 0 auto; background: var(--accent); }
.org-item .name{ font-weight:600; }
.org-item .count{ display:none; }
.org-editor{ margin-top:10px; border-top:1px dashed var(--border); padding-top:10px; }
.org-editor textarea{ width:100%; min-height:200px; background:#0b1023; color:var(--text); border:1px solid var(--border); border-radius:10px; padding:10px; font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; }
.org-actions{ display:flex; gap:8px; margin-top:8px; }

/* resaltado dentro del editor */
.org-hit{ background: rgba(168, 85, 247, .28); border-bottom: 1px dashed rgba(168, 85, 247, .8); border-radius:3px; padding:0 2px; }
.org-hit.c0{ background: rgba(34,211,238,.25); border-bottom-color: rgba(34,211,238,.8); }
.org-hit.c1{ background: rgba(16,185,129,.25); border-bottom-color: rgba(16,185,129,.8); }
.org-hit.c2{ background: rgba(251,191,36,.25); border-bottom-color: rgba(251,191,36,.8); }
.org-hit.c3{ background: rgba(244,114,182,.25); border-bottom-color: rgba(244,114,182,.8); }
.org-hit.c4{ background: rgba(248,113,113,.25); border-bottom-color: rgba(248,113,113,.8); }
.org-hit.c5{ background: rgba(147,197,253,.25); border-bottom-color: rgba(147,197,253,.8); }

/* handle/asa para abrir/cerrar desde el rail */
.org-handle{ display:none !important; }
.org-handle:hover{ outline: 1px solid var(--accent); }

/* Envoltura para poder posicionar el overlay */
.editor-wrap { position: relative; }

/* Asegura que el editor respete saltos y calce con el overlay */
.editor{
  white-space: pre-wrap;
  line-height: 1.55;
  padding: 12px 14px;
  min-height: 260px;
}

/* Overlay posicionado por JS para calzar 1:1 con el editor */
.org-overlay{
  position: absolute;
  pointer-events: none;          /* NO bloquear el teclado ni clics */
  white-space: pre-wrap;         /* respeta saltos */
  font: inherit;                 /* misma fuente */
  line-height: inherit;          /* igual al editor */
  color: transparent;            /* s�lo se ve el fondo de los hits */
  z-index: 2;
}

/* Reusa tus colores por clase c0..c5 */
.org-overlay .org-hit{
  background: transparent;
  border-bottom: 2px dotted rgba(168, 85, 247, .85);
  border-radius: 0;
}

/* paleta consistente con lo que ya definiste */
.org-overlay .c0{ background: transparent;  border-bottom-color: rgba(34,211,238,.9); }
.org-overlay .c1{ background: transparent;  border-bottom-color: rgba(16,185,129,.9); }
.org-overlay .c2{ background: transparent;  border-bottom-color: rgba(251,191,36,.9); }
.org-overlay .c3{ background: transparent; border-bottom-color: rgba(244,114,182,.9); }
.org-overlay .c4{ background: transparent; border-bottom-color: rgba(248,113,113,.9); }
.org-overlay .c5{ background: transparent; border-bottom-color: rgba(147,197,253,.9); }

@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); }
}



@media (min-width: 1440px){
  main{
    grid-template-columns: 420px 1fr;
    gap: 24px;
  }
}

@media (max-width: 640px){
  .list .tpl-row{ grid-template-columns: 1fr !important; }
  .list .tpl-actions{ justify-content: flex-end; }
}

/* ===== Ajustes de overlay de órganos (encima del editor) ===== */
.org-overlay{
  inset: 0;
  z-index: 2;           /* por encima del editor, debajo del panel */
  line-height: inherit; /* calza con el editor */
  padding: 12px 14px;   /* acompasa el padding visual del editor */
}


/* Scroll del editor en el contenedor, no dentro del editor */
.modal-card .editor{ overflow: visible !important; }
.modal-card .editor-wrap{
  position:relative;
  margin-left:0;
  transition: margin .22s ease;
  flex:1;
  min-height:0;
  overflow-y:auto;
  overflow-x:hidden;
}








.modal-card.show-orgs .org-panel.editing{ width: var(--org-width-edit); }

.modal-card.show-orgs.edit-mode .editor-wrap{ margin-left: calc(var(--org-width-edit) + 20px); }


