/* ─────────────────────────────────────────────
   sidebar.css — Thread history sidebar

   Structure:
     aside#sidebar
       header#sidebar-header  (search + close btn)
       nav#thread-list        (scrollable thread list)
         section#threads-recent
         section#threads-archive
       footer#sidebar-footer  (settings + archive btns)
   ───────────────────────────────────────────── */


/* ─── Sidebar Container ─── */

#sidebar {
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100%;
  overflow: hidden;
  background: var(--color-surface-0);
  border-right: 1px solid var(--color-border);
}


/* ─── Header: search + close ─── */

#sidebar-header {
  display: flex;
  align-items: center;
  gap: var(--gutter);
  padding: var(--gutter);
}

#thread-search-input {
  flex: 1;
  min-width: 0;
  height: var(--control-h);
  padding: 0 var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface-1);
  color: var(--color-text-1);
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  outline: none;
  transition: border-color var(--duration-fast) ease;
}

#thread-search-input::placeholder {
  color: var(--color-text-4);
}

#thread-search-input:focus {
  border-color: var(--color-text-3);
}

#thread-search-input::-webkit-search-cancel-button {
  -webkit-appearance: none;
  appearance: none;
}

#btn-sidebar-close {
  display: grid;
  place-items: center;
  width: var(--control-h);
  height: var(--control-h);
  flex-shrink: 0;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--color-text-3);
  cursor: pointer;
  transition: color var(--duration-fast) ease,
              background var(--duration-fast) ease;
}

#btn-sidebar-close:hover {
  color: var(--color-text-1);
  background: var(--color-surface-2);
}

#btn-sidebar-close:active {
  background: var(--color-surface-3);
}

#btn-sidebar-close i {
  font-size: 18px;
  line-height: 1;
}

/* Hide close button on desktop — sidebar is always visible */
@media (min-width: 1024px) {
  #btn-sidebar-close {
    display: none;
  }
}


/* ─── Thread List (scrollable) ─── */

#thread-list {
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  padding: var(--gutter);
  padding-top: 0;
  scrollbar-width: thin;
  scrollbar-color: var(--color-surface-3) transparent;
}

#thread-list::-webkit-scrollbar {
  width: 4px;
}

#thread-list::-webkit-scrollbar-track {
  background: transparent;
}

#thread-list::-webkit-scrollbar-thumb {
  background: var(--color-surface-3);
  border-radius: 2px;
}


/* ─── Thread Sections ─── */

#threads-recent,
#threads-archive {
  display: grid;
  gap: 1px;
}

#threads-archive h2 {
  font-family: var(--font-ui);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-text-4);
  margin: 0;
  padding: var(--space-3) var(--space-2) var(--space-1);
}


/* ─── Thread Group Labels (time headings) ─── */

.thread-group {
  display: grid;
  gap: 1px;
}

.thread-group + .thread-group {
  margin-top: var(--space-2);
}

.thread-group-label {
  font-family: var(--font-ui);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-text-4);
  margin: 0;
  padding: var(--space-3) var(--space-2) var(--space-1);
}


/* ─── Fuzzy Search Highlighting ─── */

.thread-item mark {
  background: none;
  color: var(--color-text-1);
  font-weight: 600;
}


/* ─── Thread Items ───
   Rendered dynamically. Expected shape:
   <button class="thread-item" data-id="th_..." aria-current="true|false">
     <span class="thread-item-title">Thread title…</span>
     <time class="thread-item-time">2h ago</time>
   </button>
*/

.thread-item {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: baseline;
  gap: var(--space-2);
  width: 100%;
  padding: var(--space-2);
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--color-text-2);
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  line-height: 1.4;
  text-align: left;
  cursor: pointer;
  transition: background var(--duration-fast) ease,
              color var(--duration-fast) ease;
}

.thread-item:hover {
  background: var(--color-surface-1);
  color: var(--color-text-1);
}

.thread-item:active {
  background: var(--color-surface-2);
}

.thread-item[aria-current="true"],
.thread-item.active {
  background: var(--color-surface-2);
  color: var(--color-text-1);
}

.thread-item-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.thread-item-time {
  font-size: var(--text-xs);
  color: var(--color-text-4);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}


/* ─── Empty State ─── */

.thread-list-empty {
  display: grid;
  place-items: center;
  padding: var(--gutter);
  color: var(--color-text-4);
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  text-align: center;
  line-height: 1.5;
}


/* ─── Footer: settings + archive ─── */

#sidebar-footer {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--gutter);
  padding: var(--gutter);
  border-top: 1px solid var(--color-border);
}

#sidebar-footer button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  height: var(--control-h);
  padding: 0;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--color-text-4);
  font-family: var(--font-ui);
  font-size: var(--text-xs);
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: pointer;
  transition: color var(--duration-fast) ease,
              border-color var(--duration-fast) ease,
              background var(--duration-fast) ease;
}

#sidebar-footer button i {
  font-size: 14px;
  line-height: 1;
}

#sidebar-footer button:hover {
  color: var(--color-text-2);
  border-color: var(--color-text-4);
  background: var(--color-surface-1);
}

#sidebar-footer button:active {
  background: var(--color-surface-2);
}


/* ─── Settings Lock Indicator ─── */

#btn-settings {
  position: relative;
}

#btn-settings::after {
  content: '';
  position: absolute;
  top: 6px;
  right: 6px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--color-accent-red);
  transition: background var(--duration-fast) var(--ease-out);
}

#btn-settings[data-unlocked="true"]::after {
  background: var(--color-accent-green);
}


/* ─── Offline Indicator ─── */

#sidebar[data-offline="true"] #sidebar-header::before {
  content: 'OFFLINE';
  font-family: var(--font-ui);
  font-size: 0.5625rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--color-accent-red);
  padding: var(--space-1) var(--space-2);
  border: 1px solid var(--color-accent-red);
  border-radius: var(--radius-sm);
  opacity: 0.7;
  flex-shrink: 0;
  line-height: 1;
}


/* ─── Syncing State ─── */

.thread-item.syncing {
  opacity: 0.5;
}

#sidebar.syncing #sidebar-header::after {
  content: '';
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-left: var(--space-2);
  border-radius: 50%;
  background: var(--color-accent-yellow);
  animation: sidebar-sync-pulse 1.2s ease-in-out infinite;
}

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