:root {
  --bg-1: #f4f8ff;
  --bg-2: #f7fbf4;
  --card: rgba(255, 255, 255, 0.75);
  --line: rgba(12, 36, 59, 0.12);
  --text: #0f2033;
  --muted: #5d6f80;
  --brand: #0e7a8a;
  --brand-2: #f76a3d;
  --danger: #c43833;
  --success: #11845f;
  --warning: #bb7a17;
  --shadow: 0 12px 30px rgba(16, 29, 40, 0.1);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: "Poppins", "Noto Sans SC", "Microsoft YaHei", sans-serif;
  color: var(--text);
  background: linear-gradient(120deg, var(--bg-1) 0%, var(--bg-2) 100%);
}

.bg-layer {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(circle at 5% 10%, rgba(14, 122, 138, 0.2), transparent 35%),
    radial-gradient(circle at 90% 0%, rgba(247, 106, 61, 0.14), transparent 34%),
    radial-gradient(circle at 100% 70%, rgba(16, 114, 187, 0.08), transparent 35%);
  z-index: -1;
}

.layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 22px;
  padding: 20px;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  backdrop-filter: blur(10px);
  border-radius: 18px;
  box-shadow: var(--shadow);
}

.sidebar {
  padding: 18px;
  position: sticky;
  top: 20px;
  height: calc(100dvh - 40px);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.brand-block h1 {
  margin: 0;
  font-size: 1.5rem;
}

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

.brand-logo {
  width: 30px;
  height: 30px;
  flex: 0 0 auto;
}

.brand-block p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.auth-user {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  background: rgba(255, 255, 255, 0.8);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.auth-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.auth-user-label {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
}

#currentUser {
  display: block;
  margin-top: 3px;
  font-size: 0.93rem;
}

#logoutBtn {
  display: none;
}

#changePasswordBtn {
  display: none;
}

.hook-head {
  margin-top: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 600;
  color: var(--muted);
}

.hook-list {
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-right: 2px;
}

.hook-item {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.8);
  border-radius: 12px;
  padding: 11px;
  cursor: pointer;
  transition: transform 0.2s ease, border-color 0.2s ease, background-color 0.2s ease;
}

.hook-item:hover {
  transform: translateY(-2px);
  border-color: rgba(14, 122, 138, 0.45);
}

.hook-item.active {
  border-color: rgba(14, 122, 138, 0.85);
  background: linear-gradient(120deg, rgba(14, 122, 138, 0.12), rgba(247, 106, 61, 0.08));
}

.hook-item h4 {
  margin: 0;
  font-size: 0.98rem;
  line-height: 1.3;
}

.hook-item p {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 0.8rem;
}

.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 2px 9px;
  font-size: 0.72rem;
  margin-top: 8px;
}

.badge-success {
  background: rgba(17, 132, 95, 0.14);
  color: var(--success);
}

.badge-failed {
  background: rgba(196, 56, 51, 0.14);
  color: var(--danger);
}

.badge-running {
  background: rgba(16, 114, 187, 0.15);
  color: #1a66a3;
}

.badge-idle {
  background: rgba(111, 125, 138, 0.14);
  color: #5e6e7c;
}

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

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

.stat {
  padding: 16px;
}

.stat span {
  display: block;
  color: var(--muted);
  font-size: 0.84rem;
}

.stat strong {
  display: block;
  margin-top: 8px;
  font-size: 1.8rem;
}

.editor,
.runs {
  padding: 18px;
}

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

.panel-header h2 {
  margin: 0;
  font-size: 1.15rem;
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

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

label {
  display: block;
  margin-top: 10px;
  font-size: 0.84rem;
  color: var(--muted);
}

.field-tip {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.4;
}

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

input,
select,
textarea {
  width: 100%;
  margin-top: 6px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.86);
  color: var(--text);
  padding: 10px;
}

textarea {
  resize: vertical;
  min-height: 210px;
  line-height: 1.45;
  font-family: "JetBrains Mono", "Consolas", monospace;
  font-size: 0.88rem;
}

