/* BUS // OP-01 — Tactile Field Dispatcher. Implements DESIGN.md (Agent Bus Design System). */
@import url('https://fonts.googleapis.com/css2?family=Fraunces:wght@700&family=Plus+Jakarta+Sans:wght@400;500;600;700&family=IBM+Plex+Mono:wght@400;600;700&display=swap');

:root {
  --paper: #F4F1EA;
  --outer: #E2DDD3;
  --card: #FAF8F5;
  --recessed: #EAE5DC;
  --charcoal: #262523;
  --charcoal-text: #F4F1EA;
  --ink: #161615;
  --secondary: #6E6A63;
  --border-subtle: #D6D0C4;
  --border-inset: #C8C1B4;
  --border-hardware: #161615;
  --shadow: #161615;
  --forest: #1E6F50;
  --ochre: #D98200;
  --vermilion: #E03E1A;
  --cobalt: #1D4ED8;
  --plum: #6D28D9;
  --led: #34D399;
  --caution-red-a: #FEE2E2;
  --caution-red-b: #FECACA;
  --caution-amber-a: #FEF3C7;
  --caution-amber-b: #FDE68A;
  --track: #262523;
  --r-xs: 4px; --r-sm: 6px; --r-md: 8px; --r-lg: 12px; --r-xl: 16px; --r-2xl: 24px; --r-chassis: 28px;
}

[data-theme="dark"] {
  --paper: #171614;
  --outer: #0D0C0B;
  --card: #211F1C;
  --recessed: #121110;
  --charcoal: #1D1B18;
  --charcoal-text: #F2EFE9;
  --ink: #F2EFE9;
  --secondary: #9E988E;
  --border-subtle: #35322D;
  --border-inset: #2E2B27;
  --border-hardware: #3A3630;
  --shadow: #090908;
  --caution-red-a: #3B1815;
  --caution-red-b: #4C1D19;
  --caution-amber-a: #382810;
  --caution-amber-b: #493414;
  --track: #121110;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }

body {
  font-family: 'Plus Jakarta Sans', system-ui, sans-serif;
  background: var(--outer);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.6;
}

.serif { font-family: 'Fraunces', Georgia, serif; }
.mono { font-family: 'IBM Plex Mono', ui-monospace, monospace; }

/* ---------- Chassis ---------- */
.chassis {
  max-width: 430px; min-width: 320px; margin: 0 auto;
  height: 100dvh; display: flex; flex-direction: column;
  background: var(--paper); position: relative; overflow: hidden;
}
@media (min-width: 520px) {
  body { padding: 24px 0; }
  .chassis {
    height: min(880px, calc(100dvh - 48px));
    border: 2px solid var(--border-hardware); border-radius: var(--r-chassis);
    box-shadow: 0 6px 0 var(--shadow);
  }
}

/* ---------- Header ---------- */
.hw-header {
  min-height: 54px; flex: none; z-index: 20;
  background: var(--charcoal); color: var(--charcoal-text);
  display: flex; align-items: center; gap: 10px; padding: 6px 12px;
  border-bottom: 2px solid var(--shadow);
}
.led {
  width: 10px; height: 10px; border-radius: 9999px; background: var(--led); flex: none;
  animation: led-pulse 2s ease-in-out infinite;
}
@keyframes led-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(52, 211, 153, 0.55); }
  50% { box-shadow: 0 0 0 5px rgba(52, 211, 153, 0); }
}
.hw-header .title { font-family: 'Fraunces', serif; font-weight: 700; font-size: 18px; letter-spacing: -0.01em; line-height: 1.2; }
.hw-header .subtitle { font-family: 'IBM Plex Mono', monospace; font-size: 11px; font-weight: 700; letter-spacing: 0.06em; opacity: 0.65; }
.live-pill {
  font-family: 'IBM Plex Mono', monospace; font-size: 11px; font-weight: 700;
  border: 1.5px solid rgba(244, 241, 234, 0.4); border-radius: var(--r-md);
  padding: 3px 8px; white-space: nowrap;
}
.icon-btn {
  min-width: 44px; min-height: 44px; display: grid; place-items: center;
  background: transparent; border: none; color: inherit; cursor: pointer;
  font-size: 18px; border-radius: var(--r-lg);
}
.icon-btn:active { background: rgba(244, 241, 234, 0.12); }

