/* Layout: a working account book. Ruled paper leaves, red double margin rule, totals in red ink. Top bar is the book's spine. */
:root {
  --paper: #eef0e4;
  --desk: #dfe3d2;
  --rule: #b9c7cf;
  --ink: #23262e;
  --ink-soft: #5a5e66;
  --red: #9e2b25;
  --gild: #7a6a2c;
  --ok: #3f6b3a;
  --field: #f8f9f2;
  --spine: #2d2a33;
  --spine-ink: #ece7d8;
  --display: "Old Standard TT", "EB Garamond", Georgia, "Times New Roman", serif;
  --body: "EB Garamond", Georgia, "Times New Roman", serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #1e2124; --desk: #15171a; --rule: #3a4650; --ink: #e5e3d8; --ink-soft: #a9a89c;
    --red: #e3786e; --gild: #d2bd6e; --ok: #8fc286; --field: #262a2e; --spine: #0e0f11; --spine-ink: #e5e3d8;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--desk); color: var(--ink); font-family: var(--body); font-size: 17px; line-height: 1.45; }
[hidden] { display: none !important; }
a { color: inherit; }

.top { background: var(--spine); color: var(--spine-ink); position: sticky; top: 0; z-index: 20; }
.top-inner { max-width: 1180px; margin: 0 auto; display: flex; flex-wrap: wrap; align-items: center; gap: 6px 20px;
  padding: 8px max(16px, env(safe-area-inset-right, 0px)) 8px max(16px, env(safe-area-inset-left, 0px)); }
.brand { font-family: var(--display); font-size: 21px; text-decoration: none; letter-spacing: .01em; }
.nav { display: flex; gap: 2px; overflow-x: auto; flex: 1 1 auto; min-width: 0; scrollbar-width: none; }
.nav a { text-decoration: none; padding: 6px 10px; border-radius: 3px; white-space: nowrap; font-size: 16px; opacity: .85; }
.nav a:hover { opacity: 1; background: rgba(255,255,255,.08); }
.nav a.on { opacity: 1; background: rgba(255,255,255,.14); box-shadow: inset 0 -2px 0 var(--red); }
.who { font-size: 15px; opacity: .9; white-space: nowrap; }
.link { background: none; border: none; color: inherit; text-decoration: underline; cursor: pointer; font: inherit; padding: 0 2px; }

.fresh { background: var(--gild); color: var(--paper); text-align: center; padding: 6px 16px; font-size: 15px; }
.fresh button { margin-left: 10px; }

.page { max-width: 1180px; margin: 0 auto; padding: 24px max(16px, env(safe-area-inset-right, 0px)) 64px max(16px, env(safe-area-inset-left, 0px)); display: grid; gap: 24px; }
.page > * { min-width: 0; }

.leaf { background: var(--paper); border: 1px solid var(--rule); position: relative; padding: 24px 24px 28px 52px; min-width: 0; }
.leaf::before, .leaf::after { content: ""; position: absolute; top: 0; bottom: 0; width: 1px; background: var(--red); opacity: .65; }
.leaf::before { left: 30px; } .leaf::after { left: 34px; }
@media (max-width: 600px) { .leaf { padding: 18px 12px 22px 28px; } .leaf::before { left: 12px; } .leaf::after { left: 16px; } }

h1 { font-family: var(--display); font-weight: 400; font-size: clamp(26px, 4vw, 36px); line-height: 1.1; margin: 0 0 4px; text-wrap: balance; }
h2 { font-family: var(--display); font-weight: 400; font-size: 22px; margin: 22px 0 4px; display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
h2:first-child { margin-top: 0; }
h2 .num { color: var(--red); }
.lead { font-style: italic; color: var(--ink-soft); margin: 0 0 14px; max-width: 72ch; }
.how { font-style: italic; color: var(--ink-soft); margin: 0 0 8px; font-size: 15.5px; max-width: 72ch; }
.head { display: flex; flex-wrap: wrap; gap: 12px 24px; justify-content: space-between; align-items: flex-end; border-bottom: 2px solid var(--ink); padding-bottom: 12px; margin-bottom: 16px; }
.head > div { min-width: 0; }

.figures { display: flex; flex-wrap: wrap; gap: 10px 32px; font-variant-numeric: tabular-nums lining-nums; }
.fig { display: grid; }
.fig .k { font-size: 12.5px; letter-spacing: .07em; text-transform: uppercase; color: var(--ink-soft); }
.fig .v { font-family: var(--display); font-size: 24px; }
.fig .v.red { color: var(--red); }

.tablewrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums lining-nums; }
th { font-weight: 500; font-size: 12.5px; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-soft); text-align: left; padding: 6px 6px; border-bottom: 1px solid var(--ink); vertical-align: bottom; }
td { padding: 5px 6px; border-bottom: 1px solid var(--rule); vertical-align: middle; }
th.n, td.n { text-align: right; }
td.nowrap, th.nowrap { white-space: nowrap; }
tr.total td { border-top: 2px solid var(--ink); border-bottom: 3px double var(--ink); font-weight: 600; color: var(--red); white-space: nowrap; }
tr.total td:first-child { color: var(--ink); font-family: var(--display); font-weight: 400; }
tr.adding td { background: color-mix(in srgb, var(--gild) 9%, transparent); }
tr.editing td { background: color-mix(in srgb, var(--red) 6%, transparent); }
td.actions { white-space: nowrap; text-align: right; width: 1%; }
.neg { color: var(--red); }
.pos { color: var(--ok); }
.muted { color: var(--ink-soft); }
.small { font-size: 14.5px; }

