:root {
  --bg: #f4f6fb;
  --panel: #ffffff;
  --text: #1e293b;
  --muted: #64748b;
  --border: #e2e8f0;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --ok: #15803d;
  --bad: #b91c1c;
  --warn: #b45309;
  --info: #1d4ed8;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.04),
    0 10px 30px rgba(15, 23, 42, 0.06);
  --radius: 14px;
  --control-h: 40px;
  --container: 1180px;
  --gutter: 22px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(1000px 500px at 10% -10%, #e0e7ff 0, transparent 55%),
    radial-gradient(900px 500px at 100% 0, #dbeafe 0, transparent 50%),
    var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.65;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

p { margin: 0 0 12px; }
p:last-child { margin-bottom: 0; }

/* ---------- top bar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: linear-gradient(90deg, #0f172a, #1e293b);
  color: #e2e8f0;
  box-shadow: 0 6px 20px rgba(15, 23, 42, 0.16);
}

.topbar-inner {
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
  max-width: var(--container);
  margin: 0 auto;
  padding: 10px var(--gutter);
}

.topbar .brand {
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.2px;
  white-space: nowrap;
}
.topbar .brand:hover { text-decoration: none; }

.topbar nav {
  display: flex;
  align-items: center;
  flex: 1;
  min-width: 0;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: none;
}
.topbar nav::-webkit-scrollbar { display: none; }
.topbar nav a {
  display: inline-flex;
  align-items: center;
  height: 34px;
  padding: 0 12px;
  border-radius: 8px;
  color: #cbd5e1;
  white-space: nowrap;
}
.topbar nav a:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  text-decoration: none;
}
.topbar nav a.active {
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
}

.logout { display: flex; align-items: center; margin-left: auto; }
.link-button {
  min-height: auto;
  padding: 6px 8px;
  border: 0;
  background: none;
  color: #cbd5e1;
  font-size: 14px;
  cursor: pointer;
}
.link-button:hover { color: #fff; }

/* ---------- layout ---------- */

.container {
  max-width: var(--container);
  margin: 28px auto 64px;
  padding: 0 var(--gutter);
}

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 22px;
}
.page-head h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.25;
  letter-spacing: -0.2px;
}
.page-sub {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
}
.page-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.page-actions + h2 { margin-top: 20px; }
.button-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: #fff;
  color: var(--text);
  font-size: 13px;
}
.button-link:hover {
  border-color: #c7d2fe;
  color: var(--primary);
  text-decoration: none;
}

h1 { font-size: 24px; margin: 0 0 18px; }
h2 { font-size: 16px; margin: 0 0 14px; }

/* ---------- cards and panels ---------- */

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  align-items: stretch;
  margin-bottom: 20px;
}

.card,
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  box-shadow: var(--shadow);
}

.stat-card { position: relative; overflow: hidden; }
.stat-card::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 4px;
  background: linear-gradient(180deg, #6366f1, #2563eb);
}
.card-label { color: var(--muted); font-size: 13px; }
.card-value {
  margin-top: 6px;
  font-size: 30px;
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: -0.5px;
}
.card-limit {
  margin-left: 6px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 500;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  gap: 18px;
  align-items: stretch;
  margin-bottom: 18px;
}
.grid-2 > .panel { margin-bottom: 0; }

.panel { margin-bottom: 18px; }
.panel > h2 {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 0 0 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
  font-size: 16px;
}
.divider { height: 1px; background: var(--border); margin: 16px 0; }

.status-list {
  display: grid;
  grid-template-columns: 128px 1fr;
  gap: 10px 14px;
  margin: 0;
}
.status-list dt {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}
.status-list dd {
  margin: 0;
  min-width: 0;
  word-break: break-word;
}

