:root {
  --bg: #f5f0e8;
  --surface: #ffffff;
  --surface-alt: #fdf8f2;
  --ink: #1c1c1c;
  --muted: #6b6155;
  --accent: #0f6b5f;
  --accent-strong: #0b4f47;
  --accent-warm: #cf7b2c;
  --line: #e6dccd;
  --shadow: 0 24px 48px rgba(15, 10, 5, 0.1);
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Space Grotesk", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top, rgba(207, 123, 44, 0.15), transparent 55%),
    radial-gradient(circle at 20% 80%, rgba(15, 107, 95, 0.18), transparent 55%),
    linear-gradient(135deg, #fbf6ef, #f1e7d8 45%, #f7f1e8 100%);
  min-height: 100vh;
  line-height: 1.6;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background-image: linear-gradient(transparent 85%, rgba(15, 10, 5, 0.03));
  opacity: 0.4;
  pointer-events: none;
}

.ambient {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
}

.orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(0px);
  opacity: 0.8;
  animation: float 14s ease-in-out infinite;
}

.orb-a {
  width: 260px;
  height: 260px;
  top: 6%;
  left: 8%;
  background: radial-gradient(circle, rgba(15, 107, 95, 0.25), transparent 70%);
}

.orb-b {
  width: 320px;
  height: 320px;
  bottom: 12%;
  right: 10%;
  animation-delay: -6s;
  background: radial-gradient(circle, rgba(207, 123, 44, 0.22), transparent 70%);
}

.orb-c {
  width: 180px;
  height: 180px;
  top: 45%;
  right: 30%;
  animation-delay: -10s;
  background: radial-gradient(circle, rgba(43, 76, 126, 0.18), transparent 70%);
}

.page {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: 100vh;
}

.sidebar {
  padding: 32px 28px;
  background: rgba(255, 255, 255, 0.86);
  border-right: 1px solid var(--line);
  backdrop-filter: blur(12px);
  display: flex;
  flex-direction: column;
  gap: 32px;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
}

.logo-mark {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), var(--accent-warm));
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.6);
}

.brand-title {
  font-family: "Fraunces", serif;
  font-size: 1.2rem;
  margin: 0;
}

.brand-subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.nav-link {
  border: none;
  background: transparent;
  text-align: left;
  padding: 10px 12px;
  border-radius: 12px;
  font-size: 0.95rem;
  color: var(--muted);
  cursor: pointer;
  transition: all 0.2s ease;
}

.nav-link:hover,
.nav-link.is-active {
  background: var(--surface);
  color: var(--accent-strong);
  box-shadow: 0 10px 24px rgba(15, 10, 5, 0.08);
}

.sidebar-footer {
  margin-top: auto;
  border-top: 1px solid var(--line);
  padding-top: 16px;
}

.small {
  font-size: 0.85rem;
}

.muted {
  color: var(--muted);
}

.main {
  padding: 36px 48px 60px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 24px;
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 0.7rem;
  margin: 0;
  color: var(--muted);
}

h1 {
  font-family: "Fraunces", serif;
  font-size: 2.4rem;
  margin: 6px 0 0;
}

h2 {
  font-family: "Fraunces", serif;
  font-size: 1.6rem;
  margin: 0 0 6px;
}

h3 {
  font-size: 1.1rem;
  margin: 0 0 12px;
}

.topbar-actions {
  display: flex;
  gap: 12px;
}

.primary-button,
.ghost-button {
  border-radius: 999px;
  border: none;
  padding: 10px 18px;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s ease;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.primary-button {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 12px 20px rgba(15, 107, 95, 0.2);
}

.primary-button:hover {
  background: var(--accent-strong);
}

.ghost-button {
  background: rgba(255, 255, 255, 0.8);
  color: var(--accent-strong);
  border: 1px solid rgba(15, 107, 95, 0.2);
}

.ghost-button:hover {
  border-color: rgba(15, 107, 95, 0.4);
}

.panel {
  animation: fadeUp 0.6s ease both;
}

.panel.hidden {
  display: none;
}

body.is-auth #login-view {
  display: none;
}

body:not(.is-auth) .nav-link,
body:not(.is-auth) .topbar-actions {
  pointer-events: none;
  opacity: 0.4;
}

body:not(.is-auth) .panel:not(#login-view) {
  display: none;
}

