/* ============================================================
   组件层：布局 / 按钮 / 表单 / 卡片 / 列表 / 弹层 / 提示
   ============================================================ */

/* ---------------- 应用骨架 ---------------- */
.app {
  display: flex;
  min-height: 100dvh;
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--nav-w);
  display: flex;
  flex-direction: column;
  padding: 18px 14px 14px;
  background: var(--bg-elevated);
  border-right: 1px solid var(--line);
  z-index: 40;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px 18px;
}
.brand-mark {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  color: #fff;
  background: linear-gradient(145deg, #5b7cfa, #3b53d6);
  box-shadow: 0 2px 8px rgba(66, 99, 235, 0.35);
  flex: none;
}
.brand-name {
  font-size: 15.5px;
  font-weight: 650;
  letter-spacing: 0.01em;
}
.brand-sub {
  font-size: 11px;
  color: var(--faint);
  letter-spacing: 0.06em;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 10px;
  color: var(--text-2);
  font-size: 14px;
  font-weight: 500;
  transition: background 0.14s ease, color 0.14s ease;
  text-decoration: none;
}
.nav-item:hover {
  background: var(--surface-3);
  color: var(--text);
  text-decoration: none;
}
.nav-item[aria-current="page"] {
  background: var(--accent-soft);
  color: var(--accent-text);
  font-weight: 600;
}
.nav-item svg {
  flex: none;
  opacity: 0.9;
}
.nav-badge {
  margin-left: auto;
  font-size: 11px;
  font-weight: 600;
  padding: 1px 7px;
  border-radius: 99px;
  background: var(--danger-soft);
  color: var(--danger-2);
}
.nav-foot {
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.shell {
  flex: 1;
  min-width: 0;
  margin-left: var(--nav-w);
  display: flex;
  flex-direction: column;
}

.page {
  width: 100%;
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 26px 30px 96px;
}

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}
.page-title {
  font-size: 24px;
  line-height: 1.25;
  font-weight: 670;
  letter-spacing: -0.015em;
}
.page-sub {
  margin-top: 4px;
  font-size: 13px;
  color: var(--muted);
}
.page-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: none;
}

