/* =============================================================
   JYCX Brain Dashboard — Pass 4a baseline styles
   =============================================================
   Neutral, function-focused palette. Linear/Notion-ish.
   Light/dark via prefers-color-scheme. NOT the JYCX marketing brand.
   ============================================================= */

:root {
  --bg: #ffffff;
  --bg-alt: #f7f7f8;
  --bg-card: #ffffff;
  --border: #e5e5e7;
  --text: #1d1d1f;
  --text-muted: #6e6e73;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --error-bg: #fef2f2;
  --error-text: #b91c1c;
  --success-bg: #f0fdf4;
  --success-text: #15803d;
  --code-bg: #f3f3f3;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1c1e;
    --bg-alt: #2c2c2e;
    --bg-card: #2c2c2e;
    --border: #3a3a3c;
    --text: #f2f2f7;
    --text-muted: #9a9a9e;
    --accent: #5b8cf6;
    --accent-hover: #7ba6ff;
    --error-bg: #3a1d1d;
    --error-text: #fca5a5;
    --success-bg: #14321e;
    --success-text: #86efac;
    --code-bg: #2c2c2e;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.55;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); text-decoration: underline; }

/* ---- Top bar (authenticated layout) ---- */
.topbar {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 0.75rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 600; font-size: 1rem; }
.brand a { color: var(--text); }
.brand a:hover { text-decoration: none; }

.nav { display: flex; gap: 1rem; flex: 1; }
.nav-link {
  color: var(--text-muted);
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  font-size: 0.95rem;
}
.nav-link:hover { color: var(--text); background: var(--bg-alt); text-decoration: none; }
.nav-link.current { color: var(--text); background: var(--bg-alt); font-weight: 500; }

.user { display: flex; align-items: center; gap: 0.75rem; font-size: 0.9rem; }
.user-name { color: var(--text-muted); }
.logout { color: var(--text-muted); }

.main {
  max-width: 760px;
  margin: 0 auto;
  padding: 2rem 1.5rem 4rem;
}

/* ---- Login page ---- */
.login-page { background: var(--bg-alt); min-height: 100vh; display: grid; place-items: center; }
.login-shell {
  width: 100%;
  max-width: 380px;
  padding: 2rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
}
.login-shell h1 { margin: 0 0 0.5rem; font-size: 1.25rem; }
.login-shell .lede { color: var(--text-muted); font-size: 0.9rem; margin: 0 0 1.5rem; }

/* ---- Forms ---- */
.field { display: flex; flex-direction: column; gap: 0.35rem; margin-bottom: 1rem; }
.field label { font-size: 0.85rem; color: var(--text-muted); }
.field input, .field select, .field textarea {
  font: inherit;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent);
}
.field textarea { resize: vertical; min-height: 8rem; }

button.primary, .button.primary {
  font: inherit;
  font-weight: 500;
  padding: 0.55rem 1rem;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s ease;
}
button.primary:hover, .button.primary:hover { background: var(--accent-hover); }
button.primary:disabled { opacity: 0.5; cursor: default; }

button.secondary, .button.secondary {
  font: inherit;
  padding: 0.5rem 0.85rem;
  background: var(--bg-alt);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
}
button.secondary:hover, .button.secondary:hover { background: var(--bg-card); }

/* ---- Page headings ---- */
.page-title { font-size: 1.25rem; font-weight: 600; margin: 0 0 0.25rem; }
.page-sub { color: var(--text-muted); font-size: 0.9rem; margin: 0 0 2rem; }

/* ---- Cards ---- */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.25rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
}
.card h2 { font-size: 1rem; font-weight: 600; margin: 0 0 0.75rem; }

/* ---- Banners ---- */
.banner { padding: 0.75rem 1rem; border-radius: 6px; font-size: 0.9rem; margin-bottom: 1rem; }
.banner.error { background: var(--error-bg); color: var(--error-text); border: 1px solid color-mix(in srgb, var(--error-text) 30%, transparent); }
.banner.success { background: var(--success-bg); color: var(--success-text); border: 1px solid color-mix(in srgb, var(--success-text) 30%, transparent); }

