:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --ink: #111827;
  --ink-2: #374151;
  --muted: #6b7280;
  --line: #e5e7eb;
  --line-strong: #d1d5db;
  --brand: #2563eb;
  --brand-hover: #1d4ed8;
  --brand-soft: #eff4ff;
  --ok: #15803d;
  --ok-soft: #e8f7ee;
  --warn: #b45309;
  --warn-soft: #fff5e6;
  --bad: #b91c1c;
  --bad-soft: #fdecec;
  --radius: 10px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .05);
  --shadow-md: 0 8px 24px rgba(16, 24, 40, .08);
  --focus: 0 0 0 3px rgba(37, 99, 235, .18);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}

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

.layout { display: flex; min-height: 100vh; }

/* ---------- Sidebar ---------- */

.sidebar {
  width: 216px;
  flex: 0 0 216px;
  background: #0f172a;
  color: #cbd5e1;
  padding: 22px 12px;
  display: flex;
  flex-direction: column;
  gap: 22px;
  /* Keep the menu in place while a long page scrolls. */
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand {
  color: #fff;
  font-weight: 700;
  font-size: 17px;
  letter-spacing: .3px;
  padding: 0 10px;
  display: flex;
  align-items: center;
}
.brand::before {
  content: "R";
  margin-right: 10px;
  display: inline-grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 7px;
  background: linear-gradient(135deg, #3b82f6, #2563eb);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
}
.brand span { color: #60a5fa; }

.sidebar nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar nav a {
  color: #cbd5e1;
  padding: 8px 12px;
  border-radius: 8px;
  font-weight: 500;
  transition: background-color .15s, color .15s;
}
.sidebar nav a:hover { background: #1e293b; text-decoration: none; color: #fff; }
.sidebar nav a.active { background: #1e293b; color: #fff; box-shadow: inset 3px 0 0 var(--brand); }

.sidebar-foot {
  margin-top: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 10px 0;
  border-top: 1px solid #1e293b;
  font-size: 13px;
}
.sidebar-foot a { color: #94a3b8; }
.sidebar-foot a:hover { color: #fff; }
.sidebar-foot form { margin: 0; }
.link { background: none; border: 0; color: #94a3b8; cursor: pointer; font-size: 13px; padding: 0; font-family: inherit; }
.link:hover { color: #fff; text-decoration: underline; }

/* ---------- Layout & typography ---------- */

.main { flex: 1; padding: 30px 36px 64px; max-width: 1180px; margin: 0 auto; min-width: 0; }

h1 { font-size: 22px; font-weight: 650; letter-spacing: -.01em; margin: 0 0 18px; }
h2 { font-size: 15px; font-weight: 600; color: var(--ink-2); margin: 28px 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.text-bad { color: var(--bad); }
.num { font-variant-numeric: tabular-nums; }

/* ---------- Cards ---------- */

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 8px; }
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow-sm);
}
.card .label { color: var(--muted); font-size: 12.5px; font-weight: 500; }
.card .value { font-size: 26px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.card .value small { font-size: 13px; font-weight: 500; color: var(--muted); }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow-sm);
}
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }

/* ---------- Tables ---------- */

.table-wrap {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow-x: auto;
}
table { width: 100%; border-collapse: collapse; background: var(--panel); }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
tbody tr:last-child > * { border-bottom: 0; }
th {
  font-size: 12.5px;
  color: var(--muted);
  font-weight: 600;
  white-space: nowrap;
  background: #f9fafb;
  border-bottom: 1px solid var(--line);
}
tbody tr { transition: background-color .12s; }
tbody tr:hover { background: #f9fafb; }
td.wrap { word-break: break-all; }
td.muted:only-child { text-align: center; padding: 22px 14px; }
td.edit-cell { background: #fafbfc; padding: 16px 18px; }

/* ---------- Badges ---------- */

.badge {
  display: inline-block;
  padding: 1px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  line-height: 20px;
  white-space: nowrap;
}
.badge.sent { background: var(--ok-soft); color: var(--ok); }
.badge.pending { background: var(--warn-soft); color: var(--warn); }
.badge.ready { background: var(--brand-soft); color: var(--brand); }
.badge.failed { background: var(--bad-soft); color: var(--bad); }
.badge.running { background: var(--brand-soft); color: var(--brand); }
.badge.success { background: var(--ok-soft); color: var(--ok); }

/* ---------- Buttons ---------- */

.btn {
  display: inline-block;
  border: 1px solid var(--line-strong);
  background: #fff;
  color: var(--ink);
  padding: 7px 14px;
  border-radius: 8px;
  font-size: 13.5px;
  font-weight: 500;
  line-height: 1.3;
  cursor: pointer;
  font-family: inherit;
  box-shadow: var(--shadow-sm);
  transition: background-color .15s, border-color .15s, color .15s, box-shadow .15s;
}
.btn:hover { background: #f3f4f6; text-decoration: none; }
.btn:focus-visible { outline: none; box-shadow: var(--focus); }
.btn:active { background: #e5e7eb; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; box-shadow: 0 1px 2px rgba(37, 99, 235, .25); }
.btn.primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); }
.btn.primary:active { background: #1e40af; }
.btn.danger { color: var(--bad); border-color: #f3c6c6; }
.btn.danger:hover { background: var(--bad-soft); }
.btn.tiny { padding: 3px 9px; font-size: 12.5px; border-radius: 6px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; box-shadow: none; }

form.inline { display: inline; margin: 0; }

/* ---------- Forms ---------- */

label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; font-weight: 500; }
input[type=text], input[type=password], input[type=number], input[type=time], input[type=email], select, textarea {
  width: 100%;
  min-height: 36px;
  padding: 7px 11px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  font: inherit;
  background: #fff;
  color: var(--ink);
  box-shadow: var(--shadow-sm);
  transition: border-color .15s, box-shadow .15s;
}
input[type=text]:hover, input[type=password]:hover, input[type=number]:hover, input[type=time]:hover,
input[type=email]:hover, select:hover, textarea:hover { border-color: #9ca3af; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: var(--focus); }
textarea { min-height: 74px; resize: vertical; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.field { margin-bottom: 14px; }
.time-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 8px; }
.time-row { display: flex; align-items: center; gap: 8px; }
.time-row input { max-width: 160px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 13.5px; color: var(--ink); cursor: pointer; }
.check input { width: auto; min-height: 0; accent-color: var(--brand); }

details.panel > summary { cursor: pointer; font-weight: 600; color: var(--ink-2); list-style-position: inside; }
details.panel > summary:hover { color: var(--brand); }

/* ---------- Flash & log ---------- */

.flash {
  padding: 10px 14px;
  border-radius: 8px;
  margin-bottom: 16px;
  font-size: 13.5px;
  border-left: 3px solid currentColor;
}
.flash.ok { background: var(--ok-soft); color: var(--ok); }
.flash.bad { background: var(--bad-soft); color: var(--bad); }

.log {
  background: #0f172a;
  color: #cbd5e1;
  border: 1px solid #1e293b;
  border-radius: var(--radius);
  padding: 14px 16px;
  font: 12.5px/1.65 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  max-height: 520px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}
.log .warn { color: #fbbf24; }
.log .error { color: #f87171; }

/* ---------- Login ---------- */

.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(900px 500px at 15% -10%, #dbe7ff 0%, transparent 60%),
    radial-gradient(700px 480px at 110% 110%, #e0e7ff 0%, transparent 60%),
    var(--bg);
}
.login-card {
  width: 360px;
  max-width: 100%;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 30px 30px 28px;
  box-shadow: var(--shadow-md);
}
.login-card h1 { margin-bottom: 24px; }
.login-card .muted { margin-bottom: 20px; }

/* ---------- Tabs & pagination ---------- */

.pagination { display: flex; gap: 8px; align-items: center; margin-top: 14px; }
.tabs { display: flex; gap: 6px; margin-bottom: 14px; flex-wrap: wrap; }
.tabs a {
  padding: 5px 12px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: #fff;
  color: var(--ink-2);
  font-size: 13px;
  font-weight: 500;
  transition: background-color .15s, border-color .15s, color .15s;
}
.tabs a:hover { border-color: #9ca3af; text-decoration: none; color: var(--ink); }
.tabs a.active { background: var(--brand); border-color: var(--brand); color: #fff; }

.kv { display: grid; grid-template-columns: 130px 1fr; gap: 9px 16px; font-size: 13.5px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

.narrow { max-width: 460px; margin: 0 auto; }
.narrow h1 { text-align: center; }

/* Narrow pages sit at the horizontal centre of the window, not of the
   content column: with a 216px sidebar the column centre is 108px to the
   right, which reads as "still not centred". */
@media (min-width: 861px) {
  .narrow {
    margin-left: calc(50% - 108px - 232px);
    margin-right: auto;
    min-height: calc(100vh - 90px);
    display: flex;
    flex-direction: column;
    justify-content: center;
  }
}

.summary {
  background: #fbfbfc;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  white-space: pre-wrap;
}

/* ---------- Small screens ---------- */

@media (max-width: 860px) {
  .layout { flex-direction: column; }
  .sidebar {
    width: auto;
    flex: none;
    flex-direction: row;
    align-items: center;
    gap: 14px;
    padding: 10px 14px;
    overflow-x: auto;
    position: static;
    height: auto;
    overflow-y: visible;
  }
  .brand { font-size: 15px; padding: 0 4px; flex: none; }
  .sidebar nav { flex-direction: row; }
  .sidebar nav a { white-space: nowrap; }
  .sidebar nav a.active { box-shadow: inset 0 -2px 0 var(--brand); border-radius: 8px 8px 0 0; }
  .sidebar-foot { margin: 0; padding: 0; border-top: 0; flex: none; gap: 10px; }
  .main { padding: 18px 16px 48px; }
  .grid2, .grid3 { grid-template-columns: 1fr; }
}
