/* ===== Base ===== */
:root {
  color-scheme: dark;
  --bg-0: #020617;
  --bg-1: #050816;
  --bg-2: #0f172a;
  --text: #e6eaef;
  --muted: #9fb0c2;
  --border: #1e293b;
  --border-2: #334155;
  --brand: #1f54c7;
  --brand-2: #2a6df0;
  --assistant-text-strong: #f8fbff;
  --assistant-link: #8fb5ff;
  --typing-text: #cbd5e1;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg-0: #e5edff;
  --bg-1: #f9fbff;
  --bg-2: #e0ebff;
  --text: #020617;
  --muted: #4b5563;
  --border: #d1d5db;
  --border-2: #9ca3af;
  --brand: #1f54c7;
  --brand-2: #2a6df0;
  --assistant-text-strong: #0f172a;
  --assistant-link: #1d4ed8;
  --typing-text: #334155;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  position: relative;
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  min-height: 100vh;
  background: radial-gradient(circle at top, var(--bg-2), var(--bg-0) 60%);
  color: var(--text);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background:
    linear-gradient(180deg, rgba(2, 6, 23, 0.42), rgba(2, 6, 23, 0.18)),
    url("/static/bg-darkmode-fast.jpg") left top / min(1100px, 82vw) auto no-repeat;
  opacity: 0.24;
  pointer-events: none;
  z-index: 0;
}

:root[data-theme="light"] body::before {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.24), rgba(224, 235, 255, 0.1)),
    url("/static/bg-lightmode-optimized.jpg") left top / min(1100px, 82vw) auto no-repeat;
  opacity: 0.24;
}

.page {
  position: relative;
  z-index: 1;
  display: flex;
  min-height: 100vh;
}

/* ===== Buttons & Controls ===== */
.btn {
  background: var(--bg-1);
  color: var(--text);
  border: 1px solid var(--border-2);
  border-radius: 10px;
  padding: 8px 12px;
  cursor: pointer;
  font: inherit;
}
.btn:hover {
  filter: brightness(1.03);
}
.btn.icon {
  padding: 6px 10px;
}
.btn.small {
  padding: 4px 8px;
  font-size: 12px;
}
.btn.primary,
.btn.brand {
  background: linear-gradient(180deg, var(--brand-2), var(--brand));
  color: #f5f8ff;
  border: 1px solid var(--brand);
}
.btn.primary:hover,
.btn.brand:hover {
  filter: brightness(1.05);
}
.btn.danger {
  background: #7f1d1d;
  border-color: #991b1b;
  color: #fff;
}
.btn.danger:hover {
  background: #a91d1d;
}

/* simple icon-only button */
.icon-btn {
  border-radius: 999px;
  width: 28px;
  height: 28px;
  border: 1px solid transparent;
  background: transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 14px;
  color: var(--muted);
}
.icon-btn:hover {
  background: rgba(255, 255, 255, 0.06);
  border-color: var(--border-2);
  color: #f87171;
}
.icon-btn.danger {
  color: #f97373;
}

/* shared soft hover highlight for buttons */
.btn,
.theme-toggle,
#send-btn {
  position: relative;
  overflow: hidden;
}

.btn::after,
.theme-toggle::after,
#send-btn::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.06);
  opacity: 0;
  transition: opacity 0.15s ease;
  pointer-events: none;
}

.btn:hover::after,
.theme-toggle:hover::after,
#send-btn:hover::after {
  opacity: 1;
}

/* Theme toggle */
.theme-toggle {
  background: var(--bg-1);
  color: var(--text);
  border: 1px solid var(--border-2);
  border-radius: 10px;
  padding: 8px 10px;
  cursor: pointer;
}

/* ===== Layout ===== */
.chat-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
}

/* Header */
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(
    90deg,
    var(--bg-0),
    var(--bg-1) 50%,
    var(--bg-0) 100%
  );
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.38);
  z-index: 10;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo {
  height: 32px;
}

