/* MAX Relay dashboard — restrained UI with a light touch of motion.
   The panel runs under script-src 'none', so every effect here is pure CSS. */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f2f3f6;
  --fg: #14161a;
  --muted: #6c7280;
  --faint: #9aa0aa;
  --line: #e4e6ea;
  --line-2: #d6d9df;
  --accent: #4f46e5;
  --accent-soft: rgba(79, 70, 229, 0.10);
  --accent-fg: #ffffff;
  --ok: #10804a;
  --ok-soft: rgba(16, 128, 74, 0.12);
  --warn: #a8560a;
  --warn-soft: rgba(168, 86, 10, 0.12);
  --bad: #b3261e;
  --bad-soft: rgba(179, 38, 30, 0.12);
  --shadow: 0 1px 2px rgba(16, 18, 24, 0.05), 0 8px 24px -12px rgba(16, 18, 24, 0.18);
  --radius: 12px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c0d10;
    --surface: #141619;
    --surface-2: #1a1d21;
    --fg: #e9eaec;
    --muted: #979da7;
    --faint: #6f7681;
    --line: #24272c;
    --line-2: #313640;
    --accent: #8b85f5;
    --accent-soft: rgba(139, 133, 245, 0.14);
    --accent-fg: #14161a;
    --ok: #4ec98a;
    --ok-soft: rgba(78, 201, 138, 0.14);
    --warn: #e0a458;
    --warn-soft: rgba(224, 164, 88, 0.14);
    --bad: #f0837d;
    --bad-soft: rgba(240, 131, 125, 0.14);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 10px 30px -14px rgba(0, 0, 0, 0.7);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

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

/* ------------------------------------------------------------------ motion */

@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}

@keyframes fade {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slide-down {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: none; }
}

@keyframes halo {
  0% { box-shadow: 0 0 0 0 currentColor; opacity: 0.55; }
  70% { box-shadow: 0 0 0 7px currentColor; opacity: 0; }
  100% { box-shadow: 0 0 0 0 currentColor; opacity: 0; }
}

@keyframes spin { to { transform: rotate(360deg); } }

@keyframes grow {
  from { transform: scaleX(0); }
  to { transform: scaleX(1); }
}

/* --------------------------------------------------------------- structure */

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

.side {
  width: 236px;
  flex: 0 0 236px;
  padding: 26px 18px;
  background: var(--surface);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 26px;
  position: sticky;
  top: 0;
  height: 100vh;
  animation: fade 0.4s ease both;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 650;
  letter-spacing: -0.01em;
  padding: 0 10px;
}

.brand-mark {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  background: linear-gradient(140deg, var(--accent), color-mix(in srgb, var(--accent) 55%, #ec4899));
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  flex: none;
}

.nav { display: flex; flex-direction: column; gap: 2px; }

.nav a {
  position: relative;
  display: block;
  padding: 9px 12px;
  border-radius: 9px;
  color: var(--muted);
  font-size: 14.5px;
  text-decoration: none;
  transition: background 0.18s ease, color 0.18s ease, transform 0.18s ease;
}

.nav a::before {
  content: "";
  position: absolute;
  left: 3px;
  top: 50%;
  width: 3px;
  height: 0;
  border-radius: 2px;
  background: var(--accent);
  transform: translateY(-50%);
  transition: height 0.22s cubic-bezier(0.2, 0.8, 0.3, 1);
}

.nav a:hover { background: var(--surface-2); color: var(--fg); transform: translateX(2px); }

.nav a.is-active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 550;
}

.nav a.is-active::before { height: 18px; }

.side-foot {
  margin-top: auto;
  padding: 12px;
  border-radius: 10px;
  background: var(--surface-2);
  font-size: 13px;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.state { display: flex; align-items: center; gap: 8px; color: var(--fg); font-size: 13px; }

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--faint);
  flex: none;
  position: relative;
}

.dot::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
}

.dot-connected { background: var(--ok); color: var(--ok); }
.dot-connected::after { animation: halo 2.4s ease-out infinite; }
.dot-error { background: var(--bad); color: var(--bad); }
.dot-connecting, .dot-waiting_code, .dot-waiting_password { background: var(--warn); color: var(--warn); }
.dot-connecting::after, .dot-waiting_code::after, .dot-waiting_password::after { animation: halo 1.4s ease-out infinite; }

.side-user { color: var(--fg); font-weight: 550; }

.main {
  flex: 1 1 auto;
  min-width: 0;
  max-width: 940px;
  padding: 34px 36px 90px;
}

.main > * { animation: rise 0.42s cubic-bezier(0.2, 0.8, 0.3, 1) both; }
.main > *:nth-child(1) { animation-delay: 0.02s; }
.main > *:nth-child(2) { animation-delay: 0.06s; }
.main > *:nth-child(3) { animation-delay: 0.10s; }
.main > *:nth-child(4) { animation-delay: 0.14s; }
.main > *:nth-child(5) { animation-delay: 0.18s; }
.main > *:nth-child(6) { animation-delay: 0.22s; }
.main > *:nth-child(n + 7) { animation-delay: 0.26s; }

