:root {
  color-scheme: light;
  --background: #F5F5F7;
  --surface: #FFFFFF;
  --text: #111111;
  --muted: #8E8E93;
  --group: #A1A1A6;
  --line: #E5E5EA;
  --success: #2E9E6B;
  --link: #2F5BEA;
  --warning: #F59E0B;
  --error: #E5484D;
  --card-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
  --active-shadow: 0 8px 20px rgba(0, 0, 0, 0.25);
  --sidebar-width: 264px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--background);
  color: var(--text);
  font: 16px/1.5 -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
}
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--link); outline-offset: 3px; }
h1, h2, p { margin: 0; }
h1 { font-size: 24px; font-weight: 700; line-height: 1.3; margin-bottom: 20px; }
h2 { font-size: 20px; font-weight: 700; line-height: 1.35; margin-bottom: 16px; }
p + p { margin-top: 12px; }
form > p { margin-top: 16px; }
svg { display: block; flex: none; }

.layout { display: grid; grid-template-columns: var(--sidebar-width) minmax(0, 1fr); min-height: 100dvh; }
.sidebar {
  position: sticky;
  top: 0;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 20px 16px 16px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
  background: var(--surface);
  border-right: 1px solid var(--line);
}
.sidebar-header { display: flex; align-items: center; justify-content: space-between; margin: 0 4px 18px; }
.brand { display: flex; align-items: center; gap: 12px; color: var(--text); min-width: 0; }
.brand:hover { text-decoration: none; }
.brand strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-block {
  display: inline-grid;
  flex: 0 0 40px;
  width: 40px;
  height: 40px;
  place-items: center;
  border-radius: 12px;
  color: var(--surface);
  background: linear-gradient(180deg, #2C2C2E, #1C1C1E);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2), inset 0 1px 0 rgba(255, 255, 255, 0.08);
}
.sidebar-nav { display: grid; gap: 13px; }
.group-title { color: var(--group); font-size: 13px; font-weight: 600; padding: 0 10px; margin-bottom: 3px; }
.nav-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 37px;
  gap: 8px;
  padding: 5px 12px 5px 20px;
  border-radius: 12px;
  color: var(--text);
}
.nav-link:hover { background: var(--background); text-decoration: none; }
.nav-link.on, .nav-link.on:hover, .filter-link.on {
  background: var(--text);
  color: var(--surface);
  box-shadow: var(--active-shadow);
}
.nav-link svg { width: 15px; height: 15px; flex: none; visibility: hidden; }
.nav-link.on svg { visibility: visible; }
.sidebar-footer { margin-top: auto; padding-top: 16px; }
.sidebar-notice {
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--card-shadow);
  margin-bottom: 12px;
}
.sidebar-notice h2 { font-size: 14px; margin-bottom: 4px; }
.sidebar-notice p { font-size: 13px; }
.language-switch, .balance-line, .account-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 4px;
  font-size: 13px;
}
.language-switch label { margin: 0; font-weight: 400; }
.language-switch select { width: auto; max-width: 140px; padding: 6px 8px; min-height: 34px; }
.balance-line, .account-line { color: var(--text); border-top: 1px solid var(--line); }
.balance-line:hover { text-decoration: none; }
.balance-line:hover > :first-child { text-decoration: underline; }
.account-line > span { font-weight: 600; }
.mobile-bar, .drawer-close { display: none; }

.main { min-width: 0; }
.topbar {
  height: 65px;
  padding: 0 32px;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}
.topbar svg { width: 14px; height: 14px; }
.topbar > :last-child { color: var(--text); }
.main-content { max-width: 1360px; margin: 0 auto; padding: 32px 32px 104px; }
.page-heading { display: flex; align-items: center; gap: 12px; margin-bottom: 24px; }
.page-heading h1 { margin: 0; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 20px;
  box-shadow: var(--card-shadow);
  margin-bottom: 16px;
  min-width: 0;
}
.grid { display: grid; gap: 16px; }
.metrics { grid-template-columns: repeat(4, minmax(0, 1fr)); margin-bottom: 20px; }
.stat { display: flex; flex-direction: column; align-items: flex-start; color: var(--text); min-height: 138px; margin: 0; }
a.stat:hover { text-decoration: none; border-color: var(--muted); }
.stat-label { font-size: 14px; }
.stat strong { font-size: 24px; line-height: 1.25; margin: 12px 0 4px; overflow-wrap: anywhere; }
.stat small { font-size: 13px; font-weight: 400; white-space: nowrap; }
.amount { color: var(--success); font-variant-numeric: tabular-nums; }
.dashboard-panels { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: 16px; }
.status-row {
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-top: 1px solid var(--line);
  padding-block: 10px;
}
.status-row strong { font-weight: 600; }
.status-row .hint { display: block; overflow-wrap: anywhere; }
.task-link { color: var(--text); }
.task-count { display: flex; gap: 8px; align-items: center; font-variant-numeric: tabular-nums; }
.task-count svg { color: var(--muted); width: 16px; height: 16px; }
.hint, .muted { color: var(--muted); }
.hint { font-size: 13px; font-weight: 400; }
a.hint { color: var(--link); }
.settings-shortcuts { padding-inline-start: 20px; margin-bottom: 0; }
.settings-shortcuts li + li { margin-top: 8px; }
.settings-shortcuts a:target { outline: 2px solid var(--link); outline-offset: 3px; }
#unmatched { scroll-margin-top: 16px; }
.payment-section + .payment-section { border-top: 1px solid var(--line); margin-top: 20px; padding-top: 16px; }
.error { color: var(--error); }

