*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --paper:      #FAF9F6;
  --paper-warm: #F3F1EC;
  --ink:        #1A1A1A;
  --ink-soft:   #6B6B68;
  --ink-faint:  #A8A8A4;
  --line:       #E8E6E1;
  --accent:     #5B5F97;
  --accent-soft:#ECEDF6;
  --accent-mid: #C9CBEE;
  --tag-soft:   #F8F1E7;
  --green:      #6FAE7C;
  --radius:     12px;
}

body {
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--paper);
  font-family: 'Inter', system-ui, sans-serif;
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

.content-area {
  flex: 1;
  display: flex;
  overflow: hidden;
}

/* ---------- Header ---------- */
header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 13px 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(250,249,246,0.92);
  backdrop-filter: blur(8px);
  flex-shrink: 0;
}

.brand {
  font-family: 'Fraunces', serif;
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.03em;
  flex-shrink: 0;
}
.brand a {
  color: inherit;
  text-decoration: none;
  cursor: pointer;
}


.search-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 6px 5px 16px;
  box-shadow: 0 2px 10px rgba(26,26,26,0.05);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.search-wrap:focus-within {
  border-color: var(--accent-mid);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

#searchInput {
  flex: 1;
  border: none; outline: none;
  font-size: 13.5px;
  font-family: inherit;
  background: transparent;
  color: var(--ink);
  min-width: 0;
}

#searchInput::placeholder { color: var(--ink-faint); }
#searchInput:disabled     { cursor: not-allowed; }

#searchBtn {
  border: none;
  background: var(--accent);
  color: #fff;
  width: 30px; height: 30px;
  border-radius: 50%;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  padding: 0;
  transition: background 0.15s, transform 0.1s;
}

#searchBtn:hover   { background: #4A4E85; }
#searchBtn:active  { transform: scale(0.9); }
#searchBtn:disabled { background: var(--accent-mid); cursor: default; }

#clearBtn {
  border: 1px solid var(--line);
  background: var(--paper-warm);
  color: var(--ink-soft);
  font-size: 12px;
  font-family: inherit;
  padding: 5px 13px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  display: none;
  transition: border-color 0.15s, color 0.15s;
}

#clearBtn:hover { border-color: var(--accent); color: var(--accent); }
#clearBtn.visible { display: block; }

#selectBtn {
  padding: 6px 16px;
  font-size: 12.5px;
  font-family: inherit;
  background: var(--ink);
  color: var(--paper);
  border: none;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: background 0.15s;
}

#selectBtn:hover    { background: #333; }
#selectBtn:disabled { background: #999; cursor: default; }

/* ---------- Storage chip ---------- */
.storage-chip {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex-shrink: 0;
  min-width: 80px;
}

.storage-bar-track {
  width: 100%;
  height: 3px;
  background: var(--line);
  border-radius: 999px;
  overflow: hidden;
}

.storage-bar-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.5s ease, background 0.3s ease;
}

.storage-bar-fill.near-full { background: #D4A82B; }
.storage-bar-fill.full      { background: #C0392B; }

.storage-label {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  color: var(--ink-faint);
  white-space: nowrap;
  text-align: right;
}

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

.sidebar-header {
  padding: 16px 14px 10px;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}

.sidebar-title {
  font-family: 'Fraunces', serif;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-soft);
  letter-spacing: 0.01em;
}

#folderList {
  flex: 1;
  overflow-y: auto;
  padding: 8px 6px;
}

#folderList::-webkit-scrollbar { width: 4px; }
#folderList::-webkit-scrollbar-thumb { background: var(--line); border-radius: 999px; }

.sidebar-empty {
  font-size: 11.5px;
  color: var(--ink-faint);
  line-height: 1.6;
  padding: 12px 8px;
  text-align: center;
}

