:root {
  --navy: #12121e;
  --navy-dark: #0b0b12;
  --navy-light: rgba(200,168,75,0.1);
  --accent: #c8a84b;
  --text: #f3f2f0;
  --text-light: rgba(243,242,240,0.62);
  --border: rgba(200,168,75,0.2);
  --bg: #0a0a12;
  --bg-alt: #151523;
  --sidebar-width: 260px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  background-image:
    radial-gradient(ellipse 75% 45% at 50% -5%, rgba(200,168,75,0.12), transparent 72%),
    radial-gradient(circle at 88% 24%, rgba(200,168,75,0.06), transparent 28%);
}

body[dir="rtl"] .sidebar { left: auto; right: 0; }
body[dir="rtl"] .main-content { margin-left: 0; margin-right: var(--sidebar-width); }
body[dir="rtl"] .message.user { margin-left: 0; margin-right: auto; }
body[dir="rtl"] .message.assistant { margin-right: 0; margin-left: auto; }

.topbar {
  background: rgba(10,10,18,0.86);
  color: #fff;
  padding: 0 28px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 100;
  border-bottom: 1px solid rgba(200,168,75,0.15);
  backdrop-filter: blur(12px);
}
.topbar .brand { font-weight: 700; font-size: 16px; letter-spacing: 2px; color: #fff; }
.topbar .user-menu { display: flex; align-items: center; gap: 12px; font-size: 13px; }
.topbar .user-menu span { color: rgba(243,242,240,0.75); }
.topbar a { color: var(--accent); text-decoration: none; }
.topbar a:hover { color: #f1d37e; }

.sidebar {
  position: fixed;
  top: 60px; left: 0; bottom: 0;
  width: var(--sidebar-width);
  background: rgba(10,10,18,0.9);
  border-right: 1px solid rgba(200,168,75,0.12);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.sidebar-header { padding: 14px; border-bottom: 1px solid rgba(200,168,75,0.12); }
.btn-new-chat {
  width: 100%; padding: 8px 12px;
  background: linear-gradient(135deg, #c8a84b, #a07830);
  color: #0a0a12;
  border: none; border-radius: 6px;
  cursor: pointer; font-size: 13px; font-weight: 600;
}
.btn-new-chat:hover { opacity: 0.9; }
.conv-list { flex: 1; overflow-y: auto; }
.conv-item {
  padding: 6px 10px 6px 14px; cursor: pointer;
  border-bottom: 1px solid rgba(200,168,75,0.08);
  font-size: 13px; color: var(--text);
  display: flex; align-items: center; gap: 4px;
}
.conv-item:hover { background: rgba(200,168,75,0.08); }
.conv-item.active {
  background: rgba(200,168,75,0.14);
  font-weight: 600;
  color: #f5df9f;
  border-left: 2px solid var(--accent);
}
.conv-item-title {
  flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.conv-item-input {
  flex: 1; padding: 2px 6px; font-size: 13px; font-family: inherit;
  border: 1px solid var(--accent); border-radius: 4px; outline: none;
  min-width: 0;
}
.conv-actions {
  display: none; gap: 2px; flex-shrink: 0;
}
.conv-item:hover .conv-actions,
.conv-item.active .conv-actions { display: flex; }
.conv-action-btn {
  background: none; border: none; cursor: pointer;
  padding: 2px 4px; border-radius: 3px;
  font-size: 12px; color: var(--text-light); line-height: 1;
}
.conv-action-btn:hover { background: rgba(200,168,75,0.14); color: var(--text); }
.conv-action-btn.delete:hover { color: #dc3545; }
.sidebar-footer { padding: 12px 14px; border-top: 1px solid rgba(200,168,75,0.12); }
.sidebar-footer a { font-size: 13px; color: var(--accent); text-decoration: none; }

.main-content {
  margin-top: 60px;
  margin-left: var(--sidebar-width);
  display: flex; flex-direction: column;
  height: calc(100vh - 60px);
}
.messages-area { flex: 1; overflow-y: auto; padding: 24px; }
.message { max-width: 70%; margin-bottom: 16px; }
.message.user { margin-left: auto; }
.message.assistant { margin-right: auto; }
.message-bubble {
  padding: 10px 14px; border-radius: 10px;
  line-height: 1.6; word-wrap: break-word;
}
.message.user .message-bubble {
  background: rgba(200,168,75,0.16);
  border: 1px solid rgba(200,168,75,0.35);
  color: #f4e4b0;
}
.message.assistant .message-bubble {
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(200,168,75,0.2);
}
.message-bubble.message-error {
  background: #fff5f5; border: 1px solid #f5c2c7;
  display: flex; align-items: flex-start; gap: 10px;
}
.error-icon { font-size: 28px; line-height: 1; flex-shrink: 0; }
.error-text { font-size: 13px; color: #842029; line-height: 1.6; }
/* Military loader */
.mil-loader {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-family: 'SFMono-Regular', Consolas, monospace;
  color: #d2b45f;
  padding: 2px 0;
}
.mil-loader-text {
  animation: mil-flicker 2.4s ease-in-out infinite;
}
.mil-loader-dots::after {
  content: '';
  display: inline-block;
  width: 1.6em;
  animation: mil-ellipsis 1.2s steps(4, end) infinite;
}
@keyframes mil-ellipsis {
  0%   { content: ''; }
  25%  { content: '.'; }
  50%  { content: '..'; }
  75%  { content: '...'; }
  100% { content: ''; }
}
@keyframes mil-flicker {
  0%, 100% { opacity: 1; }
  45%       { opacity: 1; }
  50%       { opacity: 0.35; }
  55%       { opacity: 1; }
}

.citations {
  margin-top: 6px; font-size: 12px; color: var(--text-light);
  padding-left: 14px;
}
.citations a { color: var(--accent); }

/* Markdown content inside assistant bubbles */
.message.assistant .message-bubble { line-height: 1.7; }
.message.assistant .message-bubble p { margin-bottom: 10px; }
.message.assistant .message-bubble p:last-child { margin-bottom: 0; }
.message.assistant .message-bubble h1,
.message.assistant .message-bubble h2,
.message.assistant .message-bubble h3,
.message.assistant .message-bubble h4 {
  color: #f4e3ad; font-weight: 700;
  margin: 14px 0 6px;
}
.message.assistant .message-bubble h1 { font-size: 1.2em; }
.message.assistant .message-bubble h2 { font-size: 1.1em; }
.message.assistant .message-bubble h3 { font-size: 1em; }
.message.assistant .message-bubble ul,
.message.assistant .message-bubble ol {
  padding-left: 20px; margin-bottom: 10px;
}
.message.assistant .message-bubble li { margin-bottom: 4px; }
.message.assistant .message-bubble code {
  background: rgba(200,168,75,0.12); color: #f8db80;
  padding: 1px 5px; border-radius: 3px;
  font-family: 'SFMono-Regular', Consolas, monospace; font-size: 0.9em;
}
.message.assistant .message-bubble pre {
  background: #0f1019; border: 1px solid rgba(200,168,75,0.16); border-radius: 6px;
  padding: 12px 14px; margin: 10px 0;
  overflow-x: auto;
}
.message.assistant .message-bubble pre code {
  background: none; color: #efe1bb;
  padding: 0; font-size: 0.875em;
}
.message.assistant .message-bubble blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 12px; margin: 10px 0;
  color: var(--text-light);
}
.message.assistant .message-bubble table {
  font-size: 13px; margin: 10px 0; width: auto;
}
.message.assistant .message-bubble strong { font-weight: 700; }
.message.assistant .message-bubble em { font-style: italic; }
.message.assistant .message-bubble hr {
  border: none; border-top: 1px solid var(--border); margin: 12px 0;
}

.input-area {
  padding: 12px 20px;
  border-top: 1px solid rgba(200,168,75,0.16);
  background: rgba(10,10,18,0.86);
  backdrop-filter: blur(8px);
  display: flex; gap: 8px; align-items: flex-end;
}
.input-area textarea {
  flex: 1; padding: 8px 12px;
  color: #fff;
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(200,168,75,0.22); border-radius: 6px;
  resize: none; font-size: 14px; font-family: inherit;
  max-height: 120px; min-height: 40px;
}
.input-area textarea:focus {
  outline: none;
  border-color: rgba(200,168,75,0.56);
  background: rgba(200,168,75,0.05);
}
.btn-send {
  padding: 8px 18px;
  background: linear-gradient(135deg, #c8a84b, #a07830);
  color: #0a0a12;
  border: none; border-radius: 6px; cursor: pointer; font-weight: 600;
  height: 40px;
}
.btn-send:hover { opacity: 0.9; }
.btn-send:disabled { opacity: 0.5; cursor: not-allowed; }
.web-toggle { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-light); height: 40px; }
.web-toggle input { cursor: pointer; }

/* Auth page */
.auth-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: var(--bg-alt); }
.auth-card { background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 40px; width: 360px; }
.auth-card h1 { color: var(--navy); font-size: 22px; margin-bottom: 8px; }
.auth-card .subtitle { color: var(--text-light); font-size: 13px; margin-bottom: 24px; }
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 12px; font-weight: 600; color: var(--text-light); margin-bottom: 4px; }
.form-group input { width: 100%; padding: 8px 12px; border: 1px solid var(--border); border-radius: 6px; font-size: 14px; }
.form-group input:focus { outline: none; border-color: var(--accent); }
.btn-primary { width: 100%; padding: 10px; background: var(--navy); color: #fff; border: none; border-radius: 6px; font-size: 14px; font-weight: 600; cursor: pointer; }
.btn-primary:hover { background: var(--navy-dark); }
.error-msg { color: #dc3545; font-size: 13px; margin-top: 8px; display: none; }

/* Admin / Documents pages */
.page-content { max-width: 960px; margin: 0 auto; padding: 24px; }
.page-title { font-size: 20px; font-weight: 700; color: #f3e2ad; margin-bottom: 20px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 10px 12px; border-bottom: 1px solid var(--border); text-align: left; }
th { background: rgba(200,168,75,0.08); font-weight: 600; color: #ead18c; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 11px; font-weight: 600; }
.badge-admin { background: rgba(200,168,75,0.18); color: #f4df9f; }
.badge-user { background: rgba(255,255,255,0.1); color: var(--text-light); }
.btn-sm { padding: 4px 10px; font-size: 12px; border-radius: 4px; border: none; cursor: pointer; }
.btn-danger { background: #dc3545; color: #fff; }
.btn-secondary { background: rgba(255,255,255,0.04); color: var(--text); border: 1px solid var(--border); }

/* ── Alibaba supplier cards ─────────────────────────────────────────────── */
.alibaba-cards {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
}

.alibaba-card {
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  padding: 10px 14px;
  background: var(--bg-alt);
  font-size: 13px;
  line-height: 1.5;
}

.alibaba-card .alibaba-card-title {
  font-weight: 600;
  color: var(--text);
  margin-bottom: 2px;
}

.alibaba-card .alibaba-card-meta {
  color: var(--text-light);
  margin-bottom: 6px;
}

.alibaba-card .alibaba-card-link a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
}

.alibaba-card .alibaba-card-link a:hover {
  text-decoration: underline;
}

.alibaba-no-results {
  font-size: 13px;
  color: var(--text-light);
  margin-top: 8px;
  font-style: italic;
}

/* ── Landing page ─────────────────────────────────────────────────────────── */
.landing-nav {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  padding: 0 48px; height: 60px;
  display: flex; align-items: center; justify-content: space-between;
  background: rgba(10,10,18,0.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(200,168,75,0.12);
}
.landing-brand {
  font-size: 17px; font-weight: 700; letter-spacing: 2px; color: #fff;
  display: flex; align-items: center; gap: 10px;
}
.landing-brand .l-star { color: #c8a84b; font-size: 20px; }
.landing-nav-actions { display: flex; gap: 12px; align-items: center; }
.l-btn-ghost {
  background: transparent; border: 1px solid rgba(200,168,75,0.4);
  color: #c8a84b; padding: 7px 20px; border-radius: 4px;
  font-size: 13px; font-weight: 600; cursor: pointer; transition: all 0.2s; letter-spacing: 0.5px;
}
.l-btn-ghost:hover { background: rgba(200,168,75,0.1); border-color: #c8a84b; }
.l-btn-gold {
  background: linear-gradient(135deg, #c8a84b, #a07830);
  color: #0a0a12; border: none; padding: 8px 22px; border-radius: 4px;
  font-size: 13px; font-weight: 700; cursor: pointer; transition: opacity 0.2s; letter-spacing: 0.5px;
}
.l-btn-gold:hover { opacity: 0.9; }
.landing-hero {
  min-height: 100vh; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  text-align: center; padding: 120px 24px 80px; position: relative;
}
.landing-hero::before {
  content: ''; position: absolute; inset: 0;
  background: radial-gradient(ellipse 80% 60% at 50% 40%, rgba(200,168,75,0.07) 0%, transparent 70%);
  pointer-events: none;
}
.l-badge {
  display: inline-flex; align-items: center; gap: 8px;
  background: rgba(200,168,75,0.08); border: 1px solid rgba(200,168,75,0.25);
  color: #c8a84b; font-size: 11px; font-weight: 700;
  letter-spacing: 3px; padding: 6px 16px; border-radius: 2px; margin-bottom: 32px;
}
.l-badge::before {
  content: ''; width: 6px; height: 6px; background: #c8a84b;
  border-radius: 50%; animation: l-pulse 2s infinite;
}
@keyframes l-pulse { 0%,100%{opacity:1} 50%{opacity:0.3} }
.l-h1 {
  font-size: clamp(42px, 7vw, 76px); font-weight: 800; letter-spacing: 4px;
  color: #fff; margin-bottom: 8px; line-height: 1;
}
.l-h1 .l-star { color: #c8a84b; }
.l-sub {
  font-size: 13px; font-weight: 600; letter-spacing: 5px;
  color: rgba(200,168,75,0.6); text-transform: uppercase; margin-bottom: 20px;
}
.l-desc {
  font-size: 16px; color: rgba(255,255,255,0.45);
  max-width: 480px; line-height: 1.7; margin-bottom: 44px;
}
.l-desc strong { color: rgba(255,255,255,0.7); }
.l-ctas { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; }
.l-btn-primary {
  background: linear-gradient(135deg, #c8a84b, #a07830);
  color: #0a0a12; border: none; padding: 14px 36px; border-radius: 4px;
  font-size: 14px; font-weight: 700; cursor: pointer; letter-spacing: 1px; transition: all 0.2s;
}
.l-btn-primary:hover { transform: translateY(-1px); box-shadow: 0 8px 24px rgba(200,168,75,0.25); }
.l-btn-secondary {
  background: transparent; border: 1px solid rgba(200,168,75,0.35); color: #c8a84b;
  padding: 14px 36px; border-radius: 4px; font-size: 14px; font-weight: 600;
  cursor: pointer; letter-spacing: 1px; transition: all 0.2s;
}
.l-btn-secondary:hover { background: rgba(200,168,75,0.08); border-color: #c8a84b; }
.l-scroll-hint {
  position: absolute; bottom: 36px; left: 50%; transform: translateX(-50%);
  color: rgba(200,168,75,0.35); font-size: 11px; letter-spacing: 2px;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
}
.l-scroll-hint::after { content: '↓'; font-size: 16px; animation: l-bounce 1.8s infinite; }
@keyframes l-bounce { 0%,100%{transform:translateY(0)} 50%{transform:translateY(5px)} }
.l-divider {
  height: 1px;
  background: linear-gradient(to right, transparent, rgba(200,168,75,0.2), transparent);
  margin: 0 48px;
}
.l-features { padding: 100px 48px; max-width: 1100px; margin: 0 auto; }
.l-section-label {
  text-align: center; font-size: 11px; font-weight: 700; letter-spacing: 4px;
  color: rgba(200,168,75,0.5); margin-bottom: 16px;
}
.l-features h2 { text-align: center; font-size: 32px; font-weight: 700; color: #fff; margin-bottom: 12px; letter-spacing: 1px; }
.l-features-desc {
  text-align: center; color: rgba(255,255,255,0.35); font-size: 14px;
  margin-bottom: 64px; max-width: 480px; margin-left: auto; margin-right: auto; line-height: 1.6;
}
.l-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 20px; }
.l-card {
  background: rgba(255,255,255,0.02); border: 1px solid rgba(200,168,75,0.12);
  border-radius: 6px; padding: 28px 24px; transition: all 0.25s; position: relative; overflow: hidden;
}
.l-card::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 2px;
  background: linear-gradient(to right, #c8a84b, transparent); opacity: 0; transition: opacity 0.25s;
}
.l-card:hover { background: rgba(200,168,75,0.04); border-color: rgba(200,168,75,0.28); transform: translateY(-2px); }
.l-card:hover::before { opacity: 1; }
.l-card-icon { font-size: 22px; margin-bottom: 14px; color: #c8a84b; }
.l-card h3 { font-size: 15px; font-weight: 700; color: #fff; margin-bottom: 8px; }
.l-card p { font-size: 13px; color: rgba(255,255,255,0.4); line-height: 1.6; }
.l-access { padding: 80px 48px 120px; text-align: center; border-top: 1px solid rgba(200,168,75,0.08); }
.l-access h2 { font-size: 26px; font-weight: 700; margin-bottom: 8px; letter-spacing: 1px; }
.l-access p { color: rgba(255,255,255,0.3); font-size: 13px; margin-top: 20px; max-width: 400px; margin-left: auto; margin-right: auto; }
.l-footer {
  border-top: 1px solid rgba(255,255,255,0.05); padding: 24px 48px;
  display: flex; align-items: center; justify-content: space-between;
  color: rgba(255,255,255,0.2); font-size: 12px;
}

/* ── Landing modals ── */
.l-modal-overlay {
  display: none; position: fixed; inset: 0; z-index: 200;
  background: rgba(5,5,10,0.85); backdrop-filter: blur(8px);
  align-items: center; justify-content: center;
}
.l-modal-overlay.active { display: flex; }
.l-modal {
  background: #12121e; border: 1px solid rgba(200,168,75,0.25);
  border-radius: 8px; padding: 40px; width: 100%; max-width: 420px;
  position: relative; box-shadow: 0 24px 80px rgba(0,0,0,0.6);
  max-height: 90vh; overflow-y: auto;
}
.l-modal-close {
  position: absolute; top: 16px; right: 20px;
  background: none; border: none; color: rgba(255,255,255,0.3);
  font-size: 20px; cursor: pointer; line-height: 1;
}
.l-modal-close:hover { color: #fff; }
.l-modal-title { font-size: 18px; font-weight: 700; color: #fff; margin-bottom: 4px; letter-spacing: 0.5px; }
.l-modal-sub { font-size: 12px; color: rgba(255,255,255,0.3); margin-bottom: 28px; }
.l-modal label {
  display: block; font-size: 11px; font-weight: 600;
  color: rgba(200,168,75,0.7); letter-spacing: 1.5px; margin-bottom: 6px; margin-top: 16px;
}
.l-modal label:first-of-type { margin-top: 0; }
.l-modal input, .l-modal textarea {
  width: 100%; background: rgba(255,255,255,0.04);
  border: 1px solid rgba(200,168,75,0.18); color: #fff;
  border-radius: 4px; padding: 10px 12px; font-size: 13px;
  font-family: inherit; transition: border-color 0.2s;
}
.l-modal input:focus, .l-modal textarea:focus {
  outline: none; border-color: rgba(200,168,75,0.5); background: rgba(200,168,75,0.04);
}
.l-modal textarea { resize: vertical; min-height: 80px; }
.l-modal-btn {
  margin-top: 24px; width: 100%;
  background: linear-gradient(135deg, #c8a84b, #a07830);
  color: #0a0a12; border: none; border-radius: 4px;
  padding: 12px; font-size: 14px; font-weight: 700;
  cursor: pointer; letter-spacing: 0.5px; transition: opacity 0.2s;
}
.l-modal-btn:hover { opacity: 0.9; }
.l-modal-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.l-modal-switch { margin-top: 16px; text-align: center; font-size: 12px; color: rgba(255,255,255,0.3); }
.l-modal-switch a { color: #c8a84b; text-decoration: none; cursor: pointer; }
.l-modal-switch a:hover { text-decoration: underline; }
.l-modal-error { color: #e05555; font-size: 12px; margin-top: 8px; display: none; }
.l-modal-success { color: #50c87c; font-size: 13px; margin-top: 12px; text-align: center; display: none; }
