* { box-sizing: border-box; }
body {
  margin: 0;
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: #221c3a;
  background: #faf7f1;
}
/* brand display face — matches myownarc.com */
h1, h2, .panel-title { font-family: 'Fraunces', Georgia, serif; letter-spacing: -0.01em; }
a { color: #5b4bd4; text-decoration: none; }
a:hover { text-decoration: underline; }

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

.sidebar {
  width: 260px;
  flex-shrink: 0;
  background: #221c3a;
  color: #dedaf0;
  padding: 1.2rem 1rem;
}
.sidebar h1 { font-size: 1.25rem; margin: 0 0 1rem; }
.sidebar h1 a { color: #fff; display: flex; align-items: center; gap: 8px; }
.sidebar h1 .arc-word, .mb-title .arc-word { color: #8f7ff0; }
.sidebar h2 {
  font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.08em;
  color: #9b95b8; 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: #dedaf0; display: block; padding: 0.28rem 0.5rem; flex: 1; }
.sidebar li.active { background: #352e55; }
.sidebar .count { color: #9b95b8; 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: #352e55; border: none; color: #fff;
  border-radius: 6px; padding: 0.3rem 0.5rem;
}
.new-folder button, .icon-btn {
  background: none; border: none; color: #9b95b8; 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: #352e55; color: #fff;
}
.search-box input::placeholder { color: #9b95b8; }
.search-results {
  position: absolute; top: 110%; left: 0; width: 340px; max-height: 420px;
  overflow-y: auto; background: #fff; color: #221c3a; 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 #f0ece3; }
.search-results .result:hover { background: #f3eee4; 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: #6b6580; }
.search-results .result .r-snippet { font-size: 0.8rem; color: #4c4763; }
.search-results mark { background: #ffe9a8; padding: 0 1px; }
.search-results .none { padding: 0.6rem 0.7rem; color: #6b6580; 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 #e5e1d6; 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: #6b6580; font-size: 0.85rem; }
.upload-row input[type="url"] {
  flex: 1; min-width: 220px; padding: 0.45rem 0.6rem;
  border: 1px solid #cfc9bd; border-radius: 6px;
}
.file-label input { display: none; }
.file-label span {
  display: inline-block; padding: 0.45rem 0.8rem; background: #f0ece3;
  border: 1px dashed #c2bcae; border-radius: 6px; cursor: pointer; font-size: 0.9rem;
}
.hint { color: #6b6580; font-size: 0.8rem; margin: 0.6rem 0 0; }

button.primary {
  background: #5b4bd4; color: #fff; border: none; border-radius: 6px;
  padding: 0.48rem 1rem; cursor: pointer; font-size: 0.9rem;
}
button.primary:hover { background: #43389f; }
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 #e5e1d6; border-radius: 10px; overflow: hidden; }
.doc-table th {
  text-align: left; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em;
  color: #6b6580; padding: 0.6rem 0.8rem; border-bottom: 1px solid #e5e1d6;
}
.doc-table td { padding: 0.55rem 0.8rem; border-bottom: 1px solid #f0ece3; vertical-align: top; }
.doc-table tr:last-child td { border-bottom: none; }
.muted { color: #6b6580; }
.type-badge { font-size: 0.72rem; color: #6b6580; text-transform: uppercase; }

.empty { color: #6b6580; 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: #ece8f9; border-radius: 999px; padding: 0.15rem 0.6rem;
  font-size: 0.82rem; color: #352e55;
}
a.tag { text-decoration: none; }
.ideas-search { display: flex; gap: 0.4rem; align-items: center; margin: 0.6rem 0; flex-wrap: wrap; }
.ideas-search input[type="search"] { flex: 1; min-width: 12rem; max-width: 24rem; }
a.tag:hover { background: #ddd6f5; }
.tag.active { background: #352e55; color: #fff; }
.tag-row input {
  border: 1px dashed #c2bcae; 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: #5b4bd4; }
.edit-form { display: grid; grid-template-columns: 1fr 1fr; gap: 0.6rem 1rem; margin-top: 0.7rem;
  background: #fff; border: 1px solid #e5e1d6; border-radius: 10px; padding: 1rem; }
.edit-form label { display: flex; flex-direction: column; font-size: 0.8rem; color: #6b6580; }
.edit-form input, .edit-form select {
  padding: 0.4rem 0.5rem; border: 1px solid #cfc9bd; 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 #e5e1d6; 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: #a29cb8;
}

.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 #cfc9bd; border-radius: 6px;
  max-width: 320px; background: #fff;
}
.icon-btn.dark { color: #9b95b8; }
.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 #e5e1d6; font-size: 0.92rem;
}
.msg.user .bubble { background: #5b4bd4; color: #fff; border: none; }
.msg.assistant .bubble a.cite {
  display: inline-block; background: #efeafd; color: #43389f; border-radius: 5px;
  padding: 0 5px; font-weight: 700; font-size: 0.78em; line-height: 1.5;
  vertical-align: super; text-decoration: none;
}
.msg.assistant .bubble a.cite:hover { background: #ded3fb; 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: #6b6580; }
.msg .sources a:hover { color: #5b4bd4; }

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

/* citation landing: the passage highlights the way the marketing demo
   promises — amber wash, not a subtle ring */
.chunk { scroll-margin-top: 1rem; }
.chunk:target {
  border-color: #e8a13d; background: #fff7df;
  box-shadow: 0 0 0 3px rgba(232,161,61,0.3);
}

.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(91,75,212,0.3); }
.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: #221c3a; 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 #e5e1d6;
  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 #f0ece3; padding: 0.45rem 0; cursor: pointer;
  font-size: 0.82rem;
}
.hl-item:hover { background: #f3eee4; }
.hl-text { color: #4c4763; }
.hl-meta { color: #a29cb8; font-size: 0.75rem; display: flex; justify-content: space-between; }
.hl-del { background: none; border: none; color: #a29cb8; 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 #e8a13d;
  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 #cfc9bd; border-radius: 6px;
}
.note-toolbar select { border: 1px solid #cfc9bd; 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 #cfc9bd; border-radius: 6px;
  padding: 0.25rem 0.6rem; cursor: pointer; font-size: 0.8rem;
}
.note-actions button:hover { background: #f0ece3; }
.note-panes { display: flex; gap: 1rem; align-items: stretch; }
#note-body {
  flex: 1; min-height: 480px; padding: 0.8rem; border: 1px solid #cfc9bd;
  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 #e5e1d6; 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: #4c4763; }
.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 #cfc9bd; 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 #f0ece3; padding: 0.5rem 0.4rem; cursor: pointer;
}
.picker-item:hover { background: #f3eee4; }
.picker-item .r-title { display: block; font-weight: 600; font-size: 0.88rem; }
.picker-item .r-meta { display: block; color: #6b6580; font-size: 0.76rem; }
.picker-item .r-snippet { display: block; color: #4c4763; font-size: 0.8rem; }

/* ---- login ---- */
.login-page {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; background: #221c3a;
}
.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-brand {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  font-family: 'Fraunces', Georgia, serif; font-weight: 700; font-size: 1.35rem;
  color: #221c3a; margin-bottom: 0.2rem;
}
.login-brand .arc-word { color: #5b4bd4; }
.login-links { text-align: center; font-size: 0.78rem; color: #6b6580; margin-top: 0.4rem; }
.login-links a { color: #6b6580; }
.login-links a:hover { color: #221c3a; }
.login-box input {
  padding: 0.55rem 0.7rem; border: 1px solid #cfc9bd; border-radius: 8px; font-size: 1rem;
}

/* ---- discover ---- */
.disc-card {
  display: flex; gap: 1rem; align-items: flex-start; background: #fff;
  border: 1px solid #e5e1d6; 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: #6b6580; font-size: 0.82rem; margin: 0.15rem 0; }
.disc-card .r-snippet { color: #4c4763; 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: #f0ece3; color: #6b6580; }
.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 #5b4bd4; }

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

/* mobile top bar — hidden on desktop */
.mobile-bar { display: none; }

@media (max-width: 760px) {
  .layout { flex-direction: column; }
  /* the full menu is taller than a phone screen, so it collapses behind ☰ */
  .sidebar { display: none; width: 100%; }
  .sidebar.open { display: block; }
  .mobile-bar {
    display: flex; align-items: center; gap: 0.6rem; position: sticky; top: 0;
    z-index: 60; background: #221c3a; padding: 0.55rem 0.8rem;
  }
  .mobile-bar .mb-title { color: #fff; font-weight: 600; }
  #menu-toggle {
    background: none; border: none; color: #fff; font-size: 1.35rem;
    cursor: pointer; padding: 0 0.2rem; line-height: 1;
  }
  main { padding: 1rem; }
  /* wide tables scroll sideways instead of crushing their columns */
  .doc-table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .edit-form { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  /* phone library shows title / authors / year; the rest lives on the
     document page a tap away */
  .doc-table .col-m-hide { display: none; }
}

/* sortable library columns */
.doc-table th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
.doc-table th.sortable:hover { text-decoration: underline; }
.doc-table th.sorted-asc::after { content: " ▲"; font-size: 0.7em; }
.doc-table th.sorted-desc::after { content: " ▼"; font-size: 0.7em; }

/* ---------- admin ---------- */
.btn-sm {
  background: #fff; border: 1px solid #cfc9bd; border-radius: 6px;
  padding: 0.3rem 0.7rem; cursor: pointer; font-size: 0.82rem; color: #221c3a;
}
.btn-sm:hover { background: #f3eee4; }
.btn-sm.violet { background: #5b4bd4; border-color: #5b4bd4; color: #fff; }
.btn-sm.violet:hover { background: #43389f; }
.msg-card {
  border: 1px solid #e5e1d6; border-radius: 8px; padding: 0.7rem 0.9rem;
  margin-bottom: 0.6rem; background: #fff;
}
.msg-card.resolved { opacity: 0.7; }
.msg-card .msg-meta { color: #6b6580; font-size: 0.8rem; margin: 0 0 0.3rem; }
.msg-card .msg-body { white-space: pre-wrap; margin: 0 0 0.4rem; }
.admin-search { display: flex; gap: 0.4rem; align-items: center; margin-bottom: 0.8rem; }
.admin-search input {
  padding: 0.4rem 0.6rem; border: 1px solid #cfc9bd; border-radius: 6px; min-width: 220px;
}
.expand-row td { background: #faf7f1; font-size: 0.85rem; }
.actions-cell { display: flex; flex-direction: column; gap: 0.35rem; align-items: flex-start; }
.actions-cell form { display: flex; gap: 0.3rem; align-items: center; }
.pw-form { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }
.pw-form input {
  padding: 0.45rem 0.6rem; border: 1px solid #cfc9bd; border-radius: 6px; font-size: 0.9rem;
}

/* ---------- extraction matrices ---------- */
.matrix-scroll { overflow-x: auto; }
.matrix-table th { white-space: nowrap; }
.matrix-table td { font-size: 0.85rem; vertical-align: top; min-width: 130px; max-width: 260px; }
.matrix-table .matrix-doc-col { min-width: 200px; max-width: 280px; }
.matrix-table td[title] { cursor: help; }
