:root {
  --panel-bg: #fdfdfd;
  --accent: #006ba6;
  --muted: #666;
}

.collections-panel {
  margin-top: 1rem;
  background: var(--panel-bg);
  padding: 1.25rem;
  border-radius: 0.5rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.collections-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.collections-summary {
  font-size: 0.9rem;
  color: var(--muted);
  margin: 0.125rem 0;
}

.saved-views-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  margin-bottom: 0.85rem;
}

.saved-view-chip {
  display: inline-flex;
  align-items: center;
  padding: 0.35rem 0.8rem;
  border-radius: 999px;
  border: 1px solid #cbd5e1;
  background: #fff;
  color: #334155;
  text-decoration: none;
  font-size: 0.88rem;
  font-weight: 600;
}

.saved-view-chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.collections-toolbar {
  display: grid;
  gap: 0.9rem;
  margin-bottom: 0.75rem;
  padding: 0.85rem;
  border: 1px solid #e2e8f0;
  border-radius: 0.65rem;
  background: #fafcff;
}

.toolbar-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 0.75rem;
}

.toolbar-field {
  display: grid;
  gap: 0.3rem;
}

.toolbar-search {
  min-width: min(100%, 260px);
}

.toolbar-field label {
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: #475569;
}

.collections-toolbar input[type="search"],
.compact-select {
  width: 100%;
  min-height: 2.4rem;
}

.toolbar-actions {
  display: flex;
  gap: 0.65rem;
  align-items: center;
  flex-wrap: wrap;
}

.clear-filters {
  color: #475569;
  font-size: 0.92rem;
  text-decoration: underline;
}

.collections-refresh {
  font-size: 0.9rem;
}

.collections-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.85rem;
}

.detail-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  z-index: 40;
}

.detail-drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: min(440px, 100%);
  height: 100vh;
  background: #fff;
  box-shadow: -8px 0 30px rgba(15, 23, 42, 0.18);
  z-index: 50;
  display: grid;
  grid-template-rows: auto 1fr;
}

.detail-drawer-header {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-start;
  padding: 1.1rem 1.2rem;
  border-bottom: 1px solid #e2e8f0;
}

.detail-kicker {
  margin: 0 0 0.2rem;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #64748b;
}

.detail-drawer-header h2 {
  margin: 0;
  font-size: 1.2rem;
}

.detail-handle {
  margin: 0.2rem 0 0;
  color: #64748b;
  word-break: break-all;
}

.detail-close {
  border: 1px solid #cbd5e1;
  background: #fff;
  border-radius: 999px;
  width: 2rem;
  height: 2rem;
  font-size: 1.2rem;
  line-height: 1;
}

.detail-drawer-body {
  overflow-y: auto;
  padding: 1.2rem;
  display: grid;
  gap: 1.15rem;
}

.detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: center;
}

.detail-actions a,
.detail-export-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.2rem;
  padding: 0.35rem 0.85rem;
  border-radius: 999px;
  border: 1px solid #cbd5e1;
  background: #fff;
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}

.detail-export-button {
  cursor: pointer;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.85rem;
}

.detail-grid div {
  padding: 0.75rem 0.85rem;
  border: 1px solid #e2e8f0;
  border-radius: 0.65rem;
  background: #f8fbff;
}

.detail-grid span {
  display: block;
  margin-bottom: 0.3rem;
  font-size: 0.75rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #64748b;
}

.detail-grid strong {
  color: #0f172a;
}

.detail-notes,
.detail-events {
  display: grid;
  gap: 0.55rem;
}

.detail-notes h3,
.detail-events h3 {
  margin: 0;
  font-size: 1rem;
}

.detail-notes p {
  margin: 0;
  padding: 0.9rem;
  border-radius: 0.65rem;
  background: #f8fafc;
  color: #334155;
}

.timeline-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.75rem;
}

.timeline-item {
  padding: 0.85rem 0.95rem;
  border: 1px solid #e2e8f0;
  border-radius: 0.7rem;
  background: #fff;
}

.timeline-top {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  align-items: baseline;
}

.timeline-top span {
  color: #64748b;
  font-size: 0.82rem;
}

.timeline-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.55rem;
}

.timeline-pill {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  background: #eef2ff;
  color: #334155;
  font-size: 0.76rem;
}

.collections-table-container {
  overflow-x: auto;
}

.collections-table {
  width: 100%;
  border-collapse: collapse;
}

.collections-table th,
.collections-table td {
  padding: 0.75rem;
  vertical-align: top;
}

.collections-table th {
  text-align: left;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.collection-title {
  margin: 0;
  font-size: 1rem;
}

.collection-handle {
  font-size: 0.8rem;
  color: var(--muted);
  text-transform: lowercase;
  word-break: break-all;
}

.count-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #e5f1ff;
  color: #034a8f;
  border-radius: 999px;
  padding: 0.25rem 0.75rem;
  font-weight: 600;
  font-size: 0.85rem;
}

