/* Shortlink panel. Tokens and layout follow the CF Panel (tutuk) so the two
   panels look and behave the same: sidebar, topbar, cards, light/dark. */
:root {
  --bg: #f4f5f7; --surface: #ffffff; --surface-2: #f7f8fa; --surface-3: #eef0f4;
  --ink: #131722; --ink-2: #414a5a; --muted: #5f6878; --line: #e4e7ec; --line-2: #d3d8e0;
  --primary: #2f5bea; --primary-2: #2449c4; --primary-soft: #e9eefe; --on-primary: #ffffff;
  --accent: #f6821f;
  --ok: #157a3c; --ok-bg: #e3f5ea; --warn: #8a5a00; --warn-bg: #fff1cc; --err: #b4231a; --err-bg: #fde7e5;
  --info: #1d4f91; --info-bg: #e6effc;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .04);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .14);
  --radius: 12px; --radius-sm: 8px;
  --fs-xs: 11.5px; --fs-sm: 12.5px; --fs-base: 13.5px; --fs-md: 14px; --fs-lg: 15px; --fs-xl: 18px; --fs-2xl: 22px; --fs-3xl: 28px;
  --mono: ui-monospace, "Cascadia Code", SFMono-Regular, Menlo, Consolas, monospace;
  --sans: Inter, "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, Roboto, "Noto Sans Thai", Arial, sans-serif;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0b0c0f; --surface: #181a20; --surface-2: #1e2128; --surface-3: #2a2e37;
  --ink: #f2f4f8; --ink-2: #cdd3dd; --muted: #a0a9b8; --line: #30353f; --line-2: #3e4450;
  --primary: #86abff; --primary-2: #a3c0ff; --primary-soft: rgba(134, 171, 255, .15); --on-primary: #0b0c0f;
  --ok: #6fe3a0; --ok-bg: rgba(111, 227, 160, .13); --warn: #ffd36e; --warn-bg: rgba(255, 211, 110, .14);
  --err: #ff9a92; --err-bg: rgba(255, 154, 146, .14); --info: #93bdff; --info-bg: rgba(147, 189, 255, .14);
  --shadow: inset 0 1px 0 rgba(255, 255, 255, .03), 0 1px 3px rgba(0, 0, 0, .45);
  --shadow-lg: 0 18px 44px rgba(0, 0, 0, .6);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body { font: 14px/1.5 var(--sans); color: var(--ink); background: var(--bg); -webkit-font-smoothing: antialiased; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; letter-spacing: -.01em; }
.ic { flex: none; vertical-align: -3px; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); font-size: var(--fs-sm); }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
:root[data-theme="dark"] .only-light, :root:not([data-theme="dark"]) .only-dark { display: none; }

/* ---------- layout: sidebar + main ---------- */
.layout { display: grid; grid-template-columns: 244px minmax(0, 1fr); min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 4px; padding: 16px 12px;
  background: var(--surface); border-right: 1px solid var(--line); z-index: 40; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: var(--fs-lg); color: var(--ink); padding: 6px 10px 18px; }
