:root {
  color-scheme: light dark;
  --bg: #f6f6f4;
  --surface: rgba(255, 255, 255, .86);
  --surface-solid: #fff;
  --surface-soft: rgba(238, 238, 234, .8);
  --text: #17191f;
  --muted: #6b7079;
  --line: rgba(23, 25, 31, .1);
  --line-strong: rgba(23, 25, 31, .18);
  --primary: #2d5be3;
  --primary-strong: #1f47bd;
  --primary-soft: #e7edfc;
  --danger: #b4423a;
  --danger-soft: #f9e8e6;
  --gold: #a16207;
  --gold-soft: #fbf1dc;
  --shadow: 0 24px 80px rgba(23, 25, 31, .08);
  --shadow-small: 0 12px 36px rgba(23, 25, 31, .06);
  --on-primary: #fff;
  --on-danger: #fff;
  --radius-xl: 24px;
  --radius-l: 16px;
  --radius-m: 10px;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }

html {
  min-height: 100%;
  background: var(--bg);
  scroll-behavior: smooth;
  scrollbar-gutter: stable;
}

body {
  min-width: 320px;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  color: var(--text);
  background: var(--bg);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

body.dialog-open { overflow: hidden; }

button, input, textarea, select { font: inherit; }
button, a, label { -webkit-tap-highlight-color: transparent; }
button { color: inherit; }
button:disabled { cursor: not-allowed; opacity: .48; }
a { color: inherit; }
img { max-width: 100%; }

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .76rem;
  overflow-wrap: anywhere;
}
h1, h2, h3 { margin-top: 0; }
h2 { margin-bottom: 0; font-size: 1.2rem; }
h3 { margin: 0; font-size: 1rem; }
p { margin-top: 0; }

.clipboard-proxy {
  position: fixed;
  top: 0;
  left: -10000px;
  width: 1px;
  height: 1px;
  opacity: 0;
}

/* ---------- brand and buttons ---------- */

.brand {
  display: inline-flex;
  align-items: center;
  gap: .55rem;
  font-size: 1.2rem;
  font-weight: 750;
  letter-spacing: .04em;
  text-decoration: none;
}
.brand-logo { width: 1.75rem; height: 1.35rem; }
.brand-tag {
  padding: .1rem .45rem;
  border-radius: 999px;
  color: var(--primary-strong);
  background: var(--primary-soft);
  font-size: .68rem;
  font-weight: 700;
  letter-spacing: .06em;
}
.brand-hero { font-size: clamp(2.2rem, 7vw, 3.2rem); gap: .9rem; }
.brand-hero .brand-logo { width: 3.4rem; height: 2.6rem; }

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  padding: .6rem 1rem;
  border: 1px solid transparent;
  border-radius: var(--radius-m);
  font-size: .88rem;
  font-weight: 650;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color .18s ease, border-color .18s ease, transform .18s ease;
}
.button:active:not(:disabled) { transform: translateY(1px); }
.button-primary { color: var(--on-primary); background: var(--primary); }
.button-primary:hover:not(:disabled) { background: var(--primary-strong); }
.button-secondary { border-color: var(--line-strong); background: var(--surface-soft); }
.button-secondary:hover:not(:disabled) { border-color: var(--primary); }
.button-quiet { background: transparent; }
.button-quiet:hover:not(:disabled) { background: var(--surface-soft); }
.button-danger { color: var(--on-danger); background: var(--danger); }
.button-danger:hover:not(:disabled) { filter: brightness(.94); }
.button-small { padding: .38rem .7rem; font-size: .8rem; }
.button-wide { width: 100%; }
.button-icon { width: 2.1rem; height: 2.1rem; padding: 0; font-size: 1.2rem; line-height: 1; }

:where(button, a, input, textarea, select):focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* ---------- public page ---------- */

