/* ══════════════════════════════════════════════════════════════════════════
   reader.css — Gnoke Reader
   All document rendering typography lives here.
   Loaded only by main/index.html — never by splash or other pages.
   ══════════════════════════════════════════════════════════════════════════ */

/* ── Reader page layout ── */
#reader-page {
  display: none;         /* shown by ReaderCore when file is open */
  flex-direction: column;
}
#reader-page.active {
  display: flex;
}

/* ── Reader toolbar (inside the page, below topbar) ── */
.reader-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  flex-wrap: wrap;
  z-index: 50;
}
.reader-toolbar-left  { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.reader-toolbar-right { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }

.reader-filename {
  font-family: var(--font-mono);
  font-size: .72rem; letter-spacing: .04em;
  color: var(--text); font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 220px;
}

.reader-format-badge {
  font-family: var(--font-mono);
  font-size: .58rem; letter-spacing: .1em; text-transform: uppercase;
  background: var(--accent-lt); color: var(--accent);
  padding: 2px 7px; border-radius: 999px; flex-shrink: 0;
}

/* Search box */
.reader-search-wrap {
  display: flex; align-items: center; gap: 6px;
  background: var(--surface2); border: 1.5px solid var(--border);
  border-radius: 20px; padding: 4px 10px;
  transition: border-color var(--transition);
}
.reader-search-wrap:focus-within { border-color: var(--accent); }
.reader-search-wrap input {
  border: none; background: transparent; color: var(--text);
  font-size: .78rem; width: 140px; outline: none; padding: 0;
}
.reader-search-wrap input::placeholder { color: var(--muted); }
.reader-search-count {
  font-family: var(--font-mono); font-size: .62rem;
  color: var(--muted); white-space: nowrap;
}

/* Font size controls */
.font-btn {
  width: 28px; height: 28px; border-radius: 50%;
  border: 1px solid var(--border); background: var(--surface2);
  color: var(--text2); cursor: pointer; font-size: .8rem;
  display: flex; align-items: center; justify-content: center;
  transition: all var(--transition); flex-shrink: 0;
}
.font-btn:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-lt); }

/* Close reader button */
.reader-close-btn {
  width: 28px; height: 28px; border-radius: 50%;
  border: 1px solid var(--border); background: transparent;
  color: var(--muted); cursor: pointer; font-size: .9rem;
  display: flex; align-items: center; justify-content: center;
  transition: all var(--transition); flex-shrink: 0;
}
.reader-close-btn:hover { border-color: var(--danger); color: var(--danger); background: var(--red-lt); }

/* ── Content area ── */
.reader-content {
  flex: 1; overflow-y: auto; overflow-x: hidden;
  padding: 32px 20px 60px;
  background: var(--bg);
}

/* Max width for comfortable reading */
.reader-body {
  max-width: 700px;
  margin: 0 auto;
  font-size: var(--reader-font-size, 16px);
  line-height: 1.75;
  color: var(--text);
  word-break: break-word;
  overflow-wrap: break-word;
}

/* ── Search highlight ── */
mark.search-hit {
  background: #fde68a; color: #1a1033;
  border-radius: 2px; padding: 0 1px;
}
[data-theme="dark"] mark.search-hit {
  background: #78350f; color: #fef3c7;
}
mark.search-hit.current {
  background: var(--accent); color: #fff;
}

/* ════════════════════════════════════
   MARKDOWN / DOCX rendered content
   ════════════════════════════════════ */
.reader-body h1, .reader-body h2, .reader-body h3,
.reader-body h4, .reader-body h5, .reader-body h6 {
  font-family: var(--font-display);
  font-weight: 700; line-height: 1.25;
  color: var(--text); margin: 1.6em 0 .6em;
}
.reader-body h1 { font-size: 2rem;   border-bottom: 2px solid var(--border); padding-bottom: .3em; margin-top: .6em; }
.reader-body h2 { font-size: 1.5rem; border-bottom: 1px solid var(--border); padding-bottom: .2em; }
.reader-body h3 { font-size: 1.2rem; }
.reader-body h4 { font-size: 1rem; }

.reader-body p  { margin: .9em 0; }

.reader-body a  { color: var(--accent); text-decoration: underline; word-break: break-all; }
.reader-body a:hover { opacity: .75; }

.reader-body strong { font-weight: 700; color: var(--text); }
.reader-body em     { font-style: italic; }

.reader-body ul, .reader-body ol {
  margin: .8em 0 .8em 1.5em; padding: 0;
}
.reader-body li { margin: .35em 0; }

