/* style.css — Data Room Design System */

/* Google Fonts */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
  --font-display: 'Inter', system-ui, sans-serif;
  --font-body: 'Inter', system-ui, sans-serif;

  /* Type Scale */
  --text-xs:   clamp(0.75rem,  0.7rem  + 0.25vw, 0.875rem);
  --text-sm:   clamp(0.875rem, 0.8rem  + 0.35vw, 1rem);
  --text-base: clamp(1rem,     0.9rem  + 0.5vw,  1.125rem);
  --text-lg:   clamp(1.125rem, 0.95rem + 0.85vw, 1.5rem);
  --text-xl:   clamp(1.5rem,   1rem    + 1.5vw,  2.25rem);
  --text-2xl:  clamp(2rem,     1.2rem  + 2.5vw,  3.5rem);

  /* 4px Spacing */
  --space-1:  0.25rem;
  --space-2:  0.5rem;
  --space-3:  0.75rem;
  --space-4:  1rem;
  --space-5:  1.25rem;
  --space-6:  1.5rem;
  --space-8:  2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;
  --space-16: 4rem;
  --space-20: 5rem;
  --space-24: 6rem;
  --space-32: 8rem;

  /* Radius */
  --radius-sm: 0.375rem;
  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;
  --radius-xl: 1rem;
  --radius-full: 9999px;

  /* Transitions */
  --transition-interactive: 180ms cubic-bezier(0.16, 1, 0.3, 1);

  /* Content widths */
  --content-narrow: 640px;
  --content-default: 960px;
  --content-wide: 1200px;
  --content-full: 100%;

  /* Sidebar width */
  --sidebar-width: 260px;
  --sidebar-collapsed: 64px;
}

/* LIGHT MODE */
:root, [data-theme="light"] {
  --color-bg:             #f7f6f2;
  --color-surface:        #f9f8f5;
  --color-surface-2:      #fbfbf9;
  --color-surface-offset: #f3f0ec;
  --color-surface-offset-2: #edeae5;
  --color-surface-dynamic: #e6e4df;
  --color-divider:        #dcd9d5;
  --color-border:         #d4d1ca;

  --color-text:           #28251d;
  --color-text-muted:     #7a7974;
  --color-text-faint:     #bab9b4;
  --color-text-inverse:   #f9f8f4;

  --color-primary:        #01696f;
  --color-primary-hover:  #0c4e54;
  --color-primary-active: #0f3638;
  --color-primary-highlight: #cedcd8;

  --color-warning:        #964219;
  --color-warning-hover:  #713417;
  --color-warning-active: #4b2614;
  --color-warning-highlight: #ddcfc6;

  --color-error:          #a12c7b;
  --color-error-hover:    #7d1e5e;
  --color-error-active:   #561740;
  --color-error-highlight: #e0ced7;

  --color-success:        #437a22;
  --color-success-hover:  #2e5c10;
  --color-success-active: #1e3f0a;
  --color-success-highlight: #d4dfcc;

  --shadow-sm: 0 1px 2px oklch(0.2 0.01 80 / 0.06);
  --shadow-md: 0 4px 12px oklch(0.2 0.01 80 / 0.08);
  --shadow-lg: 0 12px 32px oklch(0.2 0.01 80 / 0.12);
}

/* DARK MODE */
[data-theme="dark"] {
  --color-bg:             #171614;
  --color-surface:        #1c1b19;
  --color-surface-2:      #201f1d;
  --color-surface-offset: #1d1c1a;
  --color-surface-offset-2: #22211f;
  --color-surface-dynamic: #2d2c2a;
  --color-divider:        #262523;
  --color-border:         #393836;
  --color-text:           #cdccca;
  --color-text-muted:     #797876;
  --color-text-faint:     #5a5957;
  --color-text-inverse:   #2b2a28;
  --color-primary:        #4f98a3;
  --color-primary-hover:  #227f8b;
  --color-primary-active: #1a626b;
  --color-primary-highlight: #313b3b;
  --color-warning:        #bb653b;
  --color-warning-hover:  #b95525;
  --color-warning-active: #993d10;
  --color-warning-highlight: #564942;
  --color-error:          #d163a7;
  --color-error-hover:    #b9478f;
  --color-error-active:   #9b2f76;
  --color-error-highlight: #4c3d46;
  --color-success:        #6daa45;
  --color-success-hover:  #4d8f25;
  --color-success-active: #387015;
  --color-success-highlight: #3a4435;
  --shadow-sm: 0 1px 2px oklch(0 0 0 / 0.2);
  --shadow-md: 0 4px 12px oklch(0 0 0 / 0.3);
  --shadow-lg: 0 12px 32px oklch(0 0 0 / 0.4);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --color-bg:             #171614;
    --color-surface:        #1c1b19;
    --color-surface-2:      #201f1d;
    --color-surface-offset: #1d1c1a;
    --color-surface-offset-2: #22211f;
    --color-surface-dynamic: #2d2c2a;
    --color-divider:        #262523;
    --color-border:         #393836;
    --color-text:           #cdccca;
    --color-text-muted:     #797876;
    --color-text-faint:     #5a5957;
    --color-text-inverse:   #2b2a28;
    --color-primary:        #4f98a3;
    --color-primary-hover:  #227f8b;
    --color-primary-active: #1a626b;
    --color-primary-highlight: #313b3b;
    --color-warning:        #bb653b;
    --color-warning-hover:  #b95525;
    --color-warning-active: #993d10;
    --color-warning-highlight: #564942;
    --color-error:          #d163a7;
    --color-error-hover:    #b9478f;
    --color-error-active:   #9b2f76;
    --color-error-highlight: #4c3d46;
    --color-success:        #6daa45;
    --color-success-hover:  #4d8f25;
    --color-success-active: #387015;
    --color-success-highlight: #3a4435;
    --shadow-sm: 0 1px 2px oklch(0 0 0 / 0.2);
    --shadow-md: 0 4px 12px oklch(0 0 0 / 0.3);
    --shadow-lg: 0 12px 32px oklch(0 0 0 / 0.4);
  }
}

/* ========== COMPONENT STYLES ========== */

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: 500;
  line-height: 1.4;
  transition: all var(--transition-interactive);
  white-space: nowrap;
  cursor: pointer;
  border: none;
}

.btn-primary {
  background: var(--color-primary);
  color: var(--color-text-inverse);
}
.btn-primary:hover { background: var(--color-primary-hover); }
.btn-primary:active { background: var(--color-primary-active); }

.btn-secondary {
  background: var(--color-surface-dynamic);
  color: var(--color-text);
  border: 1px solid var(--color-border);
}
.btn-secondary:hover { background: var(--color-surface-offset-2); border-color: var(--color-text-faint); }

.btn-ghost {
  background: transparent;
  color: var(--color-text-muted);
}
.btn-ghost:hover { background: var(--color-surface-offset); color: var(--color-text); }

