/* ══════════════════════════════════════════════════════════════════════════
   wiki.css  —  Wiki page specific styles
   Complete wiki design: sections, book grid, page list,
   content/editing view, Quill overrides, search results, revisions.
   ══════════════════════════════════════════════════════════════════════════ */

/* ── Page layout ── */
:root { --page-max: 1060px; }
body {
  padding: 1.5rem 1rem 4rem;
  display: flex; flex-direction: column; align-items: center; justify-content: flex-start;
}
.wiki-wrap { width: 100%; max-width: var(--page-max); position: relative; z-index: 1; }
@keyframes vcrise { from{opacity:0;transform:translateY(18px)} to{opacity:1;transform:translateY(0)} }
.wiki-wrap { animation: vcrise 0.45s cubic-bezier(0.16,1,0.3,1); }

/* ── Space background ── */
.space-bg { position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background:
    radial-gradient(ellipse 800px 600px at 5% 10%,  rgba(124,92,252,0.13) 0%, transparent 70%),
    radial-gradient(ellipse 600px 500px at 92% 80%, rgba(46,196,255,0.10) 0%, transparent 70%),
    radial-gradient(ellipse 500px 400px at 50% 115%,rgba(56,215,160,0.08) 0%, transparent 70%);
  animation: spaceshift 30s ease-in-out infinite alternate; }
@keyframes spaceshift { from{opacity:.65} to{opacity:1} }

/* ── Wiki action bar (breadcrumb + page actions) ── */
.wiki-action-bar {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.65rem 1.1rem;
  background: var(--card-bg); border: 1px solid var(--border);
  border-radius: var(--radius-sm); box-shadow: var(--shadow-card);
  margin-bottom: 1rem; position: relative; overflow: hidden;
}
.wiki-action-bar::before { content:''; position:absolute; top:0; left:10%; right:10%; height:1px;
  background:linear-gradient(90deg,transparent,rgba(255,255,255,0.18),transparent); }
.wiki-breadcrumb {
  display: flex; align-items: center; gap: 0.4rem;
  flex: 1; min-width: 0; overflow: hidden;
  font-size: 0.82rem; color: var(--text-dim);
}
.wiki-breadcrumb-sep { color: var(--text-muted); flex-shrink: 0; }
.wiki-bc-item {
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  cursor: pointer; transition: color 0.12s; flex-shrink: 1;
}
.wiki-bc-item:hover { color: var(--text); }
.wiki-bc-item.current { color: var(--text); font-weight: 600; flex-shrink: 0; }
.wiki-bar-actions { display: flex; gap: 0.35rem; flex-shrink: 0; }

/* ── Glass section card ── */
.wiki-section {
  background: var(--card-bg); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.3rem 1.5rem 1.1rem;
  margin-bottom: 1rem; position: relative; overflow: hidden;
  box-shadow: var(--shadow-card);
  border-left: 3px solid rgba(124,92,252,0.35);
}
.wiki-section::before { content:''; position:absolute; top:0; left:10%; right:10%; height:1px;
  background:linear-gradient(90deg,transparent,rgba(255,255,255,0.18),transparent); }
.wiki-section-header {
  display: flex; align-items: center; gap: 0.6rem; margin-bottom: 1rem;
  cursor: pointer; user-select: none;
}
.wiki-section-icon { font-size: 1.2rem; flex-shrink: 0; }
.wiki-section-name { font-size: 1rem; font-weight: 700; color: var(--text); flex: 1; }
.wiki-section-count { font-size: 0.7rem; color: var(--text-muted); }
.wiki-section-chevron { font-size: 0.7rem; color: var(--text-muted); transition: transform 0.2s; flex-shrink: 0; }
.wiki-section.collapsed .wiki-section-chevron { transform: rotate(-90deg); }
.wiki-section-body { position: relative; z-index: 1; }
.wiki-section.collapsed .wiki-section-body { display: none; }
.wiki-section-actions { display: flex; gap: 0.35rem; flex-shrink: 0; }

