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

:root {
  --primary:       #2A9D8F;
  --primary-dark:  #21867A;
  --primary-light: #E8F5F3;
  --slate:         #264653;
  --slate-light:   #3D5A6A;
  --bg:            #F4F4F0;
  --sidebar-bg:    #FAFAF8;
  --white:         #FFFFFF;
  --border:        #E5E2DC;
  --text:          #264653;
  --text-muted:    #7A8A8F;
  --text-light:    #B0BEC5;
  --shadow:        0 1px 4px rgba(38,70,83,.08);
  --shadow-md:     0 4px 20px rgba(38,70,83,.13);
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}

/* ── Layout ───────────────────────────────────────────────────────────────── */
.app { display: flex; height: 100vh; overflow: hidden; }

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
.sidebar {
  width: 260px; min-width: 260px;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column; overflow: hidden;
}

.sidebar-header {
  padding: 15px 14px 13px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px;
}

.logo { display: flex; align-items: center; gap: 9px; }
.logo-img {
  width: 34px; height: 34px; border-radius: 9px;
  object-fit: contain; flex-shrink: 0;
}
.logo-fallback {
  width: 34px; height: 34px; border-radius: 9px;
  background: linear-gradient(135deg, var(--primary), var(--slate));
  color: #fff; font-size: 17px; font-weight: 700;
  align-items: center; justify-content: center; flex-shrink: 0;
}
.logo-text {
  font-size: 20px; font-weight: 700; color: var(--primary);
  letter-spacing: 1.5px;
}

.new-chat-btn {
  display: flex; align-items: center; gap: 5px;
  padding: 6px 11px; border-radius: 8px;
  background: var(--primary); color: #fff;
  border: none; cursor: pointer; font-size: 12.5px; font-weight: 600;
  transition: background .15s; white-space: nowrap; flex-shrink: 0;
}
.new-chat-btn:hover { background: var(--primary-dark); }

/* ── Tabs ────────────────────────────────────────────────────────────────── */
.profile-switcher {
  display: flex; gap: 8px; padding: 10px 14px 6px;
}
.profile-btn {
  flex: 1; border: 1px solid var(--border); background: var(--white);
  color: var(--text-muted); border-radius: 10px; padding: 8px 10px;
  font-size: 13px; font-weight: 600; cursor: pointer; transition: all .15s;
}
.profile-btn.active { background: var(--primary-light); color: var(--primary); border-color: rgba(42,157,143,.35); }
.profile-caption { padding: 0 14px 10px; font-size: 11px; color: var(--text-light); }

.sidebar-tabs {
  display: flex; padding: 0 14px;
  border-bottom: 1px solid var(--border);
}
.tab-btn {
  flex: 1; padding: 9px 4px 8px; border: none; background: none;
  font-size: 13px; font-weight: 500; color: var(--text-muted);
  cursor: pointer; border-bottom: 2px solid transparent;
  transition: all .15s; margin-bottom: -1px;
}
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-btn:hover:not(.active) { color: var(--text); }

/* ── Tab Panels ──────────────────────────────────────────────────────────── */
.tab-panel { display: flex; flex-direction: column; flex: 1; overflow: hidden; min-height: 0; }
.tab-panel.hidden { display: none !important; }

/* ── Conversation List ───────────────────────────────────────────────────── */
.conv-list { flex: 1; overflow-y: auto; padding: 6px 8px 12px; }

.conv-group-label {
  font-size: 10.5px; font-weight: 600; color: var(--text-light);
  text-transform: uppercase; letter-spacing: .8px;
  padding: 12px 8px 4px;
}
.conv-group-label:first-child { padding-top: 8px; }

.conv-item {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; border-radius: 8px; cursor: pointer;
  transition: background .12s; font-size: 13.5px; color: var(--text);
  margin-bottom: 1px;
}
.conv-item:hover { background: rgba(42,157,143,.08); }
.conv-item.active { background: var(--primary-light); color: var(--primary); font-weight: 500; }

