:root {
  --bg: #12141a;
  --panel: #171a21;
  --panel-2: #1d212a;
  --line: #272c37;
  --text: #f4f6fb;
  --muted: #b7c0d2;
  --accent: #6e61ac;
  --danger: #d4645f;
  --red: #c9453f;
  --blue: #2f6fd0;
  --radius: 14px;
  --tap: 44px;
  /* tamanho do texto de leitura — o controle A-/A+ sobrescreve no <html> */
  --reading: 17px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button,
input,
textarea {
  font: inherit;
  color: inherit;
}

code {
  background: var(--panel-2);
  padding: 1px 5px;
  border-radius: 5px;
  font-size: .92em;
}

.muted {
  color: var(--muted);
}

/* ---------- gate ---------- */
.gate {
  display: grid;
  place-items: center;
  padding: 24px;
}

.gate-card {
  width: 100%;
  max-width: 340px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 24px;
}

.gate-card h1 {
  margin: 0 0 4px;
  font-size: 20px;
}

.gate-card p {
  margin: 0 0 18px;
  font-size: 14px;
}

.gate-card input,
.gate-card button {
  width: 100%;
  height: var(--tap);
  border-radius: 10px;
  padding: 0 14px;
  margin-top: 10px;
}

.gate-card input {
  background: var(--panel-2);
  border: 1px solid var(--line);
}

.gate-card button {
  background: var(--accent);
  border: 0;
  font-weight: 600;
}

.gate-error {
  color: var(--danger);
  font-size: 14px;
  margin-bottom: 0 !important;
}

/* ---------- shell ---------- */
.app {
  display: flex;
  height: 100dvh;
  overflow: hidden;
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 30;
  width: 82vw;
  max-width: 300px;
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  transform: translateX(-100%);
  transition: transform .22s ease;
  padding-top: env(safe-area-inset-top);
}

.sidebar.open {
  transform: none;
}

.sidebar-head {
  display: flex;
  gap: 8px;
  padding: 12px;
}

.head-btn {
  flex: 1;
  min-width: 0;
  height: 40px;
  border: 0;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 14px;
  font-weight: 600;
  color: #fff;
}

.head-btn svg {
  width: 17px;
  height: 17px;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.head-btn.red {
  background: var(--red);
}

.head-btn.blue {
  background: var(--blue);
}

.head-btn:active {
  filter: brightness(.9);
}

.head-btn:disabled {
  opacity: .6;
  cursor: default;
}

.sidebar-foot {
  padding: 12px;
  border-top: 1px solid var(--line);
}

.thread-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 8px 8px;
}

.thread-group {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: var(--tap);
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--panel);
  border: 0;
  border-radius: 10px;
  margin-top: 6px;
  padding: 4px 10px;
  cursor: pointer;
  text-align: left;
  font-size: 13px;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
}

.thread-group:hover {
  background: var(--panel-2);
}

.thread-group.open {
  color: var(--text);
}

.thread-group .chev {
  width: 12px;
  font-size: 12px;
}

.thread-group .label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.thread-group .count {
  background: var(--panel-2);
  border-radius: 999px;
  padding: 1px 8px;
  letter-spacing: 0;
  color: var(--muted);
}

.thread-row {
  display: flex;
  align-items: center;
  border-radius: 10px;
  margin-bottom: 2px;
  background: var(--panel);
  touch-action: none;
}

.thread-row.armed {
  outline: 1px dashed var(--accent);
}

.thread-row.dragging {
  opacity: .85;
  background: var(--panel-2);
}

.thread {
  flex: 1;
  min-width: 0;
  text-align: left;
  background: none;
  border: 0;
  border-radius: 10px;
  padding: 10px 12px;
  cursor: pointer;
}

.thread:hover,
.thread.active {
  background: var(--panel-2);
}

.thread b {
  display: block;
  font-size: 15px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.thread span {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-top: 3px;
}

.thread-menu {
  width: 32px;
  height: var(--tap);
  flex: 0 0 auto;
  background: none;
  border: 0;
  border-radius: 8px;
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}

.thread-menu:hover {
  background: var(--panel-2);
  color: var(--text);
}

.row-menu {
  position: fixed;
  z-index: 50;
  min-width: 160px;
  overflow: hidden;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 12px 32px #0008;
}

.row-menu button {
  display: block;
  width: 100%;
  min-height: var(--tap);
  text-align: left;
  background: none;
  border: 0;
  padding: 0 16px;
  font-size: 15px;
  cursor: pointer;
}

.row-menu button:hover {
  background: var(--panel);
}

.row-menu button.danger {
  color: var(--danger);
  border-top: 1px solid var(--line);
}

.scrim {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: #0009;
  opacity: 0;
  pointer-events: none;
  transition: opacity .22s ease;
}

.scrim.open {
  opacity: 1;
  pointer-events: auto;
}

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  /* âncora da régua de demandas */
  position: relative;
}