/* 移动端底栏 */
.tabbar {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 50;
  height: calc(var(--tabbar-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: color-mix(in srgb, var(--bg-elevated) 88%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-top: 1px solid var(--line);
}
.tabbar-inner {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  height: var(--tabbar-h);
}
.tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-size: 10.5px;
  color: var(--muted);
  text-decoration: none;
  min-width: 44px;
}
.tab[aria-current="page"] {
  color: var(--accent);
  font-weight: 600;
}
.tab:hover {
  text-decoration: none;
}

@media (max-width: 900px) {
  .sidebar {
    display: none;
  }
  .shell {
    margin-left: 0;
  }
  .tabbar {
    display: block;
  }
  .page {
    padding: 16px 16px calc(var(--tabbar-h) + var(--safe-bottom) + 28px);
  }
  .page-head {
    margin-bottom: 14px;
    align-items: center;
  }
  .page-title {
    font-size: 21px;
  }
}

/* ---------------- 卡片 / 区块 ---------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-xs);
}
.card-pad {
  padding: 16px;
}
.card-hover {
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}
.card-hover:hover {
  border-color: var(--line-strong);
  box-shadow: var(--shadow-sm);
}

.section {
  margin-bottom: 22px;
}
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
  min-height: 26px;
}
.section-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13.5px;
  font-weight: 650;
  color: var(--text-2);
  letter-spacing: 0.01em;
}
.section-title .count {
  font-weight: 500;
  color: var(--faint);
  font-variant-numeric: tabular-nums;
}
.section-link {
  font-size: 12.5px;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 3px 6px;
  border-radius: 7px;
}
.section-link:hover {
  background: var(--surface-3);
  color: var(--text);
  text-decoration: none;
}

.grid {
  display: grid;
  gap: 12px;
}
.grid-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
.grid-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}
@media (max-width: 760px) {
  .grid-2,
  .grid-3 {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* ---------------- 按钮 ---------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 36px;
  padding: 0 13px;
  border-radius: 10px;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--text);
  font-size: 13.5px;
  font-weight: 550;
  white-space: nowrap;
  transition: background 0.14s ease, border-color 0.14s ease, transform 0.06s ease,
    box-shadow 0.14s ease;
  user-select: none;
}
.btn:hover {
  background: var(--surface-3);
  text-decoration: none;
}
.btn:active {
  transform: translateY(0.5px);
}
.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}
.btn svg {
  flex: none;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
  box-shadow: 0 1px 2px rgba(66, 99, 235, 0.35);
}
.btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}
.btn-ghost {
  border-color: transparent;
  background: transparent;
  color: var(--text-2);
}
.btn-ghost:hover {
  background: var(--surface-3);
  color: var(--text);
}
.btn-soft {
  background: var(--accent-soft);
  border-color: transparent;
  color: var(--accent-text);
}
.btn-soft:hover {
  background: var(--accent-soft);
  filter: brightness(0.97);
}
.btn-danger {
  color: var(--danger-2);
  border-color: color-mix(in srgb, var(--danger-2) 30%, var(--line));
  background: var(--surface);
}
.btn-danger:hover {
  background: var(--danger-soft);
}
.btn-sm {
  height: 30px;
  padding: 0 10px;
  font-size: 12.5px;
  border-radius: 8px;
  gap: 4px;
}
.btn-lg {
  height: 42px;
  padding: 0 18px;
  font-size: 15px;
  border-radius: 12px;
}
.btn-block {
  width: 100%;
}
.btn-icon {
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: 9px;
  border-color: transparent;
  color: var(--muted);
  background: transparent;
}
.btn-icon:hover {
  background: var(--surface-3);
  color: var(--text);
}
.btn-icon.sm {
  width: 28px;
  height: 28px;
}

/* ---------------- 表单 ---------------- */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}
.label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-2);
  display: flex;
  align-items: center;
  gap: 6px;
}
.label .req {
  color: var(--danger-2);
  font-weight: 500;
}
.hint {
  font-size: 11.5px;
  color: var(--muted);
  line-height: 1.5;
}
.err-text {
  font-size: 11.5px;
  color: var(--danger-2);
}

.input,
.textarea,
.select {
  width: 100%;
  min-width: 0;
  height: 40px;
  padding: 0 12px;
  border-radius: 10px;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  transition: border-color 0.14s ease, box-shadow 0.14s ease;
  appearance: none;
  -webkit-appearance: none;
}
.input::placeholder,
.textarea::placeholder {
  color: var(--faint);
}
.input:focus,
.textarea:focus,
.select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 16%, transparent);
}
.input:disabled,
.select:disabled {
  background: var(--surface-3);
  color: var(--muted);
}
.input.invalid,
.textarea.invalid {
  border-color: var(--danger-2);
}
.textarea {
  height: auto;
  min-height: 84px;
  padding: 10px 12px;
  line-height: 1.6;
  resize: vertical;
}
.select {
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23737c8b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 32px;
}
.input-sm {
  height: 34px;
  font-size: 13px;
  border-radius: 8px;
}
.input-date {
  font-variant-numeric: tabular-nums;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}
.form-grid .span-2 {
  grid-column: 1 / -1;
}
@media (max-width: 620px) {
  .form-grid {
    grid-template-columns: minmax(0, 1fr);
  }
  .form-grid .span-2 {
    grid-column: auto;
  }
}

.check-row {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 13.5px;
  cursor: pointer;
  user-select: none;
  min-height: 32px;
}
.check-box {
  width: 19px;
  height: 19px;
  border-radius: 6px;
  border: 1.5px solid var(--line-strong);
  display: grid;
  place-items: center;
  background: var(--surface);
  flex: none;
  transition: all 0.12s ease;
  color: transparent;
}
.check-row[data-checked="true"] .check-box {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}