.conv-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.conv-delete {
  opacity: 0; background: none; border: none; cursor: pointer;
  color: var(--text-muted); padding: 3px; border-radius: 4px;
  display: flex; align-items: center; flex-shrink: 0;
  transition: opacity .12s;
}
.conv-item:hover .conv-delete { opacity: 1; }
.conv-item.active .conv-delete { opacity: .5; }
.conv-delete:hover { opacity: 1 !important; color: #dc2626; background: #fee2e2; }

/* ── File Sections ───────────────────────────────────────────────────────── */
.file-section-label {
  padding: 10px 16px 5px;
  font-size: 10.5px; font-weight: 600; color: var(--text-light);
  text-transform: uppercase; letter-spacing: .8px;
}

.doc-list { flex: 1; overflow-y: auto; padding: 0 8px; min-height: 0; }
.doc-item {
  display: flex; align-items: center; gap: 8px; padding: 8px 8px;
  border-radius: 8px; cursor: pointer; transition: background .12s;
  font-size: 13px; color: var(--text); margin-bottom: 1px;
}
.doc-item:hover { background: rgba(42,157,143,.08); }
.doc-item.active { background: var(--primary-light); color: var(--primary); }
.doc-icon { font-size: 15px; flex-shrink: 0; }
.doc-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-delete {
  font-size: 15px; opacity: 0; transition: opacity .12s;
  color: var(--text-muted); cursor: pointer; padding: 2px 4px;
  border-radius: 4px;
}
.doc-item:hover .doc-delete { opacity: 1; }
.doc-delete:hover { color: #dc2626; background: #fee2e2; }
.no-docs { padding: 16px; color: var(--text-muted); font-size: 13px; text-align: center; }

.upload-btn {
  margin: 8px 12px; padding: 10px; border-radius: 10px;
  border: 1.5px dashed var(--border); background: none; cursor: pointer;
  color: var(--text-muted); font-size: 13px; transition: all .15s;
  display: flex; align-items: center; justify-content: center; gap: 7px;
  flex-shrink: 0;
}
.upload-btn:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-light); }
.upload-btn.connected { border-style: solid; border-color: #16a34a; color: #16a34a; background: #f0fdf4; }

.search-input {
  flex: 1; padding: 7px 10px; border: 1px solid var(--border);
  border-radius: 8px; font-size: 13px; outline: none; background: var(--white);
  color: var(--text); transition: border .15s;
}
.search-input:focus { border-color: var(--primary); }

.icon-btn {
  padding: 7px 9px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--white); cursor: pointer; display: flex; align-items: center;
  color: var(--text-muted); transition: all .15s;
}
.icon-btn:hover { border-color: var(--primary); color: var(--primary); }

/* ── Modal ───────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(38,70,83,.45);
  z-index: 200; align-items: center; justify-content: center;
}
.modal-box {
  background: var(--white); border-radius: 18px; padding: 30px 28px;
  max-width: 390px; width: 90%; text-align: center; box-shadow: var(--shadow-md);
}
.modal-icon { margin-bottom: 14px; }
.modal-box h3 { font-size: 18px; font-weight: 700; margin-bottom: 8px; color: var(--slate); }
.modal-box p { color: var(--text-muted); font-size: 14px; margin-bottom: 14px; line-height: 1.5; }
.od-link {
  display: block; padding: 10px 14px; background: var(--primary-light);
  border-radius: 9px; color: var(--primary); font-weight: 600;
  margin-bottom: 12px; text-decoration: none; font-size: 14px;
  transition: background .15s;
}
.od-link:hover { background: #c5e8e4; }
.od-code {
  font-size: 26px; font-weight: 700; letter-spacing: 5px;
  color: var(--slate); background: var(--bg); padding: 14px;
  border-radius: 10px; margin-bottom: 14px; font-family: "Courier New", monospace;
}
.od-hint { font-size: 13px; color: var(--text-muted); margin-bottom: 14px; }
.btn-primary {
  width: 100%; padding: 13px; background: var(--primary); color: #fff;
  border: none; border-radius: 11px; font-size: 15px; font-weight: 600;
  cursor: pointer; margin-bottom: 8px; transition: background .15s;
}
.btn-primary:hover { background: var(--primary-dark); }
.btn-ghost {
  width: 100%; padding: 10px; background: none; border: none;
  color: var(--text-muted); font-size: 14px; cursor: pointer;
}

/* ── Main ────────────────────────────────────────────────────────────────── */
.main { flex: 1; display: flex; flex-direction: column; overflow: hidden; background: var(--bg); }

