/* ========== CSS Variables ========== */
:root {
  --sidebar-width: 220px;
  --sidebar-collapsed-width: 60px;
  --header-height: 56px;
  --primary: #1a73e8;
  --primary-hover: #1557b0;
  --primary-light: #e8f0fe;
  --success: #34a853;
  --warning: #fbbc04;
  --danger: #ea4335;
  --bg-body: #f5f7fa;
  --bg-card: #ffffff;
  --bg-sidebar: #1e293b;
  --text-primary: #1f2937;
  --text-secondary: #6b7280;
  --border-color: #e5e7eb;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
  --transition: all 0.3s ease;
}

/* ========== Reset & Base ========== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
  background: var(--bg-body);
  color: var(--text-primary);
  overflow: hidden;
  height: 100vh;
}

/* ========== Layout ========== */
.app-wrapper {
  display: flex;
  height: 100vh;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--bg-sidebar);
  position: fixed;
  left: 0;
  top: 0;
  z-index: 1000;
  transition: var(--transition);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-brand {
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  padding: 0 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  white-space: nowrap;
}

.sidebar-brand i {
  font-size: 24px;
  margin-right: 10px;
  color: var(--primary);
}

.sidebar-nav {
  flex: 1;
  padding: 12px 8px;
  overflow-y: auto;
}

.sidebar-nav .nav-item {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  color: rgba(255, 255, 255, 0.7);
  text-decoration: none;
  border-radius: 8px;
  margin-bottom: 4px;
  cursor: pointer;
  transition: var(--transition);
  font-size: 14px;
  white-space: nowrap;
}

.sidebar-nav .nav-item:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.sidebar-nav .nav-item.active {
  background: var(--primary);
  color: #fff;
}

.sidebar-nav .nav-item i {
  font-size: 18px;
  width: 24px;
  text-align: center;
  margin-right: 12px;
}

/* Main Content */
.main-content {
  margin-left: var(--sidebar-width);
  flex: 1;
  display: flex;
  flex-direction: column;
  transition: var(--transition);
}

/* Header */
.app-header {
  height: var(--header-height);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-left .breadcrumb {
  font-size: 14px;
  color: var(--text-secondary);
}

.header-left .breadcrumb .current {
  color: var(--text-primary);
  font-weight: 600;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.source-summary-text {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  background: #f8fafc;
  color: var(--text-primary);
  font-size: 12px;
  white-space: nowrap;
}

.btn-toggle-sidebar {
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  color: var(--text-secondary);
  padding: 4px;
}

.btn-toggle-sidebar:hover {
  color: var(--text-primary);
}

/* Page Content */
.page-content {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}

.page-section {
  display: none;
}

.page-section.active {
  display: block;
}

/* ========== Cards & Panels ========== */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 20px;
}

.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-header h5 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}

.card-body {
  padding: 20px;
}

/* Stat Cards */
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 20px;
  box-shadow: var(--shadow-sm);
}

.stat-card .stat-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--text-primary);
}

.stat-card .stat-label {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.stat-card .stat-change {
  font-size: 12px;
  margin-top: 8px;
}

.stat-card .stat-change.positive {
  color: var(--success);
}

.stat-card .stat-change.negative {
  color: var(--danger);
}

/* ========== Model Cards ========== */
.model-card {
  background: var(--bg-card);
  border: 2px solid var(--border-color);
  border-radius: 12px;
  padding: 20px;
  cursor: pointer;
  transition: var(--transition);
  text-align: center;
}

.model-card:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow-md);
}

.model-card.selected {
  border-color: var(--primary);
  background: var(--primary-light);
}

.model-card .model-icon {
  font-size: 36px;
  color: var(--primary);
  margin-bottom: 12px;
}

.model-card .model-name {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 4px;
}

.model-card .model-category {
  font-size: 12px;
  color: var(--text-secondary);
}

/* ========== Event Cards ========== */
.event-card {
  background: var(--bg-card);
  border: 2px solid var(--border-color);
  border-radius: 12px;
  padding: 24px;
  cursor: pointer;
  transition: var(--transition);
  text-align: center;
}