.brand:hover { text-decoration: none; }
.brand .dot { width: 28px; height: 28px; border-radius: 8px; background: var(--accent); display: grid; place-items: center; color: #fff; }
.brand small { display: block; font-weight: 500; font-size: var(--fs-xs); color: var(--muted); }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav .group-label { margin: 14px 11px 4px; font-size: var(--fs-xs); font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.nav a { display: flex; align-items: center; gap: 12px; padding: 9px 11px; border-radius: var(--radius-sm); color: var(--ink-2); font-weight: 550; }
.nav a:hover { background: var(--surface-3); text-decoration: none; color: var(--ink); }
.nav a.active { background: var(--primary-soft); color: var(--primary); }
.nav a.cta { margin: 2px 0 10px; background: var(--primary); color: var(--on-primary); justify-content: center; }
.nav a.cta:hover { background: var(--primary-2); color: var(--on-primary); }
.nav .count { margin-left: auto; min-width: 20px; padding: 0 6px; border-radius: 999px; background: var(--err-bg); color: var(--err);
  font-size: var(--fs-xs); font-weight: 700; text-align: center; line-height: 20px; }
.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 2px; border-top: 1px solid var(--line); padding-top: 10px; }
.side-foot button, .side-foot a { display: flex; align-items: center; gap: 12px; width: 100%; padding: 9px 11px; border: 0; background: none;
  border-radius: var(--radius-sm); color: var(--ink-2); font: inherit; font-weight: 550; cursor: pointer; text-align: left; }
.side-foot button:hover, .side-foot a:hover { background: var(--surface-3); color: var(--ink); text-decoration: none; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 10px; padding: 10px 28px;
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.topbar .search { position: relative; flex: 1; max-width: 460px; }
.topbar .search .ic { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.topbar .search input { padding-left: 36px; background: var(--surface); }
.topbar .spacer { flex: 1; }
.icon-btn { display: inline-grid; place-items: center; width: 36px; height: 36px; padding: 0; border-radius: var(--radius-sm); }
.menu-btn { display: none; }
.content { width: 100%; max-width: 1280px; margin: 0 auto; padding: 22px 28px 72px; }
.scrim { display: none; }

@media (max-width: 1100px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: fixed; left: 0; top: 0; width: 264px; transform: translateX(-105%); transition: transform .2s ease; box-shadow: var(--shadow-lg); }
  body.nav-open .sidebar { transform: none; }
  body.nav-open .scrim { display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, .45); z-index: 35; }
  .menu-btn { display: inline-grid; }
  .topbar { padding: 10px 14px; }
  .content { padding: 16px 14px 64px; }
}

/* account menu */
details.pop { position: relative; }
details.pop > summary { list-style: none; }
details.pop > summary::-webkit-details-marker { display: none; }
.avatar { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; background: var(--primary); color: var(--on-primary);
  font-weight: 700; font-size: var(--fs-sm); cursor: pointer; }
.pop-body { position: absolute; right: 0; top: calc(100% + 8px); min-width: 230px; z-index: 50; padding: 8px; box-shadow: var(--shadow-lg); }
.menu { display: flex; flex-direction: column; gap: 2px; margin: 0; }
.menu .me { display: flex; flex-direction: column; padding: 6px 10px 10px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.menu .me span { color: var(--muted); font-size: var(--fs-sm); }
.menu a, .menu button { justify-content: flex-start; width: 100%; }

/* ---------- page head ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h1 { font-size: var(--fs-2xl); font-weight: 700; }
.page-head p { margin: 4px 0 0; color: var(--muted); max-width: 760px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.crumb { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-weight: 600; font-size: var(--fs-sm); margin-bottom: 8px; }

/* ---------- cards ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; margin-bottom: 16px;
  box-shadow: var(--shadow); }
.card.flush { padding: 0; overflow: hidden; }
.card h2 { font-size: var(--fs-lg); font-weight: 650; margin: 0 0 12px; }
.card h2 small { color: var(--muted); font-weight: 400; margin-left: 8px; font-size: var(--fs-sm); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.card-head h2 { margin: 0; }
.card-body { padding: 16px 18px; }
.table-scroll { overflow-x: auto; }
.grid { display: grid; gap: 16px; }
.grid > * { min-width: 0; }
.grid > .card { margin-bottom: 0; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.split { grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); }
.grid + .card, .card + .grid, .grid + .grid { margin-top: 16px; }
@media (max-width: 1080px) { .grid.cols-2, .grid.split { grid-template-columns: minmax(0, 1fr); } }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { display: block; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px;
  box-shadow: var(--shadow); color: inherit; }
a.kpi:hover { border-color: var(--primary); text-decoration: none; }
.kpi .label { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: var(--fs-sm); font-weight: 600; }
.kpi .value { font-size: var(--fs-3xl); font-weight: 700; letter-spacing: -.02em; margin-top: 4px; line-height: 1.15; font-variant-numeric: tabular-nums; }
.kpi .sub { color: var(--muted); font-size: var(--fs-sm); margin-top: 4px; }
.kpi.ok .value { color: var(--ok); } .kpi.warn .value { color: var(--warn); } .kpi.err .value { color: var(--err); }

/* attention list */
.tasks { display: flex; flex-direction: column; }
.task { display: flex; align-items: center; gap: 12px; padding: 11px 18px; border-top: 1px solid var(--line); color: inherit; }
.task:first-child { border-top: 0; }
a.task:hover { background: var(--surface-2); text-decoration: none; }
.task .mark { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 9px; flex: none; }
.task.err .mark { background: var(--err-bg); color: var(--err); } .task.warn .mark { background: var(--warn-bg); color: var(--warn); }
.task.soft .mark { background: var(--surface-3); color: var(--ink-2); }
.task .go { margin-left: auto; color: var(--primary); font-weight: 600; white-space: nowrap; }
.empty { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 28px 18px; color: var(--muted); text-align: center; }
.empty .mark { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 12px; background: var(--ok-bg); color: var(--ok); }

/* ---------- tables ---------- */
table { width: 100%; border-collapse: collapse; font-size: var(--fs-base); }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child > td { border-bottom: 0; }
th { background: var(--surface-2); color: var(--muted); font-weight: 600; font-size: var(--fs-sm); white-space: nowrap; }
tbody tr:hover td { background: var(--surface-2); }
td .sub { display: block; color: var(--muted); font-size: var(--fs-sm); margin-top: 1px; }
.dname { font-weight: 600; color: var(--ink); }
a.dname:hover { color: var(--primary); }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: nowrap; }
.row-actions form { display: inline; }
.target { display: inline-block; max-width: 420px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: bottom; color: var(--ink-2); }

@media (max-width: 760px) {
  table.cards-sm thead { display: none; }
  table.cards-sm, table.cards-sm tbody { display: block; }
  table.cards-sm tr { display: grid; grid-template-columns: minmax(0, 1fr); gap: 2px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
  table.cards-sm tr:hover td { background: none; }
  table.cards-sm td { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 3px 0; border: 0; text-align: right; min-width: 0; }
  table.cards-sm td::before { content: attr(data-label); color: var(--muted); font-size: var(--fs-sm); font-weight: 600; flex: none; text-align: left; }
  table.cards-sm td.cell-main { display: block; text-align: left; padding-bottom: 6px; }
  table.cards-sm td.cell-main::before { display: none; }
  table.cards-sm td.act { justify-content: flex-start; padding-top: 8px; }
  table.cards-sm td.act::before { display: none; }
  .target { max-width: 220px; }
  .hide-sm { display: none !important; }
}

/* ---------- badges, chips ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px; font-size: var(--fs-sm); font-weight: 600;
  white-space: nowrap; line-height: 1.6; background: var(--surface-3); color: var(--muted); }
.badge.ok { background: var(--ok-bg); color: var(--ok); } .badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.err { background: var(--err-bg); color: var(--err); } .badge.info { background: var(--info-bg); color: var(--info); }
.badge.primary { background: var(--primary-soft); color: var(--primary); }
.badge .pip { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.isp { display: inline-flex; gap: 4px; flex-wrap: wrap; }
.isp span { padding: 1px 7px; border-radius: 6px; font-size: var(--fs-xs); font-weight: 700; background: var(--surface-3); color: var(--muted); }
.isp .OK { background: var(--ok-bg); color: var(--ok); }
.isp .SUSPICIOUS { background: var(--warn-bg); color: var(--warn); }
.isp .LIKELY_BLOCKED { background: var(--err-bg); color: var(--err); }
.seg { display: inline-flex; padding: 3px; border-radius: 10px; background: var(--surface-3); gap: 2px; flex-wrap: wrap; }
.seg a { padding: 5px 12px; border-radius: 7px; color: var(--muted); font-weight: 600; font-size: var(--fs-base); white-space: nowrap; }
.seg a:hover { color: var(--ink); text-decoration: none; }
.seg a.active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.seg a .n { margin-left: 4px; color: var(--muted); font-weight: 500; }

/* ---------- buttons ---------- */
button, .btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 8px 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--line-2); background: var(--surface); color: var(--ink); font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap; }
button:hover, .btn:hover { background: var(--surface-3); text-decoration: none; }
button:focus-visible, .btn:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--primary); outline-offset: 2px; }
.btn.primary, button.primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn.primary:hover, button.primary:hover { background: var(--primary-2); border-color: var(--primary-2); }
.btn.danger, button.danger { color: var(--err); border-color: color-mix(in srgb, var(--err) 35%, var(--line)); }
.btn.danger:hover, button.danger:hover { background: var(--err-bg); }
.btn.ghost, button.ghost { border-color: transparent; background: none; color: var(--ink-2); }
.btn.ghost:hover, button.ghost:hover { background: var(--surface-3); }
.btn.sm, button.sm { padding: 4px 10px; font-size: var(--fs-sm); border-radius: 7px; }
button.copied { color: var(--ok); border-color: var(--ok); }

