:root {
    --bg: #f4f6f5;
    --ink: #18231f;
    --muted: #63736b;
    --green: #0f8f67;
    --blue: #2f7df4;
    --orange: #f59e0b;
    --line: #d9e1dd;
    --panel: #ffffff;
}

* { box-sizing: border-box; }
html, body { max-width: 100%; overflow-x: hidden; }
html {
    background: var(--bg);
    color: var(--ink);
    font-family: "Microsoft YaHei", "PingFang SC", "Noto Sans CJK SC", system-ui, sans-serif;
}
body { min-width: 320px; margin: 0; }

.topbar {
    min-height: 58px;
    padding: 0 max(20px, calc((100% - 1180px) / 2));
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    background: #fff;
    border-bottom: 1px solid var(--line);
}
.brand { font-weight: 750; color: var(--ink); text-decoration: none; }
.topbar nav { display: flex; flex-wrap: wrap; gap: 18px; }
.topbar a { color: var(--ink); text-decoration: none; }

.shell { width: 100%; max-width: 1180px; margin: 0 auto; padding: 28px 20px 56px; }
.page-head { display: flex; align-items: end; justify-content: space-between; gap: 18px; margin-bottom: 20px; }
.page-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.eyebrow { margin: 0 0 5px; color: var(--green); font-size: 12px; font-weight: 700; }
h1, h2 { margin: 0; }
h1 { font-size: 27px; line-height: 1.2; }
h2 { font-size: 15px; }

