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

:root {
  --primary: #4f46e5;
  --primary-light: #e0e7ff;
  --bg: #f8fafc;
  --sidebar-bg: #1e293b;
  --sidebar-text: #94a3b8;
  --sidebar-active: #ffffff;
  --card-bg: #ffffff;
  --text: #1e293b;
  --text-secondary: #64748b;
  --border: #e2e8f0;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --info: #3b82f6;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* Sidebar */
.sidebar {
  width: 220px;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.logo {
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}

.logo-icon {
  font-size: 24px;
}

.logo-text {
  font-size: 20px;
  font-weight: 700;
  color: white;
  letter-spacing: 1px;
}

.nav-menu {
  list-style: none;
  padding: 12px 0;
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 20px;
  color: var(--sidebar-text);
  cursor: pointer;
  transition: all 0.2s;
  font-size: 14px;
}

.nav-item:hover {
  background: rgba(255,255,255,0.05);
  color: var(--sidebar-active);
}

.nav-item.active {
  background: rgba(79, 70, 229, 0.2);
  color: var(--sidebar-active);
  border-right: 3px solid var(--primary);
}

.nav-icon {
  font-size: 18px;
  width: 24px;
  text-align: center;
}

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid rgba(255,255,255,0.1);
}

.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 600;
  flex-shrink: 0;
}

.avatar.small {
  width: 28px;
  height: 28px;
  font-size: 12px;
}

.user-name {
  color: white;
  font-size: 13px;
  font-weight: 500;
}

.user-role {
  color: var(--sidebar-text);
  font-size: 11px;
}

/* Content */
.content {
  flex: 1;
  overflow-y: auto;
  padding: 24px 32px;
}

.page {
  display: none;
}

.page.active {
  display: block;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}

.page-header h1 {
  font-size: 22px;
  font-weight: 600;
}

.date-display {
  color: var(--text-secondary);
  font-size: 14px;
}

/* Stats Grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--card-bg);
  border-radius: 12px;
  padding: 20px;
  border: 1px solid var(--border);
}

.stat-number {
  font-size: 32px;
  font-weight: 700;
  color: var(--primary);
}

.stat-label {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 4px;
}

.stat-trend {
  font-size: 12px;
  margin-top: 8px;
}

.stat-trend.up {
  color: var(--success);
}

.stat-trend.neutral {
  color: var(--text-secondary);
}

/* Cards */
.card {
  background: var(--card-bg);
  border-radius: 12px;
  border: 1px solid var(--border);
  padding: 20px;
  margin-bottom: 20px;
}

.card-header {
  margin-bottom: 16px;
}

.card-header h3 {
  font-size: 15px;
  font-weight: 600;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: 1.5fr 1fr;
  gap: 20px;
  margin-bottom: 20px;
}

.dashboard-grid .card {
  margin-bottom: 0;
}

/* Case Progress */
.case-progress-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.case-progress-item:last-child {
  border-bottom: none;
}

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