.topbar {
  padding: 0 20px; height: 56px;
  display: flex; align-items: center; justify-content: space-between;
  background: var(--white); border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.topbar-left {
  display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1;
}
.topbar-title {
  font-size: 14.5px; font-weight: 600; color: var(--slate);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.topbar-actions { display: flex; gap: 8px; align-items: center; flex-shrink: 0; }

.doc-badge {
  background: var(--primary-light); color: var(--primary);
  font-size: 11px; padding: 2px 9px; border-radius: 20px;
  font-weight: 500; white-space: nowrap; flex-shrink: 0;
}

.toggle-btn {
  display: flex; align-items: center; gap: 5px;
  padding: 6px 13px; border-radius: 20px; border: 1px solid var(--border);
  background: none; cursor: pointer; font-size: 13px; color: var(--text-muted);
  transition: all .15s; white-space: nowrap;
}
.toggle-btn.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.toggle-btn:hover:not(.active) { border-color: var(--primary); color: var(--primary); }

/* ── Messages ────────────────────────────────────────────────────────────── */
.messages {
  flex: 1; overflow-y: auto; padding: 24px 24px;
  display: flex; flex-direction: column; gap: 16px;
}

.message { display: flex; gap: 12px; max-width: 800px; animation: fadeIn .2s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: none; } }
.message.user { flex-direction: row-reverse; align-self: flex-end; }
.message.assistant { align-self: flex-start; }

.avatar {
  width: 34px; height: 34px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700;
}
.message.user .avatar {
  background: var(--primary); color: #fff;
}
.message.assistant .avatar {
  background: var(--primary-light);
  border: 2px solid rgba(42,157,143,.25);
  overflow: hidden; padding: 0;
}

.bubble {
  padding: 12px 16px; border-radius: 16px; font-size: 14.5px;
  line-height: 1.65; max-width: calc(100% - 50px); word-wrap: break-word;
}
.message.user .bubble {
  background: var(--primary); color: #fff;
  border-bottom-right-radius: 4px;
}
.message.assistant .bubble {
  background: var(--white); border: 1px solid var(--border);
  border-bottom-left-radius: 4px; box-shadow: var(--shadow);
}

.bubble pre {
  background: var(--bg); padding: 10px 12px; border-radius: 8px;
  overflow-x: auto; font-size: 13px; margin: 8px 0;
}
.bubble code {
  background: var(--bg); padding: 2px 5px; border-radius: 4px;
  font-size: 13px; font-family: "Courier New", monospace;
}
.bubble pre code { background: none; padding: 0; }
.bubble strong { font-weight: 600; }
.bubble em { font-style: italic; }
.bubble p { margin-bottom: 8px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble ul, .bubble ol { padding-left: 20px; margin: 6px 0; }
.bubble li { margin-bottom: 3px; }
.bubble h1, .bubble h2, .bubble h3 {
  margin: 10px 0 6px; color: var(--slate); font-weight: 600;
}
.bubble h1 { font-size: 17px; }
.bubble h2 { font-size: 16px; }
.bubble h3 { font-size: 15px; }

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px; padding: 2px 9px; border-radius: 20px; margin-bottom: 7px;
}
.badge-search { background: #fef3c7; color: #92400e; }
.badge-doc { background: var(--primary-light); color: var(--primary); }

.typing { display: flex; align-items: center; gap: 4px; padding: 6px 4px; }
.dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--primary); opacity: .5;
  animation: bounce .9s ease infinite;
}
.dot:nth-child(2) { animation-delay: .2s; }
.dot:nth-child(3) { animation-delay: .4s; }
@keyframes bounce {
  0%,60%,100% { transform: translateY(0); }
  30% { transform: translateY(-6px); }
}

/* ── Create Bar ──────────────────────────────────────────────────────────── */
.create-bar {
  padding: 7px 20px; background: var(--white);
  border-top: 1px solid var(--border);
  display: flex; gap: 8px; align-items: center; flex-shrink: 0;
}
.create-bar span { font-size: 12px; color: var(--text-muted); }
.create-btn {
  display: flex; align-items: center; gap: 5px;
  padding: 5px 13px; border-radius: 20px; border: 1px solid var(--border);
  background: none; cursor: pointer; font-size: 13px; color: var(--text-muted);
  transition: all .15s;
}
.create-btn:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-light); }

/* ── Input ───────────────────────────────────────────────────────────────── */
.input-area {
  padding: 12px 20px calc(20px + env(safe-area-inset-bottom));
  background: var(--white);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  margin-bottom: 10px;
}
.input-row { display: flex; gap: 10px; align-items: flex-end; }

@media (min-width: 768px) and (max-width: 1024px) {
  .messages { padding-bottom: 56px; }
  .create-bar { margin-bottom: 10px; }
  .input-area { margin-bottom: 34px; }
}

@media (max-width: 767px) {
  .messages { padding-bottom: 42px; }
  .input-area { margin-bottom: 28px; }
}