.plain {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

/* -------------------------------------------------------------- typography */

.page-head { margin: 0 0 24px; }
.page-head h1 { font-size: 26px; font-weight: 650; letter-spacing: -0.02em; margin: 0; }
.page-head p { margin: 5px 0 0; color: var(--muted); font-size: 14px; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 22px;
  margin: 0 0 16px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.card:hover { border-color: var(--line-2); }

.card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin: 0 0 16px;
}

.card-head h2 {
  font-size: 12px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--faint);
  margin: 0;
}

.card-head .aside { font-size: 13px; color: var(--muted); }

.hint { color: var(--muted); font-size: 13.5px; margin: 12px 0 0; }
.hint:first-child { margin-top: 0; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }
.break { overflow-wrap: anywhere; }
.empty { color: var(--faint); }
.back { margin: 0 0 10px; font-size: 13.5px; }

.notice {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 11px 14px;
  margin: 0 0 18px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  font-size: 14px;
  box-shadow: var(--shadow);
  animation: slide-down 0.35s cubic-bezier(0.2, 0.8, 0.3, 1) both;
}

.notice::before {
  content: "";
  width: 3px;
  align-self: stretch;
  border-radius: 2px;
  background: var(--accent);
  flex: none;
}

.notice-error { color: var(--bad); background: var(--bad-soft); border-color: transparent; }
.notice-error::before { background: var(--bad); }

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

label { display: block; font-size: 13px; font-weight: 550; color: var(--muted); }

input[type="text"], input:not([type]), input[type="password"], input[type="tel"], textarea {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  border: 1px solid var(--line-2);
  border-radius: 9px;
  background: var(--surface);
  color: var(--fg);
  font: inherit;
  transition: border-color 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

textarea { resize: vertical; min-height: 76px; }

input::placeholder, textarea::placeholder { color: var(--faint); }

input:hover, textarea:hover { border-color: var(--muted); }

input:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.stack { display: flex; flex-direction: column; gap: 16px; max-width: 470px; }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; margin-top: 14px; }
.row:first-child { margin-top: 0; }
.row > form { margin: 0; }
.row .grow { flex: 1 1 240px; }

button {
  font: inherit;
  font-weight: 550;
  padding: 10px 18px;
  border: 1px solid transparent;
  border-radius: 9px;
  background: var(--accent);
  color: var(--accent-fg);
  cursor: pointer;
  transition: transform 0.14s ease, box-shadow 0.18s ease, background 0.18s ease,
    border-color 0.18s ease, opacity 0.18s ease;
}

button:hover { transform: translateY(-1px); box-shadow: 0 6px 16px -8px var(--accent); }
button:active { transform: translateY(0); box-shadow: none; }
button:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
button:disabled { opacity: 0.45; cursor: not-allowed; transform: none; box-shadow: none; }

.btn-ghost {
  background: var(--surface);
  color: var(--fg);
  border-color: var(--line-2);
}

.btn-ghost:hover { background: var(--surface-2); box-shadow: none; }
.btn-danger { color: var(--bad); border-color: var(--line-2); background: var(--surface); }
.btn-danger:hover { background: var(--bad-soft); box-shadow: none; }

.link {
  background: none;
  border: none;
  padding: 0;
  font-weight: 500;
  color: var(--muted);
  text-decoration: underline;
  cursor: pointer;
}

.link:hover { color: var(--fg); transform: none; box-shadow: none; }

.auth-box {
  width: 100%;
  max-width: 340px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 30px 28px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  animation: rise 0.5s cubic-bezier(0.2, 0.8, 0.3, 1) both;
}

.auth-box h1 { margin: 0; font-size: 21px; letter-spacing: -0.01em; }
.auth-box .brand { padding: 0; }

/* -------------------------------------------------------------------- data */

.kv {
  display: grid;
  grid-template-columns: minmax(150px, 210px) 1fr;
  gap: 9px 18px;
  margin: 0;
  font-size: 14px;
}

.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }

th {
  text-align: left;
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--faint);
  padding: 0 12px 10px 0;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

td {
  padding: 11px 12px 11px 0;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

tbody tr { transition: background 0.15s ease; }
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: none; }

.table-wrap { overflow-x: auto; margin: 0 -4px; padding: 0 4px; }
.cut { max-width: 320px; overflow-wrap: anywhere; }

.tag {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 550;
  background: var(--surface-2);
  color: var(--muted);
  white-space: nowrap;
}

.tag-completed, .tag-sent { background: var(--ok-soft); color: var(--ok); }
.tag-running, .tag-queued, .tag-sending, .tag-pending { background: var(--accent-soft); color: var(--accent); }
.tag-failed, .tag-blocked, .tag-uncertain, .tag-cancelled { background: var(--bad-soft); color: var(--bad); }
.tag-partial, .tag-skipped { background: var(--warn-soft); color: var(--warn); }

.stats {
  list-style: none;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px;
  padding: 0;
  margin: 0 0 18px;
}

.stats li {
  background: var(--surface-2);
  border-radius: 10px;
  padding: 13px 15px;
  font-size: 12.5px;
  color: var(--muted);
  transition: transform 0.18s ease;
}

