:root {
  color-scheme: light dark;
  --bg: #f5f6f8;
  --card: #ffffff;
  --fg: #16181d;
  --muted: #6b7280;
  --border: #d9dde3;
  --accent: #2563eb;
  --accent-fg: #ffffff;
  --error: #b42318;
  --ok: #067647;
  --radius: 10px;
  --badge-bg: #eef0f4;
  --badge-pending-bg: #fdf4e3;
  --badge-pending-fg: #7a5312;
  --badge-pending-border: #d9a441;
}

html[data-theme="dark"] {
  --bg: #14161a;
  --card: #1d2026;
  --fg: #e8eaed;
  --muted: #9aa3af;
  --border: #333941;
  --accent: #60a5fa;
  --accent-fg: #0b1020;
  --error: #f97066;
  --ok: #47cd89;
  --badge-bg: #262a31;
  --badge-pending-bg: #2c2413;
  --badge-pending-fg: #e5c07b;
  --badge-pending-border: #6b5324;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 1.5rem 1rem 3rem;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.wrap {
  max-width: 60rem;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

h1 {
  font-size: 1.35rem;
  margin: 0;
}

h1 a {
  color: inherit;
  text-decoration: none;
}

h2 {
  font-size: 1.1rem;
  margin: 0;
}

nav {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

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

form {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

label {
  font-size: 0.85rem;
  color: var(--muted);
  font-weight: 600;
}

label.inline {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-weight: 400;
}

input,
select,
button {
  font: inherit;
  border-radius: 8px;
  border: 1px solid var(--border);
  padding: 0.55rem 0.7rem;
  background: var(--card);
  color: var(--fg);
}

input:focus-visible,
select:focus-visible,
button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

button {
  cursor: pointer;
  background: var(--accent);
  color: var(--accent-fg);
  border-color: transparent;
  font-weight: 600;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

button.secondary,
#theme-toggle {
  background: transparent;
  color: var(--fg);
  border-color: var(--border);
}

details {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.7rem;
}

summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--muted);
}

details[open] summary {
  margin-bottom: 0.5rem;
}

.hint {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 400;
}

.preview {
  margin: 0;
  min-height: 1.2em;
  font-size: 0.85rem;
  color: var(--muted);
}

.preview.invalid {
  color: var(--error);
}

.error {
  color: var(--error);
  min-height: 1.2em;
  margin: 0.5rem 0 0;
  font-size: 0.9rem;
}

.result {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-top: 0.5rem;
}

.result input {
  flex: 1 1 18rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.list-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
}

.list-head input {
  flex: 0 1 16rem;
}

.table-scroll {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

th,
td {
  text-align: left;
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

td.target {
  max-width: 22rem;
  overflow-wrap: anywhere;
  color: var(--muted);
}

td.slug a {
  color: var(--accent);
  text-decoration: none;
  overflow-wrap: anywhere;
}

td.slug a:hover {
  text-decoration: underline;
}

/* The cell stays a table-cell: display:flex on a td takes it out of the table
   layout algorithm, which knocks the column out of line with its header. The
   buttons live in an inner wrapper instead. */
td.actions {
  white-space: nowrap;
}

td.actions div.actions {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
}

td.actions div.actions button {
  padding: 0.3rem 0.5rem;
  font-size: 0.8rem;
}

/* Status markers for links that behave differently from a plain redirect. */
.badge {
  display: inline-block;
  padding: 0.2rem 0.45rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--badge-bg);
  color: var(--muted);
  font-size: 0.75rem;
  line-height: 1.4;
  white-space: nowrap;
}

.badge.pending {
  border-color: var(--badge-pending-border);
  background: var(--badge-pending-bg);
  color: var(--badge-pending-fg);
}

.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 0.75rem;
}

.pager span {
  color: var(--muted);
  font-size: 0.85rem;
}

.empty {
  color: var(--muted);
  padding: 1rem 0;
}

dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--fg);
  padding: 0;
}

dialog::backdrop {
  background: rgb(0 0 0 / 55%);
}

.dialog-body {
  position: relative;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
}

.dialog-body h3 {
  margin: 0;
}

.close {
  position: absolute;
  top: 0.4rem;
  right: 0.5rem;
  background: transparent;
  color: var(--fg);
  border: none;
  font-size: 1.4rem;
  line-height: 1;
  padding: 0.2rem 0.4rem;
}

#qr-code-target,
#qr-link-target {
  max-width: 20rem;
  overflow-wrap: anywhere;
  text-align: center;
}

/* Two symbols side by side, stacking on a narrow screen. */
.qr-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 1.25rem;
  justify-content: center;
}

.qr-item {
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
}

.qr-item canvas {
  max-width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.qr-item figcaption {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

/* The editor stacks its fields like the create form does. */
#edit-dialog {
  width: min(34rem, calc(100vw - 2rem));
}

#edit-dialog .dialog-body {
  align-items: stretch;
  text-align: left;
  max-height: 90vh;
  overflow-y: auto;
}

#edit-dialog .close {
  /* The close button stays pinned while the body scrolls. */
  position: sticky;
  align-self: flex-end;
  top: 0;
  margin-bottom: -1.6rem;
}

.inline-controls {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.inline-controls input {
  flex: 1;
  min-width: 0;
}

.dialog-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
}

footer {
  text-align: center;
  color: var(--muted);
  font-size: 0.8rem;
  padding-top: 0.5rem;
}

@media (max-width: 640px) {
  body {
    padding: 1rem 0.75rem 2rem;
  }

  .inline-controls {
    flex-wrap: wrap;
  }

  th.hide-sm,
  td.hide-sm {
    display: none;
  }
}
