:root {
  --chrome: #d8d5cc;
  --chrome-dark: #898982;
  --chrome-light: #ffffff;
  --blue: #000080;
  --blue-soft: #a9bfda;
  --ink: #111111;
  --green: #007000;
  --red: #cc1d1d;
  --purple: #8a1fb0;
  --orange: #c24800;
  --paper: #fffef9;
  --panel: #efeee8;
  font-family: "MS Sans Serif", Tahoma, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body, #app { height: 100%; margin: 0; }
body {
  background: #b8b8b8;
  color: var(--ink);
  letter-spacing: 0;
  overflow: hidden;
}
button, input { font: inherit; letter-spacing: 0; }

.app {
  height: 100vh;
  display: grid;
  grid-template-rows: 32px 34px 54px 1fr 44px;
  border: 2px solid #f8f8f8;
  box-shadow: inset -2px -2px #6b6b6b, inset 2px 2px #ffffff;
  background: var(--chrome);
}

.titlebar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px;
  background: linear-gradient(90deg, #000080, #143f9f);
  color: white;
  font-weight: 700;
  font-size: 20px;
  line-height: 1;
}
.titlemark {
  width: 20px;
  height: 20px;
  display: grid;
  place-items: center;
  color: #ffe870;
  border: 1px solid #d7d2ad;
  background: #18206d;
  font-size: 16px;
}
.title { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.window-buttons { display: flex; gap: 4px; }
.window-buttons span {
  width: 24px;
  height: 22px;
  background: var(--chrome);
  border: 2px solid;
  border-color: #fff #555 #555 #fff;
}

.menubar {
  display: flex;
  gap: 18px;
  align-items: center;
  padding: 0 12px;
  border-bottom: 1px solid var(--chrome-dark);
  box-shadow: 0 1px #fff;
}
.menubar button {
  border: 0;
  background: transparent;
  padding: 4px 0;
  font-size: 16px;
}
.menubar button:first-letter { text-decoration: underline; }

.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-bottom: 2px solid;
  border-color: #fff #777 #777 #fff;
}
.toolbar button, .commandbar button {
  min-width: 32px;
  height: 30px;
  border: 2px solid;
  border-color: #fff #707070 #707070 #fff;
  background: #e8e7df;
  cursor: pointer;
}
.toolbar button:active, .commandbar button:active {
  border-color: #707070 #fff #fff #707070;
}
.toolbar-status {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 8px;
  background: #f8f7ef;
  border: 1px inset #aaa;
  font-size: 13px;
}
#statusDot {
  width: 9px;
  height: 9px;
  display: inline-block;
  border-radius: 50%;
  background: #a00;
}
.connected #statusDot { background: #0a8a1f; }

.workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr) 270px;
  gap: 6px;
  padding: 6px;
}
.tree, .chat-shell, .canvas-stage, .side .panel {
  background: var(--paper);
  border: 2px solid;
  border-color: #7c7c7c #fff #fff #7c7c7c;
}
.tree {
  padding: 10px 8px;
  overflow: auto;
}
.tree-root { font-weight: 700; margin-bottom: 8px; }
.tree-branch { margin-left: 16px; border-left: 1px dotted #777; padding-left: 12px; }
.tree-folder { margin: 10px 0 5px; font-weight: 700; }
.tree-group { display: grid; gap: 2px; }
.tree-item {
  text-align: left;
  border: 0;
  background: transparent;
  padding: 3px 5px;
  min-height: 24px;
  cursor: pointer;
}
.tree-item.active {
  color: white;
  background: #000080;
}

.main-stage {
  min-width: 0;
  min-height: 0;
  display: grid;
}
.chat-shell {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: 42px 1fr;
}
.chat-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 6px 10px;
  background: var(--blue-soft);
  border-bottom: 2px solid;
  border-color: #fff #777 #777 #fff;
}
.chat-heading {
  min-width: 140px;
  white-space: nowrap;
}
.channel-icon {
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 24px;
  margin-right: 8px;
  border: 1px solid #777;
  background: #fff;
  font-weight: 700;
}
.topic {
  flex: 1;
  color: #333;
  font-size: 13px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.agent-status {
  flex: 0 1 360px;
  min-width: 190px;
  max-width: 420px;
  padding: 4px 8px;
  border: 1px inset #8f8f8f;
  background: #fff7d1;
  color: #3a2b00;
  font: 700 13px/1.2 "Courier New", Consolas, monospace;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.agent-status.done { background: #e8f5df; color: #164a1f; }
.agent-status.error { background: #f8ded9; color: #7a1200; }
.agent-status.warning { background: #f3ead2; color: #5b3a00; }
.auto-reply-control {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 7px;
  border: 1px inset #8f8f8f;
  background: #f7f6ef;
  font-size: 13px;
  white-space: nowrap;
}
.auto-reply-control input { margin: 0; }
.auto-reply-control[hidden] { display: none; }
.messages {
  min-height: 0;
  overflow: auto;
  padding: 12px 14px;
  background: white;
  font: 16px/1.45 "Courier New", Consolas, monospace;
}
.line { display: flex; gap: 8px; white-space: pre-wrap; overflow-wrap: anywhere; }
.time { color: #333; flex: 0 0 auto; }
.system { color: var(--green); }
.agent-event .text {
  display: inline-block;
  padding: 1px 5px;
  border: 1px solid #c7bd7a;
  background: #fff9dc;
  color: #3a2b00;
}
.nick { color: #0031c4; font-weight: 700; flex: 0 0 auto; }
.nick.self { color: var(--orange); }
.nick.keko { color: var(--purple); }
.text a { color: #0000ee; }

.side {
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(190px, 38%) 1fr;
  gap: 6px;
}
.panel {
  min-height: 0;
  display: grid;
  grid-template-rows: 32px 1fr;
}
.panel-title {
  padding: 7px 9px;
  border-bottom: 1px solid #aaa;
  background: var(--panel);
  font-weight: 700;
}
.nick-list, .canvas-list {
  overflow: auto;
  padding: 8px;
}
.nick-row {
  padding: 4px 3px;
  font: 16px/1.3 "Courier New", monospace;
  cursor: pointer;
}
.nick-row:hover { background: #e9efff; }
.artifact {
  display: grid;
  gap: 5px;
  margin-bottom: 8px;
  padding: 8px;
  border: 1px solid #9f9f9f;
  background: #fff;
}
.artifact strong { font-size: 13px; overflow-wrap: anywhere; }
.artifact span { color: #555; font-size: 12px; text-transform: uppercase; }
.artifact a { color: #000080; }
.artifact img {
  max-width: 100%;
  max-height: 170px;
  object-fit: contain;
  border: 1px solid #aaa;
  background: white;
}

.canvas-stage {
  min-width: 0;
  min-height: 0;
  display: none;
  grid-template-rows: 40px 1fr;
}
.canvas-mode .workspace { grid-template-columns: 260px minmax(0, 1fr); }
.canvas-mode .side { display: none; }
.canvas-mode .chat-shell { display: none; }
.canvas-mode .canvas-stage { display: grid; }
.canvas-stage-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 10px;
  background: var(--blue-soft);
  border-bottom: 2px solid;
  border-color: #fff #777 #777 #fff;
}
.canvas-stage-title button {
  height: 26px;
  border: 2px solid;
  border-color: #fff #707070 #707070 #fff;
  background: #e8e7df;
}
.canvas-stage-list {
  min-height: 0;
  overflow: auto;
  padding: 12px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  align-content: start;
  gap: 12px;
  background: #fff;
}
.stage-artifact {
  margin: 0;
  min-height: 150px;
}
.stage-artifact.image img {
  max-height: 360px;
  width: 100%;
}
.canvas-empty {
  min-height: 240px;
  display: grid;
  place-content: center;
  gap: 8px;
  text-align: center;
  border: 2px dashed #9f9f9f;
  background: #fafafa;
  color: #333;
}

.commandbar {
  display: grid;
  grid-template-columns: 1fr 86px;
  gap: 6px;
  padding: 6px;
  border-top: 2px solid;
  border-color: #fff #777 #777 #fff;
}
.commandbar input {
  width: 100%;
  min-width: 0;
  padding: 5px 8px;
  border: 2px inset #aaa;
  background: white;
  font: 17px/1.2 "Courier New", monospace;
}

.connect-dialog, .action-dialog {
  width: min(420px, calc(100vw - 24px));
  border: 2px solid;
  border-color: #fff #555 #555 #fff;
  background: var(--chrome);
  box-shadow: 8px 8px 0 #0004;
  padding: 0;
}
.connect-dialog::backdrop, .action-dialog::backdrop { background: #0006; }
.connect-dialog form, .action-dialog form { display: grid; gap: 12px; padding: 18px; }
.connect-dialog h1, .action-dialog h2 { margin: 0; font-size: 26px; color: #000080; }
.connect-dialog p { margin: 0; color: #333; }
.connect-dialog label, .action-dialog label { display: grid; gap: 5px; font-weight: 700; }
.connect-dialog input, .action-dialog input {
  padding: 7px;
  border: 2px inset #aaa;
  background: white;
}
.connect-dialog button, .action-dialog button {
  height: 34px;
  border: 2px solid;
  border-color: #fff #555 #555 #fff;
  background: #e8e7df;
  font-weight: 700;
}
.action-fields { display: grid; gap: 10px; }
.check-row {
  display: flex !important;
  grid-template-columns: none !important;
  align-items: center;
  gap: 8px;
}
.check-row input {
  width: 16px;
  height: 16px;
}
.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}
.dialog-copy {
  max-height: 48vh;
  overflow: auto;
  padding: 8px;
  border: 2px inset #aaa;
  background: white;
  font: 14px/1.35 "Courier New", monospace;
}

@media (max-width: 900px) {
  .app { grid-template-rows: 32px 0 46px 1fr 44px; }
  .menubar { display: none; }
  .workspace { grid-template-columns: 160px 1fr; }
  .side { display: none; }
  .chat-title { grid-template-columns: 1fr; height: auto; align-items: start; }
  .topic { display: none; }
  .agent-status { width: 100%; max-width: none; }
  .messages { font-size: 14px; }
  .canvas-stage-list { grid-template-columns: 1fr; }
}
