:root {
  --dax-bg: #0d0d0d;
  --dax-surface: #161616;
  --dax-surface-2: #1f1f23;
  --dax-line: #2a2a30;
  --dax-line-soft: #1c1c20;
  --dax-text: #ECECF1;
  --dax-text-soft: #B5B5BD;
  --dax-text-mute: #7C7C85;
  --dax-blue: #3B82F6;
  --dax-blue-deep: #1F3864;
  --dax-blue-soft: rgba(59, 130, 246, 0.15);
  --dax-warn: #FBBF24;
  --dax-error: #F87171;
}

* { box-sizing: border-box; }

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

html, body {
  margin: 0;
  height: 100%;
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  color: var(--dax-text);
  background: var(--dax-bg);
}

body { display: flex; flex-direction: column; }

/* ---------- Login page ---------- */

.login-body { background: var(--dax-bg); }

.login-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 28px;
}

.dakona-wordmark { height: 22px; opacity: 0.95; }

.env-badge {
  font-size: 11px;
  letter-spacing: 0.06em;
  color: var(--dax-warn);
  background: rgba(251, 191, 36, 0.08);
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid rgba(251, 191, 36, 0.25);
}

.login-main {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-card {
  background: var(--dax-surface);
  border: 1px solid var(--dax-line);
  border-radius: 18px;
  padding: 42px 48px 36px;
  text-align: center;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.45);
}

.dax-avatar {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  object-fit: cover;
  margin-bottom: 18px;
  background: var(--dax-surface-2);
}

.brand-name {
  font-size: 32px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--dax-text);
  background: linear-gradient(135deg, #FFFFFF 0%, var(--dax-blue) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 12px;
}

.brand-strip {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 11px;
  color: var(--dax-text-mute);
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--dax-line);
  padding: 6px 14px;
  border-radius: 999px;
  margin-bottom: 28px;
}

.brand-strip strong { color: var(--dax-text-soft); font-weight: 600; }
.brand-strip-divider { opacity: 0.4; }

.welcome {
  font-size: 24px;
  font-weight: 600;
  margin: 0 0 22px;
  color: var(--dax-text);
}

.ms-signin {
  display: inline-block;
  background: #fff;
  padding: 0;
  border-radius: 4px;
  text-decoration: none;
  transition: opacity 0.15s ease;
  border: 0;
}

.ms-signin:hover { opacity: 0.92; }

.ms-signin img {
  display: block;
  height: 41px;
  width: auto;
}

.login-foot {
  margin: 22px 0 0;
  font-size: 12px;
  color: var(--dax-text-mute);
}

/* ---------- Chat page ---------- */

.chat-body { background: var(--dax-bg); }

.chat-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 22px;
  background: var(--dax-surface);
  color: var(--dax-text);
  border-bottom: 1px solid var(--dax-line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--dax-surface-2);
}

.brand-mark {
  font-weight: 700;
  font-size: 18px;
  letter-spacing: 0.06em;
}

.brand-tag {
  font-size: 10px;
  color: var(--dax-warn);
  background: rgba(251, 191, 36, 0.1);
  padding: 3px 8px;
  border-radius: 10px;
  border: 1px solid rgba(251, 191, 36, 0.2);
  letter-spacing: 0.08em;
}

.user-area { display: flex; align-items: center; gap: 16px; }
.user { font-size: 13px; color: var(--dax-text-soft); }
.signout {
  font-size: 12px;
  color: var(--dax-text-mute);
  text-decoration: none;
  padding: 6px 12px;
  border-radius: 6px;
  border: 1px solid var(--dax-line);
}
.signout:hover { color: var(--dax-text); border-color: var(--dax-blue); }

.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

#webchat {
  flex: 1;
  min-height: 0;
  background: var(--dax-bg);
}

.status {
  padding: 10px 18px;
  background: rgba(251, 191, 36, 0.1);
  color: var(--dax-warn);
  border-top: 1px solid rgba(251, 191, 36, 0.25);
  font-size: 13px;
}

/* ---------- Sidebar layout ---------- */

:root {
  --sidebar-w: 260px;
}

body.chat-body {
  display: flex;
  flex-direction: row;
  height: 100%;
  overflow: hidden;
}

.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--dax-surface);
  border-right: 1px solid var(--dax-line);
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  transition: transform 0.22s ease, width 0.22s ease;
  z-index: 20;
  flex-shrink: 0;
}

.sidebar.collapsed {
  width: 0;
  min-width: 0;
  transform: translateX(-260px);
  border-right: none;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 14px 10px;
  border-bottom: 1px solid var(--dax-line-soft);
  flex-shrink: 0;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  overflow: hidden;
}

