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

html, body {
  height: 100%;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: #ffffff;
  color: #1a1a1a;
  overflow: hidden;
}

#app {
  display: flex;
  height: 100vh;
  width: 100vw;
}

.sidebar {
  width: 240px;
  min-width: 240px;
  background: #f8f9fa;
  border-right: 1px solid #e5e7eb;
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  padding: 20px;
  border-bottom: 1px solid #e5e7eb;
}

.sidebar-header h1 {
  font-size: 20px;
  font-weight: 700;
  color: #111827;
  letter-spacing: -0.02em;
}

.accent {
  color: #2563eb;
}

.sidebar-scroll {
  flex: 1;
  overflow-y: auto;
}

.sidebar-section {
  padding: 16px 12px 8px;
}

.sidebar-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #9ca3af;
  padding: 0 8px;
  margin-bottom: 6px;
}

.sidebar-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  color: #374151;
  transition: background 0.15s;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-item:hover {
  background: #e5e7eb;
}

.sidebar-item.active {
  background: #dbeafe;
  color: #1d4ed8;
  font-weight: 500;
}

.sidebar-item .si-icon {
  flex-shrink: 0;
  font-size: 16px;
}

.sidebar-item .si-text {
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 8px;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  background: #fff;
  color: #374151;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s;
  margin-top: 4px;
}

.sidebar-btn:hover {
  background: #f3f4f6;
}

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid #e5e7eb;
}

.cc-status {
  padding: 10px;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 8px;
  font-size: 13px;
  color: #1e40af;
}

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

.cc-bar {
  height: 4px;
  background: #dbeafe;
  border-radius: 2px;
  margin-top: 6px;
  overflow: hidden;
}

.cc-fill {
  height: 100%;
  width: 0%;
  background: #2563eb;
  border-radius: 2px;
  transition: width 0.3s;
}

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 24px;
  border-bottom: 1px solid #e5e7eb;
  background: #fff;
  min-height: 52px;
}

.topbar-title {
  font-size: 15px;
  font-weight: 600;
  color: #111827;
}

.topbar-project {
  font-size: 13px;
  color: #6b7280;
  flex: 1;
}

.topbar-btn {
  padding: 6px 12px;
  font-size: 13px;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  background: #fff;
  color: #374151;
  cursor: pointer;
  font-weight: 500;
  white-space: nowrap;
  transition: background 0.15s;
}

.topbar-btn:hover {
  background: #f3f4f6;
  border-color: #d1d5db;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.message {
  max-width: 780px;
  width: 100%;
  margin: 0 auto;
  display: flex;
  gap: 12px;
}

.msg-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 600;
  flex-shrink: 0;
  margin-top: 2px;
}

.message.user .msg-avatar {
  background: #dbeafe;
  color: #1d4ed8;
}

.message.assistant .msg-avatar {
  background: #f3e8ff;
  color: #7c3aed;
}

.msg-body {
  flex: 1;
  min-width: 0;
}

.msg-role {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 4px;
  color: #374151;
}

.msg-text {
  font-size: 15px;
  line-height: 1.65;
  color: #1f2937;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.doc-upload-card {
  background: #f0f7ff;
  border: 1px solid #bfdbfe;
  border-radius: 10px;
  padding: 14px 18px;
  max-width: 520px;
}

.doc-upload-card .duc-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.doc-upload-card .duc-icon {
  font-size: 24px;
}

.doc-upload-card .duc-name {
  font-size: 14px;
  font-weight: 600;
  color: #1d4ed8;
}

.doc-upload-card .duc-meta {
  font-size: 12px;
  color: #6b7280;
}

.doc-upload-card .duc-preview {
  font-size: 13px;
  line-height: 1.5;
  color: #4b5563;
  max-height: 80px;
  overflow: hidden;
  white-space: pre-wrap;
  border-top: 1px solid #dbeafe;
  padding-top: 8px;
  margin-top: 4px;
}

.doc-upload-card .duc-status {
  font-size: 12px;
  color: #2563eb;
  font-weight: 500;
  margin-top: 8px;
  padding: 6px 10px;
  background: #eff6ff;
  border-radius: 6px;
}