.public .topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: .75rem;
  height: 2.6rem;
  padding: 0 clamp(.75rem, 3vw, 2rem);
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  backdrop-filter: blur(14px);
  transition: transform .25s ease;
}
/* Scrolling down slides the bar away so the list has the whole screen; scrolling up brings it back. */
.public .topbar.is-hidden { transform: translateY(-100%); }
.public .brand { font-size: .95rem; gap: .4rem; }
.public .brand-logo { width: 1.35rem; height: 1.05rem; }
.tabs {
  display: flex;
  gap: .15rem;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
/* Centred while there is room, scrollable from the first tab when there is not. */
.tabs > :first-child { margin-left: auto; }
.tabs > :last-child { margin-right: auto; }
.tab {
  padding: .3rem .7rem;
  border: 1px solid transparent;
  border-radius: 999px;
  color: var(--muted);
  background: transparent;
  font-size: .84rem;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  transition: color .18s ease, background-color .18s ease;
}
.tab:hover { color: var(--text); }
.tab[aria-current="true"] { color: var(--primary-strong); background: var(--primary-soft); }
.tools { display: flex; justify-content: flex-end; align-items: center; gap: .3rem; }
.tools .button-small { padding: .25rem .55rem; font-size: .76rem; }

.public .shell { max-width: 46rem; margin: 0 auto; padding: .75rem 1.25rem 3rem; }

.daybar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
  margin-bottom: .2rem;
}
.day-heading {
  display: flex;
  flex: 1;
  flex-wrap: wrap;
  justify-content: center;
  column-gap: .5rem;
  min-width: 0;
  font-size: .9rem;
  line-height: 1.5;
}
.day-heading h1 { margin: 0; font-size: inherit; font-weight: 700; letter-spacing: -.01em; }
.day-heading p { margin: 0; }
.daybar .button-icon { width: 1.9rem; height: 1.9rem; font-size: 1.1rem; }

.status { min-height: 1.5rem; padding: .5rem 0; text-align: center; }

.group + .group { margin-top: 1.5rem; }
.group-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: .75rem;
  margin: 1.2rem 0 .1rem;
  padding-bottom: .5rem;
  border-bottom: 2px solid var(--text);
}
.group-title h2 { font-size: 1rem; font-weight: 750; letter-spacing: .02em; text-transform: uppercase; }
.group-title p { margin: 0; }

.item { position: relative; padding: 1.05rem 0 1.1rem; border-bottom: 1px solid var(--line); }
.item.is-pinned { padding-left: .9rem; }
.item.is-pinned::before {
  content: "";
  position: absolute;
  top: 1.2rem;
  bottom: 1.2rem;
  left: 0;
  width: 3px;
  border-radius: 3px;
  background: var(--primary);
}
.item-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .45rem;
  margin-bottom: .3rem;
  color: var(--muted);
  font-size: .78rem;
}
.item-source { color: var(--text); font-weight: 650; }
.badge {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  padding: .05rem .45rem;
  border-radius: 999px;
  font-size: .68rem;
  font-weight: 750;
  letter-spacing: .06em;
  text-transform: uppercase;
}
.badge-top { color: var(--gold); background: var(--gold-soft); }
.badge-new { color: var(--primary-strong); background: var(--primary-soft); }
.badge-new::before { content: ""; width: .4rem; height: .4rem; border-radius: 999px; background: var(--primary); }
.item-title { margin: 0 0 .35rem; font-size: 1.08rem; font-weight: 680; line-height: 1.4; letter-spacing: -.005em; }
.item-title a { text-decoration: none; }
.item-title a:hover { color: var(--primary); text-decoration: underline; text-underline-offset: .15em; }
.item-summary { margin: 0; color: color-mix(in srgb, var(--text) 82%, var(--muted)); font-size: .95rem; line-height: 1.65; }
.item-tags { display: flex; flex-wrap: wrap; gap: .35rem; margin-top: .55rem; }
.tag {
  padding: .1rem .5rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: .72rem;
}
.empty { padding: 3rem 1rem; text-align: center; }
.empty .button { margin-top: .8rem; }

.foot {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  max-width: 46rem;
  margin: 0 auto;
  padding: 0 1.25rem 2.5rem;
}
.foot-links { display: flex; gap: .9rem; }
.foot a { color: var(--muted); text-decoration: none; }
.foot a:hover { color: var(--primary); }

/* ---------- admin: boot, auth, layout ---------- */