.stats li:hover { transform: translateY(-2px); }
.stats b { display: block; font-size: 25px; font-weight: 650; color: var(--fg); line-height: 1.25; letter-spacing: -0.02em; }

.bar {
  height: 6px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
  margin: 4px 0 0;
}

.bar span {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: var(--accent);
  transform-origin: left;
  animation: grow 0.7s cubic-bezier(0.2, 0.8, 0.3, 1) both;
}

.bar-ok span { background: var(--ok); }
.bar-bad span { background: var(--bad); }

.chips { list-style: none; display: flex; flex-wrap: wrap; gap: 7px; padding: 0; margin: 14px 0 0; }

.chips li {
  border: 1px solid var(--line);
  background: var(--surface-2);
  border-radius: 999px;
  padding: 4px 11px;
  font-size: 13px;
  animation: fade 0.3s ease both;
}

.clip {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
  white-space: nowrap;
}

.thumbs {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  padding: 0;
  margin: 0;
}

.thumbs li {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
  max-width: 180px;
}

.thumbs img {
  display: block;
  width: 180px;
  height: 130px;
  object-fit: cover;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-2);
  transition: transform 0.18s ease, border-color 0.18s ease;
}

.thumbs a:hover img { transform: scale(1.02); border-color: var(--line-strong, var(--accent)); }

.spinner {
  display: inline-block;
  width: 13px;
  height: 13px;
  margin-right: 8px;
  vertical-align: -2px;
  border: 2px solid var(--line-2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.blank {
  text-align: center;
  padding: 34px 20px;
  color: var(--muted);
  font-size: 14px;
}

.right { text-align: right; white-space: nowrap; }
.right form { display: inline-block; margin: 0; }

.btn-small { padding: 5px 11px; font-size: 13px; border-radius: 8px; }

/* A row's action stays quiet until the row is pointed at. */
tbody tr .btn-small { opacity: 0.55; transition: opacity 0.18s ease, background 0.18s ease, transform 0.14s ease; }
tbody tr:hover .btn-small, tbody tr .btn-small:focus-visible { opacity: 1; }

.fold { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 12px; }

.fold summary {
  cursor: pointer;
  font-size: 13.5px;
  color: var(--muted);
  list-style: none;
  display: flex;
  align-items: center;
  gap: 7px;
  transition: color 0.18s ease;
}

.fold summary::-webkit-details-marker { display: none; }

.fold summary::before {
  content: "";
  width: 0;
  height: 0;
  border: 4px solid transparent;
  border-left-color: currentColor;
  transition: transform 0.2s ease;
}

.fold[open] summary::before { transform: rotate(90deg) translateX(-1px); }
.fold summary:hover { color: var(--fg); }
.fold[open] > *:not(summary) { animation: slide-down 0.28s cubic-bezier(0.2, 0.8, 0.3, 1) both; }

/* ------------------------------------------------------------- responsive */

@media (max-width: 780px) {
  .shell { flex-direction: column; }
  .side {
    width: auto;
    flex: none;
    height: auto;
    position: static;
    border-right: none;
    border-bottom: 1px solid var(--line);
    padding: 16px 18px;
    gap: 14px;
  }
  .nav { flex-direction: row; flex-wrap: wrap; gap: 6px; }
  .nav a { padding: 7px 12px; }
  .nav a::before { display: none; }
  .side-foot { margin-top: 0; flex-direction: row; align-items: center; gap: 14px; flex-wrap: wrap; }
  .main { padding: 22px 18px 64px; }
  .kv { grid-template-columns: 1fr; gap: 2px; }
  .kv dd { margin-bottom: 12px; }
}

/* ------------------------------------------------- cross-document transitions

   Sections live on separate URLs, so navigating between them is a real page
   load. The View Transition API animates that hand-off natively — no script,
   which matters because the panel runs under script-src 'none'. Browsers
   without support just navigate as before. */

@view-transition { navigation: auto; }

/* The sidebar is the same on every page: naming it keeps it pinned and
   unanimated instead of cross-fading with the rest of the document. */
.side { view-transition-name: side; }
.main { view-transition-name: main; }

::view-transition-old(main) {
  animation: vt-leave 0.16s cubic-bezier(0.4, 0, 1, 1) both;
}

::view-transition-new(main) {
  animation: vt-enter 0.28s cubic-bezier(0.2, 0.8, 0.3, 1) both;
}

::view-transition-old(side), ::view-transition-new(side) { animation: none; }

@keyframes vt-leave {
  to { opacity: 0; transform: translateY(-6px); }
}

@keyframes vt-enter {
  from { opacity: 0; transform: translateY(10px); }
}

/* With a view transition running, the per-card stagger would play on top of the
   page slide and read as two competing motions. Let the transition carry it. */
@supports (view-transition-name: none) {
  .main > * { animation: none; }
}

@media (prefers-reduced-motion: reduce) {
  @view-transition { navigation: none; }

  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }

  ::view-transition-group(*), ::view-transition-old(*), ::view-transition-new(*) {
    animation: none !important;
  }
}
