:root {
  --primary-color: #10a37f;
  --primary-hover: #0d8a6a;
  --primary-light: rgba(16, 163, 127, 0.1);
  --danger-color: #ef4444;
  --warning-color: #f59e0b;
  --success-color: #22c55e;
  --info-color: #3b82f6;
  --background: #f8fafc;
  --surface: #ffffff;
  --surface-hover: #f1f5f9;
  --border: #e2e8f0;
  --text-primary: #1e293b;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.07);
  --transition: 200ms ease;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Microsoft YaHei UI', sans-serif;
  font-size: 14px;
  color: var(--text-primary);
  background: var(--background);
  line-height: 1.5;
}

code, pre, .stat-value, .console-log, .field-card__name {
  font-family: 'Cascadia Code', 'Consolas', 'Monaco', monospace;
}

/* ── Navbar ── */
.navbar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 24px;
  height: 52px;
  padding: 0 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

.nav-brand {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  white-space: nowrap;
}

.nav-links {
  display: flex;
  gap: 4px;
}

.nav-link {
  padding: 6px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  text-decoration: none;
  cursor: pointer;
  transition: var(--transition);
}

.nav-link:hover { background: var(--surface-hover); color: var(--text-primary); }
.nav-link.active { background: var(--primary-light); color: var(--primary-color); }

.nav-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

.nav-clock {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: #f8fafc;
  white-space: nowrap;
}

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

.nav-clock__value {
  font-family: 'Cascadia Code', 'Consolas', 'Monaco', monospace;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-primary);
}

/* ── Main ── */
.main-content { padding: 20px 24px; max-width: 1400px; margin: 0 auto; }

body.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(circle at top left, rgba(16, 163, 127, 0.18), transparent 36%),
    linear-gradient(160deg, #f8fafc 0%, #eef6f3 55%, #e7f3ff 100%);
}

.page { display: none; }
.page--active { display: block; }

.auth-shell {
  width: min(100%, 440px);
}

.auth-card {
  overflow: hidden;
  border: 1px solid rgba(148, 163, 184, 0.28);
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 24px 80px rgba(15, 23, 42, 0.12);
}

.auth-card__header {
  padding: 28px 28px 18px;
  border-bottom: 1px solid rgba(226, 232, 240, 0.9);
  background: linear-gradient(145deg, rgba(16, 163, 127, 0.12), rgba(59, 130, 246, 0.08));
}

.auth-card__eyebrow {
  margin: 0 0 8px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--primary-color);
}

.auth-card__header h1 {
  margin: 0 0 8px;
  font-size: 28px;
  line-height: 1.1;
}

.auth-card__subtext {
  margin: 0;
  color: var(--text-secondary);
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 22px 28px 28px;
}

.auth-message {
  min-height: 18px;
  font-size: 12px;
  color: var(--text-secondary);
}

.auth-message.error {
  color: #dc2626;
}

.auth-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.auth-default-tip {
  font-size: 12px;
  color: var(--text-muted);
}

/* ── Stat cards ── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  border-top: 3px solid var(--border);
  transition: var(--transition);
}

.stat-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.stat-card.success { border-top-color: var(--success-color); }
.stat-card.warning { border-top-color: var(--warning-color); }
.stat-card.danger  { border-top-color: var(--danger-color); }
.stat-card.info    { border-top-color: var(--info-color); }

.stat-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.stat-value {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
}

/* ── Cards ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  margin-bottom: 16px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}

.card-header h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
}

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

.card-body { padding: 18px; }

.security-card {
  margin-bottom: 16px;
}

.security-panel {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  flex-wrap: wrap;
}

.security-panel__intro {
  flex: 1 1 260px;
  max-width: 480px;
}

.security-panel__intro p {
  margin: 0 0 10px;
  color: var(--text-secondary);
}

.security-note {
  margin: 0;
  color: var(--text-muted);
}

.password-form {
  flex: 1 1 540px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.password-form__grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.password-form__actions {
  display: flex;
  justify-content: flex-end;
}

/* ── Tabs ── */
.tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.tab-btn {
  padding: 6px 14px;
  border: none;
  border-radius: var(--radius);
  background: transparent;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  transition: var(--transition);
}

.tab-btn:hover { background: var(--surface-hover); }
.tab-btn.active { background: var(--primary-light); color: var(--primary-color); }

.tab-btn.has-dirty::after {
  content: '';
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--danger-color);
  margin-left: 6px;
  vertical-align: middle;
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}

.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-sm { padding: 5px 12px; font-size: 12px; }

.btn-primary { background: var(--primary-color); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }

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

