:root {
  --primary: #0d9488;
  --primary-dark: #0f766e;
  --primary-soft: #ccfbf1;
  --bg: #f2faf7;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #7a9189;
  --border: #d3e9e2;
  --danger: #dc2626;
  --warn: #d97706;
  --warn-soft: #fef3c7;
  --red-soft: #ffe4e6;
  --shadow: 0 1px 3px rgba(13,148,136,.10);
  --radius: 16px;
  --tabbar-h: 60px;
  --header-h: 54px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* 顶部 */
.app-header {
  position: sticky; top: 0; z-index: 20;
  height: calc(var(--header-h) + env(safe-area-inset-top, 0px));
  display: flex; align-items: flex-end; justify-content: space-between;
  padding: env(safe-area-inset-top, 0px) 16px 0;
  background: linear-gradient(135deg, #14b8a6, #0d9488);
  color: #fff;
}
.header-brand { font-weight: 700; font-size: 18px; display: flex; align-items: center; gap: 6px; padding-bottom: 12px; }
.header-logo { font-size: 20px; }
.icon-btn {
  background: none; border: none; color: inherit;
  font-size: 20px; width: 40px; height: 40px;
  border-radius: 12px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  margin-bottom: 3px;
}
.app-header .icon-btn:active { background: rgba(255,255,255,.25); }

main {
  padding: 14px 14px;
  padding-bottom: calc(var(--tabbar-h) + 90px + var(--safe-bottom));
  max-width: 560px; margin: 0 auto;
}

/* 分区标题 */
.section-title { font-size: 14px; font-weight: 700; color: var(--muted); margin: 4px 0 10px; }

/* 临期横幅 */
.urgent-banner {
  background: linear-gradient(135deg, #fbbf24, #f59e0b);
  color: #7c2d12; border-radius: 14px;
  padding: 11px 14px; margin-bottom: 14px;
  font-size: 14px; font-weight: 700; cursor: pointer;
  display: flex; align-items: center; justify-content: space-between;
  box-shadow: var(--shadow);
}
.urgent-banner:active { filter: brightness(.97); }
.urgent-banner .ub-go { font-size: 16px; }

/* 分类分组 */
.cat-group { margin-bottom: 18px; }
.cat-head {
  display: flex; align-items: baseline; justify-content: space-between;
  margin-bottom: 8px; padding: 0 2px;
}
.cat-name { font-size: 15px; font-weight: 800; }
.cat-name .cat-dot { font-size: 14px; margin-right: 6px; }
.cat-count { font-size: 12px; color: var(--muted); }

.entry-list { display: flex; flex-direction: column; gap: 8px; }
.entry {
  background: var(--card); border-radius: 14px;
  padding: 11px 13px; box-shadow: var(--shadow);
  display: flex; align-items: center; gap: 10px;
  cursor: pointer; border: 1px solid transparent;
}
.entry:active { background: var(--primary-soft); border-color: #99f6e4; }
.entry.expired { border-color: #fecaca; background: #fffbfb; }
.entry.soon { border-color: #fde68a; }
.entry-body { flex: 1; min-width: 0; }
.entry-main { font-size: 15px; font-weight: 700; }
.entry-sub { font-size: 12px; color: var(--muted); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry-sub b { font-weight: 600; }
.entry-extra { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex-shrink: 0; }
.entry-arrow { color: var(--border); font-size: 16px; flex-shrink: 0; }

.tag {
  font-size: 11px; font-weight: 700; padding: 2px 9px; border-radius: 999px;
  white-space: nowrap;
}
.tag.soft { background: var(--primary-soft); color: var(--primary-dark); }
.tag.gray { background: #f1f5f9; color: #64748b; }
.tag.red { background: var(--red-soft); color: var(--danger); }
.tag.amber { background: var(--warn-soft); color: var(--warn); }
.count-chip { font-size: 12px; font-weight: 700; color: var(--primary-dark); background: var(--primary-soft); border-radius: 999px; padding: 1px 8px; }
.count-chip::before { content: "×"; }

.empty-tip { text-align: center; color: #a8c4bb; font-size: 14px; padding: 40px 10px; line-height: 1.9; }

/* 分类管理 */
.cat-add { display: flex; gap: 8px; margin-bottom: 4px; }
.cat-add input {
  flex: 1; padding: 11px 13px; font-size: 15px;
  border: 1px solid var(--border); border-radius: 12px;
  background: #fff; min-width: 0;
}
.cat-add input:focus { outline: none; border-color: var(--primary); }
.cat-tip { font-size: 12px; color: var(--muted); margin: 6px 2px 12px; line-height: 1.6; }
.cat-row {
  background: var(--card); border-radius: 13px;
  display: flex; align-items: center; gap: 4px;
  padding: 8px 10px; margin-bottom: 8px; box-shadow: var(--shadow);
}
.cat-move { display: flex; flex-direction: column; gap: 1px; }
.cat-move button {
  border: none; background: none; color: var(--muted);
  font-size: 13px; line-height: 1.1; padding: 1px 4px; cursor: pointer; border-radius: 6px;
}
.cat-move button:active { background: var(--primary-soft); color: var(--primary-dark); }
.cat-move button:disabled { opacity: .25; }
.cat-info { flex: 1; min-width: 0; padding: 0 4px; }
.cat-info .ci-name { font-size: 15px; font-weight: 700; }
.cat-info .ci-name input {
  width: 100%; font-size: 15px; font-weight: 700; padding: 5px 8px;
  border: 1.5px solid var(--primary); border-radius: 8px; background: #fff;
}
.cat-info .ci-sub { font-size: 11px; color: var(--muted); }
.cat-fixed { font-size: 11px; color: #b0c9c1; margin-left: 6px; }
.cat-op { border: none; background: none; font-size: 15px; padding: 6px 7px; cursor: pointer; border-radius: 8px; }
.cat-op:active { background: var(--primary-soft); }

/* 底部导航 */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  height: calc(var(--tabbar-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--card); border-top: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-around;
  max-width: 560px; margin: 0 auto;
}
.tab {
  background: none; border: none; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 11px; color: var(--muted); padding: 5px 14px;
}
.tab .ti { font-size: 21px; line-height: 1.2; position: relative; display: inline-block; }
.tab.active { color: var(--primary-dark); font-weight: 700; }
.badge {
  position: absolute; top: -4px; right: -11px;
  background: var(--danger); color: #fff;
  font-size: 10px; font-style: normal; font-weight: 700;
  min-width: 16px; height: 16px; border-radius: 999px;
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0 4px;
}

/* 悬浮添加按钮 */
.fab {
  position: fixed; right: calc(50% - 280px + 22px); bottom: calc(var(--tabbar-h) + 22px + var(--safe-bottom));
  width: 58px; height: 58px; border-radius: 50%;
  border: none; background: linear-gradient(135deg, #14b8a6, #0d9488);
  color: #fff; font-size: 30px; font-weight: 400; line-height: 1;
  box-shadow: 0 6px 16px rgba(13,148,136,.4); cursor: pointer;
  z-index: 30; display: flex; align-items: center; justify-content: center;
}
.fab:active { transform: scale(.94); }
@media (max-width: 600px) { .fab { right: 20px; } }

/* 模态框 */
.modal {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(6,60,54,.45);
  display: flex; align-items: flex-end; justify-content: center;
}
.modal-card {
  background: var(--card); width: 100%; max-width: 560px;
  border-radius: 20px 20px 0 0;
  max-height: 90vh; overflow-y: auto;
  padding-bottom: var(--safe-bottom);
  -webkit-overflow-scrolling: touch;
}
.modal-card-sm { border-radius: 20px; margin: 0 16px 16px; width: calc(100% - 32px); }
#confirm-modal { z-index: 55; }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px 6px;
}
.modal-head h3 { margin: 0; font-size: 18px; }
.modal-head .modal-close { color: var(--muted); }
.modal-body { padding: 8px 18px 16px; }
.modal-foot { display: flex; gap: 12px; padding: 12px 18px 20px; }
.modal-body.center { text-align: center; }
.modal-body.center p { font-size: 16px; font-weight: 600; }

.field { display: block; margin-bottom: 13px; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 5px; font-weight: 600; }
.field input, .field select, textarea {
  width: 100%; padding: 11px 13px; font-size: 16px;
  border: 1px solid var(--border); border-radius: 12px;
  background: #fff; color: var(--text); font-family: inherit;
}
.field input:focus, .field select:focus, textarea:focus { outline: none; border-color: var(--primary); }
.field select { appearance: none; -webkit-appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 18px) 55%, calc(100% - 13px) 55%; background-size: 5px 5px; background-repeat: no-repeat; }
.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 1; min-width: 0; }
textarea { min-height: 110px; resize: vertical; font-size: 14px; line-height: 1.6; }

/* 按钮 */
.btn {
  flex: 1; border: none; border-radius: 14px; padding: 13px;
  font-size: 16px; font-weight: 700; cursor: pointer;
}
.btn-primary { background: linear-gradient(135deg, #14b8a6, #0d9488); color: #fff; }
.btn-primary:active { filter: brightness(.94); }
.btn-ghost { background: #eef8f4; color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-small { flex: none; padding: 7px 15px; font-size: 13px; border-radius: 10px; font-weight: 700; }
.btn-sm { flex: none; padding: 11px 16px; font-size: 15px; }

/* 设置 */
.settings-block { padding: 10px 0 14px; border-bottom: 1px solid var(--border); }
.settings-label { font-size: 13px; color: var(--muted); font-weight: 700; margin-bottom: 8px; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  border: 1.5px solid var(--border); background: #fff; color: var(--muted);
  padding: 6px 14px; border-radius: 999px; font-size: 14px; cursor: pointer; font-weight: 600;
}
.chip.on { border-color: var(--primary); background: var(--primary-soft); color: var(--primary-dark); }
.settings-note { font-size: 12px; color: var(--muted); margin: 8px 0 0; line-height: 1.7; }
.settings-row { display: flex; align-items: center; justify-content: space-between; padding: 12px 0; border-bottom: 1px solid var(--border); gap: 10px; }
.settings-row > span { font-size: 14px; font-weight: 600; }
.settings-row:last-of-type { border-bottom: none; }
.settings-hint { font-size: 12px; color: var(--muted); margin-top: 14px; line-height: 1.8; }

#paste-modal .btn { padding: 12px 4px; font-size: 15px; }

/* 搜索栏 */
.searchbar {
  display: flex; align-items: center; gap: 6px;
  background: #fff; border: 1.5px solid var(--border); border-radius: 12px;
  padding: 0 6px 0 10px; margin-bottom: 4px;
}
.searchbar:focus-within { border-color: var(--primary); }
.sb-icon { font-size: 14px; opacity: .6; }
#search-input {
  flex: 1; min-width: 0; border: none; background: none;
  font-size: 15px; padding: 9px 2px; color: var(--text);
  -webkit-appearance: none; appearance: none;
}
#search-input:focus { outline: none; }
#search-input::-webkit-search-cancel-button { display: none; }
.sb-clear {
  border: none; background: #eef4f1; color: var(--muted);
  width: 24px; height: 24px; border-radius: 50%;
  font-size: 12px; cursor: pointer; flex-shrink: 0;
}
.search-summary { font-size: 12px; color: var(--muted); padding: 2px 2px 8px; }

/* 清单树状分组 */
.subtree {
  margin: 2px 0 4px 14px;
  padding-left: 12px;
  border-left: 2px solid #d7efe7;
}
.subtree .cat-name { font-size: 14px; }
.subtree .subtree .cat-name { font-size: 13px; color: #47665e; }
.cat-group .subtree .cat-group { margin-bottom: 12px; }

/* 三级分类选择 */
.cat3-grid { display: flex; gap: 8px; }
.cat3-grid select {
  width: 100%; min-width: 0; padding: 11px 8px; font-size: 14px;
  border: 1px solid var(--border); border-radius: 12px; background: #fff; color: var(--text);
  appearance: none; -webkit-appearance: none; text-align: center;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 10px) 55%, calc(100% - 6px) 55%;
  background-size: 4px 4px; background-repeat: no-repeat;
}
.cat3-grid select:focus { outline: none; border-color: var(--primary); }
.cat3-grid select:disabled { background: #f3f7f5; color: #b3c4be; }
.cat3-labels { display: flex; gap: 8px; margin-top: 4px; }
.cat3-labels span {
  flex: 1; text-align: center; font-size: 11px; color: var(--muted);
}
.path-preview { margin-top: 8px; min-height: 22px; }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + 90px + var(--safe-bottom));
  transform: translateX(-50%);
  background: rgba(15,40,35,.92); color: #fff; font-size: 14px;
  padding: 10px 18px; border-radius: 999px; z-index: 60;
  white-space: nowrap; max-width: 90vw; overflow: hidden; text-overflow: ellipsis;
}

@media (min-width: 560px) {
  .modal { align-items: center; }
  .modal-card { border-radius: 20px; margin: 0 16px; width: calc(100% - 32px); }
}
