:root {
  --bg: #f6f7fb; --card: #fff; --text: #14161f; --muted: #6b7085; --line: #e4e6ee;
  --accent: #4f46e5; --accent-2: #4338ca; --accent-soft: #eef0ff;
  --ok: #0f8a5f; --ok-soft: #e7f7f0; --bad: #c62f3b; --bad-soft: #fdecee; --warn: #a76100; --warn-soft: #fff4e0;
  --radius: 12px; --shadow: 0 1px 2px rgba(20,22,31,.05), 0 4px 16px rgba(20,22,31,.04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1016; --card: #171a23; --text: #e9eaf0; --muted: #8d92a6; --line: #262a37;
    --accent: #7c74ff; --accent-2: #9a94ff; --accent-soft: #23234a;
    --ok: #3ecf8e; --ok-soft: #10291f; --bad: #ff6b76; --bad-soft: #321519; --warn: #f0b04a; --warn-soft: #2e2311;
    --shadow: none; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
h1, h2, h3 { margin: 0 0 .5em; line-height: 1.25; }
h3 { font-size: 15px; }
.h2 { font-size: 22px; }
.wrap { max-width: 1080px; margin: 0 auto; padding: 0 16px; }
.row { display: flex; align-items: center; gap: 12px; }
.between { justify-content: space-between; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { display: flex; justify-content: center; }
.center-text { text-align: center; }
.trunc { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.err { color: var(--bad); margin: .5em 0; }
.hp { position: absolute; left: -9999px; }

/* header */
.top { background: var(--card); border-bottom: 1px solid var(--line); }
.top .row { height: 58px; justify-content: space-between; }
.brand { font-weight: 650; color: var(--text); display: flex; align-items: center; gap: 10px; font-size: 16px; }
.brand:hover { text-decoration: none; }
.logo { width: 26px; height: 26px; border-radius: 7px; background: var(--accent) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Cpath d='M13 19l6-6M11 15l-2 2a4 4 0 006 6l2-2M21 17l2-2a4 4 0 00-6-6l-2 2' stroke='white' stroke-width='2.4' fill='none' stroke-linecap='round'/%3E%3C/svg%3E") center/100%; }
.nav { display: flex; gap: 4px; align-items: center; }
.nav a, .nav .link { padding: 6px 10px; border-radius: 8px; color: var(--muted); font-size: 14px; }
.nav a.on { color: var(--text); background: var(--bg); }
.nav a:hover { text-decoration: none; color: var(--text); }
.nav form { margin: 0; }
button.link { background: none; border: 0; cursor: pointer; font: inherit; }
main.wrap { padding-top: 28px; padding-bottom: 40px; min-height: 70vh; }
.foot { color: var(--muted); font-size: 12px; padding-bottom: 24px; text-align: center; }

/* cards, forms */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); margin-bottom: 16px; }
.narrow { max-width: 440px; margin: 6vh auto; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.stack > * { margin: 0; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 550; }
label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 450; }
input, select, textarea {
  font: inherit; font-size: 15px; color: var(--text); background: var(--bg); border: 1px solid var(--line);
  border-radius: 9px; padding: 9px 11px; width: 100%; min-width: 0;
}
input[type=checkbox] { width: auto; accent-color: var(--accent); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
textarea { resize: vertical; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 16px; border-radius: 9px;
  border: 1px solid var(--line); background: var(--card); color: var(--text); font: inherit; font-size: 14px; font-weight: 550;
  cursor: pointer; white-space: nowrap; text-decoration: none !important;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-2); }
.btn.danger { color: var(--bad); }
.btn.danger:hover { border-color: var(--bad); }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn.block { width: 100%; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.actions form { margin: 0; }
details summary { cursor: pointer; color: var(--muted); font-size: 13px; margin: 10px 0; }
.flash { padding: 10px 14px; border-radius: 10px; margin-bottom: 16px; background: var(--ok-soft); color: var(--ok); font-weight: 550; overflow-wrap: anywhere; }
.flash.err-bg { background: var(--bad-soft); color: var(--bad); }
.badge { font-size: 11px; font-weight: 650; text-transform: uppercase; letter-spacing: .03em; padding: 2px 7px; border-radius: 99px; background: var(--accent-soft); color: var(--accent); }
.badge.disabled, .badge.expired, .badge.limit { background: var(--bad-soft); color: var(--bad); }
.code-block { background: var(--bg); border: 1px solid var(--line); border-radius: 9px; padding: 10px; overflow-x: auto; margin: 0; white-space: pre; }

/* home */
.hero { max-width: 680px; margin: 6vh auto 0; text-align: center; }
.hero h1 { font-size: clamp(26px, 5vw, 38px); letter-spacing: -.02em; }
.shorten { text-align: left; margin-top: 24px; }
.shorten-row { display: flex; gap: 8px; }
.shorten-row input { font-size: 16px; padding: 12px 14px; }
.alias { flex-direction: row; align-items: center; gap: 0; font-weight: 450; }
.alias span { color: var(--muted); font-size: 14px; padding-right: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 55%; }
.result { display: flex; gap: 18px; align-items: center; text-align: left; }
.result-main { flex: 1; min-width: 0; }
.short { font-size: 20px; font-weight: 650; overflow-wrap: anywhere; }
.qr canvas, .qr img { display: block; border-radius: 8px; background: #fff; padding: 8px; max-width: 100%; height: auto; }
.qr canvas { display: none; }
.dest { background: var(--bg); padding: 10px 12px; border-radius: 9px; overflow-wrap: anywhere; font-family: ui-monospace, Menlo, monospace; font-size: 13px; }

/* admin */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.tile span { display: block; color: var(--muted); font-size: 12px; }
.tile strong { font-size: 24px; font-weight: 650; letter-spacing: -.01em; }
.grid-create { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 12px; margin-bottom: 4px; }
.create > .btn { margin-top: 8px; }
.toolbar { display: flex; gap: 8px; margin: 22px 0 12px; }
.search { display: flex; gap: 8px; flex: 1; }
.search input { flex: 1; }
.search select { width: auto; }
.list .item { display: flex; align-items: center; gap: 16px; padding: 14px 16px; margin-bottom: 8px; }
.item.is-new { border-color: var(--accent); }
.item-main { flex: 1; min-width: 0; }
.item-top { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.code { font-weight: 650; font-size: 15px; }
.item-title { font-size: 14px; }
.item-clicks { text-align: right; min-width: 56px; }
.item-clicks strong { display: block; font-size: 18px; }
.item-clicks span { font-size: 11px; color: var(--muted); }
.item-actions { display: flex; gap: 6px; }
.empty { text-align: center; color: var(--muted); padding: 40px; }
.pager { display: flex; gap: 12px; align-items: center; justify-content: center; margin-top: 16px; }
dialog { border: 1px solid var(--line); color: var(--text); max-width: 340px; width: calc(100% - 32px); }
dialog::backdrop { background: rgba(0,0,0,.45); }
dialog .short { font-size: 15px; text-align: center; }

/* link page */
.head-row { display: flex; justify-content: space-between; gap: 16px; align-items: flex-end; margin-bottom: 18px; }
.head-row > div:first-child { min-width: 0; }
.head-row h1 { margin: 6px 0 2px; overflow-wrap: anywhere; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.head-row p { margin: 0; }
.split { display: grid; grid-template-columns: 1fr 320px; gap: 16px; align-items: start; }
.split .tiles { grid-template-columns: repeat(4, 1fr); }
h2.section { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 22px 0 10px; }
.note { margin: -6px 0 14px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.grid2.top { align-items: start; }
.seg { display: flex; background: var(--bg); border-radius: 8px; padding: 2px; }
.seg a { padding: 3px 10px; font-size: 12px; color: var(--muted); border-radius: 6px; }
.seg a.on { background: var(--card); color: var(--text); box-shadow: var(--shadow); }
.seg a:hover { text-decoration: none; }
.chart { display: flex; align-items: flex-end; gap: 2px; height: 160px; margin: 14px 0 6px; border-bottom: 1px solid var(--line); }
.chart .col { flex: 1; height: 100%; display: flex; align-items: flex-end; }
.chart .col span { width: 100%; background: var(--accent); border-radius: 3px 3px 0 0; min-height: 1px; opacity: .85; }
.chart .col:hover span { opacity: 1; }
.bars { list-style: none; margin: 0; padding: 0; }
.bars li { position: relative; display: flex; justify-content: space-between; gap: 8px; padding: 6px 8px; font-size: 13px; border-radius: 6px; overflow: hidden; }
.bars .bar { position: absolute; inset: 0 auto 0 0; background: var(--accent-soft); z-index: 0; }
.bars .k, .bars .n { position: relative; z-index: 1; }
.bars .k { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bars .n { font-weight: 650; }
.qr-card { display: flex; justify-content: center; }
.results { list-style: none; padding: 0; margin: 0; }
.results li { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; border-top: 1px solid var(--line); font-size: 13px; }
.results li.bad strong { color: var(--bad); font-weight: 500; }

@media (max-width: 860px) {
  .split { grid-template-columns: 1fr; }
  .grid2 { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .grid-create { grid-template-columns: 1fr; }
  .shorten-row { flex-direction: column; }
  .result { flex-direction: column; align-items: stretch; }
  .result .qr { align-self: center; }
  .toolbar, .search { flex-wrap: wrap; }
  .search input { flex-basis: 100%; }
  .list .item { flex-wrap: wrap; }
  .item-actions { width: 100%; }
  .item-actions .btn { flex: 1; }
  .head-row { flex-direction: column; align-items: stretch; }
  .split .tiles { grid-template-columns: 1fr 1fr; }
  .tile strong { font-size: 20px; }
  .nav a, .nav .link { padding: 6px 7px; }
}