.btn-success { background: var(--success-color); color: #fff; }
.btn-success:hover:not(:disabled) { background: #16a34a; }

.btn-danger { background: var(--danger-color); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #dc2626; }

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

.btn-group-vertical { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }

/* ── Status badges ── */
.status-badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}

.status-badge.active, .status-badge.running { background: rgba(34,197,94,0.1); color: #16a34a; }
.status-badge.failed, .status-badge.error   { background: rgba(239,68,68,0.1); color: #dc2626; }
.status-badge.pending, .status-badge.waiting { background: rgba(59,130,246,0.1); color: #2563eb; }
.status-badge.expired, .status-badge.warning { background: rgba(245,158,11,0.1); color: #d97706; }
.status-badge.disabled, .status-badge.idle   { background: #f1f5f9; color: #64748b; }

/* ── Forms ── */
.form-group {
  margin-bottom: 0;
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.form-group input,
.form-group select {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  color: var(--text-primary);
  background: var(--surface);
  transition: var(--transition);
}

.form-group input:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px var(--primary-light);
}

.form-group small {
  display: block;
  margin-top: 2px;
  font-size: 11px;
  color: var(--text-muted);
}

.form-group .switch-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 0;
}

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
}

/* ── Config group ── */
.config-group { margin-bottom: 0; }
.config-group[hidden] { display: none !important; }
.config-group.is-active { animation: fadeIn 0.2s ease; }

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

.config-group__header h3 {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
}

.config-group__note {
  margin: 4px 0 0;
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.5;
  max-width: 760px;
}

.config-group__actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

/* ── Field card (inside form-row grid) ── */
.field-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  transition: var(--transition);
}

.field-card:hover { border-color: #cbd5e1; }
.field-card.is-dirty { border-left: 3px solid var(--danger-color); }
.field-card--span-2 { grid-column: span 2; }

.field-card__header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 8px;
}

.field-card__label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}

.field-card__name {
  font-size: 11px;
  color: var(--text-muted);
  margin: 2px 0 0;
}

.field-card__control {
  display: flex;
  gap: 8px;
  align-items: center;
}

.field-card__control input,
.field-card__control select,
.field-card__control textarea {
  width: 100%;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  color: var(--text-primary);
  background: var(--surface);
  transition: var(--transition);
}

.field-card__control input:focus,
.field-card__control select:focus,
.field-card__control textarea:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px var(--primary-light);
}

.field-card__control textarea {
  min-height: 112px;
  resize: vertical;
  line-height: 1.5;
  font-family: 'Cascadia Code', 'Consolas', 'Monaco', monospace;
}

.option-list {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 8px;
}

.option-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #f8fafc;
  cursor: pointer;
}

.option-chip input {
  width: auto;
  margin: 0;
  flex-shrink: 0;
}

.option-chip span {
  font-size: 13px;
  color: var(--text-primary);
}

.field-card__help {
  margin: 6px 0 0;
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.4;
}

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

/* ── Switch ── */
.switch {
  position: relative;
  display: inline-flex;
  width: 40px;
  height: 22px;
  flex-shrink: 0;
}

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

.switch__slider {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: #cbd5e1;
  transition: var(--transition);
  cursor: pointer;
}

.switch__slider::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 999px;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0,0,0,0.15);
  transition: var(--transition);
}

.switch input:checked + .switch__slider { background: var(--primary-color); }
.switch input:checked + .switch__slider::after { transform: translateX(18px); }

.switch-line {
  display: flex;
  align-items: center;
  gap: 10px;
}

.switch-line--field {
  width: 100%;
  justify-content: space-between;
}

.switch-line__label {
  font-size: 12px;
  color: var(--text-secondary);
}

