:root {
  --bg: #f7f7f5; --panel: #ffffff; --text: #1d1d1b; --muted: #6b6b66; --line: #e3e3de;
  --accent: #2f5d50; --accent-text: #ffffff; --warn: #9a5b00; --err: #a1261d; --ok: #2e7d32;
  --radius: 8px; font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #171716; --panel: #212120; --text: #ececea; --muted: #a3a39d; --line: #34342f;
          --accent: #7fb5a3; --accent-text: #10201b; }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); line-height: 1.45; }
a { color: var(--accent); }
.topbar { display: flex; align-items: center; gap: 16px; padding: 10px 20px;
          background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.brand { font-weight: 700; font-size: 1.2rem; text-decoration: none; color: var(--text); }
nav { display: flex; gap: 12px; flex-wrap: wrap; }
nav a { text-decoration: none; padding: 4px 8px; border-radius: 6px; }
nav a.active { background: var(--accent); color: var(--accent-text); }
.spacer { flex: 1; }
main { max-width: 1040px; margin: 0 auto; padding: 20px 16px 60px; }
h1 { font-size: 1.4rem; margin: 0 0 16px; }
h2 { font-size: 1.1rem; margin: 24px 0 10px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
         padding: 16px; margin-bottom: 16px; }
.muted { color: var(--muted); font-size: .9rem; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; }
label { display: block; font-weight: 600; font-size: .9rem; margin: 10px 0 4px; }
input, textarea, select { width: 100%; padding: 8px 10px; border: 1px solid var(--line);
  border-radius: 6px; background: var(--bg); color: var(--text); font: inherit; }
input[type=checkbox] { width: auto; }
textarea { min-height: 80px; resize: vertical; }
button { padding: 8px 14px; border-radius: 6px; border: 1px solid var(--accent);
         background: var(--accent); color: var(--accent-text); font: inherit; cursor: pointer; }
button.secondary { background: transparent; color: var(--accent); }
button.link { border: none; background: none; color: var(--accent); padding: 0; }
button:disabled { opacity: .5; cursor: default; }
.badge { display: inline-block; font-size: .75rem; padding: 2px 8px; border-radius: 999px;
         border: 1px solid var(--line); white-space: nowrap; }
.badge.ok { color: var(--ok); border-color: var(--ok); }
.badge.warn { color: var(--warn); border-color: var(--warn); }
.badge.err { color: var(--err); border-color: var(--err); }
.list { list-style: none; margin: 0; padding: 0; }
.list > li { padding: 10px 0; border-bottom: 1px solid var(--line); }
.list > li:last-child { border-bottom: none; }
.chat { display: flex; flex-direction: column; gap: 10px; max-height: 55vh; overflow-y: auto;
        padding-right: 4px; }
.msg { padding: 10px 12px; border-radius: var(--radius); max-width: 85%; white-space: pre-wrap; }
.msg.user { align-self: flex-end; background: var(--accent); color: var(--accent-text); }
.msg.agent { align-self: flex-start; background: var(--bg); border: 1px solid var(--line); }
.step { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; padding: 10px 0;
        border-bottom: 1px solid var(--line); }
.indent-1 { margin-left: 20px; } .indent-2 { margin-left: 40px; } .indent-3 { margin-left: 60px; }
details > summary { cursor: pointer; color: var(--muted); font-size: .9rem; }
pre { background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 8px;
      overflow-x: auto; font-size: .8rem; max-height: 300px; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.error { color: var(--err); }
.warning { color: var(--warn); font-weight: 600; }
#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
         background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 6px; }
.login { max-width: 360px; margin: 10vh auto; }

/* P3 screens */
:root { --series-1: #2a78d6; --chart-grid: #d9d8d3; }
@media (prefers-color-scheme: dark) { :root { --series-1: #3987e5; --chart-grid: #3d3d38; } }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.tile-value { font-size: 1.5rem; font-weight: 700; }
.tile-label { font-weight: 600; font-size: .9rem; }
.filters { margin-bottom: 12px; }
.filters input, .filters select { width: auto; min-width: 180px; }
label.inline { display: inline-flex; gap: 6px; align-items: center; font-weight: 400; margin: 6px 12px 6px 0; }
.tabs { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.card { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; margin-top: 8px;
        background: var(--panel); white-space: normal; }
.list > li.card { border: 1px solid var(--line); margin-bottom: 8px; }
.feed li { padding: 6px 0; }
button.danger { background: var(--err); border-color: var(--err); color: #fff; }
/* Organization graph (P3-002): an org chart drawn with borders only. */
.org { overflow-x: auto; padding-bottom: 8px; }
.org ul { display: flex; justify-content: center; padding: 16px 0 0; margin: 0; position: relative; list-style: none; }
.org li { display: flex; flex-direction: column; align-items: center; position: relative; padding: 16px 6px 0; }
.org li::before, .org li::after { content: ""; position: absolute; top: 0; width: 50%; height: 16px; border-top: 1px solid var(--muted); }
.org li::before { right: 50%; }
.org li::after { left: 50%; border-left: 1px solid var(--muted); }
.org li:only-child::before, .org li:only-child::after { display: none; }
.org li:only-child { padding-top: 0; }
.org li:first-child::before, .org li:last-child::after { border: 0 none; }
.org li:last-child::before { border-right: 1px solid var(--muted); }
.org ul ul::before { content: ""; position: absolute; top: 0; left: 50%; height: 16px; border-left: 1px solid var(--muted); }
.org > ul { padding-top: 0; }
.org-node { display: flex; flex-direction: column; gap: 2px; align-items: center; min-width: 130px; background: var(--panel);
            color: var(--text); border: 1px solid var(--line); }
.org-node.selected { border: 2px solid var(--accent); }
.org-node.suspended { border-style: dashed; opacity: .75; }
/* Charts (P3-008): single series, text in ink colors, recessive axis. */
.chart { width: 100%; height: auto; max-width: 720px; display: block; }
.chart .bar { fill: var(--series-1); }
.chart .axis { stroke: var(--chart-grid); stroke-width: 1; }
.chart .label { fill: var(--muted); font-size: 12px; }
.chart .value { fill: var(--text); font-size: 12px; }
.chart .hit { fill: transparent; }
.chart .mark:hover .bar { opacity: .8; }
.chart .mark:hover .hit { fill: var(--line); fill-opacity: .35; }
/* Command palette (P3-013) */
dialog.palette { width: min(640px, 92vw); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px;
                 background: var(--panel); color: var(--text); margin-top: 12vh; }
dialog.palette::backdrop { background: rgba(0, 0, 0, .35); }
dialog.palette li { padding: 8px; cursor: pointer; border-radius: 6px; }
dialog.palette li.active { background: var(--accent); color: var(--accent-text); }

/* P4 (PWA): installable on Mac and iPhone; phone-first layout below 700 px. */
.bell { position: relative; text-decoration: none; font-size: 1.1rem; }
.bell-count { position: absolute; top: -6px; right: -10px; background: var(--err); color: #fff;
              font-size: .65rem; border-radius: 999px; padding: 1px 5px; }
a.button { display: inline-block; padding: 8px 14px; border-radius: 6px; border: 1px solid var(--accent);
           background: var(--accent); color: var(--accent-text); text-decoration: none; }
a.button.secondary { background: transparent; color: var(--accent); }
a.tile-link { text-decoration: none; color: var(--text); }
body { padding-bottom: env(safe-area-inset-bottom); }
@media (max-width: 700px) {
  .topbar { padding: calc(8px + env(safe-area-inset-top)) 12px 8px; gap: 8px; }
  .topbar nav { order: 10; width: 100%; flex-wrap: nowrap; overflow-x: auto; gap: 4px;
                -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  .topbar nav a { white-space: nowrap; }
  #whoami { display: none; }
  main { padding: 12px 12px 48px; }
  h1 { font-size: 1.25rem; }
  .grid { grid-template-columns: 1fr; }
  .tiles { grid-template-columns: repeat(auto-fit, minmax(100px, 1fr)); }
  .msg { max-width: 95%; }
  .chat { max-height: 60vh; }
  button, a.button { min-height: 44px; }  /* touch targets */
  table { display: block; overflow-x: auto; }
  .filters input, .filters select { min-width: 0; width: 100%; }
}

/* P10: AI Organization OS */
.headline { font-size: 1.1rem; font-weight: 600; margin: 8px 0 0; }
.secondary-tabs { font-size: .9rem; border-bottom: 1px solid var(--line); padding-bottom: 8px; }
.tabs a[aria-current=page] { background: var(--accent); color: var(--accent-text); border-radius: 6px; padding: 2px 8px; }
.chart-layout { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 16px; align-items: start; }
.tree { list-style: none; margin: 0; padding-left: 18px; border-left: 1px dashed var(--line); }
.tree > li { margin: 6px 0; }
ul.root-tree { padding-left: 0; border-left: none; }
.node { display: block; width: 100%; text-align: left; background: var(--panel); color: var(--text);
        border: 1px solid var(--line); border-left: 4px solid var(--line); }
.node-department { border-left-color: var(--accent); }
.node-agent { border-left-color: var(--series-1); }
.node-person { border-left-color: var(--warn); }
.node:focus-visible, button:focus-visible, a:focus-visible { outline: 3px solid var(--series-1); outline-offset: 2px; }
.node-stats .badge { margin-left: 6px; }
.node-panel { position: sticky; top: 12px; }
.rights { display: inline-flex; gap: 4px; flex-wrap: wrap; }
.role-card h4 { margin: 12px 0 4px; font-size: .95rem; }
.table-scroll { overflow-x: auto; }
progress { width: 120px; vertical-align: middle; }
@media (max-width: 760px) {
  .chart-layout { grid-template-columns: 1fr; }
  .node-panel { position: static; }
}
.diff .added { color: var(--ok); } .diff .removed { color: var(--err); }
.stages > li { margin: 8px 0; } .stage-step .badge { margin-left: 6px; }

/* P10-034: accessibility & density */
.skip-link { position: absolute; left: -9999px; top: 0; background: var(--accent); color: var(--accent-text);
             padding: 8px 12px; z-index: 10; }
.skip-link:focus { left: 8px; top: 8px; }
main:focus { outline: none; }
body.dense main { max-width: 1280px; }
body.dense .panel { padding: 10px 12px; margin-bottom: 10px; }
body.dense .list > li { padding: 5px 0; }
body.dense table { font-size: .82rem; }
body.dense th, body.dense td { padding: 3px 6px; }
body.dense .tiles { grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); }
.tour-banner { border-left: 4px solid var(--accent); }
.timeline-month { color: var(--muted); border-bottom: none !important; padding-top: 16px !important; }
dl.glossary dt { font-weight: 700; margin-top: 10px; }
@media (max-width: 640px) {
  .topbar nav, .tabs { flex-wrap: nowrap; overflow-x: auto; max-width: 100%; }
  .tabs a, nav a { white-space: nowrap; }
  table { display: block; overflow-x: auto; }
  main { padding: 12px 10px 40px; }
}
/* P13-005: an app's own shell — the shared design system with the app's accent */
.app-header { display: flex; flex-wrap: wrap; align-items: baseline; gap: 16px; margin-bottom: 16px; }
.app-header h1 { margin: 0; color: var(--accent); }
.app-nav { display: flex; flex-wrap: wrap; gap: 8px; }
.app-nav a { padding: 4px 10px; border-radius: 6px; }
.app-nav a.active { background: var(--accent); color: var(--accent-text); }
.powered { margin: 0 0 0 auto; font-size: 0.85em; }

/* P13 B6 (ADR 0209): generic app screens over domain records — list, board, search */
.app-view .app-create { flex-wrap: wrap; gap: .5rem; margin-bottom: .75rem; }
.app-board { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(11rem, 1fr); gap: .75rem; overflow-x: auto; }
.app-board-column { background: var(--surface-2, rgba(127,127,127,.08)); border-radius: 8px; padding: .5rem; min-height: 6rem; }
.app-board-column h4 { margin: 0 0 .5rem; text-transform: capitalize; font-size: .9rem; }
.app-card { background: var(--surface, #fff); border-left: 3px solid var(--accent); border-radius: 6px; padding: .4rem .5rem; margin-bottom: .4rem; display: flex; flex-direction: column; }

/* ADR 0245: content kept out of sight (the signup form's anti-robot field) */
.m-visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}
