:root {
  --bg-page: #f2f4f7;
  --bg-surface: #ffffff;
  --bg-subtle: #f8fafc;
  --bg-bubble: #e6f4ea;
  --bg-bubble-border: #cde8d5;
  --border-color: #e2e8f0;
  --border-strong: #cbd5e1;
  --text-primary: #1e293b;
  --text-secondary: #475569;
  --text-muted: #64748b;
  --accent: #07a65b;
  --accent-hover: #058e4d;
  --accent-light: #ecfdf5;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --danger-light: #fef2f2;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 6px 20px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 16px 40px rgba(15, 23, 42, 0.14);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: var(--font-sans);
  font-size: 14px;
  color: var(--text-primary);
  background: var(--bg-page);
  -webkit-font-smoothing: antialiased;
}

.hidden {
  display: none !important;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
  text-decoration: none;
  white-space: nowrap;
}

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

.btn-sm {
  padding: 5px 10px;
  font-size: 12.5px;
}

.btn-block {
  width: 100%;
  padding: 10px 16px;
  font-size: 14px;
}

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

.btn-secondary {
  background: var(--bg-subtle);
  border-color: var(--border-strong);
  color: var(--text-primary);
}
.btn-secondary:hover:not(:disabled) {
  background: #eef2f6;
}

.btn-outline {
  background: #ffffff;
  border-color: var(--border-strong);
  color: var(--text-secondary);
}
.btn-outline:hover:not(:disabled) {
  background: var(--bg-subtle);
  color: var(--text-primary);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}
.btn-ghost:hover:not(:disabled) {
  background: #eef2f6;
  color: var(--text-primary);
}

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

.text-danger {
  color: var(--danger) !important;
}
.text-danger:hover:not(:disabled) {
  background: var(--danger-light) !important;
}

/* Forms */
.form-stack {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
}

input[type="text"],
input[type="password"],
textarea {
  font-family: inherit;
  font-size: 14px;
  color: var(--text-primary);
  background: #ffffff;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input[type="text"]:focus,
input[type="password"]:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(7, 166, 91, 0.12);
}

.checkbox-row,
.checkbox-inline {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  user-select: none;
}

.form-error {
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  background: var(--danger-light);
  border: 1px solid #fecaca;
  color: var(--danger);
  font-size: 13px;
}

/* Login View */
.login-view {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: linear-gradient(160deg, #eef2f6 0%, #f8fafc 100%);
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 28px;
  box-shadow: var(--shadow-md);
}

.login-header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 24px;
}

