:root {
  --sidebar-width: 232px;
  --bg: #f4f6fa;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --border: #e5e7eb;
  --brand: #3b6ef6;
  --brand-dark: #2a52c8;
  --sidebar-bg: #111827;
  --sidebar-text: #d1d5db;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  flex-shrink: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.brand-logo {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--brand), #7c3aed);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
}

.brand-text { font-weight: 600; color: #fff; font-size: 15px; }

.sidebar .nav { display: block; flex: 1; overflow-y: auto; padding: 12px 10px; }

.nav-section {
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #6b7280;
  padding: 14px 12px 6px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 38px;
  padding: 0 12px;
  border-radius: 8px;
  color: var(--sidebar-text);
  text-decoration: none;
  margin-bottom: 4px;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
}

.nav-link:hover { background: rgba(255, 255, 255, 0.07); color: #fff; }
.nav-link.active { background: var(--brand); color: #fff; }
.nav-icon {
  width: 20px;
  flex: 0 0 20px;
  text-align: center;
  font-size: 15px;
  line-height: 1;
}

.sidebar-footer { padding: 14px 20px; border-top: 1px solid rgba(255, 255, 255, 0.08); }
.sidebar-footer .text-muted { color: #9ca3af !important; }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.topbar {
  height: 58px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 22px;
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-title { font-weight: 600; font-size: 15px; flex: 1; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.bell-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: #dc3545;
  color: #fff;
  border-radius: 999px;
  font-size: 10px;
  line-height: 1;
  padding: 2px 5px;
  font-weight: 600;
}

.user-chip {
  background: #eef2ff;
  color: var(--brand-dark);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 13px;
  font-weight: 500;
}

.btn-ghost { border: 1px solid var(--border); background: transparent; color: var(--muted); }
.btn-ghost:hover { background: #f3f4f6; color: var(--text); }

.content { padding: 22px; flex: 1; }

/* 预览页：内容区纵向排列，文档查看器填满剩余高度 */
.content.viewer-page,
.anonymous-main.viewer-page { display: flex; flex-direction: column; }
.anonymous-main.viewer-page { height: calc(100vh - 48px); }
.viewer-page > .viewer-fill { flex: 1 1 auto; min-height: 0; }
.viewer-fill { display: flex; flex-direction: column; }
.viewer-fill > .card { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; margin-bottom: 0; }
.viewer-fill > .card > .card-body { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; overflow: auto; }
.viewer-fill .office-fullscreen-wrapper { flex: 1 1 auto; min-height: 0; height: auto; }
.viewer-fill .card-body pre { flex: 1 1 auto; min-height: 0; overflow: auto; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-bottom: 18px;
}

.card-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px 12px;
}

.card-header h5 { margin: 0; font-size: 15px; font-weight: 600; flex: 0 0 auto; }
.card-header .actions { flex-wrap: wrap; align-items: center; }
.card-header form { flex-wrap: wrap; row-gap: 8px; }
.card-header form .form-control {
  width: 200px;
  flex: 0 0 auto;
  min-width: 0;
}
.card-header form .form-select {
  width: auto;
  min-width: 120px;
  flex: 0 0 auto;
}
.card-body { padding: 18px; overflow-x: auto; }
.card-body.flush { padding: 0; }

.table { width: 100%; border-collapse: collapse; margin-bottom: 0; }
.table th, .table td { padding: 10px 12px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
.table th { background: #f9fafb; font-weight: 600; font-size: 13px; color: var(--muted); white-space: nowrap; }
.table tbody tr:hover { background: #f9fafb; }

.btn { border-radius: 8px; font-size: 13px; padding: 7px 14px; white-space: nowrap; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-primary { background: var(--brand); border-color: var(--brand); }
.btn-primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); }

.form-label { font-weight: 500; font-size: 13px; margin-bottom: 4px; }
.form-control, .form-select { border-radius: 8px; font-size: 13px; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 18px;
}

.stat-card .stat-label { color: var(--muted); font-size: 12px; margin-bottom: 6px; }
.stat-card .stat-value { font-size: 22px; font-weight: 700; }
.stat-card .stat-sub { color: var(--muted); font-size: 12px; margin-top: 4px; }

.bar-chart {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  height: 160px;
  padding-top: 10px;
  margin-bottom: 38px;
  position: relative;
}
.bar-chart::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -32px;
  height: 1px;
  background: var(--border);
}
.bar-chart .bar {
  flex: 1;
  background: linear-gradient(180deg, var(--brand), #8aa8ff);
  border-radius: 4px 4px 0 0;
  min-height: 2px;
  position: relative;
}
.bar-chart .bar:hover { opacity: 0.85; }
.bar-chart .bar-label {
  position: absolute;
  bottom: -18px;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 10px;
  color: var(--muted);
}

.progress { height: 8px; border-radius: 999px; background: #eef0f4; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--brand); }

.badge { border-radius: 999px; padding: 3px 9px; font-size: 12px; font-weight: 500; }
.color-swatch {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 3px;
  margin-right: 6px;
  vertical-align: -1px;
  border: 1px solid rgba(0, 0, 0, 0.12);
}

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 18px; overflow-x: auto; }
.tabs a {
  padding: 9px 16px;
  color: var(--muted);
  text-decoration: none;
  border-bottom: 2px solid transparent;
  font-size: 13px;
}
.tabs a.active { color: var(--brand); border-bottom-color: var(--brand); font-weight: 600; }

.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1e293b 0%, #3b6ef6 100%);
  padding: 20px;
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: #fff;
  border-radius: 16px;
  padding: 32px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
}

.login-brand { text-align: center; margin-bottom: 22px; }
.login-brand h4 { margin: 12px 0 4px; }

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 18px; align-items: start; }

.text-muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: Consolas, "Courier New", monospace; }
.nowrap { white-space: nowrap; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }

.bulk-bar {
  display: none;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  margin: 10px 12px 12px;
  background: #f0f6ff;
  border: 1px solid #cfe2ff;
  border-radius: 8px;
}
.bulk-bar.show { display: flex; }
.bulk-bar .bulk-count { font-size: 13px; color: #0d6efd; font-weight: 600; }
.bulk-bar .bulk-actions { display: flex; gap: 6px; flex-wrap: wrap; }

.table .bulk-check { width: 36px; text-align: center; }

.preview-table { max-height: 520px; overflow: auto; }

.project-options {
  max-height: 168px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 8px;
}
.project-option {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 2px;
  font-size: 13px;
  cursor: pointer;
}
.project-option:hover { background: #f9fafb; }

.mapping-picker {
  max-height: 200px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
}
.mapping-option {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 2px;
  margin: 0;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}
.mapping-option:last-child { border-bottom: none; }
.mapping-option:hover { background: #f9fafb; }
.mapping-option input[type="checkbox"] { margin: 0; flex-shrink: 0; }
.mapping-main { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.mapping-name { font-size: 13px; }

.report-var-row { display: flex; gap: 8px; margin-bottom: 8px; align-items: center; }
.report-var-row input[name^="var_key"] { flex: 1; min-width: 120px; }
.report-var-row .var-source { width: 150px; flex-shrink: 0; }
.report-var-row .var-value { flex: 1; min-width: 120px; }

.toast-container { pointer-events: none; }
.toast-container .toast { pointer-events: auto; }

#sidebar-backdrop { display: none; }

@media (max-width: 991.98px) {
  .sidebar { position: fixed; z-index: 30; transform: translateX(-100%); transition: transform 0.2s; }
  .sidebar.open { transform: translateX(0); }
  #sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(17, 24, 39, 0.5);
    z-index: 25;
  }
}

@media (max-width: 575.98px) {
  .bar-chart { gap: 2px; }
  .bar-chart .bar-label { font-size: 8px; }
  .card-body.flush > .table { min-width: 720px; }
  .card-body.flush > .table td { white-space: nowrap; }
}

.anonymous-body { background: #f3f4f6; min-height: 100vh; }
.anonymous-main { max-width: 960px; margin: 0 auto; padding: 24px 16px; }

.drop-zone {
  border: 2px dashed var(--border);
  border-radius: 10px;
  padding: 18px 16px;
  text-align: center;
  margin-bottom: 12px;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.drop-zone.dragover { border-color: var(--brand); background: rgba(59, 110, 246, 0.06); }
.drop-zone-main { display: flex; flex-direction: column; gap: 4px; align-items: center; }
.drop-zone-icon { font-size: 22px; line-height: 1; color: var(--brand); }
.drop-zone-progress { margin-top: 10px; }
.drop-zone-progress .progress { max-width: 420px; margin: 0 auto 6px; }
.drop-overlay {
  position: fixed;
  inset: 0;
  background: rgba(244, 246, 250, 0.9);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1080;
}
.drop-overlay.show { display: flex; }
.drop-overlay-box {
  border: 2px dashed var(--brand);
  border-radius: 12px;
  background: var(--card);
  padding: 40px 60px;
  font-size: 18px;
  color: var(--brand);
  pointer-events: none;
}
