:root {
  --bg: #f5f6f1;
  --ink: #1b1f24;
  --muted: #68707a;
  --line: #d9ded6;
  --panel: #ffffff;
  --panel-2: #eef3f6;
  --accent: #0f7a6f;
  --accent-2: #365f91;
  --danger: #a33a3a;
  --shadow: 0 16px 45px rgba(17, 24, 39, .08);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}
button, input, textarea {
  font: inherit;
}
button {
  min-height: 38px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  border-radius: 8px;
  padding: 8px 12px;
  cursor: pointer;
}
button:hover { border-color: #a9b3ad; }
button:disabled { opacity: .55; cursor: not-allowed; }
textarea, input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 10px 12px;
  outline: none;
}
textarea:focus, input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(15, 122, 111, .12); }
h1, h2, p { margin: 0; }
.hidden { display: none !important; }

.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-box {
  width: min(380px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  border-radius: 10px;
  padding: 24px;
  display: grid;
  gap: 16px;
}
.login-box h1 { font-size: 26px; }
.login-box label { display: grid; gap: 7px; color: var(--muted); }
.login-box button { background: var(--accent); color: white; border-color: var(--accent); }
#login-error { min-height: 20px; color: var(--danger); }

.app {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
}
.shell-nav {
  border-right: 1px solid var(--line);
  background: #e7ece6;
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.brand {
  font-size: 20px;
  font-weight: 750;
  margin: 0 0 14px 4px;
}
.nav-item {
  text-align: left;
  background: transparent;
  border-color: transparent;
}
.nav-item.active {
  background: var(--panel);
  border-color: var(--line);
  box-shadow: 0 6px 18px rgba(17, 24, 39, .06);
}
.logout { margin-top: auto; color: var(--danger); }
.main {
  min-width: 0;
  padding: 18px;
}
.view { display: none; height: calc(100vh - 36px); }
.view.active { display: block; }

.chat-layout, .docs-layout {
  height: 100%;
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 16px;
}
.agent-list, .file-list, .editor-panel, .chat-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  min-height: 0;
}
.agent-list {
  overflow: auto;
  padding: 8px;
}
.agent-row {
  width: 100%;
  text-align: left;
  display: grid;
  gap: 4px;
  padding: 12px;
  border-color: transparent;
  background: transparent;
}
.agent-row.active { background: var(--panel-2); border-color: var(--line); }
.agent-row strong { font-size: 15px; }
.agent-row span, .panel-head p, .page-head p { color: var(--muted); font-size: 13px; }
.chat-panel, .editor-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
}
.panel-head, .page-head {
  min-height: 68px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.chat-history {
  overflow: auto;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.message {
  max-width: min(760px, 88%);
  padding: 12px 14px;
  border-radius: 10px;
  background: var(--panel-2);
  white-space: pre-wrap;
}
.message.user {
  align-self: flex-end;
  background: #dcece8;
}
.message.assistant { align-self: flex-start; }
.message .role { display: block; color: var(--muted); font-size: 12px; margin-bottom: 5px; }
.composer {
  border-top: 1px solid var(--line);
  padding: 12px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 120px;
  gap: 10px;
}
.composer textarea { resize: none; }
.composer button, #save-doc { background: var(--accent); border-color: var(--accent); color: #fff; }

.docs-layout > div:first-child {
  min-height: 0;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 12px;
}
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 10px;
}
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px;
  text-align: left;
  display: grid;
  gap: 8px;
}
.card.active { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(15, 122, 111, .12); }
.card strong { font-size: 16px; }
.card span { color: var(--muted); font-size: 13px; }
.file-list {
  padding: 8px;
  overflow: auto;
}
.file-row {
  width: 100%;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  text-align: left;
  border-color: transparent;
  background: transparent;
}
.file-row.active { background: var(--panel-2); border-color: var(--line); }
#doc-editor {
  border: 0;
  border-radius: 0;
  min-height: 0;
  height: 100%;
  resize: none;
  font: 14px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
#doc-editor:focus { box-shadow: none; }

#artifact-cats { margin: 16px 0; }
.artifact-items {
  display: grid;
  gap: 12px;
}
.artifact {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 16px;
  display: grid;
  gap: 10px;
}
.artifact h3 { margin: 0; font-size: 18px; }
.artifact dl {
  margin: 0;
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr);
  gap: 6px 12px;
}
.artifact dt { color: var(--muted); }
.artifact dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.artifact pre {
  margin: 0;
  white-space: pre-wrap;
  background: var(--panel-2);
  border-radius: 8px;
  padding: 12px;
}

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; grid-template-rows: auto minmax(0, 1fr); }
  .shell-nav { flex-direction: row; align-items: center; overflow-x: auto; }
  .brand { margin: 0 10px 0 0; white-space: nowrap; }
  .logout { margin-top: 0; margin-left: auto; }
  .view { height: calc(100vh - 86px); }
  .chat-layout, .docs-layout { grid-template-columns: 1fr; grid-template-rows: 220px minmax(0, 1fr); }
  .composer { grid-template-columns: 1fr; }
}
