* { box-sizing: border-box; }
body {
  margin: 0;
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: #22303c;
  background: #f6f7f9;
}
a { color: #1a6b8f; text-decoration: none; }
a:hover { text-decoration: underline; }

.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 260px;
  flex-shrink: 0;
  background: #22303c;
  color: #d8e0e7;
  padding: 1.2rem 1rem;
}
.sidebar h1 { font-size: 1.15rem; margin: 0 0 1rem; }
.sidebar h1 a { color: #fff; }
.sidebar h2 {
  font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.08em;
  color: #8fa3b3; margin: 1.4rem 0 0.4rem;
}
.sidebar ul { list-style: none; margin: 0; padding: 0; }
.sidebar li { display: flex; align-items: center; justify-content: space-between; border-radius: 6px; }
.sidebar li a { color: #d8e0e7; display: block; padding: 0.28rem 0.5rem; flex: 1; }
.sidebar li.active { background: #33465a; }
.sidebar .count { color: #8fa3b3; font-size: 0.8rem; margin-left: 0.3rem; }
.new-folder { display: flex; gap: 4px; margin-top: 0.5rem; }
.new-folder input {
  flex: 1; min-width: 0; background: #33465a; border: none; color: #fff;
  border-radius: 6px; padding: 0.3rem 0.5rem;
}
.new-folder button, .icon-btn {
  background: none; border: none; color: #8fa3b3; cursor: pointer; font-size: 1rem;
}
.new-folder button:hover, .icon-btn:hover { color: #fff; }

.search-box { position: relative; }
.search-box input {
  width: 100%; padding: 0.45rem 0.6rem; border-radius: 6px; border: none;
  background: #33465a; color: #fff;
}
.search-box input::placeholder { color: #8fa3b3; }
.search-results {
  position: absolute; top: 110%; left: 0; width: 340px; max-height: 420px;
  overflow-y: auto; background: #fff; color: #22303c; border-radius: 8px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.25); z-index: 50;
}
.search-results .result { display: block; padding: 0.55rem 0.7rem; border-bottom: 1px solid #eef1f4; }
.search-results .result:hover { background: #f0f6fa; text-decoration: none; }
.search-results .result .r-title { font-weight: 600; font-size: 0.88rem; }
.search-results .result .r-meta { font-size: 0.75rem; color: #7b8a97; }
.search-results .result .r-snippet { font-size: 0.8rem; color: #45535f; }
.search-results mark { background: #ffe9a8; padding: 0 1px; }
.search-results .none { padding: 0.6rem 0.7rem; color: #7b8a97; font-size: 0.85rem; }

main { flex: 1; padding: 1.6rem 2rem; max-width: 1000px; }

.flash {
  background: #e2f3e8; border: 1px solid #b8e0c5; color: #1e6b3a;
  border-radius: 8px; padding: 0.5rem 0.9rem; margin-bottom: 0.8rem;
}
.flash.error { background: #fdeaea; border-color: #f2c4c4; color: #93312d; }

.upload-panel {
  background: #fff; border: 1px solid #e3e8ed; border-radius: 10px;
  padding: 1rem 1.2rem; margin-bottom: 1.4rem;
}
.upload-row { display: flex; gap: 0.7rem; align-items: center; flex-wrap: wrap; }
.upload-row .or { color: #7b8a97; font-size: 0.85rem; }
.upload-row input[type="url"] {
  flex: 1; min-width: 220px; padding: 0.45rem 0.6rem;
  border: 1px solid #ccd5dd; border-radius: 6px;
}
.file-label input { display: none; }
.file-label span {
  display: inline-block; padding: 0.45rem 0.8rem; background: #eef1f4;
  border: 1px dashed #b6c2cc; border-radius: 6px; cursor: pointer; font-size: 0.9rem;
}
.hint { color: #7b8a97; font-size: 0.8rem; margin: 0.6rem 0 0; }

button.primary {
  background: #1a6b8f; color: #fff; border: none; border-radius: 6px;
  padding: 0.48rem 1rem; cursor: pointer; font-size: 0.9rem;
}
button.primary:hover { background: #15597a; }
button.danger {
  background: #fff; color: #a33; border: 1px solid #d9a0a0; border-radius: 6px;
  padding: 0.4rem 0.9rem; cursor: pointer; margin-top: 1.5rem;
}
button.danger:hover { background: #fdeaea; }

.doc-table { width: 100%; border-collapse: collapse; background: #fff;
  border: 1px solid #e3e8ed; border-radius: 10px; overflow: hidden; }
.doc-table th {
  text-align: left; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em;
  color: #7b8a97; padding: 0.6rem 0.8rem; border-bottom: 1px solid #e3e8ed;
}
.doc-table td { padding: 0.55rem 0.8rem; border-bottom: 1px solid #eef1f4; vertical-align: top; }
.doc-table tr:last-child td { border-bottom: none; }
.muted { color: #7b8a97; }
.type-badge { font-size: 0.72rem; color: #7b8a97; text-transform: uppercase; }

.empty { color: #7b8a97; padding: 2rem 0; }

.doc-detail header h2 { margin: 0 0 0.3rem; }
.meta-line { margin: 0.15rem 0; }
.tag-row { margin: 0.6rem 0; display: flex; gap: 0.4rem; flex-wrap: wrap; align-items: center; }
.tag {
  background: #e7eef3; border-radius: 999px; padding: 0.15rem 0.6rem;
  font-size: 0.82rem; color: #33465a;
}
.tag-row input {
  border: 1px dashed #b6c2cc; border-radius: 999px; padding: 0.15rem 0.6rem; font-size: 0.82rem;
}
.inline { display: inline; }

.summary {
  background: #fffbe9; border: 1px solid #f0e4b0; border-radius: 10px;
  padding: 0.8rem 1.1rem; margin: 1rem 0;
}
.summary h3 { margin: 0 0 0.3rem; font-size: 0.9rem; }
.summary p { margin: 0; }

.edit-panel { margin: 1rem 0; }
.edit-panel summary { cursor: pointer; color: #1a6b8f; }
.edit-form { display: grid; grid-template-columns: 1fr 1fr; gap: 0.6rem 1rem; margin-top: 0.7rem;
  background: #fff; border: 1px solid #e3e8ed; border-radius: 10px; padding: 1rem; }
.edit-form label { display: flex; flex-direction: column; font-size: 0.8rem; color: #7b8a97; }
.edit-form input, .edit-form select {
  padding: 0.4rem 0.5rem; border: 1px solid #ccd5dd; border-radius: 6px; font-size: 0.9rem;
}
.edit-form button { grid-column: 1 / -1; justify-self: start; }

.fulltext { margin-top: 1.4rem; }
.fulltext h3 { font-size: 0.95rem; }
.chunk {
  background: #fff; border: 1px solid #e3e8ed; border-radius: 8px;
  padding: 0.7rem 1rem; margin-bottom: 0.6rem; position: relative;
}
.chunk p { margin: 0; white-space: pre-wrap; font-size: 0.88rem; }
.page-label {
  position: absolute; top: 0.5rem; right: 0.7rem; font-size: 0.72rem; color: #a5b2bd;
}

.top-nav { margin-bottom: 0.4rem; }
.top-nav li a { font-weight: 600; }

.panel-title { margin: 0 0 0.6rem; font-size: 1rem; }
.upload-row select {
  padding: 0.45rem 0.6rem; border: 1px solid #ccd5dd; border-radius: 6px;
  max-width: 320px; background: #fff;
}
.icon-btn.dark { color: #9aa8b4; }
.icon-btn.dark:hover { color: #a33; }

.chat-view header h2 { margin: 0 0 0.2rem; }
.chat-log { margin: 1rem 0; display: flex; flex-direction: column; gap: 0.8rem; }
.msg { display: flex; flex-direction: column; }
.msg.user { align-items: flex-end; }
.msg .bubble {
  max-width: 78%; padding: 0.65rem 0.95rem; border-radius: 12px;
  background: #fff; border: 1px solid #e3e8ed; font-size: 0.92rem;
}
.msg.user .bubble { background: #1a6b8f; color: #fff; border: none; }
.msg.assistant .bubble a.cite {
  font-weight: 600; font-size: 0.8em; vertical-align: super; text-decoration: none;
}
.msg .sources {
  margin-top: 0.35rem; display: flex; flex-direction: column; gap: 0.1rem;
  font-size: 0.78rem;
}
.msg .sources a { color: #7b8a97; }
.msg .sources a:hover { color: #1a6b8f; }

.chat-input { display: flex; gap: 0.6rem; margin-top: 1rem; }
.chat-input input {
  flex: 1; padding: 0.6rem 0.8rem; border: 1px solid #ccd5dd; border-radius: 8px;
  font-size: 0.95rem;
}

.chunk:target { border-color: #1a6b8f; box-shadow: 0 0 0 2px rgba(26,107,143,0.25); }

.export-row { font-size: 0.82rem; margin: 0 0 0.5rem; }

/* ---- PDF reader ---- */
.reader-header h2 { margin: 0 0 0.2rem; }
.reader-body { display: flex; gap: 1rem; align-items: flex-start; }
.pdf-pages { flex: 1; min-width: 0; }
.pdf-page {
  position: relative; margin: 0 auto 1rem; background: #fff;
  box-shadow: 0 1px 6px rgba(0,0,0,0.15);
}
.textLayer {
  position: absolute; inset: 0; overflow: hidden; line-height: 1;
  text-align: initial; forced-color-adjust: none;
}
.textLayer span, .textLayer br {
  color: transparent; position: absolute; white-space: pre;
  cursor: text; transform-origin: 0 0;
}
.textLayer ::selection { background: rgba(26,107,143,0.35); }
.hl-rect {
  position: absolute; background: rgba(255, 213, 79, 0.42);
  pointer-events: auto; mix-blend-mode: multiply; border-radius: 2px;
}
#hl-btn {
  position: absolute; z-index: 100; background: #22303c; color: #fff;
  border: none; border-radius: 6px; padding: 0.3rem 0.7rem; cursor: pointer;
  font-size: 0.82rem; box-shadow: 0 3px 10px rgba(0,0,0,0.3);
}
.hl-panel {
  width: 250px; flex-shrink: 0; background: #fff; border: 1px solid #e3e8ed;
  border-radius: 10px; padding: 0.8rem; position: sticky; top: 1rem;
  max-height: calc(100vh - 2rem); overflow-y: auto;
}
.hl-panel h3 { margin: 0 0 0.5rem; font-size: 0.9rem; }
.hl-item {
  border-bottom: 1px solid #eef1f4; padding: 0.45rem 0; cursor: pointer;
  font-size: 0.82rem;
}
.hl-item:hover { background: #f0f6fa; }
.hl-text { color: #45535f; }
.hl-meta { color: #a5b2bd; font-size: 0.75rem; display: flex; justify-content: space-between; }
.hl-del { background: none; border: none; color: #a5b2bd; cursor: pointer; }
.hl-del:hover { color: #a33; }
.hl-doc-title { margin: 1.2rem 0 0.3rem; font-size: 1rem; }
.hl-doc-title .muted { font-weight: 400; font-size: 0.82rem; }
.hl-quote {
  margin: 0.3rem 0; padding: 0.4rem 0.9rem; border-left: 3px solid #ffd54f;
  background: #fff; font-size: 0.9rem;
}

/* ---- note editor ---- */
.note-toolbar { display: flex; gap: 0.6rem; margin-bottom: 0.5rem; }
.note-title {
  flex: 1; font-size: 1.1rem; font-weight: 600; padding: 0.45rem 0.6rem;
  border: 1px solid #ccd5dd; border-radius: 6px;
}
.note-toolbar select { border: 1px solid #ccd5dd; border-radius: 6px; padding: 0.3rem; background: #fff; }
.note-actions {
  display: flex; gap: 0.4rem; align-items: center; flex-wrap: wrap;
  margin-bottom: 0.6rem; font-size: 0.82rem;
}
.note-actions button {
  background: #fff; border: 1px solid #ccd5dd; border-radius: 6px;
  padding: 0.25rem 0.6rem; cursor: pointer; font-size: 0.8rem;
}
.note-actions button:hover { background: #eef1f4; }
.note-panes { display: flex; gap: 1rem; align-items: stretch; }
#note-body {
  flex: 1; min-height: 480px; padding: 0.8rem; border: 1px solid #ccd5dd;
  border-radius: 8px; font: 0.9rem/1.6 ui-monospace, "SF Mono", Menlo, monospace;
  resize: vertical;
}
.note-preview {
  flex: 1; background: #fff; border: 1px solid #e3e8ed; border-radius: 8px;
  padding: 0.4rem 1.1rem; overflow-y: auto; max-height: 640px; font-size: 0.92rem;
}
.note-preview .refs { font-size: 0.85rem; color: #45535f; }
.note-footer { margin-top: 0.8rem; font-size: 0.88rem; }

.picker {
  position: fixed; inset: 0; background: rgba(20,30,40,0.5); z-index: 200;
  display: flex; align-items: flex-start; justify-content: center; padding-top: 10vh;
}
.picker-box {
  background: #fff; border-radius: 12px; width: 520px; max-width: 92vw;
  padding: 0.9rem; box-shadow: 0 12px 50px rgba(0,0,0,0.35);
}
.picker-head { display: flex; justify-content: space-between; margin-bottom: 0.5rem; }
#picker-input {
  width: 100%; padding: 0.5rem 0.7rem; border: 1px solid #ccd5dd; border-radius: 8px;
}
#picker-results { max-height: 340px; overflow-y: auto; margin-top: 0.5rem; }
.picker-item {
  display: block; width: 100%; text-align: left; background: none; border: none;
  border-bottom: 1px solid #eef1f4; padding: 0.5rem 0.4rem; cursor: pointer;
}
.picker-item:hover { background: #f0f6fa; }
.picker-item .r-title { display: block; font-weight: 600; font-size: 0.88rem; }
.picker-item .r-meta { display: block; color: #7b8a97; font-size: 0.76rem; }
.picker-item .r-snippet { display: block; color: #45535f; font-size: 0.8rem; }

/* ---- login ---- */
.login-page {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; background: #22303c;
}
.login-box {
  background: #fff; border-radius: 12px; padding: 2rem 2.2rem; width: 320px;
  display: flex; flex-direction: column; gap: 0.8rem;
  box-shadow: 0 12px 50px rgba(0,0,0,0.35);
}
.login-box h1 { margin: 0 0 0.4rem; font-size: 1.2rem; text-align: center; }
.login-box input {
  padding: 0.55rem 0.7rem; border: 1px solid #ccd5dd; border-radius: 8px; font-size: 1rem;
}

/* ---- discover ---- */
.disc-card {
  display: flex; gap: 1rem; align-items: flex-start; background: #fff;
  border: 1px solid #e3e8ed; border-radius: 10px; padding: 0.8rem 1rem;
  margin-bottom: 0.7rem;
}
.disc-main { flex: 1; min-width: 0; }
.disc-card .r-title { font-weight: 600; }
.disc-card .r-meta { color: #7b8a97; font-size: 0.82rem; margin: 0.15rem 0; }
.disc-card .r-snippet { color: #45535f; font-size: 0.85rem; }
.src-badge, .oa-badge {
  display: inline-block; font-size: 0.68rem; text-transform: uppercase;
  letter-spacing: 0.05em; border-radius: 999px; padding: 0.05rem 0.5rem; margin-left: 0.3rem;
}
.src-badge { background: #eef1f4; color: #7b8a97; }
.oa-badge { background: #e2f3e8; color: #1e6b3a; }
.import-btn { flex-shrink: 0; }
.view-link { display: block; font-size: 0.8rem; text-align: center; margin-top: 0.3rem; }
.deep-panel { margin-top: 1.4rem; border-left: 4px solid #1a6b8f; }

@media (max-width: 900px) {
  .note-panes { flex-direction: column; }
  .reader-body { flex-direction: column; }
  .hl-panel { width: 100%; position: static; }
}

@media (max-width: 760px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; }
  .edit-form { grid-template-columns: 1fr; }
}