#login-view {
  min-height: 60vh;
  display: grid;
  place-items: center;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 24px;
}

.user-pill {
  padding: 10px 14px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
  font-size: 0.85rem;
}

.grid {
  display: grid;
  gap: 20px;
}

.stats-grid {
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  margin-bottom: 24px;
}

.split-grid {
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}

.card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 20px;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.stat-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.stat-value {
  font-size: 1.8rem;
  font-weight: 700;
}

.stat-label {
  font-size: 0.85rem;
  color: var(--muted);
}

.tag-cloud {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.tag {
  padding: 6px 10px;
  background: var(--surface-alt);
  border-radius: 999px;
  font-size: 0.8rem;
  border: 1px solid var(--line);
}

.tier-list {
  display: grid;
  gap: 10px;
}

.tier-item {
  display: flex;
  justify-content: space-between;
  font-size: 0.9rem;
}

.search-form {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 24px;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  margin-bottom: 24px;
}

.field-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.field-group label {
  font-size: 0.85rem;
  color: var(--muted);
}

.field-group input,
.field-group select {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  font-family: inherit;
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-top: 16px;
}

.field-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 16px;
  gap: 12px;
  flex-wrap: wrap;
}

.checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
}

.results {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 24px;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.results-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.results-list {
  display: grid;
  gap: 12px;
}

.result-card {
  padding: 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  background: var(--surface-alt);
}

.result-meta {
  display: flex;
  gap: 8px;
  align-items: center;
  font-size: 0.8rem;
  margin-bottom: 6px;
}

.badge {
  background: rgba(15, 107, 95, 0.12);
  color: var(--accent-strong);
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 0.7rem;
}

.form-stack {
  display: grid;
  gap: 16px;
}

.key-list {
  display: grid;
  gap: 12px;
}

.key-item {
  display: grid;
  gap: 6px;
  padding: 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  background: var(--surface-alt);
}

.key-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.key-prefix {
  font-family: "Space Grotesk", sans-serif;
  font-weight: 600;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(18, 15, 10, 0.6);
  display: grid;
  place-items: center;
  z-index: 10;
}

.modal.hidden {
  display: none;
}

.modal-content {
  background: var(--surface);
  padding: 24px;
  border-radius: var(--radius-lg);
  width: min(420px, 90vw);
  box-shadow: var(--shadow);
}

.key-box {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 12px;
  border-radius: var(--radius-sm);
  background: var(--surface-alt);
  border: 1px dashed var(--line);
  margin: 16px 0;
  word-break: break-all;
}

.key-box code {
  font-size: 0.85rem;
}

.status-list {
  display: grid;
  gap: 10px;
}

.status-item {
  display: flex;
  justify-content: space-between;
  font-size: 0.9rem;
}

.link-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 10px;
}

.link-list a {
  color: var(--accent-strong);
  text-decoration: none;
}

.link-list a:hover {
  text-decoration: underline;
}

.login-card {
  max-width: 460px;
  background: var(--surface);
  padding: 32px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.login-actions {
  display: grid;
  gap: 12px;
  margin-top: 20px;
}

.notice {
  margin-top: 20px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

@keyframes float {
  0%,
  100% {
    transform: translateY(0px);
  }
  50% {
    transform: translateY(-16px);
  }
}

@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 1100px) {
  .page {
    grid-template-columns: 200px 1fr;
  }
}

@media (max-width: 900px) {
  .page {
    grid-template-columns: 1fr;
  }
  .sidebar {
    flex-direction: row;
    align-items: center;
    gap: 16px;
    border-right: none;
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    z-index: 2;
  }
  .nav {
    flex-direction: row;
    flex-wrap: wrap;
  }
  .sidebar-footer {
    display: none;
  }
  .main {
    padding: 24px;
  }
  .topbar {
    flex-direction: column;
    align-items: flex-start;
  }
}

@media (max-width: 600px) {
  .nav-link {
    padding: 8px 10px;
    font-size: 0.85rem;
  }
  .stats-grid {
    grid-template-columns: 1fr 1fr;
  }
  .field-row {
    justify-content: flex-start;
  }
}

/* =============================================================================
   Memory Lifecycle Styles
   ============================================================================= */

.lifecycle-info {
  margin-bottom: 20px;
}

.state-legend {
  display: grid;
  gap: 12px;
}

.state-item {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.9rem;
}

.state-badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.state-hot {
  background: rgba(34, 197, 94, 0.15);
  color: #16a34a;
  border: 1px solid rgba(34, 197, 94, 0.3);
}

.state-cold {
  background: rgba(59, 130, 246, 0.15);
  color: #2563eb;
  border: 1px solid rgba(59, 130, 246, 0.3);
}

.state-archived {
  background: rgba(107, 97, 85, 0.15);
  color: var(--muted);
  border: 1px solid rgba(107, 97, 85, 0.3);
}

.lifecycle-controls {
  margin-bottom: 20px;
}

.filter-form .field-row {
  margin-top: 16px;
}

.selection-info {
  font-size: 0.85rem;
  color: var(--muted);
  padding: 8px 12px;
  background: var(--surface-alt);
  border-radius: 999px;
}

.lifecycle-batch-actions {
  margin-bottom: 20px;
}

.batch-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  gap: 16px;
  flex-wrap: wrap;
}

