:root {
  --bg: #f5f7fb;
  --bg-elevated: #ffffff;
  --border-subtle: #e2e5f0;
  --border-strong: #c7cce0;
  --text-main: #111827;
  --text-muted: #6b7280;
  --primary: #2563eb;
  --primary-soft: rgba(37, 99, 235, 0.12);
  --danger: #ef4444;
  --danger-soft: rgba(239, 68, 68, 0.1);
  --accent: #22c55e;
  --shadow-soft: 0 18px 40px rgba(15, 23, 42, 0.08);
  --radius-lg: 16px;
  --radius-md: 10px;
  --radius-sm: 6px;
  --nav-width: 260px;
  --transition-fast: 0.16s ease-out;
  --transition-normal: 0.22s ease-out;
  --font-sans: system-ui, -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif;
}

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

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: var(--font-sans);
  color: var(--text-main);
  background: radial-gradient(circle at top left, #e0edff 0, #f5f7fb 42%, #f9fafb 100%);
}

body {
  -webkit-font-smoothing: antialiased;
}

#app {
  min-height: 100vh;
}

/* Views */

.view {
  display: none;
}

.view--active {
  display: block;
}

.view--hidden {
  display: none;
}

/* 登录页 */

.login-header {
  padding: 24px 24px 0;
}

.logo-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-mark {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: radial-gradient(circle at 30% 0, #60a5fa, #2563eb);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  color: #fff;
  box-shadow: 0 10px 30px rgba(37, 99, 235, 0.45);
}

.logo-title {
  font-weight: 700;
  letter-spacing: 0.03em;
}

.logo-subtitle {
  font-size: 12px;
  color: var(--text-muted);
}

.login-main {
  max-width: 1120px;
  margin: 0 auto;
  padding: 12px 16px 40px;
}

.login-title {
  font-size: 28px;
  margin: 10px 0 4px;
}

.login-desc {
  margin: 0 0 24px;
  color: var(--text-muted);
}

.login-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(0, 1.6fr);
  gap: 20px;
}

/* 登录卡片 */

.login-card {
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(18px);
  border-radius: var(--radius-lg);
  padding: 18px 18px 20px;
  box-shadow: var(--shadow-soft);
  border: 1px solid rgba(148, 163, 184, 0.35);
}

.login-card h2 {
  margin: 0 0 16px;
  font-size: 18px;
}

