:root {
    --ink: #17211d;
    --muted: #68736e;
    --paper: #f5f3ec;
    --panel: #fffefa;
    --line: #dedfd8;
    --green: #1d6b4f;
    --green-soft: #dcecdf;
    --blue-soft: #e1e9f4;
    --red: #a73f3f;
    --amber: #8a6425;
    --shadow: 0 16px 40px rgba(28, 43, 35, .07);
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--paper); color: var(--ink); font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
a { color: var(--green); text-decoration: none; }
a:hover { color: #124c38; }
h1, h2, h3 { letter-spacing: -.035em; }
h1 { font-size: clamp(2rem, 4vw, 3.4rem); line-height: 1; margin: 0; }
h2 { font-size: 1.35rem; margin: 0; }
.eyebrow { color: var(--green); font-size: .72rem; font-weight: 800; letter-spacing: .16em; margin: 0 0 .6rem; text-transform: uppercase; }
.text-positive { color: var(--green) !important; }
.text-negative { color: var(--red) !important; }
.btn { border-radius: .75rem; font-weight: 700; padding: .65rem 1rem; }
.btn-primary { background: var(--green); border-color: var(--green); }
.btn-primary:hover { background: #14523c; border-color: #14523c; }
.btn-dark { background: var(--ink); border-color: var(--ink); }
.form-control, .form-select { border: 1px solid #cfd3cd; border-radius: .7rem; min-height: 44px; }
.form-control:focus, .form-select:focus { border-color: var(--green); box-shadow: 0 0 0 .2rem rgba(29,107,79,.12); }

.app-shell { min-height: 100vh; }
.sidebar { background: var(--ink); color: white; display: flex; flex-direction: column; height: 100vh; left: 0; padding: 1.5rem; position: fixed; top: 0; width: 250px; }
.brand { align-items: center; color: inherit; display: flex; gap: .8rem; }
.brand:hover { color: inherit; }
.brand-mark { align-items: center; background: #d6e6ce; border-radius: .7rem; color: #173b2e; display: inline-flex; font-size: .8rem; font-weight: 900; height: 42px; justify-content: center; width: 42px; }
.brand strong, .brand small { display: block; }
.brand small { color: #aab7b0; font-size: .7rem; margin-top: .1rem; }
.main-nav { display: grid; gap: .25rem; margin-top: 2.5rem; }
.main-nav a, .sidebar-section a, .sidebar-footer a, .link-button { border-radius: .6rem; color: #cbd5d0; display: block; font-size: .92rem; padding: .65rem .8rem; }
.main-nav a.active, .main-nav a:hover, .sidebar-section a:hover, .sidebar-footer a:hover, .link-button:hover { background: rgba(255,255,255,.09); color: white; }
.sidebar-section { border-top: 1px solid rgba(255,255,255,.11); margin-top: 1.5rem; padding-top: 1.3rem; }
.sidebar-label { color: #7f9188; display: block; font-size: .68rem; font-weight: 800; letter-spacing: .12em; margin: 0 .8rem .45rem; text-transform: uppercase; }
.sidebar-footer { border-top: 1px solid rgba(255,255,255,.11); margin-top: auto; padding-top: 1rem; }
.link-button { background: none; border: 0; text-align: left; width: 100%; }
.main-content { margin-left: 250px; min-height: 100vh; padding: 2rem clamp(1.3rem, 4vw, 4rem) 4rem; }
.mobile-topbar { display: none; }
.message-stack { margin-bottom: 1rem; }
.page-header { align-items: end; display: flex; gap: 2rem; justify-content: space-between; margin: 1rem 0 2rem; }
.page-header h1 span { color: var(--muted); font-size: .45em; font-weight: 500; }
.header-actions { display: flex; gap: .6rem; }
.period-picker, .filter-bar { align-items: end; background: rgba(255,255,255,.55); border: 1px solid var(--line); border-radius: 1rem; display: flex; gap: .65rem; padding: .75rem; }
.period-picker label { color: var(--muted); font-size: .72rem; font-weight: 700; }
.period-picker .form-control { width: 90px; }
.period-picker .form-select { width: 92px; }
.filter-bar { margin-bottom: 1rem; }
.filter-bar > * { min-width: 0; }
.filter-bar.compact { max-width: 650px; }

.metric-grid { display: grid; gap: 1rem; grid-template-columns: repeat(4, 1fr); }
.metric-card, .panel, .asset-card { background: var(--panel); border: 1px solid var(--line); border-radius: 1.1rem; box-shadow: var(--shadow); }
.metric-card { min-height: 165px; padding: 1.2rem; position: relative; }
.metric-card > span { color: var(--muted); font-size: .78rem; font-weight: 700; }
.metric-card > strong { display: block; font-size: clamp(1.65rem, 3vw, 2.4rem); letter-spacing: -.05em; margin-top: 1.2rem; }
.metric-card > a { bottom: 1rem; font-size: .75rem; font-weight: 800; position: absolute; }
.metric-card.accent-green { background: var(--green-soft); }
.metric-card.accent-blue { background: var(--blue-soft); }
.draft-banner, .notice-card { align-items: center; background: #f4ead4; border: 1px solid #ddcea7; border-radius: 1rem; display: flex; justify-content: space-between; margin: 1rem 0; padding: 1rem 1.2rem; }
.draft-banner p, .notice-card p { color: #695d44; margin: .2rem 0 0; }
.notice-card { align-items: flex-start; display: block; }
.content-grid, .settings-grid { display: grid; gap: 1rem; grid-template-columns: 1fr 1fr; margin-top: 1rem; }
.panel { padding: 1.3rem; }
.panel-header { align-items: center; display: flex; justify-content: space-between; margin-bottom: 1rem; }
.compact-list { display: grid; }
.compact-list a { align-items: center; border-top: 1px solid var(--line); color: var(--ink); display: flex; gap: 1rem; justify-content: space-between; padding: .9rem 0; }
.compact-list a:first-child { border-top: 0; }
.compact-list small { color: var(--muted); display: block; margin-top: .15rem; }
.quarter-strip { align-items: center; background: var(--ink); border-radius: 1.2rem; color: white; display: flex; justify-content: space-between; margin-top: 1rem; padding: 1.4rem; }
.quarter-links { display: flex; flex-wrap: wrap; gap: .45rem; justify-content: end; }
.quarter-links a { align-items: center; background: rgba(255,255,255,.09); border-radius: .65rem; color: white; display: flex; gap: .35rem; padding: .55rem .7rem; }
.quarter-links small { color: #9eb1a7; }

.form-panel { max-width: 980px; }
.form-grid { display: grid; gap: 1rem; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.field-wide { grid-column: 1 / -1; }
.form-label { font-size: .82rem; font-weight: 800; }
.form-actions { border-top: 1px solid var(--line); display: flex; gap: .7rem; justify-content: flex-end; margin-top: 1.5rem; padding-top: 1rem; }
.expense-workflow { display: grid; gap: 1rem; max-width: 1100px; }
.expense-workflow .form-panel { max-width: none; }
.invoice-intake { padding: 1.3rem; }
.invoice-intake-header { align-items: flex-start; display: flex; gap: 2rem; justify-content: space-between; }
.invoice-intake-header p:not(.eyebrow), .new-counterparty-panel p { color: var(--muted); margin: .35rem 0 0; }
.ai-toggle { align-items: center; background: var(--green-soft); border: 1px solid #bed5c3; border-radius: .9rem; cursor: pointer; display: flex; gap: .75rem; min-width: 255px; padding: .8rem 1rem; }
.ai-toggle input { accent-color: var(--green); height: 18px; width: 18px; }
.ai-toggle strong, .ai-toggle small { display: block; }
.ai-toggle small { color: #52645b; font-size: .72rem; margin-top: .15rem; }
.ai-toggle:has(input:disabled) { cursor: not-allowed; opacity: .55; }
.invoice-dropzone { align-items: center; border: 2px dashed #b9c5bd; border-radius: 1rem; cursor: pointer; display: flex; flex-direction: column; justify-content: center; margin-top: 1.2rem; min-height: 180px; overflow: hidden; padding: 2rem; position: relative; transition: background .15s ease, border-color .15s ease; }
.invoice-dropzone:hover, .invoice-dropzone.is-dragging { background: #f1f7f2; border-color: var(--green); }
.invoice-dropzone.is-processing { cursor: wait; opacity: .7; }
.invoice-dropzone input[type="file"] { cursor: pointer; height: 100%; inset: 0; opacity: 0; position: absolute; width: 100%; }
.invoice-dropzone .dropzone-icon { align-items: center; background: var(--green-soft); border-radius: 999px; color: var(--green); display: flex; font-size: 1.5rem; height: 48px; justify-content: center; margin-bottom: .7rem; width: 48px; }
.invoice-dropzone > span:last-child { color: var(--muted); font-size: .8rem; margin-top: .25rem; }
.invoice-analysis-row { align-items: center; display: flex; gap: 1rem; justify-content: space-between; margin-top: .8rem; }
.analysis-status { color: var(--muted); font-size: .82rem; }
.analysis-status[data-state="success"] { color: var(--green); font-weight: 700; }
.analysis-status[data-state="error"] { color: var(--red); font-weight: 700; }
.invoice-privacy-note { color: var(--muted); font-size: .72rem; margin: .7rem 0 0; }
.invoice-warnings { background: #fff7e5; border: 1px solid #e4c988; border-radius: .8rem; color: #684e1f; margin-top: .9rem; padding: .9rem 1rem; }
.invoice-warnings ul { margin: .45rem 0 0; padding-left: 1.2rem; }
.invoice-warnings li + li { margin-top: .25rem; }
.review-badge { background: #f4ead4; border-radius: 999px; color: var(--amber); font-size: .7rem; font-weight: 800; padding: .4rem .65rem; }
.new-counterparty-panel { background: #f3f6f3; border: 1px solid var(--line); border-radius: .9rem; margin-top: 1.2rem; padding: 1rem; }
.new-counterparty-panel .form-grid { margin-top: 1rem; }
.currency-details { border-top: 1px solid var(--line); margin-top: 1.3rem; padding-top: 1rem; }
.currency-details summary { align-items: center; cursor: pointer; display: flex; justify-content: space-between; list-style: none; }
.currency-details summary::-webkit-details-marker { display: none; }
.currency-details summary strong, .currency-details summary small { display: block; }
.currency-details summary small { color: var(--muted); font-size: .72rem; margin-top: .2rem; }
.currency-details summary > span:last-child { color: var(--green); font-size: .75rem; font-weight: 800; }
.currency-details > .form-text { margin: 1rem 0; }
.ai-filled { background-color: #e9f6eb !important; transition: background-color .5s ease; }
.table-panel { padding-bottom: .6rem; }
.table { margin: 0; }
.table thead th { color: var(--muted); font-size: .69rem; letter-spacing: .08em; padding: .8rem; text-transform: uppercase; }
.table td { border-color: #ebebe6; padding: .9rem .8rem; }
.status-badge { border-radius: 999px; display: inline-flex; font-size: .68rem; font-weight: 800; padding: .3rem .55rem; }
.status-badge.confirmed { background: var(--green-soft); color: var(--green); }
.status-badge.draft { background: #efe3c8; color: var(--amber); }
.pagination-bar { align-items: center; border-top: 1px solid var(--line); display: flex; font-size: .8rem; justify-content: space-between; margin-top: .5rem; padding: 1rem .8rem .4rem; }
.empty-state { color: var(--muted); padding: 1.3rem !important; text-align: center; }
.detail-layout, .tax-layout { display: grid; gap: 1rem; grid-template-columns: minmax(0, 2fr) minmax(250px, .8fr); }
.detail-grid { display: grid; gap: 1px; grid-template-columns: repeat(2, 1fr); }
.detail-grid > div { background: #f7f7f2; padding: 1rem; }
.detail-grid span { color: var(--muted); display: block; font-size: .72rem; margin-bottom: .35rem; }
.detail-grid strong { font-size: 1.15rem; }
.detail-grid .total-cell { background: var(--green-soft); grid-column: 1 / -1; }
.detail-aside dl { display: grid; gap: .65rem; grid-template-columns: 1fr 1fr; margin: 1.2rem 0; }
.detail-aside dt { color: var(--muted); font-size: .75rem; }
.detail-aside dd { margin: 0; text-align: right; }
.card-grid { display: grid; gap: 1rem; grid-template-columns: repeat(3, 1fr); }
.asset-card { color: var(--ink); padding: 1.2rem; transition: transform .15s ease, box-shadow .15s ease; }
.asset-card:hover { color: var(--ink); transform: translateY(-2px); }
.asset-card > div { align-items: center; display: flex; justify-content: space-between; }
.asset-card small, .asset-card p { color: var(--muted); }
.asset-card h2 { margin-top: 1rem; }
.asset-card dl { border-top: 1px solid var(--line); display: grid; grid-template-columns: 1fr 1fr; margin: 1rem 0 0; padding-top: .8rem; }
.asset-card dt { color: var(--muted); font-size: .7rem; }
.asset-card dd { font-weight: 800; margin: .2rem 0 0; }
.period-list { margin-top: 1rem; }
.period-list > div { align-items: center; border-top: 1px solid var(--line); display: flex; justify-content: space-between; padding: .8rem 0; }
.period-list > div:first-child { border-top: 0; }
.period-list small { color: var(--muted); display: block; }
.confirm-card { margin: 15vh auto 0; max-width: 560px; text-align: center; }
.confirm-card form { display: flex; gap: .7rem; justify-content: center; margin-top: 1.5rem; }

.quarter-tabs { background: white; border: 1px solid var(--line); border-radius: .8rem; display: flex; padding: .3rem; }
.quarter-tabs a { border-radius: .55rem; color: var(--muted); font-size: .78rem; font-weight: 800; padding: .55rem .75rem; }
.quarter-tabs a.active { background: var(--ink); color: white; }
.tax-header-actions { align-items: center; display: flex; flex-wrap: wrap; gap: .65rem; justify-content: flex-end; }
.export-errors { border-color: #d9b4b4; margin-bottom: 1rem; }
.export-errors ul { color: var(--red); margin: 1rem 0 0; padding-left: 1.2rem; }
.export-errors li + li { margin-top: .4rem; }
.tax-calculation { padding: 0; overflow: hidden; }
.tax-row, .tax-result { align-items: center; border-top: 1px solid var(--line); display: flex; justify-content: space-between; padding: 1rem 1.2rem; }
.tax-row:first-child { border-top: 0; }
.tax-row b { background: #eceee9; border-radius: .35rem; display: inline-flex; justify-content: center; margin-right: .7rem; padding: .2rem; width: 30px; }
.tax-row.sub { background: #fafaf6; color: var(--muted); font-size: .8rem; padding-left: 4.4rem; }
.tax-row.total { background: #f0f1ec; }
.tax-result { background: var(--green-soft); padding: 1.3rem 1.2rem; }
.tax-result strong { font-size: 1.6rem; }
.tax-summary > div { border-top: 1px solid var(--line); display: flex; font-size: .82rem; justify-content: space-between; padding: .8rem 0; }
.tax-summary .btn { margin-top: 1rem; }
.tax-big-number { display: block; font-size: 2.3rem; letter-spacing: -.06em; margin: 1.4rem 0; }
.trace-panel { margin-top: 1rem; }
.trace-columns { display: grid; gap: 1rem; grid-template-columns: repeat(3, 1fr); }
.trace-columns h3 { font-size: .85rem; }
.trace-columns a { align-items: center; border-top: 1px solid var(--line); color: var(--ink); display: flex; font-size: .78rem; justify-content: space-between; padding: .65rem 0; }
.trace-columns a b { white-space: nowrap; }
.vat-table > div { display: grid; gap: 1rem; grid-template-columns: 1fr 1fr 1fr; padding: .65rem 0; }
.vat-table .vat-head { border-bottom: 1px solid var(--line); color: var(--muted); font-size: .68rem; font-weight: 800; text-transform: uppercase; }
.vat-table strong { text-align: right; }
.operation-summary { display: grid; gap: 1rem; grid-template-columns: repeat(3, 1fr); margin-top: 1rem; }
.operation-summary div { border-right: 1px solid var(--line); padding: .4rem 1rem; }
.operation-summary div:last-child { border: 0; }
.operation-summary span { color: var(--muted); display: block; font-size: .72rem; }

.login-page { display: grid; grid-template-columns: 1.2fr .8fr; min-height: 100vh; }
.login-intro { background: var(--ink); color: white; display: flex; flex-direction: column; justify-content: space-between; padding: clamp(2rem, 6vw, 6rem); }
.login-intro h1 { font-size: clamp(2.8rem, 6vw, 6rem); max-width: 900px; }
.login-intro .lead { color: #b8c5be; font-size: 1.15rem; max-width: 650px; }
.login-note { color: #85968d; font-size: .75rem; }
.login-panel { align-items: center; background: var(--paper); display: flex; justify-content: center; padding: 2rem; }
.login-card { background: var(--panel); border: 1px solid var(--line); border-radius: 1.3rem; box-shadow: var(--shadow); display: grid; gap: 1.2rem; max-width: 440px; padding: clamp(1.5rem, 4vw, 2.5rem); width: 100%; }

@media (max-width: 1100px) {
    .metric-grid { grid-template-columns: repeat(2, 1fr); }
    .card-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 760px) {
    .sidebar { display: none; }
    .main-content { margin: 0; padding: 1rem 1rem 3rem; }
    .mobile-topbar { align-items: center; display: flex; justify-content: space-between; margin-bottom: 1.5rem; }
    .mobile-topbar nav { display: flex; gap: .6rem; font-size: .75rem; }
    .mobile-topbar .brand-mark { height: 34px; width: 34px; }
    .page-header, .quarter-strip { align-items: stretch; flex-direction: column; }
    .tax-header-actions { align-items: stretch; flex-direction: column; }
    .tax-header-actions .btn { text-align: center; }
    .period-picker, .filter-bar { align-items: stretch; display: grid; grid-template-columns: 1fr 1fr; }
    .period-picker .form-control, .period-picker .form-select { width: 100%; }
    .metric-grid, .content-grid, .settings-grid, .detail-layout, .tax-layout, .trace-columns, .operation-summary, .card-grid { grid-template-columns: 1fr; }
    .form-grid, .detail-grid { grid-template-columns: 1fr; }
    .invoice-intake-header, .invoice-analysis-row { align-items: stretch; flex-direction: column; }
    .ai-toggle { min-width: 0; }
    .form-actions { align-items: stretch; flex-direction: column; }
    .detail-grid .total-cell, .field-wide { grid-column: auto; }
    .login-page { grid-template-columns: 1fr; }
    .login-intro { min-height: 42vh; padding: 2rem; }
    .login-intro h1 { font-size: 2.6rem; }
    .login-note { display: none; }
    .operation-summary div { border-bottom: 1px solid var(--line); border-right: 0; }
}