.boot {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  background: var(--bg);
  transition: opacity .45s ease, visibility .45s ease;
}
.boot.is-ready { visibility: hidden; opacity: 0; pointer-events: none; }
.brand-logo-large { width: 7.6rem; height: 5.9rem; animation: breathe 1.5s ease-in-out infinite; }
@keyframes breathe {
  0%, 100% { opacity: .35; transform: scale(.97); }
  50% { opacity: 1; transform: scale(1); }
}

.admin .shell { max-width: 78rem; min-height: 100dvh; margin: 0 auto; padding: 2rem 1.25rem 4rem; }

.eyebrow {
  margin: 0 0 .35rem;
  color: var(--primary);
  font-size: .7rem;
  font-weight: 800;
  letter-spacing: .16em;
  text-transform: uppercase;
}

.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  background: var(--surface);
  box-shadow: var(--shadow-small);
  backdrop-filter: blur(12px);
}

label { display: block; margin-bottom: .3rem; color: var(--text); font-size: .82rem; font-weight: 650; }
input, textarea, select {
  width: 100%;
  padding: .6rem .7rem;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-m);
  color: var(--text);
  background: var(--surface-solid);
  outline: none;
  transition: border-color .18s ease, box-shadow .18s ease;
}
input:focus, textarea:focus, select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 16%, transparent);
}
input:read-only { color: var(--muted); background: var(--surface-soft); }
textarea { resize: vertical; min-height: 5.5rem; }
.field { margin-bottom: .85rem; }
.field-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr)); gap: .75rem; margin-bottom: .85rem; }
.switch { display: inline-flex; align-items: center; gap: .45rem; margin: 0; white-space: nowrap; cursor: pointer; }
.switch input { width: auto; }
.inline { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.weekdays { display: flex; flex-wrap: wrap; gap: .4rem; }
.weekdays label {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  margin: 0;
  padding: .3rem .6rem;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  font-weight: 600;
  cursor: pointer;
}
.weekdays input { width: auto; margin: 0; }

.auth-view { display: grid; place-content: center; gap: 2rem; min-height: 82vh; text-align: center; }
.auth-panel { max-width: 26rem; margin: 0 auto; padding: 2rem; text-align: left; }
.mail-sent { text-align: center; }
.mail-icon {
  display: grid;
  place-items: center;
  width: 2.6rem;
  height: 2.6rem;
  margin: 0 auto .8rem;
  border-radius: 999px;
  color: var(--primary);
  background: var(--primary-soft);
  font-size: 1.3rem;
}
.mail-sent .button { margin-top: .6rem; }

.admin .topbar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1.5rem; }
.account { display: flex; align-items: center; gap: .8rem; }
.account-email { color: var(--muted); font-size: .82rem; overflow-wrap: anywhere; }

.dashboard { display: grid; grid-template-columns: 17rem 1fr; gap: 1.1rem; align-items: start; }
.side-panel, .content-panel { padding: 1.25rem; }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: .6rem; margin-bottom: .9rem; }

