:root {
  --bg: #0f1216;
  --panel: #171b21;
  --panel-2: #1e232b;
  --border: #2a303a;
  --text: #e6e9ee;
  --muted: #9aa4b2;
  --accent: #5b9dff;
  --accent-staged: #c98bff;
  --danger: #ff6b6b;
  --ok: #4fd07a;
  font-size: 16px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.5;
}

a { color: var(--accent); }

.topbar {
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0.75rem 1rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem;
}

.brand { font-weight: 700; }

.topbar nav { display: flex; gap: 0.75rem; flex: 1; flex-wrap: wrap; }
.topbar nav a {
  text-decoration: none;
  color: var(--muted);
  padding: 0.35rem 0.7rem;
  border-radius: 6px;
}
.topbar nav a.active, .topbar nav a:hover { color: var(--text); background: var(--panel-2); }

.topbar-right { display: flex; align-items: center; gap: 0.6rem; }
.who { color: var(--muted); font-size: 0.9rem; }

.link-btn {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  text-decoration: underline;
  font-size: 0.9rem;
  padding: 0;
}

.content {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1rem;
}

.login-wrap {
  min-height: 90vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.login-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 2rem;
  width: 100%;
  max-width: 380px;
}

.login-card h1 { font-size: 1.25rem; margin: 0 0 0.25rem; }
.sub { color: var(--muted); font-size: 0.9rem; }

.login-form { display: flex; flex-direction: column; gap: 0.4rem; margin-top: 1rem; }
.login-form label { font-size: 0.85rem; color: var(--muted); margin-top: 0.5rem; }
.login-form input, .inline-form input, textarea {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 0.55rem 0.7rem;
  font-size: 1rem;
  width: 100%;
  font-family: inherit;
}

button, .btn-primary, .btn-danger {
  cursor: pointer;
  border: none;
  border-radius: 8px;
  padding: 0.55rem 1rem;
  font-size: 0.95rem;
  font-weight: 600;
}

.login-form button, .btn-primary { background: var(--accent); color: #06111f; margin-top: 0.75rem; }
.btn-danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }

