/* ============================================================
   短链工坊 —— 样式表
   ============================================================ */
:root {
  --bg: #f4f5fa;
  --surface: #ffffff;
  --surface-2: #fafbfe;
  --ink: #131722;
  --ink-2: #5a6474;
  --ink-3: #8b95a7;
  --line: #e7e9f2;
  --line-strong: #d8dbe8;
  --accent: #4f46e5;
  --accent-2: #7c3aed;
  --accent-soft: #eef0ff;
  --ok: #059669;
  --ok-soft: #e8f8f1;
  --warn: #b45309;
  --warn-soft: #fdf4e3;
  --danger: #dc2626;
  --danger-soft: #fdeeee;
  --radius: 18px;
  --radius-sm: 11px;
  --shadow-1: 0 1px 2px rgba(19, 23, 34, .04), 0 8px 24px -18px rgba(19, 23, 34, .35);
  --shadow-2: 0 24px 60px -24px rgba(19, 23, 34, .3);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Noto Sans SC", sans-serif;
  --mono: ui-monospace, SFMono-Regular, "JetBrains Mono", "Cascadia Mono", Consolas, monospace;
}

* { box-sizing: border-box; }

/* 作者样式常会覆盖 hidden 的默认 display，这里强制生效 */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  background:
    radial-gradient(1100px 520px at 8% -8%, #ecebff 0%, rgba(236, 235, 255, 0) 62%),
    radial-gradient(900px 460px at 100% 0%, #e9f4ff 0%, rgba(233, 244, 255, 0) 55%),
    var(--bg);
  background-attachment: fixed;
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  font-size: 14px;
  line-height: 1.6;
}

h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
p { margin: 0; }
a { color: var(--accent); }
button { font-family: inherit; }
.muted { color: var(--ink-2); }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 6px;
}

/* ---------------------------------------------------- 品牌 / 顶栏 */
.brand { display: flex; align-items: center; gap: 12px; }
.brand strong { display: block; font-size: 15px; letter-spacing: -.01em; }
.brand small { display: block; font-size: 11px; color: var(--ink-3); letter-spacing: .04em; }
.brand-mark {
  width: 38px; height: 38px; flex: 0 0 38px;
  display: grid; place-items: center;
  border-radius: 12px;
  color: #fff;
  background: linear-gradient(140deg, var(--accent) 0%, var(--accent-2) 100%);
  box-shadow: 0 8px 18px -10px rgba(79, 70, 229, .9);
}
.brand-mark svg { width: 21px; height: 21px; }
.brand-lg { justify-content: center; margin-bottom: 26px; }
.brand-lg strong { font-size: 17px; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  background: rgba(255, 255, 255, .78);
  backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  max-width: 1180px; margin: 0 auto;
  padding: 14px 24px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
}
.topbar-actions { display: flex; gap: 10px; }

/* ---------------------------------------------------- 布局 */
.page {
  max-width: 1180px;
  margin: 0 auto;
  padding: 28px 24px 56px;
  display: flex; flex-direction: column; gap: 20px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-1);
}

/* ---------------------------------------------------- 按钮 */
.btn {
  appearance: none; cursor: pointer;
  border: 1px solid transparent;
  border-radius: 11px;
  padding: 10px 18px;
  font-size: 14px; font-weight: 600;
  transition: transform .12s ease, box-shadow .18s ease, background .18s ease, border-color .18s ease;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .6; cursor: not-allowed; transform: none; }
.btn-primary {
  color: #fff;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-2) 100%);
  box-shadow: 0 10px 22px -14px rgba(79, 70, 229, 1);
}
.btn-primary:hover:not(:disabled) { box-shadow: 0 14px 26px -12px rgba(79, 70, 229, .85); }
.btn-soft {
  color: var(--accent);
  background: var(--accent-soft);
  border-color: #dfe2ff;
}
.btn-soft:hover:not(:disabled) { background: #e5e8ff; }
.btn-ghost {
  color: var(--ink-2);
  background: var(--surface);
  border-color: var(--line-strong);
}
.btn-ghost:hover:not(:disabled) { color: var(--ink); border-color: #c3c8d8; background: var(--surface-2); }
.btn-block { width: 100%; padding: 12px; }
.btn-sm { padding: 6px 12px; font-size: 12.5px; border-radius: 9px; }

.icon-btn {
  appearance: none; background: transparent; border: 0; cursor: pointer;
  width: 30px; height: 30px; border-radius: 8px;
  font-size: 20px; line-height: 1; color: var(--ink-3);
  display: grid; place-items: center;
}
.icon-btn:hover { background: var(--bg); color: var(--ink); }

/* ---------------------------------------------------- 表单 */
.field { display: flex; flex-direction: column; gap: 7px; }
.field > span { font-size: 12.5px; font-weight: 600; color: var(--ink-2); }
.field > small { font-size: 12px; }

input[type="text"], input[type="search"], input[type="password"],
input[type="datetime-local"], select, textarea {
  width: 100%;
  font-family: inherit; font-size: 14px; color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  transition: border-color .16s ease, box-shadow .16s ease, background .16s ease;
}
textarea { resize: vertical; line-height: 1.6; font-family: var(--mono); font-size: 13px; }
input::placeholder, textarea::placeholder { color: var(--ink-3); }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3.5px rgba(79, 70, 229, .13);
}
select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%235a6474' stroke-width='2.5' stroke-linecap='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 34px;
}

