/* XML Formatter Fácil — estilos propios de la herramienta.
   Se apoya en las variables y componentes ya definidos en styles.css
   (--accent, --surface, --border, --font-mono, .card, .btn, .chip,
   .faq-item, etc.) y añade únicamente lo que un editor de código y las
   Advanced Tools necesitan. */

.xml-tool { max-width: 980px; margin-inline: auto; }

/* ---------- Barra de herramientas ---------- */
.xml-toolbar {
  display: flex; flex-wrap: wrap; gap: .7rem; align-items: center; justify-content: space-between;
  margin-bottom: .8rem;
}
.xml-toolbar .toolbar-group { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.xml-toolbar-files { padding-bottom: .9rem; margin-bottom: .9rem; border-bottom: 1px solid var(--border); }

.copy-confirm {
  font-size: .8rem; font-weight: 700; color: var(--success);
  animation: xf-fade-in .15s var(--ease-out);
}
@keyframes xf-fade-in { from { opacity: 0; transform: translateY(2px); } to { opacity: 1; transform: none; } }

/* ---------- Menú de ejemplos ---------- */
.samples-dropdown { position: relative; }
.samples-menu {
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 30; min-width: 220px;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-md);
  box-shadow: var(--shadow-md); padding: .35rem; display: flex; flex-direction: column; gap: .1rem;
}
.sample-item {
  text-align: left; padding: .55rem .7rem; border-radius: var(--radius-sm); font-size: .85rem;
  color: var(--text); background: transparent;
}
.sample-item:hover, .sample-item:focus-visible { background: var(--accent-soft); color: var(--accent-strong); outline: none; }

/* ---------- Chip de archivo cargado ---------- */
.file-info-chip {
  display: flex; align-items: center; gap: .7rem; text-align: left;
  border: 1px solid var(--border); border-radius: var(--radius-md); padding: .55rem .8rem;
  background: var(--surface-muted); margin-left: auto;
}
.file-info-chip .file-icon { font-size: 1.15rem; flex: none; }
.file-info-meta { display: flex; flex-direction: column; gap: .05rem; min-width: 0; }
.file-info-meta strong { font-size: .84rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 220px; }
.file-info-meta span { font-size: .74rem; color: var(--text-muted); }

/* ---------- Opciones (indentación / toggles) ---------- */
.xml-options-row {
  display: flex; flex-wrap: wrap; gap: .8rem 1.6rem; align-items: center; justify-content: space-between;
  padding: .75rem .9rem; margin-bottom: .8rem; background: var(--surface-muted);
  border: 1px solid var(--border); border-radius: var(--radius-md); font-size: .85rem;
}
.opt-group { display: flex; flex-wrap: wrap; gap: .15rem .9rem; align-items: center; }
.opt-group-toggles { gap: .5rem 1rem; }
.opt-label { font-weight: 700; color: var(--text-muted); font-size: .8rem; margin-right: .2rem; }
.opt-radio, .opt-toggle { display: inline-flex; align-items: center; gap: .35rem; cursor: pointer; color: var(--text); white-space: nowrap; }
.opt-radio input, .opt-toggle input { accent-color: var(--accent); width: 15px; height: 15px; }

/* ---------- Barra de búsqueda ---------- */
.search-bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: .6rem;
  padding: .6rem .8rem; margin-bottom: .8rem; background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: var(--radius-md);
}
.search-bar .search-icon { width: 17px; height: 17px; color: var(--text-faint); flex: none; }
.search-bar #searchInput {
  flex: 1; min-width: 160px; border: none; background: transparent; color: var(--text);
  font-size: .88rem; font-family: inherit;
}
.search-bar #searchInput:focus { outline: none; }
.search-opt { font-size: .78rem; color: var(--text-muted); }
.search-count { font-size: .78rem; color: var(--text-muted); font-variant-numeric: tabular-nums; min-width: 5.5em; }

/* ---------- Banner de validación ---------- */
.validation-banner {
  display: flex; flex-wrap: wrap; align-items: center; gap: .5rem .7rem;
  padding: .7rem .9rem; margin-bottom: .8rem; border-radius: var(--radius-md);
  border: 1px solid var(--border); background: var(--surface-muted); font-size: .88rem; min-height: 2.7rem;
}
.validation-banner.is-empty { color: var(--text-faint); }
.validation-banner.is-empty::before { content: "···"; color: var(--text-faint); font-weight: 700; }
.validation-banner.is-valid { border-color: var(--success); background: var(--success-soft); }
.validation-banner.is-valid .validation-text { color: var(--success); font-weight: 800; }
.validation-banner.is-invalid { border-color: var(--danger); background: var(--danger-soft); }
.validation-banner.is-invalid .validation-text { color: var(--danger); font-weight: 800; }
.validation-text { font-weight: 700; }
.validation-detail { color: var(--text-muted); flex: 1; min-width: 200px; }
.validation-banner .btn { flex: none; }

