/* === Reset & Base === */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --sidebar-width: 220px;
  --sidebar-collapsed: 64px;
  --topbar-height: 56px;
  --primary: #4f6ef7;
  --primary-light: #eef1ff;
  --bg: #f5f6fa;
  --sidebar-bg: #1e2a3a;
  --sidebar-hover: #2a3a4e;
  --sidebar-active: #4f6ef7;
  --text: #333;
  --text-light: #999;
  --white: #fff;
  --shadow: 0 1px 4px rgba(0,0,0,0.08);
  --radius: 8px;
}

body {
  font-family: -apple-system, "Microsoft YaHei", "PingFang SC", "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
}

.app {
  display: flex;
  height: 100vh;
}

/* === Sidebar === */
.sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  color: var(--white);
  display: flex;
  flex-direction: column;
  transition: width 0.3s ease;
  overflow: hidden;
  flex-shrink: 0;
}

.sidebar.collapsed {
  width: var(--sidebar-collapsed);
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px;
  height: var(--topbar-height);
  border-bottom: 1px solid rgba(255,255,255,0.08);
  white-space: nowrap;
}

.logo-icon {
  font-size: 22px;
  flex-shrink: 0;
}

.logo-text {
  font-size: 16px;
  font-weight: 600;
  opacity: 1;
  transition: opacity 0.2s;
}

.sidebar.collapsed .logo-text,
.sidebar.collapsed .nav-label,
.sidebar.collapsed .user-name {
  opacity: 0;
  width: 0;
  overflow: hidden;
}

/* Nav Menu */
.nav-menu {
  flex: 1;
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 6px;
  color: rgba(255,255,255,0.7);
  text-decoration: none;
  font-size: 14px;
  white-space: nowrap;
  transition: all 0.2s;
  cursor: pointer;
}

.nav-item:hover {
  background: var(--sidebar-hover);
  color: var(--white);
}

.nav-item.active {
  background: var(--sidebar-active);
  color: var(--white);
}

.nav-icon {
  font-size: 18px;
  flex-shrink: 0;
  width: 24px;
  text-align: center;
}

.nav-label {
  transition: opacity 0.2s;
}

/* Sidebar Footer */
.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid rgba(255,255,255,0.08);
}

.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
  white-space: nowrap;
}

.avatar {
  font-size: 20px;
  flex-shrink: 0;
}

.user-name {
  font-size: 13px;
  color: rgba(255,255,255,0.7);
  transition: opacity 0.2s;
}

/* === Main Area === */
.main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

/* Topbar */
.topbar {
  height: var(--topbar-height);
  background: var(--white);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
  box-shadow: var(--shadow);
  flex-shrink: 0;
  z-index: 10;
}

.toggle-btn {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--text);
  padding: 4px;
  border-radius: 4px;
  line-height: 1;
}

.toggle-btn:hover {
  background: var(--bg);
}

.page-title {
  font-size: 17px;
  font-weight: 600;
  flex: 1;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.datetime {
  font-size: 13px;
  color: var(--text-light);
}

.refresh-btn {
  font-size: 12px;
  padding: 4px 12px;
  border: 1px solid var(--primary);
  border-radius: 4px;
  background: transparent;
  color: var(--primary);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}
.refresh-btn:hover:not(:disabled) {
  background: var(--primary);
  color: #fff;
}
.refresh-btn:disabled {
  cursor: default;
}

/* === Content === */
.content {
  flex: 1;
  padding: 24px;
  overflow-y: auto;
}

.page {
  display: none;
  animation: fadeIn 0.3s ease;
  width: 100%;
}

.page.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Placeholder Cards */
.placeholder-card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 60px 40px;
  text-align: center;
  box-shadow: var(--shadow);
  max-width: 500px;
  margin: 80px auto 0;
}

.placeholder-icon {
  font-size: 48px;
  display: block;
  margin-bottom: 16px;
}

.placeholder-card h2 {
  font-size: 20px;
  margin-bottom: 8px;
  color: var(--text);
}

.placeholder-card p {
  font-size: 14px;
  color: var(--text-light);
}