.form-error {
  margin-top: 10px;
  font-size: 13px;
  color: var(--danger);
  background: var(--danger-soft);
  border: 1px solid #f6d5d5;
  border-radius: 10px;
  padding: 9px 12px;
}

/* ---------------------------------------------------- 登录 */
.login-wrap { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.login-card {
  width: 100%; max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 36px 32px 32px;
  box-shadow: var(--shadow-2);
}
.login-card h1 { font-size: 20px; margin-bottom: 6px; }
.login-card p.muted { font-size: 13px; margin-bottom: 22px; }
.login-card .field { margin-bottom: 16px; }

/* ---------------------------------------------------- 创建区 */
.create-card { padding: 24px; }
.create-head { margin-bottom: 16px; display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.create-head h2 { font-size: 17px; }
.create-head p { font-size: 13px; }

.url-row { display: flex; gap: 12px; align-items: stretch; }
.url-input-wrap { position: relative; flex: 1; min-width: 0; }
.url-icon {
  position: absolute; left: 14px; top: 50%; transform: translateY(-50%);
  width: 18px; height: 18px; color: var(--ink-3); pointer-events: none;
}
.url-input-wrap input {
  padding: 14px 14px 14px 42px;
  font-size: 15px;
  border-radius: 13px;
  background: var(--surface-2);
}
.url-row .btn { padding: 0 26px; border-radius: 13px; font-size: 15px; }

.options { margin-top: 14px; }
.options > summary {
  cursor: pointer;
  list-style: none;
  font-size: 13px; font-weight: 600; color: var(--ink-2);
  display: inline-flex; align-items: center; gap: 8px;
  padding: 4px 0;
  user-select: none;
}
.options > summary::-webkit-details-marker { display: none; }
.options > summary::before {
  content: "";
  width: 6px; height: 6px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor;
  transform: rotate(-45deg); transition: transform .18s ease; margin-top: -2px;
}
.options[open] > summary::before { transform: rotate(45deg); }
.options > summary .muted { font-weight: 400; }
.options-grid {
  margin-top: 14px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  padding: 16px;
  background: var(--surface-2);
  border: 1px dashed var(--line-strong);
  border-radius: 14px;
}
.input-affix { display: flex; align-items: stretch; }
.input-affix .affix {
  display: grid; place-items: center;
  padding: 0 10px;
  font-family: var(--mono); font-size: 13px;
  color: var(--ink-3);
  background: #f1f3fa;
  border: 1px solid var(--line-strong);
  border-right: 0;
  border-radius: var(--radius-sm) 0 0 var(--radius-sm);
  white-space: nowrap; max-width: 46%; overflow: hidden;
}
.input-affix input { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; font-family: var(--mono); }

/* 生成结果条 */
.result {
  margin-top: 18px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px 16px 14px 18px;
  border-radius: 14px;
  border: 1px solid #cfd4ff;
  background: linear-gradient(120deg, #f2f3ff 0%, #f6f2ff 100%);
  animation: pop .28s ease both;
}
@keyframes pop {
  from { opacity: 0; transform: translateY(-6px) scale(.99); }
  to { opacity: 1; transform: none; }
}
.result-label { display: block; font-size: 11.5px; letter-spacing: .08em; color: var(--accent); font-weight: 700; text-transform: uppercase; }
.result-url {
  font-family: var(--mono); font-size: 16px; font-weight: 600;
  color: var(--ink); text-decoration: none;
  word-break: break-all;
}
.result-url:hover { text-decoration: underline; }
.result-actions { display: flex; gap: 8px; flex: 0 0 auto; }

/* ---------------------------------------------------- KPI */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
}
.kpi {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow-1);
  display: flex; flex-direction: column; gap: 2px;
}
.kpi-label { font-size: 12.5px; color: var(--ink-2); font-weight: 600; }
.kpi strong { font-size: 28px; line-height: 1.25; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.kpi small { font-size: 12px; }

/* ---------------------------------------------------- 列表 */
.list-card { overflow: hidden; }
.list-head {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.segmented {
  display: inline-flex; gap: 2px; padding: 3px;
  background: #f1f3fa; border-radius: 11px;
}
.seg {
  appearance: none; border: 0; cursor: pointer;
  background: transparent; color: var(--ink-2);
  font-size: 13px; font-weight: 600;
  padding: 7px 14px; border-radius: 8px;
  transition: background .16s ease, color .16s ease, box-shadow .16s ease;
}
.seg:hover { color: var(--ink); }
.seg.is-active { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(19, 23, 34, .1); }

.list-tools { display: flex; align-items: center; gap: 8px; }
.search { position: relative; }
.search svg {
  position: absolute; left: 11px; top: 50%; transform: translateY(-50%);
  width: 15px; height: 15px; color: var(--ink-3); pointer-events: none;
}
.search input {
  width: 230px; padding: 8px 12px 8px 33px;
  font-size: 13px; border-radius: 10px; background: var(--surface-2);
}

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th {
  text-align: left; font-size: 12px; font-weight: 600; color: var(--ink-3);
  letter-spacing: .03em;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
  white-space: nowrap;
}
.table td {
  padding: 14px 16px;
  border-bottom: 1px solid #f0f1f7;
  vertical-align: middle;
}
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr { transition: background .14s ease; }
.table tbody tr:hover { background: #fbfbff; }
.col-short { width: 190px; }
.col-clicks { width: 110px; }
.col-owner { width: 110px; color: var(--muted, #8a93a6); }
.col-status { width: 116px; }
.col-time { width: 132px; }
.col-actions { width: 210px; text-align: right; }

.short-cell { display: flex; align-items: center; gap: 8px; }
.short-link {
  font-family: var(--mono); font-weight: 600; font-size: 13.5px;
  color: var(--accent); text-decoration: none;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 132px;
}
.short-link:hover { text-decoration: underline; }
.code-chip {
  font-family: var(--mono); font-size: 11px; color: var(--ink-3);
  background: #f2f3f9; border-radius: 6px; padding: 1px 6px;
}
.target-cell { max-width: 360px; }
.target-url {
  display: block;
  font-size: 13px; color: var(--ink-2);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  text-decoration: none;
}
.target-url:hover { color: var(--ink); text-decoration: underline; }
.target-note {
  display: inline-block; margin-top: 3px;
  font-size: 11.5px; color: var(--ink-3);
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.clicks-cell { display: flex; align-items: center; gap: 10px; }
.clicks-num { font-variant-numeric: tabular-nums; font-weight: 650; font-size: 14.5px; }
.spark { display: flex; align-items: flex-end; gap: 2px; height: 22px; }
.spark i {
  display: block; width: 3px; border-radius: 2px;
  background: #d9dcf7;
  min-height: 2px;
}
.spark i.hot { background: var(--accent); }

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11.5px; font-weight: 600;
  padding: 3px 9px; border-radius: 999px;
  white-space: nowrap;
}
.badge i { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.ok { color: var(--ok); background: var(--ok-soft); }
.badge.warn { color: var(--warn); background: var(--warn-soft); }
.badge.exp { color: var(--ink-3); background: #f2f3f9; }
.badge-sub { display: block; margin-top: 4px; font-size: 11px; color: var(--ink-3); }

.time-cell { font-size: 12.5px; color: var(--ink-2); white-space: nowrap; font-variant-numeric: tabular-nums; }

.row-actions { display: inline-flex; gap: 6px; justify-content: flex-end; }
.act {
  appearance: none; cursor: pointer;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink-2);
  font-size: 12.5px; font-weight: 600;
  padding: 5px 11px; border-radius: 8px;
  transition: all .14s ease;
  white-space: nowrap;
}
.act:hover { color: var(--ink); border-color: #c2c7d7; background: var(--surface-2); }
.act.danger:hover { color: var(--danger); border-color: #f0c9c9; background: var(--danger-soft); }

.empty { padding: 56px 24px; text-align: center; color: var(--ink-2); }
.empty-art {
  width: 56px; height: 56px; margin: 0 auto 14px;
  display: grid; place-items: center;
  border-radius: 16px; background: var(--accent-soft); color: var(--accent);
}
.empty-art svg { width: 26px; height: 26px; }
.empty p { font-size: 13.5px; }

.foot { text-align: center; font-size: 12.5px; padding-top: 4px; }

/* ---------------------------------------------------- 用户身份 / 顶栏扩展 */
.user-badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12.5px; font-weight: 600;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid #dfe2ff;
  border-radius: 999px;
  padding: 5px 12px;
  white-space: nowrap;
}
.user-badge small { font-weight: 500; color: var(--ink-3); }

/* 修改密码 / 账号管理弹窗 */
.acc-form {
  display: grid;
  grid-template-columns: 1.2fr 1.2fr .9fr auto;
  gap: 12px;
  align-items: end;
  padding: 14px;
  background: var(--surface-2);
  border: 1px dashed var(--line-strong);
  border-radius: 14px;
}
.acc-add { height: 38px; }
.acc-table-wrap {
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
}
.acc-table th { background: var(--surface-2); }
.acc-table td { padding: 11px 14px; }
.acc-hint { font-size: 12px; line-height: 1.7; }

/* ---------------------------------------------------- 弹窗 */
.modal {
  position: fixed; inset: 0; z-index: 60;
  display: grid; place-items: center;
  padding: 20px;
}
.modal-mask {
  position: absolute; inset: 0;
  background: rgba(17, 21, 32, .42);
  backdrop-filter: blur(3px);
  animation: fade .18s ease both;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.modal-box {
  position: relative;
  width: 100%; max-width: 420px;
  max-height: calc(100dvh - 40px);
  overflow-y: auto;
  background: var(--surface);
  border-radius: 20px;
  box-shadow: var(--shadow-2);
  animation: rise .22s cubic-bezier(.2, .8, .3, 1) both;
}
.modal-box.wide { max-width: 520px; }
@keyframes rise {
  from { opacity: 0; transform: translateY(12px) scale(.985); }
  to { opacity: 1; transform: none; }
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--line);
}
.modal-head h3 { font-size: 16px; }
.modal-body { padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; margin-top: 4px; }

.qr-body { padding: 22px 20px 20px; text-align: center; }
.qr-canvas-wrap {
  display: grid; place-items: center;
  padding: 14px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 16px;
}
#qrCanvas { width: 100%; max-width: 260px; height: auto; image-rendering: pixelated; border-radius: 6px; }
.qr-url {
  margin: 14px 0 16px;
  font-family: var(--mono); font-size: 13px; color: var(--ink-2);
  word-break: break-all;
}
.qr-actions { display: flex; gap: 10px; justify-content: center; }

.lock-hint {
  display: flex; align-items: center; gap: 8px;
  font-size: 12.5px; color: var(--ink-2);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 12px;
}
.lock-hint svg { width: 15px; height: 15px; color: var(--ink-3); flex: 0 0 auto; }
.lock-hint b { font-family: var(--mono); color: var(--ink); }

/* ---------------------------------------------------- Toast */
.toast-host {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%);
  z-index: 90;
  display: flex; flex-direction: column; gap: 8px; align-items: center;
  pointer-events: none;
}
.toast {
  display: flex; align-items: center; gap: 8px;
  background: #1b2030; color: #fff;
  font-size: 13px; font-weight: 500;
  padding: 10px 16px; border-radius: 11px;
  box-shadow: 0 16px 34px -18px rgba(0, 0, 0, .8);
  animation: toastIn .22s ease both;
  max-width: 88vw;
}
.toast.out { animation: toastOut .2s ease both; }
.toast.err { background: #b91c1c; }
@keyframes toastIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes toastOut { to { opacity: 0; transform: translateY(6px); } }

/* ---------------------------------------------------- 响应式 */
@media (max-width: 980px) {
  .kpi-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .options-grid { grid-template-columns: 1fr 1fr; }
  .search input { width: 180px; }
  .acc-form { grid-template-columns: 1fr 1fr; }
  .acc-add { grid-column: span 2; }
}

@media (max-width: 760px) {
  .page { padding: 20px 14px 44px; }
  .topbar-inner { padding: 12px 14px; }
  .create-card { padding: 18px; }
  .url-row { flex-direction: column; }
  .url-row .btn { padding: 13px; }
  .options-grid { grid-template-columns: 1fr; }
  .list-head { padding: 14px; gap: 12px; }
  .list-tools { width: 100%; }
  .search { flex: 1; }
  .search input { width: 100%; }
  .result { flex-direction: column; align-items: flex-start; }
  .result-actions { width: 100%; }
  .result-actions .btn { flex: 1; }

  /* 表格转为卡片 */
  .table thead { display: none; }
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table tbody tr {
    padding: 14px;
    border-bottom: 1px solid var(--line);
  }
  .table td { padding: 5px 0; border: 0; }
  .table td[data-label]::before {
    content: attr(data-label);
    display: block;
    font-size: 11px; font-weight: 600; color: var(--ink-3);
    letter-spacing: .04em;
    margin-bottom: 3px;
  }
  .short-link { max-width: 100%; font-size: 15px; }
  .target-cell { max-width: 100%; }
  .target-url { white-space: normal; word-break: break-all; }
  .row-actions { justify-content: flex-start; flex-wrap: wrap; }
  .col-actions { text-align: left; }
  .kpi strong { font-size: 24px; }
  .modal-box { max-width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