/* ---------- badges and flash ---------- */

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 9px;
  border-radius: 999px;
  background: #eef2f7;
  color: #475569;
  font-size: 12px;
  font-weight: 500;
  vertical-align: middle;
}
.badge.ok, .badge.success { background: #dcfce7; color: var(--ok); }
.badge.bad, .badge.failed { background: #fee2e2; color: var(--bad); }
.badge.running { background: #dbeafe; color: var(--info); }
.badge.interrupted { background: #fef3c7; color: var(--warn); }

.flash {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 11px 14px;
  border: 1px solid transparent;
  border-radius: 10px;
  margin-bottom: 14px;
  font-size: 13px;
}
.flash form { margin-left: auto; }
.flash.success { background: #f0fdf4; border-color: #bbf7d0; color: var(--ok); }
.flash.error { background: #fef2f2; border-color: #fecaca; color: var(--bad); }
.flash.info { background: #eff6ff; border-color: #bfdbfe; color: var(--info); }
.flash.warn { background: #fffbeb; border-color: #fde68a; color: var(--warn); }

/* ---------- forms ---------- */

label {
  display: block;
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 13px;
}

input[type="text"], input[type="password"], input[type="number"],
input[type="url"], input[type="time"], select {
  display: block;
  width: 100%;
  height: var(--control-h);
  margin-top: 6px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: #fff;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
}
textarea {
  display: block;
  width: 100%;
  min-height: 120px;
  margin-top: 6px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: #fff;
  color: var(--text);
  font-size: 13px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  line-height: 1.6;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: #93c5fd;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.field-hint {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  align-items: start;
  margin-bottom: 16px;
}
.form-grid > label { margin-bottom: 0; }

.form-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 4px;
}
.form-actions > .muted { flex: 1 1 auto; }
.form-actions > .checkbox { margin: 0; }

.checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 10px;
  color: var(--text);
}
.checkbox input { width: auto; margin: 0; }

.inline-form {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  flex-wrap: wrap;
}
.inline-form > label {
  flex: 1 1 180px;
  min-width: 160px;
  margin-bottom: 0;
}
.inline-form > button { flex: 0 0 auto; margin-top: 22px; }
.inline-form > .checkbox {
  flex: 0 0 auto;
  margin: 10px 0 0;
}

/* ---------- buttons ---------- */

button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--control-h);
  padding: 0 16px;
  border: 0;
  border-radius: 9px;
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s, box-shadow 0.15s;
}
button.primary { background: var(--primary); color: #fff; }
button.primary:hover { background: var(--primary-dark); }
button.danger { background: #dc2626; color: #fff; }
button.danger:hover { background: #b91c1c; }
button.small {
  min-height: 30px;
  padding: 0 11px;
  font-size: 12px;
  border-radius: 7px;
}

/* ---------- tables ---------- */

.table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
}
table {
  width: 100%;
  min-width: 640px;
  border-collapse: collapse;
}
th, td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
}
th {
  background: #f8fafc;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
td { font-size: 13px; }
tbody tr:nth-child(even) { background: #fbfcfe; }
tbody tr:hover { background: #f1f5f9; }
tbody tr:last-child td { border-bottom: 0; }
.check-col { width: 36px; text-align: center; }
.check-col input { width: auto; margin: 0; }
td code { word-break: break-all; }

.bulk-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #f8fafc;
}
.bulk-bar .checkbox { margin: 0; }

.inline-action { display: inline; margin: 0; }

.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px dashed var(--border);
  color: var(--muted);
  font-size: 13px;
}
.pager-links { display: flex; align-items: center; gap: 10px; }
.pager-links .disabled { color: #c0c4cc; }
.pager-size { margin: 0; }
.pager-size label {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  color: var(--muted);
}
.pager-size select {
  width: auto;
  height: 32px;
  margin: 0;
  padding: 0 8px;
}

/* ---------- misc ---------- */

code {
  padding: 1px 6px;
  border-radius: 5px;
  background: #f1f5f9;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px;
  word-break: break-all;
}
.muted { color: var(--muted); }

.log {
  min-height: 220px;
  max-height: 62vh;
  overflow: auto;
  margin: 0;
  padding: 14px 16px;
  border-radius: 12px;
  background: #0b1220;
  color: #dbeafe;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

.auth-card {
  max-width: 380px;
  margin: 8vh auto 0;
  padding: 30px 30px 22px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--panel);
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.12);
}
.auth-card h1 { margin-bottom: 6px; font-size: 22px; }
.auth-card .muted { margin-top: 0; }
.auth-card button { width: 100%; margin-top: 6px; }

details.panel > summary {
  display: block;
  cursor: pointer;
  font-weight: 600;
  margin-bottom: 12px;
}
details.panel[open] > summary { margin-bottom: 16px; }

details.hint {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
details.hint summary {
  cursor: pointer;
  color: var(--primary);
  font-size: 13px;
}
details.hint ol {
  margin: 8px 0 0 18px;
  padding: 0;
  font-size: 13px;
  line-height: 1.8;
}

.small-link { margin-left: 8px; font-size: 12px; font-weight: 400; }

.empty-state {
  padding: 28px 16px;
  border: 1px dashed var(--border);
  border-radius: 10px;
  background: #f8fafc;
  color: var(--muted);
  text-align: center;
}

.site-footer {
  max-width: var(--container);
  margin: 0 auto;
  padding: 0 var(--gutter) 30px;
  color: #94a3b8;
  font-size: 12px;
  text-align: center;
}

@media (max-width: 720px) {
  .topbar-inner { gap: 10px; padding: 10px 14px; }
  .topbar nav { order: 3; width: 100%; }
  .logout { margin-left: auto; }
  .container { margin-top: 18px; padding: 0 14px; }
  .page-head h1 { font-size: 20px; }
  .card-value { font-size: 24px; }
  .status-list { grid-template-columns: 1fr; }
  .grid-2 { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .panel, .card { padding: 16px; }
}