/* ── Book grid ── */
.book-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 0.6rem;
}
.book-card {
  display: flex; flex-direction: column; gap: 0.35rem;
  padding: 0.85rem 1rem;
  background: rgba(124,92,252,0.06); border: 1px solid rgba(124,92,252,0.18);
  border-radius: var(--radius-sm); cursor: pointer;
  transition: all 0.18s; position: relative; overflow: hidden;
  text-decoration: none;
}
.book-card::before { content:''; position:absolute; top:0; left:0; right:0; height:1px;
  background:linear-gradient(90deg,transparent,rgba(124,92,252,0.4),transparent); }
.book-card:hover {
  background: rgba(124,92,252,0.12); border-color: rgba(124,92,252,0.38);
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(124,92,252,0.15);
}
.book-card.active {
  background: rgba(124,92,252,0.16); border-color: rgba(124,92,252,0.5);
  box-shadow: 0 0 0 1px rgba(124,92,252,0.25), 0 4px 16px rgba(124,92,252,0.2);
}
.book-icon { font-size: 1.35rem; line-height: 1; }
.book-name { font-size: 0.84rem; font-weight: 700; color: var(--text); }
.book-page-count { font-size: 0.68rem; color: var(--text-muted); }
.book-card-actions { position: absolute; top: 0.4rem; right: 0.4rem; display: none; gap: 0.25rem; }
.book-card:hover .book-card-actions { display: flex; }

/* ── Page list (inside expanded book) ── */
.page-list-grid {
  margin-top: 0.75rem;
  display: flex; flex-direction: column; gap: 0.3rem;
  padding: 0.75rem 1rem;
  background: rgba(0,0,0,0.18); border-radius: var(--radius-sm);
  border: 1px solid rgba(255,255,255,0.06);
  animation: vcrise 0.2s cubic-bezier(0.16,1,0.3,1);
}
.page-list-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 0.5rem;
}
.page-list-title { font-size: 0.72rem; font-weight: 700; letter-spacing: 1.5px;
  text-transform: uppercase; color: var(--text-muted); }
.page-row {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.45rem 0.65rem; border-radius: var(--radius-xs);
  cursor: pointer; transition: background 0.12s; color: var(--text-dim);
  font-size: 0.82rem; border: 1px solid transparent;
}
.page-row:hover { background: rgba(255,255,255,0.06); color: var(--text); border-color: rgba(255,255,255,0.07); }
.page-row.active { background: rgba(124,92,252,0.1); color: var(--accent2); border-color: rgba(124,92,252,0.25); }
.page-row-icon { font-size: 0.85rem; flex-shrink: 0; }
.page-row-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.page-row-updated { font-size: 0.65rem; color: var(--text-muted); flex-shrink: 0; }
.page-row-actions { display: none; gap: 0.25rem; flex-shrink: 0; }
.page-row:hover .page-row-actions { display: flex; }

/* ── Empty states ── */
.wiki-empty {
  text-align: center; padding: 2.5rem 1rem;
  display: flex; flex-direction: column; align-items: center; gap: 0.75rem;
}
.wiki-empty-icon { font-size: 2.5rem; opacity: 0.5; }
.wiki-empty-text { font-size: 0.88rem; color: var(--text-muted); line-height: 1.55; }

/* ── Content view (reading/editing a page) ── */
.wiki-content-card {
  background: var(--card-bg); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 2rem 2.5rem;
  box-shadow: var(--shadow-card); position: relative; overflow: hidden;
  margin-bottom: 1rem;
}
.wiki-content-card::before { content:''; position:absolute; top:0; left:10%; right:10%; height:1px;
  background:linear-gradient(90deg,transparent,rgba(255,255,255,0.18),transparent); }