.webhook-box {
  margin-top: 12px;
  border: 1px dashed rgba(14, 122, 138, 0.42);
  background: rgba(14, 122, 138, 0.06);
  border-radius: 12px;
  padding: 10px;
  display: grid;
  gap: 6px;
}

.webhook-box code {
  word-break: break-all;
  font-family: "JetBrains Mono", "Consolas", monospace;
}

.footer-row {
  margin-top: 14px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.hint {
  color: var(--muted);
  font-size: 0.84rem;
}

.btn {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.84);
  border-radius: 10px;
  padding: 8px 12px;
  cursor: pointer;
  transition: transform 0.15s ease, filter 0.15s ease;
}

.btn:hover {
  transform: translateY(-1px);
  filter: brightness(0.98);
}

.btn-primary {
  background: linear-gradient(120deg, var(--brand), #0f9ca4);
  border: none;
  color: #fff;
}

.btn-accent {
  background: linear-gradient(120deg, #f98d3f, var(--brand-2));
  border: none;
  color: #fff;
}

.btn-danger {
  background: linear-gradient(120deg, #d14d44, var(--danger));
  border: none;
  color: #fff;
}

.table-wrap {
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

th,
td {
  border-bottom: 1px solid var(--line);
  text-align: left;
  padding: 10px 6px;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 600;
}

.empty-row td {
  text-align: center;
  color: var(--muted);
}

#logDialog {
  width: min(920px, 94vw);
  border: none;
  border-radius: 16px;
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.25);
}

#logDialog::backdrop {
  background: rgba(0, 0, 0, 0.38);
}

#logDialog header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px;
  border-bottom: 1px solid var(--line);
}

#logDialog h3 {
  margin: 0;
}

#logContent {
  margin: 0;
  padding: 12px;
  max-height: 60dvh;
  overflow: auto;
  background: #0d2233;
  color: #d5e7f8;
  font-size: 0.85rem;
  line-height: 1.45;
  font-family: "JetBrains Mono", "Consolas", monospace;
}

#passwordDialog {
  width: min(520px, 94vw);
  border: none;
  border-radius: 16px;
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.25);
}

#passwordDialog::backdrop {
  background: rgba(0, 0, 0, 0.38);
}

#passwordDialog header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px;
  border-bottom: 1px solid var(--line);
}

#passwordDialog h3 {
  margin: 0;
}

.password-form {
  padding: 12px;
}

.password-actions {
  margin-top: 12px;
  display: flex;
  justify-content: flex-end;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  padding: 10px 14px;
  border-radius: 10px;
  background: rgba(15, 32, 51, 0.92);
  color: #fff;
  opacity: 0;
  transform: translateY(16px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.auth-gate {
  position: fixed;
  inset: 0;
  background:
    linear-gradient(130deg, rgba(9, 29, 44, 0.48), rgba(24, 35, 43, 0.46)),
    radial-gradient(circle at 0 0, rgba(14, 122, 138, 0.35), transparent 45%);
  backdrop-filter: blur(8px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 30;
}

.auth-gate.show {
  display: flex;
}

.auth-card {
  width: min(460px, 92vw);
  padding: 22px;
}

.auth-card h2 {
  margin: 0;
  font-size: 1.35rem;
}

.auth-card p {
  margin: 6px 0 0;
  color: var(--muted);
}

.auth-form {
  margin-top: 12px;
}

.auth-form .btn {
  margin-top: 12px;
  width: 100%;
}

@media (max-width: 1140px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: relative;
    top: 0;
    height: auto;
  }

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

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

@media (max-width: 680px) {
  .layout {
    padding: 12px;
    gap: 12px;
  }

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

  .panel-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .action-row {
    width: 100%;
  }

  .action-row .btn {
    flex: 1;
  }

  .auth-user {
    flex-direction: column;
    align-items: flex-start;
  }

  .auth-actions {
    width: 100%;
  }

  #changePasswordBtn,
  #logoutBtn {
    width: 100%;
  }
}
