<div id="settings-modal" class="modal hidden" onclick="if(event.target === this) window.toggleSettingsModal(true)">
  <div class="modal-overlay"></div>
  <div class="modal-content">

    <aside class="modal-sidebar">
      <div class="sidebar-header">
        <h2 class="sidebar-title">Settings</h2>
      </div>
      <nav id="config-nav" class="nav-list">
      </nav>

      <div class="sidebar-footer">
        <button onclick="window.toggleSettingsModal(true)" class="btn-exit">
          <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
            <path d="M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4"></path>
            <polyline points="16 17 21 12 16 7"></polyline>
            <line x1="21" y1="12" x2="9" y2="12"></line>
          </svg>
          Close
        </button>
      </div>
    </aside>

    <main class="modal-main">
      <form id="config-form" class="config-wrapper">
        <div id="config-section-content" class="section-container">
          <div class="skeleton-loader">
            <div class="skeleton title-skeleton"></div>
            <div class="skeleton field-skeleton"></div>
            <div class="skeleton field-skeleton"></div>
            <div class="skeleton field-skeleton"></div>
          </div>
        </div>

        <div class="modal-footer-sticky">
          <p class="footer-hint">Changes are applied immediately after saving.</p>
          <button type="submit" class="btn-primary">Save Changes</button>
        </div>
      </form>
    </main>
  </div>
</div>

