/* ---- CSS variable aliases so the dry test fragment renders correctly ---- */
:root {
  --color-text-primary: #15192b;
  --color-text-secondary: #4a5168;
  --color-text-tertiary: #8a92a6;
  --color-background-secondary: #f0f2f5;
  --color-border-tertiary: #e3e6ec;
  --border-radius-md: 8px;
  --border-radius-lg: 12px;
}

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --text: #15192b;
  --text-2: #4a5168;
  --text-3: #8a92a6;
  --border: #e3e6ec;
  --border-strong: #d2d7e0;
  --accent: #2f6bff;
  --accent-weak: #e8efff;
  --green: #1f9d57;
  --green-weak: #e3f6ec;
  --amber: #c98a06;
  --amber-weak: #fbf0d6;
  --red: #d6402c;
  --red-weak: #fbe4e0;
  --violet: #6d4bd6;
  --violet-weak: #ece5fb;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: none;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Inter', var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

#app {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: 100vh;
}

/* ---------- Sidebar ---------- */
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 8px 18px;
}

.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--text);
  color: #fff;
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.5px;
  object-fit: cover;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  flex: none;
}

.brand-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.brand-text strong {
  font-size: 15px;
}

.brand-text span {
  font-size: 12px;
  color: var(--text-3);
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
  flex: 1;
}

.nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-2);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
}

.nav a:hover {
  background: var(--surface-2);
  color: var(--text);
}

.nav a.active {
  background: var(--accent-weak);
  color: var(--accent);
  font-weight: 600;
}

.nav .nav-section {
  font-size: 11px;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--text-3);
  padding: 16px 12px 6px;
  font-weight: 600;
}

.nav a .tag {
  margin-left: auto;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--violet);
  background: var(--violet-weak);
  padding: 2px 6px;
  border-radius: 999px;
}

/* edit controls are hidden by default — only shown when can-edit class is on body */
#edit-toggle,
#edit-banner {
  display: none !important;
}
body.can-edit #edit-toggle {
  display: inline-flex !important;
}
body.can-edit #edit-banner {
  display: flex !important;
}

.sidebar-foot {
  border-top: 1px solid var(--border);
  padding-top: 14px;
  margin-top: 10px;
}

.updated {
  font-size: 11px;
  color: var(--text-3);
  margin: 10px 4px 0;
}

/* ---------- Main ---------- */
.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 28px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 5;
}

.topbar-title {
  font-weight: 600;
  font-size: 15px;
}

.topbar-status {
  margin-left: auto;
  font-size: 13px;
  color: var(--text-2);
  display: flex;
  gap: 8px;
  align-items: center;
}

.icon-btn {
  display: none;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius-sm);
  font-size: 16px;
  padding: 4px 10px;
  cursor: pointer;
}

.view {
  padding: 28px;
  max-width: 1000px;
  width: 100%;
}

/* ---------- Typography ---------- */
h1.page-title {
  font-size: 26px;
  margin: 0 0 6px;
  letter-spacing: -0.01em;
}

.page-lede {
  color: var(--text-2);
  margin: 0 0 22px;
  font-size: 15px;
  max-width: 70ch;
}

h2.section {
  font-size: 18px;
  margin: 30px 0 12px;
  letter-spacing: -0.01em;
}

h3.subsection {
  font-size: 14px;
  margin: 0 0 4px;
}

/* ---- Checklist page ---- */
.cl-progress { display: flex; align-items: center; gap: 12px; margin: 1rem 0 1.5rem; }
.cl-progress-bar { flex: 1; height: 8px; background: var(--border); border-radius: 999px; overflow: hidden; }
.cl-progress-bar span { display: block; height: 100%; background: var(--accent); border-radius: 999px; transition: width .3s; }
.cl-progress-label { font-size: 12px; color: var(--text-3); white-space: nowrap; }
.cl-week { margin-bottom: 1.5rem; }
.cl-week-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.cl-week-meta { font-size: 12px; color: var(--text-3); white-space: nowrap; }
.cl-list { list-style: none; margin: .5rem 0 0; padding: 0; }
.cl-item { display: flex; align-items: flex-start; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--border); }
.cl-item:last-child { border-bottom: none; }
.cl-check {
  flex-shrink: 0; width: 18px; height: 18px; margin-top: 1px;
  border: 1.5px solid var(--border); border-radius: 5px; background: var(--surface);
  cursor: pointer; font-size: 12px; line-height: 1; color: #fff; display: flex;
  align-items: center; justify-content: center; padding: 0;
}
.cl-item.done .cl-check { background: var(--accent); border-color: var(--accent); }
.cl-text { font-size: 14px; line-height: 1.5; flex: 1; }
.cl-item.done .cl-text { color: var(--text-3); text-decoration: line-through; }
.cl-text[contenteditable="true"] { outline: none; border-bottom: 1px dashed var(--accent); }
.cl-remove { margin-left: auto; }
.cl-add { margin-top: 6px; }

