:root {
  --bg: #f4f6fa;
  --bg-gradient: radial-gradient(circle at 50% 50%, #f9fafb 0%, #f4f6fa 100%);
  --surface: #ffffff;
  --surface-hover: #f1f5f9;
  --surface-muted: #f8fafc;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --line-active: #3b82f6;
  --accent: #2563eb;
  --accent-strong: #1d4ed8;
  --accent-soft: #eff6ff;
  --warning: #f59e0b;
  --danger: #ef4444;
  --shadow: 0 4px 20px rgba(15, 23, 42, 0.04), 0 1px 3px rgba(15, 23, 42, 0.02);
  --font-cyber: 'Space Grotesk', 'Inter', system-ui, -apple-system, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  height: 100%;
  font-size: 16px;
  background: var(--bg);
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100%;
  margin: 0;
  background: var(--bg-gradient);
  color: var(--ink);
  font-family: var(--font-cyber);
  -webkit-font-smoothing: antialiased;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.03);
}
::-webkit-scrollbar-thumb {
  background: rgba(59, 130, 246, 0.25);
  border-radius: 99px;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(59, 130, 246, 0.55);
}

button,
input,
textarea,
select {
  font-family: inherit;
  font-size: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.app-navbar {
  min-height: 64px;
  background: rgba(255, 255, 255, 0.88);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  box-shadow: 0 1px 3px rgba(0,0,0,0.02);
}

.navbar-brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink) !important;
  font-weight: 800;
  text-decoration: none;
  font-size: 1.25rem;
}

.brand-mark {
  display: inline-grid;
  width: 32px;
  height: 32px;
  place-items: center;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent) 0%, #8b5cf6 100%);
  color: #ffffff;
  font-weight: 900;
  box-shadow: 0 3px 10px rgba(59, 130, 246, 0.3);
}

.nav-link {
  color: var(--muted) !important;
  font-weight: 600;
  transition: color 0.2s;
}

.nav-link:hover,
.nav-link.active {
  color: var(--accent) !important;
}

.app-shell {
  flex: 1;
  width: min(100%, 1680px);
  margin: 0 auto;
  padding: 18px;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(290px, 360px) minmax(0, 1fr) minmax(280px, 360px);
  gap: 18px;
  min-height: calc(100vh - 104px);
}

.workspace-panel,
.chat-panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.workspace-panel {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 18px;
  overflow: auto;
}

.panel-header,
.chat-header,
.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.panel-header h1,
.panel-header h2,
.chat-header h2,
.section-title h2 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.panel-header h1 {
  font-size: 1.3rem;
  color: var(--ink);
  font-weight: 800;
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.icon-button,
.secondary-button,
.composer button,
.create-form button,
.upload-form button,
.input-row button {
  display: inline-flex;
  min-height: 40px;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  font-weight: 700;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  text-transform: uppercase;
  font-size: 0.8rem;
  letter-spacing: 0.05em;
}

.icon-button {
  width: 40px;
  background: var(--surface-muted);
  color: var(--ink);
  border: 1px solid var(--line);
}

.icon-button:hover {
  background: var(--surface-hover);
  border-color: var(--accent);
  color: var(--accent);
}

.secondary-button {
  padding: 0 14px;
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid rgba(59, 130, 246, 0.25);
}

.secondary-button:hover {
  background: rgba(59, 130, 246, 0.15);
}

.create-form button,
.upload-form button,
.input-row button,
.composer button {
  padding: 0 16px;
  background: var(--accent);
  color: #fff;
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.2);
}

.create-form button:hover,
.upload-form button:hover,
.input-row button:hover,
.composer button:hover {
  background: var(--accent-strong);
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.35);
  transform: translateY(-1px);
}

.setup-form,
.create-form,
.upload-form {
  display: grid;
  gap: 10px;
}

.setup-form label {
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 700;
}

.input-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  transition: all 0.2s ease;
  padding: 0 12px;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
  outline: none;
}

input {
  min-height: 42px;
}

textarea {
  resize: vertical;
  padding: 11px 12px;
}

.helper-text {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.4;
}

.section-block {
  display: grid;
  gap: 12px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.section-title span {
  display: inline-grid;
  min-width: 30px;
  min-height: 26px;
  place-items: center;
  border-radius: 6px;
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid rgba(37, 99, 235, 0.15);
  font-size: 0.82rem;
  font-weight: 700;
}

.dataset-list,
.document-list,
.session-list {
  display: grid;
  gap: 8px;
}

.dataset-item,
.session-item {
  display: grid;
  gap: 4px;
  width: 100%;
  min-height: 68px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-muted);
  color: inherit;
  text-align: left;
  transition: all 0.2s ease;
}

.dataset-item:hover,
.session-item:hover {
  background: var(--surface-hover);
  border-color: rgba(37, 99, 235, 0.2);
  transform: translateX(2px);
}