/* ---------- Sidebar loading skeleton ---------- */
.sidebar-skeleton {
  padding: 6px 4px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.skeleton-row {
  height: 36px;
  border-radius: 8px;
  background: linear-gradient(90deg,
    var(--line) 25%,
    var(--paper-warm) 50%,
    var(--line) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite ease-in-out;
}

.skeleton-row.short { width: 70%; }

@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.folder-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 9px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
  position: relative;
}

.folder-item:hover {
  background: var(--line);
}

.folder-item.active {
  background: var(--accent-soft);
}

.folder-item.active .folder-name {
  color: var(--accent);
}

.folder-icon {
  font-size: 16px;
  flex-shrink: 0;
  line-height: 1;
}

.folder-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.folder-name {
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--ink);
  line-height: 1.3;
}

.folder-meta {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  color: var(--ink-faint);
}

.folder-remove {
  opacity: 0;
  border: none;
  background: none;
  cursor: pointer;
  color: var(--ink-faint);
  font-size: 14px;
  line-height: 1;
  padding: 2px 4px;
  border-radius: 4px;
  flex-shrink: 0;
  transition: opacity 0.12s, color 0.12s, background 0.12s;
}

.folder-item:hover .folder-remove {
  opacity: 1;
}

.folder-remove:hover {
  color: #C0392B;
  background: rgba(192,57,43,0.08);
}

/* ---------- Main ---------- */
main {
  flex: 1;
  overflow-y: auto;
  padding: 22px 24px 180px;
}

/* ---------- Path row / breadcrumb ---------- */
.path-row {
  display: flex;
  align-items: center;
  gap: 5px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11.5px;
  color: var(--ink-soft);
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.path-row .crumb { color: var(--ink-soft); }
.path-row .crumb.current { color: var(--ink); font-weight: 500; }

.path-row .crumb-link {
  cursor: pointer;
  color: var(--ink-soft);
  transition: color 0.12s;
}
.path-row .crumb-link:hover { color: var(--accent); text-decoration: underline; }

.path-row .sep { color: var(--line); }

.back-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 22px; height: 22px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink-soft);
  padding: 0;
  cursor: pointer;
  margin-right: 2px;
  flex-shrink: 0;
  transition: border-color 0.12s, color 0.12s;
}
.back-btn:hover { border-color: var(--accent); color: var(--accent); }
.path-row.in-folder .back-btn { display: flex; }

/* ---------- Folder cards ---------- */
.folder-card {
  background: var(--paper-warm) !important;
  cursor: pointer !important;
}

.folder-card:hover {
  background: var(--line) !important;
  border-color: var(--ink-faint) !important;
}

.folder-chevron {
  font-size: 16px;
  color: var(--ink-faint);
  line-height: 1;
}

/* ---------- Section header ---------- */
.section-row {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 16px;
}

.section-label {
  font-family: 'Fraunces', serif;
  font-size: 15px;
  font-weight: 500;
}

.section-count {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  color: var(--ink-faint);
}

.results-summary {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  color: var(--ink-soft);
  margin-bottom: 16px;
  display: none;
}

.results-summary.visible { display: block; }

/* ---------- AI response bubble ---------- */
.ai-response {
  display: none;
  align-items: flex-start;
  gap: 10px;
  background: var(--accent-soft);
  border: 1px solid var(--accent-mid);
  border-radius: 12px;
  padding: 11px 14px;
  margin-bottom: 18px;
  animation: fadeSlideIn 0.25s ease both;
}

.ai-response.visible { display: flex; }

@keyframes fadeSlideIn {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.ai-avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-family: 'Inter', sans-serif;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.03em;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 1px;
}

.ai-text {
  font-size: 13px;
  line-height: 1.55;
  color: var(--ink);
}

/* ---------- Index progress banner ---------- */
.index-banner {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--paper-warm);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 14px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11.5px;
  color: var(--ink-soft);
  margin-bottom: 18px;
}

.index-banner .bar {
  flex: 1;
  height: 3px;
  background: var(--line);
  border-radius: 999px;
  overflow: hidden;
}

.index-banner .bar-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.4s ease;
}