.flash { padding: 0.6rem 0.9rem; border-radius: 8px; margin-bottom: 1rem; font-size: 0.9rem; }
.flash.error { background: #3a1414; color: #ff9b9b; border: 1px solid #5a1f1f; }
.flash.info { background: #142236; color: #a9c9ff; border: 1px solid #23406b; }

.tab-header { margin-bottom: 1.25rem; }
.tab-header h1 { margin-bottom: 0.15rem; }

.staged-banner {
  background: linear-gradient(90deg, #2a1440, #3a1c58);
  border: 1px solid var(--accent-staged);
  color: #e9d6ff;
  padding: 0.6rem 1rem;
  border-radius: 8px;
  font-weight: 700;
  text-align: center;
  margin-bottom: 1rem;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem;
}

.create-card { margin-bottom: 1.25rem; }
.inline-form { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.5rem; }
.inline-form input { flex: 1 1 200px; }
.inline-form button { background: var(--ok); color: #06210f; flex: 0 0 auto; }

.empty-state {
  color: var(--muted);
  border: 1px dashed var(--border);
  border-radius: 10px;
  padding: 2rem;
  text-align: center;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
}

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

.key-badge {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.2rem 0.65rem;
  font-size: 0.8rem;
  font-weight: 700;
}

.token-badge { color: var(--muted); font-size: 0.8rem; }

.edit-form textarea { resize: vertical; }
.row-actions { display: flex; gap: 0.5rem; margin-top: 0.5rem; }

.meta { color: var(--muted); font-size: 0.75rem; margin-top: 0.5rem; }

.provenance {
  margin-top: 0.75rem;
  border-top: 1px solid var(--border);
  padding-top: 0.6rem;
  font-size: 0.85rem;
}

.prov-row { margin-bottom: 0.2rem; word-break: break-word; }
.prov-row.unknown { color: var(--muted); font-style: italic; }
.prov-row.no-salience { color: var(--muted); font-size: 0.78rem; margin-top: 0.4rem; font-style: italic; }

.history summary { cursor: pointer; color: var(--accent); margin-top: 0.3rem; }
.history ul { margin: 0.4rem 0 0; padding-left: 1.1rem; }
.history li { margin-bottom: 0.3rem; word-break: break-word; }
.history .ts { color: var(--muted); margin-right: 0.4rem; }

/* ── Staged tab (B6) ───────────────────────────────────────────────── */

.corpus-stub { border-style: dashed; color: var(--muted); }

.outcome-summary { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
.pill {
  display: inline-block;
  border-radius: 999px;
  padding: 0.25rem 0.75rem;
  font-size: 0.8rem;
  font-weight: 700;
  border: 1px solid var(--border);
}
.pill-commit { color: var(--ok); border-color: var(--ok); }
.pill-review { color: var(--accent-staged); border-color: var(--accent-staged); }
.pill-drop { color: var(--danger); border-color: var(--danger); }

.shadow-card { border-left: 3px solid var(--accent-staged); }
.outcome-badge {
  font-size: 0.72rem;
  font-weight: 700;
  border-radius: 6px;
  padding: 0.15rem 0.5rem;
  white-space: nowrap;
}
.outcome-badge.outcome-auto_commit { color: var(--ok); background: rgba(79, 208, 122, 0.12); }
.outcome-badge.outcome-review_queue { color: var(--accent-staged); background: rgba(201, 139, 255, 0.12); }
.outcome-badge.outcome-drop { color: var(--danger); background: rgba(255, 107, 107, 0.12); }

.shadow-value { margin: 0.5rem 0; word-break: break-word; }

.commit-trace {
  margin-top: 0.6rem;
  border-top: 1px solid var(--border);
  padding-top: 0.5rem;
  font-size: 0.82rem;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}
.commit-trace > div { word-break: break-word; }

.btn-stub {
  background: var(--panel-2);
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.3rem 0.6rem;
  font-size: 0.8rem;
  margin-right: 0.35rem;
  cursor: not-allowed;
}

/* ── Responsive table (harness_memory_v2) ─────────────────────────────
   Desktop/tablet: a normal scrollable table. Below 700px it collapses
   into stacked label/value rows per doc-74-style "no fixed-width layout"
   guidance so it never forces horizontal scroll on a 390px viewport. ── */

.table-scroll { overflow-x: auto; }
.responsive-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.responsive-table th, .responsive-table td {
  text-align: left;
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.responsive-table th { color: var(--muted); font-weight: 600; white-space: nowrap; }

/* ── B7: 390px responsive pass ─────────────────────────────────────── */

@media (max-width: 700px) {
  .responsive-table thead { display: none; }
  .responsive-table, .responsive-table tbody, .responsive-table tr, .responsive-table td {
    display: block;
    width: 100%;
  }
  .responsive-table tr {
    border: 1px solid var(--border);
    border-radius: 10px;
    margin-bottom: 0.75rem;
    padding: 0.5rem 0.7rem;
  }
  .responsive-table td {
    border-bottom: none;
    padding: 0.3rem 0;
    display: flex;
    gap: 0.5rem;
    word-break: break-word;
  }
  .responsive-table td::before {
    content: attr(data-label);
    color: var(--muted);
    font-weight: 600;
    flex: 0 0 auto;
    min-width: 6.5rem;
  }
}

@media (max-width: 480px) {
  .topbar-inner { padding: 0.6rem 0.75rem; }
  .content { padding: 0.75rem; }
  .card-grid { grid-template-columns: 1fr; }
}

@media (max-width: 400px) {
  :root { font-size: 15px; }
  .topbar-inner { gap: 0.5rem; }
  .topbar nav { gap: 0.4rem; }
  .topbar nav a { padding: 0.3rem 0.5rem; font-size: 0.85rem; }
  .who { display: none; } /* saves width at 390px; username already shown on login */
  .login-card { padding: 1.25rem; }
  .row-actions { flex-direction: column; }
  .row-actions button { width: 100%; }
  .inline-form { flex-direction: column; }
  .inline-form input, .inline-form button { width: 100%; }
  button, .btn-primary, .btn-danger, .btn-stub { min-height: 2.5rem; } /* tap target */
  .outcome-summary { flex-direction: column; align-items: flex-start; }
  .memory-card header, .shadow-card header { flex-direction: column; align-items: flex-start; gap: 0.35rem; }
}

/* Belt-and-suspenders against horizontal scroll on any narrow viewport,
   independent of the breakpoints above. */
html, body { max-width: 100%; overflow-x: hidden; }
img, table, textarea, input { max-width: 100%; }