/* ---------- Editor de código ---------- */
.xml-editor-wrap { position: relative; margin-bottom: 1.1rem; }
.xml-editor-mount {
  display: flex; align-items: stretch;
  border: 1.5px solid var(--border-strong); border-radius: var(--radius-md); overflow: hidden;
  background: var(--bg-elevated); box-shadow: var(--shadow-sm);
  height: min(60vh, 520px); min-height: 260px;
}
.xml-editor-gutter {
  flex: none; padding: .85rem 0; text-align: right; user-select: none;
  background: var(--surface-muted); border-right: 1px solid var(--border);
  overflow: hidden; font-family: var(--font-mono); font-size: .84rem; line-height: 1.6;
  color: var(--text-faint); min-width: 3.4em;
}
.xg-line { display: block; padding: 0 .7rem; }
.xg-line.is-current-line { color: var(--accent-strong); font-weight: 700; }
.xg-line.is-error-line { background: var(--danger-soft); color: var(--danger); font-weight: 700; }

.xml-editor-scroll { position: relative; flex: 1; min-width: 0; overflow: auto; }
.xml-editor-highlight,
.xml-editor-input {
  margin: 0; padding: .85rem 1rem; border: 0; width: 100%; min-height: 100%; box-sizing: border-box;
  font-family: var(--font-mono); font-size: .84rem; line-height: 1.6; white-space: pre; tab-size: 2;
}
.xml-editor-highlight {
  position: absolute; inset: 0; color: var(--text); background: transparent; pointer-events: none;
  overflow: hidden;
}
.xml-editor-highlight code { font-family: inherit; }
.xml-editor-input {
  position: relative; background: transparent; color: transparent; caret-color: var(--text);
  resize: none; overflow: auto; z-index: 1;
}
.xml-editor-input::selection { background: var(--accent-soft); }
.is-wrapped .xml-editor-highlight,
.is-wrapped .xml-editor-input { white-space: pre-wrap; word-break: break-word; }

