:root {
  color-scheme: light;
  --ink: #17231f;
  --muted: #6c7772;
  --paper: #f6f5f1;
  --card: #fff;
  --field: #f7f8f6;
  --line: #dfe4df;
  --green: #1f654f;
  --green-2: #2e8066;
  --green-soft: #e8f1ed;
  --gold: #f5c452;
  --red: #b84035;
  --shadow: 0 5px 18px rgba(27, 61, 49, .07);
  --visual-height: 100dvh;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; min-width: 0; }
html, body { margin: 0; width: 100%; min-height: 100%; overflow-x: hidden; background: var(--paper); color: var(--ink); }
body { overscroll-behavior-y: none; -webkit-text-size-adjust: 100%; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }
.hidden { display: none !important; }
.muted { color: var(--muted); }

.app-shell { width: 100%; min-height: 100dvh; max-width: 680px; margin: auto; padding-bottom: calc(66px + env(safe-area-inset-bottom)); }
.topbar { position: sticky; top: 0; z-index: 10; display: flex; justify-content: space-between; align-items: center; padding: calc(10px + env(safe-area-inset-top)) 16px 8px; background: rgba(246,245,241,.92); backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px); }
.topbar h1 { margin: 1px 0 0; overflow: hidden; font-size: 25px; line-height: 1.1; letter-spacing: -.035em; text-overflow: ellipsis; white-space: nowrap; }
.eyebrow { color: var(--green-2); font-size: 11px; font-weight: 800; letter-spacing: .11em; text-transform: uppercase; }
#content { width: 100%; padding: 5px 12px 20px; outline: none; }

.icon-button, .text-button { min-height: 44px; border: 0; background: transparent; color: var(--green); font-weight: 750; }
.icon-button { width: 44px; flex: 0 0 44px; border-radius: 50%; font-size: 22px; }
.icon-button:active { background: var(--green-soft); }
.text-button { padding: 0 4px; font-size: 15px; }

