
:root {
  --bg: #020617;
  --bg-elevated: #020617;
  --bg-card: #020617;
  --border-subtle: #1e293b;
  --accent: #6366f1;
  --accent-soft: rgba(99, 102, 241, 0.15);
  --accent-strong: #4f46e5;
  --text-main: #e5e7eb;
  --text-muted: #9ca3af;
  --danger: #f97373;
  --danger-soft: rgba(248, 113, 113, 0.12);
  --success: #22c55e;
  --success-soft: rgba(34, 197, 94, 0.16);
  --warning: #facc15;
  --warning-soft: rgba(250, 204, 21, 0.16);
  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 999px;
  --shadow-lg: 0 24px 50px rgba(15, 23, 42, 0.75);
  --shadow-card: 0 18px 30px rgba(15, 23, 42, 0.7);
  --shadow-soft: 0 10px 20px rgba(15, 23, 42, 0.65);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI",
    sans-serif;
  background: radial-gradient(circle at top, #020617 0, #020617 45%, #020617 80%, #000000 100%);
  color: var(--text-main);
}

#app {
  min-height: 100vh;
}

/* 通用布局 */

.view {
  display: none;
}

.view-active {
  display: block;
}

.page {
  display: none;
}

.page-active {
  display: block;
}

.page h2 {
  margin: 0 0 0.4rem;
  font-size: 1.3rem;
}

.page-desc {
  margin: 0 0 1rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* 登录页 */

.login-card {
  max-width: 880px;
  margin: 3rem auto;
  background: linear-gradient(145deg, rgba(15, 23, 42, 0.96), rgba(2, 6, 23, 0.98));
  border-radius: 24px;
  padding: 2.4rem 2.6rem;
  box-shadow: var(--shadow-lg);
  border: 1px solid rgba(148, 163, 184, 0.3);
}

.login-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.logo-circle {
  width: 48px;
  height: 48px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: conic-gradient(
    from 200deg,
    #22d3ee,
    #6366f1,
    #e879f9,
    #f97316,
    #22c55e,
    #22d3ee
  );
  color: white;
  font-weight: 800;
  font-size: 1.4rem;
  box-shadow: 0 0 0 2px #020617, 0 10px 25px rgba(56, 189, 248, 0.8);
}

.logo-circle.small {
  width: 36px;
  height: 36px;
  font-size: 1.1rem;
}

.login-header h1 {
  margin: 0;
  font-size: 1.4rem;
}

.login-header p {
  margin: 0.25rem 0 0;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.login-body {
  display: grid;
  grid-template-columns: 1.1fr 1.1fr;
  gap: 1rem 1.4rem;
  margin-bottom: 1.6rem;
}

.login-accounts h2 {
  margin: 0 0 0.8rem;
  font-size: 1rem;
  color: var(--text-muted);
}

.account-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.7rem;
}

.account-pill {
  padding: 0.4rem 0.75rem;
  background: rgba(15, 23, 42, 0.9);
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.4);
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8rem;
}

