/* ============================================================
   wiki.css — Jagar Wiki
   Theme: editorial-minimal · light · refined
   ============================================================ */

/* ------------------------------------------------------------
   Custom properties
------------------------------------------------------------ */
:root {
  --bg:           #f7f6f3;
  --surface:      #ffffff;
  --surface-2:    rgba(255, 255, 255, 0.92);
  --border:       rgba(0, 0, 0, 0.07);
  --border-mid:   rgba(0, 0, 0, 0.11);
  --text:         #1e293b;
  --text-muted:   #64748b;
  --text-faint:   #94a3b8;
  --accent:       #b8945a;
  --accent-light: #f5ede0;
  --red:          #c0392b;
  --red-light:    #fdf0ee;
  --sidebar-w:    232px;
  --topbar-h:     52px;
  --radius:       12px;
  --mono:         'Menlo', 'Consolas', monospace;

  --font-display: 'Crimson Pro', Georgia, serif;
  --font-body:    'DM Sans', system-ui, sans-serif;
}

/* ------------------------------------------------------------
   Reset & base
------------------------------------------------------------ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body               { height: 100%; }
body {
  font-family: var(--font-body);
  font-size: 15px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

button, input, textarea, select {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

/* ------------------------------------------------------------
   Layout shell
------------------------------------------------------------ */
#app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ------------------------------------------------------------
   Sidebar
------------------------------------------------------------ */
#sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#sidebar-top {
  padding: 22px 20px 14px;
  border-bottom: 1px solid var(--border);
}

#wordmark {
  display: block;
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 300;
  letter-spacing: 0.04em;
  color: var(--text);
  text-decoration: none;
  margin-bottom: 2px;
  line-height: 1;
}
#wordmark:hover { color: var(--accent); }

#sidebar-label {
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin-bottom: 14px;
}

/* Search */
#search-wrap { position: relative; }

#search {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border-mid);
  border-radius: 8px;
  padding: 7px 12px;
  font-size: 13px;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s;
}
#search::placeholder { color: var(--text-faint); }
#search:focus         { border-color: var(--accent); }

/* Page list */
#page-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

.page-item {
  display: flex;
  align-items: baseline;
  gap: 0;
  padding: 7px 20px;
  font-size: 13.5px;
  font-weight: 400;
  color: var(--text-muted);
  cursor: pointer;
  border-left: 2px solid transparent;
  transition: all 0.1s;
  line-height: 1.3;
}
.page-item:hover  { color: var(--text);   background: var(--bg); }
.page-item.active { color: var(--accent); border-left-color: var(--accent); background: var(--accent-light); font-weight: 500; }

.page-empty {
  padding: 20px;
  font-size: 13px;
  color: var(--text-faint);
  text-align: center;
}

/* Sidebar bottom */
#sidebar-bottom {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#auth-status {
  font-size: 12px;
  color: var(--text-faint);
  letter-spacing: 0.02em;
}

/* Divider (resize handle visual) */
#divider {
  width: 1px;
  background: var(--border);
  flex-shrink: 0;
}

/* ------------------------------------------------------------
   Main
------------------------------------------------------------ */
#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
}

/* Topbar */
#topbar {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 32px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  gap: 16px;
}

#breadcrumb {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-faint);
}
#breadcrumb-sep  { opacity: .4; }
#breadcrumb-page { color: var(--text-muted); font-weight: 500; }

#topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

#page-updated {
  font-size: 12px;
  color: var(--text-faint);
  margin-right: 4px;
}

/* ------------------------------------------------------------
   Buttons
------------------------------------------------------------ */
.action-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid var(--border-mid);
  background: var(--surface);
  color: var(--text-muted);
  transition: all 0.12s;
  white-space: nowrap;
  letter-spacing: 0.01em;
}
.action-btn:hover         { background: var(--bg); color: var(--text); border-color: var(--border-mid); }
.action-btn.primary       { background: var(--accent); color: #fff; border-color: var(--accent); }
.action-btn.primary:hover { filter: brightness(1.08); }
.action-btn.danger        { color: var(--red); border-color: rgba(192, 57, 43, 0.25); background: transparent; }
.action-btn.danger:hover  { background: var(--red-light); }
.action-btn:disabled      { opacity: .38; cursor: not-allowed; pointer-events: none; }

/* Sidebar new-page button */
#btn-new {
  width: 100%;
  padding: 8px 12px;
  background: var(--bg);
  border: 1px dashed var(--border-mid);
  border-radius: 8px;
  font-size: 13px;
  font-weight: 400;
  color: var(--text-muted);
  cursor: pointer;
  text-align: left;
  transition: all 0.12s;
  letter-spacing: 0.02em;
}
#btn-new:hover { background: var(--surface); color: var(--accent); border-color: var(--accent); border-style: solid; }

/* ------------------------------------------------------------
   Content area
------------------------------------------------------------ */
#content-wrap {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* Viewer */
#viewer {
  flex: 1;
  overflow-y: auto;
  padding: 44px 56px;
}