/* ---- Metadata display (capture confirmation) ---- */
.meta-grid { display: grid; grid-template-columns: max-content 1fr; gap: 0.4rem 1rem; font-size: 0.9rem; }
.meta-grid dt { color: var(--text-muted); }
.meta-grid dd { margin: 0; }
.meta-grid code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.85em; padding: 0.1em 0.35em; background: var(--code-bg); border-radius: 3px; }

.access-pill {
  display: inline-block;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 500;
  background: var(--bg-alt);
  border: 1px solid var(--border);
}

/* ---- Form rows (multiple controls in a line) ---- */
.row { display: flex; gap: 0.75rem; align-items: end; flex-wrap: wrap; }
.row > .field { flex: 1; margin-bottom: 0; min-width: 12rem; }

/* ---- Footer hint ---- */
.hint { color: var(--text-muted); font-size: 0.85rem; }

/* =============================================================
   Pass 4b additions: tables, filter forms, timelines, lists
   ============================================================= */

/* ---- Filter form ---- */
.filter-form .filter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
  gap: 0.5rem 0.75rem;
  margin-bottom: 0.75rem;
}
.filter-form .field { margin-bottom: 0; }
.filter-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

/* ---- Chips (tag pills) ---- */
.chip {
  display: inline-block;
  padding: 0.1rem 0.5rem;
  margin-right: 0.25rem;
  border-radius: 999px;
  font-size: 0.75rem;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  color: var(--text-muted);
}

/* ---- Browse list ---- */
.thought-list {
  list-style: none;
  margin: 1rem 0 0;
  padding: 0;
}
.thought-item {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem 1.1rem;
  margin-bottom: 0.6rem;
  box-shadow: var(--shadow);
}
.thought-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem 0.6rem; margin-bottom: 0.4rem; font-size: 0.8rem; }
.thought-id { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-weight: 500; }
.thought-preview { white-space: pre-wrap; line-height: 1.5; font-size: 0.95rem; }
.thought-topics { margin-top: 0.5rem; }

.meta-bit {
  display: inline-block;
  padding: 0.05rem 0.45rem;
  border-radius: 4px;
  background: var(--bg-alt);
  color: var(--text-muted);
  font-size: 0.78rem;
}
.meta-bit.muted { background: transparent; }

/* ---- Contacts table ---- */
.contacts-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
.contacts-table th, .contacts-table td {
  text-align: left;
  padding: 0.45rem 0.6rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.contacts-table th {
  font-weight: 500;
  color: var(--text-muted);
  background: var(--bg-alt);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.contacts-table tr:last-child td { border-bottom: none; }
.contacts-table tr:hover { background: var(--bg-alt); }
.contact-name { font-weight: 500; }

/* ---- Detail page ---- */
.detail-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.75rem; }
.detail-header h2 { margin: 0; font-size: 1.15rem; }

/* ---- Timeline (interactions) ---- */
.timeline {
  list-style: none;
  margin: 0;
  padding: 0;
}
.timeline-item {
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--border);
}
.timeline-item:last-child { border-bottom: none; }
.timeline-meta { display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; margin-bottom: 0.25rem; font-size: 0.82rem; }
.timeline-summary { white-space: pre-wrap; font-size: 0.92rem; }

/* ---- Source records list ---- */
.source-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.source-item {
  padding: 0.45rem 0;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  font-size: 0.88rem;
}
.source-item:last-child { border-bottom: none; }

/* =============================================================
   Pass 5a additions: editorial status pills, distribution badges,
   info banner.
   ============================================================= */

.banner.info {
  background: color-mix(in srgb, var(--accent) 12%, var(--bg));
  color: var(--text);
  border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
}

