:root {
  --accent: #4c9aff;
  --bg: #12141c;
  --fg: #e4e7ee;
  --muted: #8b93a3;
  --border: #262b38;
  --card: #171a23;
  --surface: #1f2330;
  --input-bg: #10131a;
  --wash: rgba(18, 20, 28, 0.55);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--fg);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  position: relative;
}

/* Branding background artwork (layout.html injects --bg-image when set):
   fixed cover image behind everything, with a dark translucent wash on a
   ::after pseudo-element so content stays readable ("subtle overlay"). */
body::before {
  content: "";
  background-image: var(--bg-image, none);
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  background-attachment: fixed;
  position: fixed;
  inset: 0;
  z-index: -2;
}
main {
  position: relative;
  z-index: 0;
}
body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background: var(--wash);
}

header.site {
  background: rgba(18, 20, 28, 0.8);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

header.site .logo {
  height: 4.5rem;
  width: auto;
}

header.site .site-name {
  font-size: 1.1rem;
  font-weight: 600;
}

/* Admin pages: the header branding links back to the Links page. */
header.site a.home-link {
  display: inline-flex;
  align-items: center;
  color: inherit;
}
header.site a.home-link:hover { text-decoration: none; }
header.site a.home-link:hover .site-name { text-decoration: underline; }

main {
  flex: 1;
  max-width: 60rem;
  margin: 0 auto;
  padding: 1.5rem;
  width: 100%;
}

/* Admin pages render full-wide (set via the layout "wide" class). */
main.wide { max-width: none; }

footer.site {
  padding: 1rem 1.5rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
  border-top: 1px solid var(--border);
  background: rgba(18, 20, 28, 0.8);
}

footer.site a { color: var(--muted); }

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

.btn {
  display: inline-block;
  padding: 0.55rem 1.1rem;
  border-radius: 0.4rem;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #10121a;
  font-family: inherit;
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
  font-size: 0.95rem;
}
.btn:hover { filter: brightness(1.12); text-decoration: none; }
/* One focus style for every variant (anchors and buttons). */
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn.secondary {
  background: transparent;
  color: var(--accent);
}
/* Destructive actions ("kill"): red outline variant; --accent swap keeps the
   border and focus ring in the same red as the killed-state pills/dots. */
.btn.danger {
  --accent: #fda4a4;
  background: transparent;
  color: var(--accent);
}
.btn[disabled],
.btn[aria-disabled="true"] {
  opacity: 0.55;
  cursor: not-allowed;
}
.btn[disabled]:hover,
.btn[aria-disabled="true"]:hover { filter: none; }

code {
  background: var(--surface);
  padding: 0.1rem 0.35rem;
  border-radius: 0.25rem;
  font-size: 0.9em;
}

table.data {
  width: 100%;
  border-collapse: collapse;
}
table.data th, table.data td {
  text-align: left;
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid var(--border);
}
table.data th a, table.data th a:visited {
  color: var(--muted);
  text-decoration: none;
}
table.data th a:hover { color: var(--accent); text-decoration: underline; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  padding: 1.25rem;
}

.file-list { list-style: none; margin: 0; padding: 0; }
.file-list li {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--border);
}
.file-list li:last-child { border-bottom: none; }
.file-list .file-main { flex: 1; min-width: 0; }
.file-list .file-main a { font-weight: 500; }
.file-meta {
  margin: 0.15rem 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.muted { color: var(--muted); font-size: 0.9rem; }
.notice {
  background: #2a2410;
  border: 1px solid #6b5414;
  border-radius: 0.4rem;
  padding: 0.6rem 0.9rem;
  margin: 0 0 1rem;
  color: #fbd38d;
  font-size: 0.9rem;
}
.state-exhausted { color: var(--muted); }
.state-unavailable { color: #f97316; font-weight: 500; }

/* --- public landing / dead pages ----------------------------------------- */

.landing-title { margin: 0 0 0.5rem; font-size: 1.35rem; }
.landing .file-list { margin-top: 0.75rem; }
.zip-row { margin: 1.25rem 0 0.5rem; }
.dead h1 { margin-top: 0; font-size: 1.35rem; }
.dead p:last-child { margin-bottom: 0; }

/* --- mobile ---------------------------------------------------------------- */

@media (max-width: 640px) {
  body::after { background: rgba(18, 20, 28, 0.8); } /* stronger wash on small screens */
  header.site { padding: 0.6rem 1rem; }
  header.site .logo { height: 2.75rem; }  main { padding: 1rem; }
  .card { padding: 1rem; }
  .landing-title, .dead h1 { font-size: 1.15rem; }

  .file-list li {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.4rem;
  }
  .file-list li .btn {
    width: 100%;
    text-align: center;
  }
  .btn { padding: 0.65rem 1.1rem; }

  .search-row { flex-wrap: wrap; }
  .search-row input[type="search"] { max-width: none; width: 100%; }
}

.form {
  max-width: 20rem;
  margin: 3rem auto;
}
.form label {
  display: block;
  margin: 0.75rem 0 0.25rem;
  font-size: 0.9rem;
  font-weight: 500;
}
.form input {
  width: 100%;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 0.4rem;
  font-size: 0.95rem;
  background: var(--input-bg);
  color: var(--fg);
}
.form .error {
  color: #fca5a5;
  margin: 0.75rem 0;
  font-size: 0.9rem;
}

/* --- admin panel ---------------------------------------------------------- */

.row { display: flex; align-items: center; gap: 0.75rem; }
.head-row h1 { margin: 0; font-size: 1.3rem; }
.inline { display: inline; }
.push-right { margin-left: auto; }

.pill {
  display: inline-block;
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  background: var(--surface);
  color: var(--muted);
}
.pill.active { background: #123622; color: #6ee7a0; }
.pill.partially_killed { background: #3a2a12; color: #fbbf6a; }
.pill.fully_killed { background: #3d1a1a; color: #fda4a4; }
.pill.fully_killed a, .pill.active a { color: inherit; }

/* State indicator dot next to link IDs in the admin table. */
.dot {
  display: inline-block;
  width: 0.65rem;
  height: 0.65rem;
  border-radius: 50%;
  margin-right: 0.35rem;
  vertical-align: baseline;
}
.dot.active { background: #4ade80; }
.dot.partially_killed { background: #fbbf6a; }
.dot.fully_killed { background: #fda4a4; }

.links-table td, .links-table th { vertical-align: top; }
.actions-col .copyrow { margin-bottom: 0.3rem; }

.copyrow { display: flex; gap: 0.4rem; align-items: center; margin: 0.3rem 0; }
.copyrow input {
  flex: 1;
  min-width: 12rem;
  max-width: 26rem;
  padding: 0.35rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 0.35rem;
  font-size: 0.85rem;
  color: var(--muted);
  background: var(--input-bg);
}
.btn.tiny {
  padding: 0.25rem 0.6rem;
  font-size: 0.8rem;
}
/* Icon-only buttons: SVG sized via the button font-size scale. */
.btn .icon {
  width: 1em;
  height: 1em;
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* --- QR code block ---------------------------------------------------------- */

.qr-block {
  margin: 0.4rem 0 0.6rem;
  padding: 0.6rem;
  border: 1px solid var(--border);
  border-radius: 0.4rem;
  background: var(--input-bg);
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: center;
  width: fit-content;
}
.qr-block img {
  display: block;
  width: 220px;
  height: 220px;
  background: #fff;
  padding: 0.4rem;
  border-radius: 0.25rem;
  image-rendering: pixelated;
}
.qr-status { width: 100%; margin: 0; font-size: 0.82rem; }
.qr-status.ok { color: var(--ok, #4ade80); }

/* Wide tables scroll horizontally wherever they overflow (any viewport). */
.links-table-wrap { overflow-x: auto; }

.search-row { display: flex; gap: 0.5rem; margin: 0.75rem 0 1rem; }
.search-row input[type="search"] {
  flex: 1;
  max-width: 22rem;
  background: var(--input-bg);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 0.4rem;
  padding: 0.45rem 0.7rem;
}

.pager { display: flex; gap: 0.75rem; align-items: center; margin-top: 0.75rem; }

.create-form { margin-top: 1.5rem; border-top: 1px solid var(--border); padding-top: 0.75rem; }
.create-grid { display: grid; gap: 1rem 2rem; grid-template-columns: minmax(16rem, 1fr) minmax(16rem, 1fr); }
.create-grid .field { min-width: 0; }
.create-grid .note-field { grid-column: 1 / -1; }
.create-grid label { display: block; font-size: 0.9rem; font-weight: 500; }
.create-grid fieldset {
  border: 0;
  padding: 0 0 0.75rem;
  min-width: 0;
}
.create-grid fieldset legend,
.create-grid fieldset .legend { font-size: 0.9rem; font-weight: 500; padding: 0; margin-bottom: 0.4rem; }
.create-grid fieldset .muted { font-size: 0.8rem; font-weight: 400; }
.create-grid input {
  margin-top: 0.25rem;
  width: 100%;
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 0.4rem;
  background: var(--input-bg);
  color: var(--fg);
}
.create-grid label.check { font-weight: normal; }
.create-grid label.check input { width: auto; margin-top: 0; margin-right: 0.4rem; }
.expiry-row { display: flex; gap: 0.4rem; align-items: center; flex-wrap: wrap; }
.expiry-row input[type="datetime-local"] { flex: 1; min-width: 11rem; margin-top: 0; }
.limit-field .check { margin-bottom: 0.4rem; }
.create-form .btn { margin-top: 0.75rem; }
.kill-form label { display: block; font-size: 0.9rem; font-weight: 500; margin-bottom: 0.5rem; }
.kill-form input { display: block; width: 100%; max-width: 22rem; margin-top: 0.25rem; padding: 0.5rem 0.7rem; border: 1px solid var(--border); border-radius: 0.4rem; background: var(--input-bg); color: var(--fg); }

.kill-form .btn { margin-top: 0.25rem; }

.dirname { font-weight: 600; }
.up-row .dirname { font-weight: 500; }
.file-list label { display: flex; align-items: center; gap: 0.6rem; cursor: pointer; }
.browse-current { margin: 0 0 0.5rem; }
.file-list .file-meta { margin-left: 0.5rem; }
.file-list .add-btn { margin-left: auto; }
.file-list .file-main + .file-meta { margin-left: 0; }

/* --- browse staging table --------------------------------------------------- */

.staging-block h2 { font-size: 1.05rem; margin: 1.5rem 0 0.5rem; }
.staging-block h2 .muted { font-size: 0.85rem; font-weight: 400; }
.staging-table code { overflow-wrap: anywhere; }
.staging-actions { text-align: right; }
.staging-actions .btn { padding: 0.3rem 0.55rem; }
.ua-col { font-size: 0.8rem; color: var(--muted); max-width: 18rem; overflow-wrap: anywhere; }
#create-out .copyrow input { min-width: 16rem; }

/* --- live view (SSE panel) ------------------------------------------------ */

.live-card { margin-top: 1rem; }
.live-card h2 { font-size: 1.05rem; margin: 1rem 0 0.5rem; }
.live-card h2 .muted { font-size: 0.85rem; font-weight: 400; }

.live-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.55rem 0;
  border-bottom: 1px solid var(--border);
}
.live-row:last-child { border-bottom: none; }
.live-main { flex: 1; min-width: 0; }
.live-name { font-weight: 500; font-size: 0.95rem; overflow-wrap: anywhere; }
.live-meta { color: var(--muted); font-size: 0.82rem; margin-left: 0.5rem; }
.live-progress { display: flex; align-items: center; gap: 0.75rem; min-width: 20rem; max-width: 30rem; flex: 2; }
.live-bar {
  flex: 1;
  height: 0.5rem;
  border-radius: 999px;
  background: var(--surface);
  overflow: hidden;
}
.live-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.3s ease;
}
.live-outcome { display: flex; align-items: center; gap: 0.5rem; }
.pill-live { background: #123622; color: #6ee7a0; }
.pill-live-off { background: var(--surface); color: var(--muted); }
.pill-aborted { background: #3d1a1a; color: #fda4a4; }

@media (max-width: 640px) {
  .live-row { flex-direction: column; align-items: flex-start; gap: 0.4rem; }
  .live-progress { min-width: 0; width: 100%; }
  .create-grid { grid-template-columns: 1fr; }
}
