:root {
  --bg: #f5f6fb;
  --card: #ffffff;
  --text: #1b2130;
  --muted: #667085;
  --line: #e5e7ef;
  --soft: #eef0fb;
  --brand: #4f46e5;
  --brand-ink: #ffffff;
  --accent: #0ea5e9;
  --ok: #12a150;
  --err: #d92d20;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 8px 24px rgba(16, 24, 40, .06);
  --radius: 16px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1117;
    --card: #161b24;
    --text: #e7ebf3;
    --muted: #9aa4b5;
    --line: #283041;
    --soft: #1d2433;
    --brand: #8b85ff;
    --brand-ink: #0e1117;
    --accent: #38bdf8;
    --ok: #3ccf7a;
    --err: #ff6b5e;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'IBM Plex Sans Thai', system-ui, -apple-system, 'Segoe UI', sans-serif;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
.wrap { max-width: 1040px; margin: 0 auto; padding: 0 16px; }

header.top { border-bottom: 1px solid var(--line); background: var(--card); }
header.top .wrap { display: flex; align-items: center; justify-content: space-between; height: 60px; }
.logo { font-weight: 700; font-size: 20px; color: var(--text); display: flex; align-items: center; gap: 8px; }
.logo:hover { text-decoration: none; }
.logo b { color: var(--brand); }
.logo-mark { width: 30px; height: 30px; border-radius: 9px; background: var(--brand); color: var(--brand-ink); display: grid; place-items: center; font-size: 16px; }
nav a { color: var(--muted); margin-left: 18px; font-size: 15px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.hero { text-align: center; padding: 56px 0 28px; }
.hero h1 { font-size: clamp(28px, 5vw, 42px); line-height: 1.25; margin: 0 0 10px; letter-spacing: -.01em; }
.hero p { color: var(--muted); margin: 0; font-size: 17px; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 14px; color: var(--muted); }
input[type=text], input[type=url], input[type=password], input[type=search] {
  width: 100%; font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; outline: none;
}
input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 20%, transparent); }
.prefix { display: flex; align-items: stretch; }
.prefix span { background: var(--soft); border: 1px solid var(--line); border-right: 0; border-radius: 12px 0 0 12px; padding: 12px; color: var(--muted); white-space: nowrap; font-size: 15px; }
.prefix input { border-radius: 0 12px 12px 0; }

