/* ============================================
   ✨ Intickets AI — Original Dark Theme
   ============================================ */

:root {
  --color-background: #010106;
  --color-secondary: #454cee;
  --color-hover: #1d20ee;
  --color-block: #08080f;
  --color-block-accent: #14141d;
  --color-block-accent-hover: #304076;
  --color-subtext: #bfc9e9;
  --color-link: #656bff;
  
  --danger: #ef4444;
  --accent: #454cee;
  --accent-hover: #1d20ee;
  
  --sidebar-width: 260px;
  --header-height: 48px;
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --transition: 0.2s ease;
}

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

body {
  font-family: 'Roboto', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background-color: var(--color-background);
  color: #fff;
  min-height: 100vh;
  line-height: 1.5;
}

/* ============================================
   LOGIN PAGE
   ============================================ */

.login-container {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  background-color: var(--color-background);
}

.login-box {
  background: var(--color-block);
  padding: 40px;
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 400px;
  border: 1px solid rgba(255,255,255,0.1);
}

.login-logo {
  display: block;
  width: 80px;
  height: 80px;
  margin: 0 auto -20px;
}

.login-box h1 {
  text-align: center;
  margin-bottom: 28px;
  color: #fff;
  font-size: 26px;
  font-weight: 600;
}
.login-box input {
  width: 100%;
  padding: 12px 14px;
  margin-bottom: 12px;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: var(--radius-md);
  background: var(--color-block-accent);
  color: #fff;
  font-size: 14px;
  transition: border-color var(--transition);
}

.login-box input:focus {
  outline: none;
  border-color: var(--color-secondary);
}

.login-box button {
  width: 100%;
  padding: 12px;
  background: var(--color-secondary);
  color: white;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: background var(--transition);
  margin-top: 8px;
}

.login-box button:hover { background: var(--color-hover); }

/* ============================================
   BUTTONS
   ============================================ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: all var(--transition);
  text-decoration: none;
  white-space: nowrap;
  background: transparent;
  color: #fff;
}

.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: var(--color-secondary);
  color: white;
}

.btn-primary:hover:not(:disabled) { background: var(--color-hover); }

.btn-secondary {
  background: var(--color-block-accent);
  border: 1px solid rgba(255,255,255,0.1);
}

.btn-secondary:hover:not(:disabled) { 
  background: var(--color-block-accent-hover); 
  border-color: rgba(255,255,255,0.2);
}

.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover:not(:disabled) { background: #dc2626; }

.btn-sm { padding: 6px 10px; font-size: 12px; }
.btn-lg { padding: 12px 20px; font-size: 14px; }

/* ============================================
   CHAT LAYOUT
   ============================================ */

.chat-app {
  display: flex;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  background: var(--color-block);
  border-right: 1px solid rgba(255,255,255,0.1);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.sidebar-header {
  padding: 16px 12px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}

.sidebar-header .btn-block {
  width: 100%;
}

.user-profile {
  margin-bottom: 12px;
  padding: 12px;
  background: var(--color-block-accent);
  border-radius: var(--radius-md);
  border: 1px solid rgba(255,255,255,0.1);
}

.user-name {
  font-size: 14px;
  font-weight: 600;
  color: #fff;
  margin-bottom: 4px;
}

.user-login {
  font-size: 12px;
  color: var(--color-subtext);
  margin-bottom: 6px;
  font-family: monospace;
}

.user-dept {
  font-size: 11px;
  color: var(--color-link);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.chat-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.chat-list::-webkit-scrollbar { width: 4px; }
.chat-list::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.2); border-radius: 2px; }

.chat-item {
  padding: 10px 12px;
  border-radius: var(--radius-md);
  cursor: pointer;
  margin-bottom: 2px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: background var(--transition);
  font-size: 13px;
}

.chat-item:hover { background: var(--color-block-accent); }

.chat-item.active {
  background: var(--color-block-accent-hover);
}

.chat-title {
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.delete-chat {
  color: var(--color-subtext);
  cursor: pointer;
  font-size: 16px;
  padding: 2px 6px;
  border-radius: 4px;
  opacity: 0;
  transition: all var(--transition);
}

.chat-item:hover .delete-chat { opacity: 1; }
.delete-chat:hover { color: var(--danger); background: rgba(239, 68, 68, 0.1); }

.sidebar-footer {
  padding: 12px;
  border-top: none;
}

.sidebar-footer .btn-block {
  width: 100%;
}

.sidebar-footer .user-profile {
  margin-bottom: 0;
  border: none;
}

/* Main Chat */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--color-background);
}

