@import url('https://fonts.googleapis.com/css2?family=Fira+Code:wght@400;500;600&family=Plus+Jakarta+Sans:wght@300;400;500;600;700&display=swap');

:root {
  color-scheme: light;
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-hover: #fcfdfe;
  --surface-strong: #f1f5f9;
  --text: #0f172a;
  --muted: #475569;
  --muted-light: #94a3b8;
  --border: #e2e8f0;
  --border-focus: #818cf8;
  
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-glow: rgba(79, 70, 229, 0.15);
  
  --success: #10b981;
  --success-light: #ecfdf5;
  --success-text: #047857;
  
  --warning: #f59e0b;
  --warning-light: #fffbeb;
  --warning-text: #b45309;
  
  --danger: #ef4444;
  --danger-light: #fef2f2;
  --danger-text: #b91c1c;

  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.02);
  --shadow-lg: 0 10px 15px -3px rgba(15, 23, 42, 0.08), 0 4px 6px -2px rgba(15, 23, 42, 0.03);
  --shadow-xl: 0 20px 25px -5px rgba(15, 23, 42, 0.12), 0 10px 10px -5px rgba(15, 23, 42, 0.04);
  
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  
  --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
  line-height: 1.5;
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* 布局外壳 */
.app-container {
  display: grid;
  grid-template-columns: 360px 1fr;
  min-height: 100vh;
}

/* 侧边栏 */
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  height: 100vh;
  position: sticky;
  top: 0;
  overflow-y: auto;
  z-index: 10;
}

.brand-header {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-bottom: 16px;
  border-bottom: 1px dashed var(--border);
}

.logo-container {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--primary);
}

.logo-icon {
  width: 24px;
  height: 24px;
  stroke-width: 2.5;
}

.brand-header h1 {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
}

.version-badge {
  align-self: flex-start;
  background: var(--primary-light);
  color: var(--primary);
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  margin-top: 2px;
}

/* 侧边栏表单 */
.sidebar-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.form-group label {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}

input, textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  transition: var(--transition);
  outline: none;
}

textarea {
  resize: none;
  font-family: inherit;
}

input:focus, textarea:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

/* 按钮样式 */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  border: 0;
  border-radius: var(--radius-sm);
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 2px 4px rgba(79, 70, 229, 0.2);
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
  transform: translateY(-1px);
}

.btn-secondary {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--surface-strong);
  color: var(--text);
}

.form-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 4px;
}

/* 系统状态 */
.status-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.status-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  background: var(--bg);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.status-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted-light);
  text-transform: uppercase;
}

.value-text {
  font-size: 13px;
  font-weight: 500;
}

.token-container {
  display: flex;
  align-items: center;
  gap: 6px;
  max-width: 60%;
}

.token-container .value-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: 'Fira Code', monospace;
}

.btn-icon {
  background: transparent;
  border: 0;
  color: var(--muted-light);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 2px;
  border-radius: 4px;
  transition: var(--transition);
}

.btn-icon:hover {
  color: var(--primary);
  background: var(--border);
}

/* 主展示区 */
.main-content {
  padding: 32px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  height: 100vh;
  overflow-y: auto;
}

/* 统计卡片 KPIs */
.stats-overview {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: var(--transition);
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--primary);
}

.stat-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
}

.stat-icon svg {
  width: 22px;
  height: 22px;
}

.res-icon {
  background: var(--primary-light);
  color: var(--primary);
}

.vio-icon {
  background: var(--danger-light);
  color: var(--danger);
}

.gate-icon {
  background: var(--success-light);
  color: var(--success);
}

.stat-info {
  display: flex;
  flex-direction: column;
}

.stat-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
}

.stat-val {
  font-size: 24px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
}

/* 数据网格 */
.data-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
  flex: 1;
  min-height: 0; /* 允许内部滚动 */
}

/* 卡片样式 */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.card-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.data-card {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-strong);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.card-header-title {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
}

.card-header h2 {
  font-size: 15px;
  font-weight: 700;
}

/* 列表容器 */
.list-container {
  padding: 16px;
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--bg);
}

