<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>
  /* --- AMOLED THEME VARIABLES --- */
  :root {
    --amoled-black: #000000;
    --amoled-surface: #080808;
    --amoled-field: #0e0e0e;
    --amoled-border: rgba(255, 255, 255, 0.08);
    --accent-purple: #8b5cf6;
    --accent-glow: rgba(139, 92, 246, 0.15);
    --text-main: #ffffff;
    --text-dim: #a1a1aa;
  }

  /* --- MODAL BASE --- */
  .modal {
    position: fixed;
    inset: 0;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
  }

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

  .modal-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.9);
    backdrop-filter: blur(12px);
    z-index: -1;
  }

  .modal-content {
    position: relative;
    display: flex;
    flex-direction: row; /* Horizontal layout */
    width: 95%;
    max-width: 1200px; /* Increased size */
    height: 85vh;
    background: var(--amoled-black);
    border: var(--amoled-border);
    border-radius: 28px;
    overflow: hidden;
    box-shadow: 0 0 0 1px var(--amoled-border), 0 24px 60px rgba(0,0,0,0.8);
    animation: modalScaleUp 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  }

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

  .sidebar-title {
    font-size: 1.4rem;
    font-weight: 800;
    margin-bottom: 2.5rem;
    color: var(--text-main);
    letter-spacing: -0.02em;
  }

  .nav-list { flex: 1; }

  .nav-item {
    padding: 12px 16px;
    border-radius: 14px;
    cursor: pointer;
    color: var(--text-dim);
    transition: all 0.2s ease;
    margin-bottom: 6px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 12px;
    text-transform: capitalize;
  }

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

  .nav-item.active {
    background: var(--accent-glow);
    color: var(--accent-purple);
    box-shadow: inset 3px 0 0 var(--accent-purple);
  }

  /* --- MAIN CONTENT & DYNAMIC INPUTS --- */
  .modal-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--amoled-black);
    min-width: 0;
  }

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

  .section-container {
    flex: 1;
    padding: 3.5rem;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: #222 transparent;
  }

  /* Styles for the injected section content */
  .config-group {
    margin-bottom: 2.5rem;
    animation: fadeInSection 0.4s ease-out;
  }

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

  .config-input {
    width: 100%;
    padding: 1rem 1.2rem;
    background: var(--amoled-field);
    border: 1px solid #1a1a1a;
    border-radius: 14px;
    color: #fff;
    font-size: 1rem;
    transition: all 0.25s ease;
  }

  .config-input:focus {
    outline: none;
    border-color: var(--accent-purple);
    background: #121212;
    box-shadow: 0 0 0 4px var(--accent-glow);
  }

  /* --- FOOTER --- */
  .modal-footer-sticky {
    padding: 1.5rem 3.5rem;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(10px);
    border-top: var(--amoled-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
  }

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

  /* --- BUTTONS --- */
  .btn-primary {
    padding: 0.8rem 2.2rem;
    background: #ffffff;
    color: #000000;
    border: none;
    border-radius: 100px;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.2s ease;
  }

  .btn-primary:hover {
    transform: translateY(-2px);
    background: #f0f0f0;
  }

  .btn-exit {
    background: #111;
    border: 1px solid #222;
    color: #ef4444;
    padding: 10px;
    border-radius: 12px;
    width: 100%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-weight: 600;
    margin-top: auto;
  }

  /* --- ANIMATIONS & SKELETON --- */
  @keyframes modalScaleUp {
    from { opacity: 0; transform: scale(0.97) translateY(10px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
  }

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

  .skeleton-loader { display: flex; flex-direction: column; gap: 2rem; }
  .skeleton {
    background: linear-gradient(90deg, #080808 25%, #121212 50%, #080808 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: 12px;
  }
  @keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
  }
  .title-skeleton { height: 35px; width: 40%; }
  .field-skeleton { height: 55px; width: 100%; }

  /* Responsive Mobile View */
  @media (max-width: 850px) {
    .modal-content { flex-direction: column; height: 95vh; width: 100vw; border-radius: 0; }
    .modal-sidebar { width: 100%; height: auto; border-right: none; border-bottom: var(--amoled-border); padding: 1rem; }
    .sidebar-title { margin-bottom: 1rem; font-size: 1.2rem; }
    .section-container { padding: 2rem; }
    .modal-footer-sticky { padding: 1.5rem 2rem; }
  }
</style>