.brand-badge {
  width: 44px;
  height: 44px;
  border-radius: 11px;
  background: var(--accent-light);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.login-header h1 {
  margin: 0;
  font-size: 19px;
  font-weight: 600;
  color: var(--text-primary);
}

.login-subtitle {
  margin: 4px 0 0;
  font-size: 12.5px;
  color: var(--text-muted);
}

/* App Shell */
.app-shell {
  height: 100vh;
  display: flex;
  flex-direction: column;
  max-width: 1280px;
  margin: 0 auto;
  background: var(--bg-surface);
  border-left: 1px solid var(--border-color);
  border-right: 1px solid var(--border-color);
  position: relative;
}

/* Topbar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
  flex-wrap: wrap;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-mini {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--accent);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
}

.brand-title-wrap {
  display: flex;
  flex-direction: column;
}

.brand-title {
  font-size: 15px;
  font-weight: 600;
  line-height: 1.2;
}

.ws-indicator {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11.5px;
  color: var(--text-muted);
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #94a3b8;
}
.status-dot.online {
  background: var(--accent);
}
.status-dot.connecting {
  background: #f59e0b;
}
.status-dot.offline {
  background: var(--danger);
}

.topbar-center {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  justify-content: center;
  min-width: 240px;
}

.search-box {
  position: relative;
  display: flex;
  align-items: center;
  width: 220px;
}

.search-icon {
  position: absolute;
  left: 10px;
  color: var(--text-muted);
  pointer-events: none;
}

.search-box input {
  width: 100%;
  padding: 6px 26px 6px 30px;
  font-size: 13px;
  background: var(--bg-subtle);
  border-color: var(--border-color);
  border-radius: 18px;
}

.search-clear {
  position: absolute;
  right: 6px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  padding: 2px 4px;
}

.filter-tabs {
  display: inline-flex;
  background: var(--bg-subtle);
  border: 1px solid var(--border-color);
  border-radius: 18px;
  padding: 2px;
}

.filter-tab {
  border: none;
  background: transparent;
  padding: 4px 10px;
  font-size: 12px;
  color: var(--text-secondary);
  border-radius: 14px;
  cursor: pointer;
  font-family: inherit;
}

.filter-tab.active {
  background: #ffffff;
  color: var(--accent);
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

.user-pill {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-secondary);
  background: var(--bg-subtle);
  border: 1px solid var(--border-color);
  padding: 4px 10px;
  border-radius: 14px;
}

/* Timeline */
.timeline-container {
  flex: 1;
  overflow-y: auto;
  background: var(--bg-page);
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
}

.empty-state {
  margin: auto;
  text-align: center;
  color: var(--text-muted);
  max-width: 380px;
  padding: 24px;
}

.empty-icon {
  margin-bottom: 10px;
  color: #94a3b8;
}

.timeline-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.time-divider {
  display: flex;
  justify-content: center;
  margin: 8px 0 2px;
}

.time-divider span {
  font-size: 11.5px;
  color: var(--text-muted);
  background: rgba(226, 232, 240, 0.75);
  padding: 2px 10px;
  border-radius: 12px;
}

/* Chat Item Bubbles (WeChat File Transfer Assistant Style) */
.item-row {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 10px;
}

.item-row.selectable {
  cursor: pointer;
}

.item-checkbox {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
  cursor: pointer;
  flex-shrink: 0;
}

.item-row.selected .item-bubble {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(7, 166, 91, 0.2);
}

/* Batch Selection Action Bar */
.batch-bar {
  background: var(--accent-light);
  border-top: 1px solid var(--bg-bubble-border);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  flex-shrink: 0;
}

.batch-bar-left,
.batch-bar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.batch-count-text {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
}

.btn.select-active {
  background: var(--accent-light);
  color: var(--accent);
  border-color: var(--bg-bubble-border);
}

.item-bubble {
  max-width: 76%;
  min-width: 240px;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 12px 4px 12px 12px;
  padding: 12px 14px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.item-bubble.type-text {
  background: var(--bg-bubble);
  border-color: var(--bg-bubble-border);
}

.text-content {
  margin: 0;
  font-size: 14px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text-primary);
}

.text-content a {
  color: #0369a1;
  text-decoration: underline;
  word-break: break-all;
}

/* Image Bubble */
.image-preview-wrap {
  position: relative;
  border-radius: 8px;
  overflow: hidden;
  background: #f1f5f9;
  border: 1px solid var(--border-color);
  cursor: zoom-in;
  display: inline-block;
  max-width: 100%;
}

.image-preview-wrap img {
  display: block;
  max-width: 360px;
  max-height: 280px;
  width: auto;
  height: auto;
  object-fit: contain;
}

/* File Card */
.file-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 2px;
}

.file-badge {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background: #eff6ff;
  color: #2563eb;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.5px;
  flex-shrink: 0;
  border: 1px solid #dbeafe;
}

