@import url('https://fonts.googleapis.com/css2?family=Noto+Sans:wght@300;400;500;700&display=swap');

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

:root,
[data-theme="light"] {
  --bg: #f4f1ec;
  --bg-panel: rgba(255, 255, 255, 0.85);
  --nav-bg: rgba(255, 253, 250, 0.92);
  --ink: #1a1d22;
  --ink-muted: #595f68;
  --ink-dim: #9299a2;
  --accent: #164f75;
  --link: #0f527d;
  --link-underline: rgba(15, 82, 125, 0.5);
  --strong: #111820;
  --border: rgba(26, 29, 34, 0.1);
  --canvas-bg: #f4f1ec;
  --user-bubble: #164f75;
  --user-bubble-ink: #ffffff;
  --peer-bubble: rgba(26, 29, 34, 0.04);
  --peer-bubble-ink: #1a1d22;
  --input-bg: rgba(26, 29, 34, 0.03);
  --surface-hover: rgba(22, 79, 117, 0.08);
  --dot-1-r: 200; --dot-1-g: 195; --dot-1-b: 188;
  --dot-2-r: 120; --dot-2-g: 115; --dot-2-b: 128;
  --dot-3-r: 30;  --dot-3-g: 40;  --dot-3-b: 78;
}

[data-theme="macchiato"] {
  --bg: #181926;
  --bg-panel: #24273a;
  --nav-bg: rgba(36, 39, 58, 0.65);
  --ink: #cad3f5;
  --ink-muted: #a5adcb;
  --ink-dim: #8087a2;
  --accent: #8aadf4;
  --link: #8aadf4;
  --link-underline: rgba(138, 173, 244, 0.5);
  --strong: #c6d0f5;
  --border: rgba(165, 173, 203, 0.15);
  --canvas-bg: #181926;
  --user-bubble: #8aadf4;
  --user-bubble-ink: #181926;
  --peer-bubble: rgba(206, 213, 245, 0.08);
  --peer-bubble-ink: #cad3f5;
  --input-bg: rgba(36, 39, 58, 0.5);
  --surface-hover: rgba(138, 173, 244, 0.08);
  --dot-1-r: 50; --dot-1-g: 55; --dot-1-b: 75;
  --dot-2-r: 138; --dot-2-g: 173; --dot-2-b: 244;
  --dot-3-r: 180; --dot-3-g: 210; --dot-3-b: 255;
}

html, body {
  width: 100%;
  height: 100%;
  height: var(--app-height, 100dvh);
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: 'Noto Sans', sans-serif;
  font-size: 0.92rem;
  font-weight: 300;
  line-height: 1.65;
  display: flex;
  flex-direction: column;
  transition: background 0.3s ease, color 0.3s ease;
}

a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: all 0.2s ease;
}
a:hover { border-bottom-color: var(--accent); }

button, input, textarea { font: inherit; }

/* ---- Nav ---- */
.nav-bar {
  position: fixed; top: 0; left: 0;
  width: 100%; z-index: 100;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1.5rem;
  background: var(--nav-bg);
  backdrop-filter: blur(12px) saturate(120%);
  -webkit-backdrop-filter: blur(12px) saturate(120%);
  border-bottom: 1px solid var(--border);
  transition: background 0.3s ease;
}

.back-link {
  display: inline-flex;
  align-items: center;
  font-family: 'Noto Sans', sans-serif;
  font-weight: 400;
  font-size: 0.65rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  white-space: nowrap;
  color: var(--ink-muted);
  text-decoration: none;
  padding: 0.35rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 3px;
  transition: color 0.2s ease, border-color 0.2s ease, background 0.2s ease;
}
.back-link:hover {
  color: var(--ink);
  border-color: var(--ink-muted);
  background: var(--bg-panel);
  border-bottom: 1px solid var(--ink-muted);
}

.nav-brand {
  grid-column: 2;
  justify-self: center;
  font-family: 'Noto Sans', sans-serif;
  font-weight: 400;
  font-size: 0.9rem;
  letter-spacing: 0.02em;
  color: var(--ink);
  text-decoration: none;
}

.brand-sep { font-weight: 400; color: var(--ink-muted); margin: 0 0.2rem; }
.brand-sub {
  font-weight: 400;
  font-size: 0.85rem;
  color: var(--ink);
}

[data-theme="macchiato"] .nav-brand {
  color: #cad3f5;
}

