:root {
  --bg: #0d0f14;
  --panel: #151821;
  --panel-2: #1c2030;
  --line: #2a2f40;
  --text: #e8eaf0;
  --muted: #9aa1b4;
  --accent: #7c6cff;
  --success: #22c55e;
  --warn: #f59e0b;
  --danger: #f87171;
  --radius: 12px;
  font-family: 'Inter', 'Noto Sans Myanmar', system-ui, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body { font-size: 15px; line-height: 1.6; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--danger); min-height: 1.2em; margin: 4px 0; font-size: 14px; }
.spacer { flex: 1; }

/* Buttons & inputs */
.btn {
  border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
  padding: 9px 14px; border-radius: 10px; font: inherit; font-weight: 500; cursor: pointer;
  min-height: 40px;
}
.btn:hover { border-color: #3b4258; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.success { background: #15803d; border-color: #15803d; color: #fff; }
.btn.ghost { background: transparent; }
.btn.full { width: 100%; }
input, textarea, select {
  width: 100%; background: var(--bg); color: var(--text); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 12px; font: inherit;
}
input:focus, textarea:focus, select:focus, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 6px; }
label.inline { display: inline-flex; align-items: center; gap: 8px; margin: 0; white-space: nowrap; }
label.inline select { width: auto; padding: 6px 8px; }
label.inline input[type=checkbox] { width: 18px; height: 18px; }