/* ---- Org chart ---- */
.org-scroll { overflow-x: auto; padding: 8px 4px 16px; margin-top: .5rem; }
.org-chart { display: inline-block; min-width: 100%; }
.org-chart ul { display: flex; justify-content: center; padding-top: 22px; position: relative; margin: 0; list-style: none; }
.org-chart li { list-style: none; position: relative; padding: 22px 10px 0; text-align: center; }
/* down connector from a parent into the row of children */
.org-chart li::before, .org-chart li::after {
  content: ""; position: absolute; top: 0; right: 50%;
  border-top: 1.5px solid var(--border); width: 50%; height: 22px;
}
.org-chart li::after { right: auto; left: 50%; border-left: 1.5px solid var(--border); }
.org-chart li:only-child::after, .org-chart li:only-child::before { display: none; }
.org-chart li:only-child { padding-top: 22px; }
.org-chart li:first-child::before, .org-chart li:last-child::after { border: 0 none; }
.org-chart li:last-child::before { border-right: 1.5px solid var(--border); border-radius: 0 6px 0 0; }
.org-chart li:first-child::after { border-radius: 6px 0 0 0; }
.org-chart ul ul::before {
  content: ""; position: absolute; top: 0; left: 50%;
  border-left: 1.5px solid var(--border); width: 0; height: 22px;
}
.org-node {
  display: inline-block; background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 8px 12px; min-width: 120px; max-width: 160px;
}
.org-name { font-weight: 600; font-size: 13px; line-height: 1.25; }
.org-sub { font-size: 11px; color: var(--text-3); margin-top: 2px; line-height: 1.25; }
.org-node.you { border-color: var(--accent); background: rgba(55,138,221,0.08); }
.org-node.you .org-name { color: var(--accent); }

/* ---- People page ---- */
.person-rows { display: flex; flex-direction: column; border: 1px solid var(--border); border-radius: 12px; overflow: hidden; margin-top: .5rem; }
.person-row { display: grid; grid-template-columns: 200px 1fr; gap: 16px; padding: 14px 16px; border-bottom: 1px solid var(--border); background: var(--surface); }
.person-row:last-child { border-bottom: none; }
.pr-id { min-width: 0; }
.pr-name { font-weight: 600; font-size: 14px; }
.pr-role { font-size: 12px; color: var(--text-3); margin-top: 3px; }
.pr-notes { font-size: 13px; color: var(--text-2); line-height: 1.55; }
.pr-notes [data-editable] { outline: none; }
body.editing .pr-notes [data-editable] { border-bottom: 1px dashed var(--accent); cursor: text; }
@media (max-width: 640px) {
  .person-row { grid-template-columns: 1fr; gap: 6px; }
}

/* ---- Chats page ---- */
.chat-new-btn { margin-top: 1rem; }
.chat-list { display: flex; flex-direction: column; gap: 8px; margin-top: 1.5rem; }
.chat-list-item { display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: 12px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; text-decoration: none; color: inherit; transition: border-color .15s; }
.chat-list-item:hover { border-color: var(--accent); }
.cli-person { font-weight: 600; font-size: 14px; }
.cli-context { color: var(--text-3); font-size: 13px; }
.cli-date { font-size: 12px; color: var(--text-3); }

