/* ===== Reset & Base ===== */
* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: -apple-system, 'PingFang SC', 'Microsoft YaHei', sans-serif; background: #f0f2f5; color: #333; height: 100vh; overflow: hidden; }
input { font-family: inherit; }
button { cursor: pointer; font-family: inherit; }
.hidden { display: none !important; }

/* ===== Login Page ===== */
.login-page {
  display: flex; align-items: center; justify-content: center;
  height: 100vh; background: linear-gradient(135deg, #0f0c29, #302b63, #24243e);
}
.login-card {
  background: #fff; border-radius: 16px; padding: 48px 40px 40px;
  width: 380px; box-shadow: 0 20px 60px rgba(0,0,0,0.3); text-align: center;
}
.login-logo { font-size: 56px; margin-bottom: 12px; }
.login-card h1 { font-size: 22px; color: #1a1a2e; margin-bottom: 4px; }
.login-subtitle { color: #888; font-size: 13px; margin-bottom: 32px; }
.login-form input {
  display: block; width: 100%; padding: 12px 16px; margin-bottom: 12px;
  border: 1px solid #e0e0e0; border-radius: 8px; font-size: 15px; outline: none;
  transition: border-color 0.2s;
}
.login-form input:focus { border-color: #667eea; }
.login-error { color: #e74c3c; font-size: 13px; margin-bottom: 8px; text-align: left; }

/* ===== Buttons ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 20px; border-radius: 8px; font-size: 14px; font-weight: 500;
  border: 1px solid transparent; transition: all 0.2s; white-space: nowrap;
}
.btn-primary { background: #667eea; color: #fff; border-color: #667eea; }
.btn-primary:hover { background: #5a6fd6; }
.btn-outline { background: transparent; color: #667eea; border-color: #667eea; }
.btn-outline:hover { background: #f0f2ff; }
.btn-danger { background: #e74c3c; color: #fff; border-color: #e74c3c; }
.btn-danger:hover { background: #c0392b; }
.btn-full { width: 100%; }
.btn-lg { padding: 14px 32px; font-size: 16px; }

/* ===== App Layout ===== */
.app-layout { display: flex; height: 100vh; }

/* ===== Sidebar ===== */
.sidebar {
  width: 280px; min-width: 280px; background: #1a1a2e; color: #ccc;
  display: flex; flex-direction: column; overflow: hidden;
}
.sidebar-header {
  padding: 20px 16px; display: flex; align-items: center; gap: 10px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.sidebar-logo { font-size: 24px; }
.sidebar-title { font-size: 16px; font-weight: 600; color: #fff; }
.import-btn {
  display: flex; align-items: center; gap: 8px; width: calc(100% - 16px);
  margin: 12px 8px; padding: 12px 16px; background: rgba(255,255,255,0.06);
  border: 1px dashed rgba(255,255,255,0.2); border-radius: 8px;
  color: #ccc; font-size: 14px; transition: all 0.2s;
}
.import-btn:hover { background: rgba(255,255,255,0.12); border-color: #667eea; color: #fff; }
.import-icon { font-size: 20px; line-height: 1; }

/* Upload Progress */
.upload-progress { padding: 0 8px 8px; }
.progress-label { font-size: 11px; color: #888; margin-bottom: 4px; }
.progress-track { height: 4px; background: rgba(255,255,255,0.1); border-radius: 2px; overflow: hidden; }
.progress-fill { height: 100%; background: #667eea; border-radius: 2px; transition: width 0.3s; width: 0%; }

/* History */
.history-header {
  padding: 12px 16px 8px; font-size: 11px; text-transform: uppercase;
  color: #666; letter-spacing: 1px;
}
.history-list { flex: 1; overflow-y: auto; padding: 0 8px; }
.history-list::-webkit-scrollbar { width: 4px; }
.history-list::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 2px; }
.history-empty { padding: 24px 16px; text-align: center; color: #555; font-size: 13px; }

.history-item {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px; border-radius: 6px; cursor: pointer;
  transition: background 0.15s; margin-bottom: 2px; position: relative;
}
.history-item:hover { background: rgba(255,255,255,0.06); }
.history-item.active { background: rgba(102,126,234,0.15); color: #fff; }

.history-item-icon { font-size: 18px; flex-shrink: 0; }
.history-item-body { flex: 1; min-width: 0; }
.history-item-name {
  font-size: 13px; color: #eee; white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis; max-width: 160px;
}
.history-item-name:hover { overflow: visible; }
.history-item-file {
  font-size: 11px; color: #666; white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis; max-width: 180px; position: relative;
}
.history-item-file:hover { overflow: visible; }
.history-item-file:hover::after {
  content: attr(data-full); position: absolute; left: 0; top: 18px;
  background: #333; color: #eee; padding: 4px 8px; border-radius: 4px;
  font-size: 11px; white-space: nowrap; z-index: 100;
}
.history-item-time { font-size: 10px; color: #555; white-space: nowrap; flex-shrink: 0; }

.history-item-actions {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  display: none; gap: 4px;
}
.history-item:hover .history-item-actions { display: flex; }
.history-item.active:hover .history-item-actions { display: flex; }
.history-action-btn {
  width: 28px; height: 28px; border-radius: 4px; border: none;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; opacity: 0.7; transition: all 0.15s;
}
.history-action-btn:hover { opacity: 1; }
.history-action-btn.rename { background: rgba(255,255,255,0.08); color: #aaa; }
.history-action-btn.rename:hover { background: rgba(102,126,234,0.3); color: #667eea; }
.history-action-btn.delete { background: rgba(255,255,255,0.08); color: #aaa; }
.history-action-btn.delete:hover { background: rgba(231,76,60,0.3); color: #e74c3c; }

/* Rename inline */
.rename-input {
  width: 100%; padding: 2px 6px; font-size: 13px; border: 1px solid #667eea;
  background: transparent; color: #fff; border-radius: 4px; outline: none;
}

/* ===== Main Content ===== */
.main-content {
  flex: 1; overflow-y: auto; padding: 24px; position: relative;
}
.main-content::-webkit-scrollbar { width: 6px; }
.main-content::-webkit-scrollbar-thumb { background: #ddd; border-radius: 3px; }

/* ===== Empty State ===== */
.empty-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  height: 100%; text-align: center; color: #888;
}
.empty-icon { font-size: 80px; margin-bottom: 16px; opacity: 0.5; }
.empty-state h2 { font-size: 22px; color: #444; margin-bottom: 8px; }
.empty-state p { font-size: 14px; margin-bottom: 24px; }
.drop-zone {
  margin-top: 24px; border: 2px dashed #ddd; border-radius: 12px;
  padding: 40px 60px; transition: all 0.2s;
}
.drop-zone.drag-over { border-color: #667eea; background: rgba(102,126,234,0.05); }
.drop-zone p { margin: 0; color: #aaa; font-size: 14px; }

/* ===== Result ===== */
.result-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  margin-bottom: 20px;
}
.result-header h2 { font-size: 20px; color: #1a1a2e; }
.result-meta { font-size: 12px; color: #999; }

/* ===== KPI ===== */
.kpi-row { display: flex; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.kpi {
  flex: 1; min-width: 130px; padding: 16px; border-radius: 10px; text-align: center; color: #fff;
}
.kpi.high { background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%); }
.kpi.med { background: linear-gradient(135deg, #f6d365 0%, #fda085 100%); }
.kpi.low { background: linear-gradient(135deg, #84fab0 0%, #8fd3f4 100%); }
.kpi.purple { background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); }
.kpi .num { font-size: 28px; font-weight: 700; line-height: 1.2; }
.kpi .label { font-size: 12px; opacity: 0.85; margin-top: 4px; }

/* ===== Cards ===== */
.card { background: #fff; border-radius: 10px; padding: 16px; box-shadow: 0 1px 4px rgba(0,0,0,0.05); margin-bottom: 16px; }
.card h3 { font-size: 14px; color: #1a1a2e; margin-bottom: 12px; padding-bottom: 8px; border-bottom: 1px solid #eee; }
.card-full { grid-column: 1 / -1; }
.chart-box { position: relative; height: 300px; }
.chart-tall { position: relative; height: 400px; }

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

/* ===== Tables ===== */
.table-wrap { overflow-x: auto; max-height: 500px; overflow-y: auto; }
.table-wrap::-webkit-scrollbar { width: 5px; }
.table-wrap::-webkit-scrollbar-thumb { background: #ddd; border-radius: 3px; }
.tbl { width: 100%; border-collapse: collapse; font-size: 12px; }
.tbl th { background: #fafafa; padding: 8px 10px; text-align: left; font-weight: 600; border-bottom: 2px solid #e8e8e8; position: sticky; top: 0; z-index: 1; }
.tbl td { padding: 8px 10px; border-bottom: 1px solid #f0f0f0; }
.tbl tr:hover td { background: #f8f9ff; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 4px; font-size: 11px; font-weight: 600; }
.badge.high { background: #fff1f0; color: #cf1322; }
.badge.med { background: #fffbe6; color: #d48806; }
.badge.low { background: #f6ffed; color: #389e0d; }

.progress-bar { height: 5px; border-radius: 3px; background: #f0f0f0; margin: 2px 0; overflow: hidden; display: inline-block; width: 60px; vertical-align: middle; }
.progress-bar .fill { height: 100%; border-radius: 3px; }

/* ===== Dialog ===== */
.dialog-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 1000;
  display: flex; align-items: center; justify-content: center;
}
.dialog-box {
  background: #fff; border-radius: 12px; padding: 24px; width: 400px;
  max-width: 90vw; box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}
.dialog-box h3 { font-size: 17px; margin-bottom: 12px; }
.dialog-box p { font-size: 14px; color: #666; margin-bottom: 20px; line-height: 1.6; }
.dialog-actions { display: flex; gap: 8px; justify-content: flex-end; }

/* ===== Toast ===== */
.toast {
  position: fixed; top: 20px; left: 50%; transform: translateX(-50%);
  background: #e74c3c; color: #fff; padding: 12px 24px; border-radius: 8px;
  font-size: 14px; z-index: 2000; box-shadow: 0 4px 20px rgba(0,0,0,0.15);
  animation: fadeInOut 4s ease forwards;
}
@keyframes fadeInOut {
  0% { opacity: 0; transform: translateX(-50%) translateY(-10px); }
  10% { opacity: 1; transform: translateX(-50%) translateY(0); }
  80% { opacity: 1; }
  100% { opacity: 0; transform: translateX(-50%) translateY(-10px); }
}

/* ===== Responsive ===== */
@media (max-width: 1024px) {
  .grid-3 { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
  .sidebar { width: 60px; min-width: 60px; }
  .sidebar-title, .sidebar-header span:last-child, .import-btn span:last-child,
  .history-header, .history-item-name, .history-item-file, .history-item-time { display: none; }
  .history-item-actions { display: flex !important; position: static; transform: none; }
  .import-btn { justify-content: center; padding: 8px; }
}