.account-pill span.email {
  max-width: 170px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account-pill button {
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.8rem;
}

.account-pill button:hover {
  color: #fca5a5;
}

/* 表单元素 */

.field {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.9rem;
}

.field span {
  color: var(--text-main);
}

.field small {
  color: var(--text-muted);
}

.field input,
.field select,
.field textarea {
  padding: 0.5rem 0.55rem;
  border-radius: 0.6rem;
  border: 1px solid rgba(148, 163, 184, 0.4);
  background: rgba(15, 23, 42, 0.9);
  color: var(--text-main);
  outline: none;
  font-size: 0.9rem;
}

.field textarea {
  resize: vertical;
  min-height: 70px;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: rgba(129, 140, 248, 0.8);
  box-shadow: 0 0 0 1px rgba(129, 140, 248, 0.6);
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.checkbox-row input {
  width: 16px;
  height: 16px;
}

code {
  font-family: ui-monospace, Menlo, Monaco, Consolas, "SF Mono", "Courier New", monospace;
  font-size: 0.8rem;
  padding: 0.15rem 0.35rem;
  border-radius: 0.35rem;
  background: rgba(15, 23, 42, 0.95);
  border: 1px solid rgba(31, 41, 55, 0.8);
}

/* 按钮 */

.btn {
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.5);
  background: rgba(15, 23, 42, 0.95);
  color: var(--text-main);
  font-size: 0.85rem;
  padding: 0.45rem 0.9rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  transition: all 0.12s ease-out;
  white-space: nowrap;
}

.btn.full {
  width: 100%;
  justify-content: center;
}

.btn.small {
  padding: 0.35rem 0.75rem;
  font-size: 0.8rem;
}

.btn.primary {
  background: linear-gradient(135deg, #4f46e5, #22d3ee);
  border-color: transparent;
  color: #f9fafb;
  box-shadow: 0 16px 30px rgba(56, 189, 248, 0.4);
}

.btn.primary:hover {
  filter: brightness(1.06);
  box-shadow: 0 20px 40px rgba(56, 189, 248, 0.55);
  transform: translateY(-1px);
}

.btn.secondary {
  background: rgba(37, 99, 235, 0.15);
  border-color: rgba(59, 130, 246, 0.6);
}

.btn.ghost {
  background: transparent;
}

.btn.danger {
  background: linear-gradient(135deg, #ef4444, #f97316);
  border-color: transparent;
  color: #fef2f2;
  box-shadow: 0 14px 30px rgba(248, 113, 113, 0.55);
}

.btn.danger.ghost {
  background: rgba(127, 29, 29, 0.35);
  border-color: rgba(254, 202, 202, 0.5);
}

/* 顶部栏和主布局 */

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.85rem 1.8rem;
  border-bottom: 1px solid rgba(30, 64, 175, 0.6);
  background: radial-gradient(circle at top left, rgba(30, 64, 175, 0.35), transparent 55%),
    rgba(15, 23, 42, 0.98);
  box-shadow: 0 10px 25px rgba(15, 23, 42, 0.85);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.topbar-titles .app-name {
  font-weight: 600;
  font-size: 0.98rem;
}

.topbar-titles .app-subtitle {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.layout {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  min-height: calc(100vh - 60px);
}

/* 侧边栏 */

.sidebar {
  border-right: 1px solid rgba(31, 41, 55, 0.9);
  padding: 1rem 0.85rem 1.6rem;
  background: radial-gradient(circle at top left, rgba(30, 64, 175, 0.3), transparent 48%),
    rgba(15, 23, 42, 0.98);
}

.sidebar-section + .sidebar-section {
  margin-top: 1.2rem;
  padding-top: 1.2rem;
  border-top: 1px dashed rgba(51, 65, 85, 0.8);
}

.sidebar-title {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 0.4rem;
  padding: 0 0.2rem;
}

.nav-item {
  width: 100%;
  margin: 0.1rem 0;
  text-align: left;
  padding: 0.42rem 0.75rem;
  border-radius: 0.6rem;
  background: transparent;
  border: none;
  color: var(--text-main);
  cursor: pointer;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.nav-item:hover {
  background: rgba(15, 23, 42, 0.85);
}

.nav-item.active {
  background: rgba(129, 140, 248, 0.2);
  box-shadow: inset 0 0 0 1px rgba(129, 140, 248, 0.7);
}

.zone-select {
  width: 100%;
  margin-bottom: 0.3rem;
}

/* 主内容 */

.main {
  padding: 1.2rem 1.35rem 2rem;
}

/* 卡片 */

.card {
  background: radial-gradient(circle at top, rgba(15, 23, 42, 0.98), rgba(2, 6, 23, 0.98));
  border-radius: var(--radius-lg);
  padding: 1rem 1.1rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow-card);
  border: 1px solid rgba(30, 64, 175, 0.8);
}

.card h3 {
  margin: 0 0 0.6rem;
  font-size: 1rem;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 0.75rem;
}

/* 工具条 */

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  margin-bottom: 0.6rem;
}

.toolbar input {
  flex: 1;
}

/* 网格布局 */

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.8rem;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.8rem;
}

.grid-4 {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.8rem;
}

/* 开关控件 */

.switch {
  position: relative;
  display: inline-block;
  width: 38px;
  height: 20px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #374151;
  transition: 0.18s;
  border-radius: 999px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 14px;
  width: 14px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: 0.18s;
  border-radius: 999px;
}

.switch input:checked + .slider {
  background-color: #4f46e5;
}

.switch input:checked + .slider:before {
  transform: translateX(18px);
}

/* 行内字段 */

.field-inline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  font-size: 0.87rem;
  margin-bottom: 0.45rem;
}

.field-inline label:first-child {
  flex: 1;
}

.field-inline small {
  flex: 2;
  color: var(--text-muted);
}

/* Tag pill */

.tag-row {
  display: flex;
  gap: 0.5rem;
}

.tag-pill {
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.6);
  padding: 0.22rem 0.6rem;
  font-size: 0.8rem;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.tag-pill input {
  width: 14px;
  height: 14px;
}

/* 自动优化头部 */

.auto-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
}

