:root {
  color-scheme: light dark;
  font-family:
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    'Segoe UI',
    sans-serif;
  line-height: 1.4;
  padding: 0;
  margin: 0;
}

body {
  margin: 0;
  padding: 1.5rem;
  background: #f5f5f5;
  color: #222;
}

@media (prefers-color-scheme: dark) {
  body {
    background: #111;
    color: #f5f5f5;
  }
}

header {
  max-width: 1200px;
  margin: 0 auto 2rem auto;
}

main {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

section {
  background: rgba(255, 255, 255, 0.9);
  border-radius: 12px;
  padding: 1.5rem;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.08);
}

@media (prefers-color-scheme: dark) {
  section {
    background: rgba(25, 25, 25, 0.9);
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
  }
}

h1,
h2 {
  margin: 0 0 0.5rem 0;
}

.section-hint {
  margin-top: 0;
  color: #555;
  margin-bottom: 1rem;
}

@media (prefers-color-scheme: dark) {
  .section-hint {
    color: #aaa;
  }
}

button,
select {
  padding: 0.5rem 1rem;
  border-radius: 6px;
  border: 1px solid #333;
  background: #fff;
  cursor: pointer;
  font-size: 0.95rem;
}

button:hover {
  background: #ececec;
}

@media (prefers-color-scheme: dark) {
  button,
  select {
    background: #1f1f1f;
    border-color: #666;
    color: inherit;
  }

  button:hover {
    background: #2a2a2a;
  }
}

.overview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}

.overview-item {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding: 1rem;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.05);
}

@media (prefers-color-scheme: dark) {
  .overview-item {
    background: rgba(255, 255, 255, 0.05);
  }
}

.overview-item .label {
  font-size: 0.9rem;
  color: #666;
}

.overview-item .value {
  font-size: 1.3rem;
  font-weight: 600;
}