.logo-container {
  display: flex;
  align-items: center;
  gap: 20px;
  flex-shrink: 0;
}

.logo-container .logo {
  height: 42px;
  width: auto;
}

.logo-container .threeie-logo {
  max-width: 170px;
  object-fit: contain;
}

.logo-container .threeie-logo-light {
  display: none;
}

.logo-container .threeie-logo-dark {
  display: inline-block;
}

.logo-container .efb-logo {
  height: 42px;
  width: auto;
  max-width: 200px;
}

.logo-container .efb-logo-light {
  display: inline-block;
}

.logo-container .efb-logo-dark {
  display: none;
}

:root[data-theme="light"] .logo-container .efb-logo-light {
  display: none;
}

:root[data-theme="light"] .logo-container .threeie-logo-light {
  display: inline-block;
}

:root[data-theme="light"] .logo-container .threeie-logo-dark {
  display: none;
}

:root[data-theme="light"] .logo-container .efb-logo-dark {
  display: inline-block;
}

.title-block h2 {
  margin: 0 0 2px 0;
  font-size: 18px;
}
.title-block p {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
}

.header-buttons {
  display: flex;
  gap: 8px;
}

/* Chat card */
.chat-surface {
  flex: 1;
  max-width: 1100px;
  margin: 18px auto;
  background: radial-gradient(circle at top, var(--bg-2), var(--bg-0) 60%);
  border-radius: 16px;
  border: 1px solid var(--border);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.65);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Chat box */
.chat-box {
  flex: 1;
  padding: 16px;
  overflow-y: auto;
}

/* Messages */
.msg {
  border-radius: 14px;
  margin: 10px 16px;
  padding: 12px 14px;
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.18);
  border: 1px solid var(--border);
  max-width: 92%;
  margin-left: auto;
  margin-right: auto;
  transition: background 0.16s ease, box-shadow 0.16s ease,
    transform 0.16s ease, border-color 0.16s ease;
}
.msg:hover {
  background: radial-gradient(
      circle at top left,
      rgba(255, 255, 255, 0.04) 0,
      transparent 55%
    ),
    inherit;
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
  border-color: var(--border-2);
}

@media (min-width: 880px) {
  .msg {
    max-width: 820px;
  }
}
.msg.user {
  background: var(--bg-1);
  border-color: var(--border-2);
}
.msg.assistant {
  background: var(--bg-2);
  border-color: var(--border-2);
}
.msg .meta {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
}
.msg .meta .role {
  color: var(--muted);
}
.copy-answer-btn {
  margin-left: auto;
}
.msg.user .meta .role {
  display: none;
}
.msg .content {
  white-space: normal;
  color: var(--text);
  line-height: 1.72;
  font-size: 15.5px;
  word-break: break-word;
}
.msg .content > *:first-child {
  margin-top: 0;
}
.msg .content > *:last-child {
  margin-bottom: 0;
}
.msg .content h1,
.msg .content h2,
.msg .content h3 {
  margin: 1rem 0 0.45rem;
  line-height: 1.25;
  font-weight: 700;
  color: var(--assistant-text-strong);
}
.msg .content h1 {
  font-size: 1.2rem;
}
.msg .content h2 {
  font-size: 1.06rem;
  padding-bottom: 0.18rem;
  border-bottom: 1px solid rgba(159, 176, 194, 0.18);
}
.msg .content h3 {
  font-size: 1rem;
}
.msg .content p {
  margin: 0.55rem 0;
}
.msg .content ul,
.msg .content ol {
  margin: 0.45rem 0 0.85rem 1.25rem;
  padding: 0;
}
.msg .content li {
  margin: 0.3rem 0;
  padding-left: 0.1rem;
}
.msg .content strong {
  color: var(--assistant-text-strong);
}
.msg .content a {
  color: var(--assistant-link);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.msg .content code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.92em;
  background: rgba(148, 163, 184, 0.12);
  padding: 0.12rem 0.35rem;
  border-radius: 6px;
}