.doc-upload-card .duc-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid #dbeafe;
}

.duc-btn {
  padding: 8px 14px;
  font-size: 13px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  background: #fff;
  color: #374151;
  cursor: pointer;
  font-weight: 500;
  transition: background 0.15s, border-color 0.15s;
}

.duc-btn:hover {
  background: #f3f4f6;
}

.duc-btn:disabled {
  opacity: 0.6;
  cursor: default;
}

.duc-btn-analyze {
  color: #7c3aed;
  border-color: #c4b5fd;
  background: #f5f3ff;
}

.duc-btn-analyze:hover {
  background: #ede9fe;
}

.duc-btn-global {
  color: #2563eb;
  border-color: #93c5fd;
  background: #eff6ff;
}

.duc-btn-global:hover {
  background: #dbeafe;
}

.duc-btn-project {
  color: #059669;
  border-color: #6ee7b7;
  background: #ecfdf5;
}

.duc-btn-project:hover {
  background: #d1fae5;
}

.collapsed-card {
  background: #f3f4f6;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 12px 16px;
  max-width: 500px;
}

.collapsed-preview {
  font-size: 13px;
  line-height: 1.5;
  color: #6b7280;
  white-space: pre-wrap;
  max-height: 60px;
  overflow: hidden;
}

.collapsed-meta {
  font-size: 12px;
  color: #9ca3af;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid #e5e7eb;
}

.btn-expand {
  margin-top: 6px;
  padding: 4px 10px;
  border: 1px solid #d1d5db;
  border-radius: 4px;
  background: #fff;
  color: #2563eb;
  font-size: 12px;
  cursor: pointer;
}

.btn-expand:hover {
  background: #eff6ff;
}

.cursor-blink {
  display: inline-block;
  width: 2px;
  height: 16px;
  background: #2563eb;
  animation: blink 1s step-end infinite;
  vertical-align: text-bottom;
  margin-left: 2px;
}

@keyframes blink {
  50% { opacity: 0; }
}

.input-area {
  padding: 16px 24px 24px;
  background: #fff;
  border-top: 1px solid #f3f4f6;
}

.input-box {
  max-width: 100%;
  margin: 0 16px;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  padding: 8px 12px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.input-box:focus-within {
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.chat-textarea {
  flex: 1;
  border: none;
  background: transparent;
  resize: none;
  font-size: 16px;
  font-family: inherit;
  line-height: 1.6;
  color: #1a1a1a;
  outline: none;
  min-height: 72px;
  max-height: 300px;
  padding: 8px 0;
}

.chat-textarea::placeholder {
  color: #9ca3af;
}

.icon-btn {
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  color: #6b7280;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
}

.icon-btn:hover {
  background: #e5e7eb;
  color: #374151;
}

.paper-btn {
  padding: 6px 12px;
  border: none;
  background: #7c3aed;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  flex-shrink: 0;
  gap: 4px;
  transition: background 0.15s;
  white-space: nowrap;
}

.paper-btn:hover {
  background: #6d28d9;
}

.paper-btn:disabled {
  background: #c4b5fd;
  cursor: not-allowed;
}

.send-btn {
  width: 36px;
  height: 36px;
  border: none;
  background: #2563eb;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 18px;
  flex-shrink: 0;
  transition: background 0.15s;
}

.send-btn:hover {
  background: #1d4ed8;
}

.send-btn:disabled {
  background: #93c5fd;
  cursor: not-allowed;
}

.file-input {
  display: none;
}

.doc-panel {
  width: 260px;
  min-width: 260px;
  background: #fafbfc;
  border-left: 1px solid #e5e7eb;
  display: flex;
  flex-direction: column;
}

.doc-panel-header {
  padding: 16px 16px 12px;
  border-bottom: 1px solid #e5e7eb;
}

.doc-panel-title {
  font-size: 14px;
  font-weight: 600;
  color: #111827;
}

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

.doc-panel-empty {
  text-align: center;
  padding: 24px 16px;
  color: #9ca3af;
  font-size: 13px;
  line-height: 1.5;
}

.dp-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 10px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s;
  margin-bottom: 2px;
}

.dp-item:hover {
  background: #e8f0fe;
}

.dp-item .dp-icon {
  font-size: 18px;
  flex-shrink: 0;
}

.dp-item .dp-info {
  flex: 1;
  min-width: 0;
}

.dp-item .dp-name {
  font-size: 13px;
  font-weight: 500;
  color: #374151;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dp-item .dp-words {
  font-size: 11px;
  color: #9ca3af;
}

.dp-item .dp-actions {
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity 0.15s;
}

.dp-item:hover .dp-actions {
  opacity: 1;
}

.dp-action-btn {
  width: 24px;
  height: 24px;
  border: none;
  background: transparent;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #6b7280;
}

.dp-action-btn:hover {
  background: #dbeafe;
  color: #2563eb;
}

.drop-overlay {
  position: fixed;
  inset: 0;
  background: rgba(37, 99, 235, 0.08);
  border: 3px dashed #2563eb;
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.drop-overlay.active {
  display: flex;
}

.drop-label {
  font-size: 20px;
  font-weight: 600;
  color: #2563eb;
  background: #fff;
  padding: 24px 48px;
  border-radius: 12px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.1);
  pointer-events: none;
}

.modal-bg {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 500;
  display: none;
  align-items: center;
  justify-content: center;
}

.modal-bg.active {
  display: flex;
}

.modal {
  background: #fff;
  border-radius: 12px;
  max-width: 90vw;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 8px 32px rgba(0,0,0,0.15);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid #e5e7eb;
}

.modal-title {
  font-size: 16px;
  font-weight: 600;
  color: #111827;
}

.modal-x {
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  border-radius: 6px;
  cursor: pointer;
  font-size: 18px;
  color: #6b7280;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-x:hover {
  background: #f3f4f6;
}

.modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
}