.dataset-item.active,
.session-item.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: 0 2px 10px rgba(37, 99, 235, 0.08);
}

.dataset-name,
.session-name {
  font-weight: 700;
  font-size: 0.95rem;
}

.dataset-meta,
.session-meta,
.document-meta {
  color: var(--muted);
  font-size: 0.8rem;
}

.document-item {
  display: grid;
  gap: 9px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-muted);
  transition: all 0.2s ease;
}

.document-item:hover {
  background: var(--surface-hover);
}

.document-name {
  display: block;
  overflow-wrap: anywhere;
  font-size: 0.92rem;
  font-weight: 600;
}

.progress-track {
  height: 6px;
  overflow: hidden;
  border-radius: 99px;
  background: rgba(0, 0, 0, 0.05);
}

.progress-fill {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent) 0%, #8b5cf6 100%);
}

.status-pill {
  justify-self: start;
  padding: 4px 10px;
  border-radius: 6px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.74rem;
  font-weight: 700;
  border: 1px solid rgba(37, 99, 235, 0.15);
}

.status-pill.processing {
  background: rgba(245, 158, 11, 0.1);
  color: var(--warning);
  border-color: rgba(245, 158, 11, 0.2);
}

.status-pill.failed {
  background: rgba(239, 68, 68, 0.1);
  color: var(--danger);
  border-color: rgba(239, 68, 68, 0.2);
}

.chat-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
  background: #ffffff;
}

.chat-header {
  min-height: 76px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
  background: #ffffff;
}

.chat-stream {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 0;
  padding: 22px;
  overflow: auto;
  background: radial-gradient(circle at 50% 10%, rgba(59, 130, 246, 0.02) 0%, transparent 60%);
}

.empty-state,
.reference-empty {
  align-self: center;
  max-width: 520px;
  margin: auto;
  color: var(--muted);
  text-align: center;
}

.empty-state h3,
.reference-empty h3 {
  color: var(--ink);
  font-size: 1.3rem;
  font-weight: 700;
  margin-bottom: 10px;
}

.message {
  display: grid;
  gap: 8px;
  max-width: min(780px, 88%);
}

.message.user {
  align-self: flex-end;
}

.message.assistant {
  align-self: flex-start;
}

.message-bubble {
  padding: 14px 16px;
  border-radius: 12px;
  line-height: 1.6;
  overflow-wrap: anywhere;
}

.message.user .message-bubble {
  background: linear-gradient(135deg, var(--accent) 0%, #8b5cf6 100%);
  color: #fff;
  box-shadow: 0 2px 10px rgba(37, 99, 235, 0.15);
  border-bottom-right-radius: 2px;
}

.message.assistant .message-bubble {
  border: 1px solid var(--line);
  background: var(--surface-muted);
  color: var(--ink);
  border-bottom-left-radius: 2px;
}

.message-bubble p,
.message-bubble ul,
.message-bubble ol,
.message-bubble pre {
  margin-top: 0;
}

.message-bubble p:last-child,
.message-bubble ul:last-child,
.message-bubble ol:last-child,
.message-bubble pre:last-child {
  margin-bottom: 0;
}

.message-bubble code {
  padding: 3px 6px;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.05);
  font-family: monospace;
  font-size: 0.9rem;
}

.message-meta {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 500;
}

.citation-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.citation-chip {
  min-height: 32px;
  padding: 0 12px;
  border: 1px solid rgba(37, 99, 235, 0.2);
  border-radius: 6px;
  background: var(--accent-soft);
  color: var(--accent) !important;
  font-size: 0.8rem;
  font-weight: 700;
  transition: all 0.2s ease;
}

.citation-chip:hover {
  background: rgba(37, 99, 235, 0.15);
  border-color: var(--accent);
}

.composer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  padding: 16px 18px;
  border-top: 1px solid var(--line);
  background: #ffffff;
}

.composer textarea {
  max-height: 160px;
  resize: none;
  background: #ffffff;
  border-color: #cbd5e1;
}

.reference-content {
  display: grid;
  gap: 12px;
}

.reference-card {
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-muted);
  transition: all 0.2s ease;
}

.reference-card:hover {
  background: var(--surface-hover);
}

.reference-card h3 {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  overflow-wrap: anywhere;
  color: var(--accent);
}

.reference-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.55;
}

.toast-line {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 20;
  max-width: min(420px, calc(100vw - 36px));
  padding: 12px 14px;
  border-radius: 8px;
  background: var(--accent);
  color: #ffffff;
  font-weight: 700;
  box-shadow: 0 4px 15px rgba(37, 99, 235, 0.2);
}

/* Auth Pages Web3 Cards styling */
.auth-container {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: calc(100vh - 120px);
  padding: 20px;
}