.event-card:hover {
  border-color: var(--primary);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.event-card.selected {
  border-color: var(--primary);
  background: var(--primary-light);
}

.event-card .event-icon {
  font-size: 40px;
  margin-bottom: 12px;
}

.event-card .event-name {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 4px;
}

.event-card .event-desc {
  font-size: 12px;
  color: var(--text-secondary);
}

.event-single-layout {
  display: block;
}

.event-preset-buttons {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.event-preset-btn {
  width: 100%;
  appearance: none;
  -webkit-appearance: none;
  background: #ffffff;
}

.event-preset-btn.active,
.event-preset-btn.selected {
  border-color: var(--primary);
  background: var(--primary-light);
  box-shadow: var(--shadow-md);
}

.event-preset-summary {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  background: #f8fafc;
  color: #334155;
  font-size: 13px;
  line-height: 1.6;
}

.event-bottom-grid {
  display: grid;
  grid-template-columns: minmax(320px, 36%) minmax(0, 64%);
  gap: 16px;
  align-items: start;
}

.event-result-panel {
  min-width: 0;
}

.event-result-empty {
  min-height: 210px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.event-meta-line {
  color: #334155;
  font-size: 13px;
  margin-bottom: 10px;
}

.event-interpretation {
  color: #111111;
  font-size: 14px;
  line-height: 1.7;
}

@media (max-width: 1200px) {
  .event-bottom-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 992px) {
  .event-preset-buttons {
    grid-template-columns: 1fr;
  }
}

/* ========== Chart Containers ========== */
.chart-container {
  width: 100%;
  min-height: 400px;
  position: relative;
}

.chart-container-sm {
  min-height: 300px;
}

/* ========== Data Table ========== */
.table-scroll-container {
  overflow-x: auto;
  overflow-y: auto;
  max-height: 450px;
  width: 100%;
  margin: 0;
  padding: 0;
  border-bottom: 1px solid var(--border-color);
}

#data-table-wrapper {
  position: relative;
  width: 100%;
  max-width: calc(100vw - var(--sidebar-width) - 96px);
  overflow-x: auto;
  overflow-y: auto;
  scrollbar-gutter: stable both-edges;
}

#data-table {
  width: max-content;
  min-width: 100%;
  border-collapse: separate;
  border-spacing: 0;
}

#data-table .query-action-col {
  position: sticky;
  right: 0;
  z-index: 6;
  min-width: 110px;
  background: #ffffff;
  box-shadow: -8px 0 10px -10px rgba(15, 23, 42, 0.5);
}

#data-table thead .query-action-col {
  z-index: 7;
  background: #f8fafc;
}

@media (max-width: 768px) {
  #data-table-wrapper {
    max-width: calc(100vw - 32px);
  }
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  table-layout: auto;
}

.data-table thead th {
  background: #f8fafc;
  padding: 10px 12px;
  text-align: left;
  font-weight: 600;
  color: var(--text-secondary);
  border-bottom: 2px solid var(--border-color);
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 1;
}

.data-table tbody td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
}

.data-table tbody tr:hover {
  background: #f8fafc;
}

.data-table tbody tr:nth-child(even) {
  background: #fafafa;
}

/* ========== Status Badge ========== */
.status-badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
}

.status-badge.pending {
  background: #f3f4f6;
  color: #6b7280;
}

.status-badge.running {
  background: #dbeafe;
  color: #1d4ed8;
}

.status-badge.completed {
  background: #dcfce7;
  color: #16a34a;
}

.status-badge.failed {
  background: #fee2e2;
  color: #dc2626;
}

/* ========== File Upload ========== */
.upload-zone {
  border: 2px dashed var(--border-color);
  border-radius: 12px;
  padding: 40px 20px;
  text-align: center;
  cursor: pointer;
  transition: var(--transition);
}

.upload-zone:hover,
.upload-zone.dragover {
  border-color: var(--primary);
  background: var(--primary-light);
}

.upload-zone i {
  font-size: 48px;
  color: var(--primary);
  margin-bottom: 12px;
}

.upload-zone p {
  color: var(--text-secondary);
  font-size: 14px;
}

/* ========== Upload History ========== */
.upload-history-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.upload-history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  background: #fafafa;
}

.upload-history-main {
  min-width: 0;
  flex: 1;
}