.entry-list { display: grid; gap: .25rem; }
.entry {
  width: 100%;
  padding: .5rem .65rem;
  border: 1px solid transparent;
  border-radius: var(--radius-m);
  color: inherit;
  background: transparent;
  font-size: .88rem;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  transition: background-color .18s ease;
}
.entry:hover { background: var(--surface-soft); }
.entry[aria-current="true"] {
  color: var(--primary-strong);
  background: var(--primary-soft);
  border-color: color-mix(in srgb, var(--primary) 26%, transparent);
}
.entry-meta { display: block; margin-top: .1rem; color: var(--muted); font-size: .72rem; font-weight: 500; }
.dot { display: inline-block; width: .5rem; height: .5rem; margin-right: .35rem; border-radius: 999px; background: var(--muted); vertical-align: middle; }
.dot.ok { background: #2f9e6b; }
.dot.failed { background: var(--danger); }
.dot.running { background: var(--primary); animation: breathe 1.2s ease-in-out infinite; }

.empty-state { padding: 3.5rem 1.25rem; text-align: center; }
.empty-mark { margin: 0 auto .6rem; color: var(--primary); font-size: 2rem; font-weight: 800; opacity: .28; }
.divider { height: 1px; margin: 1.1rem 0; border: 0; background: var(--line); }

.table-wrap { overflow-x: auto; }
.runs { width: 100%; border-collapse: collapse; font-size: .8rem; }
.runs th, .runs td { padding: .45rem .5rem; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
.runs th { color: var(--muted); font-weight: 650; }
.runs .error-cell { max-width: 22rem; overflow: hidden; color: var(--danger); text-overflow: ellipsis; }
.status-pill { padding: .05rem .45rem; border-radius: 999px; font-size: .72rem; font-weight: 700; }
.status-pill.ok { color: #1f7a4f; background: rgba(47, 158, 107, .14); }
.status-pill.failed, .status-pill.interrupted { color: var(--danger); background: var(--danger-soft); }
.status-pill.running { color: var(--primary-strong); background: var(--primary-soft); }

.item-admin-list { display: grid; gap: .6rem; }
.item-row {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: .85rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-l);
  background: var(--surface-solid);
}
.item-row.is-pinned { border-color: color-mix(in srgb, var(--primary) 40%, var(--line)); }
.item-row.is-hidden { opacity: .55; }
.item-row-body { min-width: 0; }
.item-row-body a { display: block; margin-bottom: .2rem; font-weight: 650; text-decoration: none; overflow-wrap: anywhere; }
.item-row-body a:hover { color: var(--primary); }
.item-row-body p { margin: 0 0 .3rem; color: var(--muted); font-size: .85rem; }
.row-actions { display: flex; align-self: flex-start; flex-shrink: 0; gap: .3rem; }

/* ---------- dialogs and toasts ---------- */

.dialog-card {
  width: min(30rem, calc(100vw - 2rem));
  padding: 1.6rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  color: var(--text);
  background: var(--surface-solid);
  box-shadow: var(--shadow);
}
.dialog-card::backdrop { background: rgba(10, 12, 20, .45); backdrop-filter: blur(2px); }
.dialog-card h2 { margin-bottom: .5rem; }
.dialog-actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1.2rem; }
.danger-mark {
  display: grid;
  place-items: center;
  width: 2.4rem;
  height: 2.4rem;
  margin-bottom: .8rem;
  border-radius: 999px;
  color: var(--danger);
  background: var(--danger-soft);
  font-size: 1.2rem;
  font-weight: 800;
}

.toast-region {
  position: fixed;
  z-index: 80;
  inset: auto 1rem 1rem auto;
  display: grid;
  gap: .6rem;
  pointer-events: none;
}
.toast {
  max-width: min(24rem, calc(100vw - 2rem));
  padding: .85rem 1rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-l);
  color: var(--text);
  background: var(--surface-solid);
  box-shadow: 0 14px 45px rgba(10, 12, 20, .18);
  animation: toast-in .25s ease both;
  transition: opacity .22s ease, transform .22s ease;
}
.toast.is-leaving { opacity: 0; transform: translateY(6px); }
.toast.error { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--line)); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ---------- dark, motion, responsive ---------- */

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: rgba(24, 26, 32, .88);
    --surface-solid: #181a20;
    --surface-soft: rgba(10, 11, 15, .6);
    --text: #e9eaef;
    --muted: #9a9fab;
    --line: rgba(233, 234, 239, .1);
    --line-strong: rgba(233, 234, 239, .18);
    --primary: #7c9dff;
    --primary-strong: #a3b9ff;
    --primary-soft: rgba(124, 157, 255, .16);
    --danger: #ef8d86;
    --danger-soft: rgba(181, 70, 63, .18);
    --gold: #e0b45a;
    --gold-soft: rgba(224, 180, 90, .16);
    --shadow: 0 24px 80px rgba(0, 0, 0, .3);
    --shadow-small: 0 12px 36px rgba(0, 0, 0, .2);
    --on-primary: #0b1530;
    --on-danger: #2b0f0d;
  }
  input, textarea, select, .button-secondary { background-color: rgba(10, 11, 15, .6); }
  .brand-logo { filter: brightness(0) invert(1); }
  .group-title { border-bottom-color: var(--line-strong); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}

@media (max-width: 60rem) {
  .admin .shell { padding: 1.4rem .9rem 3rem; }
  .dashboard { grid-template-columns: 1fr; }
  .field-grid { grid-template-columns: 1fr 1fr; }
  .item-row { flex-direction: column; }
  .toast-region { inset: auto .75rem .75rem .75rem; }
}
