:root {
  color-scheme: light;
  --bg: #f2efe7;
  --bg-soft: rgba(255, 255, 255, 0.72);
  --bg-strong: rgba(255, 255, 255, 0.9);
  --panel-border: rgba(19, 42, 63, 0.08);
  --text: #132a3f;
  --text-soft: #5b6a78;
  --accent: #0d6e6e;
  --accent-soft: rgba(13, 110, 110, 0.12);
  --accent-strong: #083f4e;
  --shadow: 0 18px 40px rgba(16, 34, 52, 0.08);
  --danger: #b6382d;
  --success: #1e8a4b;
  --muted: #7a8590;
  --black-card: #1d2127;
  --green-card: #0f6d44;
  --red-card: #982d24;
  --gray-card: #6a7078;
  --sidebar-width: 280px;
  --radius-xl: 28px;
  --radius-lg: 20px;
  --radius-md: 16px;
  --radius-sm: 12px;
  --font-stack: "Avenir Next", "Segoe UI Variable Display", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

body[data-theme="dark"] {
  color-scheme: dark;
  --bg: #13161c;
  --bg-soft: rgba(20, 24, 31, 0.82);
  --bg-strong: rgba(24, 29, 37, 0.92);
  --panel-border: rgba(255, 255, 255, 0.08);
  --text: #edf1f6;
  --text-soft: #9ba8b8;
  --accent: #6ed8c6;
  --accent-soft: rgba(110, 216, 198, 0.12);
  --accent-strong: #9ae9dd;
  --shadow: 0 18px 42px rgba(0, 0, 0, 0.3);
  --danger: #ff756b;
  --success: #4fd18a;
  --muted: #8390a2;
  --black-card: #111317;
  --green-card: #0d5e3c;
  --red-card: #7f2b27;
  --gray-card: #4a5260;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-stack);
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(223, 158, 93, 0.22), transparent 34%),
    radial-gradient(circle at bottom right, rgba(13, 110, 110, 0.18), transparent 30%),
    linear-gradient(135deg, #f6f1e8 0%, #e8efe9 48%, #e4ecef 100%);
}

body[data-theme="dark"] {
  background:
    radial-gradient(circle at top left, rgba(214, 139, 85, 0.12), transparent 28%),
    radial-gradient(circle at bottom right, rgba(110, 216, 198, 0.12), transparent 30%),
    linear-gradient(135deg, #0d1015 0%, #121821 45%, #1a2028 100%);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  min-height: 100vh;
  gap: 24px;
  padding: 24px;
}

.surface {
  background: var(--bg-soft);
  backdrop-filter: blur(18px);
  border: 1px solid var(--panel-border);
  box-shadow: var(--shadow);
}

.sidebar {
  border-radius: var(--radius-xl);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 16px;
}

.brand-mark {
  width: 56px;
  height: 56px;
  border-radius: 18px;
  background: linear-gradient(135deg, #f1a852, var(--accent));
  color: white;
  display: grid;
  place-items: center;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.brand-title {
  font-size: 1.2rem;
  font-weight: 700;
}

.brand-subtitle,
.sidebar-footer,
.panel-note,
#view-subtitle {
  color: var(--text-soft);
}

.sidebar-actions {
  display: grid;
  gap: 12px;
}

.menu {
  display: grid;
  gap: 10px;
}

.menu-button,
.ghost-button,
.primary-button,
.toggle-button {
  border: 0;
  border-radius: 999px;
  padding: 12px 16px;
  transition: transform 0.2s ease, background 0.2s ease, color 0.2s ease, opacity 0.2s ease;
}

.menu-button {
  text-align: left;
  background: transparent;
  color: var(--text);
  border: 1px solid transparent;
}

.menu-button.active {
  background: var(--accent-soft);
  border-color: rgba(13, 110, 110, 0.22);
  color: var(--accent-strong);
  transform: translateX(4px);
}

.ghost-button {
  background: rgba(255, 255, 255, 0.42);
  color: var(--text);
  border: 1px solid var(--panel-border);
}

body[data-theme="dark"] .ghost-button {
  background: rgba(255, 255, 255, 0.04);
}

.primary-button {
  background: linear-gradient(135deg, #f19c4e, var(--accent));
  color: white;
  font-weight: 700;
}

.toggle-button {
  background: rgba(255, 255, 255, 0.5);
  color: var(--text);
  border: 1px solid var(--panel-border);
}

.toggle-button.disabled {
  background: rgba(182, 56, 45, 0.12);
  color: var(--danger);
}

.status-pill {
  border-radius: 999px;
  padding: 10px 14px;
  font-size: 0.92rem;
  font-weight: 600;
}

.status-pill.running {
  background: rgba(13, 110, 110, 0.12);
  color: var(--accent-strong);
}

.status-pill.finished {
  background: rgba(30, 138, 75, 0.14);
  color: var(--success);
}

.status-pill.failed {
  background: rgba(182, 56, 45, 0.14);
  color: var(--danger);
}

.status-pill.idle {
  background: rgba(122, 133, 144, 0.16);
  color: var(--muted);
}

.sidebar-footer {
  margin-top: auto;
  font-size: 0.92rem;
  line-height: 1.6;
}

.content {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.topbar,
.panel,
.stat-card {
  border-radius: var(--radius-xl);
}

.topbar {
  padding: 24px 28px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
}

.topbar h1,
.page-head h2,
.panel-head h3,
.modal-head h3 {
  margin: 0;
}

.page {
  display: none;
  gap: 18px;
}

.page.active {
  display: grid;
}

.page-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
}

.page-actions,
.panel-actions {
  display: flex;
  gap: 12px;
  align-items: center;
}

.grid {
  display: grid;
  gap: 18px;
}

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

.full-span {
  grid-column: 1 / -1;
}

.panel,
.stat-card {
  padding: 22px;
}

.highlight-card {
  background: linear-gradient(145deg, rgba(241, 168, 82, 0.24), rgba(13, 110, 110, 0.08));
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 18px;
}

.chip {
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.52);
  color: var(--text-soft);
  font-size: 0.82rem;
  border: 1px solid var(--panel-border);
}

body[data-theme="dark"] .chip {
  background: rgba(255, 255, 255, 0.05);
}

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

.compact-grid {
  margin-bottom: 18px;
}

.field,
.switch-field {
  display: grid;
  gap: 8px;
}

.field span,
.switch-field span {
  font-size: 0.92rem;
  color: var(--text-soft);
}

.field input,
.field select,
.field textarea {
  width: 100%;
  border: 1px solid var(--panel-border);
  background: var(--bg-strong);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  outline: none;
}

.field textarea {
  resize: vertical;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: rgba(13, 110, 110, 0.36);
  box-shadow: 0 0 0 3px rgba(13, 110, 110, 0.08);
}

.full-row {
  grid-column: 1 / -1;
}

.switch-field {
  grid-template-columns: 1fr auto;
  align-items: center;
}

.switch-field input {
  width: 22px;
  height: 22px;
}

.channel-card.disabled-card {
  opacity: 0.62;
}

.cfmail-list {
  display: grid;
  gap: 14px;
}

.cfmail-item {
  border: 1px dashed var(--panel-border);
  border-radius: var(--radius-lg);
  padding: 18px;
  background: rgba(255, 255, 255, 0.28);
}

body[data-theme="dark"] .cfmail-item {
  background: rgba(255, 255, 255, 0.02);
}

.cfmail-item.disabled-card {
  opacity: 0.62;
}

.cfmail-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

.cfmail-actions {
  display: flex;
  gap: 10px;
}

.danger-button {
  background: rgba(182, 56, 45, 0.12);
  color: var(--danger);
  border: 1px solid rgba(182, 56, 45, 0.18);
}

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

.stat-card {
  color: white;
  display: grid;
  gap: 12px;
  min-height: 150px;
  align-content: center;
}

.stat-label {
  font-size: 0.92rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  opacity: 0.78;
}

.stat-card strong {
  font-size: clamp(2rem, 3vw, 3rem);
}

.stat-black {
  background: linear-gradient(145deg, #252a31, var(--black-card));
}

.stat-green {
  background: linear-gradient(145deg, #1b8b59, var(--green-card));
}

.stat-red {
  background: linear-gradient(145deg, #c44539, var(--red-card));
}

.stat-gray {
  background: linear-gradient(145deg, #7a828b, var(--gray-card));
}

.detail-list {
  display: grid;
  gap: 12px;
}

.detail-list div {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.34);
}

body[data-theme="dark"] .detail-list div {
  background: rgba(255, 255, 255, 0.03);
}

.toast {
  min-height: 24px;
  color: var(--text-soft);
  text-align: right;
  font-size: 0.94rem;
}

.toast.success {
  color: var(--success);
}

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

.modal.hidden {
  display: none;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
}

.modal-mask {
  position: absolute;
  inset: 0;
  background: rgba(7, 12, 18, 0.42);
}

.modal-dialog {
  position: relative;
  width: min(1000px, calc(100vw - 32px));
  margin: 5vh auto;
  height: min(84vh, 860px);
  border-radius: var(--radius-xl);
  padding: 20px;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 16px;
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
}

.log-output {
  margin: 0;
  padding: 18px;
  border-radius: var(--radius-lg);
  background: #0b1116;
  color: #d6e3ee;
  overflow: auto;
  font-size: 0.9rem;
  line-height: 1.65;
}

body[data-theme="dark"] .log-output {
  background: #090d12;
}

@media (max-width: 1200px) {
  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 960px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    gap: 18px;
  }

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

  .menu-button {
    text-align: center;
  }

  .menu-button.active {
    transform: none;
  }

  .two-columns,
  .form-grid,
  .stats-grid {
    grid-template-columns: 1fr;
  }

  .topbar,
  .page-head,
  .panel-head,
  .cfmail-head,
  .modal-head {
    flex-direction: column;
    align-items: stretch;
  }

  .page-actions,
  .panel-actions,
  .cfmail-actions {
    flex-wrap: wrap;
  }
}