.chat-header {
  height: var(--header-height);
  padding: 0 20px;
  border-bottom: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--color-background);
  flex-shrink: 0;
}

#chatTitle {
  font-size: 14px;
  font-weight: 500;
  color: #fff;
}

.mode-toggle {
  display: flex;
  gap: 4px;
  background: var(--color-block-accent);
  padding: 3px;
  border-radius: var(--radius-md);
}

.mode-toggle button {
  padding: 6px 12px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--color-subtext);
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  transition: all var(--transition);
}

.mode-toggle button:hover { color: #fff; }
.mode-toggle button.active { background: var(--color-secondary); color: white; }

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

.messages::-webkit-scrollbar { width: 6px; }
.messages::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.2); border-radius: 3px; }

.message {
  display: flex;
  gap: 12px;
  max-width: 100%;
  width: 100%;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.message.user {
  justify-content: flex-end;
}

.message.user .message-content {
  align-items: flex-end;
}

.message.user .message-meta {
  justify-content: flex-end;
}

.message.assistant {
  justify-content: flex-start;
}

.message.assistant .message-content {
  align-items: flex-start;
}

.message.assistant.loading {
    flex-direction: row;
    align-items: flex-start;
}

.loading-logo {
    width: 24px;
    height: 24px;
    margin-right: 12px;
    margin-top: 10px;
    flex-shrink: 0;
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

.loading-logo.thinking {
    animation: thinkSpin 2s linear infinite, thinkGlow 1.5s ease-in-out infinite;
    filter: drop-shadow(0 0 6px var(--color-secondary));
}

@keyframes thinkSpin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

@keyframes thinkGlow {
    0%, 100% { filter: drop-shadow(0 0 4px var(--color-secondary)); }
    50% { filter: drop-shadow(0 0 12px var(--color-link)); }
}

/* Streaming cursor */
.stream-cursor {
    display: inline-block;
    width: 2px;
    height: 1em;
    background: var(--color-secondary);
    margin-left: 2px;
    vertical-align: text-bottom;
    animation: blink 0.7s steps(2, start) infinite;
}

@keyframes blink {
    to { visibility: hidden; }
}

/* Thinking indicator */
.thinking-indicator {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--color-link);
    font-size: 14px;
    animation: thinkPulse 1.5s ease-in-out infinite;
}

@keyframes thinkPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.message-logo {
    width: 24px;
    height: 24px;
    margin-right: 5px;
    margin-top: 10px;
    flex-shrink: 0;
}

.message-avatar {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
  background: var(--color-block-accent);
}

.message.user .message-avatar { background: var(--color-secondary); }

.message-content {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.message-bubble {
  padding: 12px 16px;
  border-radius: var(--radius-lg);
  font-size: 14px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.message.user .message-bubble {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  border: none;
  border-radius: 20px;
}

.message.assistant .message-bubble {
  background: transparent;
  color: rgba(255, 255, 255, 0.92);
  padding: 0;
  border: none;
  border-radius: 0;
}

.message-warning {
  background: rgba(255, 191, 0, 0.15);
  border: 1px solid rgba(255, 191, 0, 0.3);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  margin-top: 12px;
  font-size: 12px;
  color: #ffbf00;
  font-weight: 500;
}

.message-bubble strong {
  font-weight: 600;
  color: #fff;
}

.message-bubble em {
  font-style: italic;
  color: var(--color-subtext);
}

.message-bubble code {
  background: var(--color-block-accent-hover);
  color: var(--color-link);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-family: 'Consolas', 'Monaco', monospace;
}

.message-bubble h1,
.message-bubble h2,
.message-bubble h3 {
  color: #fff;
  font-weight: 600;
  margin: 16px 0 8px 0;
  line-height: 1.4;
}

.message-bubble h1 { font-size: 20px; }
.message-bubble h2 { font-size: 18px; }
.message-bubble h3 { font-size: 16px; }

.message-bubble ul {
  margin: 8px 0;
  padding-left: 20px;
  list-style-type: disc;
}

.message-bubble ul li.special {
  list-style-type: none;
  position: relative;
  padding-left: 12px;
}

.message-bubble ul li.special::before {
  content: '>';
  position: absolute;
  left: -16px;
  color: var(--color-secondary);
  font-weight: 600;
}

.message-bubble li {
  margin: 4px 0;
  line-height: 1.6;
}

.message-bubble table {
  width: 100%;
  border-collapse: collapse;
  margin: 16px 0;
  font-size: 13px;
}

.message-bubble table th,
.message-bubble table td {
  padding: 10px 12px;
  border: 1px solid rgba(255,255,255,0.1);
  text-align: left;
}

.message-bubble table th {
  background: var(--color-block-accent-hover);
  color: #fff;
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.message-bubble table td {
  background: var(--color-block-accent);
  color: var(--color-subtext);
}

.message-bubble table tr:hover td {
  background: rgba(255,255,255,0.05);
}

.used-docs {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  margin-top: 12px;
  width: 13%;
}

.used-docs > span:first-child {
  width: 100%;
}

.used-docs span:not(:first-child) {
  background: var(--color-block-accent);
  color: var(--color-subtext);
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  font-size: 11px;
  border: 1px solid rgba(255,255,255,0.1);
  cursor: pointer;
  transition: all var(--transition);
}

.used-docs span:not(:first-child):hover {
  background: var(--color-block-accent-hover);
  color: #fff;
  border-color: var(--color-secondary);
}

.doc-link {
  cursor: pointer;
}

/* Input */
.chat-input-area {
  padding: 16px 20px;
  border-top: none;
  background: var(--color-background);
  display: flex;
  gap: 10px;
  align-items: flex-end;
  flex-shrink: 0;
  position: relative;
}

.input-wrapper {
  position: relative;
  flex: 1;
  display: flex;
  align-items: stretch;
}

.chat-input-area textarea {
  flex: 1;
  padding: 12px 50px 12px 16px;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: var(--radius-lg);
  background: var(--color-block-accent);
  color: #fff;
  font-size: 14px;
  resize: none;
  min-height: 120px;
  max-height: 200px;
  font-family: inherit;
  line-height: 1.5;
  transition: border-color var(--transition);
}

.chat-input-area textarea:focus {
  outline: none;
  border-color: var(--color-secondary);
}

.chat-input-area textarea::placeholder { color: var(--color-subtext); }

.chat-input-area button {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  padding: 10px 14px;
  background: var(--color-secondary);
  color: white;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: 16px;
  font-weight: 500;
  transition: background var(--transition);
  height: 36px;
  min-width: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chat-input-area button:hover:not(:disabled) { background: var(--color-hover); }
.chat-input-area button:disabled { background: var(--color-block-accent); color: var(--color-subtext); cursor: not-allowed; }

.empty-chat {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  height: 100%;
  color: var(--color-subtext);
  font-size: 14px;
}

.empty-state-icon { font-size: 48px; margin-bottom: 16px; opacity: 0.5; }

/* ============================================
   ADMIN PANEL
   ============================================ */

.admin-app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

.admin-sidebar {
  width: 240px;
  background: var(--color-block);
  border-right: 1px solid rgba(255,255,255,0.1);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.admin-sidebar > div:first-child {
  padding: 16px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}

.admin-sidebar > div:first-child strong {
  color: #fff;
  font-size: 16px;
  font-weight: 600;
}

.nav-item {
  padding: 12px 16px;
  cursor: pointer;
  border-bottom: 1px solid transparent;
  font-size: 13px;
  color: var(--color-subtext);
  transition: all var(--transition);
  display: flex;
  align-items: center;
  gap: 10px;
}

.nav-item:hover { background: var(--color-block-accent); color: #fff; }

.nav-item.active {
  background: var(--color-block-accent-hover);
  color: var(--color-link);
  border-left: 3px solid var(--color-link);
  padding-left: 13px;
}

.nav-item:last-child {
  margin-top: auto;
  border-top: 1px solid rgba(255,255,255,0.1);
}

.admin-content {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  background: var(--color-background);
}

.admin-content::-webkit-scrollbar { width: 6px; }
.admin-content::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.2); border-radius: 3px; }

.admin-content h2 {
  margin-bottom: 20px;
  color: #fff;
  font-size: 20px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}

.admin-card {
  background: var(--color-block);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 16px;
  border: 1px solid rgba(255,255,255,0.1);
}

.admin-card h3 {
  margin-bottom: 16px;
  font-size: 14px;
  font-weight: 600;
  color: #fff;
}

.form-group { margin-bottom: 16px; }

.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--color-subtext);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: var(--radius-md);
  background: var(--color-block-accent);
  color: #fff;
  font-size: 13px;
  font-family: inherit;
  transition: border-color var(--transition);
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--color-secondary);
}

.form-group textarea {
  min-height: 100px;
  resize: vertical;
  line-height: 1.5;
}

.form-row { display: flex; gap: 12px; }
.form-row .form-group { flex: 1; }

/* Tables */
.table-simple {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.table-simple th,
.table-simple td {
  padding: 12px;
  text-align: left;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}

.table-simple th {
  color: var(--color-subtext);
  font-weight: 500;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  background: var(--color-block-accent);
}

.table-simple tr:hover td { background: var(--color-block-accent); }
.table-simple td:last-child { text-align: right; }

/* Index Entries */
.index-entry {
  background: var(--color-block-accent);
  border-radius: var(--radius-md);
  padding: 14px;
  margin-bottom: 10px;
  border: 1px solid rgba(255,255,255,0.1);
}

.entry-title {
  font-weight: 500;
  font-size: 14px;
  color: #fff;
  margin-bottom: 6px;
}

.entry-meta {
  font-size: 12px;
  color: var(--color-subtext);
  margin-bottom: 4px;
}

/* Tags */
.tag {
  display: inline-block;
  background: var(--color-block-accent);
  color: var(--color-subtext);
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  font-size: 11px;
  margin: 2px;
  border: 1px solid rgba(255,255,255,0.1);
}

/* Toast */
.toast {
  position: fixed;
  top: 16px;
  right: 16px;
  padding: 12px 20px;
  border-radius: var(--radius-md);
  color: white;
  font-size: 13px;
  font-weight: 500;
  z-index: 3000;
  animation: slideIn 0.3s ease;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

@keyframes slideIn {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}

.toast.success { background: var(--color-secondary); }
.toast.error { background: var(--danger); }

/* Modal */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(4px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 2000;
  animation: fadeIn 0.2s ease;
}

.modal-content {
  background: var(--color-block);
  border-radius: var(--radius-lg);
  width: 90%;
  max-width: 640px;
  max-height: 85vh;
  overflow-y: auto;
  border: 1px solid rgba(255,255,255,0.1);
  animation: slideUp 0.3s ease;
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  position: sticky;
  top: 0;
  background: var(--color-block);
  z-index: 1;
}

.modal-header h3 {
  color: #fff;
  font-size: 16px;
  font-weight: 600;
}

.modal-close {
  font-size: 20px;
  color: var(--color-subtext);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  transition: color var(--transition);
}

.modal-close:hover { color: #fff; }

.modal-body { padding: 20px; }

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 16px 20px;
  border-top: 1px solid rgba(255,255,255,0.1);
  background: var(--color-block);
  position: sticky;
  bottom: 0;
}

/* Doc Row */
.doc-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: var(--color-block-accent);
  border-radius: var(--radius-md);
  margin: 6px 0;
  border: 1px solid rgba(255,255,255,0.1);
}

.doc-row:hover { border-color: rgba(255,255,255,0.2); }

.doc-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
  color: #fff;
}

/* Loading */
.loading {
  text-align: center;
  padding: 40px;
  color: var(--color-subtext);
  font-size: 14px;
}

/* Responsive */
@media (max-width: 768px) {
  .admin-sidebar { width: 100%; height: auto; border-right: none; border-bottom: 1px solid rgba(255,255,255,0.1); }
  .admin-app { flex-direction: column; }
  .admin-content { padding: 16px; }
  .form-row { flex-direction: column; }
}

/* Utilities */
.text-primary { color: #fff; }
.text-secondary { color: var(--color-subtext); }
.text-muted { color: #6b7280; }
.text-accent { color: var(--color-link); }
.text-danger { color: var(--danger); }

.bg-primary { background: var(--color-background); }
.bg-secondary { background: var(--color-block); }
.bg-tertiary { background: var(--color-block-accent); }

.border { border: 1px solid rgba(255,255,255,0.1); }

.rounded-sm { border-radius: var(--radius-sm); }
.rounded-md { border-radius: var(--radius-md); }
.rounded-lg { border-radius: var(--radius-lg); }

.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }

.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: 8px; }
.gap-2 { gap: 16px; }

/* ============================================
   Refined Chat Layout
   ============================================ */

.chat-app {
  position: relative;
  isolation: isolate;
  background:
    radial-gradient(circle at top left, rgba(69, 76, 238, 0.16), transparent 32%),
    radial-gradient(circle at top right, rgba(48, 64, 118, 0.22), transparent 28%),
    linear-gradient(180deg, #04050c 0%, #080b15 52%, #05070e 100%);
}

.chat-app::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image: linear-gradient(rgba(255,255,255,0.03) 1px, transparent 1px),
                    linear-gradient(90deg, rgba(255,255,255,0.03) 1px, transparent 1px);
  background-size: 36px 36px;
  mask-image: linear-gradient(180deg, rgba(0,0,0,0.4), transparent 85%);
  pointer-events: none;
  z-index: -1;
}

.sidebar-backdrop {
  display: none;
}

.sidebar {
  position: relative;
  z-index: 2;
  width: 296px;
  padding: 16px 14px 14px;
  background: rgba(7, 9, 16, 0.88);
  backdrop-filter: blur(22px);
  border-right: 1px solid rgba(255,255,255,0.08);
  box-shadow: 28px 0 80px rgba(0,0,0,0.28);
}

.sidebar-header {
  padding: 0 0 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 6px 2px;
}

.sidebar-brand-logo {
  width: 36px;
  height: 36px;
  padding: 7px;
  border-radius: 12px;
  background: linear-gradient(135deg, rgba(69, 76, 238, 0.35), rgba(101, 107, 255, 0.08));
  border: 1px solid rgba(101, 107, 255, 0.18);
  box-shadow: 0 14px 28px rgba(69, 76, 238, 0.16);
}

.sidebar-brand-text {
  font-size: 18px;
  font-weight: 700;
  color: #fff;
  letter-spacing: 0.02em;
  transform: translateX(20%);
}

.sidebar-brand-ai {
  color: #ef4444;
}

.chat-list {
  padding: 14px 6px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.chat-item {
  margin-bottom: 0;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid transparent;
}

.chat-item:hover {
  background: rgba(255,255,255,0.05);
  border-color: rgba(255,255,255,0.07);
}

.chat-item.active {
  background: linear-gradient(135deg, rgba(48, 64, 118, 0.72), rgba(69, 76, 238, 0.2));
  border-color: rgba(101, 107, 255, 0.26);
}

.delete-chat {
  font-size: 15px;
}

.sidebar-footer {
  padding: 12px 6px 0;
  border-top: 1px solid rgba(255,255,255,0.08);
}

.user-profile {
  padding: 14px;
  border-radius: 18px;
  background: rgba(17, 20, 32, 0.9);
  border: 1px solid rgba(255,255,255,0.08);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.04);
}

.user-name {
  font-size: 15px;
}

.user-login {
  font-size: 12px;
}

.chat-main {
  position: relative;
  background: transparent;
}

.chat-header {
  position: sticky;
  top: 0;
  z-index: 3;
  min-height: 64px;
  height: auto;
  gap: 12px;
  padding: 16px clamp(18px, 3vw, 32px);
  border-bottom: 1px solid rgba(255,255,255,0.07);
  background: rgba(4, 6, 12, 0.72);
  backdrop-filter: blur(18px);
}

#chatTitle {
  flex: 1;
  min-width: 0;
  max-width: 920px;
  font-size: 15px;
  font-weight: 600;
  color: rgba(255,255,255,0.92);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-toggle {
  display: none;
  width: 40px;
  height: 40px;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 12px;
  background: rgba(255,255,255,0.04);
  color: #fff;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition);
}

.sidebar-toggle:hover {
  background: rgba(255,255,255,0.08);
  border-color: rgba(255,255,255,0.16);
}

/* ---- Gemini-style centered chat layout ---- */
.messages {
  gap: 6px;
  align-items: center;
  padding: 28px clamp(18px, 3vw, 34px) 32px;
  scroll-behavior: smooth;
}

.empty-chat {
  width: min(100%, 820px);
  max-width: 100%;
  align-self: center;
}

.message {
  width: min(100%, 820px);
  max-width: 100%;
  gap: 12px;
  align-self: center;
}

.message.user {
  justify-content: flex-end;
  flex-direction: row;
}

.message.assistant {
  justify-content: flex-start;
  flex-direction: row;
}

.message-content {
  gap: 6px;
  min-width: 0;
}

.message.assistant .message-content {
  flex: 1;
  max-width: 100%;
  align-items: flex-start;
}

.message.user .message-content {
  flex: none;
  max-width: 75%;
  align-items: flex-end;
}

.message.user .message-meta {
  justify-content: flex-end;
}

.message-logo,
.loading-logo,
.message-avatar {
  width: 32px;
  height: 32px;
  margin: 0;
  border-radius: 50%;
  flex-shrink: 0;
}

.message-logo,
.loading-logo {
  padding: 5px;
  background: rgba(69, 76, 238, 0.15);
  border: 1px solid rgba(101, 107, 255, 0.18);
  box-shadow: none;
}

.message-avatar {
  font-size: 14px;
  background: linear-gradient(135deg, rgba(69, 76, 238, 0.9), rgba(101, 107, 255, 0.74));
  box-shadow: none;
}

.message-bubble {
  padding: 14px 18px;
  border-radius: 22px;
  line-height: 1.7;
  overflow-wrap: anywhere;
  box-shadow: none;
}

.message.user .message-bubble {
  background: rgba(255, 255, 255, 0.08);
  border: none;
  border-radius: 22px;
  color: #fff;
}

.message.assistant .message-bubble {
  padding: 4px 0;
  background: transparent;
  border: none;
  border-radius: 0;
  color: rgba(255, 255, 255, 0.92);
  box-shadow: none;
}

.message-warning {
  margin-top: 8px;
  backdrop-filter: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: transparent;
  border: none;
  border-radius: 0;
  padding: 0;
}

.message-warning-text {
  font-size: 12px;
  font-weight: 400;
  line-height: 1.45;
  color: rgba(191, 201, 233, 0.5);
}

.message-bubble table {
  display: block;
  overflow-x: auto;
}

.message-sources {
  border-top: 1px solid rgba(255, 191, 0, 0.18);
  padding-top: 8px;
}

.message-sources summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  list-style: none;
  cursor: pointer;
  color: #ffd66b;
  font-size: 12px;
  font-weight: 600;
}

.message-sources summary::-webkit-details-marker {
  display: none;
}

.message-sources-arrow {
  font-size: 11px;
  transition: transform var(--transition);
}

.message-sources[open] .message-sources-arrow {
  transform: rotate(180deg);
}

.used-docs {
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  width: auto;
  max-width: 100%;
}

.used-docs .doc-link {
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 12px;
  line-height: 1.2;
  border: 1px solid rgba(255,255,255,0.1);
  background: rgba(255,255,255,0.05);
  color: var(--color-subtext);
}

.used-docs .doc-link:hover {
  background: var(--color-block-accent-hover);
  color: #fff;
  border-color: var(--color-secondary);
}

.doc-link {
  cursor: pointer;
  appearance: none;
}

.empty-chat {
  min-height: 100%;
  padding: 24px;
  text-align: center;
}

.empty-chat {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 8px;
  border-radius: 28px;
  background: rgba(9, 12, 20, 0.72);
  border: 1px solid rgba(255,255,255,0.08);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.04), 0 30px 80px rgba(0,0,0,0.2);
}