#empty-state {
  max-width: 440px;
  margin: 60px auto 0;
  text-align: center;
}
.empty-headline {
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: 300;
  color: var(--text-muted);
  margin-bottom: 10px;
}
.empty-sub {
  font-size: 14px;
  color: var(--text-faint);
  line-height: 1.65;
}

/* ------------------------------------------------------------
   Markdown rendered styles
------------------------------------------------------------ */
#viewer h1 {
  font-family: var(--font-display);
  font-size: 2.4em;
  font-weight: 300;
  color: var(--text);
  line-height: 1.2;
  margin-bottom: 6px;
  letter-spacing: -0.01em;
}
#viewer h2 {
  font-family: var(--font-display);
  font-size: 1.55em;
  font-weight: 400;
  color: var(--text);
  margin: 36px 0 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
#viewer h3 {
  font-size: 1em;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin: 28px 0 10px;
}
#viewer h4 { font-size: .95em; font-weight: 500; margin: 20px 0 8px; }

#viewer p  { line-height: 1.78; margin-bottom: 16px; color: var(--text); font-size: 15px; }
#viewer p:last-child { margin-bottom: 0; }

#viewer a               { color: var(--accent); text-decoration: none; }
#viewer a:hover         { text-decoration: underline; }
#viewer a.wiki-broken   { color: var(--text-faint); text-decoration: line-through; }

#viewer strong { font-weight: 500; }
#viewer em     { font-style: italic; }
#viewer hr     { border: none; border-top: 1px solid var(--border); margin: 32px 0; }

#viewer ul, #viewer ol {
  padding-left: 22px;
  margin-bottom: 16px;
}
#viewer li              { line-height: 1.72; margin-bottom: 4px; }
#viewer li:last-child   { margin-bottom: 0; }

#viewer blockquote {
  margin: 20px 0;
  padding: 14px 20px;
  border-left: 3px solid var(--accent);
  background: var(--accent-light);
  border-radius: 0 8px 8px 0;
  color: var(--text-muted);
  font-style: italic;
}

#viewer code {
  font-family: var(--mono);
  font-size: .85em;
  background: var(--bg);
  border: 1px solid var(--border-mid);
  border-radius: 4px;
  padding: 1px 6px;
}
#viewer pre {
  background: #1e293b;
  border-radius: var(--radius);
  padding: 20px 24px;
  overflow-x: auto;
  margin-bottom: 20px;
}
#viewer pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: .82em;
  color: #e2e8f0;
  line-height: 1.65;
}

#viewer table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 20px;
  font-size: 14px;
}
#viewer th {
  text-align: left;
  padding: 9px 14px;
  background: var(--surface);
  border-bottom: 2px solid var(--border-mid);
  font-weight: 500;
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
}
#viewer td {
  padding: 9px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}
#viewer tr:last-child td { border-bottom: none; }

#viewer img {
  max-width: 100%;
  border-radius: var(--radius);
  margin: 10px 0;
  display: block;
}
#viewer video {
  max-width: 100%;
  border-radius: var(--radius);
  margin: 10px 0;
  display: block;
}

/* Page metadata line under h1 */
.page-meta {
  font-size: 12.5px;
  color: var(--text-faint);
  margin-bottom: 32px;
  letter-spacing: 0.02em;
}

/* ------------------------------------------------------------
   Editor
------------------------------------------------------------ */
#editor {
  flex: 1;
  overflow-y: auto;
  padding: 32px 56px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

#editor-title {
  font-family: var(--font-display);
  font-size: 2em;
  font-weight: 300;
  color: var(--text);
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--border-mid);
  padding: 4px 0 12px;
  outline: none;
  width: 100%;
  letter-spacing: -0.01em;
}
#editor-title:focus { border-bottom-color: var(--accent); }
#editor-title::placeholder { color: var(--text-faint); }

#editor-body {
  flex: 1;
  min-height: 300px;
  resize: none;
  background: var(--surface);
  border: 1px solid var(--border-mid);
  border-radius: var(--radius);
  padding: 20px 24px;
  font-family: var(--mono);
  font-size: 13.5px;
  line-height: 1.7;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s;
}
#editor-body:focus { border-color: var(--accent); }
#editor-body::placeholder { color: var(--text-faint); }

#editor-hint {
  font-size: 12px;
  color: var(--text-faint);
  letter-spacing: 0.02em;
}

/* ------------------------------------------------------------
   Dialog (new page)
------------------------------------------------------------ */
dialog {
  background: var(--surface);
  border: 1px solid var(--border-mid);
  border-radius: 16px;
  padding: 28px 32px;
  width: 400px;
  max-width: 90vw;
  box-shadow: 0 20px 60px rgba(0,0,0,0.12);
  color: var(--text);
}
dialog::backdrop { background: rgba(15,23,42,0.35); backdrop-filter: blur(4px); }