.btn-danger {
  background: var(--color-error);
  color: var(--color-text-inverse);
}
.btn-danger:hover { background: var(--color-error-hover); }

.btn-sm {
  padding: var(--space-1) var(--space-3);
  font-size: var(--text-xs);
}

.btn-icon {
  padding: var(--space-2);
  border-radius: var(--radius-md);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Inputs */
.input {
  width: 100%;
  padding: var(--space-2) var(--space-3);
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  color: var(--color-text);
  transition: border-color var(--transition-interactive), box-shadow var(--transition-interactive);
}
.input::placeholder { color: var(--color-text-faint); }
.input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px oklch(from var(--color-primary) l c h / 0.15);
}

/* Cards */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  transition: all var(--transition-interactive);
}
.card:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--color-text-faint);
}

/* Badge */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: 500;
  line-height: 1;
}
.badge-primary {
  background: var(--color-primary-highlight);
  color: var(--color-primary);
}
.badge-success {
  background: var(--color-success-highlight);
  color: var(--color-success);
}

/* Divider */
.divider {
  height: 1px;
  background: var(--color-divider);
  border: none;
}

/* Label */
.label {
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ========== APP LAYOUT ========== */
.app-layout {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  min-height: 100dvh;
}

.sidebar {
  background: var(--color-surface);
  border-right: 1px solid var(--color-divider);
  display: flex;
  flex-direction: column;
  height: 100dvh;
  position: sticky;
  top: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.sidebar-header {
  padding: var(--space-4) var(--space-4);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  border-bottom: 1px solid var(--color-divider);
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-weight: 600;
  font-size: var(--text-sm);
  color: var(--color-text);
}

.sidebar-nav {
  padding: var(--space-3) var(--space-2);
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  text-decoration: none;
  cursor: pointer;
  transition: all var(--transition-interactive);
}
.nav-item:hover {
  background: var(--color-surface-offset);
  color: var(--color-text);
}
.nav-item.active {
  background: var(--color-primary-highlight);
  color: var(--color-primary);
  font-weight: 500;
}
.nav-item svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.sidebar-section {
  padding: var(--space-3) var(--space-2);
  border-top: 1px solid var(--color-divider);
}
.sidebar-section-title {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--color-text-faint);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: var(--space-1) var(--space-3);
  margin-bottom: var(--space-1);
}

.folder-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-sm);
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  cursor: pointer;
  transition: all var(--transition-interactive);
}
.folder-item:hover {
  background: var(--color-surface-offset);
  color: var(--color-text);
}
.folder-item.active {
  color: var(--color-primary);
}
.folder-item svg {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

/* Main content area */
.main-content {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  overflow-y: auto;
}

.main-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-6);
  border-bottom: 1px solid var(--color-divider);
  background: var(--color-surface);
  position: sticky;
  top: 0;
  z-index: 10;
}

.main-header-title {
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--color-text);
}

.main-header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.main-body {
  flex: 1;
  padding: var(--space-6);
}

/* ========== PASSWORD SCREEN ========== */
.password-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  background: var(--color-bg);
}
.password-box {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-8);
  width: 100%;
  max-width: 380px;
  text-align: center;
}
.password-box h2 {
  font-size: var(--text-lg);
  font-weight: 600;
  margin: var(--space-4) 0 var(--space-1);
}
.password-box p {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  margin-bottom: var(--space-6);
}
.password-form {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}
.password-error {
  font-size: var(--text-xs);
  color: var(--color-error);
  display: none;
}

/* ========== DOCUMENTS VIEW ========== */
.documents-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: var(--space-4);
}

.doc-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  cursor: pointer;
  transition: all var(--transition-interactive);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  position: relative;
}
.doc-card:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--color-text-faint);
}