/* === Responsive === */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    height: 100vh;
    z-index: 100;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
  }

  .sidebar.mobile-open {
    transform: translateX(0);
  }

  .sidebar.collapsed {
    width: var(--sidebar-width);
  }
}

/* === Login Page === */
.login-overlay {
  position: fixed;
  inset: 0;
  background: linear-gradient(135deg, #1e2a3a 0%, #2d3e50 50%, #1a2332 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}

.login-overlay.hidden { display: none; }

.login-box {
  background: var(--white);
  border-radius: 12px;
  padding: 40px 36px;
  width: 380px;
  max-width: 90vw;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.login-header {
  text-align: center;
  margin-bottom: 28px;
}

.login-logo {
  font-size: 36px;
  display: block;
  margin-bottom: 8px;
  color: var(--primary);
}

.login-header h2 {
  font-size: 20px;
  font-weight: 600;
  color: var(--text);
}

.login-box .form-group { margin-bottom: 16px; }
.login-box .form-input { width: 100%; max-width: 100%; padding: 11px 14px; font-size: 14px; }

.login-btn {
  width: 100%;
  padding: 12px;
  font-size: 15px;
  font-weight: 600;
  margin-top: 8px;
  border-radius: 8px;
}

.login-error {
  color: #ef4444;
  font-size: 13px;
  min-height: 20px;
  margin: 0 0 4px;
}

.login-hint {
  text-align: center;
  font-size: 12px;
  color: var(--text-light);
  margin-top: 16px;
}

/* === Logout Button === */
.logout-btn {
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.15);
  color: rgba(255,255,255,0.6);
  padding: 4px 12px;
  border-radius: 4px;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
  margin-top: 8px;
  width: 100%;
}

.logout-btn:hover {
  background: rgba(239,68,68,0.2);
  border-color: rgba(239,68,68,0.4);
  color: #fca5a5;
}

.sidebar.collapsed .logout-btn { font-size: 0; padding: 4px; }
.sidebar.collapsed .logout-btn::after { content: '↩'; font-size: 14px; }

/* === JSON Upload Zone === */
.json-upload-zone {
  border: 2px dashed #d1d5db;
  border-radius: 10px;
  padding: 40px 20px;
  text-align: center;
  color: var(--text-light);
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
}
.json-upload-zone:hover, .json-upload-zone.dragover {
  border-color: var(--primary);
  background: var(--primary-light);
  color: var(--primary);
}
.json-upload-link { color: var(--primary); cursor: pointer; font-weight: 500; }
.json-upload-link:hover { text-decoration: underline; }

/* === Notify Bell === */
.notify-bell { position: relative; cursor: pointer; }
.bell-icon { font-size: 20px; }
.bell-badge {
  position: absolute; top: -4px; right: -6px;
  background: #ef4444; color: #fff; font-size: 10px; font-weight: 700;
  min-width: 16px; height: 16px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center; padding: 0 4px;
}
.notify-dropdown {
  display: none; position: absolute; top: 100%; right: 0; margin-top: 8px;
  width: 380px; max-height: 420px; background: var(--white);
  border-radius: 10px; box-shadow: 0 8px 30px rgba(0,0,0,0.15);
  z-index: 500; overflow: hidden;
}
.notify-dropdown.show { display: block; }
.notify-header { padding: 12px 16px; font-size: 14px; font-weight: 600; border-bottom: 1px solid #f0f0f0; }
.notify-list { max-height: 320px; overflow-y: auto; }
.notify-item { padding: 10px 16px; border-bottom: 1px solid #f8f8f8; font-size: 12px; cursor: pointer; transition: background 0.15s; }
.notify-item:hover { background: #f8f9ff; }
.notify-item .ni-name { font-weight: 600; }
.notify-item .ni-detail { color: var(--text-light); margin-top: 2px; }
.notify-item.level-expired { border-left: 3px solid #ef4444; }
.notify-item.level-warn7 { border-left: 3px solid #f59e0b; }
.notify-item.level-warn30 { border-left: 3px solid #eab308; }
.notify-footer { padding: 8px 16px; text-align: center; border-top: 1px solid #f0f0f0; }
.notify-empty { padding: 30px; text-align: center; color: var(--text-light); font-size: 13px; }

/* === Service deadline colors === */
.svc-normal { color: #16a34a; }
.svc-warn30 { color: #ca8a04; background: #fefce8; padding: 1px 4px; border-radius: 3px; }
.svc-warn7 { color: #ea580c; background: #fff7ed; padding: 1px 4px; border-radius: 3px; }
.svc-expired { color: #dc2626; background: #fef2f2; padding: 1px 4px; border-radius: 3px; }
.svc-off { color: #9ca3af; }

/* === Export Dialog === */
.export-field-list { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; }
.export-field-item { display: flex; align-items: center; gap: 4px; font-size: 13px; padding: 4px 8px; border-radius: 4px; cursor: pointer; }
.export-field-item:hover { background: var(--bg); }
.export-field-item input { accent-color: var(--primary); }

/* === Pagination === */
.pagination-bar { display: flex; align-items: center; justify-content: center; gap: 4px; padding: 12px 0; flex-wrap: wrap; }
.page-btn { min-width: 32px; height: 28px; border: 1px solid #ddd; background: #fff; border-radius: 4px; cursor: pointer; font-size: 12px; }
.page-btn:hover:not(:disabled):not(.active) { border-color: #1890ff; color: #1890ff; }
.page-btn.active { background: #1890ff; color: #fff; border-color: #1890ff; }
.page-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.page-ellipsis { padding: 0 4px; color: #999; font-size: 12px; }

.page-size-select { margin-left: 8px; padding: 2px 4px; border: 1px solid #ddd; border-radius: 4px; font-size: 12px; }

.batch-bar { display: flex; align-items: center; gap: 8px; padding: 8px 12px; background: #e6f7ff; border: 1px solid #91d5ff; border-radius: 4px; margin-bottom: 8px; flex-wrap: wrap; font-size: 13px; }
.batch-bar .btn-sm { padding: 4px 10px; font-size: 12px; border-radius: 4px; border: 1px solid #ddd; cursor: pointer; }
.batch-bar .btn-primary { background: #1890ff; color: #fff; border-color: #1890ff; }
.batch-bar .btn-danger { background: #ff4d4f; color: #fff; border-color: #ff4d4f; }

/* 自动登录按钮 */
.btn-auto-login { background: #1890ff; color: #fff; border: none; border-radius: 3px; padding: 2px 6px; font-size: 11px; cursor: pointer; margin-left: 4px; vertical-align: middle; }
.btn-auto-login:hover { background: #40a9ff; }
.btn-auto-login:disabled { background: #ccc; cursor: not-allowed; }

/* 通用按钮样式 */
.btn { display: inline-block; padding: 8px 16px; font-size: 13px; border-radius: 6px; border: 1px solid #ddd; cursor: pointer; font-weight: 500; transition: all 0.2s; background: #fff; color: #333; }
.btn-primary { background: #4f6ef7; color: #fff; border-color: #4f6ef7; }
.btn-primary:hover { background: #3b5de7; border-color: #3b5de7; }
.btn-outline { background: #fff; color: #4f6ef7; border-color: #4f6ef7; }
.btn-outline:hover { background: #f0f4ff; }
.btn-danger { background: #ef4444; color: #fff; border-color: #ef4444; }
.btn-danger:hover { background: #dc2626; border-color: #dc2626; }
.btn-sm { padding: 5px 12px; font-size: 12px; }

/* === 表头列筛选组件 === */
.data-table th { position: relative; }

.col-filter-btn {
  margin-left: 4px;
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 10px;
  line-height: 1;
  color: var(--text-light);
  padding: 3px 4px;
  border-radius: 4px;
  vertical-align: middle;
}
.col-filter-btn:hover { background: rgba(0,0,0,.06); color: var(--text); }
.col-filter-btn.col-filter-active { color: var(--primary); }

.col-filter-panel {
  position: absolute;
  top: 100%;
  left: 0;
  z-index: 60;
  margin-top: 4px;
  background: var(--white);
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,.14);
  padding: 6px;
  min-width: 140px;
  max-height: 260px;
  overflow-y: auto;
  font-weight: 400;
  font-size: 13px;
  text-transform: none;
  letter-spacing: normal;
  color: var(--text);
  cursor: default;
}

.col-filter-options { display: flex; flex-direction: column; gap: 1px; }
.col-filter-option {
  padding: 6px 10px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text);
  white-space: nowrap;
}
.col-filter-option:hover { background: var(--bg); }
.col-filter-option.active { background: var(--primary-light); color: var(--primary); font-weight: 600; }

.col-filter-input { width: 160px; font-size: 13px; }

.col-filter-daterange { display: flex; align-items: center; gap: 6px; }
.col-filter-date { width: 130px; font-size: 12px; padding: 5px 6px; }
.col-filter-date-sep { font-size: 12px; color: var(--text-light); }

/* === AI 助手：悬浮图标 + 聊天抽屉 === */
.ai-fab {
  position: fixed;
  right: 28px;
  bottom: 28px;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), #7c6ef7);
  color: #fff;
  border: none;
  font-size: 24px;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(79,110,247,.4);
  z-index: 100000;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform .15s;
}
.ai-fab:hover { transform: scale(1.08); }

.ai-chat-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.25);
  z-index: 100001;
  opacity: 0; pointer-events: none;
  transition: opacity .2s;
}
.ai-chat-overlay.show { opacity: 1; pointer-events: auto; }

.ai-chat-drawer {
  position: fixed;
  top: 0; right: -420px;
  width: 400px; max-width: 92vw;
  height: 100vh;
  background: var(--white);
  box-shadow: -4px 0 24px rgba(0,0,0,.15);
  z-index: 100002;
  display: flex;
  flex-direction: column;
  transition: right .25s ease;
}
.ai-chat-drawer.open { right: 0; }

.ai-chat-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid #f0f0f0;
  flex-shrink: 0;
}
.ai-chat-title { font-size: 16px; font-weight: 700; }
.ai-chat-header-actions { display: flex; gap: 6px; }
.ai-chat-icon-btn {
  width: 28px; height: 28px;
  border: none; background: var(--bg);
  border-radius: 6px; cursor: pointer;
  font-size: 14px; color: var(--text-light);
}
.ai-chat-icon-btn:hover { background: #e8eaf0; color: var(--text); }

.ai-chat-messages {
  flex: 1; overflow-y: auto;
  padding: 16px 18px;
  display: flex; flex-direction: column; gap: 12px;
}
.ai-chat-welcome {
  color: var(--text-light);
  font-size: 13.5px;
  background: var(--bg);
  padding: 12px 14px;
  border-radius: 10px;
}

.ai-msg { display: flex; }
.ai-msg-user { justify-content: flex-end; }
.ai-msg-assistant { justify-content: flex-start; }
.ai-msg-bubble {
  max-width: 82%;
  padding: 10px 13px;
  border-radius: 12px;
  font-size: 13.5px;
  line-height: 1.6;
  word-break: break-word;
}
.ai-msg-user .ai-msg-bubble {
  background: var(--primary);
  color: #fff;
  border-bottom-right-radius: 3px;
}
.ai-msg-assistant .ai-msg-bubble {
  background: var(--bg);
  color: var(--text);
  border-bottom-left-radius: 3px;
}

.ai-typing { display: inline-flex; gap: 3px; align-items: center; height: 14px; }
.ai-typing span {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--text-light);
  display: inline-block;
  animation: aiTypingBounce 1.2s infinite ease-in-out;
}
.ai-typing span:nth-child(2) { animation-delay: .15s; }
.ai-typing span:nth-child(3) { animation-delay: .3s; }
@keyframes aiTypingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: .5; }
  30% { transform: translateY(-4px); opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  .ai-typing span { animation: none; }
}

.ai-chat-input-bar {
  display: flex; gap: 8px; align-items: flex-end;
  padding: 12px 14px;
  border-top: 1px solid #f0f0f0;
  flex-shrink: 0;
}
.ai-chat-input {
  flex: 1;
  resize: none;
  border: 1px solid #ddd;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13.5px;
  font-family: inherit;
  max-height: 120px;
  line-height: 1.5;
}
.ai-chat-input:focus { outline: none; border-color: var(--primary); }
.ai-chat-send-btn { flex-shrink: 0; padding: 8px 16px; }
