/* ================================================================
   MEGRA design system — Direction C (Hybrid), MVP variant
   Source: docs/design/megra/mvp/index.html + mvp/design-system.html
   ARCHETYPE_FILTERING_ENABLED = False

   Layer 1: Design tokens + reset + layout shell
   Layer 2: components.css (buttons, badges, cards, tables, etc.)
   ================================================================ */

:root {
  /* -- Surfaces -- */
  --bg: #f6f5f2;
  --bg-1: #edecea;
  --surface: #ffffff;
  --surface-1: #fafaf8;

  /* -- Borders -- */
  --border: #e5e5e0;
  --border-strong: #d4d4cd;

  /* -- Text -- */
  --text: #1a1a1a;
  --text-1: #48463f;
  --text-2: #525252;
  --text-3: #a8a49b;

  /* -- Brand accents -- */
  --lime: #84cc16;
  --lime-dim: #65a30d;
  --lime-soft: rgba(132, 204, 22, .10);
  --orange: #f97316;
  --orange-soft: rgba(249, 115, 22, .08);
  --violet: #8b5cf6;
  --violet-soft: rgba(139, 92, 246, .08);
  --cyan: #06b6d4;
  --cyan-soft: rgba(6, 182, 212, .08);

  /* -- Status -- */
  --ok: #16a34a;
  --warn: #f59e0b;
  --fail: #dc2626;
  --info: #0ea5e9;
  --idle: #94a3b8;

  /* -- Radius -- */
  --r-sm: 6px;
  --r-md: 12px;
  --r-lg: 24px;

  /* -- Shadows (brief spec) -- */
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html {
  font-family: 'DM Sans', system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
body { min-height: 100vh; }
button { font-family: inherit; cursor: pointer; }
a { color: inherit; text-decoration: none; }
.mono { font-family: 'Space Mono', monospace; font-variant-numeric: tabular-nums; }

/* -- App shell -- */
.app-shell {
  display: flex;
  min-height: 100vh;
}
.app-main {
  margin-left: 220px;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* -- Sidebar -- */
.sidebar {
  width: 220px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
}
.sidebar .logo {
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: baseline;
  gap: 2px;
}
.sidebar .logo-text {
  font-family: 'Syne', sans-serif;
  font-weight: 800;
  font-size: 22px;
  letter-spacing: -0.03em;
  color: var(--text);
}
.sidebar .logo-mark {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--lime);
  margin-left: 1px;
  vertical-align: super;
  animation: pulse 2.5s ease-in-out infinite;
  align-self: flex-start;
  margin-top: 6px;
}
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: .5; transform: scale(.7); }
}

.sidebar nav {
  flex: 1;
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--r-sm);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-1);
  transition: all 100ms ease;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}
.nav-item:hover { background: var(--bg); color: var(--text); }
/* Active state defined in components.css (lime left-bar accent) */
.nav-item i { width: 18px; height: 18px; color: var(--text-2); flex-shrink: 0; }
.nav-item.disabled { color: var(--text-3); cursor: not-allowed; pointer-events: none; }
.nav-item.disabled i { color: var(--text-3); }
.nav-item .nav-count {
  margin-left: auto;
  font-family: 'Space Mono', monospace;
  font-size: 11px;
  color: var(--text-3);
}
.nav-item.active .nav-count { color: var(--lime-dim); }

.badge-soon {
  margin-left: auto;
  font-family: 'Space Mono', monospace;
  font-size: 10px;
  font-weight: 700;
  color: var(--text-3);
  background: var(--bg-1);
  border-radius: 3px;
  padding: 1px 5px;
  letter-spacing: 0.04em;
}

/* -- Topbar -- */
.topbar {
  height: 52px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  position: sticky;
  top: 0;
  z-index: 90;
}
.topbar .eyebrow {
  font-family: 'Space Mono', monospace;
  font-size: 11px;
  color: var(--text-3);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.topbar-right { display: flex; align-items: center; gap: 12px; }

.harvest-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-2);
  font-family: 'Space Mono', monospace;
}
.harvest-status::before {
  content: '';
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--ok);
  animation: pulse 2s ease-in-out infinite;
}
.harvest-status[data-status="warn"]::before { background: var(--warn); }
.harvest-status[data-status="fail"]::before { background: var(--fail); }
.harvest-status[data-status="idle"]::before { background: var(--idle); animation: none; }