.upload-history-name {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.upload-history-meta {
  margin-top: 2px;
  font-size: 12px;
  color: var(--text-secondary);
}

.upload-delete-btn {
  flex-shrink: 0;
  border: 1px solid #fda4af;
  color: #be123c;
  background: #fff1f2;
  border-radius: 8px;
  font-size: 13px;
  line-height: 1;
  padding: 8px 12px;
  cursor: pointer;
  transition: var(--transition);
}

.upload-delete-btn:hover {
  background: #ffe4e6;
  border-color: #fb7185;
}

.upload-delete-btn:active {
  transform: translateY(1px);
}

.upload-history-empty {
  text-align: center;
  color: var(--text-secondary);
  padding: 14px 8px;
}

/* ========== Progress ========== */
.training-progress {
  margin: 16px 0;
}

.training-progress .progress {
  height: 20px;
  border-radius: 10px;
}

.training-progress .progress-bar {
  transition: width 0.5s ease;
}

.progress-stats {
  display: flex;
  justify-content: space-between;
  margin-top: 8px;
  font-size: 12px;
  color: var(--text-secondary);
}

/* ========== Filter Bar ========== */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
  margin-bottom: 16px;
}

.filter-bar .form-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.filter-bar .form-group label {
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 500;
}

/* ========== Tabs ========== */
.module-tabs .nav-tabs {
  border-bottom: 2px solid var(--border-color);
}

.module-tabs .nav-tabs .nav-link {
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 500;
  padding: 10px 20px;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
}

.module-tabs .nav-tabs .nav-link:hover {
  color: var(--primary);
}

.module-tabs .nav-tabs .nav-link.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

/* ========== Empty State ========== */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-secondary);
}

.empty-state i {
  font-size: 48px;
  margin-bottom: 16px;
  opacity: 0.5;
}

.empty-state p {
  font-size: 14px;
}

/* ========== Loading ========== */
.loading-overlay {
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  border-radius: 12px;
}

/* ========== Pagination ========== */
.pagination-wrapper {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 16px;
  font-size: 13px;
  color: var(--text-secondary);
  width: 100%;
  box-sizing: border-box;
}

/* ========== Export Status Tip ========== */
.export-status-tip {
  display: inline-block;
  margin-left: 12px;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 12px;
  color: var(--text-secondary);
  background: #f3f4f6;
}

.export-status-tip.loading {
  color: var(--primary);
  background: var(--primary-light);
}

.export-status-tip.success {
  color: var(--success);
  background: #dcfce7;
}

.export-status-tip.error {
  color: var(--danger);
  background: #fee2e2;
}

/* ========== Button Styles ========== */
.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
}

.btn-primary:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
}

.btn-outline-primary {
  color: var(--primary);
  border-color: var(--primary);
}

.btn-outline-primary:hover {
  background: var(--primary);
  border-color: var(--primary);
}

/* ========== Animations ========== */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.page-section.active {
  animation: fadeIn 0.3s ease;
}

/* ========== Toast ========== */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 9999;
}

/* ========== Responsive ========== */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.show {
    transform: translateX(0);
  }
  .main-content {
    margin-left: 0;
  }
  .filter-bar {
    flex-direction: column;
  }
}

/* ========== Editable Table Cells ========== */
.editable-cell {
  cursor: pointer;
  transition: background-color 0.2s;
}

.editable-cell:hover {
  background-color: #f3f4f6;
}

.editable-cell[contenteditable="true"] {
  background-color: #fff3cd;
  border: 1px solid #ffc107;
  border-radius: 4px;
  outline: none;
  padding: 4px 8px;
}

.editable-cell.cell-editing {
  background-color: #fff3cd;
  box-shadow: inset 0 0 0 2px #ffc107;
}

.editable-cell.cell-pending-edit {
  background-color: #dbeafe;
}

.data-table tbody tr.row-pending-edit {
  background-color: #dbeafe !important;
}

.data-table tbody tr.row-pending-edit:hover {
  background-color: #bfdbfe !important;
}

.data-table tbody tr.row-pending-delete {
  background-color: #fee2e2 !important;
}

.data-table tbody tr.row-pending-delete:hover {
  background-color: #fecaca !important;
}

.data-table tbody tr.table-warning {
  background-color: #fffbeb !important;
}

.data-table tbody tr.table-warning:hover {
  background-color: #fef3c7 !important;
}

.data-table tbody tr.table-danger {
  background-color: #fef2f2 !important;
}

.data-table tbody tr.table-danger:hover {
  background-color: #fee2e2 !important;
}

/* ========== Scrollbar ========== */
.page-content::-webkit-scrollbar {
  width: 6px;
}

.page-content::-webkit-scrollbar-track {
  background: transparent;
}

.page-content::-webkit-scrollbar-thumb {
  background: #d1d5db;
  border-radius: 3px;
}

.page-content::-webkit-scrollbar-thumb:hover {
  background: #9ca3af;
}
