:root {
  color-scheme: light;
  --paper: #eef4fb;
  --sheet: #ffffff;
  --ink: #0b1f3a;
  --muted: #5b6d80;
  --line: #b8c9dc;
  --soft-line: #dde7f1;
  --accent: #1769e0;
  --accent-ink: #ffffff;
  --wash: #e7f1ff;
  --grid: #dce7f3;
  --danger: #b42318;
  --good: #08775a;
  --shadow: 0 18px 48px rgba(11, 31, 58, .1);
  --display: "Segoe UI", "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
  --body: "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
}

html[data-theme="night"] {
  color-scheme: dark;
  --paper: #071426;
  --sheet: #0d2138;
  --ink: #f4f8ff;
  --muted: #a8b8cb;
  --line: #33516f;
  --soft-line: #203b57;
  --accent: #67afff;
  --accent-ink: #061426;
  --wash: #153a61;
  --grid: #112c47;
  --danger: #ff8a80;
  --good: #63d5ad;
  --shadow: 0 22px 58px rgba(0, 8, 20, .36);
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--paper); }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background-color: var(--paper);
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 32px 32px;
  font: 15px/1.55 var(--body);
}
button, input, select, textarea { font: inherit; }
button, select { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 30%, transparent);
  outline-offset: 2px;
}
.hidden { display: none !important; }

.app {
  width: min(1440px, calc(100% - 40px));
  margin: 20px auto 32px;
  padding: 26px 24px 40px;
  background: var(--sheet);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
}
.masthead {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 24px;
  align-items: end;
  padding: 10px 0 22px;
  border-bottom: 2px solid var(--accent);
}
.eyebrow {
  display: inline-block;
  margin: 0 0 8px;
  padding: 4px 8px;
  color: var(--accent);
  background: var(--wash);
  border: 1px solid var(--line);
  border-bottom-color: var(--accent);
  border-radius: 5px 5px 0 0;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .16em;
}
h1 { margin: 0; font: 760 clamp(34px, 5vw, 58px)/1 var(--display); letter-spacing: -.035em; }
h2 { margin: 0; font: 700 22px/1.15 var(--display); letter-spacing: -.02em; }
.masthead-note { max-width: 680px; margin: 12px 0 0; color: var(--muted); }
.header-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.button {
  appearance: none;
  min-height: 42px;
  padding: 9px 14px;
  color: var(--ink);
  background: var(--sheet);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-weight: 700;
  transition: transform .16s ease, border-color .16s ease, color .16s ease;
}
.button:hover { color: var(--accent); border-color: var(--accent); transform: translateY(-1px); }
.button.primary { color: var(--accent-ink); background: var(--accent); border-color: var(--accent); }
.button.primary:hover { color: var(--accent-ink); filter: brightness(.92); }
.button.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 55%, var(--line)); }
.button.small { min-height: 34px; padding: 5px 10px; font-size: 13px; }
.icon-button {
  appearance: none;
  min-width: 38px;
  min-height: 38px;
  padding: 5px 7px;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 4px;
  font-size: 13px;
}
.icon-button:hover { color: var(--accent); border-color: var(--accent); }
.theme-button { width: 42px; height: 42px; padding: 0; background: var(--wash); border: 1px solid var(--line); border-radius: 12px; font-size: 20px; }
.sync-pill {
  display: inline-flex;
  align-items: center;
  min-height: 42px;
  padding: 8px 11px;
  color: var(--muted);
  background: var(--wash);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 12px;
  font-weight: 750;
}
.sync-pill::before { width: 7px; height: 7px; margin-right: 7px; content: ""; background: var(--good); border-radius: 50%; }
.sync-pill[data-state="syncing"]::before { background: var(--accent); animation: pulse 1s infinite; }
.sync-pill[data-state="error"]::before { background: var(--danger); }
@keyframes pulse { 50% { opacity: .35; } }

.summary {
  display: grid;
  grid-template-columns: minmax(280px, 1.55fr) repeat(3, minmax(150px, .7fr));
  margin-top: 20px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 10px;
}
.metric { min-height: 154px; padding: 24px 22px; border-right: 1px solid var(--line); }
.metric:last-child { border-right: 0; }
.metric.hero { background: var(--wash); }
.metric-label { color: var(--muted); font-size: 12px; font-weight: 800; letter-spacing: .1em; }
.metric-value { display: block; margin-top: 17px; font: 700 clamp(27px, 3vw, 46px)/1 var(--display); letter-spacing: -.04em; }
.metric.hero .metric-value { color: var(--accent); }
.metric-date { font-size: clamp(22px, 2.4vw, 35px); }
.metric-detail { display: block; margin-top: 12px; color: var(--muted); font-size: 12px; }

.records { padding-top: 28px; }
.records-head { display: flex; justify-content: space-between; align-items: end; gap: 18px; margin-bottom: 16px; }
.section-meta { margin: 5px 0 0; color: var(--muted); font-size: 12px; }
.filters { display: grid; grid-template-columns: minmax(260px, 1.6fr) repeat(3, minmax(140px, .6fr)); gap: 8px; margin-bottom: 14px; }
.search-box {
  display: grid;
  grid-template-columns: 20px minmax(0, 1fr) auto;
  align-items: center;
  min-height: 42px;
  padding: 0 7px 0 12px;
  background: var(--sheet);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.search-box:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); }