.btn {
  font: inherit; font-weight: 600; cursor: pointer; border: 1px solid transparent; border-radius: 12px;
  padding: 12px 20px; background: var(--brand); color: var(--brand-ink); white-space: nowrap;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn:hover { filter: brightness(1.07); text-decoration: none; }
.btn:disabled { opacity: .6; cursor: wait; }
.btn.ghost { background: transparent; color: var(--text); border-color: var(--line); }
.btn.sm { padding: 6px 12px; font-size: 14px; border-radius: 9px; }
.btn.danger { background: transparent; color: var(--err); border-color: var(--line); }

.shorten-form { display: grid; gap: 14px; max-width: 720px; margin: 0 auto; }
.row { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: end; }
.msg { font-size: 14px; min-height: 20px; }
.msg.err { color: var(--err); }

.result { max-width: 720px; margin: 16px auto 0; display: none; grid-template-columns: 1fr auto; gap: 20px; align-items: center; }
.result.show { display: grid; }
.short-url { font-size: 22px; font-weight: 700; word-break: break-all; }
.orig { color: var(--muted); font-size: 14px; word-break: break-all; margin: 2px 0 12px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.qr { width: 132px; text-align: center; }
.qr svg { width: 132px; height: 132px; background: #fff; border-radius: 10px; padding: 4px; }
.qr a { font-size: 13px; }

.features { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin: 40px 0; }
.features h3 { margin: 6px 0 4px; font-size: 17px; }
.features p { margin: 0; color: var(--muted); font-size: 15px; }
.icon { font-size: 26px; }

h2.section { font-size: 19px; margin: 32px 0 12px; }
table { width: 100%; border-collapse: collapse; font-size: 15px; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--muted); font-weight: 500; font-size: 13px; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.truncate { max-width: 340px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }
.table-wrap { overflow-x: auto; }
.empty { color: var(--muted); text-align: center; padding: 20px 0; margin: 0; }

/* stats */
.stats-head { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; flex-wrap: wrap; margin: 28px 0 16px; }
.stats-head h1 { margin: 0; font-size: 26px; word-break: break-all; }
.seg { display: inline-flex; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 3px; }
.seg button { font: inherit; font-size: 14px; border: 0; background: transparent; color: var(--muted); padding: 6px 12px; border-radius: 9px; cursor: pointer; }
.seg button.on { background: var(--brand); color: var(--brand-ink); }
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.kpi .label { color: var(--muted); font-size: 14px; }
.kpi .value { font-size: 30px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.3; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 12px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 12px; }
.card h3 { margin: 0 0 12px; font-size: 16px; }
.chart-box { position: relative; height: 260px; }
.mt { margin-top: 12px; }

.bar-row { position: relative; display: flex; justify-content: space-between; gap: 10px; padding: 7px 10px; margin-bottom: 5px; border-radius: 8px; overflow: hidden; font-size: 15px; }
.bar-fill { position: absolute; inset: 0 auto 0 0; background: var(--soft); z-index: 0; border-radius: 8px; }
.bar-row span { position: relative; z-index: 1; }
.bar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-val { font-variant-numeric: tabular-nums; white-space: nowrap; }
.bar-val small { color: var(--muted); margin-left: 4px; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 10px; opacity: 0; transition: .2s; pointer-events: none; font-size: 15px; }
.toast.show { opacity: 1; transform: translateX(-50%); }

footer { color: var(--muted); font-size: 14px; text-align: center; padding: 40px 0; }

@media (max-width: 760px) {
  .row { grid-template-columns: 1fr; }
  .result { grid-template-columns: 1fr; }
  .qr { margin: 0 auto; }
  .features, .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: 1fr 1fr; }
  .kpi .value { font-size: 24px; }
  .truncate { max-width: 160px; }
  nav a { margin-left: 12px; }
}

/* ---------- ระบบสมาชิก ---------- */
nav { display: flex; align-items: center; gap: 16px; }
nav a { margin-left: 0; }
nav a.btn { color: var(--brand-ink); }
.nav-user:hover { text-decoration: none; }
.avatar { width: 64px; height: 64px; border-radius: 50%; background: var(--brand); color: var(--brand-ink); display: grid; place-items: center; font-weight: 700; font-size: 26px; flex: none; }
.avatar.sm { width: 32px; height: 32px; font-size: 14px; }

.auth-wrap { max-width: 420px; margin: 48px auto; }
.auth-wrap h1 { font-size: 26px; margin: 0 0 4px; text-align: center; }
.auth-wrap .sub { color: var(--muted); text-align: center; margin: 0 0 20px; }
.auth-form { display: grid; gap: 14px; }
.auth-form .btn { width: 100%; }
.auth-foot { text-align: center; color: var(--muted); font-size: 15px; margin-top: 16px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 15px; color: var(--muted); }
.pw-wrap { position: relative; }
.pw-wrap input { padding-right: 64px; }
.pw-toggle { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); background: none; border: 0; color: var(--brand); font: inherit; font-size: 14px; cursor: pointer; }
.hp { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }
.hint { font-size: 13px; color: var(--muted); }
input.invalid { border-color: var(--err); }
.msg.ok { color: var(--ok); }

.app { display: grid; grid-template-columns: 220px 1fr; gap: 20px; margin: 24px 0 40px; }
.side { display: flex; flex-direction: column; gap: 4px; position: sticky; top: 16px; align-self: start; }
.side a, .side button { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px; color: var(--text); font: inherit; font-size: 15px; background: none; border: 0; cursor: pointer; text-align: left; }
.side a:hover, .side button:hover { background: var(--soft); text-decoration: none; }
.side a.on { background: var(--brand); color: var(--brand-ink); }
.side .who { display: flex; align-items: center; gap: 10px; padding: 8px 12px 14px; border-bottom: 1px solid var(--line); margin-bottom: 8px; }
.side .who b { display: block; line-height: 1.3; word-break: break-all; }
.side .who small { color: var(--muted); }
.app-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.app-head h1 { margin: 0; font-size: 24px; }
.quick { display: grid; grid-template-columns: 1fr 200px auto; gap: 10px; }
.link-row .short a { font-weight: 600; }
.link-row .dest { color: var(--muted); font-size: 13px; max-width: 360px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
.qr-pop { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: none; place-items: center; z-index: 50; padding: 16px; }
.qr-pop.show { display: grid; }
.qr-pop .card { text-align: center; max-width: 320px; width: 100%; }
.qr-pop svg { width: 220px; height: 220px; background: #fff; border-radius: 12px; padding: 6px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }
.profile-head { display: flex; align-items: center; gap: 16px; }
.profile-head h2 { margin: 0; font-size: 22px; }
.profile-head p { margin: 2px 0 0; color: var(--muted); }

@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .side { position: static; flex-direction: row; overflow-x: auto; }
  .side .who { display: none; }
  .quick, .form-grid { grid-template-columns: 1fr; }
  nav { gap: 10px; font-size: 14px; }
  .link-row .dest { max-width: 180px; }
}

@media (max-width: 760px) {
  .side { padding: 6px; gap: 2px; }
  .side a, .side button { white-space: nowrap; padding: 8px 10px; font-size: 14px; }
  nav a.nav-link-hide { display: none; }
}
