:root {
  --app-bg: #f6f6f2;
  --app-surface: rgba(255,255,255,.86);
  --app-border: rgba(20,20,20,.08);
}

body {
  background: var(--app-bg);
  color: #181818;
  min-height: 100vh;
}

.app-nav {
  background: rgba(246, 246, 242, .88);
  backdrop-filter: blur(14px);
}

.brand-mark {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  display: inline-grid;
  place-items: center;
  background: #171717;
  color: white;
  font-size: .9rem;
}

.searchbar { width: min(420px, 52vw); }
.searchbar .form-control { border-radius: 999px; background: rgba(255,255,255,.75); }

.eyebrow {
  font-size: .75rem;
  letter-spacing: .11em;
  text-transform: uppercase;
  font-weight: 700;
  color: #6f6f68;
}

.card, .empty-state { border-radius: 1.1rem; }
.empty-state { background: rgba(255,255,255,.56); border: 1px dashed rgba(0,0,0,.14); }
.collection-card { background: var(--app-surface); transition: transform .16s ease, box-shadow .16s ease; }
.collection-card:hover { transform: translateY(-2px); box-shadow: 0 .65rem 1.8rem rgba(0,0,0,.08)!important; }
.collection-icon { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; background: #efefe9; color: #222; font-size: 1.35rem; }
.count-pill { min-width: 34px; height: 34px; padding: 0 .65rem; border-radius: 999px; display: grid; place-items: center; background: #191919; color: #fff; font-size: .78rem; }
.capture-card { background: rgba(255,255,255,.8); }
.item-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; align-items: start; }
.item-card { background: rgba(255,255,255,.9); overflow: hidden; }
.item-content { white-space: pre-wrap; line-height: 1.6; color: #2c2c2c; }
.note-box { white-space: pre-wrap; background: #f2f2ed; border-left: 3px solid #1d1d1b; border-radius: .55rem; padding: .8rem 1rem; }
.source-link { color: #5f5f59; font-size: .9rem; }
.tag { background: #efefe9; border-radius: 999px; padding: .28rem .58rem; font-size: .78rem; color: #55554f; }
.min-w-0 { min-width: 0; }
.form-control, .form-select { border-radius: .75rem; border-color: rgba(0,0,0,.13); }
.btn { border-radius: .72rem; }

@media (max-width: 767.98px) {
  .item-grid { grid-template-columns: 1fr; }
  .searchbar { width: 48vw; }
  .navbar-brand { font-size: 1rem; }
}

.inbox-card {
  background: #181818;
  color: white;
  transition: transform .16s ease, box-shadow .16s ease;
}
.inbox-card:hover { transform: translateY(-2px); box-shadow: 0 .65rem 1.8rem rgba(0,0,0,.14)!important; }
.inbox-card .text-body { color: white !important; }
.inbox-card .text-secondary, .inbox-card .eyebrow { color: rgba(255,255,255,.62) !important; }
.inbox-card .count-pill { background: white; color: #181818; }
.quick-capture { background: rgba(255,255,255,.82); }
.preview-image-wrap { display: block; aspect-ratio: 16 / 9; overflow: hidden; background: #ecece6; }
.preview-image { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .2s ease; }
.item-card:hover .preview-image { transform: scale(1.015); }
.metadata-description {
  color: #5a5a54;
  line-height: 1.55;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.metadata-box { background: #f2f2ed; border-radius: .8rem; }

/* V0.4: navigation, favorites, archive & filters */
.collection-switcher {
  display: flex;
  gap: .5rem;
  overflow-x: auto;
  padding-bottom: .25rem;
  scrollbar-width: thin;
}
.collection-switcher-link {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: .55rem;
  padding: .48rem .7rem .48rem .85rem;
  border: 1px solid var(--app-border);
  border-radius: 999px;
  color: #5a5a54;
  background: rgba(255,255,255,.62);
  text-decoration: none;
  font-size: .86rem;
}
.collection-switcher-link:hover { color: #181818; background: rgba(255,255,255,.92); }
.collection-switcher-link.active { background: #181818; color: white; border-color: #181818; }
.collection-switcher-count {
  min-width: 1.55rem;
  height: 1.55rem;
  padding: 0 .35rem;
  display: inline-grid;
  place-items: center;
  border-radius: 999px;
  background: rgba(0,0,0,.07);
  font-size: .7rem;
}
.collection-switcher-link.active .collection-switcher-count { background: rgba(255,255,255,.16); }

.stat-card {
  height: 100%;
  min-height: 74px;
  padding: .8rem 1rem;
  border: 1px solid var(--app-border);
  border-radius: .9rem;
  background: rgba(255,255,255,.58);
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.stat-card strong { font-size: 1.2rem; line-height: 1; }
.stat-card span { margin-top: .35rem; color: #77776f; font-size: .76rem; }

.view-tabs {
  display: inline-flex;
  gap: .2rem;
  padding: .25rem;
  border-radius: .8rem;
  background: rgba(0,0,0,.055);
}
.view-tab {
  display: inline-flex;
  align-items: center;
  gap: .45rem;
  padding: .45rem .7rem;
  border-radius: .62rem;
  text-decoration: none;
  color: #62625d;
  font-size: .84rem;
  font-weight: 600;
}
.view-tab span { font-size: .7rem; opacity: .7; }
.view-tab.active { background: white; color: #181818; box-shadow: 0 .1rem .35rem rgba(0,0,0,.06); }

.filter-bar { background: rgba(255,255,255,.72); }
.filter-bar .form-label { margin-bottom: .3rem; color: #686862; }
.favorite-button {
  width: 34px;
  height: 31px;
  border: 1px solid rgba(0,0,0,.1);
  background: rgba(255,255,255,.72);
  color: #6a6a64;
  font-size: 1.05rem;
  line-height: 1;
}
.favorite-button:hover, .favorite-button.active { background: #181818; color: white; border-color: #181818; }
.favorite-badge { background: #181818; color: white; }
.item-card.is-favorite { box-shadow: 0 .45rem 1.35rem rgba(0,0,0,.095)!important; }
.item-card.is-archived { opacity: .78; }
.item-card.is-archived:hover { opacity: 1; }
.collection-meta { display: flex; justify-content: flex-end; gap: .5rem; color: #7b7b75; font-size: .7rem; white-space: nowrap; }
.collection-meta-light { color: rgba(255,255,255,.58); }

@media (max-width: 575.98px) {
  .view-tabs { width: 100%; }
  .view-tab { flex: 1; justify-content: center; }
  .collection-stats .stat-card { min-height: 64px; }
}

/* V0.5: compact collection cards + item detail pages + rendered Markdown */
.item-grid {
  grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
  gap: .9rem;
}

.compact-item-card {
  height: 100%;
  transition: transform .16s ease, box-shadow .16s ease;
}
.compact-item-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 .65rem 1.8rem rgba(0,0,0,.09)!important;
}
.compact-item-card .preview-image-wrap { aspect-ratio: 16 / 8.7; }
.compact-title {
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.compact-domain {
  max-width: 10rem;
  color: #77776f;
  font-size: .72rem;
}
.compact-excerpt {
  color: #5d5d57;
  font-size: .88rem;
  line-height: 1.48;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.compact-note {
  padding: .55rem .7rem;
  border-radius: .6rem;
  background: #f2f2ed;
  color: #5d5d57;
  font-size: .8rem;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.compact-product { font-size: .9rem; }
.compact-tags .tag { font-size: .7rem; padding: .2rem .45rem; }
.compact-footer { border-top: 1px solid rgba(0,0,0,.06); }
.compact-footer a { color: #30302d; }
.item-actions { position: relative; z-index: 2; }
.stretched-title { position: relative; z-index: 1; }

.detail-shell { max-width: 980px; }
.detail-card { background: rgba(255,255,255,.92); border-radius: 1.25rem; }
.detail-image-wrap {
  max-height: 520px;
  overflow: hidden;
  background: #ecece6;
  border-bottom: 1px solid rgba(0,0,0,.06);
}
.detail-image {
  width: 100%;
  max-height: 520px;
  object-fit: contain;
  display: block;
  background: #f0f0eb;
}
.detail-title { font-size: clamp(1.75rem, 4vw, 2.75rem); line-height: 1.1; }
.detail-description {
  max-width: 74ch;
  color: #565650;
  font-size: 1.02rem;
  line-height: 1.65;
}
.detail-section { max-width: 82ch; }
.plain-text-body {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.72;
  color: #2d2d2a;
}
.metadata-details summary { cursor: pointer; color: #66665f; font-size: .88rem; font-weight: 600; }

.markdown-body {
  color: #292927;
  line-height: 1.72;
  overflow-wrap: anywhere;
}
.markdown-body > :first-child { margin-top: 0; }
.markdown-body > :last-child { margin-bottom: 0; }
.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4,
.markdown-body h5,
.markdown-body h6 {
  margin-top: 1.55em;
  margin-bottom: .55em;
  font-weight: 700;
  line-height: 1.25;
}
.markdown-body h1 { font-size: 1.75rem; }
.markdown-body h2 { font-size: 1.45rem; padding-bottom: .35rem; border-bottom: 1px solid rgba(0,0,0,.08); }
.markdown-body h3 { font-size: 1.2rem; }
.markdown-body p,
.markdown-body ul,
.markdown-body ol,
.markdown-body blockquote,
.markdown-body pre,
.markdown-body table { margin-bottom: 1rem; }
.markdown-body ul,
.markdown-body ol { padding-left: 1.5rem; }
.markdown-body blockquote {
  margin-left: 0;
  padding: .15rem 0 .15rem 1rem;
  border-left: 3px solid #b8b8ae;
  color: #66665f;
}
.markdown-body code {
  padding: .12rem .35rem;
  border-radius: .35rem;
  background: #eeeeea;
  font-size: .9em;
}
.markdown-body pre {
  padding: 1rem;
  overflow-x: auto;
  border-radius: .8rem;
  background: #20201e;
  color: #f5f5f2;
}
.markdown-body pre code { padding: 0; background: transparent; color: inherit; }
.markdown-body a { color: #202020; text-decoration-thickness: .08em; text-underline-offset: .15em; }
.markdown-body hr { margin: 1.6rem 0; border-color: rgba(0,0,0,.12); }
.markdown-body table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.markdown-body th,
.markdown-body td { padding: .55rem .7rem; border: 1px solid rgba(0,0,0,.1); vertical-align: top; }
.markdown-body th { background: #f1f1ec; }

@media (max-width: 575.98px) {
  .item-grid { grid-template-columns: 1fr; }
  .detail-card .card-body { padding: 1.25rem !important; }
  .detail-image-wrap, .detail-image { max-height: 360px; }
}

/* V0.6: hierarchical collections / sub-collections */
.collection-breadcrumb {
  --bs-breadcrumb-divider-color: #9a9a92;
  font-size: .82rem;
}
.collection-breadcrumb a {
  color: #66665f;
  text-decoration: none;
}
.collection-breadcrumb a:hover { color: #181818; }

.collection-tree-root {
  display: grid;
  gap: .85rem;
}
.collection-tree-node { min-width: 0; }
.collection-tree-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: .95rem 1rem;
  border: 1px solid var(--app-border);
  border-radius: 1rem;
  background: rgba(255,255,255,.78);
  transition: transform .16s ease, box-shadow .16s ease, background .16s ease;
}
.collection-tree-card:hover {
  transform: translateY(-1px);
  background: rgba(255,255,255,.96);
  box-shadow: 0 .45rem 1.35rem rgba(0,0,0,.07);
}
.collection-tree-icon {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  font-size: 1rem;
}
.collection-tree-description {
  max-width: 68ch;
  font-size: .82rem;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.collection-tree-stats {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: .55rem;
  color: #77776f;
  font-size: .7rem;
}
.collection-tree-stats .count-pill {
  min-width: 30px;
  height: 30px;
  font-size: .7rem;
}
.collection-tree-children {
  margin-top: .55rem;
  margin-left: 1.25rem;
  padding-left: 1rem;
  border-left: 2px solid rgba(0,0,0,.08);
  display: grid;
  gap: .55rem;
}
.subcollection-count {
  padding: .18rem .42rem;
  border-radius: 999px;
  background: #efefe9;
  color: #6e6e67;
  font-size: .64rem;
  white-space: nowrap;
}

.subcollection-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: .7rem;
}
.subcollection-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: .8rem;
  padding: .85rem .9rem;
  border: 1px solid var(--app-border);
  border-radius: .9rem;
  background: rgba(255,255,255,.65);
  transition: transform .16s ease, background .16s ease, box-shadow .16s ease;
}
.subcollection-card:hover {
  transform: translateY(-1px);
  background: rgba(255,255,255,.95);
  box-shadow: 0 .35rem 1rem rgba(0,0,0,.06);
}
.subcollection-icon {
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  border-radius: .65rem;
  display: grid;
  place-items: center;
  background: #ededE7;
  color: #33332f;
}
.subcollection-arrow {
  flex: 0 0 auto;
  color: #77776f;
}

@media (max-width: 575.98px) {
  .collection-tree-card { align-items: flex-start; }
  .collection-tree-stats { flex-direction: column; gap: .25rem; }
  .collection-tree-children { margin-left: .55rem; padding-left: .7rem; }
  .subcollection-grid { grid-template-columns: 1fr; }
}

/* V0.7: indexed search */
.search-provider-pill {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: .35rem .7rem;
  border: 1px solid var(--app-border);
  border-radius: 999px;
  background: rgba(255,255,255,.72);
  color: #65655f;
  font-size: .75rem;
  font-weight: 700;
}
.search-provider-pill.is-meili::before,
.search-provider-pill.is-fallback::before {
  content: '';
  width: 7px;
  height: 7px;
  border-radius: 50%;
  margin-right: .45rem;
  background: currentColor;
  opacity: .7;
}
.search-provider-pill.is-meili { color: #252522; }
.search-provider-pill.is-fallback { color: #8a6425; }