.list-container.empty {
  justify-content: center;
  align-items: center;
  color: var(--muted-light);
  font-size: 14px;
  text-align: center;
  background: var(--surface);
}

/* 列表单项 */
.list-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.list-item.clickable {
  cursor: pointer;
}

.list-item.clickable:hover {
  border-color: var(--primary);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
  background: var(--surface-hover);
}

.item-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.item-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
}

.item-body {
  font-size: 13px;
  color: var(--muted);
}

/* 状态角标 Badge */
.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 600;
  border-radius: 999px;
  white-space: nowrap;
}

.badge-success {
  background: var(--success-light);
  color: var(--success-text);
}

.badge-warning {
  background: var(--warning-light);
  color: var(--warning-text);
}

.badge-danger {
  background: var(--danger-light);
  color: var(--danger-text);
}

.badge-gray {
  background: var(--surface-strong);
  color: var(--muted);
}

/* 生命周期侧滑抽屉 (Drawer) */
.drawer-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(15, 23, 42, 0.3);
  backdrop-filter: blur(4px);
  z-index: 99;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.drawer-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.detail-drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: 440px;
  max-width: 100vw;
  height: 100vh;
  background: var(--surface);
  box-shadow: var(--shadow-xl);
  z-index: 100;
  transform: translateX(100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  flex-direction: column;
}

.detail-drawer.open {
  transform: translateX(0);
}

.drawer-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.drawer-header-title {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
}

.drawer-header-title h2 {
  font-size: 16px;
  font-weight: 700;
}

.btn-close {
  background: transparent;
  border: 0;
  color: var(--muted-light);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
  border-radius: 50%;
  transition: var(--transition);
}

.btn-close:hover {
  background: var(--surface-strong);
  color: var(--text);
}

.drawer-content {
  padding: 24px;
  overflow-y: auto;
  flex: 1;
  background: var(--bg);
}

/* 时间线样式 */
.timeline {
  position: relative;
  padding-left: 20px;
}

.timeline.empty {
  padding-left: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--muted-light);
  font-size: 14px;
}

.timeline::before {
  content: '';
  position: absolute;
  left: 6px;
  top: 8px;
  bottom: 8px;
  width: 2px;
  background: var(--border);
}

.timeline-item {
  position: relative;
  margin-bottom: 24px;
}

.timeline-item:last-child {
  margin-bottom: 0;
}

.timeline-dot {
  position: absolute;
  left: -20px;
  top: 6px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--primary);
  border: 2px solid var(--surface);
  box-shadow: 0 0 0 2px var(--primary-light);
}

.timeline-content {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.timeline-title {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text);
}

.timeline-time {
  font-size: 11px;
  color: var(--muted-light);
}

/* 卡片高亮动画 */
@keyframes highlight-flash {
  0% {
    box-shadow: 0 0 0 0 rgba(79, 70, 229, 0.4);
    border-color: var(--primary);
  }
  50% {
    box-shadow: 0 0 12px 4px rgba(79, 70, 229, 0.3);
    border-color: var(--primary);
  }
  100% {
    box-shadow: var(--shadow-sm);
    border-color: var(--border);
  }
}

.highlight-flash {
  animation: highlight-flash 1.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* 响应式适配 */
@media (max-width: 1200px) {
  .app-container {
    grid-template-columns: 320px 1fr;
  }
  .data-grid {
    grid-template-columns: 1fr;
    gap: 16px;
  }
}

@media (max-width: 900px) {
  .app-container {
    grid-template-columns: 1fr;
  }
  
  .sidebar {
    height: auto;
    position: relative;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }
  
  .main-content {
    height: auto;
    overflow-y: visible;
    padding: 20px;
  }
  
  .stats-overview {
    grid-template-columns: 1fr;
  }
}

/* Compact mobile-first layout */
.compact-app {
  display: block;
  min-height: 100vh;
}

.top-bar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: minmax(180px, 260px) 1fr minmax(160px, 280px);
  gap: 10px;
  align-items: stretch;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  background: rgba(248, 250, 252, 0.96);
  backdrop-filter: blur(8px);
}

.top-title {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-width: 0;
}

.top-title h1 {
  font-size: 17px;
  line-height: 1.2;
}