/* Status pills — small color-coded badges next to titles */
.status-pill {
  display: inline-block;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: var(--bg-alt);
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.status-pill.status-idea          { background: #f3f4f6; color: #4b5563; border-color: #d1d5db; }
.status-pill.status-draft_v1      { background: #fef3c7; color: #92400e; border-color: #fde68a; }
.status-pill.status-draft_v2      { background: #fde68a; color: #78350f; border-color: #fcd34d; }
.status-pill.status-draft_v3      { background: #fcd34d; color: #78350f; border-color: #fbbf24; }
.status-pill.status-final         { background: #ddd6fe; color: #5b21b6; border-color: #c4b5fd; }
.status-pill.status-scheduled     { background: #c7d2fe; color: #3730a3; border-color: #a5b4fc; }
.status-pill.status-published     { background: #bbf7d0; color: #166534; border-color: #86efac; }
.status-pill.status-distributed   { background: #86efac; color: #14532d; border-color: #4ade80; }
.status-pill.status-kill_list     { background: #fecaca; color: #991b1b; border-color: #fca5a5; }

@media (prefers-color-scheme: dark) {
  .status-pill.status-idea        { background: #374151; color: #d1d5db; border-color: #4b5563; }
  .status-pill.status-draft_v1    { background: #78350f; color: #fde68a; border-color: #92400e; }
  .status-pill.status-draft_v2    { background: #92400e; color: #fde68a; border-color: #b45309; }
  .status-pill.status-draft_v3    { background: #b45309; color: #fef3c7; border-color: #d97706; }
  .status-pill.status-final       { background: #4c1d95; color: #ddd6fe; border-color: #5b21b6; }
  .status-pill.status-scheduled   { background: #312e81; color: #c7d2fe; border-color: #3730a3; }
  .status-pill.status-published   { background: #14532d; color: #bbf7d0; border-color: #166534; }
  .status-pill.status-distributed { background: #166534; color: #bbf7d0; border-color: #15803d; }
  .status-pill.status-kill_list   { background: #7f1d1d; color: #fecaca; border-color: #991b1b; }
}

/* Distribution badges row — small pill list under titles */
.dist-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-top: 0.4rem;
}
.dist-bit {
  font-size: 0.72rem;
  padding: 0.05rem 0.45rem;
  border-radius: 4px;
  background: var(--bg-alt);
  color: var(--text-muted);
}
.dist-bit.dist-on {
  background: color-mix(in srgb, var(--accent) 18%, var(--bg));
  color: var(--text);
  border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
}

/* ---- Mobile (Pass 4c responsive pass) ---- */
@media (max-width: 640px) {
  .main { padding: 1.25rem 1rem 3rem; }
  .nav { gap: 0.25rem; flex-wrap: wrap; }
  .nav-link { padding: 0.25rem 0.4rem; font-size: 0.85rem; }
  .topbar { padding: 0.5rem 1rem; gap: 0.75rem; }
  .user-name { display: none; }

  /* Contacts table → card layout under 640px.
     Each row becomes a stacked card with the column header rendered
     as a label via the data-label attribute. The header row hides. */
  .contacts-table thead { display: none; }
  .contacts-table, .contacts-table tbody, .contacts-table tr, .contacts-table td {
    display: block;
    width: 100%;
  }
  .contacts-table tr {
    margin-bottom: 0.75rem;
    padding: 0.85rem 1rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: var(--shadow);
  }
  .contacts-table tr:hover { background: var(--bg-card); }
  .contacts-table td {
    padding: 0.2rem 0;
    border: none;
    font-size: 0.92rem;
    /* Allow long emails / linkedin URLs to wrap rather than overflow. */
    word-break: break-word;
  }
  .contacts-table td[data-label]:before {
    content: attr(data-label);
    display: inline-block;
    min-width: 6rem;
    color: var(--text-muted);
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-right: 0.5rem;
  }
  /* The Name cell gets bigger treatment as a card header. */
  .contacts-table td[data-label="Name"] {
    font-size: 1rem;
    font-weight: 500;
    margin-bottom: 0.4rem;
    padding-bottom: 0.4rem;
    border-bottom: 1px solid var(--border);
  }
  .contacts-table td[data-label="Name"]:before {
    display: none;
  }
  /* Hide cells that are empty on mobile so cards stay tidy. */
  .contacts-table td:empty { display: none; }

  /* Filter form: tighter on mobile */
  .filter-form .filter-grid {
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
  }

  /* Detail page meta-grid stacks. */
  .meta-grid {
    grid-template-columns: 1fr;
    gap: 0.1rem 0;
  }
  .meta-grid dt {
    margin-top: 0.5rem;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
  }

  /* Detail header: stack heading + edit button. */
  .detail-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
  }
}