.doc-card-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
}
.doc-icon-pdf { background: #fde8e8; color: #dc2626; }
.doc-icon-docx { background: #dbeafe; color: #2563eb; }
.doc-icon-txt { background: var(--color-surface-offset-2); color: var(--color-text-muted); }
.doc-icon-img { background: #d1fae5; color: #059669; }
.doc-icon-xlsx { background: #dcfce7; color: #16a34a; }
.doc-icon-pptx { background: #fef3c7; color: #d97706; }
.doc-icon-interactive { background: #ede9fe; color: #7c3aed; }
.doc-icon-folder { background: var(--color-surface-offset-2); color: var(--color-text-muted); display: flex; align-items: center; justify-content: center; font-size: 0; }

[data-theme="dark"] .doc-icon-pdf { background: #3b1c1c; color: #f87171; }
[data-theme="dark"] .doc-icon-docx { background: #1e2a3e; color: #60a5fa; }
[data-theme="dark"] .doc-icon-img { background: #1a2e22; color: #34d399; }
[data-theme="dark"] .doc-icon-xlsx { background: #1a2e1a; color: #4ade80; }
[data-theme="dark"] .doc-icon-pptx { background: #2e2a1a; color: #fbbf24; }
[data-theme="dark"] .doc-icon-interactive { background: #2d1f4e; color: #a78bfa; }
[data-theme="dark"] .doc-icon-folder { background: #1e2a2e; color: var(--color-accent); }

.doc-card-name {
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--color-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.doc-card-meta {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

/* Upload zone */
.upload-zone {
  border: 2px dashed var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-10) var(--space-6);
  text-align: center;
  cursor: pointer;
  transition: all var(--transition-interactive);
}
.upload-zone:hover, .upload-zone.drag-over {
  border-color: var(--color-primary);
  background: var(--color-primary-highlight);
}
.upload-zone-icon {
  color: var(--color-text-faint);
  margin-bottom: var(--space-3);
  display: flex;
  justify-content: center;
}
.upload-zone-text {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}
.upload-zone-text strong {
  color: var(--color-primary);
}
.upload-zone-hint {
  font-size: var(--text-xs);
  color: var(--color-text-faint);
  margin-top: var(--space-1);
}

/* Upload progress */
.upload-progress {
  display: none;
  margin-top: var(--space-4);
}
.upload-progress.active { display: block; }
.upload-progress-bar {
  height: 4px;
  background: var(--color-surface-offset);
  border-radius: var(--radius-full);
  overflow: hidden;
}
.upload-progress-fill {
  height: 100%;
  background: var(--color-primary);
  border-radius: var(--radius-full);
  transition: width 200ms ease;
  width: 0%;
}
.upload-progress-text {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  margin-top: var(--space-1);
}

/* ========== DOCUMENT DETAIL MODAL ========== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: oklch(0 0 0 / 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-interactive);
}
.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}
.modal {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-xl);
  padding: var(--space-6);
  width: 90%;
  max-width: 560px;
  max-height: 80dvh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  transform: translateY(8px);
  transition: transform var(--transition-interactive);
}
.modal-overlay.active .modal {
  transform: translateY(0);
}
.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: var(--space-4);
}
.modal-title {
  font-size: var(--text-lg);
  font-weight: 600;
  word-break: break-word;
}
.modal-close {
  padding: var(--space-1);
  border-radius: var(--radius-sm);
  color: var(--color-text-muted);
  transition: all var(--transition-interactive);
}
.modal-close:hover {
  background: var(--color-surface-offset);
  color: var(--color-text);
}
.modal-detail-row {
  display: flex;
  justify-content: space-between;
  padding: var(--space-2) 0;
  border-bottom: 1px solid var(--color-divider);
  font-size: var(--text-xs);
}
.modal-detail-label { color: var(--color-text-muted); }
.modal-detail-value { color: var(--color-text); font-weight: 500; }
.modal-preview {
  margin-top: var(--space-4);
  padding: var(--space-4);
  background: var(--color-surface-offset);
  border-radius: var(--radius-md);
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  max-height: 200px;
  overflow-y: auto;
  white-space: pre-wrap;
  line-height: 1.5;
}
.modal-actions {
  margin-top: var(--space-4);
  display: flex;
  gap: var(--space-2);
  justify-content: flex-end;
}

/* ========== CHAT VIEW ========== */
.chat-container {
  display: flex;
  flex-direction: column;
  height: calc(100dvh - 57px);
}

.chat-toolbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-6);
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}

.chat-toolbar-left {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.chat-toolbar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-2);
  flex-shrink: 0;
}

.chat-toolbar .btn {
  font-size: var(--text-xs);
  color: var(--color-text-secondary);
}

.chat-toolbar .btn:hover {
  color: var(--color-text-primary);
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: var(--space-6);
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.chat-message {
  display: flex;
  gap: var(--space-3);
}
.chat-message.assistant {
  max-width: 80%;
  width: 80%;
}
.chat-message.user {
  max-width: 800px;
  margin-left: auto;
  flex-direction: row-reverse;
}

.chat-avatar {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-xs);
  font-weight: 600;
  flex-shrink: 0;
}
.chat-avatar.assistant-avatar {
  background: var(--color-primary-highlight);
  color: var(--color-primary);
}
.chat-avatar.user-avatar {
  background: var(--color-surface-dynamic);
  color: var(--color-text-muted);
}

.chat-bubble {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-lg);
  font-size: var(--text-sm);
  line-height: 1.6;
}
.chat-message.assistant .chat-bubble {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  color: var(--color-text);
  flex: 1;
  min-width: 0;
}
.chat-message.user .chat-bubble {
  background: var(--color-primary);
  color: var(--color-text-inverse);
}

.chat-bubble { position: relative; }
.chat-bubble p { margin-bottom: 0.75em; line-height: 1.7; max-width: none; }
.chat-bubble p:last-child { margin-bottom: 0; }
.chat-bubble h1, .chat-bubble h2, .chat-bubble h3, .chat-bubble h4 {
  font-weight: 600;
  margin: 1em 0 0.5em;
  line-height: 1.3;
}
.chat-bubble h1 { font-size: 1.15em; }
.chat-bubble h2 { font-size: 1.08em; }
.chat-bubble h3 { font-size: 1em; }
.chat-bubble h4 { font-size: 0.95em; color: var(--color-text-muted); }
.chat-bubble h1:first-child, .chat-bubble h2:first-child, .chat-bubble h3:first-child { margin-top: 0; }
.chat-bubble code {
  background: var(--color-surface-offset);
  padding: 0.1em 0.3em;
  border-radius: var(--radius-sm);
  font-size: 0.9em;
}
.chat-bubble pre {
  background: var(--color-surface-offset);
  padding: var(--space-3);
  border-radius: var(--radius-md);
  overflow-x: auto;
  margin: var(--space-2) 0;
}
.chat-bubble pre code {
  background: none;
  padding: 0;
}
.chat-bubble ul, .chat-bubble ol {
  padding-left: 1.4em;
  margin: 0.5em 0;
}
.chat-bubble li { margin-bottom: 0.35em; line-height: 1.6; max-width: none; }
.chat-bubble li:last-child { margin-bottom: 0; }
.chat-bubble strong { font-weight: 600; }
.chat-bubble blockquote {
  border-left: 3px solid var(--color-border);
  padding-left: var(--space-3);
  margin: 0.5em 0;
  color: var(--color-text-muted);
}
.chat-bubble table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.75em 0;
  font-size: 0.92em;
}
.chat-bubble th, .chat-bubble td {
  padding: 6px 10px;
  border: 1px solid var(--color-border);
  text-align: left;
}
.chat-bubble th {
  background: var(--color-surface-offset);
  font-weight: 600;
}
.chat-bubble hr {
  border: none;
  border-top: 1px solid var(--color-border);
  margin: 1em 0;
}
/* Copy button */
.chat-copy-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  padding: 6px 10px;
  background: var(--color-primary);
  border: none;
  border-radius: var(--radius-sm);
  color: #fff;
  cursor: pointer;
  opacity: 1;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.02em;
  transition: background 0.15s;
  display: flex;
  align-items: center;
  gap: 5px;
  z-index: 1;
}
.chat-copy-btn:hover {
  background: var(--color-primary-dark, #015558);
}

/* Thinking / loading animation */
.chat-thinking {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 0;
}
.chat-thinking-dots {
  display: flex;
  gap: 4px;
}
.chat-thinking-dots span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--color-primary);
  opacity: 0.4;
  animation: chatDotPulse 1.4s ease-in-out infinite;
}
.chat-thinking-dots span:nth-child(2) {
  animation-delay: 0.2s;
}
.chat-thinking-dots span:nth-child(3) {
  animation-delay: 0.4s;
}
@keyframes chatDotPulse {
  0%, 80%, 100% { opacity: 0.25; transform: scale(0.8); }
  40% { opacity: 1; transform: scale(1.1); }
}
.chat-thinking-label {
  font-size: 12px;
  color: var(--color-text-muted);
  font-style: italic;
}

.chat-input-area {
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid var(--color-divider);
  background: var(--color-surface);
}
/* Suggested prompt cards in empty state */
.suggested-prompts-bar {
  display: flex;
  gap: 8px;
  padding: 8px 16px;
  overflow-x: auto;
  flex-shrink: 0;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.suggested-prompts-bar::-webkit-scrollbar {
  display: none;
}
.suggested-prompt-chip {
  flex-shrink: 0;
  padding: 6px 14px;
  font-size: 12px;
  font-weight: 500;
  color: var(--color-primary);
  background: var(--color-primary-highlight);
  border: 1px solid transparent;
  border-radius: var(--radius-full);
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
}
.suggested-prompt-chip:hover {
  background: var(--color-surface-2);
  border-color: var(--color-primary);
  box-shadow: 0 1px 4px rgba(1, 105, 111, 0.12);
}
.chat-input-wrapper {
  display: flex;
  gap: var(--space-2);
  max-width: 800px;
  margin: 0 auto;
}
.chat-input {
  flex: 1;
  padding: var(--space-3) var(--space-4);
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  font-size: var(--text-sm);
  color: var(--color-text);
  resize: none;
  min-height: 44px;
  max-height: 120px;
  transition: border-color var(--transition-interactive);
}
.chat-input::placeholder { color: var(--color-text-faint); }
.chat-input:focus {
  outline: none;
  border-color: var(--color-primary);
}
.chat-send-btn {
  padding: var(--space-3);
  background: var(--color-primary);
  color: var(--color-text-inverse);
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition-interactive);
  flex-shrink: 0;
}
.chat-send-btn:hover { background: var(--color-primary-hover); }
.chat-send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ========== EMPTY STATES ========== */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: var(--space-16) var(--space-6);
  color: var(--color-text-faint);
}
.empty-state-icon {
  margin-bottom: var(--space-4);
}
.empty-state-title {
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--color-text-muted);
  margin-bottom: var(--space-1);
}
.empty-state-desc {
  font-size: var(--text-xs);
  color: var(--color-text-faint);
}

/* ========== TOAST ========== */
.toast-container {
  position: fixed;
  bottom: var(--space-6);
  right: var(--space-6);
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.toast {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-xs);
  box-shadow: var(--shadow-md);
  display: flex;
  align-items: center;
  gap: var(--space-2);
  animation: toast-in 300ms cubic-bezier(0.16, 1, 0.3, 1);
}
.toast.success { border-left: 3px solid var(--color-success); }
.toast.error { border-left: 3px solid var(--color-error); }

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

/* ========== CREATE FOLDER MODAL ========== */
.folder-modal .modal {
  max-width: 400px;
}

/* ========== MOBILE ========== */
@media (max-width: 768px) {
  .app-layout {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: fixed;
    left: -100%;
    z-index: 50;
    width: 280px;
    transition: left var(--transition-interactive);
  }
  .sidebar.open {
    left: 0;
  }
  .mobile-overlay {
    position: fixed;
    inset: 0;
    background: oklch(0 0 0 / 0.5);
    z-index: 49;
    display: none;
  }
  .mobile-overlay.active {
    display: block;
  }
  .mobile-menu-btn {
    display: flex;
  }
  .main-body {
    padding: var(--space-3);
  }
  .chat-messages {
    padding: var(--space-3);
  }
  .chat-input-area {
    padding: var(--space-3);
  }
  .documents-grid {
    grid-template-columns: 1fr 1fr;
  }

  /* Chat bubble tables: horizontal scroll on mobile */
  .chat-bubble table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
    max-width: calc(100vw - 90px);
  }
  .chat-bubble pre {
    max-width: calc(100vw - 90px);
  }
  /* Chat messages: full-width bubbles */
  .chat-message {
    gap: var(--space-2);
  }
  .chat-avatar {
    width: 28px;
    height: 28px;
    font-size: 11px;
  }
  .chat-input-wrapper {
    max-width: 100%;
  }

  /* Viewer context panel */
  .viewer-context-panel {
    padding: var(--space-3);
  }
}

/* Small phones */
@media (max-width: 480px) {
  .documents-grid {
    grid-template-columns: 1fr;
    gap: var(--space-3);
  }
  .main-body {
    padding: var(--space-3) var(--space-2);
  }
  .page-title {
    font-size: var(--text-lg);
  }
  /* Viewer: tighter padding */
  .viewer-content {
    padding: var(--space-2);
  }
  .viewer-topbar {
    padding: var(--space-1) var(--space-2);
    gap: var(--space-1);
  }
  .viewer-doc-name {
    max-width: 140px;
    font-size: var(--text-xs);
  }
  .viewer-page-info {
    font-size: 10px;
    min-width: 60px;
  }
  .viewer-zoom-level {
    display: none;
  }
  /* Viewer zoom buttons: hide zoom in/out on very small screens, keep download */
  .viewer-topbar-right .viewer-btn:nth-child(-n+2) {
    display: none;
  }
  /* Chat: compact */
  .chat-input-area {
    padding: var(--space-2);
  }
  .chat-messages {
    padding: var(--space-2) var(--space-2);
  }
  .chat-bubble {
    padding: var(--space-2) var(--space-3);
    font-size: 13px;
  }
  .chat-bubble table {
    font-size: 11px;
    max-width: calc(100vw - 70px);
  }
  .chat-bubble th, .chat-bubble td {
    padding: 4px 6px;
  }
  .suggested-prompts-bar {
    padding: 6px 8px;
    gap: 6px;
  }
  .suggested-prompt-chip {
    padding: 5px 10px;
    font-size: 11px;
  }
  /* XLSX viewer: optimize for touch */
  .xlsx-table {
    font-size: 11px;
  }
  .xlsx-col-header {
    padding: 3px 6px;
    font-size: 9px;
  }
  .xlsx-table tbody td:not(.xlsx-row-num) {
    padding: 3px 6px;
  }
  .xlsx-row-num {
    padding: 3px 4px;
    font-size: 9px;
    min-width: 30px;
  }
  /* Admin tabs: scroll horizontally */
  .admin-tabs {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .admin-tabs::-webkit-scrollbar {
    display: none;
  }
  .admin-tab {
    font-size: var(--text-xs);
    padding: var(--space-2);
  }
  /* Analytics */
  .analytics-container {
    padding: var(--space-3);
  }
  .analytics-stats-row {
    grid-template-columns: 1fr 1fr;
  }
  .sm-summary-cards {
    grid-template-columns: 1fr 1fr;
  }
  /* Invite link cards */
  .invite-card {
    flex-direction: column;
  }
  /* Viewer text content */
  .viewer-text-content {
    padding: var(--space-3);
  }
  /* Interactive deck overlay */
  .interactive-close-bar {
    padding: var(--space-2) var(--space-3);
    height: 44px;
  }
  .interactive-title {
    font-size: var(--text-xs);
  }
  /* Download ZIP button */
  .download-bar {
    padding: 0 var(--space-2);
  }
}

@media (min-width: 769px) {
  .mobile-menu-btn { display: none; }
  .mobile-overlay { display: none !important; }
}

/* Scrollbar styling */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--color-surface-dynamic);
  border-radius: var(--radius-full);
}
::-webkit-scrollbar-thumb:hover {
  background: var(--color-text-faint);
}

/* Spinner */
.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 600ms linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Footer */
.app-footer {
  padding: var(--space-2) var(--space-3);
  text-align: center;
  font-size: var(--text-xs);
  color: var(--color-text-faint);
  border-top: 1px solid var(--color-divider);
  margin-top: auto;
}
.app-footer a {
  color: var(--color-text-faint);
  text-decoration: none;
}
.app-footer a:hover {
  color: var(--color-text-muted);
}

/* ========== INVITE LINKS VIEW ========== */
.invites-container {
  padding: var(--space-6);
  max-width: 720px;
}
.invites-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: var(--space-4);
  margin-bottom: var(--space-6);
}
.invites-desc {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  line-height: 1.5;
  max-width: 480px;
}
.invite-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  margin-bottom: var(--space-3);
  transition: border-color var(--transition-interactive);
}
.invite-card:hover {
  border-color: var(--color-primary);
}
.invite-card.revoked {
  opacity: 0.5;
}
.invite-card.revoked:hover {
  border-color: var(--color-border);
}
.invite-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-2);
}
.invite-label {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-text);
}
.invite-badge {
  font-size: var(--text-xs);
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-full);
  font-weight: 500;
}
.invite-badge.active {
  background: color-mix(in oklch, var(--color-success) 15%, transparent);
  color: var(--color-success);
}
.invite-badge.revoked {
  background: color-mix(in oklch, var(--color-error) 15%, transparent);
  color: var(--color-error);
}
.invite-url-row {
  display: flex;
  gap: var(--space-2);
  align-items: center;
  margin-bottom: var(--space-2);
}
.invite-url {
  flex: 1;
  font-size: var(--text-xs);
  padding: var(--space-2) var(--space-3);
  background: var(--color-surface-offset);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-md);
  color: var(--color-text-muted);
  font-family: monospace;
  cursor: text;
}
.invite-meta {
  display: flex;
  gap: var(--space-2);
  font-size: var(--text-xs);
  color: var(--color-text-faint);
  flex-wrap: wrap;
}
.invite-actions {
  margin-top: var(--space-3);
  display: flex;
  gap: var(--space-2);
}
.invites-divider {
  font-size: var(--text-xs);
  color: var(--color-text-faint);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: var(--space-3) 0 var(--space-2);
  border-top: 1px solid var(--color-divider);
  margin-top: var(--space-3);
}
.invite-access-badge {
  font-weight: 500;
  color: var(--color-primary);
}

