:root {
  --ink: #1a1d24;
  --muted: #666c78;
  --soft: #969da8;
  --line: #eaedf2;
  --border: #d7dce4;
  --surface: #ffffff;
  --canvas: #f4f5f7;
  --pill: #f2f3f6;
  --blue: #2672ff;
  --blue-line: #2196f3;
  --green-line: #7be088;
  --green-text: #18a65a;
  --red-text: #e04646;
  --shadow: 0 1px 4px rgba(15, 23, 42, 0.05);
}

* { box-sizing: border-box; touch-action: manipulation; }
html { background: #e8eaee; touch-action: manipulation; }
body {
  margin: 0;
  overflow-x: hidden;
  touch-action: manipulation;
  color: var(--ink);
  background: #e8eaee;
  font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Helvetica Neue', 'Noto Sans SC', sans-serif;
  -webkit-font-smoothing: antialiased;
}
html.dingtalk-swipe { overscroll-behavior-x: none; }
html.dingtalk-swipe,
html.dingtalk-swipe body { touch-action: pan-y; }
button, input, select { font: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }
.is-hidden { display: none !important; }

.app-shell {
  width: 100%;
  max-width: 480px;
  min-height: 100vh;
  margin: 0 auto;
  padding-bottom: calc(16px + env(safe-area-inset-bottom));
  background: var(--canvas);
  box-shadow: 0 0 24px rgba(0, 0, 0, 0.06);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.login-shell {
  width: 100%;
  max-width: 480px;
  min-height: 100vh;
  margin: 0 auto;
  padding: 24px 16px;
  display: grid;
  align-items: center;
  background: var(--canvas);
  box-shadow: 0 0 24px rgba(0, 0, 0, 0.06);
}
.login-card {
  background: var(--surface);
  border-radius: 14px;
  padding: 24px 18px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 10px;
}
.login-badge {
  justify-self: start;
  padding: 4px 10px;
  border-radius: 999px;
  background: #eef4ff;
  color: var(--blue);
  font-size: 12px;
  font-weight: 600;
}
.login-title {
  margin: 2px 0 0;
  font-size: 20px;
  font-weight: 700;
  color: var(--ink);
}
.login-subtitle {
  margin: 0 0 6px;
  font-size: 13px;
  color: var(--muted);
}
.login-form {
  display: grid;
  gap: 12px;
}
.login-field {
  display: grid;
  gap: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
}
.login-field input {
  width: 100%;
  height: 42px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: #ffffff;
  color: var(--ink);
  font-size: 15px;
}
.login-field input:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(38, 114, 255, 0.12);
}
.login-error {
  padding: 8px 10px;
  border-radius: 8px;
  background: #fef2f2;
  color: var(--red-text);
  font-size: 12px;
  font-weight: 500;
}
.login-submit {
  margin-top: 4px;
  height: 44px;
  border: 0;
  border-radius: 9px;
  background: var(--blue);
  color: #ffffff;
  font-size: 15px;
  font-weight: 600;
}
.login-submit:disabled {
  opacity: 0.65;
  cursor: default;
}
.topbar-sub {
  display: grid;
  grid-template-columns: 84px 1fr 84px;
  align-items: center;
  height: 44px;
  padding: 0 10px;
}
.topbar-meta {
  font-size: 10px;
  color: var(--soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.subpage-title {
  margin: 0;
  text-align: center;
  font-size: 15px;
  font-weight: 700;
  color: var(--ink);
}
.refresh-btn {
  justify-self: end;
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 8px;
  color: var(--muted);
  background: transparent;
}
.refresh-btn:active { background: var(--pill); }
.refresh-btn svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.refresh-btn.is-loading svg { animation: spin .75s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.channel-strip-wrap {
  padding: 10px 10px 8px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.channel-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}
.channel-pill {
  padding: 7px 11px;
  border: 0;
  border-radius: 7px;
  font-size: 12px;
  font-weight: 500;
  color: #3f4654;
  background: var(--pill);
  white-space: nowrap;
  transition: background-color 0.15s ease, color 0.15s ease;
}
.channel-pill.is-active {
  color: #ffffff;
  background: var(--blue);
  font-weight: 600;
}

.main-content {
  padding: 10px;
  display: grid;
  gap: 10px;
}

.filter-card,
.panel-card {
  background: var(--surface);
  border-radius: 10px;
  padding: 12px;
  box-shadow: var(--shadow);
}

.filter-card {
  display: grid;
  gap: 10px;
}
.granularity-row,
.query-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.history-query-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr) 56px;
  gap: 6px;
}
.history-filter-group {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
}
.filter-label {
  flex: none;
  font-size: 13px;
  color: var(--muted);
  min-width: 48px;
}
.history-filter-label {
  width: 28px;
  min-width: 28px;
  font-size: 12px;
}
.granularity-tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  flex: 1;
  padding: 3px;
  border-radius: 8px;
  background: var(--pill);
}
.gran-btn {
  height: 30px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
}
.gran-btn.is-active {
  background: var(--blue);
  color: #ffffff;
  font-weight: 600;
  box-shadow: 0 2px 6px rgba(38, 114, 255, 0.25);
}
.period-input-wrap {
  flex: 1;
  min-width: 0;
  display: flex;
}
.history-filter-group .date-input,
.history-filter-group .select-control {
  min-width: 0;
  padding-right: 5px;
  padding-left: 5px;
  font-size: 12px;
}
.history-shop-group .select-control {
  flex: 1;
}
.date-input,
.select-control {
  width: 100%;
  height: 36px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: #ffffff;
  color: var(--ink);
  font-size: 13px;
  font-weight: 500;
  outline: none;
}
.date-input:focus,
.select-control:focus {
  border-color: var(--blue);
}
.query-btn {
  flex: none;
  min-width: 0;
  height: 36px;
  padding: 0 8px;
  border: 0;
  border-radius: 7px;
  background: var(--blue);
  color: #ffffff;
  font-size: 14px;
  font-weight: 600;
}
.query-btn:active { opacity: 0.9; }
@media (max-width: 360px) {
  .history-query-row {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.08fr) 48px;
    gap: 4px;
  }
  .history-filter-group { gap: 3px; }
  .history-filter-label {
    width: 24px;
    min-width: 24px;
    font-size: 11px;
  }
  .history-filter-group .date-input,
  .history-filter-group .select-control {
    padding-right: 3px;
    padding-left: 3px;
    font-size: 11px;
  }
}
.period-hint-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 11px;
}
.period-badge {
  color: var(--muted);
  font-weight: 500;
}
.status-text {
  color: var(--soft);
}
.status-text.is-error {
  color: var(--red-text);
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}
.kpi-card {
  background: var(--surface);
  border-radius: 9px;
  padding: 10px 8px;
  box-shadow: var(--shadow);
  min-width: 0;
}
.kpi-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 4px;
}
.kpi-value {
  font-size: clamp(16px, 4.4vw, 19px);
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: -0.02em;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.kpi-sub {
  margin-top: 5px;
  font-size: 11px;
  color: var(--soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}
.panel-head h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  color: var(--ink);
}
.panel-note {
  font-size: 11px;
  color: var(--soft);
}

.compare-list {
  display: grid;
  gap: 6px;
}
.compare-card {
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fafbfc;
}
.compare-card-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 5px;
}
.compare-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--ink);
}
.compare-date {
  font-size: 11px;
  color: var(--soft);
}
.compare-metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}
.compare-cell {
  min-width: 0;
}
.compare-cell-label {
  font-size: 11px;
  color: var(--soft);
}
.compare-cell-val {
  margin-top: 2px;
  font-size: 13px;
  font-weight: 700;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.compare-delta {
  margin-top: 2px;
  font-size: 11px;
  font-weight: 600;
}
.compare-delta.up { color: var(--red-text); }
.compare-delta.down { color: var(--green-text); }
.compare-delta.flat { color: var(--soft); }

.breakdown-list {
  display: grid;
}
.breakdown-row {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  padding: 10px 4px;
  border-bottom: 1px solid var(--line);
}
.breakdown-row:last-child { border-bottom: 0; }
.breakdown-total {
  margin-bottom: 4px;
  border: 0;
  border-radius: 8px;
  background: #f6f8fc;
}
.breakdown-total .rank-badge {
  background: #e8efff;
  color: var(--blue);
}
.breakdown-row.is-clickable { cursor: pointer; }
.breakdown-row.is-clickable:active { background: #f7f9fc; }
.rank-badge {
  width: 20px;
  height: 20px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  background: var(--pill);
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}
.breakdown-row:nth-child(1) .rank-badge { background: #fff3df; color: #d97706; }
.breakdown-row:nth-child(2) .rank-badge { background: #eef4ff; color: var(--blue); }
.breakdown-row:nth-child(3) .rank-badge { background: #eefbf3; color: var(--green-text); }
.breakdown-main {
  min-width: 0;
}
.breakdown-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.breakdown-sub {
  margin-top: 3px;
  font-size: 11px;
  color: var(--soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.breakdown-right {
  text-align: right;
}
.breakdown-amount {
  font-size: 14px;
  font-weight: 700;
  color: var(--ink);
}
.breakdown-share {
  margin-top: 2px;
  font-size: 11px;
  color: var(--soft);
}

.tabbar {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  height: calc(56px + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  background: var(--surface);
  border-top: 1px solid var(--line);
  z-index: 40;
}
.tab-item {
  border: 0;
  background: transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: #8c93a0;
  font-size: 11px;
  font-weight: 500;
}
.tab-item.is-active {
  color: var(--ink);
  font-weight: 700;
}

.empty-state {
  padding: 26px 0;
  text-align: center;
  color: var(--soft);
  font-size: 12px;
}
.toast {
  position: fixed;
  z-index: 50;
  left: 50%;
  bottom: 72px;
  padding: 9px 14px;
  border-radius: 8px;
  color: #ffffff;
  background: rgba(26, 29, 36, 0.9);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 10px);
  transition: 0.2s ease;
  font-size: 12px;
}
.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}