.desktop-nav {
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

.desktop-nav a {
  font-family: 'Noto Sans', sans-serif;
  font-size: 0.85rem;
  font-weight: 400;
  color: var(--ink-muted);
  text-decoration: none;
  padding: 0.35rem 0.65rem;
  border-radius: 3px;
  transition: color 0.2s ease, background 0.2s ease;
}

.desktop-nav a:hover {
  color: var(--ink);
  background: var(--surface-hover);
}

/* Hamburger button */
.nav-hamburger {
  display: none;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 3px;
  cursor: pointer;
  padding: 0.45rem 0.55rem;
  z-index: 110;
  transition: background 0.2s ease, border-color 0.2s ease;
}

.nav-hamburger span {
  display: block;
  width: 18px;
  height: 2px;
  background-color: var(--ink);
  margin: 3px 0;
  border-radius: 1px;
  transition: all 0.25s ease;
}

.nav-hamburger:hover {
  background: var(--surface-hover);
  border-color: var(--ink-muted);
}

/* Full-screen overlay menu */
.nav-offcanvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: var(--bg);
  transform: translateX(100%);
  transition: transform 0.3s ease;
  z-index: 120;
  display: flex;
  flex-direction: column;
  opacity: 1;
}

.nav-offcanvas.open {
  transform: translateX(0);
}

.nav-offcanvas-header {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: transparent;
  position: relative;
}

.nav-offcanvas-brand {
  font-family: 'Noto Sans', sans-serif;
  font-size: 0.9rem;
  font-weight: 400;
  color: var(--ink);
  letter-spacing: 0.02em;
}

.nav-close {
  position: absolute;
  right: 1.25rem;
  background: transparent;
  border: none;
  color: var(--ink);
  font-size: 1.4rem;
  cursor: pointer;
  padding: 0;
  line-height: 1;
  transition: opacity 0.15s ease;
}

.nav-close:hover {
  opacity: 0.7;
}

.nav-mobile-links {
  display: flex;
  flex-direction: column;
  padding: 2rem 1.25rem;
  flex: 1;
}

.nav-mobile-links a {
  font-family: 'Noto Sans', sans-serif;
  color: var(--ink-muted);
  text-decoration: none;
  font-size: 0.85rem;
  padding: 1rem 0;
  border-bottom: 1px solid var(--border);
  transition: color 0.15s ease;
  text-align: left;
}

.nav-mobile-links a:first-child {
  padding-top: 0;
}

.nav-mobile-links a:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.nav-mobile-links a:hover {
  color: var(--ink);
}

/* Overlay backdrop */
.nav-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background-color: rgba(0, 0, 0, 0.45);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
  z-index: 115;
}

.nav-overlay.open {
  opacity: 1;
  visibility: visible;
}

/* ---- Main content ---- */
.page-body {
  flex: 1;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: calc(65px + 3rem) 1rem calc(3.5rem + 1rem + env(safe-area-inset-bottom));
  overflow: hidden;
}

.chat-shell {
  display: flex;
  flex-direction: column;
  width: min(860px, 100%);
  height: calc(var(--app-height, 100dvh) - calc(65px + 3rem) - calc(3.5rem + 1rem + env(safe-area-inset-bottom)));
  max-height: calc(var(--app-height, 100dvh) - calc(65px + 3rem) - calc(3.5rem + 1rem + env(safe-area-inset-bottom)));
  background: var(--bg-panel);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--border);
  border-radius: 3px;
  overflow: hidden;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.06);
  animation: panel-in 0.7s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  opacity: 0;
  transform: translateY(10px);
  transition: background 0.3s ease, border-color 0.3s ease;
}

@keyframes panel-in {
  0%   { opacity: 0; transform: translateY(10px); }
  100% { opacity: 1; transform: translateY(0); }
}

/* ---- Documents shell ---- */
.documents-shell {
  display: flex;
  flex-direction: column;
  width: min(1200px, 100%);
  height: 100%;
  background: var(--bg-panel);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--border);
  border-radius: 3px;
  overflow: hidden;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.06);
  animation: panel-in 0.7s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  opacity: 0;
  transform: translateY(10px);
  transition: background 0.3s ease, border-color 0.3s ease;
}

[data-theme="macchiato"] .chat-shell, 
[data-theme="macchiato"] .documents-shell {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.2);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}

