:root {
    --ink: #17251d;
    --ink-soft: #516057;
    --forest: #244734;
    --forest-2: #315e45;
    --cream: #f5f1e8;
    --paper: #fffdf8;
    --gold: #d8a84e;
    --gold-soft: #f5e6bd;
    --sage: #dbe5dc;
    --line: #e2ded3;
    --danger: #b84236;
    --danger-soft: #f8ded9;
    --white: #fff;
    --shadow: 0 12px 34px rgba(28, 46, 35, .10);
    --radius: 22px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html { background: var(--cream); color: var(--ink); font-family: 'Segoe UI', system-ui, sans-serif; -webkit-tap-highlight-color: transparent; }
body { margin: 0; min-height: 100vh; background: var(--cream); }
button, input, select, textarea { font: inherit; }
button { color: inherit; }
button, a { touch-action: manipulation; }
img { display: block; max-width: 100%; }
[hidden] { display: none !important; }

.splash { position: fixed; inset: 0; z-index: 100; display: grid; place-content: center; justify-items: center; gap: 10px; background: var(--ink); color: var(--paper); transition: opacity .35s ease, visibility .35s; }
.splash.hide { opacity: 0; visibility: hidden; }
.splash strong { font-family: Manrope, sans-serif; font-size: 25px; }
.splash small { color: #aec0b4; }
.brand-mark { width: 94px; height: 94px; overflow: hidden; border: 3px solid rgba(255,255,255,.8); border-radius: 50%; display: grid; place-items: center; margin-bottom: 8px; background: var(--paper); box-shadow: 0 18px 40px rgba(0,0,0,.25); }
.brand-mark img { width: 100%; height: 100%; object-fit: cover; }

.app-shell { min-height: 100vh; padding-bottom: calc(92px + var(--safe-bottom)); }
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between; min-height: 92px; padding: calc(16px + env(safe-area-inset-top, 0px)) 20px 13px; background: color-mix(in srgb, var(--cream) 92%, transparent); backdrop-filter: blur(18px); }
.topbar h1 { margin: 2px 0 0; font-family: Manrope, sans-serif; font-size: clamp(24px, 7vw, 31px); line-height: 1.1; letter-spacing: -.8px; }
.eyebrow { margin: 0; color: var(--forest-2); font-size: 10px; font-weight: 800; letter-spacing: 1.7px; text-transform: uppercase; }
.avatar-button { width: 47px; height: 47px; padding: 0; overflow: hidden; border: 2px solid var(--paper); border-radius: 50%; background: var(--paper); box-shadow: 0 8px 20px rgba(23,37,29,.19); cursor: pointer; }
.avatar-button img { width: 100%; height: 100%; object-fit: cover; }
.main-content { width: min(100%, 480px); margin: 0 auto; padding: 8px 16px 30px; outline: none; }

.bottom-nav { position: fixed; z-index: 30; left: 50%; bottom: 0; width: min(100%, 480px); min-height: calc(73px + var(--safe-bottom)); padding: 8px 8px var(--safe-bottom); display: grid; grid-template-columns: repeat(5, 1fr); align-items: end; transform: translateX(-50%); border-top: 1px solid rgba(33,52,41,.08); background: rgba(255,253,248,.94); backdrop-filter: blur(22px); box-shadow: 0 -12px 30px rgba(28,46,35,.08); }
.nav-item { position: relative; min-height: 55px; padding: 7px 2px 4px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; border: 0; background: none; color: #879087; cursor: pointer; }
.nav-item svg { width: 21px; height: 21px; stroke-width: 2; }
.nav-item small { font-size: 10px; font-weight: 700; }
.nav-item.active { color: var(--forest); }
.nav-item.active:not(.sell-nav)::after { content: ''; position: absolute; top: 1px; width: 19px; height: 3px; border-radius: 10px; background: var(--gold); }
.sell-nav { transform: translateY(-15px); }
.sell-nav-icon { width: 49px; height: 49px; display: grid; place-items: center; border-radius: 18px; background: var(--forest); color: white; box-shadow: 0 9px 22px rgba(36,71,52,.3); }
.sell-nav-icon svg { width: 25px; height: 25px; }
.sell-nav small { margin-top: -1px; }

.hero { position: relative; overflow: hidden; min-height: 180px; padding: 24px; border-radius: 28px; background: var(--ink); color: var(--white); box-shadow: var(--shadow); }
.hero::after { content: ''; position: absolute; width: 190px; height: 190px; right: -72px; top: -80px; border: 38px solid rgba(216,168,78,.15); border-radius: 50%; }
.hero::before { content: ''; position: absolute; width: 100px; height: 100px; right: 25px; bottom: -55px; border-radius: 30px; background: var(--gold); transform: rotate(23deg); opacity: .94; }
.hero > * { position: relative; z-index: 1; }
.hero-label { display: flex; align-items: center; gap: 7px; color: #bdcabf; font-size: 12px; font-weight: 600; }
.hero-label svg { width: 16px; }
.hero-value { margin: 15px 0 4px; font-family: Manrope, sans-serif; font-size: clamp(31px, 10vw, 44px); font-weight: 800; letter-spacing: -1.5px; }
.hero-sub { color: #bdcabf; font-size: 12px; }
.hero-actions { display: flex; gap: 9px; margin-top: 21px; }

.button { min-height: 45px; padding: 11px 17px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 0; border-radius: 14px; background: var(--forest); color: white; font-weight: 700; font-size: 13px; cursor: pointer; transition: transform .12s, filter .12s; text-decoration: none; }
.button:active { transform: scale(.98); }
.button svg { width: 18px; height: 18px; }
.button-gold { background: var(--gold); color: var(--ink); }
.button-light { background: var(--paper); color: var(--ink); }
.button-ghost { border: 1px solid var(--line); background: transparent; color: var(--ink); }
.button-danger { background: var(--danger-soft); color: var(--danger); }
.button-block { width: 100%; }
.button-small { min-height: 36px; padding: 8px 12px; border-radius: 11px; font-size: 12px; }
.icon-button { width: 42px; height: 42px; display: grid; place-items: center; flex: 0 0 auto; border: 1px solid var(--line); border-radius: 14px; background: var(--paper); cursor: pointer; }
.icon-button svg { width: 19px; height: 19px; }

.section { margin-top: 25px; }
.section-head { margin: 0 2px 12px; display: flex; align-items: center; justify-content: space-between; gap: 15px; }
.section-head h2 { margin: 0; font-family: Manrope, sans-serif; font-size: 17px; letter-spacing: -.25px; }
.text-button { padding: 5px; border: 0; background: none; color: var(--forest-2); font-size: 12px; font-weight: 700; cursor: pointer; }
.metric-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-top: 11px; }
.metric { min-height: 112px; padding: 17px; border: 1px solid rgba(36,71,52,.08); border-radius: 21px; background: var(--paper); box-shadow: 0 5px 18px rgba(35,51,42,.045); }
.metric-icon { width: 35px; height: 35px; display: grid; place-items: center; border-radius: 12px; background: var(--sage); color: var(--forest); }
.metric:nth-child(2) .metric-icon { background: var(--gold-soft); }
.metric-icon svg { width: 18px; }
.metric strong { display: block; margin-top: 13px; font-family: Manrope, sans-serif; font-size: 21px; }
.metric small { color: var(--ink-soft); font-size: 11px; }

.card, .list-card { border: 1px solid rgba(36,71,52,.08); border-radius: var(--radius); background: var(--paper); box-shadow: 0 6px 20px rgba(35,51,42,.05); }
.card { padding: 18px; }
.list { display: grid; gap: 10px; }
.list-card { width: 100%; padding: 14px; display: flex; align-items: center; gap: 13px; text-align: left; }
button.list-card { cursor: pointer; }
.list-card-content { min-width: 0; flex: 1; }
.list-card-content strong { display: block; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: 14px; }
.list-card-content small { display: block; margin-top: 4px; color: var(--ink-soft); font-size: 11px; }
.list-card-value { flex: 0 0 auto; text-align: right; }
.list-card-value strong { font-family: Manrope, sans-serif; font-size: 14px; }
.list-card-value small { display: block; margin-top: 4px; color: var(--ink-soft); font-size: 10px; }
.thumb { width: 47px; height: 58px; flex: 0 0 auto; display: grid; place-items: center; overflow: hidden; border-radius: 12px; background: var(--sage); color: var(--forest); }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb svg { width: 22px; }
.round-icon { width: 45px; height: 45px; flex: 0 0 auto; display: grid; place-items: center; border-radius: 15px; background: var(--sage); color: var(--forest); font-weight: 800; }
.round-icon.gold { background: var(--gold-soft); }
.round-icon svg { width: 21px; }
.chevron { color: #9aa29c; }
.chevron svg { width: 18px; }

.search-wrap { position: relative; margin-bottom: 14px; }
.search-wrap > svg { position: absolute; left: 15px; top: 50%; width: 18px; transform: translateY(-50%); color: #79837b; pointer-events: none; }
.search-input { width: 100%; height: 50px; padding: 0 45px; border: 1px solid var(--line); border-radius: 17px; outline: 0; background: var(--paper); color: var(--ink); box-shadow: 0 5px 16px rgba(35,51,42,.04); }
.search-input:focus { border-color: var(--forest-2); box-shadow: 0 0 0 3px rgba(49,94,69,.12); }

.page-actions { margin: 3px 0 17px; display: grid; grid-template-columns: 1fr auto; gap: 9px; }
.filter-row { display: flex; gap: 8px; margin-bottom: 15px; overflow-x: auto; scrollbar-width: none; }
.filter-row::-webkit-scrollbar { display: none; }
.chip { flex: 0 0 auto; padding: 8px 13px; border: 1px solid var(--line); border-radius: 100px; background: var(--paper); color: var(--ink-soft); font-size: 11px; font-weight: 700; }
.chip.active { border-color: var(--forest); background: var(--forest); color: white; }
.badge { display: inline-flex; align-items: center; padding: 4px 8px; border-radius: 100px; background: var(--sage); color: var(--forest); font-size: 9px; font-weight: 800; text-transform: uppercase; letter-spacing: .45px; }
.badge.warning { background: var(--gold-soft); color: #6e4a07; }
.badge.danger { background: var(--danger-soft); color: var(--danger); }

.empty { padding: 46px 22px; display: grid; justify-items: center; text-align: center; border: 1px dashed #cfc9bc; border-radius: var(--radius); color: var(--ink-soft); }
.empty-icon { width: 58px; height: 58px; display: grid; place-items: center; margin-bottom: 14px; border-radius: 20px; background: var(--sage); color: var(--forest); }
.empty-icon svg { width: 27px; }
.empty h3 { margin: 0 0 7px; font-family: Manrope, sans-serif; color: var(--ink); font-size: 16px; }
.empty p { max-width: 280px; margin: 0 0 17px; font-size: 12px; line-height: 1.6; }

.form { display: grid; gap: 15px; }
.field { display: grid; gap: 7px; }
.field label, .field-label { font-size: 11px; font-weight: 800; color: var(--ink-soft); letter-spacing: .15px; }
.input, .select, .textarea { width: 100%; min-height: 49px; padding: 11px 13px; border: 1px solid var(--line); border-radius: 14px; outline: 0; background: var(--paper); color: var(--ink); }
.textarea { min-height: 86px; resize: vertical; }
.input:focus, .select:focus, .textarea:focus { border-color: var(--forest-2); box-shadow: 0 0 0 3px rgba(49,94,69,.12); }
.form-row { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.input-prefix { position: relative; }
.input-prefix span { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); color: var(--ink-soft); }
.input-prefix .input { padding-left: 32px; }
.select-action { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.help { margin: -2px 0 0; color: #79837b; font-size: 10px; line-height: 1.5; }
.form-section-title { display: flex; align-items: center; justify-content: space-between; margin: 7px 0 -4px; }
.form-section-title h3 { margin: 0; font-family: Manrope, sans-serif; font-size: 15px; }
.line-item { position: relative; display: grid; gap: 12px; padding: 15px; border: 1px solid var(--line); border-radius: 19px; background: #fffefa; }
.line-item-head { display: flex; align-items: center; justify-content: space-between; }
.line-number { display: flex; align-items: center; gap: 8px; font-size: 12px; font-weight: 800; }
.line-number span { width: 25px; height: 25px; display: grid; place-items: center; border-radius: 9px; background: var(--sage); font-size: 10px; }
.remove-line { width: 31px; height: 31px; border: 0; border-radius: 10px; background: var(--danger-soft); color: var(--danger); display: grid; place-items: center; cursor: pointer; }
.remove-line svg { width: 15px; }
.summary-box { padding: 17px; display: grid; gap: 10px; border-radius: 18px; background: var(--ink); color: white; }
.summary-line { display: flex; justify-content: space-between; font-size: 12px; color: #c5d0c8; }
.summary-line.total { padding-top: 10px; border-top: 1px solid rgba(255,255,255,.13); color: white; font-size: 16px; font-weight: 800; }
.sticky-submit { position: sticky; bottom: calc(80px + var(--safe-bottom)); z-index: 8; padding: 9px 0; background: linear-gradient(transparent, var(--cream) 22%); }

.quick-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.quick-card { min-height: 118px; padding: 17px; display: flex; flex-direction: column; align-items: flex-start; justify-content: space-between; border: 1px solid var(--line); border-radius: 20px; background: var(--paper); text-align: left; cursor: pointer; }
.quick-card .round-icon { width: 40px; height: 40px; border-radius: 13px; }
.quick-card strong { font-size: 13px; }
.quick-card small { color: var(--ink-soft); font-size: 10px; }

.modal { width: 100%; max-width: none; height: 100%; max-height: none; margin: 0; padding: 0; border: 0; background: transparent; }
.modal::backdrop { background: rgba(16,27,21,.6); backdrop-filter: blur(3px); }
.modal-sheet { position: absolute; inset: auto 0 0; width: min(100%, 480px); max-height: 93vh; margin: auto; display: flex; flex-direction: column; border-radius: 28px 28px 0 0; background: var(--cream); box-shadow: 0 -20px 60px rgba(0,0,0,.2); animation: sheet-up .25s ease-out; }
@keyframes sheet-up { from { transform: translateY(50px); opacity: .4; } }
.modal-head { padding: 20px 19px 14px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 4px 0 0; font-family: Manrope, sans-serif; font-size: 20px; }
.modal-body { padding: 17px 17px calc(25px + var(--safe-bottom)); overflow-y: auto; }

.toast { position: fixed; z-index: 90; left: 50%; bottom: calc(92px + var(--safe-bottom)); width: max-content; max-width: calc(100% - 32px); padding: 12px 16px; border-radius: 13px; background: var(--ink); color: white; font-size: 12px; font-weight: 600; box-shadow: 0 15px 35px rgba(0,0,0,.22); transform: translate(-50%, 25px); opacity: 0; pointer-events: none; transition: .25s; }
.toast.show { transform: translate(-50%, 0); opacity: 1; }
.toast.error { background: var(--danger); }
.loader-overlay { position: fixed; z-index: 110; inset: 0; display: grid; place-content: center; justify-items: center; gap: 11px; background: rgba(245,241,232,.76); backdrop-filter: blur(5px); color: var(--ink); font-size: 12px; font-weight: 700; }
.spinner { width: 37px; height: 37px; border: 4px solid var(--sage); border-top-color: var(--forest); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.invoice { overflow: hidden; background: white; color: #19211c; border-radius: 18px; box-shadow: 0 5px 20px rgba(0,0,0,.07); }
.invoice-top { padding: 23px; background: var(--ink); color: white; }
.invoice-brand { display: flex; align-items: center; justify-content: space-between; }
.invoice-brand strong { font-family: Manrope, sans-serif; font-size: 20px; }
.invoice-word { font-size: 10px; letter-spacing: 2px; color: var(--gold-soft); }
.invoice-meta { margin-top: 20px; display: flex; justify-content: space-between; gap: 16px; font-size: 11px; color: #c3cec6; }
.invoice-body { padding: 22px; }
.invoice-to { margin-bottom: 20px; }
.invoice-to small { color: #788179; font-size: 9px; text-transform: uppercase; letter-spacing: 1px; }
.invoice-to strong { display: block; margin-top: 4px; font-size: 14px; }
.invoice-to span { display: block; margin-top: 2px; color: #626c65; font-size: 10px; }
.invoice-table { width: 100%; border-collapse: collapse; font-size: 10px; }
.invoice-table th { padding: 8px 4px; border-bottom: 1px solid #dde0dc; color: #7b847d; text-align: left; text-transform: uppercase; letter-spacing: .5px; }
.invoice-table td { padding: 10px 4px; border-bottom: 1px solid #eff0ee; }
.invoice-table th:nth-child(n+2), .invoice-table td:nth-child(n+2) { text-align: right; }
.invoice-totals { width: 58%; margin: 16px 0 0 auto; display: grid; gap: 7px; font-size: 10px; }
.invoice-total-line { display: flex; justify-content: space-between; }
.invoice-total-line.grand { margin-top: 3px; padding-top: 8px; border-top: 1px solid #dfe2de; font-size: 14px; font-weight: 800; }
.invoice-footer { padding: 14px 22px 21px; color: #68716a; text-align: center; font-size: 9px; }
.invoice-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 13px; }

.detail-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 15px 0; }
.detail-stat { padding: 12px 8px; border-radius: 14px; background: var(--sage); text-align: center; }
.detail-stat strong { display: block; font-family: Manrope, sans-serif; font-size: 14px; }
.detail-stat small { color: var(--ink-soft); font-size: 9px; }
.profile { padding: 18px; display: flex; align-items: center; gap: 13px; border-radius: 20px; background: var(--ink); color: white; }
.profile .round-icon { background: var(--gold); color: var(--ink); }
.profile strong { display: block; }
.profile small { display: block; margin-top: 4px; color: #bdc9c0; font-size: 10px; }
.muted { color: var(--ink-soft); }
.text-danger { color: var(--danger) !important; }
.profit-positive { color: #2f7550 !important; }
.profit-negative { color: var(--danger) !important; }
.progress-track { height: 9px; overflow: hidden; border-radius: 20px; background: #e0ded6; }
.progress-fill { height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--forest-2), #72a67e); }
.analysis-hero { padding: 22px; border-radius: 24px; background: var(--ink); color: white; }
.analysis-hero.loss { background: #522c28; }
.analysis-hero .hero-value { margin-top: 10px; }
.analysis-kicker { color: #bdcabf; font-size: 11px; font-weight: 700; }
.analysis-meta { margin-top: 7px; color: #bdcabf; font-size: 11px; }

html[data-theme="dark"] {
    --ink: #e8efe9;
    --ink-soft: #a3b0a7;
    --cream: #101712;
    --paper: #18231c;
    --forest: #4f9169;
    --forest-2: #78ad8a;
    --sage: #24382b;
    --line: #304036;
    --gold-soft: #4b3d20;
    background: #0b100d;
}
html[data-theme="dark"] body { background: #0b100d; }
html[data-theme="dark"] .hero,
html[data-theme="dark"] .summary-box,
html[data-theme="dark"] .profile,
html[data-theme="dark"] .analysis-hero,
html[data-theme="dark"] .invoice-top { background-color: #09110c; color: white; }
html[data-theme="dark"] .bottom-nav { background: rgba(18,27,21,.95); }
html[data-theme="dark"] .topbar { background: rgba(16,23,18,.92); }
html[data-theme="dark"] .line-item { background: #162019; }
html[data-theme="dark"] .toast { background: #050806; }
html[data-theme="dark"] .invoice { color: #19211c; }
html[data-theme="dark"] .invoice .invoice-body,
html[data-theme="dark"] .invoice .invoice-footer { background: white; }

@media (min-width: 680px) {
    body { background: #e9e5dc; }
    .app-shell { width: 480px; margin: 0 auto; background: var(--cream); box-shadow: 0 0 60px rgba(30,43,35,.12); }
    .topbar { padding-inline: 30px; }
    .main-content { padding-inline: 28px; }
    .metric-grid { grid-template-columns: repeat(2, 1fr); }
    .modal-sheet { left: 50%; right: auto; transform: translateX(-50%); }
    @keyframes sheet-up { from { transform: translate(-50%, 50px); opacity: .4; } to { transform: translate(-50%, 0); opacity: 1; } }
}

@media print {
    body * { visibility: hidden !important; }
    #modal, #modal *, .invoice { visibility: visible !important; }
    #modal { position: static; display: block; }
    #modal::backdrop, .modal-head, .invoice-actions { display: none !important; }
    .modal-sheet, .modal-body { position: static; width: 100%; max-height: none; margin: 0; padding: 0; transform: none; box-shadow: none; background: white; }
    .invoice { box-shadow: none; border-radius: 0; }
    @page { size: A5; margin: 8mm; }
}