/* ---- Chat detail ---- */
.chat-form, .chat-detail { max-width: 640px; }
.form-row { display: flex; flex-direction: column; gap: 6px; margin-bottom: 1rem; }
.form-row label { font-size: 12px; font-weight: 500; color: var(--text-3); text-transform: uppercase; letter-spacing: .04em; }
.form-input { font-family: inherit; font-size: 14px; border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px; width: 100%; background: var(--surface); color: var(--text); outline: none; transition: border-color .15s; }
.form-input:focus { border-color: var(--accent); }
.form-textarea { min-height: 160px; resize: vertical; line-height: 1.6; }
.chat-notes-area { width: 100%; min-height: 180px; margin-top: .5rem; }
.form-actions { display: flex; gap: 8px; margin-top: .5rem; }
.synth-bar { display: flex; align-items: center; gap: 12px; margin: 1.25rem 0; }
.synth-list { margin-top: .5rem; }
.synth-item { display: inline; outline: none; }
.synth-item[contenteditable="true"] { border-bottom: 1px dashed var(--accent); cursor: text; }
.synth-empty { font-style: italic; }

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

.muted {
  color: var(--text-3);
  font-size: 13px;
}

p {
  margin: 0 0 10px;
}

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

/* ---------- Cards / grid ---------- */
.grid {
  display: grid;
  gap: 14px;
}
.grid.cols-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
.grid.cols-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}
.grid.cols-4 {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.card h4 {
  margin: 0 0 6px;
  font-size: 11px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--text-3);
  font-weight: 600;
}

.card p {
  margin: 0;
  font-size: 14px;
  color: var(--text-2);
}

/* ---------- Stat ---------- */
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.stat .v {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.stat .l {
  font-size: 12px;
  color: var(--text-3);
  margin-top: 2px;
}
.stat.accent .v {
  color: var(--accent);
}
.stat.green .v {
  color: var(--green);
}
.stat.amber .v {
  color: var(--amber);
}

/* ---------- Callout ---------- */
.callout {
  border: 1px solid var(--border);
  border-left-width: 3px;
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin: 12px 0;
  background: var(--surface);
  font-size: 14px;
}
.callout .ctitle {
  font-weight: 600;
  margin-bottom: 4px;
}
.callout.info {
  border-left-color: var(--accent);
  background: var(--accent-weak);
}
.callout.success {
  border-left-color: var(--green);
  background: var(--green-weak);
}
.callout.warning {
  border-left-color: var(--amber);
  background: var(--amber-weak);
}
.callout.danger {
  border-left-color: var(--red);
  background: var(--red-weak);
}
.callout.neutral {
  border-left-color: var(--border-strong);
  background: var(--surface-2);
}

/* ---------- List ---------- */
ul.clean {
  margin: 8px 0;
  padding: 0;
  list-style: none;
}
ul.clean li {
  position: relative;
  padding: 5px 0 5px 18px;
  font-size: 14px;
  color: var(--text-2);
}
ul.clean li::before {
  content: "";
  position: absolute;
  left: 2px;
  top: 12px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--accent);
}

/* ---------- Table ---------- */
table.tbl {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
table.tbl th {
  text-align: left;
  background: var(--surface-2);
  color: var(--text-2);
  font-weight: 600;
  padding: 10px 12px;
  font-size: 12px;
  letter-spacing: 0.3px;
}
table.tbl td {
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  color: var(--text-2);
  vertical-align: top;
}
table.tbl tr td:first-child {
  color: var(--text);
  font-weight: 500;
}

/* ---------- Pills / chips ---------- */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-2);
  border: 1px solid var(--border);
}
.pill.accent {
  background: var(--accent-weak);
  color: var(--accent);
  border-color: transparent;
}
.pill.green {
  background: var(--green-weak);
  color: var(--green);
  border-color: transparent;
}
.pill.amber {
  background: var(--amber-weak);
  color: var(--amber);
  border-color: transparent;
}
.pill.dot::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin: 8px 0;
}
.flow-chip {
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  font-size: 13px;
  font-weight: 500;
}
.flow-chip.accent {
  border-color: var(--accent);
  background: var(--accent-weak);
  font-weight: 600;
}
.flow-arrow {
  color: var(--text-3);
}

/* ---------- Progress ---------- */
.bar {
  height: 8px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
  margin: 8px 0;
}
.bar > span {
  display: block;
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
}
.bar.green > span {
  background: var(--green);
}

