:root {
  --bg: #10131a;
  --panel: #171b24;
  --panel-2: #1d2230;
  --line: #2a3040;
  --text: #e7ebf3;
  --muted: #8b95a9;
  --accent: #4c8dff;
  --accent-soft: #1f3060;
  --danger: #e5484d;
  --done: #35b37e;
  --warn: #f5a623;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

button {
  font: inherit;
  cursor: pointer;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  padding: 6px 12px;
}
button:hover { border-color: #3b4459; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:disabled { opacity: .4; cursor: not-allowed; }
button.ghost { background: transparent; }
button.danger { background: transparent; border-color: var(--danger); color: var(--danger); }
button.icon { padding: 2px 9px; line-height: 1.2; font-size: 18px; }

input, textarea, select {
  font: inherit;
  width: 100%;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
}
textarea { resize: vertical; }

/* ---------------------------------------------------------------- login */

.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}
.login-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 28px;
  width: 320px;
  display: grid;
  gap: 14px;
}
.login-card h1 { margin: 0; font-size: 19px; text-align: center; }
.login-error { margin: 0; color: var(--danger); font-size: 14px; text-align: center; }

/* --------------------------------------------------------------- layout */

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}
.brand { font-weight: 600; }
.topbar-spacer { flex: 1; }
.inline { display: inline; margin: 0; }

.layout {
  display: grid;
  grid-template-columns: 260px 1fr 400px;
  height: calc(100vh - 49px);
}
.layout.chat-hidden { grid-template-columns: 260px 1fr; }
.layout.chat-hidden .chat { display: none; }

@media (max-width: 1200px) {
  .layout { grid-template-columns: 240px 1fr; }
  .chat { display: none; }
}

.sidebar {
  border-right: 1px solid var(--line);
  background: var(--panel);
  overflow-y: auto;
  padding: 12px;
}
.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.sidebar-head h2 { margin: 0; font-size: 13px; text-transform: uppercase; color: var(--muted); letter-spacing: .06em; }

.tree { display: grid; gap: 2px; }
.tree-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--text);
}
.tree-item:hover { background: var(--panel-2); }
.tree-item.active { background: var(--accent); color: #fff; }
.tree-item .label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-item .badge { font-size: 12px; color: var(--muted); }
.tree-item.active .badge { color: #dbe6ff; }
.tree-sub { padding-left: 22px; font-size: 14px; }
.tree-remove { color: var(--muted); opacity: 0; padding: 0 2px; font-size: 15px; }
.tree-item:hover .tree-remove { opacity: 1; }
.tree-remove:hover { color: var(--danger); }
.tree-add { font-size: 13px; color: var(--muted); padding: 4px 8px 4px 30px; cursor: pointer; }
.tree-add:hover { color: var(--accent); }

/* ---------------------------------------------------------------- board */

.board { display: flex; flex-direction: column; overflow: hidden; }
.board-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}
.board-head h2 { margin: 0; font-size: 17px; }

.columns {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  padding: 14px 18px;
  overflow-y: auto;
  flex: 1;
  align-items: start;
}
.column {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
  min-height: 160px;
  display: flex;
  flex-direction: column;
}
.column h3 { margin: 0 0 10px; font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.count {
  background: var(--panel-2);
  border-radius: 20px;
  padding: 1px 7px;
  font-size: 12px;
  margin-left: 4px;
}
.cards { display: grid; gap: 8px; min-height: 60px; align-content: start; }
.cards.dragover { outline: 2px dashed var(--accent); outline-offset: 4px; border-radius: 8px; }

.card {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  cursor: grab;
}
.card:hover { border-color: #3b4459; }
.card.dragging { opacity: .45; }
.card-title { font-weight: 500; margin-bottom: 4px; word-break: break-word; }
.card-meta { display: flex; flex-wrap: wrap; gap: 6px; font-size: 12px; color: var(--muted); }
.chip { background: var(--bg); border: 1px solid var(--line); border-radius: 20px; padding: 1px 8px; }
.chip.tg { color: var(--accent); border-color: #2c4271; }
.chip.due-soon { color: var(--warn); border-color: #5a4520; }
.chip.overdue { color: var(--danger); border-color: #5d2427; }
.empty { color: var(--muted); font-size: 13px; padding: 6px 2px; }

/* ----------------------------------------------------------------- chat */

.chat {
  border-left: 1px solid var(--line);
  background: var(--panel);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.chat-head {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}
.chat-titles { flex: 1; min-width: 0; }
.chat-head h2 { margin: 0; font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.chat-subtitle {
  margin: 3px 0 0;
  font-size: 13px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chat-log {
  flex: 1;
  overflow-y: auto;
  padding: 12px 14px;
  display: grid;
  /* minmax(0, 1fr): without the 0 minimum, a long unbroken line grows the
     track and the whole pane scrolls sideways instead of wrapping. */
  grid-template-columns: minmax(0, 1fr);
  gap: 10px;
  align-content: start;
}
.chat-foot {
  margin: 0;
  padding: 8px 14px;
  border-top: 1px solid var(--line);
  font-size: 12px;
  color: var(--muted);
}

.msg { min-width: 0; max-width: 100%; }
.msg-text {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 14px;
}
.msg-operator .msg-text { background: var(--accent-soft); border: 1px solid #2c4271; }
.msg-agent .msg-text { background: var(--panel-2); border: 1px solid var(--line); }
.msg-tool .msg-text {
  background: transparent;
  border: 0;
  padding: 0 2px;
  color: var(--muted);
  font-size: 12.5px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.msg-who { font-size: 11px; color: var(--muted); margin-bottom: 3px; }
.msg-tool .msg-who { display: none; }

.chat-open {
  position: fixed;
  right: 18px;
  bottom: 18px;
  border-radius: 22px;
  padding: 9px 14px;
  background: var(--panel-2);
  z-index: 5;
}

/* ---------------------------------------------------------------- modal */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(6, 8, 12, .68);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 10;
}
.modal.hidden, .hidden { display: none; }
.modal-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  width: min(560px, 100%);
  max-height: 90vh;
  overflow-y: auto;
  display: grid;
  gap: 12px;
}
.modal-card h3 { margin: 0; font-size: 17px; }
.modal-card label { display: grid; gap: 5px; font-size: 13px; color: var(--muted); }
.modal-actions { display: flex; align-items: center; gap: 8px; margin-top: 4px; }
.modal-error { margin: 0; color: var(--danger); font-size: 13px; }
