:root {
  --fg: #0a0a0a;
  --fg-soft: #3a3a3a;
  --fg-mute: #8a8a8a;
  --fg-dim: #c8c8c8;
  --bg: #fafaf9;
  --bg-soft: #f2f1ee;
  --bg-line: #e6e5e1;
  --accent: #0a0a0a;
  --ok: #0a8f3a;
  --warn: #b58100;
  --err: #b01e1e;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sans: "Inter", -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
}
[data-theme="dark"] {
  --fg: #efefef;
  --fg-soft: #cfcfcf;
  --fg-mute: #8a8a8a;
  --fg-dim: #3a3a3a;
  --bg: #0a0a0a;
  --bg-soft: #141414;
  --bg-line: #1f1f1f;
  --accent: #efefef;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--mono);
  background: var(--bg);
  color: var(--fg);
  font-size: 13px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

/* ---------- layout ---------- */
.app {
  display: grid;
  grid-template-columns: 72px 1fr;
  grid-template-rows: 52px 1fr 56px;
  grid-template-areas:
    "brand topbar"
    "nav   main"
    "nav   ambient";
  height: 100vh;
  width: 100vw;
}
.brand {
  grid-area: brand;
  display: flex;
  align-items: center;
  padding: 0 0 0 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
  font-size: 18px;
  font-family: var(--sans);
  border-bottom: 1px solid var(--bg-line);
}
.brand .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--ok); margin-left: 6px; }
.brand .dot.off { background: var(--fg-dim); }
.brand .dot.err { background: var(--err); }

.topbar {
  grid-area: topbar;
  border-bottom: 1px solid var(--bg-line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  font-size: 11px;
  color: var(--fg-mute);
  letter-spacing: 0.04em;
  text-transform: lowercase;
}
.topbar .status { display: flex; gap: 18px; align-items: center; }
.topbar .status b { color: var(--fg-soft); font-weight: 500; }
.topbar .right { display: flex; gap: 14px; align-items: center; }
.topbar .right a { color: var(--fg-mute); text-decoration: none; cursor: pointer; }
.topbar .right a:hover { color: var(--fg); }
.topbar .right .pill {
  border: 1px solid var(--bg-line);
  padding: 3px 8px;
  border-radius: 10px;
  font-size: 10px;
}

/* ---------- sidebar (vertical labels like mrk.) ---------- */
nav.side {
  grid-area: nav;
  border-right: 1px solid var(--bg-line);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 28px 0 20px 0;
  gap: 28px;
}
nav.side a {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  text-orientation: mixed;
  font-size: 10px;
  letter-spacing: 0.08em;
  color: var(--fg-mute);
  text-decoration: none;
  cursor: pointer;
  padding: 6px 2px;
  border-left: 1px solid transparent;
}
nav.side a:hover { color: var(--fg); }
nav.side a.active { color: var(--fg); border-left-color: var(--fg); }
nav.side .spacer { flex: 1; }
nav.side .mode {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  font-size: 10px;
  color: var(--fg-mute);
  cursor: pointer;
  user-select: none;
}

/* ---------- main ---------- */
main {
  grid-area: main;
  overflow-y: auto;
  padding: 40px 48px 60px 48px;
  position: relative;
}
.hero {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 44px;
}
.hero h1 {
  margin: 0;
  font-family: var(--mono);
  font-weight: 400;
  font-size: 22px;
  letter-spacing: -0.02em;
}
.hero h1 .cursor { display: inline-block; margin-left: 2px; animation: blink 1.1s step-end infinite; }
@keyframes blink { 50% { opacity: 0; } }
.hero .sub {
  color: var(--fg-mute);
  font-size: 11px;
  max-width: 460px;
  text-align: right;
}

.zones {
  display: grid;
  grid-template-columns: 1.2fr 1fr 1fr;
  gap: 28px;
}
section.zone {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}
section.zone > header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--bg-line);
  margin-bottom: 6px;
}
section.zone > header h2 {
  font-size: 10px;
  margin: 0;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-weight: 500;
}
section.zone > header .count {
  color: var(--fg-mute);
  font-size: 10px;
}