/* ---- Messages ---- */
#log {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

#log::-webkit-scrollbar { width: 3px; }
#log::-webkit-scrollbar-track { background: transparent; }
#log::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.msg-wrap {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.msg-user-wrap {
  justify-content: flex-end;
  align-items: flex-end;
}

.msg-assistant-wrap {
  justify-content: flex-start;
  align-items: flex-start;
}

.msg-user, .msg-assistant {
  max-width: 100%;
  padding: 0;
  border-radius: 0;
  font-size: 0.9rem;
  line-height: 1.7;
  overflow-wrap: anywhere;
}

.msg-user {
  background: transparent;
  color: var(--ink);
  text-align: right;
  font-weight: 500;
  font-size: 0.85rem;
  padding: 0.4rem 0.8rem;
  border-radius: 4px;
  background: var(--user-bubble);
  color: var(--user-bubble-ink);
  max-width: 60%;
}

.msg-assistant {
  background: transparent;
  color: var(--ink);
  width: 100%;
  max-width: 100%;
  padding: 1rem 0;
}

.msg-assistant p { 
  margin: 0.5rem 0; 
  line-height: 1.7;
}
.msg-assistant p:first-child { margin-top: 0; }
.msg-assistant p:last-child { margin-bottom: 0; }

.msg-assistant pre {
  background: var(--input-bg);
  padding: 1rem 1.25rem;
  border-radius: 4px;
  overflow-x: auto;
  margin: 1rem 0;
  font-size: 0.82rem;
  border-left: 3px solid var(--accent);
}
.msg-assistant code {
  font-family: 'Noto Sans', sans-serif;
  font-size: 0.82rem;
}
.msg-assistant pre code { 
  background: none; 
  padding: 0; 
  border-left: none;
}
.msg-assistant code:not(pre code) {
  background: var(--input-bg);
  padding: 0.15rem 0.4rem;
  border-radius: 3px;
  font-size: 0.85rem;
}
.msg-assistant ul, .msg-assistant ol {
  margin: 0.75rem 0;
  padding-left: 1.75rem;
  line-height: 1.7;
}
.msg-assistant li { 
  margin: 0.4rem 0; 
}
.msg-assistant h1, .msg-assistant h2, .msg-assistant h3,
.msg-assistant h4, .msg-assistant h5, .msg-assistant h6 {
  margin: 1.25rem 0 0.5rem;
  font-weight: 700;
  color: var(--ink);
}
.msg-assistant h1 { font-size: 1.3rem; }
.msg-assistant h2 { font-size: 1.15rem; }
.msg-assistant h3 { font-size: 1rem; }
.msg-assistant h4, .msg-assistant h5, .msg-assistant h6 { font-size: 0.95rem; }
.msg-assistant table {
  border-collapse: collapse;
  margin: 1rem 0;
  font-size: 0.85rem;
  width: 100%;
}
.msg-assistant th, .msg-assistant td {
  border: 1px solid var(--border);
  padding: 0.5rem 0.75rem;
  text-align: left;
}
.msg-assistant img {
  max-width: 100%;
  border-radius: 6px;
  margin: 1rem 0;
}
.msg-assistant blockquote {
  border-left: 4px solid var(--accent); 
  padding-left: 1rem;
  margin: 1rem 0;
  color: var(--ink-muted);
  background: var(--input-bg);
  padding: 0.75rem 1rem;
}
.msg-assistant a {
  color: var(--accent);
  border-bottom: 1px solid transparent;
}

.msg-wrap::after {
  content: "";
  height: 1px;
  background: var(--border);
  margin: 0.5rem 0;
}
.msg-user-wrap::after {
  display: none;
}

footer {
    position: fixed; 
    bottom: 0; 
    left: 0;
    width: 100%; 
    z-index: 20;
    padding: 0.9rem 2rem;
    display: flex; 
    justify-content: center; 
    align-items: center;
    gap: 1.5rem;
    font-family: 'Noto Sans', sans-serif;
    font-weight: 300;
    font-size: 0.72rem;
    letter-spacing: 0.05em;
    color: var(--ink-muted);
    border-top: 1px solid var(--border);
    background: var(--nav-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    transition: background 0.3s ease;
    height: auto;
    min-height: 3.5rem;
}

/* ---- Typing indicator ---- */
.typing-indicator {
  display: flex;
  justify-content: flex-start;
  padding: 0 0.9rem 0.55rem;
}
.typing-bubble-inner {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 0.55rem 0.75rem;
  background: var(--peer-bubble);
  border-radius: 12px;
  border-bottom-left-radius: 3px;
}
.typing-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--ink-dim);
  animation: typing-bounce 1.1s infinite ease-in-out;
}
.typing-dot:nth-child(2) { animation-delay: 0.16s; }
.typing-dot:nth-child(3) { animation-delay: 0.32s; }
@keyframes typing-bounce {
  0%, 75%, 100% { transform: translateY(0); opacity: 0.45; }
  35% { transform: translateY(-4px); opacity: 1; }
}