.export-memory {
  display: grid;
  gap: 0.3rem;
}

.export-count-badge {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  border-radius: 999px;
  padding: 0.15rem 0.55rem;
  background: #edf2f7;
  color: #334155;
  font-size: 0.78rem;
  font-weight: 700;
}

.collections-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  margin-top: 1rem;
}

.collections-actions .group {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.collections-actions button {
  border-radius: 999px;
  padding: 0.35rem 1rem;
}

.collections-actions .group button:not(.primary) {
  background: #fff;
}

.collections-actions button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.collections-pagination {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin-top: 1.25rem;
}

.collections-pagination a,
.collections-pagination span {
  padding: 0.25rem 0.6rem;
  border-radius: 0.35rem;
  text-decoration: none;
  color: inherit;
}

.collections-pagination .active {
  background: var(--accent);
  color: #fff;
}

.collections-pagination span.ellipsis {
  pointer-events: none;
}

.collection-row.is-active {
  background: rgba(13, 138, 61, 0.05);
}

.collection-row.is-recent {
  background: rgba(2, 132, 199, 0.05);
}

.collection-row.is-new {
  background: rgba(234, 179, 8, 0.08);
}

.collection-row.is-stale {
  opacity: 0.92;
}

.status-badge,
.date-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  padding: 0.2rem 0.65rem;
  font-size: 0.8rem;
  white-space: nowrap;
}

.status-badge.is-active {
  background: rgba(13, 138, 61, 0.12);
  color: #0a6e31;
  font-weight: 700;
}

.memory-badge.memory-posted {
  background: rgba(16, 185, 129, 0.12);
  color: #047857;
  font-weight: 700;
}

.memory-badge.memory-not-posted {
  background: rgba(244, 63, 94, 0.12);
  color: #b91c1c;
  font-weight: 700;
}

.memory-badge.memory-unknown {
  background: rgba(100, 116, 139, 0.12);
  color: #475569;
  font-weight: 700;
}

.note-input-group {
  display: grid;
  gap: 0.35rem;
}

.note-input {
  width: 100%;
  min-width: 140px;
  padding: 0.35rem 0.55rem;
  border: 1px solid #d1d5db;
  border-radius: 0.35rem;
}

.note-save,
.action-button {
  border-radius: 999px;
  padding: 0.35rem 0.85rem;
  border: 1px solid #cbd5e1;
  background: #fff;
  color: #0f172a;
  cursor: pointer;
}

.note-save:hover,
.action-button:hover {
  background: #f8fafc;
}

.row-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
}

.row-actions a {
  font-size: 0.9rem;
  color: var(--accent);
}

.row-action-link {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.1rem;
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 0.15rem;
}

.details-button {
  color: var(--accent);
}

.needs-action-badge.needs-export {
  background: rgba(251, 191, 36, 0.2);
  color: #92400e;
  font-weight: 700;
}

.needs-action-badge.needs-posting {
  background: rgba(249, 115, 22, 0.18);
  color: #9a3412;
  font-weight: 700;
}

.needs-action-badge.needs-handled {
  background: rgba(16, 185, 129, 0.14);
  color: #047857;
  font-weight: 700;
}

.needs-action-badge.needs-stale {
  background: rgba(148, 163, 184, 0.18);
  color: #475569;
  font-weight: 700;
}

.needs-action-badge.needs-watch {
  background: rgba(59, 130, 246, 0.12);
  color: #1d4ed8;
  font-weight: 700;
}

.tag-editor {
  display: grid;
  gap: 0.35rem;
}

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.tag-chip {
  display: inline-flex;
  align-items: center;
  padding: 0.18rem 0.55rem;
  border-radius: 999px;
  background: #eef2ff;
  color: #334155;
  font-size: 0.76rem;
  font-weight: 700;
}

.tag-input {
  width: 100%;
  min-width: 140px;
  padding: 0.35rem 0.55rem;
  border: 1px solid #d1d5db;
  border-radius: 0.35rem;
}

.status-badge.is-recent {
  background: rgba(2, 132, 199, 0.12);
  color: #075985;
  font-weight: 700;
}

.status-badge.is-new {
  background: rgba(234, 179, 8, 0.18);
  color: #854d0e;
  font-weight: 700;
}

.status-badge.is-stale,
.status-badge.is-unknown {
  background: rgba(100, 116, 139, 0.12);
  color: #475569;
  font-weight: 700;
}

.date-chip {
  background: #f3f6fb;
  color: #334155;
}

@media (max-width: 720px) {
  .toolbar-actions,
  .collections-meta,
  .collections-actions {
    align-items: stretch;
  }

  .toolbar-actions button,
  .collections-actions .group,
  .collections-actions .group button {
    width: 100%;
  }

  .detail-grid {
    grid-template-columns: 1fr;
  }
}