/* Colores del resaltado de sintaxis XML */
.xh-tag { color: var(--accent-strong); font-weight: 600; }
.xh-attr { color: #8a4b00; }
.xh-value { color: #14804a; }
.xh-comment { color: var(--text-faint); font-style: italic; }
.xh-cdata { color: #a15c00; }
.xh-pi { color: #7a3fb0; }
.xh-doctype { color: #7a3fb0; }
.xh-entity { color: #b3261e; font-weight: 600; }
.xh-punct { color: var(--text-muted); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --xh-attr: #ffb454; --xh-value: #4fd692; --xh-cdata: #f2b43f; --xh-pi: #c9a6ff; --xh-doctype: #c9a6ff; --xh-entity: #ff8078;
  }
}
:root[data-theme="dark"] { --xh-attr: #ffb454; --xh-value: #4fd692; --xh-cdata: #f2b43f; --xh-pi: #c9a6ff; --xh-doctype: #c9a6ff; --xh-entity: #ff8078; }
.xh-attr { color: var(--xh-attr, #8a4b00); }
.xh-value { color: var(--xh-value, #14804a); }
.xh-cdata { color: var(--xh-cdata, #a15c00); }
.xh-pi, .xh-doctype { color: var(--xh-pi, #7a3fb0); }
.xh-entity { color: var(--xh-entity, #b3261e); }

/* ---------- Zona de arrastrar y soltar (superpuesta al editor) ---------- */
.drop-overlay {
  position: absolute; inset: 0; z-index: 5; display: flex; align-items: center; justify-content: center;
  background: color-mix(in srgb, var(--accent-soft) 92%, transparent);
  border: 2px dashed var(--accent); border-radius: var(--radius-md); pointer-events: none;
}
.drop-overlay-inner { text-align: center; color: var(--accent-strong); }
.drop-overlay-inner svg { width: 34px; height: 34px; margin-bottom: .4rem; }
.drop-overlay-inner p { font-weight: 700; font-size: .95rem; }

/* ---------- Advanced Tools ---------- */
.adv-tools-section { margin-top: 1.6rem; padding-top: 1.4rem; border-top: 1px solid var(--border); }
.section-head-sm { margin-bottom: .9rem; }
.section-head-sm h2 { font-size: 1.15rem; }
.adv-tabs { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: 1rem; }
.adv-tab {
  padding: .5rem .85rem; border-radius: var(--radius-pill); font-size: .82rem; font-weight: 700;
  background: var(--surface-muted); border: 1px solid var(--border); color: var(--text-muted);
  transition: all .15s var(--ease-out);
}
.adv-tab:hover { color: var(--accent); border-color: var(--accent); }
.adv-tab.is-active { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }
.adv-panel { padding-top: .2rem; }
.adv-panel-hint { font-size: .84rem; color: var(--text-muted); margin-bottom: .8rem; }
.adv-panel-hint code { font-family: var(--font-mono); background: var(--surface-muted); padding: .05rem .3rem; border-radius: 4px; }
.adv-actions-row { display: flex; flex-wrap: wrap; gap: .55rem; margin: .7rem 0; }
.adv-warning {
  font-size: .84rem; color: var(--warning); background: var(--warning-soft); border-radius: var(--radius-sm);
  padding: .55rem .8rem; margin-bottom: .7rem;
}
.adv-textarea {
  width: 100%; min-height: 160px; resize: vertical; border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); background: var(--bg-elevated); color: var(--text);
  font-family: var(--font-mono); font-size: .82rem; line-height: 1.55; padding: .7rem .8rem;
}
.adv-textarea:focus-visible { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.adv-output {
  background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: .8rem .9rem; font-family: var(--font-mono); font-size: .82rem; line-height: 1.55;
  white-space: pre-wrap; word-break: break-word; max-height: 420px; overflow: auto; min-height: 3em;
}

/* Estructura */
.struct-toolbar { display: flex; gap: .5rem; margin-bottom: .8rem; }
.struct-empty { font-size: .86rem; color: var(--text-faint); padding: .6rem .2rem; }
.struct-tree, .struct-children { list-style: none; margin: 0; padding-left: 1.15rem; }
.struct-tree { padding-left: 0; max-height: 420px; overflow: auto; }
.struct-node {
  display: flex; align-items: center; gap: .4rem; width: 100%; text-align: left;
  padding: .3rem .4rem; border-radius: 6px; font-size: .84rem; font-family: var(--font-mono); color: var(--text);
}
.struct-node:hover { background: var(--surface-muted); color: var(--accent-strong); }
.struct-caret { transition: transform .15s var(--ease-out); color: var(--text-faint); font-size: .7rem; }
.struct-branch:not(.is-open) > .struct-node .struct-caret { transform: rotate(-90deg); }
.struct-branch:not(.is-open) > .struct-children { display: none; }
.struct-icon { color: var(--accent); flex: none; }
.struct-name { font-weight: 600; }
.struct-attrs { color: var(--text-faint); font-size: .76rem; font-family: var(--font-sans); }

/* Compare */
.compare-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-bottom: .8rem; }
.compare-col { display: flex; flex-direction: column; gap: .4rem; }
.compare-col label { font-size: .8rem; font-weight: 700; color: var(--text-muted); }
.cmp-summary { font-size: .85rem; color: var(--text-muted); margin: .7rem 0; }
.diff-view {
  background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-family: var(--font-mono); font-size: .8rem; line-height: 1.6; max-height: 480px; overflow: auto;
}
.diff-line { display: flex; gap: .6rem; padding: 0 .8rem; white-space: pre-wrap; word-break: break-word; }
.diff-sign { flex: none; width: 1ch; font-weight: 800; color: var(--text-faint); }
.diff-line.diff-added { background: var(--success-soft); }
.diff-line.diff-added .diff-sign { color: var(--success); }
.diff-line.diff-removed { background: var(--danger-soft); }
.diff-line.diff-removed .diff-sign { color: var(--danger); }

/* Estadísticas */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .7rem; }
.stat-item {
  display: flex; flex-direction: column; gap: .2rem; padding: .75rem .9rem;
  border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface-muted);
}
.stat-label { font-size: .76rem; color: var(--text-muted); font-weight: 700; }
.stat-value { font-size: 1.2rem; font-weight: 800; color: var(--accent-strong); font-variant-numeric: tabular-nums; }

/* ---------- Responsive ---------- */
@media (max-width: 719.98px) {
  .compare-grid { grid-template-columns: 1fr; }
  .xml-editor-mount { height: min(56vh, 420px); }
  .file-info-chip { margin-left: 0; width: 100%; }
}
@media (max-width: 539.98px) {
  .xml-options-row { flex-direction: column; align-items: flex-start; }
  .search-bar #searchInput { min-width: 100%; order: -1; }
  .validation-detail { min-width: 100%; }
  .stats-grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
  /* El botón del cierre de página hereda white-space:nowrap de .btn en el
     styles.css compartido, lo que provoca desbordamiento horizontal con
     textos largos en pantallas muy estrechas (mismo ajuste aplicado en el
     resto de herramientas de VivaFacilito, sin tocar el CSS compartido). */
  #closingCta .btn { white-space: normal; max-width: 100%; text-align: center; }
}