.wiki-page-title {
  font-size: 1.8rem; font-weight: 800; color: var(--text);
  background: none; border: none; outline: none;
  font-family: inherit; width: 100%;
  border-bottom: 2px solid transparent; transition: border-color 0.2s;
  margin-bottom: 0.5rem; display: block;
}
.wiki-page-title:focus { border-bottom-color: rgba(124,92,252,0.5); }
.wiki-page-meta {
  font-size: 0.74rem; color: var(--text-muted); margin-bottom: 1.5rem;
  display: flex; gap: 0.75rem; align-items: center;
}
.wiki-page-meta a { color: var(--accent2); cursor: pointer; text-decoration: none; }
.wiki-page-meta a:hover { text-decoration: underline; }
.read-view { font-size: 0.92rem; line-height: 1.8; color: var(--text); position: relative; z-index: 1; }
.read-view h1, .read-view h2, .read-view h3 { color: var(--text); margin: 1.35rem 0 0.55rem; font-weight: 700; }
.read-view h1 { font-size: 1.45rem; }
.read-view h2 { font-size: 1.2rem; }
.read-view h3 { font-size: 1rem; }
.read-view p { margin-bottom: 0.85rem; }
.read-view code {
  background: rgba(255,255,255,0.07); border-radius: 4px;
  padding: 0.1rem 0.35rem; font-family: 'DM Mono', monospace; font-size: 0.83em;
}
.read-view pre {
  background: rgba(0,0,0,0.38); border: 1px solid rgba(255,255,255,0.07);
  border-radius: var(--radius-xs); padding: 1rem 1.1rem;
  overflow-x: auto; margin-bottom: 0.85rem;
}
.read-view pre code { background: none; padding: 0; font-size: 0.85em; }
.read-view blockquote {
  border-left: 3px solid rgba(124,92,252,0.5); padding-left: 1rem;
  color: var(--text-dim); margin: 0.85rem 0;
}
.read-view ul, .read-view ol { padding-left: 1.5rem; margin-bottom: 0.85rem; }
.read-view li { margin-bottom: 0.3rem; }
.read-view a { color: var(--accent2); }
.read-view a:hover { text-decoration: underline; }

/* ── Revision history ── */
.revisions-panel {
  margin-top: 1.5rem; padding-top: 1.25rem;
  border-top: 1px solid var(--border);
}
.revisions-title {
  font-size: 0.72rem; font-weight: 700; letter-spacing: 1.5px;
  text-transform: uppercase; color: var(--text-muted); margin-bottom: 0.6rem;
}
.revision-item {
  display: flex; gap: 0.75rem; align-items: center;
  padding: 0.45rem 0.65rem; border-radius: var(--radius-xs);
  font-size: 0.78rem; color: var(--text-dim); cursor: pointer;
  transition: background 0.1s;
}
.revision-item:hover { background: rgba(255,255,255,0.05); color: var(--text); }

/* ── Quill overrides ── */
.ql-toolbar {
  background: rgba(0,0,0,0.25) !important;
  border: 1px solid rgba(255,255,255,0.1) !important;
  border-radius: var(--radius-xs) var(--radius-xs) 0 0 !important;
}
.ql-container {
  background: rgba(255,255,255,0.03) !important;
  border: 1px solid rgba(255,255,255,0.1) !important;
  border-top: none !important;
  border-radius: 0 0 var(--radius-xs) var(--radius-xs) !important;
  min-height: 320px; color: var(--text);
  font-family: 'DM Sans', sans-serif; font-size: 0.92rem;
}
.ql-editor { min-height: 280px; line-height: 1.75; color: var(--text); }
.ql-snow .ql-stroke { stroke: var(--text-dim) !important; }
.ql-snow .ql-fill { fill: var(--text-dim) !important; }
.ql-snow.ql-toolbar button:hover .ql-stroke,
.ql-snow .ql-toolbar button:hover .ql-stroke { stroke: var(--accent2) !important; }
.ql-snow .ql-picker { color: var(--text-dim); }

/* ── Search results ── */
.wiki-search-results { display: flex; flex-direction: column; gap: 0.5rem; }
.search-result-item {
  padding: 0.75rem 1rem; border-radius: var(--radius-sm);
  background: rgba(255,255,255,0.025); border: 1px solid rgba(255,255,255,0.06);
  cursor: pointer; transition: border-color 0.15s, background 0.15s;
}
.search-result-item:hover {
  border-color: rgba(124,92,252,0.35); background: rgba(124,92,252,0.06);
}
.search-result-title { font-size: 0.88rem; font-weight: 700; color: var(--text); margin-bottom: 0.2rem; }
.search-result-title mark { background: rgba(124,92,252,0.35); color: var(--accent2); border-radius: 3px; padding: 0 2px; }
.search-result-snippet { font-size: 0.76rem; color: var(--text-dim); line-height: 1.5; }
.search-result-snippet mark { background: rgba(124,92,252,0.25); color: var(--accent2); border-radius: 2px; padding: 0 2px; }
.search-result-meta { font-size: 0.68rem; color: var(--text-muted); margin-top: 0.3rem; }