/* ---------- cards ---------- */
.card {
  border: 1px solid var(--bg-line);
  background: var(--bg);
  padding: 14px 14px 12px 14px;
  transition: border-color .15s ease, transform .25s ease, opacity .25s ease;
  animation: fold-in .35s ease both;
}
@keyframes fold-in {
  from { opacity: 0; transform: translateY(-6px) scaleY(0.94); transform-origin: top; }
  to { opacity: 1; transform: none; }
}
.card:hover { border-color: var(--fg-mute); }
.card .meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 10px;
  color: var(--fg-mute);
  margin-bottom: 8px;
  letter-spacing: 0.04em;
}
.card .meta .tag {
  padding: 2px 6px;
  border: 1px solid var(--bg-line);
  border-radius: 8px;
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--fg-soft);
}
.card .title {
  font-size: 13px;
  color: var(--fg);
  margin-bottom: 6px;
  line-height: 1.4;
}
.card .plan {
  font-size: 11px;
  color: var(--fg-soft);
  background: var(--bg-soft);
  border-left: 2px solid var(--fg-dim);
  padding: 8px 10px;
  margin: 8px 0 10px 0;
  white-space: pre-wrap;
  font-family: var(--mono);
}
.card .actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 6px;
}
button.mini {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.06em;
  border: 1px solid var(--bg-line);
  background: var(--bg);
  color: var(--fg-soft);
  padding: 5px 10px;
  cursor: pointer;
  text-transform: lowercase;
}
button.mini:hover { border-color: var(--fg); color: var(--fg); }
button.mini.primary { background: var(--fg); color: var(--bg); border-color: var(--fg); }
button.mini.primary:hover { opacity: .85; }

.task-row, .watch-row {
  border: 1px solid var(--bg-line);
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  animation: fold-in .35s ease both;
}
.task-row .label, .watch-row .label { display: flex; gap: 10px; align-items: center; min-width: 0; }
.task-row .spin {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--warn);
  box-shadow: 0 0 0 0 rgba(181,129,0,.6);
  animation: pulse 1.6s ease-in-out infinite;
  flex-shrink: 0;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(181,129,0,.55); }
  70% { box-shadow: 0 0 0 8px rgba(181,129,0,0); }
  100% { box-shadow: 0 0 0 0 rgba(181,129,0,0); }
}
.task-row .text, .watch-row .text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--fg-soft);
}
.task-row .when, .watch-row .when {
  color: var(--fg-mute);
  font-size: 10px;
  flex-shrink: 0;
  margin-left: 10px;
}

.empty {
  padding: 20px 0;
  color: var(--fg-mute);
  font-size: 11px;
  text-align: left;
  border: 1px dashed var(--bg-line);
  padding: 20px;
  text-align: center;
  font-style: italic;
}

/* ---------- ambient input (novel chat) ---------- */
.ambient {
  grid-area: ambient;
  border-top: 1px solid var(--bg-line);
  background: var(--bg);
  display: flex;
  align-items: center;
  padding: 0 24px 0 48px;
  gap: 12px;
  position: relative;
}
.ambient .prompt {
  color: var(--fg-mute);
  font-family: var(--mono);
  font-size: 12px;
  user-select: none;
  letter-spacing: 0.02em;
}
.ambient input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--fg);
  font-family: var(--mono);
  font-size: 14px;
  padding: 0;
}
.ambient .cursor {
  color: var(--fg);
  animation: blink 1.1s step-end infinite;
  font-size: 14px;
  font-family: var(--mono);
}
.ambient .hint {
  color: var(--fg-mute);
  font-size: 10px;
  letter-spacing: 0.06em;
  display: flex;
  gap: 14px;
  align-items: center;
}
.ambient .hint kbd {
  border: 1px solid var(--bg-line);
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 9px;
  font-family: var(--mono);
  color: var(--fg-soft);
}

