﻿/* ── Reset & base ────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --orange:        #00a767;
  --orange-dark:   #008f58;
  --orange-pale:   #e6f7f1;
  --navy:          #1e293b;
  --navy-light:    #334155;
  --slate:         #64748b;
  --slate-pale:    #f1f5f9;
  --white:         #ffffff;
  --sidebar-bg:    #0f172a;
  --sidebar-bd:    rgba(255,255,255,.07);
  --bubble-ai:     #f8fafc;
  --bubble-user:   linear-gradient(135deg, #00a767 0%, #008f58 100%);
  --shadow:        0 1px 4px rgba(0,0,0,.10);
  --radius:        14px;
  --font:          -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

html, body {
  height: 100%;
  overflow: hidden;
  font-family: var(--font);
  background: var(--sidebar-bg);
  color: var(--navy);
}

/* ── App shell ───────────────────────────────────────────────────────────── */
.app-shell {
  display: flex;
  flex-direction: row;
  height: 100dvh;
  width: 100%;
  overflow: hidden;
}

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
.sidebar {
  width: 260px;
  min-width: 260px;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  flex-shrink: 0;
  transition: width .28s ease, min-width .28s ease;
  position: relative;
  z-index: 100;
}

/* Collapse on desktop */
.app-shell.sidebar-collapsed .sidebar {
  width: 0;
  min-width: 0;
}

/* Mobile overlay */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.55);
  z-index: 99;
  backdrop-filter: blur(2px);
}

/* Sidebar header */
.sidebar-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 16px 14px;
  border-bottom: 1px solid var(--sidebar-bd);
  white-space: nowrap;
  overflow: hidden;
  flex-shrink: 0;
}

.sidebar-logo {
  width: 38px;
  height: 38px;
  font-size: 1.2rem;
  flex-shrink: 0;
}

.sidebar-brand {
  font-size: .875rem;
  font-weight: 700;
  color: var(--white);
  letter-spacing: .01em;
}

/* New chat button */
.new-chat-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 12px 12px 4px;
  padding: 10px 14px;
  background: var(--orange);
  color: var(--white);
  border: none;
  border-radius: 10px;
  font-size: .875rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .2s;
  white-space: nowrap;
  flex-shrink: 0;
}
.new-chat-btn:hover { background: var(--orange-dark); }

/* Sessions */
.sessions-label {
  font-size: .67rem;
  font-weight: 700;
  color: #475569;
  letter-spacing: .1em;
  text-transform: uppercase;
  padding: 14px 16px 6px;
  white-space: nowrap;
  flex-shrink: 0;
}

.sessions-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px;
}

.sessions-empty {
  font-size: .8rem;
  color: #475569;
  text-align: center;
  padding: 20px 12px;
  white-space: normal;
}

.session-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 8px;
  cursor: pointer;
  color: #94a3b8;
  transition: background .15s, color .15s;
  margin-bottom: 2px;
  position: relative;
  overflow: hidden;
}
.session-item:hover { background: rgba(255,255,255,.07); color: var(--white); }
.session-item.active { background: rgba(0,167,103,.15); color: var(--white); }
.session-item.active::before {
  content: '';
  position: absolute;
  left: 0; top: 6px; bottom: 6px;
  width: 3px;
  background: var(--orange);
  border-radius: 0 3px 3px 0;
}

.session-icon { font-size: .9rem; flex-shrink: 0; }

.session-info { flex: 1; overflow: hidden; min-width: 0; }

.session-title {
  font-size: .82rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: inherit;
}

.session-time {
  font-size: .68rem;
  color: #475569;
  margin-top: 2px;
}
.session-item.active .session-time { color: #94a3b8; }

.session-del {
  background: none;
  border: none;
  color: transparent;
  font-size: .8rem;
  cursor: pointer;
  padding: 3px 6px;
  border-radius: 4px;
  flex-shrink: 0;
  transition: color .15s, background .15s;
  line-height: 1;
}
.session-item:hover .session-del { color: #475569; }
.session-del:hover { color: #ef4444 !important; background: rgba(239,68,68,.12); }

/* Sidebar footer */
.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--sidebar-bd);
  display: flex;
  flex-direction: column;
  gap: 5px;
  flex-shrink: 0;
  white-space: nowrap;
}

.sebi-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: .7rem;
  color: #64748b;
}

.rr-link {
  font-size: .7rem;
  color: var(--orange);
  text-decoration: none;
}
.rr-link:hover { text-decoration: underline; }

/* ── Main panel ──────────────────────────────────────────────────────────── */
.main-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  background: var(--white);
  min-width: 0;
}

/* ── Header ──────────────────────────────────────────────────────────────── */
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--navy);
  color: var(--white);
  flex-shrink: 0;
  gap: 8px;
}

.header-left { display: flex; align-items: center; gap: 10px; }

.menu-btn {
  background: none;
  border: none;
  color: #94a3b8;
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  flex-shrink: 0;
  transition: color .2s, background .2s;
}
.menu-btn:hover { color: var(--white); background: var(--navy-light); }