/* ---------- forms ---------- */
label { display: block; font-size: var(--fs-sm); font-weight: 600; color: var(--ink-2); margin: 12px 0 6px; }
input[type=text], input[type=password], input[type=search], select, textarea {
  width: 100%; padding: 8px 11px; border: 1px solid var(--line-2); border-radius: var(--radius-sm); font: inherit; background: var(--surface); color: var(--ink); }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: .8; }
textarea { min-height: 96px; font-family: var(--mono); font-size: var(--fs-base); resize: vertical; }
.help { color: var(--muted); font-size: var(--fs-sm); margin-top: 4px; }
.form-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 14px; }
.form-grid .span-2 { grid-column: span 2; }
@media (max-width: 860px) { .form-grid { grid-template-columns: minmax(0, 1fr); } .form-grid .span-2 { grid-column: auto; } }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; flex-wrap: wrap; }
.prefix { display: flex; align-items: stretch; }
.prefix span { display: flex; align-items: center; padding: 0 10px; border: 1px solid var(--line-2); border-right: 0; border-radius: var(--radius-sm) 0 0 var(--radius-sm);
  background: var(--surface-2); color: var(--muted); font-size: var(--fs-sm); white-space: nowrap; }
.prefix input { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.toolbar .grow { flex: 1; min-width: 180px; position: relative; }
.toolbar .grow .ic { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.toolbar .grow input { padding-left: 34px; }
.toolbar select { width: auto; min-width: 140px; }

/* ---------- notices ---------- */
.notice { display: flex; align-items: center; gap: 10px; padding: 11px 14px; border-radius: var(--radius-sm); margin-bottom: 16px; font-weight: 550; }
.notice.ok { background: var(--ok-bg); color: var(--ok); }
.notice.err { background: var(--err-bg); color: var(--err); }
.notice.warn { background: var(--warn-bg); color: var(--warn); }

/* ---------- short link cell ---------- */
.short { display: flex; align-items: center; gap: 8px; min-width: 0; }
.short a.dname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.short .fav { width: 30px; height: 30px; border-radius: 8px; background: var(--primary-soft); color: var(--primary); display: grid; place-items: center; flex: none; }

/* ---------- groups ---------- */
.groups { display: grid; grid-template-columns: repeat(auto-fill, minmax(360px, 1fr)); gap: 16px; }
@media (max-width: 760px) { .groups { grid-template-columns: minmax(0, 1fr); } }
.groups .card { margin: 0; display: flex; flex-direction: column; }
.members { list-style: none; margin: 0; padding: 0; }
.members li { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-top: 1px solid var(--line); }
.members li:first-child { border-top: 0; }
.members .dname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.members .live { color: var(--ok); font-weight: 700; font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: .05em; }
.group-foot { margin-top: auto; padding-top: 12px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; border-top: 1px solid var(--line); }
details.edit > summary { list-style: none; }
details.edit > summary::-webkit-details-marker { display: none; }
details.edit[open] { flex-basis: 100%; }

/* ---------- login ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth .card { width: min(400px, 100%); padding: 28px; }
.auth .brand { justify-content: center; padding: 0 0 6px; font-size: var(--fs-xl); }
.auth p.lead { text-align: center; color: var(--muted); margin: 0 0 8px; }
.auth button.primary { width: 100%; margin-top: 18px; padding: 10px; }

footer.foot { padding: 0 28px 24px; color: var(--muted); font-size: var(--fs-sm); }


/* ---------- stats ---------- */
.chart { width: 100%; }
.chart svg { display: block; }
.chart .bar { fill: var(--primary); opacity: .85; }
.chart .bar:hover { opacity: 1; fill: var(--accent); }
.chart-axis { display: flex; justify-content: space-between; color: var(--muted); font-size: var(--fs-xs); margin-top: 4px; }
.ranked { list-style: none; margin: 0; padding: 0; }
.ranked li { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 10px; padding: 8px 18px; border-top: 1px solid var(--line); }
.ranked li:first-child { border-top: 0; }
.ranked .k { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 550; }
.ranked .v { font-variant-numeric: tabular-nums; font-weight: 700; }
.ranked .meter { grid-column: 1 / -1; height: 4px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.ranked .meter i { display: block; height: 100%; background: var(--primary); border-radius: 999px; }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 1080px) { .grid.cols-3 { grid-template-columns: minmax(0, 1fr); } }
.status-line { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-radius: var(--radius); margin-bottom: 16px; font-weight: 600; }
.status-line.ok { background: var(--ok-bg); color: var(--ok); }
.status-line.err { background: var(--err-bg); color: var(--err); }
.status-line.warn { background: var(--warn-bg); color: var(--warn); }
.foot-note { color: var(--muted); font-size: var(--fs-sm); margin-top: 6px; }
.steps { margin: 8px 0 0; padding-left: 20px; }
.steps li { margin: 6px 0; }
.kpis.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 900px) { .kpis.four { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