/* ========== DOCUMENT PERMISSIONS MODAL ========== */
.perm-modal {
  max-width: 520px;
}
.perm-subtitle {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  margin-top: var(--space-1);
}
.perm-help {
  font-size: var(--text-xs);
  color: var(--color-text-faint);
  line-height: 1.5;
  margin-bottom: var(--space-3);
}
.perm-doc-list {
  max-height: 320px;
  overflow-y: auto;
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-md);
  background: var(--color-surface-2);
}
.perm-doc-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-3);
  border-bottom: 1px solid var(--color-divider);
  cursor: pointer;
  transition: background var(--transition-interactive);
}
.perm-doc-row:last-child {
  border-bottom: none;
}
.perm-doc-row:hover {
  background: var(--color-surface-offset);
}
.perm-checkbox {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  accent-color: var(--color-primary);
  cursor: pointer;
}
.perm-doc-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.perm-doc-name {
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--color-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.perm-doc-meta {
  font-size: var(--text-xs);
  color: var(--color-text-faint);
}
.perm-empty {
  padding: var(--space-8);
  text-align: center;
  font-size: var(--text-xs);
  color: var(--color-text-faint);
}

/* ========== FULL-SCREEN DOCUMENT VIEWER ========== */
.viewer-overlay {
  position: fixed;
  inset: 0;
  background: var(--color-bg);
  z-index: 300;
  display: flex;
  flex-direction: column;
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms ease;
}
.viewer-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.viewer-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-2) var(--space-4);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-divider);
  flex-shrink: 0;
  min-height: 48px;
  gap: var(--space-3);
}
.viewer-topbar-left {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-width: 0;
  flex: 1;
}
.viewer-topbar-center {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-shrink: 0;
}
.viewer-topbar-right {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  flex-shrink: 0;
}