.logo-badge {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--orange);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--white);
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(0,167,103,.4);
}

.logo-badge-sm {
  width: 34px;
  height: 34px;
  font-size: 1.1rem;
  box-shadow: none;
}

.header-title { font-size: .95rem; font-weight: 700; letter-spacing: .01em; }
.header-sub   { font-size: .72rem; color: #94a3b8; display: flex; align-items: center; gap: 6px; margin-top: 2px; }

.dot-green {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: #22c55e;
  animation: pulse-green 2s infinite;
  flex-shrink: 0;
}
@keyframes pulse-green {
  0%,100% { box-shadow: 0 0 0 0 rgba(34,197,94,.4); }
  50%      { box-shadow: 0 0 0 5px rgba(34,197,94,0); }
}

.header-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

.lang-select {
  background: var(--navy-light);
  color: var(--white);
  border: none;
  border-radius: 8px;
  padding: 6px 10px;
  font-size: .78rem;
  cursor: pointer;
  outline: none;
}
.lang-select option { background: var(--navy); }

.icon-btn {
  background: transparent;
  border: none;
  color: #94a3b8;
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
  transition: color .2s, background .2s;
  display: flex;
  align-items: center;
}
.icon-btn:hover { color: var(--white); background: var(--navy-light); }

/* ── Chat messages ───────────────────────────────────────────────────────── */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 15%;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
}

/* Message row layouts */
.msg-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: 100%;
  animation: fadeUp .25s ease;
}
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.msg-row.user  { flex-direction: row-reverse; }
.msg-row.ai    { flex-direction: row; }

/* Avatar */
.avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: .85rem; font-weight: 700;
}
.avatar.ai-av   { background: var(--orange); color: var(--white); }
.avatar.user-av { background: var(--slate); color: var(--white); }

/* Bubble */
.bubble {
  max-width: 72%;
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: .9rem;
  line-height: 1.6;
  box-shadow: var(--shadow);
  word-break: break-word;
}

.msg-row.ai  .bubble {
  background: var(--bubble-ai);
  border: 1px solid #e2e8f0;
  border-bottom-left-radius: 4px;
  color: var(--navy);
}

.msg-row.user .bubble {
  background: var(--bubble-user);
  color: var(--white);
  border-bottom-right-radius: 4px;
}