.auto-mode-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  border: 1px solid rgba(129, 140, 248, 0.7);
  background: rgba(15, 23, 42, 0.95);
  font-size: 0.7rem;
  color: #a5b4fc;
  margin-bottom: 0.25rem;
}

.warning {
  margin: 0.45rem 0 0;
  font-size: 0.8rem;
  color: #fbbf24;
}

/* 分割线 */

.divider {
  margin: 0.7rem 0;
  border-top: 1px dashed rgba(55, 65, 81, 0.8);
}

/* 表格型展示 */

.table {
  width: 100%;
  border-radius: 0.75rem;
  border: 1px solid rgba(31, 41, 55, 0.9);
  background: rgba(15, 23, 42, 0.95);
  overflow: hidden;
  font-size: 0.83rem;
}

.table-header,
.table-row {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  align-items: center;
  padding: 0.4rem 0.6rem;
  column-gap: 0.4rem;
}

.table-header {
  background: rgba(15, 23, 42, 0.98);
  font-weight: 500;
  color: var(--text-muted);
  border-bottom: 1px solid rgba(31, 41, 55, 0.9);
}

.table-row:nth-child(odd) {
  background: rgba(15, 23, 42, 0.92);
}

.table-row:nth-child(even) {
  background: rgba(15, 23, 42, 0.98);
}

.table-row:hover {
  background: rgba(30, 64, 175, 0.35);
}

.table-cell {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 历史记录 */

.history-list {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.history-item {
  padding: 0.5rem 0.65rem;
  border-radius: 0.75rem;
  border: 1px solid rgba(31, 41, 55, 0.9);
  background: rgba(15, 23, 42, 0.96);
  font-size: 0.8rem;
}

.history-item .meta {
  display: flex;
  justify-content: space-between;
  color: var(--text-muted);
  font-size: 0.75rem;
}

/* 代码块 */

.code-block {
  background: rgba(15, 23, 42, 0.98);
  border-radius: 0.7rem;
  padding: 0.6rem 0.75rem;
  border: 1px solid rgba(31, 41, 55, 0.9);
  overflow-x: auto;
  font-size: 0.8rem;
}

.code-block.small {
  max-height: 220px;
}

/* 模板列表 */

.template-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 0.75rem;
}

.template-card {
  border-radius: 0.9rem;
  border: 1px solid rgba(31, 41, 55, 0.9);
  background: rgba(15, 23, 42, 0.97);
  padding: 0.7rem 0.8rem;
  font-size: 0.86rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.template-card .title-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.4rem;
}

.template-card .desc {
  color: var(--text-muted);
  font-size: 0.8rem;
}

.template-card .meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.template-card .actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.4rem;
  margin-top: 0.3rem;
}