.badge { display: inline-block; font-size: 12px; padding: 2px 10px; border-radius: 999px; background: var(--panel-2); color: var(--muted); }
.badge.ok { background: #14532d; color: #bbf7d0; }
.badge.draft { background: #3b2f0b; color: #fde68a; }
.badge.warn { background: #3b2f0b; color: #fde68a; margin-top: 4px; }

.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 18px; }
.brand-dot { width: 14px; height: 14px; border-radius: 50%; background: conic-gradient(#22d3ee, #8b5cf6, #ec4899, #22d3ee); }

/* Login */
.login { min-height: 100%; display: grid; place-items: center; padding: 20px; }
.login-card { width: min(380px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 28px; }
.login-card .btn { width: 100%; margin-top: 8px; }

/* Layout */
.app { display: grid; grid-template-columns: 260px 1fr; height: 100vh; }
.sidebar { background: var(--panel); border-right: 1px solid var(--line); padding: 18px 14px; display: flex; flex-direction: column; gap: 14px; min-height: 0; }
.project-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; }
.project-list a { display: block; padding: 10px 12px; border-radius: 10px; color: var(--text); text-decoration: none; }
.project-list a:hover { background: var(--panel-2); }
.project-list a.active { background: var(--panel-2); outline: 1px solid var(--line); }
.project-list .stage { font-size: 12px; color: var(--muted); }
.sidebar-foot { display: flex; flex-direction: column; gap: 6px; }

.main { min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.empty { margin: auto; text-align: center; padding: 20px; }

.room { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.room-head { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; padding: 14px 20px; border-bottom: 1px solid var(--line); }
.room-head h1 { margin: 0; font-size: 20px; }
.stage-tabs { display: flex; flex-wrap: wrap; gap: 6px; }
.stage-tabs button { border: 1px solid var(--line); background: transparent; color: var(--muted); border-radius: 999px; padding: 6px 14px; font: inherit; font-size: 13px; cursor: pointer; min-height: 36px; }
.stage-tabs button.current { background: var(--accent); color: #fff; border-color: var(--accent); }
.stage-tabs button.done { color: #bbf7d0; border-color: #14532d; }
.stage-tabs button:disabled { opacity: .4; cursor: default; }

.room-body { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) minmax(320px, 42%); }
.chat { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--line); }
.feed { flex: 1; overflow-y: auto; padding: 18px 20px; display: flex; flex-direction: column; gap: 14px; }
.msg { display: grid; grid-template-columns: 36px 1fr; gap: 10px; }
.avatar { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; font-weight: 600; font-size: 14px; color: #fff; }
.msg .who { font-size: 13px; font-weight: 600; }
.msg .who .role { color: var(--muted); font-weight: 400; margin-left: 6px; }
.msg .who .round { color: var(--muted); font-weight: 400; margin-left: 6px; font-size: 12px; }
.msg .body { background: var(--panel); border: 1px solid var(--line); border-radius: 4px 12px 12px 12px; padding: 10px 14px; margin-top: 4px; overflow-wrap: anywhere; }
.msg.user .body { background: #231f45; border-color: #3a3270; }
.msg.system { grid-template-columns: 1fr; }
.msg.system .body { background: transparent; border: 1px dashed var(--line); color: var(--muted); font-size: 13px; border-radius: 10px; }
.typing { min-height: 26px; padding: 0 20px; color: var(--muted); font-size: 13px; }
.composer { border-top: 1px solid var(--line); padding: 12px 20px 16px; display: flex; flex-direction: column; gap: 10px; }
.composer-row { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }

.draft { display: flex; flex-direction: column; min-height: 0; }
.draft-head { display: flex; align-items: center; gap: 10px; padding: 14px 20px; border-bottom: 1px solid var(--line); }
.draft-head h2 { margin: 0; font-size: 16px; }
.draft-body { flex: 1; overflow-y: auto; padding: 16px 20px; }
.draft-editor { flex: 1; margin: 12px 20px 0; width: auto; font-family: ui-monospace, monospace; font-size: 13px; resize: none; }
.draft-actions { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px 20px 16px; border-top: 1px solid var(--line); justify-content: flex-end; }

.markdown h1 { font-size: 20px; margin: 0 0 12px; }
.markdown h2 { font-size: 17px; margin: 20px 0 8px; }
.markdown h3 { font-size: 15px; margin: 16px 0 6px; }
.markdown p, .markdown ul { margin: 6px 0; }
.markdown table { width: 100%; border-collapse: collapse; font-size: 13px; display: block; overflow-x: auto; }
.markdown th, .markdown td { border: 1px solid var(--line); padding: 6px 8px; vertical-align: top; text-align: left; }
.markdown th { background: var(--panel-2); }
.msg .body.markdown p:first-child { margin-top: 0; }
.msg .body.markdown p:last-child { margin-bottom: 0; }

/* Dialogs */
dialog { border: 1px solid var(--line); border-radius: 16px; background: var(--panel); color: var(--text); padding: 0; width: min(520px, 94vw); }
#settings-dialog { width: min(860px, 96vw); }
dialog::backdrop { background: rgba(0,0,0,.6); }
.dialog { padding: 22px; }
.dialog h2 { margin: 0 0 6px; }
.dialog h3 { margin: 18px 0 4px; font-size: 15px; }
.dialog-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 18px; }
.agent-editor { display: flex; flex-direction: column; gap: 10px; }
.agent-card { border: 1px solid var(--line); border-radius: 12px; padding: 12px; display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.agent-card .full { grid-column: 1 / -1; }
.agent-card .head { grid-column: 1 / -1; display: flex; align-items: center; gap: 10px; font-weight: 600; }
.agent-card .test { margin-left: auto; font-size: 12px; font-weight: 400; }
.agent-card .test.ok { color: #86efac; }
.agent-card .test.bad { color: var(--danger); }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--panel-2); border: 1px solid var(--line); padding: 10px 16px; border-radius: 10px; opacity: 0; pointer-events: none; transition: opacity .2s; max-width: 90vw; }
.toast.show { opacity: 1; }

/* Phone / narrow screens */
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; height: auto; min-height: 100vh; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--line); }
  .project-list { max-height: 180px; }
  .room-body { grid-template-columns: 1fr; }
  .chat { border-right: 0; border-bottom: 1px solid var(--line); }
  .feed { max-height: 60vh; }
  .draft-body { max-height: 70vh; }
  .agent-card { grid-template-columns: 1fr; }
}