.sidebar-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.sidebar-brand-block {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

.sidebar-brand-name {
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0.04em;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 6px;
}

.sidebar-brand-sub {
  font-size: 10px;
  color: var(--dax-text-mute);
  white-space: nowrap;
  letter-spacing: 0.01em;
}

.new-chat-btn {
  background: transparent;
  border: 1px solid var(--dax-line);
  color: var(--dax-text-soft);
  border-radius: 7px;
  padding: 5px 7px;
  cursor: pointer;
  display: flex;
  align-items: center;
  flex-shrink: 0;
  transition: border-color 0.15s, color 0.15s;
}
.new-chat-btn:hover { border-color: var(--dax-blue); color: var(--dax-blue); }

.sidebar-search-wrap {
  padding: 8px 10px 4px;
  flex-shrink: 0;
}
.conv-search {
  width: 100%;
  box-sizing: border-box;
  background: var(--dax-surface-2);
  border: 1px solid var(--dax-line);
  border-radius: 6px;
  color: var(--dax-text);
  font-size: 12px;
  padding: 6px 10px;
  outline: none;
  transition: border-color 0.15s;
}
.conv-search::placeholder { color: var(--dax-text-mute); }
.conv-search:focus { border-color: var(--dax-blue); }

.sidebar-conversations {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}
.sidebar-conversations::-webkit-scrollbar { width: 4px; }
.sidebar-conversations::-webkit-scrollbar-track { background: transparent; }
.sidebar-conversations::-webkit-scrollbar-thumb { background: var(--dax-line); border-radius: 4px; }

.conv-group-label {
  font-size: 10px;
  letter-spacing: 0.08em;
  color: var(--dax-text-mute);
  padding: 12px 14px 4px;
  text-transform: uppercase;
}

.conv-item {
  display: flex;
  align-items: center;
  gap: 0;
  padding: 7px 14px;
  cursor: pointer;
  border-radius: 7px;
  margin: 1px 6px;
  transition: background 0.12s;
  min-height: 36px;
}
.conv-item:hover { background: var(--dax-surface-2); }
.conv-item.active { background: var(--dax-blue-soft); }

.conv-item-inner {
  flex: 1;
  min-width: 0;
}

.conv-title {
  font-size: 13px;
  color: var(--dax-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.35;
}
.conv-item.active .conv-title { color: var(--dax-blue); }

.conv-time {
  font-size: 11px;
  color: var(--dax-text-mute);
  margin-top: 1px;
}

.conv-loading {
  font-size: 12px;
  color: var(--dax-text-mute);
  padding: 16px 14px;
}

.conv-empty {
  font-size: 12px;
  color: var(--dax-text-mute);
  padding: 16px 14px;
  line-height: 1.5;
}

.sidebar-footer {
  border-top: 1px solid var(--dax-line-soft);
  padding: 10px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.sidebar-user {
  font-size: 11px;
  color: var(--dax-text-mute);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 140px;
}

.sidebar-signout {
  font-size: 11px;
  flex-shrink: 0;
}

/* ---------- Chat shell (right side) ---------- */

.chat-shell {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  min-width: 0;
  overflow: hidden;
}

.chat-topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 18px;
  background: var(--dax-surface);
  border-bottom: 1px solid var(--dax-line);
  flex-shrink: 0;
}

.sidebar-toggle {
  background: transparent;
  border: none;
  color: var(--dax-text-mute);
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  flex-shrink: 0;
  transition: color 0.15s;
}
.sidebar-toggle:hover { color: var(--dax-text); }

.topbar-title {
  flex: 1;
  font-size: 14px;
  font-weight: 500;
  color: var(--dax-text-soft);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

.topbar-new-chat {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--dax-text-mute);
  background: transparent;
  border: 1px solid var(--dax-line);
  border-radius: 7px;
  padding: 5px 10px;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}
.topbar-new-chat:hover { border-color: var(--dax-blue); color: var(--dax-blue); }

/* Keep chat-main and signout from original, adjust for flex layout */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

#webchat {
  flex: 1;
  min-height: 0;
  background: var(--dax-bg);
}

/* ---------- History view ---------- */

.history-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  border-bottom: 1px solid var(--dax-line);
  flex-shrink: 0;
}

.history-label {
  font-size: 12px;
  color: var(--dax-text-mute);
  font-style: italic;
}

.history-continue-btn {
  font-size: 12px;
  background: var(--dax-blue);
  color: #fff;
  border: none;
  border-radius: 7px;
  padding: 6px 14px;
  cursor: pointer;
  transition: opacity 0.15s;
}
.history-continue-btn:hover { opacity: 0.85; }