/* Floating streaming bubble that appears above ambient and folds into a card */
.floater-layer {
  pointer-events: none;
  position: absolute;
  left: 48px;
  right: 24px;
  bottom: 56px;
  z-index: 50;
}
.floater {
  pointer-events: auto;
  max-width: 640px;
  margin-left: auto;
  margin-right: auto;
  background: var(--bg);
  border: 1px solid var(--fg);
  padding: 12px 14px;
  font-size: 12px;
  color: var(--fg);
  box-shadow: 0 20px 40px -24px rgba(0,0,0,.3);
  transform-origin: bottom center;
  animation: rise .3s ease both;
  white-space: pre-wrap;
  line-height: 1.55;
  position: relative;
}
.floater .you {
  color: var(--fg-mute);
  font-size: 10px;
  letter-spacing: 0.06em;
  margin-bottom: 4px;
  display: block;
}
.floater.folding { animation: fold-away .5s ease forwards; }
@keyframes rise {
  from { transform: translateY(14px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
@keyframes fold-away {
  to { transform: translateY(-10px) scaleY(0.2); opacity: 0; }
}

/* history drawer */
.history-toggle {
  position: absolute;
  top: -14px;
  right: 24px;
  background: var(--bg);
  border: 1px solid var(--bg-line);
  padding: 2px 10px;
  font-size: 9px;
  letter-spacing: 0.08em;
  color: var(--fg-mute);
  cursor: pointer;
  text-transform: uppercase;
}
.history-toggle:hover { color: var(--fg); border-color: var(--fg); }

.drawer {
  position: fixed;
  right: 0;
  top: 52px;
  bottom: 56px;
  width: 380px;
  background: var(--bg);
  border-left: 1px solid var(--bg-line);
  transform: translateX(100%);
  transition: transform .25s ease;
  z-index: 100;
  display: flex;
  flex-direction: column;
}
.drawer.open { transform: translateX(0); }
.drawer header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--bg-line);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--fg-mute);
}
.drawer header .close { cursor: pointer; }
.drawer .log {
  flex: 1;
  overflow-y: auto;
  padding: 14px 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.msg { font-size: 12px; line-height: 1.55; }
.msg .who { font-size: 9px; color: var(--fg-mute); letter-spacing: 0.1em; text-transform: uppercase; margin-bottom: 3px; }
.msg.user .body { color: var(--fg); }
.msg.ark .body { color: var(--fg-soft); white-space: pre-wrap; }

/* inline plan card rendered from ```ark-plan``` block in a chat reply */
.plan-card {
  margin-top: 10px;
  border: 1px solid var(--bg-line);
  background: var(--bg);
  padding: 10px 12px;
  font-family: var(--mono);
}
.plan-card .pc-title { font-size: 12px; color: var(--fg); margin-bottom: 6px; }
.plan-card ol { margin: 6px 0 8px 18px; padding: 0; color: var(--fg-soft); font-size: 11px; }
.plan-card ol li { margin-bottom: 2px; }
.plan-card .pc-tools { font-size: 10px; color: var(--fg-mute); margin-bottom: 8px; }
.plan-card .pc-actions { display: flex; gap: 8px; justify-content: flex-end; }
.plan-card.resolved { opacity: .55; }
.plan-card.resolved .pc-actions { display: none; }

/* approval cards in the Pending Approvals zone */
.approval-card .prompt {
  font-size: 12px;
  color: var(--fg);
  margin: 4px 0 10px 0;
  white-space: pre-wrap;
}
.approval-card textarea {
  width: 100%;
  min-height: 54px;
  background: var(--bg-soft);
  border: 1px solid var(--bg-line);
  color: var(--fg);
  font-family: var(--mono);
  font-size: 11px;
  padding: 6px 8px;
  resize: vertical;
  margin-bottom: 8px;
}

/* events expander on a running task row */
.task-events {
  margin-top: 6px;
  font-size: 10px;
  color: var(--fg-soft);
  background: var(--bg-soft);
  border-left: 2px solid var(--fg-dim);
  padding: 6px 8px;
  max-height: 180px;
  overflow: auto;
  font-family: var(--mono);
  white-space: pre-wrap;
}
.task-events .ev-row { margin-bottom: 3px; }
.task-events .ev-kind {
  display: inline-block;
  min-width: 80px;
  color: var(--fg-mute);
  margin-right: 6px;
}
.task-row.expanded { flex-direction: column; align-items: stretch; }
.task-row .row-actions { display: flex; gap: 6px; align-items: center; flex-shrink: 0; }
.task-row .row-top { display: flex; justify-content: space-between; width: 100%; align-items: center; }
button.icon {
  background: none;
  border: none;
  color: var(--fg-mute);
  cursor: pointer;
  font-family: var(--mono);
  padding: 2px 4px;
}
button.icon:hover { color: var(--fg); }

/* scrollbars subtle */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-thumb { background: var(--bg-line); }
::-webkit-scrollbar-track { background: transparent; }

@media (max-width: 960px) {
  .zones { grid-template-columns: 1fr; }
  .app { grid-template-columns: 48px 1fr; }
  main { padding: 24px 20px 40px 20px; }
  .ambient { padding-left: 20px; }
  .floater-layer { left: 20px; right: 20px; }
}

/* ---------- login overlay ---------- */
.login-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity .25s ease;
}
.login-overlay.hidden { opacity: 0; pointer-events: none; }
.login-card {
  width: 380px;
  max-width: 92vw;
  padding: 28px 28px 24px 28px;
  border: 1px solid var(--bg-line);
  background: var(--bg);
  font-family: var(--mono);
}
.login-card h1 {
  margin: 0 0 6px 0;
  font-size: 22px;
  letter-spacing: -0.02em;
  font-weight: 700;
  font-family: var(--sans);
}
.login-card p {
  margin: 0 0 20px 0;
  color: var(--fg-mute);
  font-size: 11px;
  line-height: 1.6;
}
.login-card label {
  display: block;
  font-size: 10px;
  color: var(--fg-mute);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin-bottom: 6px;
}
.login-card input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--bg-line);
  background: var(--bg);
  color: var(--fg);
  font-family: var(--mono);
  font-size: 14px;
  outline: none;
}
.login-card input:focus { border-color: var(--fg); }
.login-card .row {
  margin-top: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.login-card .err {
  color: var(--err);
  font-size: 11px;
  margin-top: 8px;
  min-height: 14px;
}
.login-card button {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  padding: 8px 16px;
  border: 1px solid var(--fg);
  background: var(--fg);
  color: var(--bg);
  cursor: pointer;
  text-transform: lowercase;
}
.login-card button:disabled { opacity: .5; cursor: wait; }
.login-card .backend-row {
  margin-top: 14px;
  font-size: 10px;
  color: var(--fg-mute);
}
.login-card .backend-row input {
  margin-top: 4px;
  font-size: 11px;
  padding: 6px 8px;
}

/* ----- settings modal ----- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 900;
  display: none;
  align-items: center;
  justify-content: center;
  font-family: var(--mono);
}
.modal-overlay.open { display: flex; }
.modal-card {
  width: 520px;
  max-width: 94vw;
  max-height: 86vh;
  overflow-y: auto;
  background: var(--bg);
  border: 1px solid var(--bg-line);
  padding: 24px 26px;
}
.modal-card h2 {
  margin: 0 0 4px 0;
  font-size: 18px;
  font-family: var(--sans);
  font-weight: 700;
}
.modal-card p.sub {
  margin: 0 0 20px 0;
  color: var(--fg-mute);
  font-size: 11px;
}
.modal-card section { margin: 0 0 22px 0; }
.modal-card h3 {
  margin: 0 0 10px 0;
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--fg-mute);
  font-weight: 500;
}
.conn-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border: 1px solid var(--bg-line);
  margin-bottom: 8px;
}
.conn-row .name { font-size: 13px; }
.conn-row .status {
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--fg-mute);
  margin-left: 8px;
}
.conn-row .status.ok { color: #4ade80; }
.conn-row .status.pending { color: #fbbf24; }
.conn-row .status.err { color: #f87171; }
.conn-row button {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.06em;
  padding: 6px 12px;
  border: 1px solid var(--fg);
  background: transparent;
  color: var(--fg);
  cursor: pointer;
  text-transform: lowercase;
}
.conn-row button.primary {
  background: var(--fg);
  color: var(--bg);
}
.conn-row button:disabled { opacity: .5; cursor: wait; }

.modal-card .actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-top: 1px solid var(--bg-line);
  padding-top: 14px;
}
.modal-card .actions .muted {
  font-size: 10px;
  color: var(--fg-mute);
}
.modal-card .actions button {
  font-family: var(--mono);
  font-size: 11px;
  padding: 6px 12px;
  border: 1px solid var(--bg-line);
  background: transparent;
  color: var(--fg);
  cursor: pointer;
  text-transform: lowercase;
  margin-left: 6px;
}
.modal-card .actions button.danger { border-color: var(--err); color: var(--err); }