.index-banner .accent-num { color: var(--accent); font-weight: 500; }
.index-banner.hidden { display: none; }

.index-stop-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
  background: none;
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 3px 8px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 10.5px;
  color: var(--ink-soft);
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.index-stop-btn:hover {
  border-color: #e05252;
  color: #e05252;
  background: rgba(224, 82, 82, 0.06);
}

/* ---------- File grid ---------- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
  gap: 12px;
}

.file-card {
  position: relative;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 13px 12px;
  cursor: default;
  transition: opacity 0.3s ease, filter 0.3s ease,
              transform 0.2s ease, box-shadow 0.2s ease,
              border-color 0.2s ease;
  animation: cardIn 0.22s ease both;
}

@keyframes cardIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes newFilePulse {
  0%   { box-shadow: 0 0 0 0 rgba(91,95,151,0.35); border-color: var(--accent); }
  60%  { box-shadow: 0 0 0 6px rgba(91,95,151,0); border-color: var(--accent); }
  100% { box-shadow: none; border-color: var(--line); }
}

.file-card--new {
  animation: cardIn 0.22s ease both, newFilePulse 2.5s ease 0.3s forwards;
}

.file-card:hover {
  box-shadow: 0 4px 16px rgba(26,26,26,0.07);
  transform: translateY(-1px);
}

/* ---------- Open-in-new-tab button ---------- */
.open-btn {
  position: absolute;
  bottom: 10px;
  right: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink-light);
  cursor: pointer;
  opacity: 0;
  transform: scale(0.85);
  transition: opacity 0.15s ease, transform 0.15s ease,
              color 0.15s ease, border-color 0.15s ease;
  padding: 0;
}

.file-card:hover .open-btn {
  opacity: 1;
  transform: scale(1);
}

.open-btn:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: rgba(91,95,151,0.06);
}

.card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 10px;
}

.file-icon { font-size: 22px; line-height: 1; }

.index-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  margin-top: 3px;
  flex-shrink: 0;
}

.index-dot.indexed   { background: var(--green); }
.index-dot.indexing  { background: #D4A82B; animation: pulse 1s infinite; }
.index-dot.skipped   { background: var(--line); }
.index-dot.oversize  { background: #E05A4E; }

@keyframes pulse {
  0%, 100% { opacity: 1; } 50% { opacity: 0.3; }
}

.file-name {
  font-size: 12.5px;
  font-weight: 500;
  line-height: 1.4;
  margin-bottom: 5px;
  word-break: break-word;
}

.file-meta {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10.5px;
  color: var(--ink-faint);
}

/* match score badge */
.match-score {
  position: absolute;
  top: 10px; right: 10px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 999px;
  padding: 2px 7px;
  display: none;
}

/* tags */
.file-tags {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
  margin-top: 9px;
  min-height: 0;
}

.tag-chip {
  font-size: 10px;
  background: var(--tag-soft);
  color: #8A6A42;
  border-radius: 999px;
  padding: 2px 8px;
  font-weight: 500;
  white-space: nowrap;
}

/* match snippet */
.match-snippet {
  display: none;
  margin-top: 10px;
  font-size: 11px;
  line-height: 1.45;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 7px;
  padding: 6px 8px;
  font-style: italic;
}


/* ---------- Filtering states ---------- */
.grid.filtering .file-card {
  opacity: 0.2;
  filter: saturate(0.2) blur(1.5px);
  pointer-events: none;
}

.grid.filtering .file-card.match {
  opacity: 1;
  filter: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent), 0 6px 20px rgba(91,95,151,0.12);
  pointer-events: auto;
}

.grid.filtering .file-card.match .match-score   { display: block; }
.grid.filtering .file-card.match .match-snippet  { display: block; }

/* ---------- Empty state ---------- */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 60vh;
  gap: 14px;
  color: var(--ink-faint);
  text-align: center;
}

.empty-state .big-icon { font-size: 40px; }