/* ── Modal ── */
.modal-backdrop { display:none; position:fixed; inset:0; z-index:8000;
  background:rgba(0,0,0,0.7); backdrop-filter:blur(6px);
  align-items:center; justify-content:center; }
.modal-backdrop.open { display:flex; }
.modal-box {
  background:linear-gradient(145deg,#0e0e1c,#12121e);
  border:1px solid var(--border-hi); border-radius:var(--radius);
  padding:1.75rem 2rem; width:92%; max-width:420px;
  box-shadow:0 0 0 1px rgba(124,92,252,0.1),0 24px 64px rgba(0,0,0,0.6);
  animation:vcrise 0.2s cubic-bezier(.16,1,.3,1) both;
  position:relative; overflow:hidden;
}
.modal-box::before { content:''; position:absolute; top:0; left:10%; right:10%; height:1px;
  background:linear-gradient(90deg,transparent,rgba(255,255,255,0.18),transparent); }
.modal-title { font-size:1rem; font-weight:800; color:var(--text); margin-bottom:0.75rem; }
.modal-input {
  width:100%; background:rgba(255,255,255,0.06);
  border:1px solid rgba(255,255,255,0.12); border-radius:var(--radius-xs);
  padding:0.55rem 0.85rem; color:var(--text); font-size:0.88rem;
  font-family:inherit; outline:none; margin-bottom:0.5rem;
  transition:border-color 0.2s;
}
.modal-input:focus { border-color:rgba(124,92,252,0.55); }
.modal-footer { display:flex; justify-content:flex-end; gap:0.5rem; margin-top:1rem; }

/* ── Toast ── */
#toast { position:fixed; bottom:1.5rem; right:1.5rem; z-index:9999;
  display:flex; flex-direction:column; gap:0.4rem; pointer-events:none; }
.toast-item {
  padding:0.6rem 1rem; border-radius:var(--radius-sm);
  background:rgba(14,14,28,0.95); border:1px solid var(--border-hi);
  color:var(--text); font-size:0.82rem; font-weight:500;
  box-shadow:0 8px 32px rgba(0,0,0,0.5);
  animation:vcrise 0.22s cubic-bezier(.16,1,.3,1);
  max-width:300px;
}

/* ── Small icon button ── */
.icon-btn {
  display:inline-flex; align-items:center; justify-content:center;
  width:24px; height:24px; border-radius:5px;
  background:none; border:none; cursor:pointer;
  font-size:0.72rem; color:var(--text-muted);
  transition:background 0.12s, color 0.12s;
}
.icon-btn:hover { background:rgba(255,255,255,0.08); color:var(--text); }
.icon-btn.danger:hover { background:rgba(248,113,113,0.12); color:var(--red); }

/* ── Responsive ── */
@media(max-width:540px){
  .wiki-content-card { padding:1.25rem 1rem; }
  .book-grid { grid-template-columns: 1fr 1fr; }
}
@media(max-width:600px){
  /* Shelf header: name+chevron on row 1, count+actions on row 2 */
  .wiki-section-header {
    flex-wrap: wrap;
    gap: 0.3rem 0.6rem;
  }
  .wiki-section-icon { order: 0; }
  .wiki-section-name  { order: 1; flex: 1; min-width: 0; }
  .wiki-section-chevron { order: 2; flex-shrink: 0; }
  .wiki-section-count {
    order: 3;
    flex-basis: 100%;
    padding-left: calc(1.2rem + 0.6rem); /* indent under icon */
    font-size: 0.68rem;
  }
  .wiki-section-actions {
    order: 4;
    flex-basis: 100%;
    padding-left: calc(1.2rem + 0.6rem);
    gap: 0.3rem;
  }
  /* Book card actions: always visible on touch, smaller */
  .book-card-actions {
    display: flex;
    opacity: 0.45;
  }
  .book-card:hover .book-card-actions,
  .book-card.active .book-card-actions {
    opacity: 1;
  }
  /* Tighten book cards so 2-col grid isn't too cramped */
  .book-card { padding: 0.65rem 0.75rem; }
  .book-icon  { font-size: 1.1rem; }
  .book-name  { font-size: 0.78rem; }
}