/* ---- Notices (upload status) ---- */
.notice-wrap {
  display: flex;
  justify-content: center;
  margin: 0.25rem 0;
}
.notice-text {
  font-size: 0.7rem;
  color: var(--ink-dim);
  background: var(--input-bg);
  padding: 0.25rem 0.75rem;
  border-radius: 2px;
  text-align: center;
  letter-spacing: 0.04em;
}
.notice-text.success { color: var(--accent); }
.notice-text.error { color: var(--ink-muted); }

/* ---- Input area ---- */
#form {
  display: flex;
  padding: 0.75rem 0.85rem;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--input-bg);
}

.input-wrapper {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex: 1;
  padding: 0.4rem;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  transition: border-color 0.2s ease;
}

.input-wrapper:focus-within {
  border-color: var(--accent);
}

[data-theme="macchiato"] .input-wrapper {
  background: rgba(24, 24, 37, 0.8);
  border: 1px solid var(--border);
}

[data-theme="macchiato"] #log {
  border-bottom: 1px solid var(--border); 
}

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  background: transparent;
  color: var(--ink-muted);
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
}

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

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

#input {
  flex: 1;
  min-width: 0;
  max-width: 100%;
  padding: 0.5rem 0.8rem;
  background: transparent;
  border: none;
  outline: none;
  color: var(--ink);
  font-size: 0.9rem;
  line-height: 1.5;
  resize: none;
  font-family: 'Noto Sans', sans-serif;
  overflow-y: auto;
  max-height: 200px;
  min-height: 32px;
}

#input::placeholder {
  color: var(--ink-dim);
}

/* Theme-aware send button colors */
[data-theme="light"] .send-btn {
  background: #164f75;
}
[data-theme="light"] .send-btn:hover {
  background: #113f5e;
}

[data-theme="macchiato"] .send-btn {
  background: #89b4fa;
  color: #1e1e2e;
}
[data-theme="macchiato"] .send-btn:hover {
  background: #74c7ec;
}

.send-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  transition: all 0.2s ease;
}

.send-btn:hover {
  transform: scale(1.05);
}

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

.send-btn svg {
  stroke: white;
  stroke-width: 2.5;
}

[data-theme="macchiato"] .send-btn svg {
  stroke: #1e1e2e;
}

/* ---- Image dialog ---- */
#imageDialog {
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0;
  background: var(--bg-panel);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  color: var(--ink);
}
#imageDialog::backdrop {
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(2px);
}
#imageForm {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 1.5rem;
  width: 28rem;
  max-width: 90vw;
}
#imageForm h2 {
  font-family: 'Noto Sans', sans-serif;
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--ink);
}
#imageForm label {
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--ink-muted);
}
#imageForm input[type="file"] {
  margin-top: 0.4rem;
  font-size: 0.78rem;
  color: var(--ink-muted);
}
#imageForm textarea {
  margin-top: 0.4rem;
  resize: none;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: var(--input-bg);
  color: var(--ink);
  padding: 0.5rem 0.65rem;
  font-size: 0.85rem;
  outline: none;
  transition: border-color 0.2s;
}
#imageForm textarea:focus { border-color: var(--accent); }
#imageForm .dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 0.25rem;
}
.dialog-cancel {
  padding: 0.45rem 0.85rem;
  background: transparent;
  color: var(--ink-muted);
  border: 1px solid var(--border);
  border-radius: 3px;
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s;
}
.dialog-cancel:hover { color: var(--ink); border-color: var(--ink-muted); }
.dialog-submit {
  padding: 0.45rem 0.85rem;
  background: var(--accent);
  color: var(--bg);
  border: none;
  border-radius: 3px;
  font-family: 'Noto Sans', sans-serif;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  transition: opacity 0.2s;
}
.dialog-submit:hover { opacity: 0.85; }
.dialog-submit:disabled { cursor: wait; opacity: 0.5; }