label { display: block; font-weight: 600; margin: 14px 0 6px; }
label .hint { display: block; margin-top: 2px; }
input, select, textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}
textarea { min-height: 132px; resize: vertical; }
input[type="checkbox"] { width: 16px; height: 16px; min-height: 0; margin: 0 6px 0 0; accent-color: var(--text); }
button, .btn {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 9px 16px;
  border: 1px solid transparent;
  border-radius: 14px;
  background: var(--text);
  color: var(--surface);
  font: inherit;
  cursor: pointer;
  white-space: nowrap;
}
button:hover, .btn:hover { background: #2C2C2E; text-decoration: none; }
button:disabled { opacity: .45; cursor: not-allowed; }
button.ghost, .icon-button, button.danger { border-color: var(--line); background: var(--surface); color: var(--text); }
button.ghost:hover, .icon-button:hover, button.danger:hover { background: var(--background); }
button.danger { color: var(--error); }
button.small { min-height: 34px; padding: 5px 10px; font-size: 13px; }
.icon-button { width: 42px; height: 42px; min-height: 42px; padding: 0; flex: none; }

.row { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px; }
.row > * { flex: 1; min-width: 120px; }
.row > .narrow { flex: 0 0 90px; min-width: 80px; }
.row > .auto { flex: 0 0 auto; min-width: 0; }
.filter-list { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 18px; }
.filter-link {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
}
.filter-link:hover { text-decoration: none; border-color: var(--muted); }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 400; font-size: 13px; white-space: nowrap; }
td { font-size: 16px; }
tr:last-child td { border-bottom: 0; }
td form + form { margin-top: 6px; }
.danger-action { margin: 10px 0; }
.danger-action summary { color: var(--error); cursor: pointer; }
.danger-action form { margin-top: 8px; }
td.row { display: table-cell; white-space: nowrap; }
.table-wrap { overflow-x: auto; }
.card > .hint:first-child { margin-bottom: 14px; }
.flash { padding: 12px 16px; border: 1px solid var(--line); border-radius: 14px; margin-bottom: 16px; background: var(--surface); }
.flash.err { border-inline-start: 3px solid var(--error); color: var(--error); }
.tag {
  display: inline-block;
  color: var(--text);
  background: var(--background);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 13px;
  white-space: nowrap;
}
.tag.ok { color: var(--success); }
.tag.warn { color: var(--warning); }
.tag.err { color: var(--error); }
.btn-edit { border: 1px solid var(--line); border-radius: 14px; padding: 14px; margin-bottom: 12px; }
.preview { background: var(--background); border-radius: 14px; padding: 14px; max-width: 560px; }
.preview .msg { background: var(--surface); padding: 12px; border-radius: 14px; margin-bottom: 8px; white-space: pre-wrap; overflow-wrap: anywhere; }
.preview .kb-row { display: flex; gap: 8px; margin-top: 8px; }
.preview .kb-row span { flex: 1; min-width: 0; text-align: center; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 8px; font-size: 13px; overflow-wrap: anywhere; }
code { background: var(--background); border-radius: 6px; padding: 2px 5px; font-size: .88em; overflow-wrap: anywhere; }
.section-gap { margin-top: 20px; }
.search-form { margin-bottom: 16px; }

.login { display: grid; min-height: 100dvh; place-items: center; padding: 20px; }
.login-card { width: min(100%, 400px); margin: 0; }
.login-card .brand { margin-bottom: 24px; }
.login-card button { width: 100%; margin-top: 20px; }

.support-button {
  position: fixed;
  inset-inline-end: max(20px, env(safe-area-inset-right));
  inset-block-end: max(20px, env(safe-area-inset-bottom));
  z-index: 2;
  width: 52px;
  height: 52px;
  padding: 0;
  border-radius: 50%;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.16);
}
.support-dialog {
  width: min(360px, calc(100% - 32px));
  margin: auto max(20px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) auto;
  color: var(--text);
}
.support-dialog::backdrop { background: rgba(0, 0, 0, .24); }
.dialog-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.dialog-header h2 { margin: 0; }
.support-dialog p { margin-bottom: 12px; }

@media (max-width: 1100px) {
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 800px) {
  .layout { display: block; }
  .mobile-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 12px;
    margin: 12px 16px 0;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 20px;
    box-shadow: var(--card-shadow);
  }
  .sidebar {
    position: fixed;
    inset: 0 0 0 auto;
    width: min(340px, 100%);
    height: 100dvh;
    transform: translateX(100%);
    visibility: hidden;
    z-index: 4;
    border-left: 1px solid var(--line);
    border-right: 0;
  }
  .sidebar.is-open { transform: none; visibility: visible; }
  .nav-link { min-height: 44px; }
  .drawer-close { display: inline-flex; }
  .drawer-backdrop { position: fixed; z-index: 3; inset: 0; background: rgba(0, 0, 0, .32); }
  body.drawer-open { overflow: hidden; }
  .topbar { display: none; }
  .main-content { padding: 24px 16px 96px; }
}

@media (max-width: 540px) {
  .metrics, .dashboard-panels { gap: 12px; }
  .dashboard-panels { grid-template-columns: 1fr; }
  .dashboard-panels .card { margin-bottom: 0; }
  .stat { min-height: 124px; }
  .stat strong { font-size: 20px; }
  .filter-list { gap: 6px; }
}