.viewer-doc-name {
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--color-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.viewer-btn {
  padding: var(--space-2);
  border-radius: var(--radius-md);
  color: var(--color-text-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-interactive);
  flex-shrink: 0;
}
.viewer-btn:hover {
  background: var(--color-surface-offset);
  color: var(--color-text);
}
.viewer-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}
.viewer-btn:disabled:hover {
  background: transparent;
  color: var(--color-text-muted);
}
.viewer-btn-danger:hover {
  background: var(--color-error-highlight);
  color: var(--color-error);
}

.viewer-page-info {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  font-weight: 500;
  white-space: nowrap;
  min-width: 80px;
  text-align: center;
}

.viewer-zoom-level {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  font-weight: 500;
  min-width: 40px;
  text-align: center;
}

.viewer-content {
  flex: 1;
  overflow: auto;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: var(--space-6);
  background: var(--color-bg);
}

.viewer-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-16);
}
.viewer-loading .spinner {
  width: 32px;
  height: 32px;
}

/* PDF continuous scroll layout */
.pdf-scroll-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-4);
  padding-bottom: var(--space-8);
  width: 100%;
}

.pdf-page-container {
  position: relative;
  width: 100%;
  max-width: 900px;
  display: flex;
  justify-content: center;
}

.pdf-page-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 200px;
  background: var(--color-surface-offset);
  border-radius: var(--radius-sm);
}

.viewer-page-image {
  max-width: 100%;
  box-shadow: var(--shadow-lg);
  border-radius: var(--radius-sm);
  transition: transform 200ms ease;
  transform-origin: top center;
}

/* PDF Link Hotspots */
.pdf-link-layer {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
  z-index: 2;
}

.pdf-link-hotspot {
  position: absolute;
  pointer-events: auto;
  cursor: pointer;
  border-radius: 3px;
  transition: background 150ms ease, box-shadow 150ms ease;
}

.pdf-link-hotspot:hover {
  background: rgba(99, 102, 241, 0.08);
  box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.25);
}

.pdf-link-hotspot.pdf-link-loom {
  cursor: pointer;
}

.pdf-link-hotspot.pdf-link-loom:hover {
  background: rgba(99, 102, 241, 0.12);
  box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.4);
}

.loom-play-badge {
  position: absolute;
  bottom: -2px;
  right: -2px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--color-accent, #625DF5);
  color: #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,0.25);
  opacity: 0;
  transform: scale(0.8);
  transition: opacity 150ms ease, transform 150ms ease;
}

.pdf-link-hotspot.pdf-link-loom:hover .loom-play-badge {
  opacity: 1;
  transform: scale(1);
}

/* Loom Video Overlay */
#loom-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 10000;
  align-items: center;
  justify-content: center;
}

#loom-overlay.active {
  display: flex;
}

.loom-overlay-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(4px);
}

.loom-overlay-content {
  position: relative;
  width: 90vw;
  max-width: 1100px;
  aspect-ratio: 16 / 9;
  border-radius: var(--radius-md, 12px);
  overflow: hidden;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.5);
}

.loom-close-btn {
  position: absolute;
  top: -40px;
  right: 0;
  z-index: 2;
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.7);
  cursor: pointer;
  padding: 4px;
  transition: color 150ms ease;
}

.loom-close-btn:hover {
  color: #fff;
}

.loom-iframe-wrap {
  width: 100%;
  height: 100%;
}

.loom-iframe {
  width: 100%;
  height: 100%;
  border: none;
  border-radius: var(--radius-md, 12px);
}