dialog h3 {
  font-family: var(--font-display);
  font-size: 1.4em;
  font-weight: 300;
  margin-bottom: 20px;
}

dialog label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}
dialog label span {
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
}
dialog label span em {
  font-style: normal;
  font-weight: 300;
  letter-spacing: 0;
  text-transform: none;
  color: var(--text-faint);
}
dialog input {
  background: var(--bg);
  border: 1px solid var(--border-mid);
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 14px;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s;
}
dialog input:focus         { border-color: var(--accent); }
dialog input::placeholder  { color: var(--text-faint); }

.dlg-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 8px;
}

/* ------------------------------------------------------------
   Toast notifications
------------------------------------------------------------ */
#toast-root {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 999;
  pointer-events: none;
}

.toast {
  background: rgba(255,255,255,0.95);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-mid);
  border-radius: 10px;
  padding: 10px 18px;
  font-size: 13.5px;
  font-weight: 400;
  color: var(--text);
  box-shadow: 0 8px 28px rgba(0,0,0,0.09);
  opacity: 0;
  transform: translateY(8px);
  animation: toast-in 0.2s ease forwards, toast-out 0.2s ease 2.8s forwards;
  max-width: 320px;
}
.toast.error { border-color: rgba(192,57,43,0.3); color: var(--red); }
.toast.ok    { border-left: 3px solid var(--accent); }

@keyframes toast-in  { to { opacity: 1; transform: translateY(0); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(4px); } }

/* ------------------------------------------------------------
   Utility
------------------------------------------------------------ */
.hidden { display: none !important; }

/* Preview mode indicator strip */
#topbar.previewing {
  background: var(--accent-light);
  border-bottom-color: rgba(184, 148, 90, 0.25);
}
#topbar.previewing #breadcrumb::after {
  content: 'Preview';
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  background: rgba(184, 148, 90, 0.15);
  border: 1px solid rgba(184, 148, 90, 0.3);
  border-radius: 4px;
  padding: 2px 7px;
}

/* Scrollbar */
::-webkit-scrollbar       { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-mid); border-radius: 3px; }

/* ------------------------------------------------------------
   Responsive — collapse sidebar on small screens
------------------------------------------------------------ */
@media (max-width: 640px) {
  #sidebar { width: 100%; position: absolute; z-index: 50; height: 100%; transform: translateX(-100%); transition: transform 0.2s; }
  #sidebar.open { transform: translateX(0); }
  #divider { display: none; }
  #main { width: 100%; }
}

/* ------------------------------------------------------------
   Search modal  (Cmd/Ctrl+K)
------------------------------------------------------------ */
#search-modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.4);
  backdrop-filter: blur(6px);
  z-index: 300;
  align-items: flex-start;
  justify-content: center;
  padding-top: 12vh;
}
#search-modal.open { display: flex; }

#search-box {
  width: 580px;
  max-width: 92vw;
  background: var(--surface);
  border: 1px solid var(--border-mid);
  border-radius: 16px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.14);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  max-height: 70vh;
}

#search-input-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

#search-icon {
  font-size: 16px;
  color: var(--text-faint);
  flex-shrink: 0;
}

#search-modal-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  font-size: 16px;
  color: var(--text);
  font-family: var(--font-body);
}
#search-modal-input::placeholder { color: var(--text-faint); }

#search-esc {
  flex-shrink: 0;
  font-size: 11px;
  color: var(--text-faint);
  background: var(--bg);
  border: 1px solid var(--border-mid);
  border-radius: 5px;
  padding: 2px 7px;
  font-family: var(--font-body);
  cursor: pointer;
}

#search-results {
  overflow-y: auto;
  padding: 6px;
  flex: 1;
}

.search-result {
  padding: 10px 14px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.08s;
}
.search-result:hover,
.search-result.selected { background: var(--accent-light); }

.sr-title {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 2px;
}
.sr-excerpt {
  font-size: 12.5px;
  color: var(--text-muted);
  line-height: 1.5;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.search-result mark {
  background: rgba(184, 148, 90, 0.22);
  color: var(--accent);
  border-radius: 2px;
  font-style: normal;
  font-weight: 600;
}

.search-empty {
  padding: 24px 16px;
  text-align: center;
  font-size: 13.5px;
  color: var(--text-faint);
}
.search-empty em { font-style: normal; color: var(--text-muted); }

#search-footer {
  display: flex;
  gap: 16px;
  padding: 10px 18px;
  border-top: 1px solid var(--border);
  background: var(--bg);
}
#search-footer span {
  font-size: 11.5px;
  color: var(--text-faint);
  display: flex;
  align-items: center;
  gap: 4px;
}
#search-footer kbd {
  background: var(--surface);
  border: 1px solid var(--border-mid);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 10px;
  font-family: var(--font-body);
  color: var(--text-muted);
}

/* Sidebar search now just acts as a trigger */
#search { cursor: pointer; }