.avatar-btn {
  width: 30px;
  height: 30px;
  border-radius: var(--r-sm);
  background: var(--text);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  border: none;
  cursor: pointer;
}
.avatar-btn:hover { background: #333; }

/* -- Main content area -- */
.content {
  flex: 1;
  padding: 28px;
  min-height: calc(100vh - 52px);
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}
.page-header h1,
.page-title {
  font-family: 'Syne', sans-serif;
  font-weight: 700;
  font-size: 22px;
  letter-spacing: -0.01em;
}
.page-subtitle {
  font-size: 13px;
  color: var(--text-2);
  margin-top: 2px;
}

/* -- KPI Grid -- */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 28px;
}
.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 18px 20px;
  position: relative;
  overflow: hidden;
}
.kpi-card::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
}
.kpi-card.kpi-lime::after { background: var(--lime); }
.kpi-card.kpi-orange::after { background: var(--orange); }
.kpi-card.kpi-violet::after { background: var(--violet); }
.kpi-card.kpi-cyan::after { background: var(--cyan); }
.kpi-card.kpi-ok::after { background: var(--ok); }
.kpi-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 12px;
}
.kpi-icon.lime { background: var(--lime-soft); color: var(--lime-dim); }
.kpi-icon.orange { background: var(--orange-soft); color: var(--orange); }
.kpi-icon.violet { background: var(--violet-soft); color: var(--violet); }
.kpi-icon.cyan { background: var(--cyan-soft); color: var(--cyan); }
.kpi-icon.ok { background: rgba(22, 163, 74, .08); color: var(--ok); }
.kpi-label { font-size: 12px; color: var(--text-2); margin-bottom: 2px; }
.kpi-value { font-size: 28px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.1; }
.kpi-delta { font-family: 'Space Mono', monospace; font-size: 11px; margin-top: 4px; }
.kpi-delta.up { color: var(--ok); }
.kpi-delta.down { color: var(--fail); }

/* -- Content grid -- */
.content-grid {
  display: grid;
  grid-template-columns: 1fr 380px;
  gap: 20px;
}

/* -- Card -- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-sm);
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px 12px;
  border-bottom: 1px solid var(--border);
}
.card-title { font-weight: 600; font-size: 14px; }
.card-action {
  font-size: 12px;
  color: var(--text-2);
  display: flex;
  align-items: center;
  gap: 4px;
}
.card-action:hover { color: var(--text); }
.card-body { padding: 16px 20px; }

/* -- Table -- */
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th {
  text-align: left;
  padding: 10px 14px;
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-2);
  font-family: 'Space Mono', monospace;
  border-bottom: 2px solid var(--border);
  background: var(--surface-1);
}
.table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.table tr:last-child td { border-bottom: none; }
.table tbody tr { transition: background 80ms ease; }
.table tbody tr:hover td { background: var(--surface-1); }

/* Helper for cells that need flex layout (rule: never display:flex on td directly) */
.cell-2line { display: flex; flex-direction: column; gap: 2px; }
.cell-row { display: flex; align-items: center; gap: 8px; }

/* -- Badge -- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
}
.badge-ok   { background: #ecfdf5; color: #059669; }
.badge-warn { background: #fffbeb; color: #d97706; }
.badge-fail { background: #fef2f2; color: #dc2626; }
.badge-idle { background: #f5f5f4; color: #78716c; }
.badge-draft { background: var(--violet-soft); color: var(--violet); }
.badge-dispatched { background: var(--cyan-soft); color: var(--cyan); }
.badge-consumed { background: var(--lime-soft); color: var(--lime-dim); }

/* -- Buttons -- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 18px;
  border-radius: var(--r-sm);
  font-family: 'DM Sans', sans-serif;
  font-size: 13px;
  font-weight: 600;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 100ms ease;
}
.btn-primary { background: var(--text); color: #fff; }
.btn-primary:hover { background: #333; }
.btn-lime { background: var(--lime); color: #fff; border-color: var(--lime); }
.btn-lime:hover { background: var(--lime-dim); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--surface-1); }
.btn-ghost { background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: rgba(0, 0, 0, .04); }
.btn-danger { background: var(--surface); color: var(--fail); border-color: rgba(220, 38, 38, .25); }
.btn-danger:hover { background: #fef2f2; border-color: rgba(220, 38, 38, .4); }

/* -- Inputs -- */
.input {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  font-family: 'DM Sans', sans-serif;
  font-size: 13px;
  color: var(--text);
  background: var(--surface);
  outline: none;
  width: 240px;
  transition: border-color 120ms, box-shadow 120ms;
}
.input:focus { border-color: var(--lime); box-shadow: 0 0 0 3px var(--lime-soft); }
.input::placeholder { color: var(--text-3); }
.select {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  font-family: 'DM Sans', sans-serif;
  font-size: 13px;
  color: var(--text);
  background: var(--surface);
  outline: none;
  width: 200px;
  appearance: none;
  cursor: pointer;
  transition: border-color 120ms, box-shadow 120ms;
}
.select:focus { border-color: var(--lime); box-shadow: 0 0 0 3px var(--lime-soft); }