/* Document prev/next buttons in topbar */
.viewer-doc-nav-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: none;
  border: 1px solid var(--color-border);
  color: var(--color-text-muted);
  border-radius: var(--radius-sm);
  padding: 4px 10px;
  font-size: var(--text-xs);
  font-weight: 500;
  cursor: pointer;
  transition: color 150ms ease, border-color 150ms ease, background 150ms ease;
  white-space: nowrap;
}
.viewer-doc-nav-btn:hover {
  color: var(--color-text);
  border-color: var(--color-text-muted);
  background: var(--color-surface-offset);
}
.viewer-doc-nav-btn.hidden {
  visibility: hidden;
  pointer-events: none;
}
.viewer-doc-nav-btn svg {
  flex-shrink: 0;
}

.viewer-text-content {
  max-width: 720px;
  width: 100%;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-8);
  font-size: var(--text-sm);
  line-height: 1.7;
  color: var(--color-text);
  white-space: pre-wrap;
  word-wrap: break-word;
  box-shadow: var(--shadow-md);
}

.viewer-image-content {
  max-width: 100%;
  max-height: calc(100dvh - 120px);
  object-fit: contain;
  box-shadow: var(--shadow-lg);
  border-radius: var(--radius-sm);
  transition: transform 200ms ease;
  transform-origin: center center;
}

/* ========== XLSX SPREADSHEET VIEWER ========== */
.xlsx-viewer {
  width: 100%;
  max-width: 100%;
  display: flex;
  flex-direction: column;
  height: calc(100dvh - 120px);
}

.xlsx-tab-bar {
  display: flex;
  gap: 2px;
  padding: 0 var(--space-2);
  background: var(--color-bg);
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
  overflow-x: auto;
}

.xlsx-tab {
  padding: var(--space-2) var(--space-4);
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--color-text-muted);
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  white-space: nowrap;
  transition: color 150ms, border-color 150ms;
}

.xlsx-tab:hover {
  color: var(--color-text);
}

.xlsx-tab.active {
  color: var(--color-primary);
  border-bottom-color: var(--color-primary);
}

.xlsx-sheet {
  flex: 1;
  min-height: 0;
}

.xlsx-table-wrap {
  overflow: auto;
  height: 100%;
  background: #fff;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
}

.xlsx-table {
  border-collapse: collapse;
  font-size: 12px;
  font-family: 'SF Mono', 'Menlo', 'Monaco', 'Consolas', monospace;
  line-height: 1.4;
  white-space: nowrap;
}

.xlsx-table thead {
  position: sticky;
  top: 0;
  z-index: 2;
}

.xlsx-col-header {
  background: #f0f0f0;
  color: #666;
  font-weight: 500;
  font-size: 10px;
  text-align: center;
  padding: 4px 8px;
  border: 1px solid #ddd;
  border-top: none;
  min-width: 40px;
}

.xlsx-corner {
  background: #e8e8e8;
  border: 1px solid #ddd;
  border-top: none;
  min-width: 40px;
  position: sticky;
  left: 0;
  z-index: 3;
}

.xlsx-row-num {
  background: #f0f0f0;
  color: #666;
  font-weight: 500;
  font-size: 10px;
  text-align: center;
  padding: 4px 6px;
  border: 1px solid #ddd;
  position: sticky;
  left: 0;
  z-index: 1;
  min-width: 40px;
}

.xlsx-table tbody td:not(.xlsx-row-num) {
  padding: 4px 8px;
  border: 1px solid #e0e0e0;
  color: #1a1a1a;
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.xlsx-table tbody tr:hover td {
  background-color: #f5f8ff;
}

.xlsx-table tbody tr:hover td.xlsx-row-num {
  background-color: #e0e8f0;
}

/* ========== ANALYTICS VIEW ========== */
.analytics-container {
  padding: var(--space-6);
  max-width: 900px;
}
.analytics-header {
  margin-bottom: var(--space-6);
}
.analytics-desc {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  line-height: 1.5;
  max-width: 600px;
}

/* Analytics summary table */
.analytics-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.analytics-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-xs);
  min-width: 500px;
}
.analytics-table th {
  text-align: left;
  padding: var(--space-3) var(--space-3);
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 2px solid var(--color-divider);
  white-space: nowrap;
}
.analytics-table td {
  padding: var(--space-3) var(--space-3);
  border-bottom: 1px solid var(--color-divider);
  color: var(--color-text);
}
.analytics-table tr {
  cursor: pointer;
  transition: background var(--transition-interactive);
}
.analytics-table tbody tr:hover {
  background: var(--color-surface-offset);
}
.analytics-doc-name {
  font-weight: 500;
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.analytics-num {
  font-variant-numeric: tabular-nums;
  text-align: right;
}

/* Analytics detail view */
.analytics-detail-header {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-6);
}
.analytics-back-btn {
  padding: var(--space-2);
  border-radius: var(--radius-md);
  color: var(--color-text-muted);
  transition: all var(--transition-interactive);
  display: inline-flex;
  align-items: center;
}
.analytics-back-btn:hover {
  background: var(--color-surface-offset);
  color: var(--color-text);
}
.analytics-detail-title {
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--color-text);
}

.analytics-stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: var(--space-4);
  margin-bottom: var(--space-8);
}
.analytics-stat-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
}
.analytics-stat-value {
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--color-text);
  font-variant-numeric: tabular-nums;
}
.analytics-stat-label {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  margin-top: var(--space-1);
}

/* Page heatmap bar chart */
.analytics-section-title {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: var(--space-4);
}
.analytics-bar-chart {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin-bottom: var(--space-8);
}
.analytics-bar-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}
.analytics-bar-label {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  width: 60px;
  text-align: right;
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}
.analytics-bar-track {
  flex: 1;
  height: 24px;
  background: var(--color-surface-offset);
  border-radius: var(--radius-sm);
  overflow: hidden;
  position: relative;
}
.analytics-bar-fill {
  height: 100%;
  background: var(--color-primary);
  border-radius: var(--radius-sm);
  transition: width 400ms cubic-bezier(0.16, 1, 0.3, 1);
  min-width: 2px;
}
.analytics-bar-value {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  width: 80px;
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}

/* Viewer breakdown table */
.analytics-viewer-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-xs);
}
.analytics-viewer-table th {
  text-align: left;
  padding: var(--space-2) var(--space-3);
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 2px solid var(--color-divider);
}
.analytics-viewer-table td {
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--color-divider);
  color: var(--color-text);
}

/* ========== BULK SELECTION ========== */

/* Checkbox on doc cards */
.doc-card-checkbox {
  position: absolute;
  top: var(--space-2);
  right: var(--space-2);
  width: 20px;
  height: 20px;
  accent-color: var(--color-primary);
  cursor: pointer;
  z-index: 2;
  opacity: 0;
  transition: opacity var(--transition-interactive);
}
.doc-card:hover .doc-card-checkbox,
.doc-card-checkbox:checked {
  opacity: 1;
}
.doc-card.selected {
  border-color: var(--color-primary);
  background: var(--color-primary-highlight);
}