.summary-card, .hero { overflow: hidden; position: relative; border-radius: 20px; background: var(--green); color: white; padding: 16px; box-shadow: var(--shadow); }
.summary-card::after, .hero::after { content: ''; position: absolute; width: 132px; height: 132px; border: 25px solid rgba(246,196,83,.2); border-radius: 50%; right: -62px; top: -62px; pointer-events: none; }
.summary-top { position: relative; z-index: 1; display: flex; justify-content: space-between; gap: 12px; align-items: start; }
.summary-label { display: block; margin-bottom: 5px; color: #dceae4; font-size: 12px; }
.summary-card strong { display: block; font-size: 27px; line-height: 1.05; letter-spacing: -.04em; }
.summary-date { color: #e1eee8; font-size: 11px; font-weight: 700; white-space: nowrap; }
.summary-meta { position: relative; z-index: 1; display: flex; flex-wrap: wrap; gap: 5px 16px; margin-top: 12px; color: #dceae4; font-size: 12px; }
.hero p { position: relative; z-index: 1; margin: 3px 0; color: #dceae4; font-size: 12px; }
.hero strong { position: relative; z-index: 1; display: block; margin: 10px 0 5px; font-size: 28px; line-height: 1.05; letter-spacing: -.04em; }

.action-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-top: 10px; }
.action-card { min-height: 64px; display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 15px; background: var(--card); color: var(--ink); text-align: left; box-shadow: 0 2px 10px rgba(27,61,49,.035); }
.action-icon { width: 30px; height: 30px; flex: 0 0 30px; display: grid; place-items: center; border-radius: 10px; background: var(--green-soft); color: var(--green); font-size: 18px; line-height: 1; }
.action-card strong { font-size: 13px; line-height: 1.18; }
.stats-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1px; margin-top: 10px; overflow: hidden; border: 1px solid var(--line); border-radius: 15px; background: var(--line); }
.stat { display: flex; align-items: baseline; gap: 7px; padding: 10px 12px; background: var(--card); }
.stat strong { flex: 0 0 auto; font-size: 20px; letter-spacing: -.03em; }
.stat small { color: var(--muted); font-size: 11px; line-height: 1.15; }

.quick-grid { display: grid; gap: 1px; margin-top: 8px; overflow: hidden; border: 1px solid var(--line); border-radius: 16px; background: var(--line); }
.quick { min-height: 54px; display: grid; grid-template-columns: 34px 1fr auto; align-items: center; gap: 9px; padding: 8px 12px; border: 0; background: var(--card); color: var(--ink); text-align: left; }
.quick span { width: 30px; height: 30px; display: grid; place-items: center; margin: 0; border-radius: 9px; background: var(--green-soft); color: var(--green); font-size: 17px; }
.quick strong { font-size: 14px; }
.quick::after { content: '›'; color: #9aa39f; font-size: 22px; }
.metric-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-top: 10px; }
.metric, .card { border: 1px solid var(--line); background: var(--card); border-radius: 15px; box-shadow: 0 2px 10px rgba(27,61,49,.035); }
.metric { padding: 11px 12px; }
.metric strong { display: block; font-size: 21px; }
.metric small { color: var(--muted); }

.section-head { display: flex; justify-content: space-between; align-items: center; min-height: 44px; margin: 9px 2px 2px; }
.section-head h2 { margin: 0; font-size: 17px; letter-spacing: -.015em; }
.section-head button { min-height: 44px; border: 0; color: var(--green); background: transparent; font-weight: 700; }
.list { display: grid; gap: 7px; }
.list-item { width: 100%; padding: 11px 12px; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 10px; border: 1px solid var(--line); border-radius: 15px; background: var(--card); color: inherit; text-align: left; box-shadow: 0 2px 10px rgba(27,61,49,.035); }
.list-item h3 { margin: 0; overflow: hidden; font-size: 14px; line-height: 1.25; text-overflow: ellipsis; white-space: nowrap; }
.list-item p { margin: 0; overflow: hidden; color: var(--muted); font-size: 12px; line-height: 1.25; text-overflow: ellipsis; white-space: nowrap; }
.list-item .amount { grid-row: span 2; grid-column: 2; align-self: center; font-size: 13px; font-weight: 800; white-space: nowrap; }
.catalog-list { margin: 0 -12px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); background: var(--card); }
.catalog-row { width: 100%; min-height: 46px; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 45%) 10px; align-items: center; gap: 9px; padding: 8px 12px 8px 16px; border: 0; border-bottom: 1px solid var(--line); background: transparent; color: var(--ink); text-align: left; }
.catalog-row:last-child { border-bottom: 0; }
.catalog-row:active { background: var(--green-soft); }
.catalog-row strong, .catalog-row span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.catalog-row strong { font-size: 14px; }
.catalog-row span { color: var(--muted); font-size: 12px; text-align: right; }
.catalog-row i { color: #9aa39f; font-size: 18px; font-style: normal; }
.badge { display: inline-flex; align-items: center; width: fit-content; padding: 3px 7px; border-radius: 999px; background: #e4efe9; color: var(--green); font-size: 10px; font-weight: 800; }
.badge.warn { background: #fff0c7; color: #785910; }
.badge.danger { background: #fde0dc; color: var(--red); }

.toolbar { display: flex; gap: 7px; margin: 1px 0 9px; overflow-x: auto; scrollbar-width: none; }
.toolbar::-webkit-scrollbar { display: none; }
.chip { min-height: 38px; flex: 0 0 auto; padding: 7px 13px; border: 1px solid var(--line); border-radius: 999px; background: var(--card); color: var(--muted); font-size: 14px; }
.chip.active { border-color: var(--green); background: var(--green); color: white; }
.search { width: 100%; max-width: 100%; min-height: 44px; margin: 1px 0 9px; padding: 9px 12px; border: 1px solid var(--line); border-radius: 13px; background: var(--card); font-size: 16px; }
.empty { max-width: 340px; margin: 20px auto 0; padding: 22px 16px; color: var(--muted); text-align: center; }
.empty-icon { color: #6f7c76; font-size: 28px; line-height: 1; }
.empty strong { display: block; margin: 8px 0 4px; color: var(--ink); font-size: 15px; }
.empty span { font-size: 13px; }
.version-note { margin: 14px 0 0; color: var(--muted); font-size: 10px; text-align: center; }

.fab { position: fixed; z-index: 15; right: max(14px, calc((100vw - 680px)/2 + 14px)); bottom: calc(72px + env(safe-area-inset-bottom)); width: 50px; height: 50px; border: 0; border-radius: 16px; background: var(--gold); color: #3c2d08; font-size: 26px; box-shadow: 0 9px 22px rgba(96,70,5,.22); }
.bottom-nav { position: fixed; z-index: 20; left: 50%; bottom: 0; transform: translateX(-50%); width: min(100%, 680px); min-height: 58px; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); padding: 4px 5px calc(4px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: rgba(255,255,255,.95); backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px); }
.bottom-nav button { min-height: 50px; padding: 4px 1px 3px; border: 0; border-radius: 11px; background: transparent; color: #7d8782; }
.bottom-nav span { display: block; font-size: 18px; line-height: 1; }
.bottom-nav small { display: block; margin-top: 3px; overflow: hidden; font-size: 9px; text-overflow: ellipsis; white-space: nowrap; }
.bottom-nav button.active { background: var(--green-soft); color: var(--green); }

dialog { border: 0; padding: 0; }
dialog::backdrop { background: rgba(16,29,24,.48); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); }
.login-dialog { width: min(calc(100vw - 28px), 390px); border-radius: 22px; box-shadow: var(--shadow); }
.login-dialog form { padding: 20px; }
.login-dialog img { width: 56px; height: 56px; }
.login-dialog h2 { margin: 6px 0; font-size: 22px; line-height: 1.15; }
.login-dialog .muted { margin: 8px 0; font-size: 12px; line-height: 1.35; }

label { display: grid; gap: 3px; margin: 6px 0; color: #425048; font-size: 11px; font-weight: 700; }
input, select, textarea { width: 100%; max-width: 100%; min-height: 40px; padding: 7px 10px; border: 1px solid #ccd4ce; border-radius: 10px; background: var(--field); color: var(--ink); font-size: 16px; line-height: 1.15; outline: none; }
select { padding-right: 30px; }
textarea { min-height: 52px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--green-2); box-shadow: 0 0 0 3px rgba(47,128,102,.14); }
.primary { min-height: 44px; padding: 10px 15px; border: 0; border-radius: 12px; background: var(--green); color: white; font-weight: 800; }
.secondary { min-height: 40px; padding: 7px 13px; border: 1px solid var(--line); border-radius: 11px; background: white; color: var(--green); font-weight: 750; }
.danger-button { min-height: 44px; border: 0; background: transparent; color: var(--red); font-weight: 750; }
.wide { width: 100%; }
.error-text { min-height: 16px; margin: 4px 0; color: var(--red); font-size: 12px; }

.editor-dialog { position: fixed; inset: 0 auto auto 50%; transform: translateX(-50%); width: min(100%, 680px); height: var(--visual-height); max-height: var(--visual-height); margin: 0; overflow: hidden; background: var(--paper); }
.editor-dialog form { height: 100%; display: flex; flex-direction: column; overflow: hidden; }
.editor-dialog header { z-index: 2; flex: 0 0 auto; display: grid; grid-template-columns: 44px minmax(0, 1fr) auto; align-items: center; gap: 3px; padding: calc(4px + env(safe-area-inset-top)) 10px 4px; border-bottom: 1px solid var(--line); background: rgba(246,245,241,.96); backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px); }
.editor-dialog h2 { margin: 0; overflow: hidden; font-size: 17px; line-height: 1.2; text-overflow: ellipsis; white-space: nowrap; }
.editor-body { flex: 1 1 auto; width: 100%; overflow-x: hidden; overflow-y: auto; overscroll-behavior: contain; padding: 3px 8px calc(14px + env(safe-area-inset-bottom)); scroll-padding: 8px 0 18px; }
.form-section { width: 100%; margin: 5px 0; padding: 1px 8px 5px; overflow: hidden; border: 1px solid var(--line); border-radius: 13px; background: var(--card); }
.form-section h3 { margin: 8px 0 2px; font-size: 13px; }
.form-section > label:not(:has(textarea)) { grid-template-columns: 88px minmax(0, 1fr); align-items: center; gap: 7px; padding: 1px 0; }
.form-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.form-row.date-status { grid-template-columns: minmax(0, 1.35fr) minmax(0, .8fr); }
.line-editor { width: 100%; display: grid; grid-template-columns: minmax(0, 1.4fr) 58px 72px 30px; gap: 5px; align-items: end; padding: 5px 0; border-bottom: 1px solid var(--line); }
.line-editor label { margin: 0; }
.line-editor button { width: 30px; height: 40px; min-height: 40px; padding: 0; border: 0; border-radius: 9px; background: #fdf0ee; color: var(--red); font-size: 18px; }
.toast { position: fixed; z-index: 50; left: 50%; bottom: calc(73px + env(safe-area-inset-bottom)); transform: translate(-50%, 14px); opacity: 0; pointer-events: none; width: max-content; max-width: calc(100vw - 28px); padding: 10px 13px; border-radius: 12px; background: #17231f; color: white; font-size: 13px; box-shadow: var(--shadow); transition: .2s ease; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.skeleton { height: 64px; border-radius: 15px; background: linear-gradient(90deg,#e9e9e4 25%,#f6f6f1 38%,#e9e9e4 60%); background-size: 400% 100%; animation: pulse 1.3s infinite; }
@keyframes pulse { from { background-position: 100% 0; } to { background-position: 0 0; } }

@media (min-width: 560px) {
  #content { padding-inline: 16px; }
  .catalog-list { margin-inline: 0; border: 1px solid var(--line); border-radius: 13px; overflow: hidden; }
  .editor-body { padding-inline: 14px; }
  .quick-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; overflow: visible; border: 0; background: transparent; }
  .quick { border: 1px solid var(--line); border-radius: 15px; }
}

@media (max-width: 350px) {
  .action-grid { grid-template-columns: 1fr; }
  .stats-row { grid-template-columns: 1fr; }
  .form-section > label:not(:has(textarea)) { grid-template-columns: 72px minmax(0, 1fr); }
  .line-editor { grid-template-columns: minmax(0, 1.2fr) 52px 64px 28px; gap: 3px; }
}

@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; animation: none !important; transition: none !important; } }