input, select, textarea {
  font: inherit; color: var(--ink); background: var(--field); border: none; border-bottom: 1px dotted var(--ink-soft);
  padding: 3px 5px; width: 100%; min-width: 0; border-radius: 0;
}
input.bad { outline: 2px solid var(--red); }
input[type="checkbox"] { width: auto; }
textarea { min-height: 90px; resize: vertical; border: 1px solid var(--rule); }
td input { min-width: 70px; }
td input.w-xs { width: 64px; min-width: 56px; }
td input.w-s { width: 90px; }
td input.w-m { width: 130px; }
button {
  font: inherit; font-size: 15px; color: var(--ink); background: var(--paper); border: 1px solid var(--ink-soft);
  padding: 5px 12px; border-radius: 3px; cursor: pointer; white-space: nowrap;
}
button:hover { border-color: var(--ink); }
button.primary { background: var(--ink); color: var(--paper); border-color: var(--ink); }
button.danger { color: var(--red); border-color: var(--red); }
button.icon { padding: 2px 8px; }
button:disabled { opacity: .5; cursor: not-allowed; }
:focus-visible { outline: 2px solid var(--gild); outline-offset: 2px; }
.btns { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.pill { display: inline-block; padding: 0 8px; border-radius: 10px; font-size: 13px; border: 1px solid currentColor; white-space: nowrap; }
.pill.low { color: var(--red); }
.pill.ok { color: var(--ok); }
.pill.off { color: var(--ink-soft); }

.cols { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 24px; }
@media (max-width: 900px) { .cols { grid-template-columns: minmax(0, 1fr); } }

.box { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 0 16px; max-width: 560px; font-variant-numeric: tabular-nums lining-nums; }
.box > div { padding: 5px 0; border-bottom: 1px solid var(--rule); display: flex; align-items: center; min-width: 0; }
.box .v { justify-content: flex-end; white-space: nowrap; }
.box .v input { width: 150px; text-align: right; }
.box .em { font-family: var(--display); font-size: 19px; }
.box .em.v { color: var(--red); border-bottom: 3px double var(--ink); }

.savebar { position: sticky; bottom: 0; z-index: 10; background: var(--paper); border-top: 2px solid var(--ink); padding: 10px 0 calc(10px + env(safe-area-inset-bottom, 0px)); display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; justify-content: space-between; }
.savebar .state { font-style: italic; color: var(--ink-soft); }
.savebar .state.dirty { color: var(--red); }

.login { max-width: 420px; margin: 8vh auto 0; }
.login form { display: grid; gap: 12px; }
.login label { display: grid; gap: 2px; font-size: 15px; color: var(--ink-soft); }
.err { color: var(--red); min-height: 1.4em; }

.hist { display: grid; gap: 0; }
.hist .row { display: grid; grid-template-columns: 150px minmax(0, 1fr) auto; gap: 4px 16px; padding: 8px 0; border-bottom: 1px solid var(--rule); align-items: start; }
@media (max-width: 640px) { .hist .row { grid-template-columns: minmax(0, 1fr); } }
.hist .when { color: var(--ink-soft); font-size: 14.5px; }
.hist .diff { font-size: 15px; color: var(--ink-soft); }
.hist .diff b { color: var(--ink); font-weight: 500; }

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr)); gap: 12px 20px; }
.form-grid label { display: grid; gap: 2px; font-size: 14.5px; color: var(--ink-soft); }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(20px + env(safe-area-inset-bottom, 0px)); background: var(--ink); color: var(--paper); padding: 10px 16px; border-radius: 4px; max-width: min(92vw, 560px); z-index: 50; box-shadow: 0 4px 18px rgba(0,0,0,.25); }
.toast.bad { background: var(--red); }
.empty { font-style: italic; color: var(--ink-soft); padding: 12px 0; }
.hint { font-size: 13.5px; color: var(--ink-soft); font-style: italic; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; scroll-behavior: auto !important; } }
@media print {
  .top, .savebar, .fresh, .toast, button { display: none !important; }
  body { background: #fff; }
  .leaf { border: none; }
}

/* --- v2: подразделы, карточки, отчёты --- */
.subnav { background: color-mix(in srgb, var(--spine) 88%, var(--paper)); color: var(--spine-ink); }
.subnav-inner { max-width: 1180px; margin: 0 auto; display: flex; gap: 4px; align-items: center; overflow-x: auto; scrollbar-width: none;
  padding: 4px max(16px, env(safe-area-inset-right, 0px)) 4px max(16px, env(safe-area-inset-left, 0px)); }
.subnav .crumb { font-family: var(--display); opacity: .6; margin-right: 10px; white-space: nowrap; }
.subnav a { text-decoration: none; padding: 4px 10px; border-radius: 3px; white-space: nowrap; font-size: 15.5px; opacity: .85; }
.subnav a:hover { opacity: 1; background: rgba(255,255,255,.08); }
.subnav a.on { opacity: 1; background: rgba(255,255,255,.16); box-shadow: inset 0 -2px 0 var(--gild); }
h3 { font-family: var(--display); font-weight: 400; font-size: 18px; margin: 16px 0 4px; }
h4 { font-family: var(--display); font-weight: 400; font-size: 16px; margin: 14px 0 4px; color: var(--ink-soft); }
h1 .pill { font-family: var(--body); vertical-align: middle; margin-left: 6px; }
.pill { color: var(--gild); }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); gap: 16px; align-items: start; }
.card { background: var(--field); border: 1px solid var(--rule); border-radius: 3px; display: grid; grid-template-columns: 96px minmax(0, 1fr); gap: 14px; padding: 14px; min-width: 0; text-align: left; font: inherit; color: inherit; }
.card.editing { grid-template-columns: minmax(0, 1fr); border-color: var(--ink-soft); }
.card.editing .pwrap { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; }
.card.inactive { opacity: .65; }
.newcard { place-items: center; grid-template-columns: 1fr; min-height: 120px; border-style: dashed; cursor: pointer; font-size: 17px; color: var(--ink-soft); background: transparent; }
.newcard:hover { color: var(--ink); border-color: var(--ink-soft); }
.portrait { width: 96px; height: 120px; object-fit: cover; border: 1px solid var(--rule); border-radius: 2px; background: var(--paper); display: block; }
.portrait.blank { display: grid; place-items: center; font-family: var(--display); font-size: 40px; color: var(--ink-soft); }
.upload { display: inline-block; cursor: pointer; font-size: 14.5px; text-decoration: underline; color: var(--ink-soft); }
.upload input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.upload:focus-within { outline: 2px solid var(--gild); }
.cbody { min-width: 0; }
.cname { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.cname h3 { margin: 0; font-size: 20px; }
.csub { color: var(--ink-soft); font-style: italic; font-size: 15px; margin-bottom: 6px; }
.stats { display: grid; grid-template-columns: auto 1fr; gap: 0 12px; margin: 6px 0; font-size: 15px; font-variant-numeric: tabular-nums; }
.stats dt { color: var(--ink-soft); } .stats dd { margin: 0; }
.cnotes { font-size: 15px; white-space: pre-wrap; margin: 6px 0 0; color: var(--ink); }
.form-grid.tight { gap: 8px 14px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 180px), 1fr)); }
.form-grid label.wide { grid-column: 1 / -1; }