.search-icon { color: var(--accent); font-size: 22px; line-height: 1; }
.search-input { width: 100%; min-width: 0; height: 40px; padding: 7px 10px; color: var(--ink); background: transparent; border: 0; outline: 0; }
.search-input:focus-visible { outline: 0; }
.search-input::placeholder { color: var(--muted); }
.search-clear { min-width: 44px; min-height: 32px; padding: 4px 8px; color: var(--accent); background: var(--wash); border: 0; border-radius: 5px; font-size: 12px; font-weight: 750; }
.control { width: 100%; min-height: 42px; padding: 8px 11px; color: var(--ink); background: var(--sheet); border: 1px solid var(--line); border-radius: 8px; }
textarea.control { min-height: 88px; resize: vertical; }
textarea.control.tall { min-height: 118px; }

.table-wrap { overflow-x: auto; background: var(--sheet); border: 1px solid var(--line); border-top: 2px solid var(--accent); border-radius: 8px; }
table { width: 100%; min-width: 940px; border-collapse: collapse; }
th { padding: 12px 10px; background: var(--wash); border-bottom: 1px solid var(--line); font-size: 12px; letter-spacing: .06em; text-align: left; white-space: nowrap; }
td { padding: 13px 10px; border-bottom: 1px solid var(--soft-line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tr:hover td { background: color-mix(in srgb, var(--wash) 36%, transparent); }
.tool-title-line { display: flex; align-items: center; gap: 8px; }
.tool-title { color: var(--ink); font: 700 17px/1.25 var(--display); text-decoration: none; overflow-wrap: anywhere; }
.tool-title[href]:hover { color: var(--accent); text-decoration: underline; text-underline-offset: 3px; }
.favorite-mark { color: #d89200; font-size: 17px; }
.subline { max-width: 440px; margin-top: 4px; color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.tag { display: inline-block; margin: 2px 4px 2px 0; padding: 2px 7px; color: var(--ink); border: 1px solid var(--line); border-radius: 4px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.tag.category { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.row-actions { display: flex; gap: 7px; }
.empty { display: grid; min-height: 300px; padding: 42px; place-items: center; align-content: center; text-align: center; }
.empty-mark { color: var(--wash); font: 700 68px/1 var(--display); }
.empty h3 { margin: 10px 0 3px; font: 700 22px/1.2 var(--display); }
.empty p { margin: 0 0 18px; color: var(--muted); }
.footer-note { display: flex; justify-content: space-between; gap: 16px; margin-top: 14px; color: var(--muted); font-size: 12px; }

dialog {
  width: min(760px, calc(100% - 28px));
  max-height: calc(100vh - 36px);
  max-height: calc(100dvh - 36px);
  padding: 0;
  overflow: hidden;
  color: var(--ink);
  background: var(--sheet);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(4, 20, 42, .66); backdrop-filter: blur(3px); }
dialog form { display: flex; max-height: calc(100vh - 36px); max-height: calc(100dvh - 36px); flex-direction: column; margin: 0; }
.dialog-fallback-open { overflow: hidden; }
.dialog-fallback-open::before { position: fixed; z-index: 90; content: ""; inset: 0; background: rgba(4, 20, 42, .66); }
dialog.dialog-fallback[open] { display: block; position: fixed; z-index: 100; top: 50%; left: 50%; margin: 0; transform: translate(-50%, -50%); }
.auth-dialog, .confirm-dialog { width: min(480px, calc(100% - 28px)); }
.dialog-head { display: flex; flex: 0 0 auto; justify-content: space-between; align-items: start; gap: 14px; padding: 22px 24px 18px; background: var(--sheet); border-bottom: 2px solid var(--accent); }
.dialog-head h2 { font-size: 28px; }
.close-button { padding: 0 5px; color: var(--muted); background: transparent; border: 0; font-size: 28px; line-height: 1; }
.form-body { min-height: 0; padding: 22px 24px 10px; overflow-y: auto; overscroll-behavior: contain; }
.auth-copy { margin: 0 0 18px; color: var(--muted); }
.form-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 18px; }
.field { display: flex; min-width: 0; flex-direction: column; gap: 7px; font-size: 13px; font-weight: 800; letter-spacing: .025em; }
.field.full { grid-column: 1 / -1; }
.field small { color: var(--muted); font-size: 12px; font-weight: 400; letter-spacing: 0; }
.preset-options { display: flex; flex-wrap: wrap; gap: 7px; }
.option-chip {
  appearance: none;
  min-height: 32px;
  padding: 5px 10px;
  color: var(--muted);
  background: var(--sheet);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 750;
}
.option-chip:hover { color: var(--accent); border-color: var(--accent); }
.option-chip[aria-pressed="true"] { color: var(--accent-ink); background: var(--accent); border-color: var(--accent); }
.checkbox-field { min-height: 42px; flex-direction: row; align-items: center; padding-top: 23px; }
.checkbox-field input { width: 19px; height: 19px; accent-color: var(--accent); }
.required::after { color: var(--accent); content: " *"; }
.error { min-height: 20px; margin: 14px 0 0; color: var(--danger); font-size: 12px; }
.dialog-actions { display: flex; flex: 0 0 auto; justify-content: space-between; gap: 12px; padding: 16px 24px 20px; background: var(--sheet); border-top: 1px solid var(--line); }
.dialog-actions.end { justify-content: flex-end; }
.action-group { display: flex; flex-wrap: wrap; gap: 8px; }
.choice-card { display: flex; gap: 12px; margin: 10px 0; padding: 14px; border: 1px solid var(--line); border-radius: 8px; cursor: pointer; }
.choice-card:has(input:checked) { background: var(--wash); border-color: var(--accent); }
.choice-card input { margin-top: 4px; accent-color: var(--accent); }
.choice-card strong, .choice-card small { display: block; }
.choice-card small { margin-top: 3px; color: var(--muted); }
.danger-choice:has(input:checked) { border-color: var(--danger); }
.toast { position: fixed; right: 24px; bottom: 24px; z-index: 20; max-width: min(360px, calc(100% - 48px)); padding: 12px 16px; color: var(--accent-ink); background: var(--accent); border-radius: 8px; box-shadow: var(--shadow); opacity: 0; pointer-events: none; transform: translateY(20px); transition: .2s ease; }
.toast.show { opacity: 1; transform: translateY(0); }

@media (max-width: 980px) {
  .masthead { grid-template-columns: 1fr; align-items: start; }
  .header-actions { justify-content: flex-start; }
  .summary { grid-template-columns: 1fr 1fr; }
  .metric:nth-child(2) { border-right: 0; }
  .metric:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
  .filters { grid-template-columns: 1fr 1fr 1fr; }
  .search-box { grid-column: 1 / -1; }
}

@media (max-width: 720px) {
  .app { width: min(100% - 16px, 1440px); margin: 8px auto 18px; padding: 14px 12px 28px; border-radius: 10px; }
  .masthead { gap: 18px; }
  .header-actions { display: grid; grid-template-columns: repeat(3, 1fr); width: 100%; }
  .sync-pill { grid-column: span 2; }
  .theme-button { width: 100%; }
  .header-actions .primary { grid-column: 1 / -1; }
  .summary { grid-template-columns: 1fr 1fr; }
  .metric { min-height: 128px; padding: 18px 12px; }
  .metric-value { font-size: 32px; }
  .metric-date { font-size: 21px; }
  .records-head { align-items: start; flex-direction: column; }
  .filters { grid-template-columns: 1fr 1fr; }
  .search-box { grid-column: 1 / -1; }
  .filters select:last-child { grid-column: 1 / -1; }
  .button, .control { min-height: 44px; }
  .table-wrap { overflow: visible; }
  table { display: block; min-width: 0; }
  thead { display: none; }
  tbody { display: grid; gap: 10px; padding: 10px; }
  tbody tr { display: grid; grid-template-columns: 1fr 1fr; overflow: hidden; background: var(--sheet); border: 1px solid var(--line); border-top: 2px solid var(--accent); border-radius: 8px; }
  tbody td { display: grid; min-width: 0; gap: 4px; padding: 10px; overflow-wrap: anywhere; border: 0; border-bottom: 1px solid var(--soft-line); }
  tbody td::before { color: var(--muted); content: attr(data-label); font-size: 12px; font-weight: 750; line-height: 1.25; }
  tbody td:first-child, tbody td:nth-child(5), tbody td:last-child { grid-column: 1 / -1; }
  tbody td:first-child { background: var(--wash); }
  tbody td:last-child { border-bottom: 0; }
  tbody tr:hover td { background: inherit; }
  tbody tr:hover td:first-child { background: var(--wash); }
  .row-actions { width: 100%; }
  .row-actions .icon-button { flex: 1; min-height: 42px; border: 1px solid var(--line); }
  .footer-note { flex-direction: column; }
  .form-grid { grid-template-columns: 1fr; }
  .field.full { grid-column: auto; }
  .checkbox-field { padding-top: 0; }
  .dialog-head, .form-body, .dialog-actions { padding-right: 16px; padding-left: 16px; }
  .dialog-actions { align-items: stretch; flex-direction: column-reverse; }
  .dialog-actions > div, .action-group { display: grid; width: 100%; grid-template-columns: 1fr 1fr; }
  .dialog-actions.end { flex-direction: row; }
  .dialog-actions.end .button { flex: 1; }
  .toast { right: 12px; bottom: 12px; max-width: calc(100% - 24px); }
}

@media (max-width: 430px) {
  .filters { grid-template-columns: 1fr; }
  .search-box, .filters select:last-child { grid-column: auto; }
  .header-actions { grid-template-columns: 1fr 1fr; }
  .sync-pill { grid-column: 1 / -1; }
  .theme-button { width: 100%; }
  .header-actions .primary { grid-column: 1 / -1; }
  .metric-detail { display: none; }
  .metric { min-height: 100px; }
}