/* ---------- Weekly log ---------- */
.log-entry {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 14px;
}
.log-head {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}
.log-head .wk {
  font-weight: 700;
  font-size: 15px;
}
.log-head .dr {
  color: var(--text-3);
  font-size: 13px;
}
.log-entry .summary {
  color: var(--text-2);
  margin-bottom: 10px;
}
.log-cols {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.log-cols h5 {
  margin: 0 0 4px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-3);
}

/* ---------- Roadmap phase ---------- */
.phase {
  border-left: 3px solid var(--border-strong);
  padding: 2px 0 2px 16px;
  margin-bottom: 18px;
}
.phase.current {
  border-left-color: var(--accent);
}
.phase.done {
  border-left-color: var(--green);
}
.phase.milestone {
  border-left-color: var(--violet);
}
.phase .ph-head {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}
.phase .ph-head h3 {
  margin: 0;
  font-size: 15px;
}

/* ---------- Buttons ---------- */
.btn {
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  width: 100%;
}
.btn:hover {
  background: var(--surface-2);
}
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  width: auto;
}
.btn-primary:hover {
  background: #2459db;
}
.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text-2);
}

/* ---------- Edit mode ---------- */
/* list editing controls */
.list-remove {
  display: none;
  margin-left: 6px;
  background: none;
  border: none;
  color: #c0392b;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 0 2px;
  vertical-align: middle;
  opacity: 0.6;
}
.list-remove:hover { opacity: 1; }
body.list-editing .list-remove { display: inline; }

.list-add-row { list-style: none; margin-top: 6px; }
.list-add-btn {
  display: none;
  background: none;
  border: 1px dashed var(--border);
  border-radius: 6px;
  color: var(--text-3);
  cursor: pointer;
  font-size: 13px;
  padding: 4px 10px;
  width: 100%;
  text-align: left;
}
.list-add-btn:hover { border-color: var(--accent); color: var(--accent); }
body.list-editing .list-add-btn { display: block; }

[data-list-text][contenteditable="true"] {
  outline: none;
  border-bottom: 1px dashed var(--accent);
}

.edit-banner {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--text);
  border-radius: 999px;
  padding: 6px 8px;
  display: flex;
  align-items: center;
  gap: 6px;
  z-index: 50;
  box-shadow: 0 2px 12px rgba(0,0,0,0.18);
}
.edit-banner .btn {
  width: auto;
  padding: 5px 14px;
  font-size: 13px;
  border-radius: 999px;
}
.edit-banner .btn-primary {
  background: #fff;
  color: var(--text);
  border: none;
}
.edit-banner .btn-primary:hover { background: #e8eaf0; }
.edit-banner .btn-ghost {
  color: #8a92a6;
  border: none;
  background: none;
  font-size: 12px;
}
.edit-banner .btn-ghost:hover { color: #fff; }

body.editing [data-edit] {
  outline: 1.5px dashed var(--accent);
  outline-offset: 3px;
  border-radius: 4px;
}
body.editing [data-edit]:focus {
  outline-style: solid;
  background: var(--accent-weak);
}

.edit-hint {
  display: none;
}
body.editing .edit-hint {
  display: block;
  font-size: 12px;
  color: var(--accent);
  margin: 4px 0 14px;
}

.add-week {
  display: none;
}
body.editing .add-week {
  display: block;
}
.add-week input,
.add-week textarea {
  width: 100%;
  font-family: inherit;
  font-size: 14px;
  padding: 8px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
}

.private-note {
  font-size: 12px;
  color: var(--violet);
  background: var(--violet-weak);
  border-radius: 999px;
  padding: 3px 10px;
  display: inline-block;
  margin-bottom: 14px;
}

/* ---------- Responsive ---------- */
@media (max-width: 820px) {
  #app {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: fixed;
    z-index: 20;
    width: 260px;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
  }
  body.menu-open .sidebar {
    transform: translateX(0);
  }
  .icon-btn {
    display: inline-block;
  }
  .grid.cols-3,
  .grid.cols-4 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .log-cols {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 520px) {
  .grid.cols-2,
  .grid.cols-3,
  .grid.cols-4 {
    grid-template-columns: 1fr;
  }
  .view {
    padding: 18px;
  }
}