/* Bulk action bar */
.bulk-action-bar {
  position: fixed;
  bottom: var(--space-6);
  left: 50%;
  transform: translateX(-50%);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-xl);
  padding: var(--space-3) var(--space-5);
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: var(--space-4);
  z-index: 90;
  animation: bulk-bar-in 250ms cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes bulk-bar-in {
  from { opacity: 0; transform: translateX(-50%) translateY(16px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}
.bulk-count {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-text);
  white-space: nowrap;
}
.bulk-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.bulk-move-wrapper {
  position: relative;
}
.bulk-move-dropdown {
  position: absolute;
  bottom: calc(100% + var(--space-2));
  left: 0;
  min-width: 200px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  z-index: 91;
  max-height: 240px;
  overflow-y: auto;
}
.bulk-move-option {
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-xs);
  color: var(--color-text);
  cursor: pointer;
  transition: background var(--transition-interactive);
}
.bulk-move-option:hover {
  background: var(--color-surface-offset);
}

/* ========== MOBILE VIEWER ========== */
@media (max-width: 768px) {
  .viewer-topbar {
    padding: var(--space-2);
    gap: var(--space-1);
  }
  .viewer-doc-name {
    max-width: 120px;
  }
  .viewer-content {
    padding: var(--space-3);
  }
  .viewer-text-content {
    padding: var(--space-4);
  }
  .bulk-action-bar {
    left: var(--space-4);
    right: var(--space-4);
    transform: none;
    width: auto;
  }
  @keyframes bulk-bar-in {
    from { opacity: 0; transform: translateY(16px); }
    to { opacity: 1; transform: translateY(0); }
  }
  .analytics-stats-row {
    grid-template-columns: 1fr 1fr;
  }
}

/* ========== ADMIN TABS ========== */
.admin-tabs {
  display: flex;
  gap: var(--space-1);
  border-bottom: 1px solid var(--color-border);
  margin-bottom: var(--space-5);
}
.admin-tab {
  background: none;
  border: none;
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--color-text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 180ms ease, border-color 180ms ease;
  white-space: nowrap;
}
.admin-tab:hover {
  color: var(--color-text);
}
.admin-tab.active {
  color: var(--color-text);
  border-bottom-color: var(--color-text);
}
.admin-tab-content {
  display: none;
}
.admin-tab-content.active {
  display: block;
}

/* ========== CHAT LOGS ========== */
.chat-log-card {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  margin-bottom: var(--space-3);
  background: var(--color-surface);
}
.chat-log-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-2);
}
.chat-log-viewer {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-text);
}
.chat-log-time {
  font-size: var(--text-xs);
  color: var(--color-text-faint);
}
.chat-log-prompt {
  font-size: var(--text-sm);
  color: var(--color-text);
  padding: var(--space-2) var(--space-3);
  background: oklch(var(--color-base-l) calc(var(--color-base-c) + 0.01) var(--color-base-h) / 0.5);
  border-radius: var(--radius-sm);
  margin-bottom: var(--space-2);
  line-height: 1.5;
}
.chat-log-response {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  padding: var(--space-2) var(--space-3);
  border-left: 2px solid var(--color-border);
  max-height: 120px;
  overflow: hidden;
  position: relative;
  line-height: 1.5;
  cursor: pointer;
  transition: max-height 300ms ease;
}
.chat-log-response.expanded {
  max-height: none;
}
.chat-log-response:not(.expanded)::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 32px;
  background: linear-gradient(transparent, var(--color-surface));
  pointer-events: none;
}
.chat-log-expand {
  font-size: var(--text-xs);
  color: var(--color-text-faint);
  background: none;
  border: none;
  cursor: pointer;
  padding: var(--space-1) 0;
  margin-top: var(--space-1);
}
.chat-log-expand:hover {
  color: var(--color-text-muted);
}

/* ========== ADMIN CONTEXT EDITOR ========== */
.admin-context-editor {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  overflow: hidden;
}
.admin-context-textarea {
  width: 100%;
  min-height: 200px;
  padding: var(--space-4);
  border: none;
  background: transparent;
  color: var(--color-text);
  font-family: inherit;
  font-size: var(--text-sm);
  line-height: 1.6;
  resize: vertical;
  outline: none;
}
.admin-context-textarea::placeholder {
  color: var(--color-text-faint);
}
.admin-context-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-2) var(--space-4);
  border-top: 1px solid var(--color-border);
  background: oklch(var(--color-base-l) calc(var(--color-base-c) + 0.005) var(--color-base-h) / 0.3);
}
.admin-context-status {
  font-size: var(--text-xs);
  color: var(--color-text-faint);
}

/* Supermemory Panel */
.supermemory-panel {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}
.supermemory-status {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  padding: var(--space-3) var(--space-4);
  background: oklch(var(--color-base-l) calc(var(--color-base-c) + 0.005) var(--color-base-h) / 0.3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
}
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.status-dot.connected { background: oklch(0.7 0.2 145); }
.status-dot.warning { background: oklch(0.75 0.15 75); }
.status-dot.disconnected { background: oklch(0.65 0.2 25); }
.status-dot.checking { background: oklch(0.7 0.1 230); animation: pulse-dot 1.5s infinite; }
@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}
.supermemory-actions {
  display: flex;
  gap: var(--space-2);
}
.sm-summary-cards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}
.sm-card {
  background: oklch(var(--color-base-l) calc(var(--color-base-c) + 0.005) var(--color-base-h) / 0.3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  text-align: center;
}
.sm-card.success .sm-card-num { color: oklch(0.7 0.2 145); }
.sm-card.skipped .sm-card-num { color: oklch(0.7 0.1 230); }
.sm-card.error .sm-card-num { color: oklch(0.65 0.2 25); }
.sm-card-num {
  font-size: var(--text-2xl);
  font-weight: 700;
  line-height: 1;
  margin-bottom: var(--space-1);
}
.sm-card-label {
  font-size: var(--text-xs);
  color: var(--color-text-faint);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.sm-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}
.sm-table th {
  text-align: left;
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--color-border);
  font-weight: 600;
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-faint);
}
.sm-table td {
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid oklch(var(--color-base-l) var(--color-base-c) var(--color-base-h) / 0.1);
  vertical-align: middle;
}
.sm-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: 600;
}
.sm-status-pushed { background: oklch(0.7 0.2 145 / 0.15); color: oklch(0.7 0.2 145); }
.sm-status-skipped { background: oklch(0.7 0.1 230 / 0.15); color: oklch(0.7 0.1 230); }
.sm-status-error { background: oklch(0.65 0.2 25 / 0.15); color: oklch(0.65 0.2 25); }
.sm-reason {
  font-size: var(--text-xs);
  color: var(--color-text-faint);
}
@media (max-width: 640px) {
  .sm-summary-cards { grid-template-columns: repeat(2, 1fr); }
}