/* Controls and filters */
.controls {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.category-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.tab-btn {
  padding: 0.5rem 1rem;
  border-radius: 20px;
  border: 1px solid #0891b2;
  background: transparent;
  color: #0891b2;
  font-weight: 500;
  transition: all 0.2s ease;
}

.tab-btn:hover {
  background: rgba(8, 145, 178, 0.1);
}

.tab-btn.active {
  background: #0891b2;
  color: #fff;
  border-color: #0891b2;
}

@media (prefers-color-scheme: dark) {
  .tab-btn {
    border-color: #22d3ee;
    color: #22d3ee;
  }

  .tab-btn:hover {
    background: rgba(34, 211, 238, 0.15);
  }

  .tab-btn.active {
    background: #0891b2;
    color: #fff;
    border-color: #0891b2;
  }
}

.search-row {
  display: flex;
  align-items: flex-end;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.search-row label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.9rem;
  flex: 1;
  min-width: 200px;
}

input[type='text'] {
  padding: 0.5rem;
  border-radius: 6px;
  border: 1px solid rgba(0, 0, 0, 0.2);
  background: rgba(255, 255, 255, 0.95);
  font-family: inherit;
  font-size: 0.95rem;
}

@media (prefers-color-scheme: dark) {
  input[type='text'] {
    background: #1f1f1f;
    border-color: #444;
    color: inherit;
  }
}

/* Entries list */
.entries-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.memory-item {
  border: 1px solid rgba(0, 0, 0, 0.1);
  border-radius: 8px;
  padding: 1rem;
  background: rgba(255, 255, 255, 0.95);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.memory-item.archived {
  opacity: 0.8;
  border-style: dashed;
}

/* Recently updated indicator */
.memory-item.recently-updated {
  border-left: 4px solid #0891b2;
  background: linear-gradient(to right, rgba(8, 145, 178, 0.05), transparent);
}

@media (prefers-color-scheme: dark) {
  .memory-item {
    background: rgba(20, 20, 20, 0.9);
    border-color: #333;
  }

  .memory-item.recently-updated {
    border-left-color: #22d3ee;
    background: linear-gradient(to right, rgba(34, 211, 238, 0.1), transparent);
  }
}

.recent-badge {
  display: inline-block;
  padding: 0.2rem 0.5rem;
  border-radius: 12px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  background: #0891b2;
  color: #fff;
  animation: pulse-badge 2s infinite;
}

@keyframes pulse-badge {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.7;
  }
}

@media (prefers-color-scheme: dark) {
  .recent-badge {
    background: #22d3ee;
    color: #111;
  }
}

.memory-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.memory-header h3 {
  margin: 0;
  font-size: 1.1rem;
  flex: 1;
  min-width: 150px;
  word-break: break-word;
}

/* Category badges - Blue/Cyan color scheme */
.category-badge {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
}

.category-preferences {
  background: #e0f2fe;
  color: #0369a1;
}

.category-connections {
  background: #cffafe;
  color: #0e7490;
}

.category-patterns {
  background: #d1fae5;
  color: #047857;
}

.category-shortcuts {
  background: #fef3c7;
  color: #b45309;
}

.category-state {
  background: #e0e7ff;
  color: #4338ca;
}

@media (prefers-color-scheme: dark) {
  .category-preferences {
    background: #0c4a6e;
    color: #bae6fd;
  }

  .category-connections {
    background: #155e75;
    color: #a5f3fc;
  }

  .category-patterns {
    background: #065f46;
    color: #a7f3d0;
  }

  .category-shortcuts {
    background: #78350f;
    color: #fde68a;
  }

  .category-state {
    background: #3730a3;
    color: #c7d2fe;
  }
}

.hits-badge {
  font-size: 0.8rem;
  color: #666;
  background: rgba(0, 0, 0, 0.05);
  padding: 0.25rem 0.6rem;
  border-radius: 12px;
  font-weight: 600;
  cursor: help;
  transition: all 0.2s ease;
}

.hits-badge:hover {
  background: rgba(0, 0, 0, 0.1);
  transform: scale(1.05);
}

@media (prefers-color-scheme: dark) {
  .hits-badge {
    color: #aaa;
    background: rgba(255, 255, 255, 0.1);
  }

  .hits-badge:hover {
    background: rgba(255, 255, 255, 0.15);
  }
}

.reason-badge {
  display: inline-block;
  padding: 0.2rem 0.5rem;
  border-radius: 8px;
  font-size: 0.75rem;
  font-weight: 500;
}

.reason-expiry {
  background: #fee2e2;
  color: #b91c1c;
}

.reason-state_clear {
  background: #fef9c3;
  color: #a16207;
}

.reason-limit_exceeded {
  background: #ffedd5;
  color: #c2410c;
}

.reason-state_update {
  background: #e0e7ff;
  color: #4338ca;
}

@media (prefers-color-scheme: dark) {
  .reason-expiry {
    background: #7f1d1d;
    color: #fecaca;
  }

  .reason-state_clear {
    background: #713f12;
    color: #fef08a;
  }

  .reason-limit_exceeded {
    background: #7c2d12;
    color: #fed7aa;
  }

  .reason-state_update {
    background: #3730a3;
    color: #c7d2fe;
  }
}

.memory-value-preview {
  color: #444;
  font-family: 'Courier New', monospace;
  font-size: 0.9rem;
  background: rgba(0, 0, 0, 0.03);
  padding: 0.5rem;
  border-radius: 6px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (prefers-color-scheme: dark) {
  .memory-value-preview {
    color: #ccc;
    background: rgba(255, 255, 255, 0.05);
  }
}

.memory-meta {
  display: flex;
  gap: 1.5rem;
  flex-wrap: wrap;
  font-size: 0.85rem;
  color: #666;
}

@media (prefers-color-scheme: dark) {
  .memory-meta {
    color: #aaa;
  }
}

.meta-item {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.meta-label {
  font-size: 0.75rem;
  color: #999;
  text-transform: uppercase;
  font-weight: 600;
  letter-spacing: 0.5px;
}

@media (prefers-color-scheme: dark) {
  .meta-label {
    color: #777;
  }
}

.meta-value {
  font-size: 0.9rem;
  font-weight: 500;
  color: #333;
}

@media (prefers-color-scheme: dark) {
  .meta-value {
    color: #ccc;
  }
}

.meta-updated .meta-value {
  color: #0891b2;
  font-weight: 600;
}

@media (prefers-color-scheme: dark) {
  .meta-updated .meta-value {
    color: #22d3ee;
  }
}

.expand-btn {
  align-self: flex-start;
  padding: 0.3rem 0.6rem;
  font-size: 0.85rem;
}

.memory-full-value {
  background: rgba(0, 0, 0, 0.03);
  border-radius: 6px;
  overflow: auto;
  max-height: 400px;
}

.memory-full-value pre {
  margin: 0;
  padding: 1rem;
  font-family: 'Courier New', monospace;
  font-size: 0.85rem;
  white-space: pre-wrap;
  word-break: break-word;
}

@media (prefers-color-scheme: dark) {
  .memory-full-value {
    background: rgba(255, 255, 255, 0.05);
  }
}

/* Toggle button */
.toggle-btn {
  background: transparent;
  border: 1px dashed #666;
  color: #666;
  font-size: 0.95rem;
}

.toggle-btn:hover {
  background: rgba(0, 0, 0, 0.05);
}

@media (prefers-color-scheme: dark) {
  .toggle-btn {
    border-color: #888;
    color: #aaa;
  }

  .toggle-btn:hover {
    background: rgba(255, 255, 255, 0.05);
  }
}

/* Export section */
#export-section {
  text-align: center;
}

#export-btn {
  background: #0891b2;
  color: #fff;
  border-color: #0891b2;
  font-weight: 500;
}

#export-btn:hover {
  background: #0e7490;
}

@media (prefers-color-scheme: dark) {
  #export-btn {
    background: #0891b2;
    border-color: #0891b2;
  }

  #export-btn:hover {
    background: #0e7490;
  }
}

/* Messages */
#messages {
  max-width: 1200px;
  margin: 1rem auto;
  min-height: 1.2rem;
  font-weight: 500;
}

#messages.success {
  color: #1a7f37;
}

#messages.error {
  color: #d93025;
}

@media (prefers-color-scheme: dark) {
  #messages.success {
    color: #62ff8e;
  }

  #messages.error {
    color: #ff6b6b;
  }
}

/* Loading state */
.loading {
  text-align: center;
  padding: 2rem;
  color: #666;
}

@media (prefers-color-scheme: dark) {
  .loading {
    color: #aaa;
  }
}

/* Breadcrumb navigation */
.breadcrumb {
  max-width: 1200px;
  margin: 0 auto 1rem auto;
  padding: 0.75rem 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
}

.breadcrumb-link {
  color: #0891b2;
  text-decoration: none;
  font-weight: 500;
  transition: color 0.2s;
}

.breadcrumb-link:hover {
  color: #0e7490;
  text-decoration: underline;
}

@media (prefers-color-scheme: dark) {
  .breadcrumb-link {
    color: #22d3ee;
  }

  .breadcrumb-link:hover {
    color: #0891b2;
  }
}

.breadcrumb-separator {
  color: #666;
  user-select: none;
}

@media (prefers-color-scheme: dark) {
  .breadcrumb-separator {
    color: #aaa;
  }
}

.breadcrumb-current {
  color: #666;
  font-weight: 500;
}

@media (prefers-color-scheme: dark) {
  .breadcrumb-current {
    color: #aaa;
  }
}