.history-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.history-messages::-webkit-scrollbar { width: 4px; }
.history-messages::-webkit-scrollbar-thumb { background: var(--dax-line); border-radius: 4px; }

.history-msg {
  max-width: 72%;
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 14px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}
.history-msg.user {
  align-self: flex-end;
  background: var(--dax-blue);
  color: #fff;
  border-bottom-right-radius: 3px;
}
.history-msg.assistant {
  align-self: flex-start;
  background: var(--dax-surface-2);
  color: var(--dax-text);
  border: 1px solid var(--dax-line);
  border-bottom-left-radius: 3px;
}

/* ---------- WebChat overrides — document style ---------- */

/* Full-width message rows */
#webchat .webchat__stacked-layout__content { max-width: 100% !important; }
#webchat .webchat__bubble { max-width: 100% !important; }

/* Bot message text — larger, more readable */
#webchat .webchat__bubble__content {
  font-size: 15px !important;
  line-height: 1.65 !important;
  padding: 4px 0 !important;
}

/* Bot messages: no background, no border — clean document look */
#webchat .webchat__bubble:not(.webchat__bubble--from-user) {
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
}

/* User message — pill style */
#webchat .webchat__bubble--from-user {
  border-radius: 18px !important;
  max-width: 680px !important;
}

/* Send box — LibreChat floating pill style */
#webchat .webchat__send-box {
  background: var(--dax-bg) !important;
  padding: 6px 14px 10px !important;
  border-top: none !important;
}
#webchat .webchat__send-box__main {
  border-radius: 12px !important;
  border: 1px solid var(--dax-line) !important;
  background: var(--dax-surface) !important;
  box-shadow: 0 2px 8px rgba(0,0,0,0.35) !important;
  overflow: hidden;
}

/* Typing indicator */
#webchat .webchat__typing-indicator { opacity: 0.5; }

/* Markdown in bot messages */
#webchat .webchat__bubble__content p { margin: 0 0 10px; }
#webchat .webchat__bubble__content p:last-child { margin-bottom: 0; }
#webchat .webchat__bubble__content ul,
#webchat .webchat__bubble__content ol { padding-left: 20px; margin: 6px 0 10px; }
#webchat .webchat__bubble__content code {
  font-family: "Cascadia Code", "Fira Code", monospace;
  font-size: 13px;
  background: var(--dax-surface-2);
  border: 1px solid var(--dax-line);
  border-radius: 4px;
  padding: 1px 5px;
}
#webchat .webchat__bubble__content pre code {
  display: block;
  padding: 12px;
  overflow-x: auto;
  border-radius: 8px;
}

/* History view — markdown rendered */
.history-msg.assistant { background: transparent; border: none; padding: 4px 0; }
.history-msg.assistant p { margin: 0 0 10px; }
.history-msg.assistant p:last-child { margin-bottom: 0; }
.history-msg.assistant code {
  font-family: "Cascadia Code", "Fira Code", monospace;
  font-size: 13px;
  background: var(--dax-surface-2);
  border: 1px solid var(--dax-line);
  border-radius: 4px;
  padding: 1px 5px;
}

/* ---------- Sidebar overlay (mobile) ---------- */

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 19;
}

/* ---------- Splash screen ---------- */

.chat-main { position: relative; }

.chat-splash {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 72px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  pointer-events: none;
  transition: opacity 0.3s ease;
  z-index: 2;
}

.chat-splash.hidden {
  opacity: 0;
  pointer-events: none;
}

.splash-avatar {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--dax-surface-2);
  margin-bottom: 4px;
}

.splash-title {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: 0.05em;
  background: linear-gradient(135deg, #FFFFFF 0%, var(--dax-blue) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.splash-tagline {
  font-size: 13px;
  color: var(--dax-text-soft);
  letter-spacing: 0.02em;
  font-weight: 500;
}

.splash-hint {
  font-size: 12px;
  color: var(--dax-text-mute);
}

/* ---------- Input disclaimer ---------- */

.input-disclaimer {
  text-align: center;
  font-size: 11px;
  color: var(--dax-text-mute);
  padding: 3px 0 6px;
  margin: 0;
  background: var(--dax-bg);
  flex-shrink: 0;
}

/* ---------- Mobile ---------- */

@media (max-width: 680px) {
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100%;
    transform: translateX(-100%);
    width: var(--sidebar-w) !important;
    min-width: var(--sidebar-w) !important;
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .sidebar.collapsed {
    transform: translateX(-100%);
    width: var(--sidebar-w) !important;
    min-width: var(--sidebar-w) !important;
    border-right: 1px solid var(--dax-line);
  }
  .sidebar-overlay.visible { display: block; }
  .chat-shell { width: 100%; }
  .topbar-new-chat span { display: none; }
}