.switch {
  position: relative;
  width: 42px;
  height: 25px;
  border-radius: 99px;
  background: var(--line-strong);
  flex: none;
  transition: background 0.16s ease;
}
.switch[data-on="true"] {
  background: var(--accent);
}
.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 19px;
  height: 19px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
  transition: transform 0.16s cubic-bezier(0.3, 1.2, 0.5, 1);
}
.switch[data-on="true"]::after {
  transform: translateX(17px);
}

/* 分段控件 */
.seg {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  background: var(--surface-3);
  border-radius: 10px;
  overflow-x: auto;
  max-width: 100%;
  scrollbar-width: none;
}
.seg::-webkit-scrollbar {
  display: none;
}
.seg-item {
  padding: 5px 11px;
  border-radius: 8px;
  font-size: 12.5px;
  font-weight: 550;
  color: var(--muted);
  white-space: nowrap;
  transition: background 0.14s ease, color 0.14s ease;
}
.seg-item:hover {
  color: var(--text);
}
.seg-item[aria-selected="true"] {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-xs);
}

/* ---------------- 徽章 / 标签 ---------------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 1.5px 7px;
  border-radius: 6px;
  font-size: 11.5px;
  font-weight: 550;
  line-height: 1.55;
  white-space: nowrap;
  border: 1px solid transparent;
}
.badge-neutral {
  background: var(--surface-3);
  color: var(--text-2);
}
.badge-accent {
  background: var(--accent-soft);
  color: var(--accent-text);
}
.badge-ok {
  background: var(--ok-soft);
  color: var(--ok);
}
.badge-warn {
  background: var(--warn-soft);
  color: var(--warn);
}
.badge-danger {
  background: var(--danger-soft);
  color: var(--danger-2);
}
.badge-info {
  background: var(--info-soft);
  color: var(--info);
}
.badge-outline {
  border-color: var(--line-strong);
  color: var(--muted);
  background: transparent;
}

.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex: none;
  background: var(--accent);
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  padding: 0 10px;
  border-radius: 99px;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  font-size: 12.5px;
  color: var(--text-2);
  white-space: nowrap;
}
.chip[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-text);
  font-weight: 550;
}

.tag-dot {
  width: 9px;
  height: 9px;
  border-radius: 3px;
  flex: none;
}

/* ---------------- 列表 ---------------- */
.list {
  display: flex;
  flex-direction: column;
}
.list-item {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  min-width: 0;
  text-align: left;
  width: 100%;
  transition: background 0.12s ease;
}
.list-item:last-child {
  border-bottom: none;
}
.list-item:hover {
  background: var(--surface-2);
  text-decoration: none;
}
.list-item.is-clickable {
  cursor: pointer;
}
.li-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.li-title {
  font-size: 14px;
  font-weight: 550;
  color: var(--text);
  line-height: 1.45;
  word-break: break-word;
}
.li-title.done {
  color: var(--muted);
  text-decoration: line-through;
  text-decoration-color: var(--faint);
}
.li-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--muted);
}
.li-side {
  flex: none;
  display: flex;
  align-items: center;
  gap: 6px;
  align-self: center;
}

/* ---------------- 空状态 / 加载 ---------------- */
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 26px 18px;
  gap: 6px;
}
.empty-icon {
  width: 42px;
  height: 42px;
  border-radius: 13px;
  display: grid;
  place-items: center;
  background: var(--surface-3);
  color: var(--faint);
  margin-bottom: 4px;
}
.empty-title {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-2);
}
.empty-desc {
  font-size: 12.5px;
  color: var(--muted);
  max-width: 34em;
  line-height: 1.6;
}

