:root {
  --bg: #0c0d0f;
  --bg-sidebar: #111315;
  --bg-elevated: #17191c;
  --bg-hover: #1d2024;
  --border: #26292e;
  --text: #e7e9ec;
  --text-dim: #9aa0a6;
  --text-faint: #6b7076;
  --accent: #d97757;   /* warm ember accent */
  --accent-hover: #e08a6d;
  --danger: #e05252;
  --radius: 10px;
  --sidebar-w: 290px;
  --font: "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.55;
}

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

/* ---------- Sidebar ---------- */
#sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}
.sidebar-header { padding: 14px; border-bottom: 1px solid var(--border); }
.btn-primary {
  width: 100%;
  background: var(--accent);
  color: #111;
  border: none;
  padding: 10px 12px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background .15s;
}
.btn-primary:hover { background: var(--accent-hover); }

.convo-list { flex: 1; overflow-y: auto; padding: 8px; }
.convo-item {
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  margin-bottom: 2px;
  transition: background .12s;
}
.convo-item:hover { background: var(--bg-hover); }
.convo-item.active { background: var(--bg-elevated); border: 1px solid var(--border); }
.convo-item .convo-title {
  font-size: 13.5px;
  font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.convo-item .convo-meta {
  font-size: 11.5px; color: var(--text-faint); margin-top: 3px;
  display: flex; gap: 8px; align-items: center;
}
.convo-item .mode-tag {
  font-size: 10px; padding: 1px 6px; border-radius: 4px;
  background: var(--bg-hover); color: var(--text-dim);
  text-transform: uppercase; letter-spacing: .4px;
}
.convo-item .mode-tag.cowork { color: var(--accent); }
.empty-convos { color: var(--text-faint); font-size: 13px; text-align: center; padding: 20px 10px; }

.sidebar-footer {
  padding: 12px 14px; border-top: 1px solid var(--border);
  font-size: 11px; color: var(--text-faint);
}

/* ---------- Main ---------- */
#main { flex: 1; display: flex; flex-direction: column; min-width: 0; position: relative; }
.chat-area { flex: 1; overflow-y: auto; display: flex; flex-direction: column; }
.empty-state {
  margin: auto; text-align: center; color: var(--text-dim);
  display: flex; flex-direction: column; align-items: center; gap: 8px;
}
.enigma-logo {
  font-size: 46px; width: 84px; height: 84px;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: 22px; color: var(--accent);
}
.empty-state h1 { font-size: 24px; color: var(--text); font-weight: 650; margin-top: 8px; }
.empty-state p { font-size: 14px; }

.messages { padding: 28px 0 40px; flex: 1; }
.message { max-width: 760px; margin: 0 auto 24px; padding: 0 24px; }
.message .role-label { font-size: 12px; text-transform: uppercase; letter-spacing: .6px; color: var(--text-faint); margin-bottom: 6px; font-weight: 600; }
.message.user .role-label { color: var(--accent); }
.message.assistant .content { background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 18px; white-space: pre-wrap; word-wrap: break-word; }
.message.user .content { white-space: pre-wrap; word-wrap: break-word; }
.message .content p { margin: 0 0 10px; }
.message .content p:last-child { margin-bottom: 0; }
.message.typing .content::after {
  content: ""; display: inline-block; width: 6px; height: 14px;
  background: var(--accent); margin-left: 3px; vertical-align: text-bottom;
  animation: blink 1s steps(2) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* ---------- Input ---------- */
.input-area { border-top: 1px solid var(--border); padding: 12px 24px 14px; background: var(--bg); }
.input-bar {
  max-width: 760px; margin: 0 auto;
  display: flex; align-items: flex-end; gap: 10px;
  background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: 16px; padding: 10px 12px;
}
.chat-input {
  flex: 1; background: transparent; border: none; outline: none;
  color: var(--text); font-family: var(--font); font-size: 15px;
  resize: none; max-height: 200px; line-height: 1.5; padding-top: 4px;
}
.chat-input::placeholder { color: var(--text-faint); }
.model-picker {
  background: var(--bg); color: var(--text-dim);
  border: 1px solid var(--border); border-radius: 8px;
  font-size: 12.5px; padding: 7px 8px; max-width: 190px; cursor: pointer;
}
.btn-send {
  width: 36px; height: 36px; border-radius: 10px; border: none;
  background: var(--accent); color: #111; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: opacity .15s; flex-shrink: 0;
}
.btn-send:hover:not(:disabled) { background: var(--accent-hover); }
.btn-send:disabled { opacity: .4; cursor: not-allowed; }
.input-footer {
  max-width: 760px; margin: 8px auto 0;
  display: flex; gap: 10px; font-size: 12px; color: var(--text-faint);
}
.mode-badge, .workspace-badge {
  background: var(--bg-elevated); border: 1px solid var(--border);
  padding: 3px 10px; border-radius: 20px;
}
.mode-badge.cowork { color: var(--accent); border-color: var(--accent); }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.6);
  display: flex; align-items: center; justify-content: center; z-index: 100;
}
.modal {
  width: 520px; max-width: 94vw; background: var(--bg-elevated);
  border: 1px solid var(--border); border-radius: 16px; overflow: hidden;
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.modal-header h2 { font-size: 18px; }
.btn-close { background: none; border: none; color: var(--text-dim); font-size: 22px; cursor: pointer; line-height: 1; }
.modal-body { padding: 18px 20px; }
.modal-desc { color: var(--text-dim); margin-bottom: 14px; font-size: 14px; }
.mode-cards { display: flex; gap: 12px; margin-bottom: 14px; }
.mode-card {
  flex: 1; padding: 16px; border: 1px solid var(--border); border-radius: 12px;
  cursor: pointer; transition: border-color .15s, background .15s;
  background: var(--bg);
}
.mode-card:hover { border-color: var(--text-dim); }
.mode-card.selected { border-color: var(--accent); background: var(--bg-hover); }
.mode-icon { font-size: 24px; margin-bottom: 8px; }
.mode-name { font-weight: 600; margin-bottom: 4px; }
.mode-desc { font-size: 12.5px; color: var(--text-faint); }
.cowork-options { margin-bottom: 14px; }
.cowork-options label, .model-select-block label {
  display: block; font-size: 12.5px; color: var(--text-dim); margin-bottom: 6px;
}
.input-field {
  width: 100%; background: var(--bg); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text); padding: 9px 11px; font-size: 14px; outline: none;
}
.input-field:focus { border-color: var(--accent); }
.model-select-block { margin-top: 14px; }
.modal-footer {
  display: flex; justify-content: flex-end; gap: 10px; padding: 14px 20px;
  border-top: 1px solid var(--border);
}
.btn-secondary {
  background: var(--bg); color: var(--text); border: 1px solid var(--border);
  padding: 9px 16px; border-radius: 8px; font-size: 14px; cursor: pointer;
}
.btn-secondary:hover { background: var(--bg-hover); }
.modal-footer .btn-primary { width: auto; padding: 9px 20px; }

.login-modal { width: 420px; }
.login-error { color: var(--danger); font-size: 13px; margin-top: 10px; min-height: 16px; }

/* Scrollbars */
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 6px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-faint); }
::-webkit-scrollbar-track { background: transparent; }
