/* ---------- App shell ---------- */
.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--md-sys-color-surface);
}

.top-app-bar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 12px;
  height: 64px;
  padding: 0 16px;
  background: var(--md-sys-color-surface);
  color: var(--md-sys-color-on-surface);
  transition: background-color var(--md-sys-motion-standard),
    box-shadow var(--md-sys-motion-standard);
}

.top-app-bar.scrolled {
  background: var(--md-sys-color-surface-container);
  box-shadow: var(--md-sys-elevation-1);
}

.top-app-bar__leading {
  width: 40px;
  height: 40px;
  border-radius: var(--md-sys-shape-corner-full);
  display: grid;
  place-items: center;
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
  font-weight: 700;
  font-size: 18px;
  letter-spacing: -0.5px;
}

.top-app-bar__title {
  flex: 1;
  font-size: 22px;
  line-height: 28px;
  font-weight: 500;
  letter-spacing: 0;
}

.top-app-bar__subtitle {
  display: block;
  font-size: 12px;
  line-height: 16px;
  font-weight: 400;
  color: var(--md-sys-color-on-surface-variant);
}

.page {
  flex: 1;
  width: 100%;
  max-width: 920px;
  margin: 0 auto;
  padding: 8px 16px 120px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ---------- Cards ---------- */
.card {
  background: var(--md-sys-color-surface-container-low);
  border-radius: var(--md-sys-shape-corner-md);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  transition: background-color var(--md-sys-motion-standard);
}

.card--filled {
  background: var(--md-sys-color-surface-container-high);
}

.card--primary {
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
}

.card__header {
  display: flex;
  align-items: center;
  gap: 8px;
}

.card__title {
  font-size: 16px;
  line-height: 24px;
  font-weight: 500;
  letter-spacing: 0.15px;
  margin: 0;
}

.card__desc {
  font-size: 13px;
  line-height: 20px;
  color: var(--md-sys-color-on-surface-variant);
  margin: -8px 0 0;
}

.badge {
  font-size: 11px;
  font-weight: 500;
  padding: 2px 8px;
  border-radius: var(--md-sys-shape-corner-full);
  background: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
  line-height: 16px;
}

/* ---------- Text fields ---------- */
.field {
  position: relative;
  display: flex;
  flex-direction: column;
}

.field__box {
  position: relative;
  display: flex;
  align-items: center;
  border-radius: var(--md-sys-shape-corner-xs);
  border: 1px solid var(--md-sys-color-outline);
  background: transparent;
  transition: border-color 150ms, box-shadow 150ms;
}

.field__box:focus-within {
  border-color: var(--md-sys-color-primary);
  box-shadow: inset 0 0 0 1px var(--md-sys-color-primary);
}

.field__box.invalid {
  border-color: var(--md-sys-color-error);
  box-shadow: inset 0 0 0 1px var(--md-sys-color-error);
}

.field input {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--md-sys-color-on-surface);
  font-family: var(--md-sys-typescale-font);
  font-size: 16px;
  line-height: 24px;
  padding: 16px;
  letter-spacing: 0.5px;
}

.field input::placeholder {
  color: transparent;
}

.field__label {
  position: absolute;
  left: 12px;
  top: 16px;
  padding: 0 4px;
  font-size: 16px;
  line-height: 24px;
  color: var(--md-sys-color-on-surface-variant);
  background: var(--md-sys-color-surface-container-low);
  pointer-events: none;
  transition: all 150ms cubic-bezier(0.2, 0, 0, 1);
  border-radius: 2px;
}

.card--filled .field__label {
  background: var(--md-sys-color-surface-container-high);
}

.field__box:focus-within + .field__label,
.field__box.filled + .field__label {
  top: -8px;
  font-size: 12px;
  line-height: 16px;
  color: var(--md-sys-color-primary);
}

.field__box.invalid + .field__label {
  color: var(--md-sys-color-error);
}

.field__support {
  font-size: 12px;
  line-height: 16px;
  color: var(--md-sys-color-on-surface-variant);
  padding: 4px 16px 0;
}