.empty-state-icon,
.empty-chat-logo {
  width: 88px;
  height: 88px;
  margin-bottom: 8px;
  border-radius: 28px;
}

.empty-state-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 40px;
  background: linear-gradient(135deg, rgba(69, 76, 238, 0.28), rgba(101, 107, 255, 0.08));
  border: 1px solid rgba(101, 107, 255, 0.2);
  opacity: 1;
}

.empty-chat-logo {
  padding: 16px;
  background: linear-gradient(135deg, rgba(69, 76, 238, 0.3), rgba(101, 107, 255, 0.08));
  border: 1px solid rgba(101, 107, 255, 0.22);
  box-shadow: 0 20px 48px rgba(69, 76, 238, 0.18);
}

.chat-input-area {
  padding: 18px clamp(18px, 3vw, 34px) 22px;
  border-top: 1px solid rgba(255,255,255,0.07);
  background: linear-gradient(180deg, rgba(4, 6, 12, 0) 0%, rgba(4, 6, 12, 0.82) 28%, #04060c 100%);
}

.input-wrapper {
  width: min(100%, 1040px);
  margin: 0 auto;
}

.chat-input-area textarea {
  min-height: 62px;
  height: 62px;
  max-height: 220px;
  padding: 18px 62px 18px 18px;
  border-radius: 22px;
  background: rgba(10, 13, 22, 0.94);
  border: 1px solid rgba(255,255,255,0.1);
  box-shadow: 0 24px 48px rgba(0,0,0,0.16);
}

.chat-input-area textarea:focus {
  border-color: rgba(101, 107, 255, 0.45);
  box-shadow: 0 0 0 4px rgba(69, 76, 238, 0.12);
}

.chat-input-area button {
  right: 12px;
  top: auto;
  bottom: 10px;
  transform: none;
  width: 42px;
  height: 42px;
  min-width: 42px;
  padding: 0;
  border-radius: 14px;
  box-shadow: 0 14px 30px rgba(69, 76, 238, 0.32);
}

@media (max-width: 980px) {
  html, body {
    overflow: hidden;
    overscroll-behavior: none;
    position: fixed;
    width: 100%;
    height: 100%;
  }

  body.sidebar-open {
    overflow: hidden;
  }

  .chat-app {
    height: 100%;
    height: 100dvh;
    height: var(--vh-real, 100dvh);
    position: fixed;
    inset: 0;
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
  }

  .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 1100;
    background: rgba(0,0,0,0.56);
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition);
  }

  .sidebar-backdrop.open {
    opacity: 1;
    pointer-events: auto;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(86vw, 320px);
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    z-index: 1200;
    padding-top: calc(16px + env(safe-area-inset-top));
    padding-bottom: calc(14px + env(safe-area-inset-bottom));
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .chat-main {
    display: flex;
    flex-direction: column;
    min-height: 0;
    height: 100%;
    overflow: hidden;
  }

  .chat-header {
    flex-shrink: 0;
    min-height: 52px;
    padding: 8px 12px;
    gap: 8px;
  }

  #chatTitle {
    font-size: 14px;
  }

  .mode-selector {
    flex-shrink: 0;
  }

  .mode-btn {
    padding: 4px 10px;
    font-size: 12px;
  }

  .messages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
    padding: 16px 12px 20px;
  }

  .message,
  .empty-chat {
    width: 100%;
  }

  .message {
    gap: 8px;
  }

  .message-logo,
  .loading-logo {
    width: 26px;
    height: 26px;
  }

  .message.assistant .message-content,
  .message.user .message-content {
    max-width: calc(100% - 38px);
  }

  .message.user .message-content {
    max-width: 88%;
  }

  .message-bubble {
    padding: 12px 14px;
    font-size: 14px;
    line-height: 1.6;
  }

  .chat-input-area {
    flex-shrink: 0;
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
    border-top: 1px solid rgba(255,255,255,0.07);
    background: rgba(4, 6, 12, 0.95);
    backdrop-filter: blur(12px);
  }

  .input-wrapper {
    width: 100%;
  }

  .chat-input-area textarea {
    min-height: 44px;
    height: 44px;
    max-height: 120px;
    padding: 11px 52px 11px 14px;
    font-size: 16px;
    border-radius: 22px;
  }

  .chat-input-area button {
    right: 8px;
    bottom: 4px;
    width: 36px;
    height: 36px;
    min-width: 36px;
    border-radius: 12px;
  }

  .empty-chat-logo {
    width: 72px;
    height: 72px;
    padding: 12px;
  }

  .empty-chat-title {
    font-size: 16px;
  }

  .empty-chat-subtitle {
    font-size: 13px;
  }

  .empty-chat {
    padding: 16px;
    border-radius: 20px;
  }

  /* Modals mobile */
  .modal-content,
  .profile-modal-content,
  .confirm-modal-content {
    max-width: calc(100vw - 24px);
    max-height: calc(100vh - 40px);
    max-height: calc(100dvh - 40px);
    margin: 20px auto;
    border-radius: 16px;
  }

  .profile-grid {
    grid-template-columns: 1fr;
  }

  .profile-section-head {
    flex-direction: column;
    align-items: flex-start;
  }

  .doc-modal-content {
    max-width: calc(100vw - 16px);
    max-height: calc(100vh - 24px);
    max-height: calc(100dvh - 24px);
  }
}