/* Site URL Config */
.site-url-config {
  background: oklch(var(--color-base-l) calc(var(--color-base-c) + 0.005) var(--color-base-h) / 0.3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  margin-bottom: var(--space-4);
}
.site-url-notice {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-xs);
  color: var(--color-text-secondary);
  margin-bottom: var(--space-3);
}
.site-url-notice svg {
  flex-shrink: 0;
  color: var(--color-warning, oklch(0.75 0.15 75));
}
.site-url-row {
  display: flex;
  gap: var(--space-2);
  align-items: center;
}
.site-url-row .input {
  flex: 1;
  font-size: var(--text-xs);
}
.site-url-config.configured .site-url-notice svg {
  color: var(--color-success, oklch(0.65 0.15 145));
}

/* Admin Login Link */
.admin-login-link {
  display: block;
  text-align: center;
  font-size: var(--text-xs);
  color: var(--color-text-faint);
  text-decoration: none;
  margin-top: var(--space-4);
  transition: color 180ms ease;
}
.admin-login-link:hover {
  color: var(--color-text-secondary);
}
.login-back-link {
  display: block;
  text-align: center;
  font-size: var(--text-xs);
  color: var(--color-text-faint);
  text-decoration: none;
  margin-top: var(--space-3);
  transition: color 180ms ease;
}
.login-back-link:hover {
  color: var(--color-text-secondary);
}

/* Invite Code Display */
.invite-code-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3);
  background: oklch(var(--color-base-l) calc(var(--color-base-c) + 0.005) var(--color-base-h) / 0.4);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-3);
}
.invite-code-display {
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  font-size: var(--text-base);
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--color-text);
  flex: 1;
}

/* ====== Documents Toolbar ====== */
.docs-toolbar {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  padding: var(--space-4) var(--space-6) 0;
}

/* ====== Saved Chats ====== */
.saved-chats-container {
  max-width: var(--content-default);
  padding: var(--space-6);
}
.saved-chats-header {
  margin-bottom: var(--space-6);
}
.saved-chat-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-4) var(--space-5);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  margin-bottom: var(--space-3);
  background: var(--color-surface);
  transition: border-color var(--transition-interactive);
}
.saved-chat-card:hover {
  border-color: var(--color-text-faint);
}
.saved-chat-card-body {
  flex: 1;
  min-width: 0;
}
.saved-chat-title {
  font-weight: 500;
  font-size: var(--text-sm);
  color: var(--color-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: var(--space-1);
}
.saved-chat-meta {
  font-size: var(--text-xs);
  color: var(--color-text-faint);
}
.saved-chat-actions {
  display: flex;
  gap: var(--space-2);
  flex-shrink: 0;
}
@media (max-width: 640px) {
  .saved-chat-card {
    flex-direction: column;
    align-items: flex-start;
  }
  .saved-chat-actions {
    width: 100%;
  }
}

/* ========== VIEWER CONTEXT PANEL ========== */
.viewer-context-panel {
  flex-shrink: 0;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding: var(--space-5) var(--space-6);
  max-height: 50vh;
  overflow-y: auto;
  animation: vcSlideDown 200ms ease-out;
}

@keyframes vcSlideDown {
  from { opacity: 0; max-height: 0; padding-top: 0; padding-bottom: 0; }
  to { opacity: 1; max-height: 50vh; padding-top: var(--space-5); padding-bottom: var(--space-5); }
}

.viewer-context-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-3);
}

.viewer-context-header h3 {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-text);
  margin: 0;
}

.viewer-context-desc {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  line-height: 1.5;
  margin: 0 0 var(--space-4) 0;
}

.viewer-context-section {
  margin-bottom: var(--space-4);
}

.viewer-context-section:last-child {
  margin-bottom: 0;
}

.viewer-context-label {
  display: block;
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-muted);
  margin-bottom: var(--space-2);
}

.viewer-context-textarea {
  width: 100%;
  min-height: 100px;
  max-height: 200px;
  padding: var(--space-3);
  font-family: var(--font-body);
  font-size: var(--text-sm);
  line-height: 1.6;
  color: var(--color-text);
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  resize: vertical;
  transition: border-color var(--transition-interactive);
}

.viewer-context-textarea:focus {
  outline: none;
  border-color: var(--color-primary);
}

.viewer-context-textarea::placeholder {
  color: var(--color-text-faint);
  font-size: var(--text-xs);
}

.viewer-context-status {
  font-size: var(--text-xs);
  color: var(--color-success);
  margin-left: var(--space-2);
  opacity: 0;
  transition: opacity 300ms ease;
}

.viewer-context-status.visible {
  opacity: 1;
}

.viewer-context-file-desc {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  margin: 0 0 var(--space-3) 0;
}

.viewer-context-files {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin-bottom: var(--space-3);
}

.viewer-context-file-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-size: var(--text-xs);
}

.viewer-context-file-info {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
  flex: 1;
}

.viewer-context-file-info svg {
  flex-shrink: 0;
  color: var(--color-text-muted);
}

.viewer-context-file-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--color-text);
  font-weight: 500;
}

.viewer-context-file-size {
  flex-shrink: 0;
  color: var(--color-text-faint);
}

.viewer-context-file-delete {
  flex-shrink: 0;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--color-text-faint);
  padding: 2px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color var(--transition-interactive), background var(--transition-interactive);
}

.viewer-context-file-delete:hover {
  color: var(--color-error);
  background: var(--color-error-highlight);
}

.viewer-context-upload-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--color-primary);
  background: none;
  border: 1px dashed var(--color-border);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: border-color var(--transition-interactive), background var(--transition-interactive);
}

.viewer-context-upload-btn:hover {
  border-color: var(--color-primary);
  background: var(--color-primary-highlight);
}

.viewer-context-upload-btn svg {
  flex-shrink: 0;
}

#chat-context-btn.active {
  background: var(--color-primary-highlight);
  color: var(--color-primary);
}

@media (max-width: 640px) {
  .viewer-context-panel {
    padding: var(--space-4);
  }
}

/* ========== INTERACTIVE DOCUMENT OVERLAY ========== */

#interactive-overlay {
  position: fixed;
  inset: 0;
  z-index: 10000;
  background: var(--color-bg);
  display: none;
  flex-direction: column;
}

#interactive-overlay.active {
  display: flex;
}

.interactive-close-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-5);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
  height: 52px;
  box-sizing: border-box;
}

.interactive-bar-left {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-width: 0;
}

.interactive-title {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.interactive-bar-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-shrink: 0;
}

.interactive-download-btn,
.interactive-close-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  border: none;
  background: transparent;
  color: var(--color-text-muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  flex-shrink: 0;
}

.interactive-download-btn:hover,
.interactive-close-btn:hover {
  background: var(--color-surface-offset);
  color: var(--color-text);
}

.interactive-iframe {
  flex: 1;
  width: 100%;
  border: none;
  background: var(--color-bg);
}