/* Markdown inside AI bubble */
.bubble p          { margin-bottom: .5em; }
.bubble p:last-child { margin-bottom: 0; }
.bubble ul, .bubble ol { padding-left: 1.4em; margin-bottom: .5em; }
.bubble li         { margin-bottom: .2em; }
.bubble strong     { font-weight: 700; }
.bubble em         { font-style: italic; }
.bubble code       { background: #e2e8f0; border-radius: 4px; padding: 1px 5px; font-size: .85em; }
.bubble pre        { background: #1e293b; color: #f8fafc; border-radius: 8px; padding: 12px; overflow-x: auto; margin: .5em 0; }
.bubble pre code   { background: none; padding: 0; color: inherit; }
.bubble table      { border-collapse: collapse; width: 100%; margin: .5em 0; font-size: .85em; }
.bubble th, .bubble td { border: 1px solid #cbd5e1; padding: 6px 10px; text-align: left; }
.bubble th         { background: #f1f5f9; font-weight: 600; }
.bubble a          { color: var(--orange); text-decoration: underline; }

/* Timestamp */
.msg-ts {
  font-size: .68rem;
  color: var(--slate);
  margin-top: 3px;
  padding: 0 4px;
  align-self: flex-end;
}
.msg-row.user .msg-ts { text-align: right; }

/* Typing indicator */
.typing-row { display: flex; align-items: center; gap: 8px; }
.typing-dots {
  background: var(--bubble-ai);
  border: 1px solid #e2e8f0;
  border-radius: var(--radius);
  border-bottom-left-radius: 4px;
  padding: 12px 16px;
  display: flex; gap: 5px; align-items: center;
}
.typing-dots span {
  width: 8px; height: 8px;
  background: var(--slate);
  border-radius: 50%;
  animation: bounce .9s infinite ease-in-out;
}
.typing-dots span:nth-child(2) { animation-delay: .15s; }
.typing-dots span:nth-child(3) { animation-delay: .3s; }
@keyframes bounce {
  0%,80%,100% { transform: translateY(0); opacity:.4; }
  40%          { transform: translateY(-7px); opacity:1; }
}

/* ── Quick actions ───────────────────────────────────────────────────────── */
.quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 15%;
  background: var(--white);
  flex-shrink: 0;
}

.chip {
  background: var(--orange-pale);
  color: var(--orange-dark);
  border: 1.5px solid #99dfc3;
  border-radius: 20px;
  padding: 6px 14px;
  font-size: .8rem;
  font-weight: 500;
  cursor: pointer;
  transition: background .2s, border-color .2s, transform .1s;
  white-space: nowrap;
}
.chip:hover  { background: #ccf0e2; border-color: var(--orange); transform: translateY(-1px); }
.chip:active { transform: translateY(0); }

/* ── Escalation banner ───────────────────────────────────────────────────── */
.escalation-banner {
  display: none;
  background: #fef3c7;
  border-top: 2px solid #f59e0b;
  color: #92400e;
  font-size: .82rem;
  font-weight: 500;
  padding: 10px 18px;
  text-align: center;
  flex-shrink: 0;
}

/* ── Input area ──────────────────────────────────────────────────────────── */
.input-area {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 14px;
  margin: 0 15% 16px;
  border: 1.5px solid #e2e8f0;
  border-radius: 18px;
  background: var(--white);
  box-shadow: 0 4px 24px rgba(0,0,0,.10), 0 1px 6px rgba(0,0,0,.06);
  flex-shrink: 0;
}

.attach-btn {
  cursor: pointer;
  color: var(--slate);
  padding: 8px;
  border-radius: 10px;
  transition: color .2s, background .2s;
  display: flex; align-items: center;
  flex-shrink: 0;
}
.attach-btn:hover { color: var(--orange); background: var(--orange-pale); }

.input-wrapper {
  flex: 1;
  background: var(--slate-pale);
  border: 1.5px solid #e2e8f0;
  border-radius: 12px;
  padding: 8px 12px;
  transition: border-color .2s;
}
.input-wrapper:focus-within { border-color: var(--orange); }

.input-wrapper textarea {
  width: 100%;
  background: transparent;
  border: none;
  outline: none;
  resize: none;
  font-family: var(--font);
  font-size: .9rem;
  color: var(--navy);
  max-height: 150px;
  overflow-y: auto;
  line-height: 1.5;
}

.send-btn {
  background: var(--orange);
  border: none;
  border-radius: 12px;
  width: 42px; height: 42px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  color: var(--white);
  flex-shrink: 0;
  transition: background .2s, transform .1s;
  box-shadow: 0 2px 8px rgba(0,167,103,.35);
}
.send-btn:hover  { background: var(--orange-dark); }
.send-btn:active { transform: scale(.95); }
.send-btn:disabled { background: #cbd5e1; box-shadow: none; cursor: not-allowed; }

/* ── Footer ──────────────────────────────────────────────────────────────── */
.chat-footer {
  padding: 6px 15% 10px;
  font-size: .7rem;
  color: var(--slate);
  text-align: center;
  flex-shrink: 0;
}
.chat-footer a { color: var(--orange); text-decoration: none; }
.chat-footer a:hover { text-decoration: underline; }

/* ── Scrollbars ──────────────────────────────────────────────────────────── */
::-webkit-scrollbar              { width: 5px; }
::-webkit-scrollbar-track        { background: transparent; }
::-webkit-scrollbar-thumb        { background: #cbd5e1; border-radius: 3px; }
.sessions-list::-webkit-scrollbar-thumb { background: #334155; }

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  /* Sidebar: slide-in overlay on mobile */
  .sidebar {
    position: fixed;
    left: 0; top: 0; bottom: 0;
    width: 260px !important;
    min-width: 0 !important;
    transform: translateX(-100%);
    transition: transform .3s ease;
    z-index: 200;
  }
  .app-shell.sidebar-open .sidebar {
    transform: translateX(0);
  }
  .app-shell.sidebar-open .sidebar-overlay {
    display: block;
  }
  /* sidebar-collapsed has no effect on mobile */
  .app-shell.sidebar-collapsed .sidebar {
    width: 260px !important;
    transform: translateX(-100%);
  }

  /* Header */
  .chat-header { padding: 10px 12px; }
  .header-title { font-size: .88rem; }
  .logo-badge-sm { display: none; }
  /* Hide language label text, keep dropdown compact */
  .lang-select { font-size: .72rem; padding: 5px 6px; max-width: 90px; }

  /* Messages: remove wide desktop padding */
  .chat-messages { padding: 14px 12px; gap: 10px; }

  /* Bubbles */
  .bubble { max-width: 88%; font-size: .85rem; padding: 10px 13px; }

  /* Quick action chips: horizontal scroll instead of wrapping */
  .quick-actions {
    padding: 8px 12px;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .quick-actions::-webkit-scrollbar { display: none; }
  .chip { flex-shrink: 0; font-size: .76rem; padding: 6px 12px; }

  /* Input area: flush with edges, no side margin */
  .input-area {
    margin: 0 10px 10px;
    margin-bottom: calc(10px + env(safe-area-inset-bottom));
    padding: 8px 10px;
    border-radius: 16px;
  }

  /* Footer */
  .chat-footer {
    padding: 4px 12px 8px;
    padding-bottom: calc(8px + env(safe-area-inset-bottom));
    font-size: .65rem;
  }

  /* Tables inside bubbles: horizontal scroll */
  .bubble table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
}

@media (min-width: 769px) {
  /* Overlay never shown on desktop */
  .sidebar-overlay { display: none !important; }
}