.case-name {
  font-size: 13px;
  font-weight: 500;
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.case-lawyer {
  font-size: 11px;
  color: var(--text-secondary);
}

.progress-bar-wrap {
  width: 120px;
  height: 6px;
  background: #f1f5f9;
  border-radius: 3px;
  overflow: hidden;
  flex-shrink: 0;
}

.progress-bar {
  height: 100%;
  background: var(--primary);
  border-radius: 3px;
  transition: width 0.3s;
}

/* Stage Badges */
.stage-badge {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 4px;
  white-space: nowrap;
  font-weight: 500;
}

.stage-intake { background: #dbeafe; color: #1d4ed8; }
.stage-investigation { background: #fef3c7; color: #92400e; }
.stage-research { background: #e0e7ff; color: #4338ca; }
.stage-strategy { background: #fce7f3; color: #9d174d; }
.stage-drafting { background: #ddd6fe; color: #6d28d9; }
.stage-review { background: #ccfbf1; color: #0f766e; }
.stage-trial { background: #fee2e2; color: #991b1b; }
.stage-closed { background: #d1fae5; color: #065f46; }

/* Team Output */
.team-member {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.team-member:last-child {
  border-bottom: none;
}

.member-info {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 500;
}

.member-stats {
  display: flex;
  gap: 6px;
}

.tag {
  font-size: 11px;
  padding: 2px 8px;
  background: var(--primary-light);
  color: var(--primary);
  border-radius: 4px;
}

/* AI Activity */
.ai-activity-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.ai-activity {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}

.ai-activity:last-child {
  border-bottom: none;
}

.activity-time {
  color: var(--text-secondary);
  font-size: 12px;
  min-width: 70px;
  flex-shrink: 0;
}

.activity-badge {
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 3px;
  font-weight: 600;
  flex-shrink: 0;
}

.activity-badge.auto {
  background: #dbeafe;
  color: #1d4ed8;
}

.activity-badge.query {
  background: #fce7f3;
  color: #9d174d;
}

/* Pipeline */
.pipeline-header-info {
  margin-bottom: 24px;
}

.pipeline-meta {
  display: flex;
  gap: 20px;
  font-size: 13px;
  color: var(--text-secondary);
  flex-wrap: wrap;
}

.case-type-tag {
  background: var(--primary-light);
  color: var(--primary);
  padding: 2px 10px;
  border-radius: 4px;
  font-weight: 500;
}

.pipeline-container {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.pipeline-stage {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}

.pipeline-stage.completed {
  border-left: 4px solid var(--success);
}

.pipeline-stage.active {
  border-left: 4px solid var(--primary);
  box-shadow: 0 2px 12px rgba(79, 70, 229, 0.1);
}

.pipeline-stage.upcoming {
  opacity: 0.5;
}

.stage-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 20px;
  cursor: pointer;
}

.stage-status-icon {
  font-size: 16px;
  width: 24px;
  text-align: center;
  flex-shrink: 0;
}

.pipeline-stage.completed .stage-status-icon {
  color: var(--success);
}

.stage-status-icon.pulse {
  color: var(--primary);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.stage-header h3 {
  font-size: 15px;
  font-weight: 600;
  flex: 1;
}

.stage-date {
  font-size: 12px;
  color: var(--text-secondary);
}

.stage-body {
  padding: 0 20px 16px 54px;
}

.stage-outputs {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.output-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.output-icon {
  font-size: 14px;
  width: 20px;
  text-align: center;
}

.output-status {
  margin-left: auto;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 4px;
  font-weight: 500;
}

.output-status.done {
  background: #d1fae5;
  color: #065f46;
}

.output-status.progress {
  background: #dbeafe;
  color: #1d4ed8;
}

.output-status.pending {
  background: #f1f5f9;
  color: #64748b;
}

.output-status.warning {
  background: #fef3c7;
  color: #92400e;
}

.stage-ai-hint {
  margin-top: 12px;
  padding: 10px 14px;
  background: #f0f0ff;
  border-radius: 8px;
  font-size: 13px;
  color: var(--primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.pipeline-connector {
  width: 2px;
  height: 20px;
  background: var(--border);
  margin-left: 32px;
}

.pipeline-connector.completed {
  background: var(--success);
}

.pipeline-connector.active {
  background: var(--primary);
}

/* Query / Chat */
.query-container {
  display: flex;
  gap: 20px;
  height: calc(100vh - 120px);
}

.query-sidebar {
  width: 260px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.query-sidebar h4 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 12px;
}

.material-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.material-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 8px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.2s;
}

.material-item:hover {
  background: var(--bg);
}

.material-icon {
  font-size: 18px;
  flex-shrink: 0;
  margin-top: 2px;
}

.material-name {
  font-size: 13px;
  font-weight: 500;
}

.material-meta {
  font-size: 11px;
  color: var(--text-secondary);
}

.material-summary {
  padding-top: 12px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-secondary);
  text-align: center;
  margin-top: 12px;
}

.chat-area {
  flex: 1;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

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

.message {
  display: flex;
  max-width: 80%;
}

.message.system {
  max-width: 100%;
  justify-content: center;
}

.message.system .message-content {
  background: #f0f0ff;
  color: var(--primary);
  font-size: 12px;
  text-align: center;
  border-radius: 8px;
}

.message.user {
  align-self: flex-end;
}

.message.user .message-content {
  background: var(--primary);
  color: white;
  border-radius: 12px 12px 4px 12px;
}

.message.ai .message-content {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px 12px 12px 4px;
}

.message-content {
  padding: 12px 16px;
  font-size: 13px;
  line-height: 1.6;
}

.message-content p {
  margin-bottom: 8px;
}

.message-content p:last-child {
  margin-bottom: 0;
}

.source-ref {
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.chat-input-area {
  padding: 12px 20px 16px;
  border-top: 1px solid var(--border);
}

.quick-questions {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.quick-q {
  font-size: 12px;
  padding: 4px 12px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: white;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s;
}

.quick-q:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-light);
}

.chat-input-wrap {
  display: flex;
  gap: 8px;
}

.chat-input {
  flex: 1;
  padding: 10px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
}

.chat-input:focus {
  border-color: var(--primary);
}

.send-btn {
  padding: 10px 20px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.2s;
}

.send-btn:hover {
  background: #4338ca;
}

/* Cases Table */
.cases-table-wrap {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}

.cases-table {
  width: 100%;
  border-collapse: collapse;
}

.cases-table th {
  text-align: left;
  padding: 12px 16px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.cases-table td {
  padding: 14px 16px;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
}

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

.cases-table tr:hover {
  background: #fafbfc;
}

.case-name-cell {
  font-weight: 500;
  color: var(--primary);
  cursor: pointer;
}

.type-tag {
  font-size: 11px;
  padding: 2px 8px;
  background: #f1f5f9;
  border-radius: 4px;
  color: var(--text-secondary);
}

.row-closed {
  opacity: 0.6;
}

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

.completeness-bar {
  height: 6px;
  background: var(--primary);
  border-radius: 3px;
  flex: 1;
  max-width: 80px;
}

.completeness-bar.full {
  background: var(--success);
}

.completeness span {
  font-size: 12px;
  color: var(--text-secondary);
  min-width: 32px;
}

/* Select */
.case-select {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  outline: none;
  background: white;
  cursor: pointer;
}

.btn-primary {
  padding: 8px 16px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  font-weight: 500;
}

.btn-primary:hover {
  background: #4338ca;
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}