.top-title .value-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.compact-app .settings-card {
  box-shadow: none;
}

.compact-app .sidebar-form {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) 150px auto;
  gap: 8px;
  align-items: end;
  padding: 8px;
}

.compact-app .form-group {
  gap: 3px;
}

.compact-app .form-group label {
  font-size: 11px;
}

.compact-app textarea,
.compact-app input {
  min-height: 34px;
  padding: 7px 9px;
  font-size: 13px;
}

.compact-app textarea {
  height: 34px;
  line-height: 18px;
}

.compact-app .form-actions {
  display: grid;
  grid-template-columns: auto auto;
  gap: 6px;
  margin: 0;
}

.compact-app .btn {
  min-height: 34px;
  padding: 6px 12px;
  font-size: 13px;
}

.token-strip {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  background: var(--surface);
}

.token-strip #tokenText {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.compact-app .main-content {
  height: auto;
  min-height: 0;
  overflow: visible;
  gap: 10px;
  padding: 10px 12px 18px;
}

.compact-app .data-grid {
  display: grid;
  grid-template-columns: 1.2fr 1fr 0.9fr;
  gap: 10px;
  min-height: 0;
}

.compact-app .priority-card {
  grid-column: 1 / -1;
}

.compact-app .card {
  border-radius: 8px;
  box-shadow: none;
}

.compact-app .card-header {
  min-height: 36px;
  padding: 8px 10px;
}

.compact-app .card-header-title {
  width: 100%;
  justify-content: space-between;
}

.compact-app .card-header h2 {
  font-size: 14px;
}

.compact-app .count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  height: 22px;
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: 12px;
}

.compact-app .list-container {
  max-height: 30vh;
  padding: 6px;
  gap: 4px;
  background: var(--surface);
}

.compact-app .priority-card .list-container {
  max-height: 24vh;
  min-height: 72px;
}

.compact-app .list-container.empty {
  min-height: 52px;
  justify-content: center;
}

.compact-app .list-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px;
  align-items: center;
  min-height: 32px;
  border-radius: 6px;
  padding: 6px 8px;
  box-shadow: none;
}

.compact-app .item-header {
  min-width: 0;
  align-items: center;
  gap: 6px;
}

.compact-app .item-title,
.compact-app .item-body,
.compact-app .badge {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.compact-app .item-title {
  min-width: 0;
  font-size: 13px;
}

.compact-app .item-body {
  color: var(--muted);
  font-size: 12px;
}

.compact-app .badge {
  max-width: 108px;
  padding: 1px 6px;
  font-size: 10px;
}

@media (max-width: 760px) {
  body {
    background: var(--surface);
  }

  .top-bar {
    position: relative;
    grid-template-columns: 1fr;
    gap: 6px;
    padding: 8px;
  }

  .top-title {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 8px;
    align-items: center;
  }

  .compact-app .settings-card,
  .token-strip {
    border-radius: 7px;
  }

  .compact-app .sidebar-form {
    grid-template-columns: 1fr auto;
    gap: 6px;
    padding: 6px;
  }

  .compact-app .sidebar-form .form-group:first-child {
    grid-column: 1 / -1;
  }

  .compact-app textarea {
    height: 30px;
    min-height: 30px;
  }

  .compact-app input {
    min-height: 32px;
  }

  .compact-app .form-actions {
    grid-template-columns: auto auto;
  }

  .token-strip {
    padding: 6px 8px;
  }

  .compact-app .main-content {
    padding: 8px;
  }

  .compact-app .data-grid {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .compact-app .data-card {
    min-height: 0;
  }

  .compact-app .priority-card .list-container {
    max-height: 28vh;
    min-height: 84px;
  }

  .compact-app .list-container {
    max-height: 22vh;
  }

  .compact-app .card-header {
    min-height: 34px;
    padding: 7px 9px;
  }

  .compact-app .list-item {
    grid-template-columns: minmax(0, 1fr) auto;
    min-height: 30px;
    padding: 5px 7px;
  }

  .compact-app .item-body {
    display: none;
  }

  .detail-drawer {
    width: 100vw;
  }
}