.button, .segment {
    min-height: 36px;
    padding: 7px 13px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fff;
    color: var(--ink);
    font: inherit;
    text-decoration: none;
    cursor: pointer;
}
.button.primary, .segment.selected { border-color: var(--green); background: var(--green); color: #fff; }

.toolbar, .time-rail, .filter-bar { display: flex; align-items: end; gap: 10px; margin: 0 0 18px; }
.toolbar label, .time-rail > span, .filter-bar label { color: var(--muted); font-size: 13px; }
.toolbar input, .filter-bar input, .filter-bar select {
    height: 36px;
    min-width: 0;
    padding: 7px 10px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fff;
    color: var(--ink);
    font: inherit;
}
.toolbar input { width: min(300px, 100%); }
.filter-bar { flex-wrap: wrap; padding: 12px 0; border-bottom: 1px solid var(--line); }
.filter-bar label { display: grid; gap: 5px; }
.filter-bar input, .filter-bar select { width: 150px; }

.table-wrap { width: 100%; max-width: 100%; overflow-x: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 7px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 11px 12px; border-bottom: 1px solid #edf1ef; text-align: left; vertical-align: top; }
th { color: var(--muted); font-weight: 650; white-space: nowrap; }
th a { color: var(--muted); text-decoration: underline; text-decoration-color: #becac4; text-underline-offset: 3px; }
tr:last-child td { border-bottom: 0; }
.url-cell { max-width: 340px; overflow-wrap: anywhere; word-break: break-word; }
.link-target-cell { display: grid; gap: 4px; }
.link-remark { color: var(--ink); font-weight: 650; }
code, .visitor-id { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 12px; }
.visitor-id { display: block; max-width: min(520px, 100%); margin-top: 7px; overflow-wrap: anywhere; color: var(--muted); }

.icon-button {
    width: 34px;
    height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    color: var(--blue);
    text-decoration: none;
}
.icon-button:hover { background: #edf4ff; }
.chart-icon { width: 17px; height: 16px; display: flex; align-items: end; justify-content: center; gap: 2px; border-bottom: 1.5px solid currentColor; }
.chart-icon i { width: 3px; display: block; border-radius: 1px 1px 0 0; background: currentColor; }
.chart-icon i:nth-child(1) { height: 6px; }
.chart-icon i:nth-child(2) { height: 11px; }
.chart-icon i:nth-child(3) { height: 15px; }

.tabs { display: flex; gap: 4px; margin-bottom: 18px; border-bottom: 1px solid var(--line); }
.tabs a { padding: 9px 12px; border-bottom: 2px solid transparent; color: var(--muted); font-size: 13px; text-decoration: none; }
.tabs a.active { border-color: var(--green); color: var(--green); font-weight: 700; }
.link-context { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 8px 0 0; color: var(--muted); font-size: 13px; }
.link-context span { padding: 2px 6px; border: 1px solid var(--line); border-radius: 4px; color: var(--green); font-size: 11px; font-weight: 700; }
.link-context strong { color: var(--ink); font-size: 12px; }
.link-context a { max-width: 100%; overflow-wrap: anywhere; color: var(--muted); }
.date-controls { display: flex; flex-wrap: wrap; align-items: end; gap: 12px 18px; margin-bottom: 18px; }
.time-rail { width: max-content; padding: 4px; align-items: center; border-radius: 7px; background: #e8eeeb; }
.time-rail > span { padding: 0 7px; }
.segment { min-height: 30px; padding: 5px 11px; border: 0; background: transparent; }
.custom-range { display: flex; flex-wrap: wrap; align-items: end; gap: 8px; }
.custom-range label { display: grid; gap: 5px; color: var(--muted); font-size: 12px; }
.custom-range input { width: 145px; height: 36px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--ink); font: inherit; }

.kpi-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-bottom: 22px; }
.kpi { min-height: 84px; padding: 14px 15px; border: 1px solid var(--line); border-radius: 7px; background: #fff; }
.kpi span { display: block; color: var(--muted); font-size: 13px; }
.kpi strong { display: block; margin-top: 7px; font: 700 25px/1 ui-monospace, SFMono-Regular, Consolas, monospace; }
.kpi small { display: block; margin-top: 8px; color: var(--muted); font-size: 11px; }

.chart-section { margin-bottom: 18px; padding: 4px 0 0; border-top: 1px solid var(--line); }
.section-heading { display: flex; justify-content: space-between; padding-top: 14px; margin-bottom: 8px; }
.chart { width: 100%; height: 230px; min-height: 180px; }
.trend-table { border-radius: 0; border-right: 0; border-left: 0; }
.data-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.data-section { margin-bottom: 14px; overflow: hidden; border: 1px solid var(--line); border-radius: 7px; background: #fff; }
.data-section h2 { padding: 14px 15px 9px; }
.data-section table { font-size: 12px; }
.empty { padding: 30px; color: var(--muted); text-align: center; }

.pagination { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 14px; color: var(--muted); font-size: 13px; }
.pagination > div { display: flex; gap: 8px; }
.visitor-table table { min-width: 1380px; }

:focus-visible { outline: 3px solid rgba(47, 125, 244, .45); outline-offset: 2px; }

@media (max-width: 720px) {
    .topbar { min-height: 58px; padding: 10px 14px; gap: 10px; }
    .topbar nav { gap: 10px; font-size: 13px; }
    .shell { padding: 20px 14px 40px; }
    .page-head { align-items: stretch; flex-direction: column; }
    .page-actions { display: grid; grid-template-columns: 1fr 1fr; }
    .page-head > .button { align-self: stretch; }
    .toolbar { align-items: stretch; flex-wrap: wrap; }
    .toolbar label { width: 100%; }
    .toolbar input { flex: 1 1 180px; width: auto; }
    .filter-bar { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: end; }
    .filter-bar label, .filter-bar input, .filter-bar select { width: 100%; }
    .time-rail { width: 100%; max-width: 100%; overflow-x: auto; }
    .date-controls, .custom-range { align-items: stretch; }
    .custom-range { width: 100%; }
    .custom-range label { flex: 1 1 150px; }
    .custom-range input { width: 100%; }
    .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .data-grid { grid-template-columns: 1fr; }
    .chart { height: 200px; }
    .pagination { align-items: stretch; flex-direction: column; }
}

@media (max-width: 420px) {
    .topbar { align-items: flex-start; flex-direction: column; }
    .page-actions, .filter-bar { grid-template-columns: 1fr; }
    .custom-range label, .custom-range .button { flex: 1 1 100%; }
    .kpi { min-width: 0; padding: 12px; }
    .kpi strong { font-size: 22px; }
}

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

/* Shared application workflows */
.skip-link { position: fixed; z-index: 100; left: 12px; top: -60px; padding: 9px 12px; background: #fff; color: var(--green); border: 1px solid var(--green); }
.skip-link:focus { top: 10px; }
.brand { display: inline-flex; align-items: center; gap: 8px; }
.brand-mark { width: 25px; height: 25px; display: inline-grid; place-items: center; border-radius: 5px; background: var(--green); color: #fff; font-size: 15px; }
.topbar nav { align-items: center; }
.topbar nav > a, .nav-form button { min-height: 34px; padding: 7px 5px; display: inline-flex; align-items: center; border: 0; border-bottom: 2px solid transparent; background: transparent; color: var(--ink); font: inherit; cursor: pointer; }
.topbar nav > a.active, .topbar nav > a[aria-current="page"] { border-bottom-color: var(--green); color: var(--green); font-weight: 700; }
.nav-form { margin: 0; }
.nav-form input { display: none; }

.page-head > div > a:first-child { display: inline-block; margin-bottom: 14px; color: var(--muted); font-size: 13px; }
.page-head h1 { margin-bottom: 7px; }
.page-head p:not(.eyebrow) { max-width: 680px; margin: 0; color: var(--muted); line-height: 1.55; }
.management-heading { align-items: center; }
.success-message, .form-message { margin: 0 0 18px; padding: 11px 13px; border-left: 3px solid var(--green); background: #eaf7f1; color: #0b6246; }
.form-message { border-left-color: #b42318; background: #fff1f0; color: #8f1e17; }
.muted-copy { color: var(--muted); }

.auth-shell { min-height: calc(100vh - 115px); display: grid; place-items: center; padding: 28px 0; }
.auth-panel { width: min(100%, 430px); padding: 28px; border: 1px solid var(--line); border-radius: 8px; background: #fff; box-shadow: 0 16px 38px rgba(24, 35, 31, .08); }
.auth-heading { margin-bottom: 22px; }
.auth-heading h1 { margin: 5px 0 8px; font-size: 29px; }
.auth-heading p:not(.eyebrow) { margin: 0; color: var(--muted); line-height: 1.55; }
.auth-form, .link-create-form { display: grid; gap: 13px; }
.auth-form label, .link-create-form label, .management-filters label, .inline-editor label, .admin-inline-form label, .domain-form label { display: grid; gap: 6px; color: var(--ink); font-size: 13px; font-weight: 650; }
.auth-form input, .auth-form textarea, .link-create-form input, .link-create-form textarea, .link-create-form select, .management-filters input, .management-filters select, .inline-editor input, .inline-editor select, .admin-inline-form input, .admin-inline-form select, .domain-form input, .domain-form select {
    width: 100%; min-width: 0; min-height: 42px; padding: 9px 11px; border: 1px solid #aebbb4; border-radius: 6px; background: #fff; color: var(--ink); font: inherit;
}
.auth-form textarea, .link-create-form textarea { resize: vertical; line-height: 1.5; }
.auth-form > button { min-height: 43px; margin-top: 3px; border: 0; border-radius: 6px; background: var(--green); color: #fff; font: 700 14px/1 inherit; cursor: pointer; }
.auth-switch { margin: 15px 0 0; color: var(--muted); text-align: center; font-size: 13px; }

.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 22px; }
.metric-item { min-height: 102px; padding: 17px; border: 1px solid var(--line); border-radius: 7px; background: #fff; }
.metric-item span { color: var(--muted); font-size: 13px; }
.metric-item strong { display: block; margin-top: 12px; font: 700 28px/1 ui-monospace, SFMono-Regular, Consolas, monospace; }
.dashboard-section { margin-bottom: 18px; padding: 18px; border: 1px solid var(--line); border-radius: 7px; background: #fff; }
.dashboard-chart { min-height: 250px; }
.dashboard-columns { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(280px, .65fr); gap: 16px; }
.dashboard-breakdowns { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.breakdown-list > div { display: flex; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px solid #edf1ef; }
.breakdown-list > div:last-child { border-bottom: 0; }
.breakdown-list span { color: var(--muted); }
.recent-list { display: grid; gap: 1px; }
.recent-item, .attention-item, .history-item { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 12px 0; border-bottom: 1px solid #edf1ef; }
.recent-item:last-child, .attention-item:last-child, .history-item:last-child { border-bottom: 0; }
.recent-item p { max-width: 560px; margin: 4px 0 0; overflow: hidden; color: var(--muted); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.recent-item > span, .attention-item > span, .history-item > span { flex: 0 0 auto; color: var(--muted); font-size: 12px; }

.management-filters { display: grid; grid-template-columns: minmax(210px, 1fr) repeat(3, minmax(125px, .42fr)) auto; align-items: end; gap: 10px; margin-bottom: 18px; }
.management-table { margin-bottom: 20px; }
.bulk-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 7px; padding: 10px; border: 1px solid var(--line); border-bottom: 0; border-radius: 7px 7px 0 0; background: #fff; }
.bulk-toolbar > span:first-of-type { min-width: 78px; color: var(--muted); font-size: 12px; }
.button.danger, .danger-action { color: #a12622; }
.button.danger { border-color: #efc7c4; background: #fff8f7; }
.row-actions { display: flex; align-items: center; gap: 3px; white-space: nowrap; }
.inline-form { display: inline-flex; margin: 0; }
.icon-only { min-width: 36px; min-height: 34px; padding: 6px; display: inline-flex; align-items: center; justify-content: center; border: 0; border-radius: 5px; background: transparent; color: var(--blue); font: inherit; font-size: 12px; text-decoration: none; cursor: pointer; }
.icon-only:hover { background: #edf4ff; }
.selection-column { width: 58px; }
.status-badge { display: inline-block; padding: 3px 7px; border-radius: 4px; background: #eef2f0; font-size: 11px; font-weight: 700; }
.status-active { background: #e4f5ed; color: #0b6b4b; }
.status-disabled { background: #f2eeee; color: #7d5550; }
td .status-badge + small { display: block; margin-top: 4px; color: var(--muted); font-size: 10px; }
.editor-row td { padding: 0; background: #f8faf9; }
.inline-editor { padding: 16px; }
.editor-grid { display: grid; grid-template-columns: minmax(120px, .6fr) minmax(260px, 1.8fr) minmax(100px, .5fr) minmax(170px, .8fr) minmax(130px, .6fr); gap: 10px; }
.editor-footer, .form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }
.pagination a[aria-disabled="true"] { opacity: .45; pointer-events: none; }

.create-layout { display: grid; gap: 16px; }
.link-create-form, .result-panel { padding: 20px; border: 1px solid var(--line); border-radius: 7px; background: #fff; }
.form-help { margin: -5px 0 2px; color: var(--muted); font-size: 12px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.import-preview { margin-top: 5px; padding: 14px; border-top: 1px solid var(--line); }
.result-tabs { display: flex; gap: 5px; border-bottom: 1px solid var(--line); }
.result-tabs button { padding: 9px 12px; border: 0; border-bottom: 2px solid transparent; background: transparent; color: var(--muted); cursor: pointer; }
.result-tabs button.active { border-color: var(--green); color: var(--green); font-weight: 700; }
.result-group { margin-top: 10px; padding: 13px; border: 1px solid var(--line); border-radius: 6px; }
.result-group > summary, .history-batch > summary, .history-target > summary, .result-link { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.result-group > summary, .history-batch > summary, .history-target > summary { cursor: pointer; }
.result-group > summary strong, .history-target > summary strong { min-width: 0; overflow-wrap: anywhere; }
.group-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; margin-top: 12px; }
.group-actions form { margin: 0; }
.result-error { margin: 10px 0 0; color: #a12622; font-size: 12px; }
.result-link { padding-top: 9px; overflow-wrap: anywhere; font-size: 13px; }
.result-link > div { min-width: 0; display: grid; gap: 4px; }
.result-link code, .result-link a { overflow-wrap: anywhere; }
.result-link small { color: var(--muted); }
.deleted-link { opacity: .68; }
.history-batch { margin-top: 10px; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
.history-batch > summary { padding: 13px; }
.history-batch > summary span { color: var(--muted); font-size: 12px; }
.history-targets { display: grid; gap: 8px; padding: 0 13px 13px; }
.history-target { padding: 11px; border: 1px solid #e6ece9; border-radius: 5px; background: #fafcfb; }
.preview-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(180px, .8fr) 110px; align-items: end; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.preview-row > span { overflow-wrap: anywhere; font-size: 13px; }

.admin-nav-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-bottom: 20px; }
.admin-nav-grid a { min-height: 92px; padding: 17px; border: 1px solid var(--line); border-radius: 7px; background: #fff; color: var(--ink); text-decoration: none; }
.admin-nav-grid a:hover { border-color: var(--green); }
.admin-nav-grid strong, .admin-nav-grid span { display: block; }
.admin-nav-grid span { margin-top: 8px; color: var(--muted); font-size: 12px; }
.admin-inline-form { display: flex; flex-wrap: wrap; align-items: end; gap: 10px; padding: 14px; border-top: 1px solid var(--line); }
.admin-inline-form > p { flex: 1 1 300px; margin: 0; color: var(--muted); }
.report-list { display: grid; gap: 14px; }
.report-item { padding: 18px; border: 1px solid var(--line); border-radius: 7px; background: #fff; }
.report-item > header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.report-item header p { margin: 5px 0 0; color: var(--muted); overflow-wrap: anywhere; }
.report-item dl { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.report-item dt { color: var(--muted); font-size: 11px; }
.report-item dd { margin: 4px 0 0; overflow-wrap: anywhere; }
.status-shell { width: min(100%, 620px); margin: 12vh auto 0; padding: 30px; border: 1px solid var(--line); border-radius: 7px; background: #fff; text-align: center; }
.status-shell h1 { margin: 7px 0 10px; }
.status-shell > p:not(.eyebrow) { color: var(--muted); }
.status-actions { display: flex; justify-content: center; gap: 9px; margin-top: 22px; }

@media (max-width: 900px) {
    .management-filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .management-filters .search-field { grid-column: 1 / -1; }
    .editor-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .editor-target { grid-column: span 2; }
    .dashboard-columns, .dashboard-breakdowns { grid-template-columns: 1fr; }
}

@media (max-width: 720px) {
    .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .admin-nav-grid { grid-template-columns: 1fr; }
    .report-item dl { grid-template-columns: 1fr; }
    .admin-inline-form { align-items: stretch; flex-direction: column; }
    .admin-inline-form > * { width: 100%; }
}

@media (max-width: 520px) {
    .auth-shell { min-height: auto; padding: 8px 0; }
    .auth-panel, .link-create-form, .result-panel, .dashboard-section, .status-shell { padding: 17px 15px; }
    .metric-grid, .management-filters, .form-grid, .editor-grid, .preview-row { grid-template-columns: 1fr; }
    .management-filters .search-field, .editor-target { grid-column: auto; }
    .metric-item { min-height: 88px; }
    .page-head .button, .form-actions .button { width: 100%; }
    .form-actions, .status-actions { flex-direction: column; }
    .history-batch > summary, .history-target > summary { align-items: flex-start; flex-direction: column; gap: 5px; }
    .group-actions { justify-content: stretch; }
    .group-actions .button { width: 100%; }
    .bulk-toolbar { align-items: stretch; }
    .bulk-toolbar > span:first-of-type { width: 100%; }
    .recent-item, .attention-item { align-items: flex-start; flex-direction: column; gap: 5px; }
}