/* -- Harvest run status (dashboard widget) -- */
.run-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid #f0efec;
}
.run-item:last-child { border-bottom: none; }
.run-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.run-dot.ok { background: var(--ok); }
.run-dot.warn { background: var(--warn); }
.run-dot.fail { background: var(--fail); }
.run-dot.running { background: var(--lime); animation: pulse 1.5s ease-in-out infinite; }
.run-meta { flex: 1; min-width: 0; }
.run-name { font-weight: 500; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.run-detail { font-family: 'Space Mono', monospace; font-size: 11px; color: var(--text-3); }

/* -- Carousel previews (MVP: uniform lime tint, no per-archetype color) -- */
.carousel-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}
.carousel-thumb {
  aspect-ratio: 1;
  border-radius: var(--r-sm);
  overflow: hidden;
  position: relative;
  cursor: pointer;
}
.carousel-thumb-inner {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 2px;
}
.carousel-thumb-inner > div { min-height: 0; }
.carousel-thumb-overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 6px 8px;
  background: linear-gradient(transparent, rgba(0, 0, 0, .6));
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.carousel-thumb-overlay span {
  font-size: 10px;
  color: #fff;
  font-family: 'Space Mono', monospace;
}

/* MVP: single neutral meme placeholder color (no per-archetype tints) */
.meme-neutral { background: #d4d4cd; }

/* -- Toasts -- */
.toast {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 16px;
  border-radius: var(--r-sm);
  font-size: 13px;
  margin-bottom: 8px;
}
.toast-ok   { background: #ecfdf5; border-left: 3px solid var(--ok); color: #065f46; }
.toast-warn { background: #fffbeb; border-left: 3px solid var(--warn); color: #78350f; }
.toast-fail { background: #fef2f2; border-left: 3px solid var(--fail); color: #7f1d1d; }
.toast-info { background: #f0f9ff; border-left: 3px solid #0284c7; color: #0c4a6e; }

/* -- Empty state (base — enhanced in components.css) -- */
.empty-state { text-align: center; padding: 64px 24px; }
.empty-state .empty-icon {
  width: 56px;
  height: 56px;
  border-radius: 14px;
  background: var(--lime-soft);
  color: var(--lime-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 20px;
}
.empty-state h4 {
  font-family: 'Syne', sans-serif;
  font-weight: 700;
  font-size: 17px;
  margin-bottom: 6px;
  letter-spacing: -0.01em;
}
.empty-state p {
  font-size: 13px;
  color: var(--text-2);
  max-width: 340px;
  margin: 0 auto 20px;
  line-height: 1.6;
}

/* -- Loading + skeleton -- */
.loading-bar {
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
  position: relative;
}
.loading-bar::after {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  height: 100%;
  width: 40%;
  background: var(--lime);
  border-radius: 2px;
  animation: load-slide 1.5s ease-in-out infinite;
}
@keyframes load-slide {
  0%   { left: -40%; }
  100% { left: 100%; }
}
.skeleton {
  background: linear-gradient(90deg, #e8e7e3 25%, #f0efec 50%, #e8e7e3 75%);
  background-size: 200% 100%;
  border-radius: var(--r-md);
  animation: shimmer 1.5s ease-in-out infinite;
}
@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* -- Pagination -- */
.pagination { display: flex; align-items: center; gap: 2px; }
.page-btn {
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--r-sm);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-2);
  border: none;
  background: transparent;
  cursor: pointer;
}
.page-btn:hover { background: var(--bg-1); color: var(--text); }
.page-btn.active { background: var(--text); color: #fff; }
.page-btn:focus-visible { outline: 2px solid var(--lime); outline-offset: 2px; }

/* -- Footer -- */
.main-footer {
  margin-top: 32px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-3);
  font-family: 'Space Mono', monospace;
}