.auto-caption-btn {
  padding: 0.2rem 0.5rem;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 2px;
  font-size: 0.65rem;
  font-weight: 500;
  color: var(--ink-muted);
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s;
}
.auto-caption-btn:hover { color: var(--ink); border-color: var(--ink-muted); }
.auto-caption-btn:disabled { cursor: wait; opacity: 0.5; }

.label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* ---- Theme toggle ---- */
.theme-toggle {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid var(--border);
  cursor: pointer;
  padding: 0;
  z-index: 30;
  transition: all 0.3s ease;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
}
.theme-toggle:hover { transform: scale(1.08); }
[data-theme="light"] .theme-toggle {
  background: linear-gradient(135deg, #24273a 0%, #164f75 100%);
  border-color: rgba(26, 29, 34, 0.2);
}

[data-theme="macchiato"] .theme-toggle {
  background: #313244;
  border-color: rgba(137, 180, 250, 0.4);
  box-shadow:
    0 0 10px rgba(137, 180, 250, 0.4),
    0 0 25px rgba(137, 180, 250, 0.2),
    0 0 50px rgba(116, 150, 230, 0.15);
  animation: neon-breathe-toggle 4s ease-in-out infinite;
}

[data-theme="macchiato"] .theme-toggle:hover {
  box-shadow:
    0 0 15px rgba(137, 180, 250, 0.6),
    0 0 35px rgba(137, 180, 250, 0.35),
    0 0 70px rgba(116, 150, 230, 0.25);
}

@keyframes neon-breathe-toggle {
  0%, 100% {
    box-shadow:
      0 0 10px rgba(137, 180, 250, 0.5),
      0 0 25px rgba(137, 180, 250, 0.3),
      0 0 50px rgba(116, 150, 230, 0.2);
  }
  50% {
    box-shadow:
      0 0 15px rgba(137, 180, 250, 0.6),
      0 0 35px rgba(137, 180, 250, 0.4),
      0 0 70px rgba(116, 150, 230, 0.25);
  }
}

/* ---- Documents Table Styles ---- */
.docs-container {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.docs-header {
  margin-bottom: 1rem;
  margin-top: 0.75rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.25rem;
  background: var(--bg-panel);
  position: sticky;
  top: 0;
  z-index: 6;
  border-bottom: 1px solid var(--border);
}

.docs-header h1 {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--ink);
  margin: 0;
}

.docs-header p {
  font-size: 0.78rem;
  color: var(--ink-muted);
  margin: 0.25rem 0 0 0;
}

.connection-status {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.7rem;
  color: var(--ink-muted);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}
.status-connected { background-color: var(--accent); }
.status-disconnected { background-color: #ef4444; }

.filter-bar {
  border-bottom: 1px solid var(--border);
  background: var(--input-bg);
  padding: 0.75rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-shrink: 0;
}

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

.table-container {
  flex: 1;
  overflow-x: auto;
  overflow-y: auto;
  max-height: calc(100vh - 280px);
}

.docs-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}

.docs-table thead {
  position: sticky;
  top: 0;
  background: var(--bg-panel);
  z-index: 7;
  border-bottom: 2px solid var(--border);
}

.docs-table th {
  padding: 0.75rem 1.25rem;
  text-align: left;
  font-weight: 600;
  color: var(--ink-muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  transition: color 0.15s ease;
  background: var(--bg-panel);
}
.docs-table th:hover {
  color: var(--ink);
}
.docs-table th .sort-icon {
  opacity: 0.3;
  font-size: 0.65rem;
  margin-left: 0.35rem;
  transition: opacity 0.15s ease, transform 0.15s ease;
}
.docs-table th.active .sort-icon {
  opacity: 1;
  color: var(--accent);
  transform: rotate(180deg);
}
.docs-table th.active.asc .sort-icon {
  transform: rotate(0deg);
}

.docs-table tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background 0.15s ease;
}
.docs-table tbody tr:hover {
  background: var(--surface-hover);
}

.docs-table td {
  padding: 0.75rem 1.25rem;
  color: var(--ink);
}

.docs-table td.filename {
  font-family: 'Noto Sans', sans-serif;
  font-size: 0.75rem;
}

.file-badge {
  display: inline-block;
  padding: 0.2rem 0.5rem;
  font-size: 0.65rem;
  font-weight: 600;
  border-radius: 3px;
  text-transform: uppercase;
}

.feature-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
}