.reader-body blockquote {
  margin: 1.2em 0;
  padding: .8em 1.2em;
  border-left: 4px solid var(--accent);
  background: var(--surface2);
  border-radius: 0 var(--radius) var(--radius) 0;
  color: var(--text2);
  font-style: italic;
}
.reader-body blockquote p { margin: 0; }

.reader-body hr {
  border: none; border-top: 1px solid var(--border);
  margin: 2em 0;
}

.reader-body img {
  max-width: 100%; height: auto;
  border-radius: var(--radius); margin: .8em 0;
  border: 1px solid var(--border);
}

/* Inline code */
.reader-body code {
  font-family: var(--font-mono);
  font-size: .87em;
  background: var(--surface2);
  color: var(--accent);
  padding: .15em .4em; border-radius: 4px;
  border: 1px solid var(--border);
  word-break: break-all;
}

/* Code blocks */
.reader-body pre {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1em 1.2em;
  overflow-x: auto;          /* horizontal scroll on code only */
  margin: 1.2em 0;
  font-size: .83em;
  line-height: 1.6;
}
.reader-body pre code {
  background: none; border: none;
  padding: 0; color: var(--text); font-size: 1em;
  word-break: normal;
}

/* Tables (markdown + CSV) */
.reader-body table,
.csv-table {
  width: 100%; border-collapse: collapse;
  font-size: .88em; margin: 1.2em 0;
  overflow-x: auto; display: block;
}
.reader-body th,
.csv-table th {
  background: var(--surface2);
  border: 1px solid var(--border2);
  padding: 8px 12px;
  font-family: var(--font-mono); font-size: .7em;
  letter-spacing: .07em; text-transform: uppercase;
  color: var(--muted); text-align: left;
  position: sticky; top: 0; z-index: 1;
}
.reader-body td,
.csv-table td {
  border: 1px solid var(--border);
  padding: 8px 12px;
  color: var(--text2);
  vertical-align: top;
  max-width: 300px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.reader-body tr:nth-child(even) td,
.csv-table tr:nth-child(even) td { background: var(--surface2); }
.reader-body tr:hover td,
.csv-table tr:hover td { background: var(--accent-lt); }

/* Row numbers for CSV */
.csv-table td.row-num {
  color: var(--muted); font-family: var(--font-mono);
  font-size: .7em; width: 36px; text-align: center;
  background: var(--surface2) !important;
}

/* ════════════════════════════════════
   PLAIN TEXT (.txt)
   ════════════════════════════════════ */
.txt-body {
  font-family: var(--font-mono);
  font-size: .88em;
  line-height: 1.7;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
}

/* ════════════════════════════════════
   LOG viewer (.log)
   ════════════════════════════════════ */
.log-body {
  font-family: var(--font-mono);
  font-size: .82em;
  line-height: 1.65;
  background: #0c0e14;
  color: #c9d1d9;
  padding: 16px 18px;
  border-radius: var(--radius);
  white-space: pre-wrap;
  word-break: break-word;
  border: 1px solid var(--border);
}
[data-theme="light"] .log-body { background: #0f1117; }

.log-line          { display: block; }
.log-error         { color: #ff7b72; }   /* red  — ERROR FATAL CRITICAL */
.log-warn          { color: #e3b341; }   /* amber — WARN WARNING */
.log-info          { color: #79c0ff; }   /* blue  — INFO */
.log-success       { color: #56d364; }   /* green — SUCCESS OK DONE */
.log-debug         { color: #6e7681; }   /* grey  — DEBUG TRACE VERBOSE */
.log-timestamp     { color: #8b949e; font-size: .9em; }

/* ════════════════════════════════════
   JSON viewer
   ════════════════════════════════════ */
.json-body {
  font-family: var(--font-mono);
  font-size: .84em;
  line-height: 1.65;
}
.json-tree { padding: 0; margin: 0; list-style: none; }
.json-tree ul { padding-left: 1.4em; margin: 0; list-style: none; border-left: 1px solid var(--border); margin-left: .2em; }
.json-key        { color: var(--accent); }
.json-str        { color: var(--green); }
.json-num        { color: #f08d49; }
.json-bool-true  { color: #56d364; }
.json-bool-false { color: #ff7b72; }
.json-null       { color: var(--muted); font-style: italic; }
.json-toggle {
  cursor: pointer; user-select: none;
  padding: 0 2px; border-radius: 3px;
  transition: background var(--transition);
}
.json-toggle:hover { background: var(--accent-dim); }
.json-toggle::before { content: '▾ '; font-size: .8em; color: var(--muted); }
.json-toggle.collapsed::before { content: '▸ '; }
.json-toggle.collapsed + ul { display: none; }
.json-count {
  font-size: .72em; color: var(--muted);
  margin-left: .4em; font-style: italic;
}

/* ════════════════════════════════════
   CSV toolbar extras
   ════════════════════════════════════ */
.csv-meta {
  font-family: var(--font-mono);
  font-size: .68rem; letter-spacing: .04em;
  color: var(--muted); margin-bottom: 12px;
  display: flex; gap: 16px; flex-wrap: wrap;
}
.csv-meta span { display: flex; gap: 4px; align-items: center; }
.csv-sortable th { cursor: pointer; }
.csv-sortable th:hover { color: var(--accent); }
.csv-sort-asc::after  { content: ' ↑'; }
.csv-sort-desc::after { content: ' ↓'; }

/* ════════════════════════════════════
   PDF viewer
   ════════════════════════════════════ */
.pdf-page-wrap {
  display: flex; flex-direction: column;
  align-items: center; gap: 16px;
  padding-bottom: 20px;
}
.pdf-canvas-wrap {
  box-shadow: 0 4px 20px rgba(0,0,0,.2);
  border-radius: 3px; overflow: hidden;
  max-width: 100%;
}
.pdf-canvas-wrap canvas {
  display: block; max-width: 100%; height: auto;
}
.pdf-controls {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 16px; background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0; flex-wrap: wrap;
  font-family: var(--font-mono); font-size: .72rem;
  color: var(--muted);
}
.pdf-page-info { min-width: 80px; text-align: center; }

/* ════════════════════════════════════
   Drop zone (home page)
   ════════════════════════════════════ */
.drop-zone {
  border: 2px dashed var(--border2);
  border-radius: var(--radius-lg);
  padding: 48px 24px;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition);
  background: var(--surface2);
  position: relative;
}
.drop-zone:hover,
.drop-zone.drag-over {
  border-color: var(--accent);
  background: var(--accent-lt);
}
.drop-zone input[type="file"] {
  position: absolute; inset: 0; opacity: 0;
  cursor: pointer; width: 100%; height: 100%;
}
.drop-icon { font-size: 2.8rem; margin-bottom: 12px; display: block; }
.drop-title {
  font-family: var(--font-display);
  font-size: 1.1rem; font-weight: 700; color: var(--text);
  margin-bottom: 6px;
}
.drop-sub { font-size: .82rem; color: var(--muted); line-height: 1.6; }
.drop-formats {
  display: flex; flex-wrap: wrap; gap: 6px;
  justify-content: center; margin-top: 16px;
}
.format-tag {
  font-family: var(--font-mono); font-size: .62rem;
  letter-spacing: .06em; text-transform: uppercase;
  background: var(--surface); color: var(--text2);
  border: 1px solid var(--border); border-radius: 999px;
  padding: 3px 10px;
}

/* Recent files list */
.recent-list { display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }
.recent-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); cursor: pointer;
  transition: all var(--transition);
}
.recent-item:hover { border-color: var(--accent); background: var(--surface2); }
.recent-icon { font-size: 1.3rem; flex-shrink: 0; }
.recent-name { font-weight: 600; font-size: .86rem; color: var(--text); }
.recent-meta { font-family: var(--font-mono); font-size: .64rem; color: var(--muted); margin-top: 2px; }
.recent-badge {
  font-family: var(--font-mono); font-size: .58rem;
  text-transform: uppercase; letter-spacing: .06em;
  background: var(--accent-lt); color: var(--accent);
  padding: 2px 7px; border-radius: 999px;
  margin-left: auto; flex-shrink: 0;
}

/* Error / empty states */
.reader-error {
  text-align: center; padding: 3rem 1rem;
  color: var(--muted); font-size: .9rem; line-height: 1.8;
}
.reader-error .err-icon { font-size: 2.5rem; display: block; margin-bottom: .8rem; }
.reader-loading {
  text-align: center; padding: 3rem 1rem;
  color: var(--muted); font-size: .82rem;
  font-family: var(--font-mono); letter-spacing: .06em;
}

/* ── Responsive reader ── */
@media (max-width: 640px) {
  .reader-body { font-size: var(--reader-font-size, 15px); }
  .reader-content { padding: 20px 14px 60px; }
  .reader-filename { max-width: 120px; }
  .reader-search-wrap input { width: 100px; }
  .pdf-controls { gap: 8px; }
  .drop-zone { padding: 32px 16px; }
}
