/* One stylesheet. Ivory/celadon background, teal accent, gold only for ornament lines. */
@font-face { font-family: "Display"; src: url("assets/noto-serif-sc-600-subset.woff2") format("woff2"); font-display: swap; }

:root {
  --ink: #1f2a2b; --muted: #5f6d6e; --line: #d9e2dd; --paper: rgba(255, 253, 247, .94);
  --teal: #17707a; --teal-dark: #115a63; --teal-soft: #e3f0ee; --gold: #b58b45;
  --danger: #b4443c; --ok: #2f7d4f; --radius: 14px; --shadow: 0 6px 22px rgba(30, 60, 60, .08);
  --nav-w: 220px; --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 15px/1.6 -apple-system, "PingFang SC", "Microsoft YaHei", "Noto Sans SC", sans-serif; color: var(--ink);
  background: #eef3ee url("assets/day-celadon-r4.jpg") center / cover fixed;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--teal); }
h1, h2, h3 { font-family: "Display", serif; font-weight: 600; margin: 0; }
.muted { color: var(--muted); }
.hidden { display: none !important; }

/* ---- layout ---- */
.shell { display: grid; grid-template-columns: var(--nav-w) 1fr; min-height: 100vh; }
.nav { background: var(--paper); border-right: 1px solid var(--line); padding: 18px 12px; display: flex; flex-direction: column; gap: 2px;
       position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { font-family: "Display", serif; font-size: 20px; color: var(--teal-dark); padding: 4px 12px 14px;
         border-bottom: 1px solid var(--line); margin-bottom: 10px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 10px; color: var(--ink); text-decoration: none; }
.nav a:hover { background: var(--teal-soft); }
.nav a.on { background: var(--teal); color: #fff; }
.nav .sep { height: 1px; background: var(--line); margin: 10px 4px; }
.main { padding: 22px 28px 40px; min-width: 0; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head h1 { font-size: 24px; color: var(--teal-dark); flex: 1; }
.tabbar { display: none; }

/* ---- cards ---- */
.card { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
        padding: 16px 18px; position: relative; }
.card.framed::before, .card.framed::after { content: ""; position: absolute; width: 26px; height: 26px; pointer-events: none;
        background: url("assets/ornament-corner-tl.svg") center / contain no-repeat; opacity: .75; }
.card.framed::before { top: 6px; left: 6px; }
.card.framed::after { bottom: 6px; right: 6px; background-image: url("assets/ornament-corner-br.svg"); }
.card h2 { font-size: 17px; color: var(--teal-dark); margin-bottom: 10px; padding-bottom: 6px; border-bottom: 1px solid rgba(181, 139, 69, .35); }
.grid { display: grid; gap: 14px; }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.stat b { display: block; font-size: 24px; color: var(--teal-dark); font-family: "Display", serif; }

/* ---- controls ---- */
.btn { border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: 7px 14px; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--teal); }
.btn.primary { background: var(--teal); border-color: var(--teal); color: #fff; }
.btn.primary:hover { background: var(--teal-dark); }
.btn.danger { color: var(--danger); }
.btn.small { padding: 3px 10px; font-size: 13px; }
.btn:disabled { opacity: .55; cursor: default; }
.input, select.input, textarea.input { width: 100%; border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: 8px 11px; }
.input:focus { outline: 2px solid rgba(23, 112, 122, .25); border-color: var(--teal); }
textarea.input { min-height: 90px; resize: vertical; }
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row > .grow { flex: 1; min-width: 160px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 10px; border-radius: 999px; background: var(--teal-soft);
        color: var(--teal-dark); font-size: 13px; border: 0; cursor: pointer; }
.chip.on { background: var(--teal); color: #fff; }
.chip .x { opacity: .7; }

/* ---- lists ---- */
.list { display: flex; flex-direction: column; }
.item { display: flex; gap: 12px; align-items: flex-start; padding: 11px 4px; border-bottom: 1px solid var(--line); cursor: pointer; }
.item:last-child { border-bottom: 0; }
.item:hover { background: rgba(23, 112, 122, .04); }
.item .ic { width: 34px; height: 34px; flex: none; border-radius: 50%; background: var(--teal-soft); color: var(--teal-dark);
            display: grid; place-items: center; font-size: 13px; font-weight: 600; }
.item .body { flex: 1; min-width: 0; }
.item .t { font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.item .s { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .r { text-align: right; font-size: 13px; color: var(--muted); white-space: nowrap; }
.amount.expense { color: var(--ink); } .amount.income { color: var(--ok); }
.empty { padding: 26px 0; text-align: center; color: var(--muted); }

/* ---- detail ---- */
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 6px 12px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; white-space: pre-wrap; word-break: break-word; }
.section-title { font-size: 14px; color: var(--muted); margin: 18px 0 8px; display: flex; align-items: center; gap: 8px; }
.attach { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px dashed var(--line); }
.attach img { width: 64px; height: 64px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); }

/* ---- dialog ---- */
.mask { position: fixed; inset: 0; background: rgba(20, 35, 35, .35); display: grid; place-items: center; z-index: 50; padding: 16px; }
.dialog { width: min(640px, 100%); max-height: calc(100vh - 32px); overflow: auto; }
.dialog .foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; position: sticky; bottom: -16px;
                background: var(--paper); padding: 10px 0 2px; }

/* ---- AI chat ---- */
.chat { display: flex; flex-direction: column; height: calc(100vh - 44px); }
.chat .log { flex: 1; overflow-y: auto; padding: 4px 2px 16px; display: flex; flex-direction: column; gap: 14px; }
.msg { max-width: 82%; padding: 10px 14px; border-radius: 14px; white-space: pre-wrap; word-break: break-word; }
.msg.user { align-self: flex-end; background: var(--teal); color: #fff; border-bottom-right-radius: 4px; }
.msg.assistant { align-self: flex-start; background: var(--paper); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg.thinking { color: var(--muted); font-style: italic; }
.drafts { align-self: stretch; display: flex; flex-direction: column; gap: 8px; }
.draft { border: 1px solid var(--line); border-left: 4px solid var(--gold); border-radius: 10px; background: #fffdf6; padding: 10px 12px; }
.draft.committed { border-left-color: var(--ok); background: #f3faf5; }
.draft.discarded { opacity: .55; }
.draft .head { display: flex; gap: 8px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.draft .detail { font-size: 13px; color: var(--muted); margin-top: 4px; white-space: pre-wrap; }
.sources { align-self: flex-start; display: flex; gap: 6px; flex-wrap: wrap; max-width: 92%; }
.composer { display: flex; gap: 8px; align-items: flex-end; background: var(--paper); border: 1px solid var(--line);
            border-radius: 16px; padding: 8px; box-shadow: var(--shadow); }
.composer textarea { flex: 1; border: 0; background: transparent; resize: none; min-height: 44px; max-height: 180px; padding: 8px; outline: none; }
.upl { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 6px; }

#toast { position: fixed; left: 50%; bottom: calc(80px + var(--safe-b)); transform: translateX(-50%); background: rgba(25, 45, 45, .92);
         color: #fff; padding: 8px 16px; border-radius: 999px; opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 60; }
#toast.show { opacity: 1; }

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .card { width: min(380px, 100%); }

/* ---- phone ---- */
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .nav { display: none; }
  .main { padding: 14px 12px calc(76px + var(--safe-b)); }
  .page-head h1 { font-size: 21px; }
  .grid.cols-3, .grid.cols-2 { grid-template-columns: 1fr; }
  .tabbar { display: grid; grid-template-columns: repeat(3, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
            background: var(--paper); border-top: 1px solid var(--line); padding-bottom: var(--safe-b); }
  .tabbar a { text-align: center; padding: 10px 0 8px; color: var(--muted); text-decoration: none; font-size: 13px; }
  .tabbar a.on { color: var(--teal); font-weight: 600; }
  .chat { height: calc(100vh - 76px - var(--safe-b) - 60px); }
  .msg { max-width: 92%; }
  .kv { grid-template-columns: 84px 1fr; }
  .kinds { overflow-x: auto; flex-wrap: nowrap !important; padding-bottom: 4px; }
  .dialog { max-height: calc(100vh - 20px); }
}