/* ---------- Workspace ---------- */
.workspace { flex: 1; overflow-y: auto; overflow-x: hidden; overscroll-behavior: contain; }
.view { display: none; padding: 14px 12px 20px; }
.view.active { display: block; }
.view-head { margin: 2px 2px 14px; }
.view-head h1 { font-family: 'Fraunces', serif; font-size: 24px; font-weight: 700; line-height: 1.25; letter-spacing: -0.01em; }
.view-head p { color: var(--secondary); font-size: 12px; margin-top: 2px; }

/* ---------- Hardware primitives ---------- */
.hw-card {
  background: var(--card); border: 1.5px solid var(--border-hardware);
  border-radius: var(--r-xl); box-shadow: 0 3px 0 var(--shadow);
}
.hw-inset {
  background: var(--recessed); border: 1.5px solid var(--border-inset);
  border-radius: var(--r-lg); box-shadow: inset 0 2px 3px rgba(0, 0, 0, 0.12);
}
.hw-btn {
  font-family: 'IBM Plex Mono', monospace; font-size: 12px; font-weight: 700; line-height: 1.2;
  min-height: 44px; padding: 10px 14px; border-radius: var(--r-lg);
  border: 1.5px solid var(--border-hardware); box-shadow: 0 2.5px 0 var(--shadow);
  cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  transition: transform 0.08s ease, box-shadow 0.08s ease;
  background: var(--recessed); color: var(--ink); user-select: none;
}
.hw-btn:active { transform: translateY(2px); box-shadow: 0 0.5px 0 var(--shadow); }
.btn-primary { background: var(--ink); color: var(--paper); }
.btn-positive { background: var(--forest); color: #FFFFFF; }
.btn-danger { background: var(--vermilion); color: #FFFFFF; }
.btn-secondary { background: var(--card); color: var(--ink); }
.btn-sm { min-height: 44px; padding: 8px 12px; font-size: 11px; }
.btn-block { width: 100%; }

/* ---------- Badges & chips ---------- */
.badge {
  font-family: 'IBM Plex Mono', monospace; font-size: 11px; font-weight: 700; line-height: 1.1;
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 7px; border-radius: var(--r-sm); border: 1.5px solid var(--border-hardware);
  background: var(--card); color: var(--ink); white-space: nowrap;
}
.badge-urgent { background: var(--vermilion); color: #FFFFFF; }
.badge-forest { background: var(--forest); color: #FFFFFF; }
.badge-ochre { background: var(--ochre); color: #FFFFFF; }
.badge-quiet { background: var(--recessed); color: var(--secondary); border-color: var(--border-inset); }
.badge-channel { background: var(--recessed); border-color: var(--border-inset); color: var(--ink); }
.agent-chip {
  font-family: 'IBM Plex Mono', monospace; font-size: 12px; font-weight: 700; line-height: 1.2;
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 8px; border-radius: var(--r-md); border: 1.5px solid; white-space: nowrap;
}
.agent-chip .dot { width: 8px; height: 8px; border-radius: 9999px; flex: none; }
.agent-nyx { background: #E0E7FF; color: #1E1B4B; border-color: #3730A3; }
.agent-nyx .dot { background: #4F46E5; }
.agent-nosmile99 { background: #D1FAE5; color: #022C22; border-color: #065F46; }
.agent-nosmile99 .dot { background: #059669; }
.agent-wren { background: #FEF3C7; color: #451A03; border-color: #92400E; }
.agent-wren .dot { background: #D97706; }
.agent-luki { background: #E7E5E4; color: #1C1917; border-color: #44403C; }
.agent-luki .dot { background: #1E6F50; }

/* ---------- Caution stripes ---------- */
.caution-stripe { height: 10px; border-radius: var(--r-xl) var(--r-xl) 0 0; border-bottom: 1.5px solid var(--border-hardware); }
.caution-red { background: repeating-linear-gradient(-45deg, var(--caution-red-a) 0 8px, var(--caution-red-b) 8px 16px); }
.caution-amber { background: repeating-linear-gradient(-45deg, var(--caution-amber-a) 0 8px, var(--caution-amber-b) 8px 16px); }
.caution-label {
  font-family: 'IBM Plex Mono', monospace; font-size: 11px; font-weight: 700;
  padding: 7px 12px; display: flex; align-items: center; gap: 7px;
}
.caution-label.red { color: var(--vermilion); }
.caution-label.amber { color: var(--ochre); }

/* ---------- Bus feed ---------- */
.resync-banner { margin-bottom: 12px; overflow: hidden; }
.resync-banner .body { padding: 10px 12px; font-size: 13px; }
.resync-banner .body b { font-weight: 700; }
.msg-list { display: grid; gap: 14px; }
.swipe-shell { position: relative; border-radius: var(--r-xl); }
.swipe-bg {
  position: absolute; inset: 0; z-index: 1; border-radius: var(--r-xl);
  background: var(--track); color: #F4F1EA;
  display: flex; align-items: center; padding: 0 18px; gap: 8px;
  font-family: 'IBM Plex Mono', monospace; font-size: 12px; font-weight: 700;
  border: 1.5px solid var(--border-hardware);
}
.swipe-bg.armed { background: var(--forest); }
.swipe-fg { position: relative; z-index: 2; will-change: transform; touch-action: pan-y; }
.msg-card { padding: 14px; }
.msg-card.urgent { border-left: 4px solid var(--vermilion); }
.msg-top { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.msg-time { font-family: 'IBM Plex Mono', monospace; font-size: 11px; color: var(--secondary); margin-left: auto; }
.msg-body { font-size: 14px; line-height: 1.6; }
.msg-body .mono-inline { font-family: 'IBM Plex Mono', monospace; font-size: 13px; }
.msg-actions { display: flex; gap: 8px; margin-top: 12px; }
.msg-actions .hw-btn { flex: 1; }
.quote-strip {
  border-left: 4px solid var(--forest); padding: 8px 10px; margin-bottom: 10px;
  font-size: 12px; color: var(--secondary);
}
.quote-strip b { color: var(--ink); font-family: 'IBM Plex Mono', monospace; font-size: 11px; }
.quote-strip .q-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@keyframes msg-highlight {
  0%, 100% { box-shadow: 0 3px 0 var(--shadow); }
  30% { box-shadow: 0 3px 0 var(--shadow), 0 0 0 3px var(--ochre); }
}
.msg-flash { animation: msg-highlight 1.1s ease 2; }

/* ---------- Composer ---------- */
.composer-dock { flex: none; padding: 10px 12px; background: var(--paper); border-top: 1.5px solid var(--border-subtle); display: none; }
.composer-dock.active { display: block; }
.composer-compact {
  display: flex; align-items: center; gap: 8px; padding: 8px 10px; cursor: pointer; width: 100%; text-align: left;
  font: inherit; color: var(--ink);
}
.composer-compact .draft { flex: 1; color: var(--secondary); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.composer-expanded { padding: 12px; display: none; }
.composer-expanded.open { display: block; }
.reply-banner {
  display: none; align-items: center; gap: 8px; padding: 8px 10px; margin-bottom: 10px;
  border-left: 4px solid var(--forest); font-size: 12px;
}
.reply-banner.open { display: flex; }
.reply-banner .rb-text { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--secondary); }
.select-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; margin-bottom: 10px; }
.field label {
  display: block; font-family: 'IBM Plex Mono', monospace; font-size: 11px; font-weight: 700;
  letter-spacing: 0.06em; color: var(--secondary); margin-bottom: 5px; text-transform: uppercase;
}
.field select, .field input[type="text"], .field textarea {
  width: 100%; font-family: 'Plus Jakarta Sans', sans-serif; font-size: 16px !important; color: var(--ink);
  background: var(--recessed); border: 1.5px solid var(--border-inset); border-radius: var(--r-lg);
  padding: 11px 12px; box-shadow: inset 0 2px 3px rgba(0, 0, 0, 0.12);
}
.field select { appearance: none; }
.field textarea { resize: vertical; line-height: 1.5; }
.field .mono-area { font-family: 'IBM Plex Mono', monospace; font-size: 14px !important; line-height: 1.6; }
.field select:focus, .field input:focus, .field textarea:focus { outline: 2px solid var(--forest); outline-offset: 0; }
.composer-actions { display: flex; gap: 8px; margin-top: 10px; }
.composer-actions .hw-btn { flex: 1; }

/* ---------- Nav deck ---------- */
.nav-deck {
  flex: none; z-index: 30; display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px;
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  background: var(--paper); border-top: 2px solid var(--border-hardware);
}
.nav-tab {
  min-height: 52px; border-radius: var(--r-lg); border: 1.5px solid transparent;
  background: transparent; color: var(--secondary); cursor: pointer; position: relative;
  font-family: 'IBM Plex Mono', monospace; font-size: 11px; font-weight: 700; line-height: 1.1;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
}
.nav-tab .ico { font-size: 17px; line-height: 1; }
.nav-tab.active {
  background: var(--ink); color: var(--paper); border-color: var(--border-hardware);
  box-shadow: 0 2.5px 0 var(--shadow);
}
.nav-badge {
  position: absolute; top: 4px; right: 8px; min-width: 19px; height: 19px; padding: 0 5px;
  border-radius: 9999px; background: var(--vermilion); color: #FFFFFF;
  font-size: 11px; font-weight: 700; display: grid; place-items: center;
  border: 1.5px solid var(--border-hardware);
}
.nav-badge.quiet { background: var(--recessed); color: var(--ink); }

/* ---------- Needs You ---------- */
.needs-list { display: grid; gap: 14px; }
.zero-state { text-align: center; padding: 28px 18px; }
.zero-state .big { font-family: 'Fraunces', serif; font-size: 20px; font-weight: 700; margin-bottom: 4px; }
.zero-state p { color: var(--secondary); font-size: 13px; }

/* ---------- Kanban ---------- */
.kb-strip {
  display: flex; gap: 12px; overflow-x: auto; scroll-snap-type: x mandatory;
  padding: 2px 2px 14px; margin: 0 -12px; padding-left: 12px; padding-right: 12px;
  scrollbar-width: none;
}
.kb-strip::-webkit-scrollbar { display: none; }
.kb-col {
  flex: 0 0 85vw; max-width: 330px; scroll-snap-align: start;
  padding: 10px; display: flex; flex-direction: column; gap: 10px;
  border-radius: var(--r-xl);
}
.kb-col-head { display: flex; align-items: center; gap: 7px; padding: 2px 2px 0; }
.kb-col-head .col-name { font-family: 'IBM Plex Mono', monospace; font-size: 12px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; }
.col-dot { width: 9px; height: 9px; border-radius: 9999px; flex: none; border: 1.5px solid var(--border-hardware); }
.kb-count { margin-left: auto; }
.task-card { overflow: hidden; }
.task-inner { padding: 12px; }
.task-title { font-family: 'Fraunces', serif; font-size: 16px; font-weight: 700; line-height: 1.375; margin-bottom: 4px; }
.task-summary { font-size: 13px; color: var(--secondary); line-height: 1.5; margin-bottom: 10px; }
.task-meta { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.task-actions { display: flex; gap: 8px; }
.task-actions .hw-btn { flex: 1; }
.status-strip { display: grid; grid-template-columns: repeat(4, 1fr); gap: 5px; margin-top: 10px; }
.status-seg {
  min-height: 44px; border-radius: var(--r-md); border: 1.5px solid var(--border-inset);
  background: var(--recessed); color: var(--secondary); cursor: pointer;
  font-family: 'IBM Plex Mono', monospace; font-size: 11px; font-weight: 700;
  display: grid; place-items: center;
}
.status-seg.current { background: var(--ink); color: var(--paper); border-color: var(--border-hardware); box-shadow: 0 2px 0 var(--shadow); }
.status-seg.s-blocked.current { background: var(--vermilion); color: #FFFFFF; }
.status-seg.s-done.current { background: var(--forest); color: #FFFFFF; }
.status-seg.s-doing.current { background: var(--ochre); color: #FFFFFF; }

/* ---------- Agents ---------- */
.agent-card { padding: 14px; margin-bottom: 14px; }
.agent-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.agent-head .a-name { font-family: 'Fraunces', serif; font-size: 18px; font-weight: 700; }
.agent-head .a-role { font-size: 12px; color: var(--secondary); }
.meter { height: 12px; border: 1.5px solid var(--border-hardware); border-radius: 9999px; background: var(--recessed); overflow: hidden; }
.meter > div { height: 100%; background: var(--forest); }
.meter.warn > div { background: var(--ochre); }
.meter-row { display: flex; justify-content: space-between; font-family: 'IBM Plex Mono', monospace; font-size: 11px; font-weight: 700; color: var(--secondary); margin: 10px 0 5px; }
.mode-switch { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.event-list { font-family: 'IBM Plex Mono', monospace; font-size: 12px; line-height: 1.7; padding: 12px; overflow-x: auto; }
.event-list .ev-name { color: var(--forest); font-weight: 700; }
.event-list .ev-cursor { color: var(--secondary); }
.event-list div { white-space: nowrap; }

/* ---------- Drawer & sheets ---------- */
.sheet-backdrop {
  position: absolute; inset: 0; z-index: 40; background: rgba(22, 22, 21, 0.6);
  backdrop-filter: blur(1px); opacity: 0; pointer-events: none; transition: opacity 0.22s ease;
}
.sheet-backdrop.open { opacity: 1; pointer-events: auto; }
.drawer {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 45; height: 96%;
  background: var(--paper); border-top: 2px solid var(--border-hardware);
  border-radius: var(--r-2xl) var(--r-2xl) 0 0; transform: translateY(103%);
  visibility: hidden; pointer-events: none;
  transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1), visibility 0s 0.28s;
  display: flex; flex-direction: column; overflow: hidden;
}
.drawer.open {
  transform: translateY(0); visibility: visible; pointer-events: auto;
  transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1), visibility 0s 0s;
}
.drawer-head {
  flex: none; background: var(--charcoal); color: var(--charcoal-text);
  display: flex; align-items: center; gap: 8px; padding: 8px 12px; flex-wrap: wrap;
}
.drawer-head .dh-title { font-family: 'IBM Plex Mono', monospace; font-size: 11px; font-weight: 700; letter-spacing: 0.06em; opacity: 0.7; }
.drawer-head .spacer { flex: 1; }
.drawer-head .hw-btn { min-height: 44px; }
.drawer-body { flex: 1; overflow-y: auto; padding: 14px 12px 24px; display: grid; gap: 14px; align-content: start; }
.drawer-body .field { margin-bottom: 10px; }
.drawer-body .field:last-child { margin-bottom: 0; }
.card-pad { padding: 14px; }
.card-label {
  font-family: 'IBM Plex Mono', monospace; font-size: 11px; font-weight: 700;
  letter-spacing: 0.06em; text-transform: uppercase; color: var(--secondary); margin-bottom: 10px;
}
.prop-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.due-strip { display: grid; grid-template-columns: repeat(4, 1fr); gap: 5px; }
.due-seg {
  min-height: 44px; border-radius: var(--r-md); border: 1.5px solid var(--border-inset);
  background: var(--recessed); color: var(--secondary); cursor: pointer;
  font-family: 'IBM Plex Mono', monospace; font-size: 11px; font-weight: 700; display: grid; place-items: center;
}
.due-seg.current { background: var(--ink); color: var(--paper); border-color: var(--border-hardware); }
.label-row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.label-chip {
  font-family: 'IBM Plex Mono', monospace; font-size: 11px; font-weight: 700;
  background: var(--recessed); border: 1.5px solid var(--border-inset); border-radius: var(--r-sm);
  padding: 5px 4px 5px 8px; display: inline-flex; align-items: center; gap: 4px;
}
.label-chip button {
  min-width: 30px; min-height: 30px; border: none; background: transparent; cursor: pointer;
  font-size: 14px; color: var(--secondary); display: grid; place-items: center;
}
.check-item { display: flex; align-items: center; gap: 10px; padding: 7px 0; border-bottom: 1px dashed var(--border-subtle); }
.check-item:last-child { border-bottom: none; }
.check-box {
  width: 24px; height: 24px; flex: none; border-radius: var(--r-sm); cursor: pointer;
  border: 1.5px solid var(--border-hardware); background: var(--card);
  display: grid; place-items: center; color: #FFFFFF; font-size: 14px; font-weight: 700;
}
.check-box.done { background: var(--forest); }
.check-item .c-text { flex: 1; font-size: 14px; }
.check-item .c-text.done { color: var(--secondary); text-decoration: line-through; }
.check-item .c-del {
  min-width: 44px; min-height: 44px; border: none; background: transparent; cursor: pointer;
  color: var(--secondary); font-size: 16px; display: grid; place-items: center;
}
.comment { padding: 10px 0; border-bottom: 1px dashed var(--border-subtle); }
.comment:last-of-type { border-bottom: none; }
.comment .c-head { display: flex; gap: 8px; align-items: center; margin-bottom: 4px; }
.comment .c-time { font-family: 'IBM Plex Mono', monospace; font-size: 11px; color: var(--secondary); }
.activity-well { padding: 12px; font-family: 'IBM Plex Mono', monospace; font-size: 12px; line-height: 1.7; color: var(--secondary); }
.modal-sheet {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 46;
  background: var(--card); border-top: 2px solid var(--border-hardware);
  border-radius: var(--r-2xl) var(--r-2xl) 0 0; padding: 20px 16px calc(16px + env(safe-area-inset-bottom));
  transform: translateY(103%); visibility: hidden; pointer-events: none;
  transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1), visibility 0s 0.28s;
}
.modal-sheet.open {
  transform: translateY(0); visibility: visible; pointer-events: auto;
  transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1), visibility 0s 0s;
}
.modal-sheet h3 { font-family: 'Fraunces', serif; font-size: 20px; font-weight: 700; margin-bottom: 6px; }
.modal-sheet p { color: var(--secondary); font-size: 13px; margin-bottom: 16px; }
.modal-sheet .row { display: flex; gap: 8px; }
.modal-sheet .row .hw-btn { flex: 1; }

/* ---------- Toasts ---------- */
.toast-zone { position: absolute; left: 12px; right: 12px; bottom: 86px; z-index: 50; display: grid; gap: 8px; pointer-events: none; }
.toast {
  background: var(--charcoal); color: var(--charcoal-text);
  border: 1.5px solid var(--border-hardware); border-radius: var(--r-lg);
  box-shadow: 0 4px 0 var(--shadow); padding: 12px 14px; font-size: 14px;
  display: flex; gap: 9px; align-items: center; animation: toast-in 0.22s ease;
}
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