<style>
  /* --- THEME VARIABLES (Heredadas y adaptadas de anime.css) --- */
  :root {
    --modal-bg: #0b0b0b;
    --modal-sidebar: rgba(255, 255, 255, 0.02);
    --modal-border: rgba(255, 255, 255, 0.08);
    --input-bg: rgba(255, 255, 255, 0.04);
    --accent: #8b5cf6; /* Tu morado principal */
    --text-primary: #ffffff;
    --text-secondary: #a1a1aa;
  }

  /* --- MODAL BASE --- */
  .modal {
    position: fixed;
    inset: 0;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    font-family: system-ui, -apple-system, sans-serif; /* Coherencia con anime.css */
  }

  .modal.hidden { display: none !important; }

  .modal-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.85); /* Un poco menos opaco para profundidad */
    backdrop-filter: blur(8px);
    z-index: -1;
    animation: fadeIn 0.3s ease;
  }

  .modal-content {
    position: relative;
    display: flex;
    flex-direction: row;
    width: 100%;
    max-width: 1100px;
    height: 80vh;
    background: var(--modal-bg);
    border: 1px solid var(--modal-border);
    border-radius: 16px; /* Bordes menos exagerados, más elegantes */
    overflow: hidden;
    box-shadow: 0 40px 80px rgba(0,0,0,0.6);
    animation: modalSlideUp 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  }

  /* --- SIDEBAR --- */
  .modal-sidebar {
    width: 260px;
    background: var(--modal-sidebar);
    border-right: 1px solid var(--modal-border);
    display: flex;
    flex-direction: column;
    padding: 2rem 1.5rem;
    flex-shrink: 0;
  }

  .sidebar-header { margin-bottom: 2rem; }

  .sidebar-title {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--text-primary);
    margin: 0;
    letter-spacing: -0.03em;
  }

  .nav-list { flex: 1; display: flex; flex-direction: column; gap: 4px; }

  .nav-item {
    padding: 10px 14px;
    border-radius: 8px;
    cursor: pointer;
    color: var(--text-secondary);
    transition: all 0.2s ease;
    font-weight: 600;
    font-size: 0.95rem;
    display: flex;
    align-items: center;
    gap: 12px;
    text-transform: capitalize;
  }

  .nav-item:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
  }

  .nav-item.active {
    background: var(--accent);
    color: white;
    box-shadow: 0 4px 12px rgba(139, 92, 246, 0.25); /* Glow sutil */
  }

  /* --- MAIN CONTENT area --- */
  .modal-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: transparent;
    min-width: 0;
    position: relative;
  }

  .config-wrapper {
    display: flex;
    flex-direction: column;
    height: 100%;
  }

  .section-container {
    flex: 1;
    padding: 3rem;
    overflow-y: auto;
    /* Custom Scrollbar sutil */
    scrollbar-width: thin;
    scrollbar-color: #333 transparent;
  }

  /* --- INPUTS & FORMS (Estilo WaifuBoards/Anime) --- */
  .config-group {
    margin-bottom: 2rem;
    animation: fadeInSection 0.3s ease-out;
  }

  .config-group label {
    display: block;
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 0.6rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
  }

  .config-input {
    width: 100%;
    padding: 0.9rem 1rem;
    background: var(--input-bg);
    border: 1px solid var(--modal-border);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 1rem;
    font-family: inherit;
    transition: all 0.2s ease;
  }

  .config-input:focus {
    outline: none;
    border-color: var(--accent);
    background: rgba(255, 255, 255, 0.08);
    box-shadow: 0 0 0 1px var(--accent);
  }

  /* --- FOOTER ACTION BAR --- */
  .modal-footer-sticky {
    padding: 1.2rem 3rem;
    background: rgba(11, 11, 11, 0.8); /* Glass effect */
    backdrop-filter: blur(10px);
    border-top: 1px solid var(--modal-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
  }

  .footer-hint {
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-weight: 500;
  }

  /* --- BUTTONS --- */
  .btn-primary {
    padding: 0.7rem 2rem;
    background: white; /* Estilo 'btn-watch' de anime.css */
    color: black;
    border: none;
    border-radius: 6px;
    font-weight: 800;
    font-size: 0.95rem;
    cursor: pointer;
    transition: transform 0.2s ease, filter 0.2s;
  }

  .btn-primary:hover {
    transform: scale(1.02);
    filter: brightness(0.9);
  }

  .btn-exit {
    background: transparent;
    border: 1px solid var(--modal-border);
    color: #ef4444; /* Rojo error sutil */
    padding: 10px;
    border-radius: 8px;
    width: 100%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-weight: 600;
    margin-top: auto;
    transition: background 0.2s;
  }

  .btn-exit:hover {
    background: rgba(239, 68, 68, 0.1);
    border-color: #ef4444;
  }

  /* --- SKELETON & ANIMATIONS --- */
  @keyframes modalSlideUp {
    from { opacity: 0; transform: scale(0.98) translateY(15px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
  }

  @keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
  @keyframes fadeInSection { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }

  .skeleton-loader { display: flex; flex-direction: column; gap: 1.5rem; }
  .skeleton {
    background: linear-gradient(90deg, #111 25%, #1a1a1a 50%, #111 75%);
    background-size: 200% 100%;
    animation: shimmer 2s infinite;
    border-radius: 6px;
  }
  @keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

  .title-skeleton { height: 28px; width: 30%; margin-bottom: 1rem; }
  .field-skeleton { height: 48px; width: 100%; }

  /* --- RESPONSIVE --- */
  @media (max-width: 850px) {
    .modal-content { flex-direction: column; height: 100%; width: 100%; border-radius: 0; border: none; }
    .modal-sidebar { width: 100%; height: auto; border-right: none; border-bottom: 1px solid var(--modal-border); padding: 1.5rem; }
    .sidebar-footer { display: none; } /* Ocultar btn salir sidebar en movil */
    .section-container { padding: 1.5rem; }
    .modal-footer-sticky { padding: 1rem 1.5rem; }

    /* Añadir un botón de cierre flotante en móvil si fuera necesario,
       pero el diseño actual debería funcionar bien con scroll */
  }

  /* --- Estilo para la nueva descripción --- */
  .config-description {
    font-size: 0.85rem;
    color: rgba(255, 255, 255, 0.5); /* Gris sutil */

    /* Ajustes para posición inferior */
    margin-top: 0.5rem;    /* Espacio entre el input y la descripción */
    margin-bottom: 0;      /* Ya no necesitamos margen abajo */

    line-height: 1.4;
    font-weight: 400;
  }

  /* Ajuste para inputs vacíos (placeholder) */
  .config-input::placeholder {
    color: rgba(255, 255, 255, 0.2);
    font-style: italic;
  }
</style>