.saved-accounts {
  overflow: hidden;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.card-header h2 {
  margin: 0;
}

.card-body {
  font-size: 14px;
}

.card-footer {
  padding-top: 10px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.form-grid {
  display: grid;
  gap: 14px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.field-label {
  font-size: 13px;
  font-weight: 600;
  color: #4b5563;
}

.field input,
.field select,
.field textarea {
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  padding: 8px 10px;
  font-size: 14px;
  outline: none;
  background: #f9fafb;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast), background var(--transition-fast);
}

.field textarea {
  resize: vertical;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--primary);
  background: #fff;
  box-shadow: 0 0 0 1px rgba(37, 99, 235, 0.35);
}

.field small {
  font-size: 12px;
  color: var(--text-muted);
}

.field--inline {
  flex-direction: row;
  align-items: center;
  gap: 8px;
}

.field--inline input[type="checkbox"] {
  width: 16px;
  height: 16px;
}

.btn {
  border-radius: 999px;
  border: none;
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: background var(--transition-fast), color var(--transition-fast), box-shadow var(--transition-fast), border-color var(--transition-fast), transform var(--transition-fast);
}

.btn-primary {
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  color: #fff;
  box-shadow: 0 12px 25px rgba(37, 99, 235, 0.3);
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 16px 30px rgba(37, 99, 235, 0.38);
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--border-strong);
  color: #111827;
}

.btn-outline-sm {
  padding: 5px 10px;
  font-size: 13px;
  border-radius: 999px;
  border: 1px solid var(--border-subtle);
  background: #f9fafb;
}

.btn-outline-sm:hover {
  border-color: var(--primary);
}

.btn-danger-outline {
  background: transparent;
  border: 1px solid var(--danger);
  color: var(--danger);
}

.btn-text {
  background: transparent;
  border: none;
  color: var(--primary);
  padding: 0 4px;
}

.btn-text:hover {
  text-decoration: underline;
}

.btn-full {
  width: 100%;
  margin-top: 10px;
}

.login-tip {
  font-size: 12px;
  margin-top: 12px;
  color: var(--text-muted);
}

.alert {
  padding: 8px 10px;
  border-radius: var(--radius-md);
  font-size: 13px;
  margin-top: 6px;
}

.alert-error {
  background: var(--danger-soft);
  color: #991b1b;
  border: 1px solid rgba(239, 68, 68, 0.4);
}

/* Saved accounts */

.saved-list {
  border-radius: var(--radius-md);
  border: 1px dashed var(--border-subtle);
  padding: 8px;
  max-height: 320px;
  overflow: auto;
  background: #f9fafb;
}

.account-item {
  border-radius: 10px;
  padding: 8px 10px;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  cursor: pointer;
  background: #fff;
  border: 1px solid rgba(148, 163, 184, 0.5);
}

.account-item:hover {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.account-item-main {
  display: flex;
  flex-direction: column;
}

.account-email {
  font-size: 14px;
  font-weight: 500;
}

.account-label {
  font-size: 12px;
  color: var(--text-muted);
}

.account-meta {
  font-size: 11px;
  color: var(--text-muted);
}

.account-actions {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* 主布局 */

.topbar {
  height: 64px;
  background: rgba(255, 255, 255, 0.96);
  border-bottom: 1px solid rgba(226, 232, 240, 0.9);
  backdrop-filter: blur(18px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.account-switcher,
.zone-switcher {
  display: flex;
  align-items: center;
  gap: 6px;
  background: #eff3ff;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 13px;
}

.account-switcher select,
.zone-switcher select {
  border: none;
  background: transparent;
  font-size: 13px;
  outline: none;
}

.chip-label {
  font-size: 12px;
  color: #4b5563;
}

/* 侧边栏 + 内容 */

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

.sidebar {
  border-right: 1px solid rgba(226, 232, 240, 0.9);
  background: rgba(248, 250, 252, 0.98);
  padding: 14px 10px 18px;
}

.sidebar-section + .sidebar-section {
  margin-top: 18px;
}

.sidebar-title {
  font-size: 12px;
  font-weight: 600;
  color: #9ca3af;
  padding: 0 10px 4px;
  text-transform: uppercase;
}

.nav-item {
  width: 100%;
  text-align: left;
  border-radius: 9px;
  padding: 7px 10px;
  border: none;
  background: transparent;
  font-size: 14px;
  color: #374151;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: background var(--transition-fast), color var(--transition-fast), transform var(--transition-fast);
}

.nav-item:hover {
  background: #e5edff;
}

.nav-item--active {
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  color: #fff;
  box-shadow: 0 12px 24px rgba(37, 99, 235, 0.3);
  transform: translateY(-1px);
}

.content {
  padding: 18px 18px 32px;
}

.page {
  display: none;
}

.page--active {
  display: block;
}

.page-title {
  margin: 0 0 6px;
  font-size: 22px;
}

.page-desc {
  margin: 0 0 16px;
  color: var(--text-muted);
  font-size: 14px;
}

.warn {
  color: #b45309;
}

/* 通用卡片 */

.card {
  background: #ffffff;
  border-radius: var(--radius-lg);
  box-shadow: 0 16px 40px rgba(15, 23, 42, 0.05);
  border: 1px solid rgba(209, 213, 219, 0.8);
  padding: 14px 14px 14px;
  margin-bottom: 16px;
}

.inline-status {
  font-size: 13px;
  color: var(--text-muted);
}

/* 表格 */

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.table th,
.table td {
  padding: 6px 8px;
  border-bottom: 1px solid #e5e7eb;
  text-align: left;
}

.table th {
  font-size: 12px;
  color: #6b7280;
  font-weight: 600;
}

.table tbody tr:last-child td {
  border-bottom: none;
}

/* 代码块 */

.code-block {
  background: #0f172a;
  color: #e5e7eb;
  padding: 10px 12px;
  border-radius: 10px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono",
    "Courier New", monospace;
  font-size: 12px;
  overflow: auto;
}

/* 标签开关 */

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tag-toggle {
  border-radius: 999px;
  border: 1px solid var(--border-subtle);
  padding: 3px 10px;
  font-size: 12px;
  background: #f3f4f6;
  cursor: pointer;
}

.tag-toggle.active {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: #1d4ed8;
}

/* History */

.history-list-item {
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid var(--border-subtle);
  margin-bottom: 6px;
  background: #f9fafb;
  font-size: 13px;
}

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

/* Worker 模板 */

.tpl-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.tpl-item {
  border-radius: 12px;
  border: 1px solid var(--border-subtle);
  padding: 10px 12px;
  background: #f9fafb;
}

.tpl-item-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.tpl-item-meta {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

.tpl-item-actions {
  display: flex;
  gap: 6px;
  margin-top: 6px;
}

/* Toast */

.toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  padding: 8px 14px;
  border-radius: 999px;
  background: #111827;
  color: #f9fafb;
  font-size: 13px;
  box-shadow: 0 18px 45px rgba(15, 23, 42, 0.45);
  z-index: 50;
}

/* Utility */

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

.hidden {
  display: none !important;
}

.danger {
  color: var(--danger);
}

/* 按钮 - 图标 */

.icon-btn {
  border-radius: 999px;
  border: 1px solid var(--border-subtle);
  padding: 4px 9px;
  background: #f9fafb;
  cursor: pointer;
}

/* 响应式 */

.mobile-only {
  display: none;
}

@media (max-width: 880px) {
  .login-layout {
    grid-template-columns: minmax(0, 1fr);
  }

  .saved-accounts {
    order: 2;
  }
}

@media (max-width: 768px) {
  .topbar {
    padding-inline: 10px;
  }

  .layout {
    grid-template-columns: minmax(0, 1fr);
  }

  .sidebar {
    position: fixed;
    inset: 64px 0 auto;
    width: 260px;
    transform: translateX(-280px);
    transition: transform var(--transition-normal);
    z-index: 30;
    box-shadow: 15px 0 30px rgba(15, 23, 42, 0.3);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .content {
    padding-inline: 10px;
  }

  .mobile-only {
    display: inline-flex;
  }

  .account-switcher,
  .zone-switcher {
    display: none;
  }

  .login-header {
    padding-inline: 16px;
  }

  .login-main {
    padding-inline: 16px;
  }
}