.simbox { border: 1px dashed var(--ink-soft); padding: 4px 16px 14px; margin: 8px 0 12px; background: color-mix(in srgb, var(--gild) 6%, transparent); }
table.compact td { padding: 4px 6px; }
.section { margin: 10px 0 18px; }
.sec-head { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; margin-bottom: 4px; }
.sec-head h3 { margin: 0; }
.sec-title { font-family: var(--display); font-size: 18px; max-width: 360px; }
.addsec input { max-width: 420px; }
button.small, .small { font-size: 14px; }
details.detail { margin: 18px 0; border: 1px solid var(--rule); padding: 8px 14px; background: var(--field); }
details.detail summary { cursor: pointer; font-family: var(--display); font-size: 17px; }
.glog { list-style: none; margin: 0; padding: 0; columns: 2 420px; column-gap: 28px; }
.glog li { display: flex; gap: 8px; align-items: baseline; padding: 2px 0; border-bottom: 1px dotted var(--rule); break-inside: avoid; font-size: 14.5px; }
.glog li .muted { flex: 1; min-width: 0; }
.ings { display: grid; gap: 4px; margin-bottom: 4px; }
.ing { display: flex; gap: 6px; align-items: center; }
.ing select { min-width: 140px; }

/* --- v3: длинный текст, доска, сводка --- */
.clampbox { display: inline; }
.clamp { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: var(--lines, 2); line-clamp: var(--lines, 2); overflow: hidden; white-space: pre-wrap; }
.clampbox.open .clamp { display: block; -webkit-line-clamp: unset; line-clamp: unset; overflow: visible; }
.more { margin-top: 2px; }
td .clampbox { display: block; max-width: 46ch; }
.board { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); gap: 16px; align-items: start; }
.note { background: var(--field); border: 1px solid var(--rule); border-top: 3px solid var(--gild); padding: 12px 14px; display: grid; gap: 8px; min-width: 0; }
.note.pinned { border-top-color: var(--red); }
.note.new { border-style: dashed; border-top: 3px dashed var(--gild); background: transparent; }
.note label { display: grid; gap: 2px; font-size: 14.5px; color: var(--ink-soft); }
.note label.inline { display: flex; gap: 6px; align-items: center; }
.note h3 { margin: 0; font-size: 19px; }
.ntext { white-space: pre-wrap; overflow-wrap: anywhere; }
.nfoot { font-size: 13.5px; color: var(--ink-soft); font-style: italic; }

/* --- v4: вложения доски --- */
.atts { display: flex; flex-wrap: wrap; gap: 8px; }
.att-img { position: relative; display: inline-block; }
.att-img img { width: 120px; height: 90px; object-fit: cover; border: 1px solid var(--rule); border-radius: 2px; display: block; background: var(--paper); }
.att-img .icon { position: absolute; top: 2px; right: 2px; background: var(--paper); }
.att-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; font-size: 15px; }
.note .upload { display: block; }