/* ---------- topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  padding-top: calc(8px + env(safe-area-inset-top));
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}

.scope-chip {
  flex: 1;
  height: 38px;
  border-radius: 19px;
  padding: 0 16px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.task-line {
  margin: 0;
  padding: 6px 14px 0;
  font-size: 13px;
  color: var(--muted);
  text-align: center;
}

.task-line.locked {
  color: var(--danger);
}

.icon {
  width: var(--tap);
  height: var(--tap);
  flex: 0 0 auto;
  background: none;
  border: 0;
  border-radius: 10px;
  font-size: 18px;
  cursor: pointer;
}

.zoom {
  display: flex;
  flex: 0 0 auto;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 19px;
  background: var(--panel-2);
}

.zoom button {
  width: 38px;
  height: 38px;
  border: 0;
  background: none;
  color: var(--text);
  font-weight: 600;
  cursor: pointer;
}

.zoom button:first-child {
  font-size: 13px;
  border-right: 1px solid var(--line);
}

.zoom button:last-child {
  font-size: 17px;
}

.zoom button:hover {
  background: var(--panel);
}

.zoom button:disabled {
  opacity: .35;
  cursor: default;
}

.icon:hover {
  background: var(--panel-2);
}

.primary {
  flex: 1;
  height: 40px;
  border-radius: 10px;
  border: 0;
  background: var(--accent);
  font-weight: 600;
  cursor: pointer;
}

.ghost {
  width: 100%;
  height: 40px;
  border-radius: 10px;
  background: none;
  border: 1px solid var(--line);
  color: var(--muted);
  cursor: pointer;
}

/* ---------- messages ---------- */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  -webkit-overflow-scrolling: touch;
}

.empty {
  text-align: center;
  color: var(--muted);
  margin-top: 18vh;
}

.empty h2 {
  color: var(--text);
  font-size: 20px;
  margin-bottom: 8px;
}

.msg {
  max-width: 760px;
  margin: 0 auto 16px;
}

.msg.operator .bubble {
  margin-left: auto;
  max-width: 85%;
  background: var(--accent);
  border-radius: 16px 16px 4px 16px;
  padding: 12px 16px;
  font-size: var(--reading);
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg.harness .bubble {
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: 12px;
  padding: 16px 18px;
}

.msg.harness.error .bubble {
  border-left-color: var(--danger);
}

/* relatório do Harness: mantém a quebra de linha do texto, mas em fonte de leitura */
.bubble pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: inherit;
  font-size: var(--reading);
  line-height: 1.75;
  letter-spacing: .01em;
}

.pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.pill {
  font-size: 13px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
}

.pill.task {
  color: var(--text);
  border-color: var(--accent);
}

.typing {
  color: var(--muted);
  font-size: 15px;
  text-align: center;
  padding: 8px;
}

/* ---------- composer ---------- */
.composer {
  border-top: 1px solid var(--line);
  background: var(--bg);
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
}

.tags {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 8px;
  scrollbar-width: none;
}

.tags::-webkit-scrollbar {
  display: none;
}

.tag {
  flex: 0 0 auto;
  height: 32px;
  padding: 0 14px;
  border-radius: 16px;
  background: none;
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 14px;
  cursor: pointer;
}

.tag.on {
  color: var(--text);
  border-color: var(--accent);
  background: #6e61ac22;
}

.input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 6px 6px 6px 16px;
}

#input {
  flex: 1;
  max-height: 140px;
  border: 0;
  background: none;
  resize: none;
  padding: 9px 0;
  outline: none;
  font-size: var(--reading);
  line-height: 1.5;
}

.send {
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  border-radius: 50%;
  border: 0;
  background: var(--accent);
  font-size: 18px;
  cursor: pointer;
}

.send:disabled {
  opacity: .45;
  cursor: default;
}

.mic {
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--muted);
  cursor: pointer;
}

.mic svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.mic.on {
  background: var(--red);
  border-color: var(--red);
  color: #fff;
  animation: mic-pulse 1.4s ease-out infinite;
}

.mic:disabled {
  opacity: .4;
  cursor: default;
}