.file-badge.ext-pdf { background: #fef2f2; color: #dc2626; border-color: #fee2e2; }
.file-badge.ext-zip { background: #fffbeb; color: #d97706; border-color: #fef3c7; }
.file-badge.ext-doc { background: #eff6ff; color: #2563eb; border-color: #dbeafe; }
.file-badge.ext-xls { background: #ecfdf5; color: #059669; border-color: #d1fae5; }
.file-badge.ext-code { background: #f3e8ff; color: #7c3aed; border-color: #e9d5ff; }

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

.file-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
  word-break: break-all;
}

.file-meta {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Bubble Footer */
.bubble-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-top: 6px;
  border-top: 1px solid rgba(15, 23, 42, 0.06);
  font-size: 11.5px;
  color: var(--text-muted);
}

.bubble-ttl {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.bubble-actions {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.action-link {
  border: none;
  background: rgba(255, 255, 255, 0.7);
  color: var(--text-secondary);
  border-radius: 5px;
  padding: 3px 8px;
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border: 1px solid rgba(15, 23, 42, 0.08);
}

.action-link:hover {
  background: #ffffff;
  color: var(--accent);
  border-color: var(--accent);
}

.action-link.delete-btn:hover {
  color: var(--danger);
  border-color: #fca5a5;
  background: var(--danger-light);
}

/* Upload Progress Queue */
.upload-queue {
  background: var(--bg-subtle);
  border-top: 1px solid var(--border-color);
  padding: 8px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 160px;
  overflow-y: auto;
}

.upload-item {
  background: #ffffff;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.upload-item-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 12.5px;
}

.upload-filename {
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.upload-stats {
  color: var(--text-muted);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.upload-progress-track {
  height: 6px;
  background: #e2e8f0;
  border-radius: 4px;
  overflow: hidden;
}

.upload-progress-bar {
  height: 100%;
  background: var(--accent);
  width: 0%;
  transition: width 0.1s linear;
}

/* Composer */
.composer-bar {
  background: var(--bg-surface);
  border-top: 1px solid var(--border-color);
  padding: 10px 16px 14px;
  flex-shrink: 0;
}

.composer-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}

.composer-hint {
  font-size: 11.5px;
  color: var(--text-muted);
}

.composer-input-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

.composer-input-row textarea {
  flex: 1;
  resize: vertical;
  min-height: 54px;
  max-height: 180px;
  line-height: 1.5;
}

.send-btn {
  height: 54px;
  padding: 0 20px;
}

/* Drag & Drop Overlay */
.drop-overlay {
  position: absolute;
  inset: 0;
  background: rgba(7, 166, 91, 0.08);
  backdrop-filter: blur(2px);
  border: 3px dashed var(--accent);
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.drop-overlay-box {
  background: #ffffff;
  border-radius: var(--radius-lg);
  padding: 28px 36px;
  text-align: center;
  box-shadow: var(--shadow-lg);
  color: var(--accent);
}

.drop-overlay-box p {
  margin: 10px 0 4px;
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
}

.drop-overlay-box span {
  font-size: 12.5px;
  color: var(--text-muted);
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 100;
}

.modal-card {
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  max-height: 90vh;
}

.modal-sm { max-width: 420px; }
.modal-lg { max-width: 760px; }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-color);
}

.modal-header h3 {
  margin: 0;
  font-size: 15.5px;
  font-weight: 600;
}

.modal-close {
  border: none;
  background: transparent;
  font-size: 20px;
  line-height: 1;
  color: var(--text-muted);
  cursor: pointer;
}

.modal-card .form-stack,
.modal-body {
  padding: 16px 18px;
  overflow-y: auto;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 18px;
  border-top: 1px solid var(--border-color);
  background: var(--bg-subtle);
}

.modal-desc, .confirm-text {
  margin: 0;
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--text-secondary);
}

/* Admin Panel */
.admin-create-row {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.admin-create-row input[type="text"],
.admin-create-row input[type="password"] {
  flex: 1;
  min-width: 150px;
  padding: 7px 10px;
  font-size: 13px;
}

.table-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 14px 0 8px;
}

.table-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
}

.table-wrap {
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table th,
.data-table td {
  padding: 9px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border-color);
}

.data-table th {
  background: var(--bg-subtle);
  font-weight: 600;
  color: var(--text-secondary);
}

.data-table tr:last-child td {
  border-bottom: none;
}

.role-badge {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 10px;
  font-size: 11.5px;
  font-weight: 500;
  background: var(--bg-subtle);
  color: var(--text-secondary);
}
.role-badge.admin {
  background: var(--accent-light);
  color: var(--accent);
}

/* Lightbox */
.lightbox-content {
  width: 100%;
  max-width: 96vw;
  max-height: 94vh;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.lightbox-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(15, 23, 42, 0.85);
  color: #ffffff;
  padding: 8px 14px;
  border-radius: 8px;
}

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

.lightbox-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.lightbox-close-btn {
  color: #e2e8f0;
}
.lightbox-close-btn:hover {
  background: rgba(255, 255, 255, 0.15);
  color: #ffffff;
}

.lightbox-img-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
}

.lightbox-img-wrap img {
  max-width: 100%;
  max-height: 82vh;
  border-radius: 6px;
  box-shadow: var(--shadow-lg);
}

/* Toasts */
.toast-container {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 200;
  pointer-events: none;
}

.toast {
  background: #1e293b;
  color: #ffffff;
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 13px;
  box-shadow: var(--shadow-md);
  opacity: 0;
  transform: translateY(-6px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

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

.toast.toast-success {
  background: var(--accent);
}

/* Responsive Mobile Adjustments */
@media (max-width: 768px) {
  .topbar {
    padding: 8px 10px;
    gap: 8px;
  }
  .topbar-center {
    order: 3;
    width: 100%;
    justify-content: space-between;
  }
  .search-box {
    flex: 1;
    width: auto;
  }
  .hide-mobile {
    display: none;
  }
  .timeline-container {
    padding: 12px;
  }
  .item-bubble {
    max-width: 92%;
  }
  .image-preview-wrap img {
    max-width: 100%;
  }
  .composer-hint {
    display: none;
  }
}