.modal-foot {
  padding: 12px 20px;
  border-top: 1px solid #e5e7eb;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.library-desc {
  font-size: 13px;
  color: #6b7280;
  margin-bottom: 12px;
}

.doc-list {
  list-style: none;
}

.doc-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s;
}

.doc-item:hover {
  background: #f3f4f6;
}

.doc-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1;
}

.doc-icon {
  font-size: 18px;
  flex-shrink: 0;
}

.doc-name {
  font-size: 14px;
  color: #374151;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.doc-date {
  font-size: 12px;
  color: #9ca3af;
  flex-shrink: 0;
}

.doc-item-actions {
  display: flex;
  gap: 4px;
  margin-left: 8px;
}

.doc-item-actions button {
  padding: 3px 8px;
  font-size: 11px;
  border: 1px solid #d1d5db;
  border-radius: 4px;
  background: #fff;
  color: #374151;
  cursor: pointer;
}

.doc-item-actions button:hover {
  background: #eff6ff;
  color: #2563eb;
}

.empty-state {
  text-align: center;
  padding: 16px;
  color: #9ca3af;
  font-size: 13px;
  list-style: none;
}

.text-input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
}

.text-input:focus {
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.btn-ok {
  padding: 8px 16px;
  background: #2563eb;
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  cursor: pointer;
}

.btn-ok:hover {
  background: #1d4ed8;
}

.btn-cancel {
  padding: 8px 16px;
  background: #fff;
  color: #374151;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  font-size: 14px;
  cursor: pointer;
}

.btn-cancel:hover {
  background: #f3f4f6;
}

.welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  padding: 40px;
  text-align: center;
}

.welcome h2 {
  font-size: 24px;
  font-weight: 700;
  color: #111827;
  margin-bottom: 8px;
}

.welcome p {
  font-size: 15px;
  color: #6b7280;
  max-width: 420px;
  line-height: 1.6;
}

