:root {
  --bg: #1e1f22;
  --sidebar-bg: #17181b;
  --chat-bg: #222327;
  --surface: #2b2d31;
  --surface-2: #383a40;
  --text: #dbdee1;
  --text-dim: #949ba4;
  --accent: #5865f2;
  --accent-hover: #4752c4;
  --mine: #5865f2;
  --mine-border: #4a54d8;
  --other: #383a40;
  --other-border: #2f3136;
  --ok: #23a55a;
  --warn: #f0b232;
  --err: #f23f43;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: "Segoe UI", "Malgun Gothic", "Apple SD Gothic Neo", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

#app {
  display: flex;
  height: 100vh;
}

/* ---------- Sidebar ---------- */
#sidebar {
  width: 260px;
  flex: 0 0 260px;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  border-right: 1px solid #2f3136;
}

.sidebar-header {
  padding: 18px 16px 12px;
  border-bottom: 1px solid #2f3136;
}
.logo {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: 0.5px;
  color: #fff;
}
.logo-sub {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 2px;
}

.sidebar-section-title {
  padding: 16px 16px 6px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-dim);
}

#canvas-list {
  list-style: none;
  overflow-y: auto;
  flex: 1;
  padding: 0 8px;
}

.canvas-card {
  padding: 12px;
  margin-bottom: 8px;
  border-radius: 8px;
  background: var(--surface);
  border: 1px solid transparent;
  cursor: default;
}
.canvas-card.painting { border-color: var(--warn); }
.canvas-card.error   { border-color: var(--err); }
.canvas-card.ok      { border-color: var(--ok); }

.canvas-name {
  font-weight: 700;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.canvas-meta {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 4px;
}
.canvas-prompt {
  font-size: 12px;
  color: var(--text);
  margin-top: 6px;
  word-break: break-word;
  line-height: 1.35;
}
.canvas-status {
  margin-top: 8px;
  font-size: 11px;
  font-weight: 600;
}

.canvas-empty {
  color: var(--text-dim);
  font-size: 13px;
  padding: 12px;
}

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid #2f3136;
}
.badge {
  font-size: 11px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
}
.badge-ok      { background: rgba(35,165,90,.2);  color: var(--ok); }
.badge-warn    { background: rgba(240,178,50,.2); color: var(--warn); }
.badge-err     { background: rgba(242,63,67,.2);  color: var(--err); }
.badge-unknown { background: rgba(148,155,164,.2); color: var(--text-dim); }

/* ---------- Chat ---------- */
#chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--chat-bg);
  min-width: 0;
}

#chat-header {
  padding: 14px 22px;
  border-bottom: 1px solid #2f3136;
  background: var(--surface);
}
.chat-title { font-weight: 700; font-size: 16px; }
.chat-subtitle { font-size: 12px; color: var(--text-dim); margin-top: 2px; }

#messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px 22px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.message {
  display: flex;
  flex-direction: column;
  margin-bottom: 8px;
}
.message.user { align-items: flex-end; }
.message.assistant, .message.system { align-items: flex-start; }

.msg-author {
  font-size: 11px;
  color: var(--text-dim);
  margin-bottom: 3px;
  padding: 0 4px;
}

.bubble {
  max-width: 78%;
  padding: 9px 14px;
  border-radius: 14px;
  line-height: 1.5;
  font-size: 14px;
  white-space: pre-wrap;
  word-break: break-word;
}
.bubble img.paint-img {
  display: block;
  max-width: 280px;
  max-height: 280px;
  border-radius: 10px;
  margin-top: 6px;
}
.bubble a { color: #9aa5ff; }
.message.user .bubble {
  background: var(--mine);
  border: 1px solid var(--mine-border);
  border-top-right-radius: 4px;
}
.message.assistant .bubble,
.message.system .bubble {
  background: var(--other);
  border: 1px solid var(--other-border);
  border-top-left-radius: 4px;
}

.message.assistant.typing .bubble {
  color: var(--text-dim);
  font-style: italic;
}

.error-text { color: var(--err); }

/* ---------- Input ---------- */
#input-area {
  padding: 14px 22px 18px;
  background: var(--chat-bg);
  border-top: 1px solid #2f3136;
}
.input-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}
#message-input {
  flex: 1;
  background: var(--surface);
  border: 1px solid #2f3136;
  border-radius: 10px;
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  padding: 11px 14px;
  resize: none;
  min-height: 42px;
  max-height: 140px;
  outline: none;
}
#message-input:focus { border-color: var(--accent); }
#send-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-weight: 700;
  font-size: 14px;
  padding: 11px 20px;
  cursor: pointer;
}
#send-btn:hover { background: var(--accent-hover); }
#send-btn:disabled { opacity: .6; cursor: not-allowed; }

@media (max-width: 720px) {
  #sidebar { display: none; }
}