:root {
  color-scheme: light;
  --bg: #f3f5f8;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --surface-muted: #eef2f7;
  --border: #dde3ea;
  --text: #17191c;
  --muted: #6f7782;
  --accent: #1f2937;
  --shadow: 0 18px 42px rgba(15, 23, 42, 0.08);
  --sidebar-w: 300px;
  --composer-offset: 210px;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); font: 16px/1.5 Inter, system-ui, -apple-system, BlinkMacSystemFont, sans-serif; }
body { min-height: 100vh; overflow-x: hidden; }
button, textarea, input { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); }

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 14px;
  border-right: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(250,252,255,0.96), rgba(246,248,251,0.92));
  backdrop-filter: blur(12px);
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow: hidden;
  box-shadow: inset -1px 0 0 rgba(255,255,255,0.5);
}
.sidebar-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px;
  border: 1px solid rgba(255,255,255,0.65);
  border-radius: 22px;
  background: linear-gradient(180deg, rgba(255,255,255,0.9), rgba(246,249,252,0.88));
  box-shadow: 0 14px 32px rgba(15, 23, 42, 0.07);
}
.sidebar-brand { display: flex; align-items: center; gap: 12px; min-width: 0; flex: 1 1 auto; }
.sidebar-logo,
.topbar-logo {
  width: 44px;
  height: 44px;
  object-fit: contain;
  border-radius: 14px;
  background: linear-gradient(180deg, #ffffff, #f6f8fb);
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.08);
}
.sidebar-title,
.topbar-title { font-size: 16px; font-weight: 600; line-height: 1.1; letter-spacing: -0.02em; }
.sidebar-tagline,
.topbar-status { margin-top: 2px; font-size: 12px; color: var(--muted); }
.sidebar-actions,
.topbar-left { display: flex; align-items: center; gap: 8px; }
.sidebar-section {
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 9px;
  border: 1px solid rgba(255,255,255,0.6);
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(255,255,255,0.8), rgba(248,250,253,0.82));
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.045);
}
.sidebar-section-grow { flex: 1 1 auto; }
.sidebar-section-chat { min-height: 0; }
.sidebar-section-favorites { flex: 0 0 auto; max-height: min(30vh, 260px); }
.sidebar-search {
  width: 100%;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.9);
  color: var(--text);
  padding: 11px 13px;
  outline: none;
  font-size: 14px;
}
.sidebar-section-title { padding: 0 6px 10px; font-size: 11px; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); }
.sidebar-list { display: flex; flex-direction: column; gap: 6px; min-height: 0; overflow: auto; padding-right: 2px; }
.sidebar-section-chat .sidebar-list,
.sidebar-section-favorites .sidebar-list { flex: 1 1 auto; }
.sidebar-item {
  width: 100%;
  text-align: left;
  border: 1px solid transparent;
  background: linear-gradient(180deg, rgba(255,255,255,0.58), rgba(248,250,253,0.48));
  border-radius: 16px;
  padding: 10px 12px;
  color: var(--text);
  transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease, background .18s ease;
  position: relative;
  overflow: hidden;
}
.sidebar-item:hover,
.sidebar-item.active {
  background: linear-gradient(180deg, #ffffff, #f7faff);
  border-color: rgba(203, 213, 225, 0.95);
  box-shadow: 0 10px 22px rgba(15, 23, 42, 0.055);
}
.sidebar-item:hover { transform: translateY(-1px); }
.sidebar-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 8px;
  bottom: 8px;
  width: 4px;
  border-radius: 999px;
  background: linear-gradient(180deg, #111827, #475569);
}
.sidebar-item-title { font-size: 13px; font-weight: 600; line-height: 1.32; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-item-snippet { margin-top: 4px; font-size: 12px; color: var(--text); opacity: .74; line-height: 1.32; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.sidebar-item-meta { margin-top: 4px; font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.search-hit { background: rgba(250, 204, 21, 0.24); color: inherit; border-radius: 5px; padding: 0 2px; }
.sidebar-item-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: flex-start;
  gap: 8px;
}
.sidebar-item-copy { min-width: 0; flex: 1 1 auto; }
.sidebar-item-actions {
  display: flex;
  align-items: center;
  gap: 5px;
  opacity: 1;
  flex: 0 0 auto;
}
.sidebar-item-action {
  -webkit-appearance: none;
  appearance: none;
  flex: 0 0 26px;
  width: 26px;
  height: 26px;
  border-radius: 9px;
  border: 1px solid rgba(148, 163, 184, 0.18);
  background: rgba(255,255,255,0.68);
  color: #6b7280;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  margin: 0;
  box-shadow: none;
  transition: background .18s ease, border-color .18s ease, color .18s ease, transform .18s ease;
}
.sidebar-item-action:hover {
  color: var(--text);
  background: rgba(255,255,255,0.9);
  border-color: rgba(148, 163, 184, 0.28);
  transform: translateY(-1px);
}
.sidebar-item-action .icon-svg { width: 13px; height: 13px; }
.sidebar-empty {
  padding: 14px 12px;
  font-size: 13px;
  color: var(--muted);
  border: 1px dashed rgba(148, 163, 184, 0.35);
  border-radius: 16px;
  background: linear-gradient(180deg, rgba(255,255,255,0.55), rgba(248,250,253,0.5));
}

.main-shell { min-width: 0; display: flex; flex-direction: column; min-height: 100vh; }
.topbar.compact {
  position: sticky;
  top: 0;
  z-index: 8;
  min-height: 54px;
  padding: 7px 12px;
  border-bottom: 1px solid var(--border);
  background: rgba(243,245,248,0.84);
  backdrop-filter: blur(10px);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.topbar-brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.mobile-only { display: none; }

.icon-btn {
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: linear-gradient(180deg, #ffffff, #f6f8fb);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  box-shadow: 0 6px 18px rgba(15, 23, 42, 0.05);
  transition: transform .18s ease, box-shadow .18s ease, background .18s ease, border-color .18s ease;
}
.icon-btn:hover { background: linear-gradient(180deg, #ffffff, #edf2f8); transform: translateY(-1px); box-shadow: 0 10px 20px rgba(15, 23, 42, 0.08); }
.icon-btn:active { transform: translateY(0); }
.icon-svg {
  width: 18px;
  height: 18px;
  display: inline-block;
  background-color: currentColor;
  mask-repeat: no-repeat;
  -webkit-mask-repeat: no-repeat;
  mask-position: center;
  -webkit-mask-position: center;
  mask-size: contain;
  -webkit-mask-size: contain;
}
.icon-svg[data-icon="menu"] { mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M4 7h16M4 12h16M4 17h16'/%3E%3C/svg%3E"); -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M4 7h16M4 12h16M4 17h16'/%3E%3C/svg%3E"); }
.icon-svg[data-icon="compose"] { mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 20h9'/%3E%3Cpath d='M16.5 3.5a2.12 2.12 0 1 1 3 3L7 19l-4 1 1-4Z'/%3E%3C/svg%3E"); -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 20h9'/%3E%3Cpath d='M16.5 3.5a2.12 2.12 0 1 1 3 3L7 19l-4 1 1-4Z'/%3E%3C/svg%3E"); }
.icon-svg[data-icon="logout"] { mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4'/%3E%3Cpath d='m16 17 5-5-5-5'/%3E%3Cpath d='M21 12H9'/%3E%3C/svg%3E"); -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4'/%3E%3Cpath d='m16 17 5-5-5-5'/%3E%3Cpath d='M21 12H9'/%3E%3C/svg%3E"); }
.icon-svg[data-icon="send"] { mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M22 2 11 13'/%3E%3Cpath d='M22 2 15 22l-4-9-9-4Z'/%3E%3C/svg%3E"); -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M22 2 11 13'/%3E%3Cpath d='M22 2 15 22l-4-9-9-4Z'/%3E%3C/svg%3E"); }
.icon-svg[data-icon="star"] { mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='black'%3E%3Cpath d='m12 17.27 6.18 3.73-1.64-7.03L22 9.24l-7.19-.61L12 2 9.19 8.63 2 9.24l5.46 4.73L5.82 21z'/%3E%3C/svg%3E"); -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='black'%3E%3Cpath d='m12 17.27 6.18 3.73-1.64-7.03L22 9.24l-7.19-.61L12 2 9.19 8.63 2 9.24l5.46 4.73L5.82 21z'/%3E%3C/svg%3E"); }
.icon-svg[data-icon="close"] { mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M18 6 6 18M6 6l12 12'/%3E%3C/svg%3E"); -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M18 6 6 18M6 6l12 12'/%3E%3C/svg%3E"); }
.icon-svg[data-icon="trash"] { mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 6h18'/%3E%3Cpath d='M8 6V4h8v2'/%3E%3Cpath d='m19 6-1 14H6L5 6'/%3E%3Cpath d='M10 11v6M14 11v6'/%3E%3C/svg%3E"); -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 6h18'/%3E%3Cpath d='M8 6V4h8v2'/%3E%3Cpath d='m19 6-1 14H6L5 6'/%3E%3Cpath d='M10 11v6M14 11v6'/%3E%3C/svg%3E"); }
.icon-svg[data-icon="spark"] { mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m12 3 1.8 5.2L19 10l-5.2 1.8L12 17l-1.8-5.2L5 10l5.2-1.8Z'/%3E%3C/svg%3E"); -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m12 3 1.8 5.2L19 10l-5.2 1.8L12 17l-1.8-5.2L5 10l5.2-1.8Z'/%3E%3C/svg%3E"); }
.icon-svg[data-icon="briefcase"] { mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='7' width='18' height='12' rx='2'/%3E%3Cpath d='M8 7V5a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2'/%3E%3C/svg%3E"); -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='7' width='18' height='12' rx='2'/%3E%3Cpath d='M8 7V5a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2'/%3E%3C/svg%3E"); }
.icon-svg[data-icon="chart"] { mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 19h16'/%3E%3Cpath d='M7 16V9'/%3E%3Cpath d='M12 16V5'/%3E%3Cpath d='M17 16v-7'/%3E%3C/svg%3E"); -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 19h16'/%3E%3Cpath d='M7 16V9'/%3E%3Cpath d='M12 16V5'/%3E%3Cpath d='M17 16v-7'/%3E%3C/svg%3E"); }
.icon-svg[data-icon="shield"] { mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 3 5 6v6c0 5 3.5 8 7 9 3.5-1 7-4 7-9V6z'/%3E%3C/svg%3E"); -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 3 5 6v6c0 5 3.5 8 7 9 3.5-1 7-4 7-9V6z'/%3E%3C/svg%3E"); }
.icon-svg[data-icon="compass"] { mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='9'/%3E%3Cpath d='m15.5 8.5-3.2 7.2-3.8-3.8z'/%3E%3C/svg%3E"); -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='9'/%3E%3Cpath d='m15.5 8.5-3.2 7.2-3.8-3.8z'/%3E%3C/svg%3E"); }
.icon-svg[data-icon="sliders"] { mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M4 21v-7'/%3E%3Cpath d='M4 10V3'/%3E%3Cpath d='M12 21v-9'/%3E%3Cpath d='M12 8V3'/%3E%3Cpath d='M20 21v-4'/%3E%3Cpath d='M20 13V3'/%3E%3Cpath d='M2 14h4'/%3E%3Cpath d='M10 8h4'/%3E%3Cpath d='M18 13h4'/%3E%3C/svg%3E"); -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M4 21v-7'/%3E%3Cpath d='M4 10V3'/%3E%3Cpath d='M12 21v-9'/%3E%3Cpath d='M12 8V3'/%3E%3Cpath d='M20 21v-4'/%3E%3Cpath d='M20 13V3'/%3E%3Cpath d='M2 14h4'/%3E%3Cpath d='M10 8h4'/%3E%3Cpath d='M18 13h4'/%3E%3C/svg%3E"); }
.icon-svg[data-icon="house"] { mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='black'%3E%3Cpath d='M12 3 3 10v11h6v-6h6v6h6V10z'/%3E%3C/svg%3E"); -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='black'%3E%3Cpath d='M12 3 3 10v11h6v-6h6v6h6V10z'/%3E%3C/svg%3E"); }
.icon-svg[data-icon="globe"] { mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='9'/%3E%3Cpath d='M3 12h18'/%3E%3Cpath d='M12 3a15 15 0 0 1 0 18'/%3E%3Cpath d='M12 3a15 15 0 0 0 0 18'/%3E%3C/svg%3E"); -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='9'/%3E%3Cpath d='M3 12h18'/%3E%3Cpath d='M12 3a15 15 0 0 1 0 18'/%3E%3Cpath d='M12 3a15 15 0 0 0 0 18'/%3E%3C/svg%3E"); }
.icon-svg[data-icon="users"] { mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2'/%3E%3Ccircle cx='9' cy='7' r='4'/%3E%3Cpath d='M22 21v-2a4 4 0 0 0-3-3.87'/%3E%3Cpath d='M16 3.13a4 4 0 0 1 0 7.75'/%3E%3C/svg%3E"); -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2'/%3E%3Ccircle cx='9' cy='7' r='4'/%3E%3Cpath d='M22 21v-2a4 4 0 0 0-3-3.87'/%3E%3Cpath d='M16 3.13a4 4 0 0 1 0 7.75'/%3E%3C/svg%3E"); }
.icon-send { width: 16px; height: 16px; }

.messages {
  flex: 1;
  padding: 18px 24px calc(var(--composer-offset) + 24px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-width: 980px;
  width: 100%;
  margin: 0 auto;
  min-width: 0;
}
.message { display: flex; flex-direction: column; gap: 6px; max-width: 900px; }
.message.user { align-self: flex-end; }
.message.assistant { align-self: flex-start; }
.message-role { font-size: 12px; color: var(--muted); padding: 0 4px; }
.message-bubble {
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 16px 18px;
  background: linear-gradient(180deg, rgba(255,255,255,0.98), rgba(251,252,254,0.98));
  box-shadow: var(--shadow);
}
.message.user .message-bubble { background: linear-gradient(180deg, #f4f7fb, #edf2f8); }
.message-text { word-break: break-word; font-size: 15px; line-height: 1.62; }
.message-text p { margin: 0; }
.message-text p + p,
.message-text p + ul,
.message-text ul + p,
.message-text ul + ul { margin-top: 10px; }
.message-text ul { margin: 0; padding-left: 20px; }
.message-text li + li { margin-top: 6px; }
.meta-block { margin-top: 12px; padding: 10px 12px; border-radius: 14px; background: var(--surface-soft); color: var(--muted); border: 1px solid var(--border); }
.sources-wrap { margin-top: 12px; display: grid; gap: 8px; }
.message.assistant .sources-wrap {
  position: sticky;
  top: 70px;
  z-index: 3;
  padding: 12px;
  border: 1px solid rgba(221, 227, 234, 0.92);
  border-radius: 18px;
  background: rgba(255,255,255,0.9);
  backdrop-filter: blur(10px);
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.08);
}
.sources-title { font-size: 12px; font-weight: 600; color: var(--muted); }
.sources-list { display: grid; gap: 8px; }
.message.assistant .sources-list {
  max-height: min(42vh, 320px);
  overflow: auto;
  padding-right: 4px;
}
.source-card {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 10px 12px;
  background: linear-gradient(180deg, #fbfcfe, #f6f9fc);
}
.source-card-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.source-title { font-size: 13px; font-weight: 600; color: var(--text); }
.source-path { margin-top: 4px; font-size: 12px; color: var(--muted); word-break: break-word; }
.source-badge {
  flex: 0 0 auto;
  font-size: 11px;
  font-weight: 700;
  padding: 4px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: #f5f7fa;
  color: #5b6471;
}
.source-badge.approved { background: #eefbf3; color: #1f7a45; border-color: #cfead8; }
.source-badge.distilled { background: #eef6ff; color: #365d96; border-color: #d3e2f7; }
.source-badge.working { background: #fff4ea; color: #9a5a10; border-color: #f0d8bd; }
.source-badge.raw { background: #f8f3ff; color: #7052a8; border-color: #e1d7f3; }
.attachments { margin-top: 12px; display: grid; gap: 12px; }
.attachment-group { display: grid; gap: 8px; }
.attachment-group-title { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; padding-left: 2px; }
.followups-wrap {
  margin-top: 14px;
  padding-top: 2px;
}
.followups-title {
  margin-bottom: 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}
.followups { display: flex; flex-wrap: wrap; gap: 8px; }
.followup-chip {
  border: 1px solid var(--border);
  border-radius: 999px;
  background: linear-gradient(180deg, #ffffff, #f7faff);
  color: var(--text);
  padding: 9px 13px;
  max-width: 100%;
  text-align: left;
  box-shadow: 0 6px 16px rgba(15, 23, 42, 0.04);
  transition: transform .18s ease, box-shadow .18s ease, background .18s ease;
}
.followup-chip:hover {
  transform: translateY(-1px);
  background: linear-gradient(180deg, #ffffff, #edf4fd);
  box-shadow: 0 10px 22px rgba(15, 23, 42, 0.08);
}
.followup-chip:active { transform: translateY(0); }
.attachment-card { border: 1px solid var(--border); border-radius: 16px; padding: 12px; background: linear-gradient(180deg, #fbfcfe, #f6f9fc); }
.attachment-badge-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.attachment-badge { font-size: 11px; font-weight: 700; padding: 4px 8px; border-radius: 999px; background: #e9eef6; color: #475569; text-transform: uppercase; letter-spacing: .06em; }
.attachment-smart-chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.attachment-smart-chip { font-size: 11px; font-weight: 700; padding: 4px 8px; border-radius: 999px; border: 1px solid var(--border); background: #fff; color: #475569; letter-spacing: .02em; }
.attachment-smart-chip.primary { background: #edf6ff; color: #285ea8; border-color: #cfe0f6; }
.attachment-smart-chip.followup { background: #f5f7fa; color: #5b6471; }
.attachment-smart-chip.backup { background: #f8f3ff; color: #7052a8; border-color: #e1d7f3; }
.attachment-smart-chip.proof { background: #eefbf3; color: #1f7a45; border-color: #cfead8; }
.attachment-smart-chip.objection { background: #fff4ea; color: #9a5a10; border-color: #f0d8bd; }
.attachment-smart-chip.visual { background: #eef6ff; color: #365d96; border-color: #d3e2f7; }
.attachment-smart-chip.deck { background: #f4f0ff; color: #6752a6; border-color: #ddd6f7; }
.attachment-note { margin-top: 6px; font-size: 12px; color: var(--text); opacity: .82; }
.attachment-card.image-card { padding: 10px; }
.attachment-preview { width: 100%; aspect-ratio: 16 / 10; border-radius: 12px; overflow: hidden; border: 1px solid var(--border); background: #fff; margin-bottom: 10px; padding: 0; }
.attachment-preview img { width: 100%; height: 100%; object-fit: cover; display: block; }
.attachment-preview.pdf-preview img { object-fit: contain; background: #f8fafc; }
.attachment-card a {
  color: var(--text);
  text-decoration: none;
  display: inline-flex;
  align-items: flex-start;
  gap: 8px;
  min-width: 0;
  max-width: 100%;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.attachment-name { min-width: 0; overflow-wrap: anywhere; word-break: break-word; }
.attachment-meta { margin-top: 4px; font-size: 12px; color: var(--muted); word-break: break-word; overflow-wrap: anywhere; }
.attachment-actions { margin-top: 10px; display: flex; gap: 8px; flex-wrap: wrap; }
.attachment-open { border: 1px solid var(--border); border-radius: 999px; background: #fff; color: var(--text); padding: 8px 12px; text-decoration: none; display: inline-flex; align-items: center; min-width: 0; max-width: 100%; }
.message-footer { margin-top: 10px; display: flex; justify-content: flex-end; }
.favorite-btn { width: 32px; height: 32px; }
.favorite-btn.active { background: #111827; color: #fff; border-color: #111827; }

.composer {
  position: fixed;
  left: var(--sidebar-w);
  right: 0;
  bottom: 0;
  padding: 12px 20px calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(180deg, rgba(243,245,248,0), rgba(243,245,248,0.82) 34%, rgba(243,245,248,0.98));
}
.composer-inner {
  max-width: 980px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  padding: 8px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(255,255,255,0.97), rgba(250,252,255,0.97));
  box-shadow: 0 14px 30px rgba(15, 23, 42, 0.07);
  min-width: 0;
}
.composer-mobile-actions { display: none; grid-column: 1 / -1; }
.composer-options-btn {
  border: 1px solid var(--border);
  border-radius: 999px;
  background: linear-gradient(180deg, #ffffff, #f6f9fc);
  color: var(--text);
  min-height: 38px;
  padding: 0 12px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
}
.composer-options-btn .icon-svg { width: 15px; height: 15px; }
.composer-toolbar { display: flex; gap: 8px; grid-column: 1 / -1; flex-wrap: wrap; padding: 2px 2px 0; }
.composer-entry {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: stretch;
  min-width: 0;
}
.scenario-chips { display: flex; gap: 8px; flex-wrap: wrap; width: 100%; align-items: center; }
.scenario-chip {
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: linear-gradient(180deg, #ffffff, #f6f9fc);
  color: var(--text);
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.04);
  transition: transform .18s ease, box-shadow .18s ease, background .18s ease, border-color .18s ease;
}
.scenario-chip:hover { transform: translateY(-1px); box-shadow: 0 8px 18px rgba(15, 23, 42, 0.08); }
.scenario-chip .icon-svg { width: 15px; height: 15px; }
.scenario-chip.active {
  background: linear-gradient(180deg, #111827, #1f2937);
  color: #fff;
  border-color: #111827;
}
.composer-select-wrap { display: grid; gap: 5px; min-width: 170px; }
.composer-select-wide { min-width: 240px; }
.composer-select-wrap span { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
.composer-select-wrap select {
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-soft);
  color: var(--text);
  padding: 9px 10px;
  outline: none;
}
.composer-switch-wrap { display: grid; gap: 5px; min-width: 0; width: max-content; }
.composer-switch-wrap span { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; padding-left: 4px; }
.visibility-toggle {
  display: inline-grid;
  grid-template-columns: repeat(2, 32px);
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(244,247,250,0.96), rgba(236,241,246,0.96));
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.72), 0 6px 16px rgba(15, 23, 42, 0.06);
}
.visibility-option {
  width: 32px;
  height: 28px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: #6b7280;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background .18s ease, color .18s ease, transform .18s ease, box-shadow .18s ease;
}
.visibility-option .icon-svg { width: 14px; height: 14px; background-color: #6b7280; }
.visibility-option.active .icon-svg { background-color: #ffffff; }
.visibility-option.active {
  background: linear-gradient(180deg, #1f2937, #111827);
  color: #fff;
  box-shadow: 0 2px 6px rgba(15, 23, 42, 0.14);
}
textarea { resize: none; min-height: 54px; max-height: 180px; padding: 13px 15px; border-radius: 16px; border: 1px solid transparent; background: transparent; color: var(--text); outline: none; }
textarea::placeholder,
input::placeholder { color: #9ca3af; }
.send-btn,
.login-form button { border: none; border-radius: 16px; min-width: 52px; padding: 0 16px; background: var(--accent); color: #fff; font-weight: 600; }
.typing .message-bubble { border-style: dashed; }

.auth-overlay { position: fixed; inset: 0; background: rgba(243,245,248,0.84); backdrop-filter: blur(10px); display: grid; place-items: center; z-index: 20; padding: 24px; }
.auth-card { width: min(100%, 420px); background: linear-gradient(180deg, rgba(255,255,255,0.99), rgba(248,250,253,0.98)); border: 1px solid var(--border); border-radius: 28px; padding: 28px; box-shadow: var(--shadow); text-align: center; }
.auth-logo { width: 120px; height: 120px; object-fit: contain; margin: 0 auto 18px; }
.auth-card h2 { margin: 0 0 10px; font-size: 28px; letter-spacing: -0.03em; }
.auth-tagline { margin: 0; color: var(--muted); }
.login-form { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; margin-top: 22px; }
.login-form.users-mode { grid-template-columns: 1fr; }
.login-form input { min-width: 0; border-radius: 18px; border: 1px solid var(--border); background: var(--surface-soft); color: var(--text); padding: 15px 16px; outline: none; }
.login-error { margin-top: 12px; color: #c43d3d; }

.admin-modal { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; padding: 20px; }
.admin-backdrop { position: absolute; inset: 0; background: rgba(17, 24, 39, 0.48); backdrop-filter: blur(4px); }
.admin-card { position: relative; width: min(100%, 920px); max-height: 88vh; overflow: auto; border-radius: 24px; border: 1px solid var(--border); background: linear-gradient(180deg, rgba(255,255,255,0.98), rgba(247,250,253,0.98)); box-shadow: 0 24px 80px rgba(15, 23, 42, 0.18); padding: 18px; }
.admin-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.admin-title { font-size: 20px; font-weight: 700; }
.admin-subtitle { font-size: 12px; color: var(--muted); }
.admin-user-form { display: grid; grid-template-columns: 1fr 1fr 1fr auto; gap: 10px; margin-bottom: 14px; }
.admin-user-form input { min-width: 0; border-radius: 14px; border: 1px solid var(--border); background: var(--surface-soft); padding: 12px 14px; }
.admin-user-form button { border: none; border-radius: 14px; background: var(--accent); color: #fff; padding: 0 16px; font-weight: 600; }
.admin-users-list { display: grid; gap: 10px; }
.admin-user-card { border: 1px solid var(--border); border-radius: 18px; background: linear-gradient(180deg, #fff, #f8fafc); padding: 14px; }
.admin-user-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.admin-user-name { font-weight: 700; }
.admin-user-meta { font-size: 12px; color: var(--muted); margin-top: 4px; }
.admin-user-stats { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.admin-stat { font-size: 11px; padding: 4px 8px; border-radius: 999px; background: var(--surface-soft); color: var(--muted); border: 1px solid var(--border); }
.admin-user-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.admin-action { border: 1px solid var(--border); border-radius: 999px; background: #fff; color: var(--text); padding: 8px 12px; }
.admin-action.danger { color: #9a3412; }

.media-preview { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; padding: 24px; }
.media-preview-backdrop { position: absolute; inset: 0; background: rgba(17, 24, 39, 0.66); backdrop-filter: blur(6px); }
.media-preview-card { position: relative; max-width: min(92vw, 1200px); max-height: 88vh; padding: 14px; border-radius: 24px; background: rgba(255,255,255,0.97); box-shadow: 0 20px 80px rgba(16, 24, 40, 0.18); }
.media-preview-image { display: block; max-width: 100%; max-height: calc(88vh - 28px); border-radius: 18px; }
.media-preview-close { position: absolute; top: 14px; right: 14px; width: 36px; height: 36px; border: 1px solid rgba(255,255,255,0.7); background: rgba(17,24,39,0.72); color: #fff; border-radius: 999px; }

.sidebar-backdrop { display: none; }

@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: min(78vw, 296px);
    z-index: 20;
    transform: translateX(-100%);
    transition: transform .22s ease, box-shadow .22s ease;
    box-shadow: 0 18px 48px rgba(15, 23, 42, 0.16);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop { display: block; position: fixed; inset: 0; z-index: 19; background: rgba(17, 24, 39, 0.24); backdrop-filter: blur(2px); opacity: 1; transition: opacity .2s ease; }
  .mobile-only { display: inline-flex; }
  .sidebar-item-actions { opacity: 1; }
  .messages { padding: 14px 14px 114px; }
  .messages { padding-bottom: calc(var(--composer-offset) + 22px + env(safe-area-inset-bottom)); }
  .message.assistant .sources-wrap {
    position: static;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    backdrop-filter: none;
    box-shadow: none;
  }
  .message.assistant .sources-list {
    max-height: none;
    overflow: visible;
    padding-right: 0;
  }
  .composer { left: 0; padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); }
  .topbar.compact { min-height: 50px; padding: 7px 10px; }
  .topbar-logo { width: 30px; height: 30px; }
  .topbar-title { font-size: 15px; }
  .topbar-status { font-size: 11px; }
}

@media (max-width: 640px) {
  .login-form { grid-template-columns: 1fr; }
  .composer-inner { grid-template-columns: minmax(0, 1fr) auto; }
  .admin-user-form { grid-template-columns: 1fr; }
  .composer-mobile-actions { display: flex; }
  .messages {
    gap: 12px;
    padding: 12px 12px 108px;
    padding-bottom: calc(var(--composer-offset) + 18px + env(safe-area-inset-bottom));
  }
  .message {
    max-width: 100%;
    gap: 4px;
  }
  .message-role {
    font-size: 11px;
    padding: 0 2px;
  }
  .composer-inner { gap: 5px; padding: 6px; border-radius: 16px; box-shadow: 0 8px 20px rgba(15, 23, 42, 0.07); }
  .composer-options-btn { min-height: 34px; padding: 0 10px; font-size: 12px; gap: 6px; }
  .composer-toolbar { display: none; padding: 0; gap: 6px; }
  .message.user .message-bubble {
    max-width: min(78vw, 380px);
    margin-left: auto;
    background: linear-gradient(180deg, #dfe8fb, #d2def7);
    border-color: rgba(110, 136, 189, 0.46);
    box-shadow: 0 10px 24px rgba(47, 88, 168, 0.11);
  }
  .message.assistant .message-bubble {
    max-width: min(84vw, 680px);
    background: linear-gradient(180deg, rgba(255,255,255,0.97), rgba(247,249,252,0.95));
    border-color: rgba(204, 214, 228, 0.95);
    box-shadow: 0 10px 24px rgba(15, 23, 42, 0.06);
    backdrop-filter: blur(1.5px);
  }
  .composer-entry {
    gap: 0;
    background: var(--surface-soft);
    border: 1px solid var(--border);
    border-radius: 14px;
    overflow: hidden;
  }
  .composer-toolbar.mobile-open {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 6px;
  }
  .composer-select-wrap,
  .composer-select-wide,
  .composer-switch-wrap { min-width: 0; }
  .composer-select-wrap { width: 100%; }
  .composer-switch-wrap { width: auto; }
  .composer-select-wrap > span,
  .composer-switch-wrap > span { display: none; }
  .composer-select-wrap select { min-height: 38px; padding: 7px 10px; font-size: 14px; }
  .scenario-chips { grid-column: 1 / -1; flex-wrap: nowrap; overflow-x: auto; padding-bottom: 2px; width: 100%; gap: 6px; }
  .scenario-chip { width: 34px; height: 34px; flex: 0 0 auto; }
  .visibility-toggle { width: auto; min-width: 74px; padding: 3px; border-radius: 999px; }
  .visibility-option { width: 32px; height: 28px; border-radius: 999px; }
  textarea { min-height: 48px; padding: 10px 12px; border-radius: 14px 0 0 14px; background: transparent; }
  .send-btn,
  .login-form button { min-height: 46px; }
  .send-btn { width: 46px; min-width: 46px; padding: 0; border-radius: 0 14px 14px 0; box-shadow: none; }
  .message-bubble { padding: 12px 14px; border-radius: 18px; }
  .message-text { font-size: 14px; line-height: 1.58; }
  .message-text p + p,
  .message-text p + ul,
  .message-text ul + p,
  .message-text ul + ul { margin-top: 8px; }
  .message-text li + li { margin-top: 4px; }
  .meta-block { margin-top: 10px; padding: 9px 11px; }
  .attachments { margin-top: 10px; gap: 10px; }
  .followups-wrap { margin-top: 10px; }
  .attachment-actions { gap: 6px; }
  .attachment-open { font-size: 13px; padding: 7px 10px; }
  .followup-chip { font-size: 13px; padding: 8px 10px; }
}

@media (hover: none) {
  .sidebar-item-actions { opacity: 1; }
}