.download-bar {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.dl-btn {
  padding: 6px 14px;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  background: #fff;
  color: #374151;
  font-size: 13px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: background 0.15s;
}

.dl-btn:hover {
  background: #f3f4f6;
}

.hidden {
  display: none !important;
}

.notification {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 14px;
  z-index: 2000;
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
  transition: opacity 0.3s;
  max-width: 500px;
  text-align: center;
}

.notification.error {
  background: #fef2f2;
  color: #991b1b;
  border: 1px solid #fecaca;
}

.notification.success {
  background: #f0fdf4;
  color: #166534;
  border: 1px solid #bbf7d0;
}

.notification.info {
  background: #eff6ff;
  color: #1e40af;
  border: 1px solid #bfdbfe;
}

.paper-popup {
  position: fixed;
  bottom: 80px;
  right: 40px;
  width: 600px;
  max-width: calc(100vw - 80px);
  max-height: 70vh;
  background: #fff;
  border: 1px solid #d1d5db;
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2), 0 0 0 1px rgba(0,0,0,0.05);
  display: flex;
  flex-direction: column;
  z-index: 5000;
  overflow: hidden;
}

.pp-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: #7c3aed;
  color: #fff;
  cursor: grab;
  user-select: none;
  flex-shrink: 0;
}

.pp-header:active { cursor: grabbing; }

.pp-title {
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}

.pp-controls {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.pp-controls button {
  background: rgba(255,255,255,0.2);
  border: none;
  color: #fff;
  width: 26px;
  height: 26px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

.pp-controls button:hover { background: rgba(255,255,255,0.35); }

.pp-status {
  padding: 8px 14px;
  background: #f5f3ff;
  border-bottom: 1px solid #e5e7eb;
  flex-shrink: 0;
}

.pp-status-text {
  font-size: 12px;
  color: #6b7280;
  display: block;
  margin-bottom: 4px;
}

.pp-bar {
  height: 4px;
  background: #e5e7eb;
  border-radius: 2px;
  overflow: hidden;
}

.pp-fill {
  height: 100%;
  width: 0%;
  background: #7c3aed;
  border-radius: 2px;
  transition: width 0.4s ease;
}

.pp-body {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}

.pp-content {
  padding: 16px;
  font-size: 14px;
  line-height: 1.7;
  color: #1a1a1a;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.pp-content:empty::after {
  content: 'Waiting for content...';
  color: #9ca3af;
  font-style: italic;
}

.pp-footer {
  padding: 10px 14px;
  background: #f9fafb;
  border-top: 1px solid #e5e7eb;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.pp-downloads {
  display: flex;
  gap: 6px;
}

.pp-word-count {
  font-size: 12px;
  color: #6b7280;
  font-weight: 500;
}

.lib-selectable {
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  transition: background 0.15s;
}

.lib-selectable:hover {
  background: #f3f4f6;
}

.lib-selected {
  background: #ede9fe;
  border-left: 3px solid #7c3aed;
}

.lib-selected:hover {
  background: #ddd6fe;
}

.lib-checkbox-wrap {
  flex-shrink: 0;
  display: flex;
  align-items: center;
}

.lib-checkbox {
  width: 18px;
  height: 18px;
  accent-color: #7c3aed;
  cursor: pointer;
}

.doc-meta-right {
  margin-left: auto;
  font-size: 12px;
  color: #9ca3af;
  white-space: nowrap;
  flex-shrink: 0;
}

.tractatus-popup {
  position: fixed;
  bottom: 80px;
  left: 40px;
  width: 380px;
  max-width: calc(100vw - 80px);
  max-height: 50vh;
  background: #fff;
  border: 1px solid #d1d5db;
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.15);
  z-index: 600;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.tp-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: linear-gradient(135deg, #059669, #10b981);
  color: #fff;
  cursor: grab;
  flex-shrink: 0;
  border-radius: 12px 12px 0 0;
}

.tp-header:active { cursor: grabbing; }

.tp-title {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tp-controls {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.tp-controls button {
  background: rgba(255,255,255,0.2);
  border: none;
  color: #fff;
  width: 24px;
  height: 24px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.tp-controls button:hover { background: rgba(255,255,255,0.35); }

.tp-body {
  flex: 1;
  overflow: hidden;
  min-height: 0;
}

.tp-content {
  padding: 12px 14px;
  font-family: 'SF Mono', 'Consolas', 'Monaco', monospace;
  font-size: 11px;
  line-height: 1.5;
  color: #374151;
  overflow-y: auto;
  max-height: 30vh;
  white-space: pre-wrap;
  word-break: break-word;
}
