:root {
  --bg: #fbfaf7;
  --surface: #ffffff;
  --text: #1d1b16;
  --muted: #6b6659;
  --accent: #b8860b;
  --border: #e6e1d5;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16140f;
    --surface: #1f1c16;
    --text: #f1ede3;
    --muted: #a59f90;
    --accent: #e0b04a;
    --border: #35302a;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  line-height: 1.5;
}

a { color: var(--accent); }

.app-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.brand {
  font-weight: 700;
  text-decoration: none;
  color: var(--text);
}

.app-main {
  max-width: 64rem;
  margin: 0 auto;
  padding: 1.5rem 1rem;
}

/* Account pages (server-rendered sign-in, password, two-factor) */
.account-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem 1rem;
}

.account-card {
  width: 100%;
  max-width: 26rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.75rem 1.5rem;
}

.account-brand {
  margin: 0 0 1rem;
  font-weight: 700;
  color: var(--accent);
}

.account-card h1 {
  font-size: 1.4rem;
  margin: 0 0 1rem;
}

.field {
  display: grid;
  gap: 0.35rem;
  margin-bottom: 1rem;
}

.field input {
  font: inherit;
  padding: 0.6rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
}

.check {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 1rem;
}

button.primary, a.button.primary {
  display: inline-block;
  font: inherit;
  font-weight: 600;
  padding: 0.6rem 1.1rem;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #1d1b16;
  text-decoration: none;
  cursor: pointer;
}

.status { padding: 0.6rem 0.8rem; border-radius: 8px; }
.status-error { background: color-mix(in srgb, #d64545 14%, transparent); }
.status-ok { background: color-mix(in srgb, #3a9d5d 14%, transparent); }
.aside { color: var(--muted); font-size: 0.92rem; }
.validation-message { color: #d64545; font-size: 0.9rem; }
.qr { display: grid; justify-items: center; gap: 0.5rem; margin: 1rem 0; }
.qr img { background: #fff; padding: 8px; border-radius: 8px; }
.shared-key, .codes code { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; }
.codes { columns: 2; padding-left: 1.2rem; }

/* ---------- Dashboard ---------- */
.app-header { flex-wrap: wrap; }
.app-nav { display: flex; gap: 0.25rem; flex: 1; flex-wrap: wrap; }
.app-nav a { padding: 0.35rem 0.6rem; border-radius: 6px; color: var(--muted); text-decoration: none; }
.app-nav a.active, .app-nav a:hover { color: var(--text); background: var(--bg); }

h1 { font-size: 1.5rem; margin: 0 0 1rem; }
h2 { font-size: 1.15rem; margin: 0 0 0.75rem; }
h3 { font-size: 0.95rem; margin: 0.75rem 0 0.5rem; color: var(--muted); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem 1.1rem;
  margin-bottom: 1rem;
}

.page-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: 0.5rem; }
.page-head h1, .page-head h2 { margin: 0; }

.muted { color: var(--muted); }
.error { color: #d64545; }
.notice { color: #3a9d5d; }
.warning { color: #b9770e; }
.hint-ok { color: #3a9d5d; margin: 0.25rem 0 0; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.button {
  display: inline-block;
  font: inherit;
  padding: 0.5rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
}
.button:hover { border-color: var(--accent); }
.button:disabled { opacity: 0.55; cursor: default; }
.button.primary { background: var(--accent); border-color: var(--accent); color: #1d1b16; font-weight: 600; }
.button.danger { border-color: #d64545; color: #d64545; }
.button.ghost { background: transparent; border-color: transparent; }
.button.small { padding: 0.2rem 0.55rem; font-size: 0.85rem; }
.button.copied { border-color: #3a9d5d; color: #3a9d5d; }

input[type=text], input[type=url], input[type=search], input[type=datetime-local], select, textarea {
  font: inherit;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  max-width: 100%;
}
textarea { width: 100%; }
.form .field input, .form .field textarea { width: 100%; }

.inline-form { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.inline-form input { flex: 1; min-width: 12rem; }
.prefix { color: var(--muted); font-size: 0.9rem; }

.filters { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 1rem; }
.filters input { flex: 1; min-width: 12rem; }

.quick-create h1 { font-size: 1.3rem; }
.created { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; font-weight: 600; }

.stats-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr)); gap: 1rem; }
.stat { text-align: center; }
.stat-value { font-size: 2rem; font-weight: 700; margin: 0; }
.stat-label { color: var(--muted); margin: 0; }

.link-list { list-style: none; padding: 0; margin: 0; }
.link-row { display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
.link-main { min-width: 0; flex: 1; }
.link-title { font-weight: 600; text-decoration: none; color: var(--text); margin-right: 0.5rem; }
.link-clicks { margin: 0; text-align: right; white-space: nowrap; }
.short-url { margin: 0.25rem 0; display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; color: var(--accent); }
.short-url.big { font-size: 1.1rem; font-weight: 600; }
.destination { margin: 0.25rem 0; color: var(--muted); overflow-wrap: anywhere; }
.destination.current { color: var(--text); font-size: 1.05rem; }

.badge { font-size: 0.75rem; padding: 0.1rem 0.5rem; border-radius: 999px; border: 1px solid var(--border); color: var(--muted); }
.badge-active { color: #3a9d5d; border-color: #3a9d5d; }
.badge-disabled, .badge-expired { color: #b9770e; border-color: #b9770e; }
.badge-deleted { color: #d64545; border-color: #d64545; }

.sparkline { margin: 0.5rem 0 0; }
.sparkline svg { width: 100%; height: 64px; display: block; }
.sparkline-line { fill: none; stroke: var(--accent); stroke-width: 2; vector-effect: non-scaling-stroke; }
.sparkline-area { fill: var(--accent); opacity: 0.12; stroke: none; }
.sparkline figcaption { color: var(--muted); font-size: 0.85rem; }

.breakdowns { display: grid; grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr)); gap: 1rem; }
.breakdown ul { list-style: none; padding: 0; margin: 0; }
.breakdown li { display: grid; grid-template-columns: minmax(0, 1fr) 5rem 3rem; gap: 0.5rem; align-items: center; padding: 0.15rem 0; }
.breakdown-key { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.breakdown-count { text-align: right; color: var(--muted); }
.breakdown meter { width: 100%; }

.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 0.4rem 0.3rem; border-bottom: 1px solid var(--border); vertical-align: top; }

.history { list-style: none; padding: 0; margin: 0; }
.history li { padding: 0.6rem 0; border-bottom: 1px solid var(--border); }
.history li:last-child { border-bottom: 0; }

.top-links { margin: 0; padding-left: 1.2rem; }
.actions { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; margin-top: 1rem; }
.confirm { color: #d64545; }
.danger-zone { border-color: #d64545; }

@media (max-width: 40rem) {
  .link-row { flex-direction: column; align-items: flex-start; }
  .link-clicks { text-align: left; }
  .app-main { padding: 1rem 0.75rem; }
}

/* Blazor shows this bar itself when the app hits an error it cannot recover from. */
#blazor-error-ui {
  display: none;
  position: fixed;
  inset: auto 0 0 0;
  padding: 0.75rem 1rem;
  background: #d64545;
  color: #fff;
  z-index: 1000;
}

#blazor-error-ui .reload { color: #fff; font-weight: 600; margin-left: 0.5rem; }