/* Typing bubble */
.msg.typing .content {
  color: var(--typing-text);
}
.typing-dots {
  display: inline-flex;
  gap: 4px;
}
.typing-dots span {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: #e5e7eb;
  animation: bounce 1.2s infinite ease-in-out;
}
.typing-dots span:nth-child(2) {
  animation-delay: 0.15s;
}
.typing-dots span:nth-child(3) {
  animation-delay: 0.3s;
}
@keyframes bounce {
  0%,
  80%,
  100% {
    transform: translateY(0);
    opacity: 0.5;
  }
  40% {
    transform: translateY(-3px);
    opacity: 1;
  }
}

/* Input area */
.input-container {
  border-top: 1px solid var(--border);
  padding: 10px 14px;
  display: flex;
  gap: 8px;
  align-items: stretch;
  background: var(--bg-0);
}
#user-input {
  flex: 1;
  max-height: 180px;
  min-height: 44px;
  resize: none;
  border-radius: 12px;
  border: 1px solid var(--border-2);
  padding: 10px 12px;
  font: inherit;
  color: var(--text);
  background: var(--bg-1);
}
#user-input:focus {
  outline: 1px solid var(--brand-2);
}
#send-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  align-self: stretch;
  padding-inline: 14px;
  min-width: 48px;
}

/* ===== History Drawer ===== */
.history-panel {
  height: 100vh;
  overflow: auto;
  position: fixed;
  left: 0;
  top: 0;
  width: 340px;
  background: radial-gradient(
      1400px 900px at -300px -200px,
      rgba(31, 84, 199, 0.13) 0%,
      rgba(31, 84, 199, 0) 55%
    ),
    var(--bg-0);
  border-right: 1px solid var(--border);
  padding: 16px;
  box-shadow: 8px 0 24px rgba(0, 0, 0, 0.22);
  z-index: 50;
  transform: translateX(-105%);
  opacity: 0;
  pointer-events: none;
  transition: transform 220ms ease-out, opacity 220ms ease-out;
}
.history-panel:not(.hidden) {
  transform: translateX(0);
  opacity: 1;
  pointer-events: auto;
}

.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.history-actions {
  display: flex;
  gap: 8px;
}
.history-list {
  display: grid;
  gap: 10px;
}

.history-card {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  transition: background 0.18s ease, transform 0.18s ease,
    box-shadow 0.18s ease, border-color 0.18s ease;
  cursor: pointer;
}
.history-card .row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.title-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.history-card .title {
  font-weight: 600;
  color: var(--text);
}
.history-card .summary {
  color: #cbd5e1;
}

/* hover */
.history-card:hover {
  background: var(--bg-2);
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
  border-color: var(--border-2);
}

/* active (current chat) */
.history-card.active {
  border-color: var(--brand-2);
  box-shadow: 0 0 0 1px rgba(42, 109, 240, 0.7),
    0 10px 28px rgba(0, 0, 0, 0.5);
}

/* delete icon shown only on hover */
.history-card .btn-delete {
  opacity: 0;
  transform: translateX(4px);
  pointer-events: none;
  transition: opacity 0.15s ease, transform 0.15s ease;
}
.history-card:hover .btn-delete {
  opacity: 1;
  transform: translateX(0);
  pointer-events: auto;
}

.muted {
  color: var(--muted);
}
.small {
  font-size: 12px;
}

/* ===== Modal ===== */
.modal-overlay.hidden {
  display: none;
}
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 60;
}
.modal {
  background: var(--bg-1);
  border-radius: 14px;
  padding: 16px 18px 14px 18px;
  border: 1px solid var(--border-2);
  min-width: 320px;
  max-width: 420px;
  box-shadow: 0 18px 45px rgba(0, 0, 0, 0.75);
}
.modal h3 {
  margin: 0 0 10px 0;
}
.modal label {
  font-size: 13px;
  color: var(--muted);
  display: block;
  margin-bottom: 6px;
}
.modal input {
  width: 100%;
  background: var(--bg-0);
  color: var(--text);
  border: 1px solid var(--border-2);
  border-radius: 8px;
  padding: 10px;
}
.modal-row {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 12px;
}