@keyframes mic-pulse {
  from { box-shadow: 0 0 0 0 #c9453f66; }
  to { box-shadow: 0 0 0 12px #c9453f00; }
}

/* ---------- scope sheet ---------- */
.sheet {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: none;
  background: #0009;
}

.sheet.open {
  display: flex;
  align-items: flex-end;
}

.sheet-card {
  width: 100%;
  max-height: 80dvh;
  background: var(--panel);
  border-radius: 18px 18px 0 0;
  padding: 14px 14px calc(14px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

#scopeSearch {
  height: var(--tap);
  border-radius: 10px;
  padding: 0 14px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  outline: none;
}

.scope-list {
  overflow-y: auto;
  margin-top: 10px;
}

.scope-project {
  font-size: 13px;
  color: var(--muted);
  text-transform: uppercase;
  margin: 14px 0 6px;
}

.scope-item {
  display: block;
  width: 100%;
  text-align: left;
  min-height: var(--tap);
  background: none;
  border: 0;
  border-bottom: 1px solid var(--line);
  padding: 10px 4px;
  cursor: pointer;
}

.scope-item:hover {
  background: var(--panel-2);
}

/* ---------- desktop ---------- */
@media (min-width: 900px) {
  .only-mobile {
    display: none;
  }

  .sidebar {
    position: static;
    transform: none;
    width: 280px;
    max-width: none;
  }

  .scrim {
    display: none;
  }

  .topbar {
    justify-content: center;
  }

  .scope-chip {
    flex: 0 1 420px;
  }

  .sheet.open {
    align-items: center;
    justify-content: center;
  }

  .sheet-card {
    max-width: 480px;
    border-radius: 16px;
    max-height: 70dvh;
  }
}
/* ---------- editar demanda anterior ---------- */
.msg-edit {
  display: block;
  margin: 6px 2px 0 auto;
  padding: 4px 2px;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
}

.run-panel {
  margin: 0 12px 8px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
}
.run-head {
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}
.run-steps {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  margin: 8px 0 0;
  padding: 0;
  list-style: none;
}
.run-steps li {
  color: var(--muted);
  font-size: 14px;
}
.run-steps li::before {
  margin-right: 6px;
  content: '○';
}
.run-steps li.done {
  color: var(--text);
}
.run-steps li.done::before {
  content: '●';
}
.run-steps li.now {
  color: var(--blue);
  font-weight: 600;
}
.run-steps li.now::before {
  display: inline-block;
  animation: run-spin 1.2s linear infinite;
  content: '◐';
}

@keyframes run-spin {
  to {
    transform: rotate(360deg);
  }
}
.run-last {
  overflow: hidden;
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
  text-overflow: ellipsis;
}

/* Executar é ação destrutiva de verdade: fica sempre visível, não some no hover. */
.msg-run {
  display: inline-block;
  margin: 8px 0 0;
  padding: 7px 14px;
  border: 1px solid var(--blue);
  border-radius: 6px;
  background: var(--blue);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.msg-run:disabled {
  opacity: 0.6;
  cursor: default;
}

/* No toque não existe hover: o botão fica sempre visível. */
@media (hover: hover) {
  .msg-edit {
    opacity: 0;
    transition: opacity 0.12s;
  }

  .msg:hover .msg-edit,
  .msg-edit:focus-visible {
    opacity: 1;
  }
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(0, 0, 0, 0.55);
}

.modal-card {
  width: 100%;
  max-width: 560px;
  max-height: 86dvh;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}

.modal-card textarea {
  width: 100%;
  resize: vertical;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-2);
  color: var(--text);
  font: inherit;
  font-size: var(--reading);
  line-height: 1.6;
}

.modal-note {
  margin: 0;
  max-height: 34dvh;
  overflow: auto;
  white-space: pre-line;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.6;
}

.modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.modal-actions button {
  flex: 1 1 auto;
  min-height: var(--tap);
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-2);
  color: var(--text);
  font: inherit;
  cursor: pointer;
}

.modal-actions .danger {
  border-color: var(--danger);
  color: #fff;
  background: var(--danger);
}

.modal-actions button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.modal-actions .ghost {
  background: none;
}

/* ---------- régua de demandas ---------- */
.rail {
  position: absolute;
  right: 4px;
  top: 88px;
  bottom: 120px;
  z-index: 5;
  width: 20px;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 9px;
}

.rail.on {
  display: flex;
}

.tick {
  position: relative;
  width: 13px;
  height: 3px;
  padding: 0;
  border: 0;
  border-radius: 2px;
  background: var(--line);
  cursor: pointer;
  transition: width 0.12s, background 0.12s;
}

/* alvo de toque bem maior que o traço desenhado */
.tick::after {
  content: '';
  position: absolute;
  inset: -9px -5px;
}

.tick:hover,
.tick.now {
  width: 19px;
  background: var(--accent);
}

.rail-tip {
  position: fixed;
  right: 32px;
  z-index: 6;
  max-width: min(62vw, 340px);
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-2);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s;
}

.rail-tip.on {
  opacity: 1;
}

.msg.flash .bubble {
  animation: demand-flash 0.9s ease-out;
}

@keyframes demand-flash {
  from {
    box-shadow: 0 0 0 3px var(--accent);
  }

  to {
    box-shadow: 0 0 0 0 transparent;
  }
}
