.wiki-layout {
    display: grid;
    grid-template-columns: 220px 200px 1fr;
    height: 100%;
    overflow: hidden;
    position: relative;
  }
  @media (max-width: 768px) {
    .wiki-layout {
      grid-template-columns: 1fr;
      overflow-y: auto;
    }
  }
  .wiki-panel {
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--bg-surface);
  }
  .wiki-panel-header {
    padding: 12px 14px 8px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
  }
  .wiki-panel-header h4 {
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin: 0;
  }
  .wiki-panel-list {
    flex: 1;
    overflow-y: auto;
    padding: 6px;
  }
  .wiki-item {
    padding: 7px 10px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.83rem;
    color: var(--text-secondary);
    transition: background 0.12s, color 0.12s;
    display: flex;
    align-items: center;
    gap: 7px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }
  .wiki-item:hover { background: var(--bg-surface-2); color: var(--text-primary); }
  .wiki-item.active {
    background: var(--bg-accent);
    color: var(--accent-primary);
    font-weight: 600;
  }
  .wiki-item i { width: 13px; height: 13px; flex-shrink: 0; }
  .wiki-item-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
  .wiki-item .wiki-del {
    opacity: 0; width: 14px; height: 14px; flex-shrink: 0;
    color: var(--accent-danger); margin-left: auto;
  }
  .wiki-item:hover .wiki-del { opacity: 1; }
  .wiki-editor-area {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--bg-body);
    position: relative;
  }
  .wiki-editor-header {
    padding: 12px 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
    background: var(--bg-surface);
  }
  .wiki-page-title-input {
    flex: 1;
    font-size: 1.1rem;
    font-weight: 600;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-primary);
    font-family: inherit;
  }
  .wiki-page-title-input::placeholder { color: var(--text-muted); }
  .wiki-editor-textarea {
    flex: 1;
    resize: none;
    border: none;
    outline: none;
    padding: 20px;
    font-family: var(--font-mono, monospace);
    font-size: 0.9rem;
    background: transparent;
    color: var(--text-primary);
    line-height: 1.7;
  }
  .wiki-preview {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    line-height: 1.75;
    display: none;
  }
  .wiki-preview h1 { font-size: 1.8em; border-bottom: 2px solid var(--border-color); padding-bottom: 0.3em; }
  .wiki-preview h2 { font-size: 1.4em; border-bottom: 1px solid var(--border-color); padding-bottom: 0.2em; margin-top: 1.6em; }
  .wiki-preview h3 { font-size: 1.15em; margin-top: 1.3em; }
  .wiki-preview blockquote { border-left: 3px solid var(--accent-primary); padding-left: 1em; color: var(--text-secondary); margin: 1em 0; }
  .wiki-preview code { background: var(--bg-surface-2); padding: 2px 6px; border-radius: 4px; font-family: var(--font-mono); font-size: 0.85em; }
  .wiki-preview a { color: var(--accent-teal); text-decoration: none; }
  .wiki-preview a:hover { text-decoration: underline; }
  .wiki-empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    gap: 12px;
    font-size: 0.88rem;
  }
  .wikilink.is-ghost {
    color: var(--accent-danger);
    border-bottom: 1px dashed var(--accent-danger);
    opacity: 0.8;
  }
  .wiki-tag {
    color: var(--accent-teal);
    background: var(--accent-teal-bg);
    padding: 1px 6px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
  }
  .backlinks-section {
    margin-top: 40px;
    padding: 20px;
    border-top: 1px solid var(--border-color);
    background: var(--bg-surface-2);
    border-radius: 12px;
  }
  .backlink-item {
    font-size: 0.85rem;
    padding: 6px 10px;
    border-radius: 6px;
    cursor: pointer;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 8px;
  }
  .backlink-item:hover {
    background: var(--bg-surface-hover);
    color: var(--text-primary);
  }
  .wiki-empty-state i { width: 40px; height: 40px; opacity: 0.3; }

  /* ── Wiki Database Styles ── */
  .wiki-db-table-wrapper {
    overflow: auto;
    flex: 1;
    padding: 16px;
    background: var(--bg-body);
  }
  .wiki-db-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
    background: var(--bg-card);
    border-radius: 8px;
    overflow: hidden;
    box-shadow: var(--shadow-sm);
  }
  .wiki-db-table th, .wiki-db-table td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
  }
  .wiki-db-table th {
    background: var(--bg-surface-2);
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
  }
  .wiki-db-table tbody tr:hover {
    background: var(--bg-surface-hover);
  }
  .wiki-db-input {
    background: transparent;
    border: 1px transparent solid;
    color: var(--text-primary);
    padding: 4px 6px;
    border-radius: 4px;
    font-size: 0.85rem;
    width: 100%;
  }
  .wiki-db-input:focus {
    background: var(--bg-surface);
    border-color: var(--accent-primary);
    outline: none;
  }

  /* ── Thread Panels (Tangent Notes Style) ── */
  .wiki-thread-container {
    display: flex;
    flex: 1;
    overflow-x: auto;
    overflow-y: hidden;
    height: 100%;
    background: var(--bg-body);
  }
  .wiki-thread-pane {
    min-width: 450px;
    max-width: 600px;
    width: 500px;
    border-right: 2px solid var(--border-color);
    display: flex;
    flex-direction: column;
    height: 100%;
    flex-shrink: 0;
    background: var(--bg-card);
    box-shadow: -4px 0 16px rgba(0,0,0,0.05);
    animation: slideInRight 0.2s ease-out;
  }
  @keyframes slideInRight {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
  }

@media (max-width: 768px) {
  .wiki-thread-pane {
    min-width: 100%;
    max-width: 100%;
    width: 100%;
  }
}
@media (max-width: 600px) {
  .wiki-db-table th, .wiki-db-table td { display: block; width: 100%; }
}