.feature-tag {
  display: inline-block;
  padding: 0.15rem 0.4rem;
  font-size: 0.6rem;
  border-radius: 2px;
  background: var(--input-bg);
  color: var(--ink-muted);
}

.empty-state {
  text-align: center;
  padding: 2rem;
  color: var(--ink-muted);
  font-size: 0.85rem;
}

/* ---- Responsive ---- */
@media (max-width: 768px) {
  .desktop-nav {
    display: none;
  }

  .back-link { 
    font-size: 0.55rem; 
    padding: 0.3rem 0.55rem; 
  }  

  .desktop-nav a {
    font-family: 'Noto Sans', sans-serif;
    font-size: 0.85rem;
    font-weight: 400;
    color: var(--ink-muted);
    text-decoration: none;
    padding: 0.35rem 0.65rem;
    border-radius: 3px;
    transition: color 0.2s ease, background 0.2s ease;
  }
  
  .desktop-nav a:hover {
    color: var(--ink);
    background: var(--surface-hover);
  }
  
  .back-link { 
    font-size: 0.55rem; 
    padding: 0.3rem 0.55rem; 
  }
  
  .nav-bar {
    gap: 0.5rem;
    padding: 0.65rem 1rem;
  }

  .nav-brand { 
    font-size: 0.85rem; 
  }
  
  .brand-sub { font-size: 0.8rem; }

  .nav-hamburger {
    display: block;
  }

  .page-body {
    padding: calc(60px + 0.75rem) 0.5rem max(0.75rem, env(safe-area-inset-bottom));
  }

  .chat-shell, .documents-shell {
    border-radius: 0;
    width: 100%;
  }

  .theme-toggle {
    width: 20px;
    height: 20px;
    bottom: 1rem;
    right: 0.75rem;
  }
}

@media (max-width: 460px) {
  .nav-brand { font-size: 0.8rem; }
}

/* ---- File badge colors ---- */
.file-badge.pdf-badge    { background: #fee2e2; color: #b91c1c; }
.file-badge.docx-badge   { background: #dbeafe; color: #1d4ed8; }
.file-badge.odt-badge    { background: #ccfbf1; color: #0f766e; }
.file-badge.xlsx-badge   { background: #dcfce7; color: #166534; }
.file-badge.pptx-badge   { background: #ffedd5; color: #c2410c; }
.file-badge.html-badge   { background: #fef9c3; color: #a16207; }
.file-badge.epub-badge   { background: #e0e7ff; color: #4338ca; }
.file-badge.txt-badge    { background: #f1f5f9; color: #475569; }
.file-badge.md-badge     { background: #e0f2fe; color: #0369a1; }
.file-badge.default-badge { background: #f1f5f9; color: #475569; }

[data-theme="macchiato"] .file-badge.pdf-badge    { background: rgba(239, 68, 68, 0.15); color: #f87171; }
[data-theme="macchiato"] .file-badge.docx-badge   { background: rgba(59, 130, 246, 0.15); color: #60a5fa; }
[data-theme="macchiato"] .file-badge.odt-badge    { background: rgba(20, 184, 166, 0.15); color: #2dd4bf; }
[data-theme="macchiato"] .file-badge.xlsx-badge   { background: rgba(34, 197, 94, 0.15); color: #4ade80; }
[data-theme="macchiato"] .file-badge.pptx-badge   { background: rgba(249, 115, 22, 0.15); color: #fb923c; }
[data-theme="macchiato"] .file-badge.html-badge   { background: rgba(234, 179, 8, 0.15); color: #facc15; }
[data-theme="macchiato"] .file-badge.epub-badge   { background: rgba(99, 102, 241, 0.15); color: #818cf8; }
[data-theme="macchiato"] .file-badge.txt-badge    { background: rgba(148, 163, 184, 0.15); color: #94a3b8; }
[data-theme="macchiato"] .file-badge.md-badge     { background: rgba(14, 165, 233, 0.15); color: #38bdf8; }
[data-theme="macchiato"] .file-badge.default-badge { background: rgba(148, 163, 184, 0.15); color: #94a3b8; }

.sort-control {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