.skeleton {
  background: linear-gradient(90deg, var(--surface-3) 25%, var(--surface-2) 37%, var(--surface-3) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.4s ease infinite;
  border-radius: 8px;
}
@keyframes shimmer {
  0% {
    background-position: 100% 0;
  }
  100% {
    background-position: 0 0;
  }
}

/* ---------------- 弹层 ---------------- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: rgba(16, 20, 28, 0.42);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fade-in 0.15s ease;
}
@keyframes fade-in {
  from {
    opacity: 0;
  }
}
.modal {
  width: 100%;
  max-width: 560px;
  max-height: min(88dvh, 900px);
  display: flex;
  flex-direction: column;
  background: var(--bg-elevated);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--line);
  animation: pop-in 0.18s cubic-bezier(0.2, 0.9, 0.3, 1.1);
  overflow: hidden;
}
.modal.wide {
  max-width: 760px;
}
@keyframes pop-in {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.985);
  }
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px 12px;
  border-bottom: 1px solid var(--line);
}
.modal-title {
  font-size: 16px;
  font-weight: 650;
}
.modal-body {
  padding: 16px 18px;
  overflow-y: auto;
  flex: 1;
  -webkit-overflow-scrolling: touch;
}
.modal-foot {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 18px calc(14px + var(--safe-bottom));
  border-top: 1px solid var(--line);
  background: var(--surface-2);
}
.modal-foot .left {
  margin-right: auto;
}

@media (max-width: 640px) {
  .overlay {
    padding: 0;
    align-items: flex-end;
  }
  .modal {
    max-width: 100%;
    max-height: 92dvh;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    animation: sheet-in 0.22s cubic-bezier(0.2, 0.9, 0.3, 1);
  }
  @keyframes sheet-in {
    from {
      transform: translateY(100%);
    }
  }
  .modal-foot {
    padding-bottom: calc(14px + var(--safe-bottom));
  }
}

/* ---------------- Toast ---------------- */
.toast-wrap {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 16px);
  transform: translateX(-50%);
  z-index: 120;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
  width: min(92vw, 420px);
}
@media (min-width: 901px) {
  .toast-wrap {
    bottom: 28px;
  }
}
.toast {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 100%;
  padding: 9px 14px;
  border-radius: 11px;
  background: #1d222b;
  color: #f4f6f8;
  font-size: 13px;
  box-shadow: var(--shadow-md);
  animation: toast-in 0.2s ease;
  pointer-events: auto;
}
.toast.error {
  background: #b3261e;
}
.toast.success {
  background: #1f7a33;
}
@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
}

/* ---------------- 同步状态 ---------------- */
.sync-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  color: var(--muted);
  padding: 4px 9px;
  border-radius: 99px;
  background: var(--surface-3);
  white-space: nowrap;
}
.sync-pill .dot {
  width: 6px;
  height: 6px;
  background: var(--ok);
}
.sync-pill[data-state="saving"] .dot {
  background: var(--warn);
  animation: pulse 1s ease infinite;
}
.sync-pill[data-state="error"] .dot {
  background: var(--danger-2);
}
.sync-pill[data-state="offline"] .dot {
  background: var(--muted);
}
@keyframes pulse {
  50% {
    opacity: 0.35;
  }
}

/* ---------------- 杂项 ---------------- */
.divider {
  height: 1px;
  background: var(--line);
  border: 0;
  margin: 0;
}
.progress {
  height: 6px;
  border-radius: 99px;
  background: var(--surface-3);
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  border-radius: 99px;
  background: var(--accent);
  transition: width 0.3s ease;
}
.kv {
  display: grid;
  grid-template-columns: 84px minmax(0, 1fr);
  gap: 6px 12px;
  font-size: 13px;
}
.kv dt {
  color: var(--muted);
  font-size: 12.5px;
}
.kv dd {
  margin: 0;
  color: var(--text);
  word-break: break-word;
}
.stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 12px 14px;
}
.stat-num {
  font-size: 21px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}
.stat-label {
  font-size: 12px;
  color: var(--muted);
}
.tint-ok {
  color: var(--ok);
}
.tint-warn {
  color: var(--warn);
}
.tint-danger {
  color: var(--danger-2);
}
.tint-accent {
  color: var(--accent);
}