.empty-state p {
  font-size: 14px;
  line-height: 1.6;
  max-width: 300px;
}

/* ---------- Status pill ---------- */
#status {
  position: fixed;
  bottom: 24px; left: 50%;
  transform: translateX(-50%);
  font-family: 'JetBrains Mono', monospace;
  font-size: 12.5px;
  background: var(--ink);
  color: var(--paper);
  padding: 7px 16px;
  border-radius: 999px;
  opacity: 0;
  transition: opacity 0.2s ease;
  pointer-events: none;
  white-space: nowrap;
  z-index: 100;
}

/* scrollbar */
main::-webkit-scrollbar { width: 5px; }
main::-webkit-scrollbar-thumb { background: var(--line); border-radius: 999px; }

/* ---------- Search suggestions dropdown ---------- */
.search-suggestions {
  position: fixed;
  top: 0; /* set by JS */
  left: 0; /* set by JS */
  width: 0; /* set by JS */
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 12px 40px rgba(26,26,26,0.13), 0 2px 8px rgba(26,26,26,0.06);
  padding: 8px 6px;
  display: flex;
  flex-direction: column;
  gap: 1px;
  z-index: 500;
  opacity: 0;
  transform: translateY(-6px);
  visibility: hidden;
  transition: opacity 0.18s ease, transform 0.18s ease, visibility 0.18s;
  pointer-events: none;
}

.search-suggestions.open {
  opacity: 1;
  transform: translateY(0);
  visibility: visible;
  pointer-events: auto;
}

.sugg-label {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  color: var(--ink-faint);
  padding: 4px 12px 8px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.sugg-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.1s, color 0.1s;
  font-size: 13px;
  color: var(--ink-soft);
  line-height: 1.3;
}

.sugg-chip:hover {
  background: var(--accent-soft);
  color: var(--accent);
}

.sugg-chip:hover .sugg-icon { opacity: 1; }

.sugg-icon {
  font-size: 14px;
  flex-shrink: 0;
  opacity: 0.55;
  width: 18px;
  text-align: center;
}

/* ---------- Folder-picker modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(26,26,26,0.35);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.modal-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.modal {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 32px 30px 26px;
  width: 360px;
  max-width: 90vw;
  box-shadow: 0 20px 60px rgba(26,26,26,0.16);
  display: flex;
  flex-direction: column;
  gap: 0;
  transform: translateY(8px) scale(0.98);
  transition: transform 0.22s ease;
}

.modal-overlay.open .modal {
  transform: translateY(0) scale(1);
}

.modal-icon {
  font-size: 34px;
  margin-bottom: 14px;
  line-height: 1;
}

.modal-title {
  font-family: 'Fraunces', serif;
  font-size: 19px;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--ink);
  margin-bottom: 10px;
}

.modal-body {
  font-size: 13.5px;
  line-height: 1.6;
  color: var(--ink-soft);
  margin-bottom: 20px;
}

.modal-privacy {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  background: var(--paper-warm);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 22px;
}

.modal-privacy-icon {
  font-size: 15px;
  flex-shrink: 0;
  margin-top: 1px;
}

.modal-privacy-text {
  font-size: 11.5px;
  line-height: 1.5;
  color: var(--ink-soft);
}

.modal-privacy-text strong {
  color: var(--ink);
  font-weight: 600;
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.modal-cancel {
  border: 1px solid var(--line);
  background: var(--paper-warm);
  color: var(--ink-soft);
  font-family: inherit;
  font-size: 13px;
  padding: 8px 18px;
  border-radius: 999px;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}

.modal-cancel:hover { border-color: var(--ink-soft); color: var(--ink); }

.modal-confirm {
  border: none;
  background: var(--ink);
  color: var(--paper);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  padding: 8px 20px;
  border-radius: 999px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 7px;
  transition: background 0.15s;
}

.modal-confirm:hover { background: #333; }

.modal-confirm--danger {
  background: #c0392b;
}
.modal-confirm--danger:hover { background: #a93226; }