.batch-buttons {
  display: flex;
  gap: 10px;
}

.batch-buttons .ghost-button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.lifecycle-results {
  margin-bottom: 24px;
}

.memory-list {
  display: grid;
  gap: 12px;
}

.memory-card {
  padding: 16px;
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  background: var(--surface-alt);
  transition: all 0.2s ease;
}

.memory-card:hover {
  border-color: rgba(15, 107, 95, 0.3);
}

.memory-card.is-selected {
  border-color: var(--accent);
  background: rgba(15, 107, 95, 0.05);
}

.memory-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.memory-select {
  flex-shrink: 0;
}

.memory-id {
  font-family: "Space Grotesk", monospace;
  font-size: 0.8rem;
  color: var(--muted);
}

.memory-score {
  font-size: 0.75rem;
  color: var(--muted);
  margin-left: auto;
  padding: 2px 8px;
  background: var(--surface);
  border-radius: 999px;
  border: 1px solid var(--line);
}

.memory-content {
  margin-bottom: 10px;
}

.memory-content p {
  margin: 0;
  font-size: 0.9rem;
  line-height: 1.5;
  color: var(--ink);
}

.memory-footer {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.archived-info {
  font-size: 0.8rem;
  color: var(--muted);
  font-style: italic;
}

.memory-actions {
  display: flex;
  gap: 8px;
  margin-left: auto;
}

.action-btn {
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.action-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.archive-btn:hover {
  border-color: #3b82f6;
  color: #2563eb;
  background: rgba(59, 130, 246, 0.08);
}

.rehydrate-btn:hover {
  border-color: #22c55e;
  color: #16a34a;
  background: rgba(34, 197, 94, 0.08);
}

.purge-btn:hover {
  border-color: #ef4444;
  color: #dc2626;
  background: rgba(239, 68, 68, 0.08);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 20px;
}

@media (max-width: 600px) {
  .batch-bar {
    flex-direction: column;
    align-items: flex-start;
  }

  .batch-buttons {
    width: 100%;
    justify-content: flex-end;
  }

  .memory-footer {
    flex-direction: column;
    align-items: flex-start;
  }

  .memory-actions {
    margin-left: 0;
    margin-top: 8px;
  }
}

/* =============================================================================
   Lifecycle Timeline Styles
   ============================================================================= */

.lifecycle-timeline {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  margin: 8px 0;
  background: var(--surface);
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  font-size: 0.8rem;
  flex-wrap: wrap;
}

.timeline-event {
  color: var(--muted);
}

.timeline-hint {
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 500;
}

.timeline-hint.recovery-ok {
  background: rgba(34, 197, 94, 0.12);
  color: #16a34a;
  border: 1px solid rgba(34, 197, 94, 0.25);
}

.timeline-hint.recovery-expired {
  background: rgba(239, 68, 68, 0.12);
  color: #dc2626;
  border: 1px solid rgba(239, 68, 68, 0.25);
}

.timeline-hint.active-hint {
  background: rgba(59, 130, 246, 0.12);
  color: #2563eb;
  border: 1px solid rgba(59, 130, 246, 0.25);
}

.archived-reason {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  font-style: italic;
  margin: 4px 0 8px 12px;
}

@media (max-width: 600px) {
  .lifecycle-timeline {
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
  }
}

/* =============================================================================
   Preview Results Styles
   ============================================================================= */

.modal-wide {
  width: min(600px, 90vw);
  max-height: 80vh;
  overflow-y: auto;
}

.preview-results {
  margin: 16px 0;
  padding: 16px;
  background: var(--surface-alt);
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  max-height: 300px;
  overflow-y: auto;
}

.preview-summary {
  display: flex;
  gap: 20px;
  margin-bottom: 16px;
}

.preview-stat {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px 16px;
  background: var(--surface);
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
}

.preview-stat strong {
  font-size: 1.4rem;
}

.preview-stat span {
  font-size: 0.8rem;
  color: var(--muted);
}

.preview-note {
  font-size: 0.85rem;
  font-style: italic;
  color: var(--accent-warm);
  padding: 8px 12px;
  background: rgba(207, 123, 44, 0.1);
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
}

.preview-section {
  margin-bottom: 12px;
}

.preview-section h4 {
  font-size: 0.85rem;
  margin: 0 0 8px;
  color: var(--muted);
}

.preview-list {
  margin: 0;
  padding-left: 20px;
  font-size: 0.85rem;
}

.preview-list li {
  margin-bottom: 4px;
}

.modal-note {
  text-align: center;
  margin-top: 16px;
}

.reversibility-hint {
  display: block;
  margin-top: 10px;
  padding: 10px 14px;
  background: rgba(34, 197, 94, 0.1);
  border: 1px solid rgba(34, 197, 94, 0.25);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  color: #16a34a;
}

.error {
  color: #dc2626;
}

/* =============================================================================
   Activity Log Styles
   ============================================================================= */

.activity-stats {
  margin-bottom: 20px;
}

.stats-grid.small {
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 12px;
}

.stat-card.small {
  padding: 14px;
}

.stat-card.small .stat-value {
  font-size: 1.4rem;
}

.stat-card.small .stat-label {
  font-size: 0.75rem;
}

.activity-controls {
  margin-bottom: 20px;
}

.activity-export {
  margin-bottom: 20px;
  background: var(--surface-alt);
}

.activity-export .field-row {
  display: flex;
  align-items: flex-end;
  gap: 16px;
  flex-wrap: wrap;
}

.activity-export .field-group {
  flex: 0 0 auto;
  min-width: 180px;
}

.activity-results {
  margin-bottom: 24px;
}

.activity-list {
  display: grid;
  gap: 12px;
}

.activity-entry {
  padding: 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  background: var(--surface-alt);
}

.activity-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}

.action-badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.action-archived {
  background: rgba(59, 130, 246, 0.15);
  color: #2563eb;
  border: 1px solid rgba(59, 130, 246, 0.3);
}

.action-rehydrated {
  background: rgba(34, 197, 94, 0.15);
  color: #16a34a;
  border: 1px solid rgba(34, 197, 94, 0.3);
}

.action-purged {
  background: rgba(239, 68, 68, 0.15);
  color: #dc2626;
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.action-summarized {
  background: rgba(168, 85, 247, 0.15);
  color: #9333ea;
  border: 1px solid rgba(168, 85, 247, 0.3);
}

.action-default {
  background: rgba(107, 97, 85, 0.15);
  color: var(--muted);
  border: 1px solid rgba(107, 97, 85, 0.3);
}

.memory-ref {
  font-family: "Space Grotesk", monospace;
  font-size: 0.85rem;
  color: var(--accent-strong);
  background: rgba(15, 107, 95, 0.08);
  padding: 2px 8px;
  border-radius: 4px;
}

.tier-transition {
  font-size: 0.8rem;
  color: var(--muted);
  padding: 2px 8px;
  background: var(--surface);
  border-radius: 4px;
  border: 1px solid var(--line);
}

.activity-body {
  margin-bottom: 8px;
}

.activity-reason {
  margin: 0;
  font-size: 0.9rem;
  color: var(--ink);
  font-style: italic;
}

.activity-footer {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}

.load-more {
  margin-top: 16px;
  text-align: center;
}

.load-more .ghost-button.hidden {
  display: none;
}

@media (max-width: 600px) {
  .activity-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .preview-summary {
    flex-direction: column;
    gap: 12px;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}