.badge-blue {
  border-radius: 999px;
  border: 1px solid rgba(129, 140, 248, 0.7);
  background: rgba(37, 99, 235, 0.2);
  padding: 0.05rem 0.4rem;
  font-size: 0.7rem;
}

.badge-green {
  border-radius: 999px;
  border: 1px solid rgba(34, 197, 94, 0.7);
  background: rgba(22, 163, 74, 0.2);
  padding: 0.05rem 0.4rem;
  font-size: 0.7rem;
}

/* 模态框 */

.modal {
  position: fixed;
  inset: 0;
  display: none;
}

.modal.visible {
  display: block;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.8);
  backdrop-filter: blur(6px);
}

.modal-body {
  position: absolute;
  top: 50%;
  left: 50%;
  width: min(720px, 96vw);
  transform: translate(-50%, -50%);
  background: rgba(15, 23, 42, 0.98);
  border-radius: 1rem;
  padding: 1.2rem 1.4rem;
  box-shadow: var(--shadow-lg);
  border: 1px solid rgba(148, 163, 184, 0.6);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.6rem;
  margin-top: 0.6rem;
}

/* Toast */

.toast {
  position: fixed;
  left: 50%;
  bottom: 1.8rem;
  transform: translateX(-50%);
  padding: 0.6rem 1rem;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.98);
  color: var(--text-main);
  font-size: 0.85rem;
  border: 1px solid rgba(148, 163, 184, 0.6);
  box-shadow: var(--shadow-soft);
  z-index: 99;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease-out, transform 0.18s ease-out;
}

.toast.show {
  opacity: 1;
  pointer-events: auto;
  transform: translate(-50%, -8px);
}

.toast.success {
  border-color: rgba(34, 197, 94, 0.7);
}

.toast.error {
  border-color: rgba(248, 113, 113, 0.9);
}

/* Loading 遮罩 */

.loading-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.75);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 90;
}

.loading-backdrop.hidden {
  display: none;
}

.spinner {
  width: 32px;
  height: 32px;
  border-radius: 999px;
  border: 3px solid rgba(148, 163, 184, 0.6);
  border-top-color: #38bdf8;
  animation: spin 0.8s linear infinite;
  margin-bottom: 0.4rem;
}

.loading-text {
  font-size: 0.85rem;
  color: var(--text-muted);
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* 分析页 */

.analytics-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 0.7rem;
  margin-top: 0.6rem;
}

.stat-card {
  border-radius: 0.85rem;
  padding: 0.55rem 0.7rem;
  background: rgba(15, 23, 42, 0.97);
  border: 1px solid rgba(31, 41, 55, 0.9);
  font-size: 0.8rem;
}

.stat-card .label {
  color: var(--text-muted);
  margin-bottom: 0.15rem;
}

.stat-card .value {
  font-weight: 600;
}

.analytics-daily {
  margin-top: 0.8rem;
  font-size: 0.82rem;
}

/* KV */

.kv-namespace-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

/* 文件输入按钮 */

.file-input-label {
  position: relative;
  overflow: hidden;
}

/* 响应式 */

@media (max-width: 960px) {
  .login-card {
    margin: 1.5rem 0.5rem;
    padding: 1.6rem 1.4rem;
  }
  .login-body {
    grid-template-columns: 1fr;
  }
  .layout {
    grid-template-columns: 220px minmax(0, 1fr);
  }
}

@media (max-width: 768px) {
  .layout {
    grid-template-columns: 1fr;
  }
  .sidebar {
    border-right: none;
    border-bottom: 1px solid rgba(31, 41, 55, 0.9);
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
  }
  .sidebar-section {
    flex: 1 1 220px;
  }
}