.auth-card {
  width: 100%;
  max-width: 440px;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 32px;
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
}

.auth-title {
  text-align: center;
  margin-bottom: 24px;
}

.auth-title h1 {
  font-size: 1.8rem;
  font-weight: 800;
  margin: 0 0 6px;
  background: linear-gradient(135deg, var(--ink) 30%, var(--accent) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.auth-title p {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0;
}
.wallet-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--accent-soft);
  border: 1px solid rgba(37, 99, 235, 0.15);
  padding: 6px 12px;
  border-radius: 12px;
  font-size: 0.85rem;
}

.management-panel .panel-header {
  background: linear-gradient(135deg, #3b82f6 0%, #8b5cf6 100%);
  margin: -18px -18px 12px -18px;
  padding: 20px 18px;
  border-top-left-radius: 15px;
  border-top-right-radius: 15px;
  color: #ffffff;
}

.management-panel .panel-header h1 {
  color: #ffffff !important;
  font-weight: 700;
  margin: 0;
}

.management-panel .panel-header .eyebrow {
  color: rgba(255, 255, 255, 0.85) !important;
  font-weight: 700;
}

.management-panel .panel-header .icon-button {
  background: rgba(255, 255, 255, 0.15);
  border-color: rgba(255, 255, 255, 0.2);
  color: #ffffff;
}

.management-panel .panel-header .icon-button:hover {
  background: rgba(255, 255, 255, 0.25);
  color: #ffffff;
}

@media (max-width: 1180px) {
  .workspace {
    grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
  }

  .reference-panel {
    grid-column: 1 / -1;
    min-height: 260px;
  }
}

/* Mobile Workspace Navigation Tabs */
.mobile-workspace-tabs {
  display: none;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 6px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}

.mobile-tab-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  font-weight: 700;
  font-size: 0.85rem;
  padding: 10px 6px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: all 0.25s ease;
  text-transform: none;
}

.mobile-tab-btn:hover {
  background: var(--surface-hover);
  color: var(--ink);
}

.mobile-tab-btn.active {
  background: var(--accent-soft);
  color: var(--accent);
  box-shadow: inset 0 0 0 1px rgba(37, 99, 235, 0.15);
}

@media (max-width: 820px) {
  .app-shell {
    padding: 10px;
  }

  .workspace {
    grid-template-columns: 1fr;
    min-height: auto;
  }

  .chat-panel {
    min-height: 72vh;
  }

  .message {
    max-width: 100%;
  }

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

  /* Mobile Tabs Display & Hiding logic */
  .mobile-workspace-tabs {
    display: grid;
    grid-column: 1 / -1;
  }

  .workspace[data-active-tab="chat-panel"] .management-panel,
  .workspace[data-active-tab="chat-panel"] .reference-panel {
    display: none !important;
  }

  .workspace[data-active-tab="management-panel"] .chat-panel,
  .workspace[data-active-tab="management-panel"] .reference-panel {
    display: none !important;
  }

  .workspace[data-active-tab="reference-panel"] .chat-panel,
  .workspace[data-active-tab="reference-panel"] .management-panel {
    display: none !important;
  }

  .workspace[data-active-tab="chat-panel"] .chat-panel {
    display: grid !important;
  }

  .workspace[data-active-tab="management-panel"] .management-panel {
    display: flex !important;
    max-height: none;
  }

  .workspace[data-active-tab="reference-panel"] .reference-panel {
    display: flex !important;
    max-height: none;
  }
}

/* Web3 Premium Footer Styling */
.app-footer {
  margin-top: 40px;
  border-top: 1px solid var(--line);
  background: var(--surface);
  padding: 24px 0;
  box-shadow: 0 -4px 20px rgba(0,0,0,0.01);
}

.footer-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px;
}

.footer-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  color: var(--ink);
}

.footer-links {
  display: flex;
  gap: 20px;
  align-items: center;
}

.footer-link {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 500;
  transition: color 0.2s ease;
}

.footer-link:hover {
  color: var(--accent);
}

.footer-status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  font-weight: 600;
  color: #10b981; /* Green success */
  background: rgba(16, 185, 129, 0.08);
  border: 1px solid rgba(16, 185, 129, 0.15);
  padding: 4px 10px;
  border-radius: 20px;
}

.footer-status-dot {
  width: 6px;
  height: 6px;
  background: #10b981;
  border-radius: 50%;
  box-shadow: 0 0 8px #10b981;
  animation: pulse-dot 2s infinite;
}

@keyframes pulse-dot {
  0% {
    transform: scale(0.95);
    box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7);
  }
  70% {
    transform: scale(1);
    box-shadow: 0 0 0 5px rgba(16, 185, 129, 0);
  }
  100% {
    transform: scale(0.95);
    box-shadow: 0 0 0 0 rgba(16, 185, 129, 0);
  }
}
