:root {
  color-scheme: light;
  --bg: #f6f7fb;
  --text: #111827;
  --muted: #6b7280;
  --card: #ffffff;
  --line: #e5e7eb;
  --accent: #111827;
  --danger: #b91c1c;
  --success: #166534;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; color: var(--text); background: var(--bg); }
a { color: inherit; }
.container { width: min(1120px, calc(100% - 32px)); margin: 32px auto; }
.topbar { position: sticky; top: 0; z-index: 10; background: rgba(255,255,255,.92); border-bottom: 1px solid var(--line); backdrop-filter: blur(10px); display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 14px 24px; }
.brand { font-weight: 800; text-decoration: none; }
.topbar nav { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.topbar nav a { text-decoration: none; color: var(--muted); font-weight: 600; }
.topbar nav a:hover { color: var(--text); }
.userpill { background: #eef2ff; color: #3730a3; padding: 6px 10px; border-radius: 999px; font-size: 13px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 22px; padding: 24px; box-shadow: 0 16px 40px rgba(17,24,39,.07); margin-bottom: 20px; }
.auth { max-width: 460px; margin: 56px auto; }
h1, h2 { margin-top: 0; letter-spacing: -.03em; }
label { display: grid; gap: 7px; font-weight: 700; margin: 14px 0; }
input, textarea, select { width: 100%; border: 1px solid var(--line); border-radius: 14px; padding: 11px 12px; font: inherit; background: #fff; }
textarea { min-height: 110px; resize: vertical; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.check input { width: auto; }
button, .button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 0; background: var(--accent); color: #fff; border-radius: 14px; padding: 11px 15px; font: inherit; font-weight: 800; text-decoration: none; cursor: pointer; }
button.secondary, .button.secondary { background: #e5e7eb; color: #111827; }
button.danger, .button.danger { background: var(--danger); color: #fff; }
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin: 20px 0; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; }
.list { display: grid; gap: 10px; }
.row { background: #fff; border: 1px solid var(--line); border-radius: 18px; padding: 14px; display: grid; grid-template-columns: 1fr auto auto; gap: 16px; align-items: center; }
.flash { border-radius: 14px; padding: 12px 14px; margin-bottom: 14px; font-weight: 700; }
.flash.success { background: #dcfce7; color: var(--success); }
.flash.error { background: #fee2e2; color: var(--danger); }
.tablewrap { overflow-x: auto; background: #fff; border: 1px solid var(--line); border-radius: 20px; }
table { width: 100%; border-collapse: collapse; min-width: 760px; }
th, td { text-align: left; border-bottom: 1px solid var(--line); padding: 12px; vertical-align: middle; }
th { color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: .06em; }
tr:last-child td { border-bottom: 0; }
.tokenbox code { display: block; word-break: break-all; background: #111827; color: #fff; padding: 14px; border-radius: 14px; }
.hero { min-height: 65vh; display: grid; place-content: center; text-align: center; }
.hero h1 { font-size: clamp(42px, 7vw, 84px); margin: 0 0 10px; }
.public .container { width: 100%; margin: 0; }
.linktree { min-height: 100vh; display: grid; place-items: center; padding: 32px 16px; background: linear-gradient(135deg, #111827, #374151); background-size: cover; background-position: center; }
.linkcard { width: min(520px, 100%); background: rgba(255,255,255,.9); backdrop-filter: blur(14px); border: 1px solid rgba(255,255,255,.4); border-radius: 30px; padding: 30px; box-shadow: 0 22px 60px rgba(0,0,0,.25); text-align: center; }
.linkcard h1 { font-size: 40px; margin-bottom: 8px; }
.bio { color: var(--muted); white-space: pre-wrap; }
.links { display: grid; gap: 12px; margin: 24px 0; }
.linkbtn { text-align: left; display: flex; align-items: center; gap: 12px; background: #fff; border: 1px solid var(--line); padding: 14px; border-radius: 18px; text-decoration: none; transition: transform .15s ease, box-shadow .15s ease; }
.linkbtn:hover { transform: translateY(-2px); box-shadow: 0 10px 24px rgba(17,24,39,.12); }
.linkbtn img { width: 48px; height: 48px; object-fit: cover; border-radius: 14px; flex: 0 0 auto; }
.linkbtn strong, .linkbtn small { display: block; }
.linkbtn small { color: var(--muted); margin-top: 2px; }
footer { color: var(--muted); font-size: 13px; }
@media (max-width: 740px) {
  .topbar { align-items: flex-start; flex-direction: column; }
  .row { grid-template-columns: 1fr; }
  .toolbar { align-items: flex-start; flex-direction: column; }
}

/* Link-Reihenfolge: Drag-and-drop + Sortierbuttons */
.muted { color: var(--muted); margin: 4px 0 0; }
.link-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
}
.sortable-row { transition: transform .12s ease, box-shadow .12s ease, opacity .12s ease; }
.sortable-row.dragging { opacity: .55; box-shadow: 0 18px 36px rgba(17,24,39,.14); }
.link-order-controls {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding-right: 2px;
}
.drag-handle { width: 36px; height: 36px; display: inline-flex; align-items: center; justify-content: center; border: 1px solid var(--line); border-radius: 12px; background: #f9fafb; color: var(--muted); font-weight: 900; cursor: grab; user-select: none; }
.drag-handle:active { cursor: grabbing; }
.link-move-form { display: inline-flex; align-items: center; gap: 5px; margin: 0; }
.iconbtn { width: 34px; height: 34px; padding: 0; border-radius: 11px; background: #e5e7eb; color: #111827; font-weight: 900; }
.chevron-btn { position: relative; }
.chevron-btn::before {
  content: "";
  width: 9px;
  height: 9px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  display: block;
}
.chevron-up::before { transform: rotate(225deg); margin-top: 5px; }
.chevron-down::before { transform: rotate(45deg); margin-bottom: 5px; }
.iconbtn:disabled { opacity: .35; cursor: not-allowed; }
.link-main {
  flex: 1 1 auto;
  min-width: 0;
}
.link-main small {
  display: block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
}
.link-status {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 14px;
  white-space: nowrap;
}
.link-edit-button {
  flex: 0 0 auto;
  white-space: nowrap;
}
.sort-save-state { min-height: 18px; margin: 6px 0 0; font-size: 13px; font-weight: 700; color: var(--muted); }
.sort-save-state[data-type="ok"] { color: var(--success); }
.sort-save-state[data-type="error"] { color: var(--danger); }
.sort-save-state[data-type="saving"] { color: var(--muted); }
@media (max-width: 740px) {
  .link-row {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 10px;
  }
  .link-order-controls { grid-row: 1 / span 2; align-self: start; }
  .link-main { align-self: center; }
  .link-status { grid-column: 2; }
  .link-edit-button { grid-column: 2; justify-self: start; }
}

/* Analytics */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 14px;
  margin: 18px 0 22px;
}
.stat-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 18px;
  box-shadow: 0 12px 30px rgba(17,24,39,.06);
}
.stat-card span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .05em;
}
.stat-card strong {
  display: block;
  margin-top: 8px;
  font-size: clamp(28px, 5vw, 42px);
  line-height: 1;
  letter-spacing: -.04em;
}
.analytics-grid {
  display: grid;
  grid-template-columns: minmax(260px, .8fr) minmax(320px, 1.2fr);
  gap: 16px;
  align-items: start;
}
.metric-list {
  display: grid;
  gap: 10px;
}
.metric-list > div {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}
.metric-list > div:last-child { border-bottom: 0; }
.metric-list span { color: var(--muted); font-weight: 700; }
.metric-list strong { font-size: 24px; }
.top-list {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.top-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px 12px;
  background: #f9fafb;
}
.top-list small {
  display: block;
  color: var(--muted);
  margin-top: 2px;
}
.top-list span {
  flex: 0 0 auto;
  font-weight: 900;
}
@media (max-width: 860px) {
  .analytics-grid { grid-template-columns: 1fr; }
}
