:root {
  --bg: #f5f6f2;
  --surface: #ffffff;
  --surface-soft: #f8f9f6;
  --sidebar: #e7ede4;
  --ink: #14231e;
  --muted: #66736d;
  --line: #dbe2dc;
  --accent: #c85638;
  --accent-soft: #f6e4dc;
  --danger: #a53f35;
  --danger-soft: #f7e8e5;
  --focus: #2f6f62;
  --shadow: 0 16px 44px rgba(23, 35, 31, .09);
  --shadow-soft: 0 8px 26px rgba(23, 35, 31, .055);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, "Microsoft YaHei", "PingFang SC", sans-serif;
}

button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .55; }
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible, summary:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.app { display: flex; min-height: 100vh; }

aside {
  position: sticky;
  top: 0;
  width: 232px;
  height: 100vh;
  flex: 0 0 232px;
  background: var(--sidebar);
  padding: 28px 20px;
  display: flex;
  flex-direction: column;
}

.brand { display: flex; align-items: center; gap: 10px; letter-spacing: .12em; font-size: 17px; }
.brand span {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: var(--ink);
  color: white;
  letter-spacing: 0;
}

.new {
  min-height: 44px;
  margin: 36px 0 20px;
  border: 0;
  border-radius: 10px;
  background: var(--ink);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.nav {
  width: 100%;
  min-height: 43px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: #5e6a63;
  padding: 10px;
  display: flex;
  align-items: center;
  gap: 11px;
  text-align: left;
}
.nav:hover, .nav.active { background: #d4dfd1; color: var(--ink); }
.nav-icon { width: 19px; height: 19px; flex: 0 0 19px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.nav i {
  margin-left: auto;
  min-width: 20px;
  padding: 2px 6px;
  border-radius: 10px;
  background: var(--accent);
  color: white;
  font-size: 11px;
  font-style: normal;
  text-align: center;
}
.nav i:empty, .nav i[data-count="0"] { display: none; }

.side-note {
  margin-top: auto;
  color: #657169;
  font-size: 12px;
  line-height: 1.65;
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
}
.settings-link, .link-button {
  padding: 0;
  border: 0;
  background: none;
  color: var(--muted);
  text-decoration: underline;
  text-underline-offset: 3px;
}

main { flex: 1; width: min(1160px, calc(100% - 232px)); padding: 42px clamp(28px, 6vw, 76px) 70px; }
header, #view, .storage-notice { max-width: 920px; }
header { display: flex; justify-content: space-between; align-items: end; border-bottom: 1px solid var(--line); padding-bottom: 22px; }
.kicker { margin: 0 0 9px; color: var(--accent); font-size: 12px; letter-spacing: .12em; }
h1 { margin: 0; font-size: 40px; line-height: 1.15; letter-spacing: -.03em; }
h2, h3 { letter-spacing: 0; }
.date, .status, .count, .helper { color: var(--muted); font-size: 12px; }
.storage-notice {
  margin-top: 18px;
  padding: 11px 13px;
  border: 1px solid #e3bbb4;
  border-radius: 5px;
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 13px;
  line-height: 1.55;
}
.storage-notice[hidden] { display: none; }

.record-box, .detail, .settings-panel {
  margin-top: 30px;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
}
.record-box { border-color: #d5ddd6; box-shadow: var(--shadow-soft); }
.capture-page { margin-top: 24px; }
.capture-page > .back { margin-bottom: 8px; }
.capture-page .record-box { margin-top: 0; }
.capture-editor textarea { min-height: 300px; }
.editor-meta { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 14px; }
.editor-meta strong { font-size: 14px; }
.editor-meta span, .editor-note { color: var(--muted); font-size: 12px; }
.editor-note { margin-top: 14px; line-height: 1.6; }
.capture-tools { margin-top: 12px; }
.record-box textarea {
  width: 100%;
  min-height: 132px;
  resize: vertical;
  border: 0;
  outline: 0;
  color: var(--ink);
  font-size: 17px;
  line-height: 1.7;
}
.record-box textarea::placeholder { color: #9aa29e; }

.capture-options { margin-top: 10px; padding-top: 14px; border-top: 1px solid var(--line); }
.capture-options > span { display: block; margin-bottom: 9px; color: var(--muted); font-size: 12px; }
.category-picker { position: relative; }
.category-picker summary {
  width: fit-content;
  max-width: 100%;
  min-height: 36px;
  padding: 8px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: var(--surface-soft);
  list-style: none;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.category-picker summary::-webkit-details-marker { display: none; }
.category-picker summary::after { content: "⌄"; margin-left: 10px; color: var(--muted); }
.category-options {
  position: absolute;
  z-index: 8;
  top: calc(100% + 6px);
  left: 0;
  width: min(330px, 88vw);
  max-height: 250px;
  overflow: auto;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
  box-shadow: var(--shadow);
}
.category-option { display: flex; align-items: center; gap: 9px; min-height: 38px; padding: 7px 8px; border-radius: 4px; }
.category-option:hover { background: var(--surface-soft); }
.category-option input { width: 17px; height: 17px; accent-color: var(--focus); }
.category-option.child { padding-left: 25px; color: #52605a; }
.category-empty { padding: 14px; color: var(--muted); font-size: 13px; }

.tools { display: flex; align-items: center; gap: 9px; margin-top: 16px; padding-top: 15px; border-top: 1px solid var(--line); }
.tools .status { margin-right: auto; }
.button, .tools button, .list-head button, .category-toolbar button {
  min-height: 38px;
  padding: 9px 13px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: transparent;
  color: #59645e;
}
.button:hover, .tools button:hover, .list-head button:hover, .category-toolbar button:hover { background: var(--surface-soft); color: var(--ink); }
.button.primary, .tools .save { border-color: var(--ink); background: var(--ink); color: white; font-weight: 650; padding-inline: 18px; }
.button.danger, .tools .danger { border-color: #e3bbb4; color: var(--danger); }
.button.danger:hover, .tools .danger:hover { background: var(--danger-soft); }

.record-list { margin-top: 34px; }
.list-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 12px; }
.list-head h2 { margin: 0; font-size: 18px; }
.list-actions { display: flex; align-items: center; gap: 10px; }
.filters { display: flex; gap: 9px; margin-bottom: 14px; }
.filters select, .filters input, .search {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: white;
  color: var(--ink);
  padding: 9px 12px;
}
.search { width: 100%; font-size: 15px; }

.segmented { display: inline-flex; padding: 3px; border: 1px solid var(--line); border-radius: 5px; background: #ebeeea; }
.segmented button {
  min-height: 31px;
  padding: 6px 10px;
  border: 0;
  border-radius: 3px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
}
.segmented button.active { background: white; color: var(--ink); box-shadow: 0 1px 3px rgba(23,35,31,.1); }

.record {
  position: relative;
  margin-top: 10px;
  padding: 18px 52px 18px 20px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--surface);
  transition: border-color .15s ease, transform .15s ease;
}
.record[data-id] { cursor: pointer; }
.record[data-id]:hover { border-color: #c8d0c8; transform: translateY(-1px); }
.record p { margin: 0; line-height: 1.65; white-space: pre-wrap; overflow-wrap: anywhere; }
.record time { display: block; margin-top: 11px; color: var(--muted); font-size: 11px; line-height: 1.6; }
.record audio { width: 100%; height: 38px; margin-top: 13px; }
.record-actions { position: absolute; top: 12px; right: 12px; }
.icon-button {
  width: 32px;
  height: 32px;
  padding: 0;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: #9a635b;
  font-size: 19px;
  line-height: 1;
  opacity: .45;
}
.record:hover .icon-button, .icon-button:focus-visible { opacity: 1; }
.icon-button:hover { background: var(--danger-soft); color: var(--danger); }
.meta-category { color: #4d6d62; }
.empty { padding: 54px 18px; color: var(--muted); text-align: center; }
.empty-mark { width: 42px; height: 42px; margin: 0 auto 14px; display: grid; place-items: center; border: 1px solid #cad5cc; border-radius: 14px; background: #edf1eb; color: #456158; font-family: Georgia, serif; font-size: 18px; transform: rotate(-3deg); }
.empty p { margin: 0; line-height: 1.7; }
.empty .button { margin-top: 18px; color: var(--ink); background: white; }

.more-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-top: 24px; }
.more-card { min-height: 92px; padding: 17px; display: flex; flex-direction: column; align-items: flex-start; justify-content: space-between; gap: 12px; border: 1px solid var(--line); border-radius: 12px; background: white; color: var(--ink); text-align: left; }
.more-card:hover { border-color: #bdcbbf; box-shadow: var(--shadow-soft); }
.more-card span { color: var(--accent); font-size: 18px; }
.more-card small { color: var(--muted); font-size: 13px; }

.back { margin: -4px 0 14px; padding: 5px 0; border: 0; background: none; color: var(--muted); }
.detail .version { display: block; color: var(--accent); font-size: 11px; }
.detail h2 { margin: 10px 0 18px; font-size: 23px; }
.detail textarea { width: 100%; min-height: 220px; padding: 14px; resize: vertical; border: 1px solid var(--line); border-radius: 4px; font-size: 16px; line-height: 1.7; }
.detail-categories { margin: 20px 0 4px; }
.detail-categories h3 { margin: 0 0 10px; font-size: 14px; }
.detail-categories .category-options { position: static; width: 100%; max-height: none; padding: 4px; border: 1px solid var(--line); box-shadow: none; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.detail-status { margin-top: 8px; color: var(--muted); font-size: 12px; }

.category-group { margin-top: 12px; border: 1px solid var(--line); border-radius: 5px; background: white; }
.category-row { min-height: 66px; padding: 14px 16px; display: flex; align-items: center; gap: 12px; }
.category-row.clickable { cursor: pointer; }
.category-row.clickable:hover { background: var(--surface-soft); }
.category-row + .category-row { border-top: 1px solid var(--line); }
.category-row.child { min-height: 56px; padding-left: 34px; }
.category-main { min-width: 0; flex: 1; }
.category-main strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.category-main small { color: var(--muted); }
.category-toolbar { display: flex; gap: 4px; }
.category-toolbar button { min-height: 32px; padding: 6px 9px; font-size: 12px; }
.category-toolbar .delete-category { color: var(--danger); }
.uncategorized { margin-bottom: 18px; }

.timeline-group { margin-top: 24px; }
.timeline-date { margin: 0 0 8px; color: #52605a; font-size: 13px; font-weight: 600; }

.modal-backdrop { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; padding: 20px; background: rgba(17, 27, 23, .42); }
.modal { width: min(440px, 100%); padding: 22px; border-radius: 6px; background: white; box-shadow: var(--shadow); }
.modal h2 { margin: 0 0 18px; font-size: 21px; }
.field { display: grid; gap: 7px; margin-top: 14px; }
.field span { color: #4f5b55; font-size: 13px; }
.field input, .field select { width: 100%; min-height: 42px; padding: 9px 11px; border: 1px solid var(--line); border-radius: 4px; background: white; }
.modal-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 22px; }

.settings-panel h2 { margin-top: 0; font-size: 21px; }
.settings-actions { display: flex; flex-wrap: wrap; gap: 9px; margin-top: 18px; }
.visually-hidden { position: absolute !important; width: 1px !important; height: 1px !important; padding: 0 !important; margin: -1px !important; overflow: hidden !important; clip: rect(0,0,0,0) !important; white-space: nowrap !important; border: 0 !important; }
.recording { color: #b84232 !important; border-color: #d88b7e !important; }
.recording::before { content: "● "; animation: pulse 1s infinite; }
.recording-cancel { order: 2; }
.mobile-nav { display: none; }
@keyframes pulse { 50% { opacity: .3; } }

@media (max-width: 760px) {
  body { padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
  .app { display: block; }
  aside { display: none; }
  main { width: 100%; padding: calc(24px + env(safe-area-inset-top)) 5vw 32px; }
  header { align-items: center; }
  h1 { font-size: 30px; }
  .date { max-width: 120px; text-align: right; font-size: 11px; }
  .record-box, .detail, .settings-panel { margin-top: 22px; padding: 17px; }
  .record-box textarea { min-height: 112px; }
  .tools { flex-wrap: wrap; }
  .tools .status { width: 100%; order: 3; }
  .record { padding: 16px 48px 16px 16px; }
  .record-actions { top: 9px; right: 9px; }
  .icon-button { opacity: .8; }
  .list-head { align-items: flex-start; }
  .list-head.with-controls { flex-direction: column; }
  .filters { flex-wrap: wrap; }
  .filters select { flex: 1; min-width: 130px; }
  .detail-categories .category-options { grid-template-columns: 1fr; }
  .category-row { align-items: flex-start; }
  .category-toolbar { flex-direction: column; }
  .mobile-nav {
    position: fixed;
    z-index: 20;
    left: 0;
    right: 0;
    bottom: 0;
    height: calc(62px + env(safe-area-inset-bottom));
    padding: 6px 5px env(safe-area-inset-bottom);
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    border-top: 1px solid var(--line);
    background: rgba(255, 255, 255, .97);
  }
  .mnav { position: relative; min-width: 0; border: 0; background: none; color: var(--muted); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; }
  .mnav svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
  .mnav small { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
  .mnav.active { color: var(--accent); }
  .capture-nav { color: var(--ink); transform: translateY(-8px); }
  .capture-nav > span { width: 43px; height: 43px; display: grid; place-items: center; border-radius: 15px; background: var(--ink); color: white; box-shadow: 0 8px 20px rgba(20,35,30,.2); font-size: 25px; line-height: 1; }
  .capture-nav small { color: var(--ink); font-weight: 650; }
  .capture-nav.active > span { background: var(--accent); }
  .capture-page { margin-top: 18px; }
  .capture-editor textarea { min-height: 250px; }
  .capture-tools { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .capture-tools button { width: 100%; }
  .capture-tools #voice, .capture-tools .recording-cancel { order: 1; }
  .capture-tools #saveContinue { order: 2; }
  .capture-tools .save { order: 3; grid-column: 1 / -1; }
  .capture-tools .status { order: 4; grid-column: 1 / -1; width: auto; }
  .more-grid { grid-template-columns: 1fr; }
}

@media (max-width: 390px) {
  .segmented button { padding-inline: 8px; }
  .list-actions { width: 100%; justify-content: space-between; }
  .category-row.child { padding-left: 22px; }
}