/* ===== RTL helper ===== */
.msg .content.rtl-msg,
.rtl-msg {
  direction: rtl;
  text-align: right;
}
/* =========================
   MOBILE / PORTRAIT FIXES
   ========================= */
   @media (max-width: 700px) {

    body {
      background: radial-gradient(circle at top, var(--bg-2), var(--bg-0) 65%);
    }
  
    .page {
      flex-direction: column; /* allow drawer overlay on top */
    }
  
    /* Header becomes a tidy vertical stack */
    .chat-header {
      flex-direction: column;
      align-items: stretch;
      gap: 8px;
      padding: 10px 12px;
    }
  
    .header-left {
      width: 100%;
      display: flex;
      align-items: center;
      gap: 8px;
    }
  
    .logo-container {
      gap: 10px;
    }
    
    .logo-container .logo,
    .logo-container .efb-logo {
      height: 26px;
      flex: 0 0 auto;
    }
    
    .logo {
      height: 26px;
      flex: 0 0 auto;
    }
  
    .title-block {
      flex: 1;
      min-width: 0;
    }
  
    .title-block h2 {
      font-size: 16px;
      line-height: 1.2;
      margin: 0;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }
  
    .title-block p {
      font-size: 11px;
      line-height: 1.35;
      margin-top: 2px;
      color: var(--muted);
      /* stop vertical letter-stacking */
      white-space: normal;
      word-break: break-word;
    }
  
    /* Buttons row sits under title, scrollable if needed */
    .header-buttons {
      width: 100%;
      display: flex;
      gap: 6px;
      overflow-x: auto;
      padding-bottom: 2px;
    }
  
    .header-buttons::-webkit-scrollbar {
      height: 0px;
    }
  
    .btn {
      padding: 7px 10px;
      font-size: 13px;
      border-radius: 9px;
      flex: 0 0 auto;
    }
  
    .theme-toggle {
      padding: 7px 9px;
      font-size: 13px;
      flex: 0 0 auto;
    }
  
    /* Chat card fills screen width nicely */
    .chat-surface {
      width: calc(100% - 14px);
      margin: 8px auto 10px auto;
      border-radius: 14px;
      min-height: calc(100vh - 150px); /* keeps size stable */
    }
  
    .chat-box {
      padding: 10px;
    }
  
    .msg {
      margin: 8px 6px;
      padding: 10px 12px;
      border-radius: 12px;
      max-width: 100%;
    }
  
    /* Input stays compact and aligned */
    .input-container {
      padding: 8px;
      gap: 6px;
    }
  
    #user-input {
      min-height: 42px;
      border-radius: 10px;
      padding: 9px 10px;
      font-size: 14px;
    }
  
    #send-btn {
      min-width: 44px;
      border-radius: 10px;
      padding-inline: 12px;
    }
  
    /* History drawer becomes overlay and wider */
    .history-panel {
      width: 85vw;
      max-width: 360px;
      padding: 12px;
      box-shadow: 10px 0 28px rgba(0,0,0,.35);
    }
  
    .history-header h3 {
      font-size: 15px;
    }
  
    .history-card {
      padding: 10px;
      border-radius: 10px;
    }
  
    .history-card .title {
      font-size: 14px;
    }
  
    .history-card .summary {
      font-size: 12px;
    }
  
    .muted.small {
      font-size: 11px;
    }
  }
  
  /* extra-small phones */
  @media (max-width: 420px) {
    .logo-container { gap: 12px; }
    .logo-container .logo,
    .logo-container .efb-logo { height: 34px; }
    .logo-container .threeie-logo { max-width: 120px; }
    .logo-container .efb-logo { max-width: 145px; }
    .title-block h2 { font-size: 15px; }
    .title-block p  { font-size: 10.5px; }
    .btn, .theme-toggle { font-size: 12px; }
  }  