/* ── Two column layout ── */
.two-column-layout {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.column-left, .column-right { min-width: 0; }

.runtime-info { margin-top: 16px; }

.info-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

.info-row:last-child { border-bottom: none; }
.info-row span { color: var(--text-muted); }
.info-row strong { color: var(--text-primary); }

/* ── Log toolbar ── */
.log-toolbar {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.log-toolbar select,
.log-toolbar input {
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 12px;
  background: var(--surface);
  color: var(--text-primary);
}

.log-toolbar input {
  flex: 1;
  min-width: 120px;
}

.log-toolbar select:focus,
.log-toolbar input:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 2px var(--primary-light);
}

.checkbox-inline {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
}

/* ── Console log ── */
.console-log {
  background: #1a1b26;
  border-radius: var(--radius);
  padding: 12px;
  min-height: 300px;
  max-height: calc(100vh - 340px);
  overflow: auto;
  font-size: 12px;
  line-height: 1.6;
}

.log-line, .log-entry {
  padding: 2px 0;
  color: #a9b1d6;
}

.log-entry {
  display: grid;
  grid-template-columns: auto auto 1fr;
  gap: 8px;
  padding: 3px 0;
  border-bottom: 1px solid rgba(255,255,255,0.04);
}

.log-entry:last-child { border-bottom: none; }

.log-entry__ts {
  color: #565f89;
  font-size: 11px;
  white-space: nowrap;
}

.log-entry__level {
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 3px;
  text-align: center;
  min-width: 48px;
  background: rgba(148,163,184,0.12);
  color: #a9b1d6;
}

.log-entry--success .log-entry__level { background: rgba(34,197,94,0.15); color: #73daca; }
.log-entry--warn .log-entry__level    { background: rgba(245,158,11,0.15); color: #e0af68; }
.log-entry--error .log-entry__level   { background: rgba(239,68,68,0.15); color: #f7768e; }

.log-entry__message {
  color: #c0caf5;
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0;
}

.log-empty {
  min-height: 200px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #565f89;
}

/* ── Toast ── */
.toast-container {
  position: fixed;
  top: 60px;
  right: 16px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.toast {
  padding: 10px 16px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-primary);
  font-size: 13px;
  box-shadow: var(--shadow-md);
  animation: slideIn 0.2s ease;
}

.toast--success { border-left: 3px solid var(--success-color); }
.toast--error   { border-left: 3px solid var(--danger-color); }
.toast--info    { border-left: 3px solid var(--info-color); }

.toast--leaving {
  opacity: 0;
  transform: translateX(20px);
  transition: all 0.2s ease;
}

/* ── Tiny btn ── */
.tiny-btn {
  padding: 3px 8px;
  font-size: 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-hover);
  color: var(--text-secondary);
  cursor: pointer;
}

.tiny-btn:hover { background: #e2e8f0; }

/* ── Misc ── */
.flash-mark { animation: flashMark 0.5s ease; }

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

/* ── Schedule page ── */
.scheduler-status-grid {
  grid-template-columns: repeat(3, 1fr);
}

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

.schedule-slots-header h4 {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
}

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

.schedule-monitor-layout {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.schedule-slot-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  transition: var(--transition);
}

.schedule-slot-card:hover {
  border-color: #cbd5e1;
  box-shadow: var(--shadow-sm);
}

.slot-main {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr auto auto;
  gap: 12px;
  align-items: end;
}

.slot-field label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.slot-field input[type="time"],
.slot-field input[type="number"] {
  width: 100%;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  background: var(--surface);
  color: var(--text-primary);
  transition: var(--transition);
}

.slot-field input:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px var(--primary-light);
}

.slot-field--toggle {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.slot-field--action {
  display: flex;
  align-items: flex-end;
}

.slot-summary {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

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

.schedule-run-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 240px;
  max-height: 620px;
  overflow: auto;
}

.schedule-run-item {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 12px;
  text-align: left;
  cursor: pointer;
  transition: var(--transition);
}

.schedule-run-item:hover {
  border-color: #cbd5e1;
  box-shadow: var(--shadow-sm);
}

.schedule-run-item.is-active {
  border-color: rgba(16, 163, 127, 0.4);
  background: linear-gradient(180deg, rgba(16, 163, 127, 0.08), rgba(16, 163, 127, 0.03));
  box-shadow: 0 0 0 1px rgba(16, 163, 127, 0.16);
}

.schedule-run-item__header,
.schedule-run-item__meta,
.schedule-run-item__sub {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.schedule-run-item__header {
  margin-bottom: 6px;
}

.schedule-run-item__title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-primary);
}

.schedule-run-item__meta {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.schedule-run-item__sub {
  font-size: 11px;
  color: var(--text-muted);
}

.schedule-log-meta {
  margin-bottom: 12px;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes slideIn {
  from { opacity: 0; transform: translateX(100%); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes flashMark {
  from { box-shadow: 0 0 0 2px var(--primary-light); }
  to { box-shadow: none; }
}

/* ── Responsive ── */
@media (max-width: 1024px) {
  .field-grid { grid-template-columns: 1fr; }
  .field-card--span-2 { grid-column: span 1; }
  .two-column-layout { grid-template-columns: 1fr; }
  .slot-main { grid-template-columns: 1fr 1fr 1fr auto auto; }
  .schedule-monitor-layout { grid-template-columns: 1fr; }
  .password-form__grid { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
  .navbar { padding: 0 16px; gap: 12px; }
  .main-content { padding: 12px 16px; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .form-row { grid-template-columns: 1fr; }
  .scheduler-status-grid { grid-template-columns: 1fr; }
  .slot-main { grid-template-columns: 1fr 1fr; }
  .security-panel { flex-direction: column; }
  .password-form { width: 100%; }
  .auth-card__header { padding: 22px 22px 16px; }
  .auth-form { padding: 18px 22px 22px; }
  .schedule-run-item__meta,
  .schedule-run-item__sub { flex-direction: column; align-items: flex-start; }
}

@media (max-width: 480px) {
  .stat-grid { grid-template-columns: 1fr; }
  .card-header { flex-direction: column; align-items: flex-start; }
  .card-actions { width: 100%; }
  .auth-actions { flex-direction: column; align-items: flex-start; }
}
