:root {
  --bg: #0f1620;
  --panel: #161f2b;
  --panel-alt: #1c2734;
  --border: #26323f;
  --text: #e7edf3;
  --text-dim: #8ea0b3;
  --accent: #e0a63a;      /* gold — nod to trading/forex */
  --accent-dim: #b5842a;
  --bubble-in: #1c2734;
  --bubble-out: #2b3a2c;
  --danger: #d9534f;
  --radius: 10px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Inter", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; background: var(--bg); color: var(--text); }
body { overflow: hidden; }

.hidden { display: none !important; }

.screen { height: 100vh; height: 100dvh; width: 100%; }

/* ---------- Login ---------- */
#login-screen { display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 32px 28px; width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 14px;
}
.login-brand { text-align: center; margin-bottom: 8px; }
.brand-mark {
  display: inline-flex; align-items: center; justify-content: center;
  width: 48px; height: 48px; border-radius: 12px; background: var(--accent); color: #1a1300;
  font-weight: 800; font-size: 22px; margin-bottom: 10px;
}
.brand-mark.small { width: 32px; height: 32px; font-size: 15px; border-radius: 9px; }
.login-brand h1 { font-size: 19px; margin: 4px 0; }
.login-brand p { font-size: 13px; color: var(--text-dim); margin: 0; }
.login-card label { font-size: 13px; color: var(--text-dim); display: flex; flex-direction: column; gap: 6px; }
.login-card input {
  background: var(--panel-alt); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 10px 12px; font-size: 14px;
}
.login-card button[type="submit"] {
  margin-top: 6px; background: var(--accent); color: #1a1300; border: none;
  border-radius: 8px; padding: 11px; font-weight: 700; font-size: 14px; cursor: pointer;
}
.error-text { color: var(--danger); font-size: 13px; min-height: 16px; margin: 0; }

/* ---------- App layout ---------- */
#app-screen { display: flex; }

.sidebar {
  width: 340px; min-width: 300px; background: var(--panel); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; height: 100%;
}
.sidebar-header {
  display: flex; align-items: center; gap: 8px; padding: 12px; border-bottom: 1px solid var(--border);
}
.sidebar-header input {
  flex: 1; background: var(--panel-alt); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 9px 12px; font-size: 13px;
}
.icon-btn {
  background: var(--panel-alt); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; width: 36px; height: 36px; cursor: pointer; font-size: 15px;
}

.account-filters {
  display: flex; gap: 6px; padding: 10px 12px; overflow-x: auto; border-bottom: 1px solid var(--border);
}
.chip {
  flex-shrink: 0; background: var(--panel-alt); border: 1px solid var(--border); color: var(--text-dim);
  padding: 6px 12px; border-radius: 999px; font-size: 12px; cursor: pointer;
}
.chip.active { background: var(--accent); color: #1a1300; border-color: var(--accent); font-weight: 700; }

.conversation-list { flex: 1; overflow-y: auto; }
.conv-item {
  display: flex; gap: 10px; padding: 12px; border-bottom: 1px solid var(--border); cursor: pointer;
  align-items: flex-start;
}
.conv-item:hover, .conv-item.active { background: var(--panel-alt); }
.conv-avatar {
  width: 40px; height: 40px; border-radius: 50%; background: var(--panel-alt); border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center; font-weight: 700; flex-shrink: 0;
}
.conv-main { flex: 1; min-width: 0; }
.conv-top-row { display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.conv-name { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-time { font-size: 11px; color: var(--text-dim); flex-shrink: 0; }
.conv-preview {
  font-size: 12.5px; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  margin-top: 2px;
}
.conv-badges { display: flex; gap: 6px; align-items: center; margin-top: 4px; }
.account-badge {
  font-size: 10.5px; padding: 2px 7px; border-radius: 999px; font-weight: 700; color: #0b0d10;
}
.unread-dot {
  background: var(--accent); color: #1a1300; font-size: 11px; font-weight: 800;
  border-radius: 999px; min-width: 18px; height: 18px; display: flex; align-items: center; justify-content: center;
  padding: 0 5px;
}
.pin-icon { font-size: 11px; }

/* ---------- Chat pane ---------- */
.chat-pane { flex: 1; display: flex; flex-direction: column; height: 100%; }
.chat-empty { flex: 1; display: flex; align-items: center; justify-content: center; color: var(--text-dim); font-size: 14px; }
.chat-active { flex: 1; display: flex; flex-direction: column; min-height: 0; }

.chat-header {
  display: flex; justify-content: space-between; align-items: center; padding: 14px 18px;
  border-bottom: 1px solid var(--border); background: var(--panel);
}
.chat-header h2 { font-size: 16px; margin: 0 0 4px 0; }
.chat-actions { display: flex; gap: 8px; align-items: center; }
#tag-select {
  background: var(--panel-alt); color: var(--text); border: 1px solid var(--border); border-radius: 8px;
  padding: 7px 10px; font-size: 12.5px;
}

.chat-messages { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 10px; }
.bubble {
  max-width: 66%; padding: 9px 13px; border-radius: 14px; font-size: 14px; line-height: 1.45;
  word-wrap: break-word; white-space: pre-wrap;
}
.bubble.in { align-self: flex-start; background: var(--bubble-in); border-bottom-left-radius: 4px; }
.bubble.out { align-self: flex-end; background: var(--bubble-out); border-bottom-right-radius: 4px; }
.bubble-meta { font-size: 10.5px; color: var(--text-dim); margin-top: 4px; }

.chat-input-row {
  display: flex; align-items: flex-end; gap: 8px; padding: 12px 14px; border-top: 1px solid var(--border);
  background: var(--panel);
}
#message-input {
  flex: 1; resize: none; max-height: 120px; background: var(--panel-alt); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; font-size: 14px; font-family: inherit;
}
.send-btn {
  background: var(--accent); color: #1a1300; border: none; border-radius: 10px; padding: 0 18px; height: 40px;
  font-weight: 700; cursor: pointer; font-size: 13.5px;
}

/* ---------- Canned modal ---------- */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.55); display: flex; align-items: center; justify-content: center;
  padding: 16px; z-index: 50;
}
.modal-box {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  width: 100%; max-width: 420px; max-height: 80vh; display: flex; flex-direction: column; padding: 16px;
}
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.canned-list { overflow-y: auto; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.canned-item {
  background: var(--panel-alt); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; cursor: pointer;
}
.canned-item b { font-size: 13px; }
.canned-item p { font-size: 12.5px; color: var(--text-dim); margin: 4px 0 0 0; }
.secondary-btn {
  margin-top: 12px; background: var(--panel-alt); border: 1px dashed var(--border); color: var(--text-dim);
  border-radius: 8px; padding: 10px; cursor: pointer; font-size: 13px;
}

.back-btn-mobile { display: none; }

/* ---------- Mobile ---------- */
@media (max-width: 760px) {
  #app-screen { position: relative; }
  .sidebar { width: 100%; min-width: 0; position: absolute; inset: 0; z-index: 5; }
  .chat-pane { position: absolute; inset: 0; z-index: 4; }
  .sidebar.hide-on-mobile { display: none; }
  .bubble { max-width: 82%; }
  .back-btn-mobile { display: inline-flex; align-items: center; justify-content: center; margin-right: 10px; }
}