#message-input {
  flex: 1; padding: 12px 16px; border: 1.5px solid var(--border);
  border-radius: 12px; font-size: 15px; resize: none;
  min-height: 48px; max-height: 160px; overflow-y: auto;
  font-family: inherit; outline: none; transition: border .15s, background .15s;
  line-height: 1.5; background: var(--bg); color: var(--text);
}
#message-input:focus { border-color: var(--primary); background: var(--white); }
#message-input::placeholder { color: var(--text-muted); }

.send-btn {
  width: 48px; height: 48px; border-radius: 12px; border: none;
  background: var(--primary); color: #fff; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; transition: background .15s;
}
.send-btn:hover { background: var(--primary-dark); }
.send-btn:disabled { background: var(--border); cursor: not-allowed; }

/* ── Empty State ─────────────────────────────────────────────────────────── */
.empty-state {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 14px; padding: 40px; text-align: center;
}

.empty-brand {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
}
.empty-logo-img {
  width: 76px; height: 76px; border-radius: 18px; object-fit: contain;
  box-shadow: 0 4px 16px rgba(42,157,143,.2);
}
.sira-big-fallback {
  width: 76px; height: 76px; border-radius: 18px;
  background: linear-gradient(135deg, var(--primary), var(--slate));
  align-items: center; justify-content: center;
  font-size: 36px; font-weight: 700; color: #fff;
  box-shadow: 0 4px 16px rgba(42,157,143,.2);
}
.empty-brand-name {
  font-size: 38px; font-weight: 800; letter-spacing: 6px;
  color: var(--primary);
  text-shadow: 0 2px 12px rgba(42,157,143,.18);
}
.empty-brand-sub {
  font-size: 12px; font-weight: 500; letter-spacing: 1.5px;
  color: var(--text-muted); text-transform: uppercase;
}

.empty-state h2 { font-size: 20px; color: var(--slate); font-weight: 600; }
.empty-state p {
  font-size: 14.5px; color: var(--text-muted);
  max-width: 360px; line-height: 1.65;
}
.suggestions {
  display: flex; flex-wrap: wrap; gap: 8px;
  justify-content: center; margin-top: 4px;
}
.suggestion {
  padding: 8px 15px; border-radius: 20px; border: 1.5px solid var(--border);
  background: var(--white); cursor: pointer; font-size: 13.5px; color: var(--text);
  transition: all .15s;
}
.suggestion:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-light); }

/* ── Download Link ───────────────────────────────────────────────────────── */
.download-link {
  display: inline-flex; align-items: center; gap: 6px; margin-top: 10px;
  padding: 8px 14px; border-radius: 9px; background: var(--bg);
  color: var(--primary); text-decoration: none; font-size: 14px; font-weight: 500;
  transition: background .15s; border: 1px solid var(--border);
}
.download-link:hover { background: var(--primary-light); border-color: var(--primary); }

/* ── Sidebar Toggle ──────────────────────────────────────────────────────── */
.sidebar-toggle {
  display: none; width: 36px; height: 36px; border-radius: 8px;
  border: 1px solid var(--border); background: none; cursor: pointer;
  align-items: center; justify-content: center; color: var(--text-muted);
  flex-shrink: 0; transition: all .15s;
}
.sidebar-toggle:hover { border-color: var(--primary); color: var(--primary); }

/* ── Toast ───────────────────────────────────────────────────────────────── */
.toast {
  position: fixed; bottom: 28px; left: 50%; transform: translateX(-50%);
  background: var(--slate); color: #fff; padding: 10px 20px;
  border-radius: 10px; font-size: 14px; z-index: 300;
  opacity: 0; transition: opacity .2s; pointer-events: none;
  white-space: nowrap; box-shadow: var(--shadow-md);
}
.toast.show { opacity: 1; }

/* ── Scrollbar ───────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-light); }

/* ── Mobile / iPad ───────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar {
    position: fixed; left: -260px; top: 0; bottom: 0;
    z-index: 50; transition: left .25s ease;
    box-shadow: 4px 0 28px rgba(38,70,83,.18);
  }
  .sidebar.open { left: 0; }
  .sidebar-toggle { display: flex; }
  .overlay {
    display: none; position: fixed; inset: 0;
    background: rgba(38,70,83,.35); z-index: 40;
  }
  .overlay.show { display: block; }
  .messages { padding: 16px 14px; gap: 14px; }
  .input-area { padding: 10px 14px 18px; }
  .topbar { padding: 0 14px; }
  .create-bar { padding: 6px 14px; }
  .bubble { font-size: 14px; }
}

@media (max-width: 480px) {
  .create-bar span { display: none; }
}