.field__support.error {
  color: var(--md-sys-color-error);
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

@media (max-width: 560px) {
  .field-row {
    grid-template-columns: 1fr;
  }
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 40px;
  padding: 0 24px;
  border: 0;
  border-radius: var(--md-sys-shape-corner-full);
  font-family: var(--md-sys-typescale-font);
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 0.1px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: box-shadow 150ms, background-color 150ms, opacity 150ms;
  white-space: nowrap;
}

.btn:disabled {
  cursor: default;
  opacity: 0.38;
}

.btn--filled {
  background: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
}

.btn--filled:not(:disabled):hover {
  box-shadow: var(--md-sys-elevation-1);
}

.btn--tonal {
  background: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
}

.btn--outlined {
  background: transparent;
  color: var(--md-sys-color-primary);
  border: 1px solid var(--md-sys-color-outline);
}

.btn--text {
  background: transparent;
  color: var(--md-sys-color-primary);
  padding: 0 12px;
}

.btn--elevated {
  background: var(--md-sys-color-surface-container-low);
  color: var(--md-sys-color-primary);
  box-shadow: var(--md-sys-elevation-1);
}

.icon-btn {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: var(--md-sys-shape-corner-full);
  background: transparent;
  color: var(--md-sys-color-on-surface-variant);
  cursor: pointer;
  font-size: 18px;
  transition: background-color 150ms;
}

.icon-btn:hover {
  background: var(--md-sys-color-surface-container-high);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.spacer {
  flex: 1;
}

/* ---------- Chips / segmented ---------- */
.chip-set {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 12px;
  border-radius: var(--md-sys-shape-corner-sm);
  border: 1px solid var(--md-sys-color-outline-variant);
  background: transparent;
  color: var(--md-sys-color-on-surface-variant);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 150ms, color 150ms, border-color 150ms;
}

.chip:hover {
  background: var(--md-sys-color-surface-container-high);
}

.chip.active {
  background: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
  border-color: transparent;
}

/* ---------- Stats ---------- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 12px;
}

.stat {
  background: var(--md-sys-color-surface-container);
  border-radius: var(--md-sys-shape-corner-md);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stat__value {
  font-size: 26px;
  line-height: 32px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

.stat__label {
  font-size: 12px;
  line-height: 16px;
  color: var(--md-sys-color-on-surface-variant);
}

.stat--accent {
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
}

.stat--accent .stat__label {
  color: var(--md-sys-color-on-primary-container);
  opacity: 0.75;
}

/* ---------- Result list ---------- */
.result-list {
  background: var(--md-sys-color-surface-container);
  border-radius: var(--md-sys-shape-corner-md);
  max-height: 320px;
  overflow: auto;
  padding: 8px 0;
  font-variant-numeric: tabular-nums;
  font-size: 14px;
  line-height: 20px;
  scrollbar-width: thin;
}

.result-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 16px;
}

.result-row:hover {
  background: var(--md-sys-color-surface-container-high);
}

.result-row__idx {
  color: var(--md-sys-color-on-surface-variant);
  font-size: 12px;
  min-width: 44px;
}

.result-row__num {
  letter-spacing: 0.5px;
}

.result-empty {
  padding: 32px 16px;
  text-align: center;
  color: var(--md-sys-color-on-surface-variant);
  font-size: 13px;
}

/* ---------- Progress ---------- */
.linear {
  height: 4px;
  border-radius: var(--md-sys-shape-corner-full);
  background: var(--md-sys-color-surface-variant);
  overflow: hidden;
  position: relative;
}

.linear__bar {
  position: absolute;
  inset: 0 auto 0 0;
  width: 40%;
  border-radius: inherit;
  background: var(--md-sys-color-primary);
  animation: indet 1.4s cubic-bezier(0.2, 0, 0, 1) infinite;
}

@keyframes indet {
  0% {
    left: -40%;
    width: 40%;
  }
  50% {
    left: 30%;
    width: 55%;
  }
  100% {
    left: 100%;
    width: 30%;
  }
}

@media (prefers-reduced-motion: reduce) {
  .linear__bar {
    animation: none;
    left: 0;
    width: 100%;
    opacity: 0.6;
  }
  * {
    transition-duration: 1ms !important;
  }
}

/* ---------- Snackbar ---------- */
.snackbar {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%) translateY(16px);
  min-width: 280px;
  max-width: min(560px, calc(100vw - 32px));
  padding: 14px 16px;
  border-radius: var(--md-sys-shape-corner-xs);
  background: var(--md-sys-color-inverse-surface);
  color: var(--md-sys-color-inverse-on-surface);
  font-size: 14px;
  line-height: 20px;
  box-shadow: var(--md-sys-elevation-3);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--md-sys-motion-standard),
    transform var(--md-sys-motion-standard);
  z-index: 50;
}

.snackbar.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
  pointer-events: auto;
}

.snackbar.error {
  background: var(--md-sys-color-error-container);
  color: var(--md-sys-color-on-error-container);
}

/* ---------- Misc ---------- */
.mono {
  font-family: 'Roboto Mono', ui-monospace, 'Cascadia Mono', monospace;
}

.hint {
  font-size: 12px;
  line-height: 18px;
  color: var(--md-sys-color-on-surface-variant);
}

textarea.raw {
  width: 100%;
  min-height: 96px;
  resize: vertical;
  border-radius: var(--md-sys-shape-corner-xs);
  border: 1px solid var(--md-sys-color-outline);
  background: transparent;
  color: var(--md-sys-color-on-surface);
  font-family: 'Roboto Mono', ui-monospace, monospace;
  font-size: 12px;
  line-height: 18px;
  padding: 12px;
  outline: 0;
}

textarea.raw:focus {
  border-color: var(--md-sys-color-primary);
  box-shadow: inset 0 0 0 1px var(--md-sys-color-primary);
}

.divider {
  height: 1px;
  background: var(--md-sys-color-outline-variant);
  margin: 4px 0;
}

.link {
  color: var(--md-sys-color-primary);
  text-decoration: none;
  font-weight: 500;
}

.link:hover {
  text-decoration: underline;
}

/* ---------- 静态版补充：号段 chips 滚动容器 / 文本域高度 / 顶栏粘性 ---------- */
.chip-set--scroll {
  max-height: 180px;
  overflow: auto;
  scrollbar-width: thin;
  padding-right: 4px;
}

.chip-set--scroll .chip {
  cursor: default;
}

textarea.raw {
  min-height: 128px;
  font-size: 13px;
}

/* 原生 select 一致性补齐（若后续加下拉） */
select.raw {
  width: 100%;
  padding: 12px;
  border-radius: var(--md-sys-shape-corner-xs);
  border: 1px solid var(--md-sys-color-outline);
  background: transparent;
  color: var(--md-sys-color-on-surface);
  font-family: var(--md-sys-typescale-font);
  font-size: 16px;
}

/* 键盘焦点可见性（原生元素比 React 版更需要显式处理） */
:where(button, input, textarea, a):focus-visible {
  outline: 2px solid var(--md-sys-color-primary);
  outline-offset: 2px;
}

/* 视觉隐藏但对读屏可见 */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* 窄屏下概览标题与 URL 徽章不要挤在一行 */
.card__header {
  flex-wrap: wrap;
  row-gap: 6px;
}

.card__header > .badge.mono {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (max-width: 360px) {
  .page { padding: 8px 12px 96px; }
  .card { padding: 16px; }
}
