:root {
    --ink: #202923;
    --muted: #768078;
    --line: #e8e9e2;
    --paper: #fff;
    --canvas: #f6f5f1;
    --green: #267a55;
    --green-soft: #e7f3ec;
    --red: #bf554a;
    --red-soft: #f8ece9;
    --orange: #c47a29;
    --orange-soft: #fbf1e2;
    --sidebar: #202a24;
    --sidebar-muted: #96a39a;
    --shadow: 0 16px 44px rgba(34, 43, 36, .07);
    font-family: 'DM Sans', 'Segoe UI', sans-serif;
    color: var(--ink);
    background: var(--canvas);
    font-synthesis: none;
    text-rendering: optimizeLegibility;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; background: var(--canvas); color: var(--ink); font-size: 14px; }
button, input, select, textarea { font: inherit; }
a { color: inherit; text-decoration: none; }
button { cursor: pointer; }
h1, h2, h3, p { margin-top: 0; }
h1, h2, h3, .brand strong { font-family: Manrope, 'Segoe UI', sans-serif; letter-spacing: -.035em; }
.muted { color: var(--muted); }
.eyebrow { color: var(--green); font-size: 10px; font-weight: 700; letter-spacing: .16em; margin-bottom: 9px; }
.field-hint { color: var(--muted); font-weight: 400; }
.brand-mark { width: 39px; height: 39px; display: grid; place-items: center; border-radius: 12px; background: #dceadf; color: #286448; font: 800 22px Manrope, sans-serif; }
.button { min-height: 43px; display: inline-flex; justify-content: center; align-items: center; gap: 12px; border: 1px solid transparent; border-radius: 8px; padding: 0 16px; font-weight: 700; transition: .18s ease; }
.button-primary { background: var(--green); color: #fff; }
.button-primary:hover { background: #1d6646; transform: translateY(-1px); }
.button-secondary { background: #fff; color: var(--ink); border-color: var(--line); }
.button-secondary:hover { border-color: #b7c4b9; }
.button-danger { background: var(--red-soft); color: var(--red); border-color: #f0d5d0; }
.button-small { min-height: 34px; padding: 0 11px; font-size: 12px; }
.button-wide { width: 100%; margin-top: 7px; }
.button:disabled { cursor: not-allowed; opacity: .48; transform: none; }
.icon-button { width: 34px; height: 34px; border: 0; border-radius: 8px; background: transparent; color: var(--sidebar-muted); font-size: 20px; }
.icon-button:hover { color: #fff; background: rgba(255,255,255,.08); }
.alert { padding: 12px 14px; border-radius: 8px; margin: 0 0 18px; line-height: 1.5; }
.alert-error { color: #973e35; background: #fbefed; border: 1px solid #f2d3cf; }
.alert-success { color: #236542; background: #e9f5ed; border: 1px solid #cbe8d3; }

/* Main app frame */
.app-shell { min-height: 100vh; }
.sidebar { position: fixed; z-index: 20; inset: 0 auto 0 0; width: 246px; display: flex; flex-direction: column; background: var(--sidebar); color: #f6f7f2; padding: 26px 17px 14px; }
.brand { display: flex; align-items: center; gap: 11px; padding: 0 7px; }
.brand strong { display: block; font-size: 17px; letter-spacing: -.04em; }
.brand small { display: block; margin-top: 2px; color: #aab5aa; font-size: 8px; letter-spacing: .16em; }
.workspace-label { margin: 43px 10px 12px; color: #839188; font-size: 9px; font-weight: 700; letter-spacing: .16em; }
.company-switcher { display: grid; gap: 7px; margin: -2px 3px 18px; padding: 10px; border: 1px solid rgba(255,255,255,.1); border-radius: 8px; background: rgba(255,255,255,.04); }
.company-switcher label { color: #94a197; font-size: 8px; font-weight: 700; letter-spacing: .12em; }
.company-switcher select { width: 100%; border: 0; outline: 0; background: transparent; color: #f6f7f2; font-size: 11px; }
.company-switcher select option { color: var(--ink); }
.side-nav { display: grid; gap: 4px; }
.nav-link { min-height: 42px; display: flex; align-items: center; gap: 12px; border-radius: 7px; padding: 0 11px; color: #c2cbc2; font-size: 13px; transition: .15s; }
.nav-link:hover { background: rgba(255,255,255,.07); color: #fff; }
.nav-link.is-active { color: #fff; background: #35463a; box-shadow: inset 2px 0 #8db797; }
.nav-icon { width: 18px; text-align: center; color: #a6b6a8; font-size: 17px; }
.nav-link.is-active .nav-icon { color: #a9d7b6; }
.nav-lower-label { margin-top: 35px; }
.sidebar-bottom { display: flex; align-items: center; gap: 10px; margin-top: auto; padding: 16px 4px 2px; border-top: 1px solid rgba(255,255,255,.1); }
.firm-avatar { width: 34px; height: 34px; display: grid; flex: 0 0 auto; place-items: center; border-radius: 50%; background: #425949; color: #dcefe0; font-weight: 700; }
.firm-logo { width: 34px; height: 34px; flex: 0 0 auto; border-radius: 7px; background: #fff; object-fit: contain; padding: 2px; }
.firm-identity { min-width: 0; flex: 1; }
.firm-identity strong, .firm-identity small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.firm-identity strong { font-size: 11px; }
.firm-identity small { margin-top: 4px; color: var(--sidebar-muted); font-size: 10px; }
.logout-form { margin: 0; }
.main-column { min-height: 100vh; margin-left: 246px; display: flex; flex-direction: column; }
.topbar { height: 62px; display: flex; align-items: center; justify-content: space-between; padding: 0 42px; border-bottom: 1px solid var(--line); background: rgba(255,255,255,.72); }
.breadcrumb { display: flex; align-items: center; gap: 11px; color: #89928a; font-size: 12px; }
.breadcrumb i { color: #c4c9c2; font-style: normal; }
.breadcrumb strong { color: var(--ink); font-weight: 600; }
.topbar-date { color: #7e8980; font-size: 11px; }
.menu-toggle { display: none; border: 0; background: none; color: var(--ink); font-size: 21px; }
.main-content { width: min(1320px, 100%); flex: 1; margin: 0 auto; padding: 36px 42px 54px; }
.app-footer { display: flex; justify-content: space-between; padding: 15px 42px 18px; border-top: 1px solid var(--line); color: #929a92; font-size: 10px; }
.page-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 24px; }
.page-heading h1 { margin-bottom: 6px; font-size: 26px; line-height: 1.2; }
.page-heading p { margin: 0; color: var(--muted); font-size: 12px; }
.heading-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.panel { border: 1px solid var(--line); border-radius: 10px; background: var(--paper); box-shadow: 0 4px 14px rgba(34,43,36,.025); }
.panel-heading { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 19px 20px 15px; }
.panel-heading h2, .panel-heading h3 { margin: 0; font-size: 14px; letter-spacing: -.02em; }
.panel-heading p { margin: 4px 0 0; color: var(--muted); font-size: 11px; }
.text-link { color: var(--green); font-size: 10px; font-weight: 700; }
.panel-body { padding: 18px 20px; }
.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 13px; margin-bottom: 16px; }
.stat-card { min-height: 129px; position: relative; overflow: hidden; padding: 19px 19px 16px; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
.stat-label { display: flex; align-items: center; gap: 8px; color: #68736b; font-size: 11px; font-weight: 600; }
.stat-dot { width: 7px; height: 7px; border-radius: 50%; background: #8f9a91; }
.stat-card.is-green .stat-dot { background: #388562; }
.stat-card.is-red .stat-dot { background: #c96157; }
.stat-card.is-orange .stat-dot { background: #d48b39; }
.stat-value { margin-top: 17px; font: 700 23px Manrope, sans-serif; letter-spacing: -.055em; white-space: nowrap; }
.stat-card.is-green .stat-value { color: var(--green); }
.stat-card.is-red .stat-value { color: var(--red); }
.stat-card.is-orange .stat-value { color: var(--orange); }
.stat-sub { margin-top: 5px; color: #a0a8a0; font-size: 10px; }
.dashboard-grid { display: grid; grid-template-columns: minmax(0,1.5fr) minmax(280px,.9fr); gap: 15px; }
.chart-legend { display: flex; gap: 14px; color: var(--muted); font-size: 10px; }
.legend-item { display: flex; align-items: center; gap: 5px; }
.legend-dot { width: 7px; height: 7px; border-radius: 50%; background: #43835e; }
.legend-dot.is-orange { background: #d49a58; }
.chart-wrap { height: 218px; display: flex; align-items: stretch; gap: 13px; padding: 6px 6px 0; border-bottom: 1px solid var(--line); }
.chart-month { min-width: 0; flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 9px; }
.chart-bars { width: 100%; max-width: 42px; height: 174px; display: flex; align-items: flex-end; justify-content: center; gap: 4px; }
.chart-bar { width: min(17px, 40%); min-height: 3px; border-radius: 4px 4px 0 0; background: #43835e; }
.chart-bar.is-orange { background: #d49a58; }
.chart-month small { padding-bottom: 8px; color: #879188; font-size: 9px; }
.table-wrap { width: 100%; overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; text-align: left; }
.data-table th { padding: 11px 14px; border-bottom: 1px solid var(--line); color: #89938a; font-size: 9px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; white-space: nowrap; }
.data-table td { padding: 13px 14px; border-bottom: 1px solid #f0f0ec; color: #4f5a52; font-size: 11px; vertical-align: middle; }
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table td strong { color: var(--ink); font-weight: 600; }
.table-empty { padding: 30px 15px !important; color: var(--muted) !important; text-align: center; }
.amount-positive { color: var(--green) !important; font-weight: 700; white-space: nowrap; }
.amount-negative { color: var(--red) !important; font-weight: 700; white-space: nowrap; }
.amount-warning { color: var(--orange) !important; font-weight: 700; white-space: nowrap; }
.badge { display: inline-flex; align-items: center; border-radius: 20px; padding: 4px 8px; background: #f1f2ed; color: #66716a; font-size: 9px; font-weight: 700; white-space: nowrap; }
.badge-green { color: var(--green); background: var(--green-soft); }
.badge-red { color: var(--red); background: var(--red-soft); }
.badge-orange { color: var(--orange); background: var(--orange-soft); }
.filters { display: flex; align-items: flex-end; flex-wrap: wrap; gap: 9px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.filters label, .form-stack label { min-width: 0; display: grid; gap: 6px; color: #5f6b62; font-size: 10px; font-weight: 600; }
.filters input, .filters select, .form-stack input, .form-stack select, .form-stack textarea { width: 100%; min-height: 39px; border: 1px solid #e1e4dd; border-radius: 7px; outline: 0; padding: 8px 10px; background: #fff; color: var(--ink); font-size: 12px; }
.filters input:focus, .filters select:focus, .form-stack input:focus, .form-stack select:focus, .form-stack textarea:focus { border-color: #80aa8c; box-shadow: 0 0 0 3px rgba(67,131,94,.1); }
.filters .filter-wide { flex: 1 1 180px; }
.filters .filter-small { width: 148px; }
.filters .button { min-height: 39px; }
.pagination { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 13px 16px; border-top: 1px solid var(--line); color: var(--muted); font-size: 10px; }
.pagination-links { display: flex; gap: 6px; }
.pagination-links a { min-width: 29px; min-height: 29px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
.pagination-links a:hover { border-color: #89ae93; color: var(--green); }
.content-grid { display: grid; grid-template-columns: minmax(0,1fr) 310px; align-items: start; gap: 15px; }
.form-stack { display: grid; gap: 13px; }
.form-stack textarea { min-height: 78px; resize: vertical; }
.form-stack .form-row { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 10px; }
.inline-actions { display: flex; align-items: center; gap: 6px; }
.inline-form { display: inline; margin: 0; }
.form-note { margin: 0; color: var(--muted); font-size: 10px; line-height: 1.5; }
.balance-box { display: flex; align-items: center; justify-content: space-between; border-top: 1px solid var(--line); margin-top: 13px; padding-top: 14px; color: var(--muted); font-size: 11px; }
.balance-box strong { font-size: 14px; }
.detail-grid { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 12px; margin-bottom: 16px; }
.detail-item { padding: 12px; border-radius: 8px; background: #f8f8f5; }
.detail-item span { display: block; color: var(--muted); font-size: 10px; }
.detail-item strong { display: block; margin-top: 6px; font-size: 12px; }
.upload-preview { display: flex; align-items: center; gap: 12px; }
.upload-preview img { max-width: 96px; max-height: 56px; object-fit: contain; }
.logo-placeholder { width: 84px; height: 48px; display: grid; place-items: center; border-radius: 7px; background: #f2f3ef; color: #879188; font-size: 10px; }
.overdue-row { background: #fffbf4; }
.overdue-label { color: var(--orange); font-size: 9px; font-weight: 700; }
.print-only { display: none; }

/* Installer and login */
.install-page { min-height: 100vh; display: grid; place-items: center; padding: 28px 16px; background: #f2f3ee; }
.install-shell { width: min(600px, 100%); }
.install-heading { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.install-heading h1 { margin: 0; font-size: 21px; }
.install-heading .eyebrow { margin: 0 0 3px; font-size: 8px; }
.install-steps { display: grid; grid-template-columns: repeat(4,1fr); margin-bottom: 14px; }
.install-step { position: relative; display: flex; flex-direction: column; align-items: center; gap: 7px; color: #a0a8a0; font-size: 9px; }
.install-step:not(:last-child)::after { position: absolute; content: ''; height: 1px; width: calc(100% - 40px); top: 14px; left: calc(50% + 20px); background: #dfe2dc; }
.install-step b { z-index: 1; width: 29px; height: 29px; display: grid; place-items: center; border: 1px solid #dfe2dc; border-radius: 50%; background: #f2f3ee; font-size: 10px; }
.install-step.is-current { color: var(--green); font-weight: 700; }
.install-step.is-current b, .install-step.is-done b { border-color: var(--green); color: white; background: var(--green); }
.install-step.is-done { color: #64766a; }
.install-card { padding: 27px; border: 1px solid var(--line); border-radius: 12px; background: #fff; box-shadow: var(--shadow); }
.install-card h2 { margin-bottom: 7px; font-size: 20px; }
.install-card > .muted { margin-bottom: 20px; font-size: 12px; line-height: 1.5; }
.install-card code { padding: 2px 5px; border-radius: 4px; background: #f2f3ef; }
.install-card .button { margin-top: 18px; }
.requirement-list { list-style: none; margin: 0 0 20px; padding: 0; border-top: 1px solid var(--line); }
.requirement-list li { display: flex; justify-content: space-between; padding: 13px 2px; border-bottom: 1px solid var(--line); font-size: 12px; }
.status-ok { color: var(--green); }
.status-error { color: var(--red); }
.form-stack .button-row { display: flex; justify-content: space-between; gap: 8px; margin-top: 5px; }
.form-stack .button-row .button { margin-top: 0; }
.install-footnote { margin: 14px 0 0; color: #8c958d; text-align: center; font-size: 10px; }
.login-page { min-height: 100vh; background: #fff; }
.login-shell { min-height: 100vh; display: grid; grid-template-columns: minmax(360px, .92fr) minmax(420px,1.08fr); }
.login-intro { position: relative; min-height: 100vh; overflow: hidden; display: flex; flex-direction: column; padding: 38px 54px 29px; background: #e9eee7; }
.login-brand { padding: 0; }
.login-brand small { color: #819083; }
.intro-copy { position: relative; z-index: 2; margin: auto 0; padding-bottom: 60px; }
.intro-copy .eyebrow { margin-bottom: 14px; }
.intro-copy h1 { margin-bottom: 15px; font-size: clamp(33px,4vw,49px); line-height: 1.14; }
.intro-copy > p:last-child { max-width: 315px; margin: 0; color: #748078; font-size: 13px; line-height: 1.7; }
.login-copyright { position: relative; z-index: 2; color: #849087; font-size: 10px; }
.login-decoration { position: absolute; right: -74px; bottom: 64px; width: 290px; height: 190px; display: flex; align-items: flex-end; gap: 9px; transform: rotate(-16deg); opacity: .68; }
.login-decoration span { width: 13px; border-radius: 9px; background: #cad9c9; }
.login-decoration span:nth-child(3n+1) { height: 50%; }
.login-decoration span:nth-child(3n+2) { height: 76%; background: #d6e1d3; }
.login-decoration span:nth-child(3n) { height: 100%; background: #bfd2c1; }
.login-panel { display: grid; place-items: center; padding: 36px; }
.login-form-wrap { width: min(365px,100%); }
.login-form-wrap h2 { margin-bottom: 7px; font-size: 24px; }
.login-form-wrap > .muted { margin-bottom: 25px; font-size: 12px; }
.login-form { gap: 16px; }
.login-form label { font-size: 11px; }
.login-form input { min-height: 45px; padding: 10px 12px; font-size: 13px; }
.login-help { margin: 19px 0 0; color: #8a938b; text-align: center; font-size: 10px; }
.login-help a { color: var(--green); font-weight: 700; }

@media (max-width: 1100px) {
    .sidebar { width: 218px; }
    .main-column { margin-left: 218px; }
    .main-content { padding-right: 26px; padding-left: 26px; }
    .topbar { padding-right: 26px; padding-left: 26px; }
    .stats-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
    .content-grid { grid-template-columns: minmax(0,1fr) 285px; }
}
@media (max-width: 820px) {
    .sidebar { transform: translateX(-100%); transition: transform .22s ease; }
    .sidebar.is-open { transform: translateX(0); }
    .sidebar-scrim { position: fixed; z-index: 19; inset: 0; display: none; background: rgba(20,28,23,.35); }
    .menu-open .sidebar-scrim { display: block; }
    .main-column { margin-left: 0; }
    .topbar { height: 57px; justify-content: flex-start; gap: 13px; }
    .menu-toggle { display: inline-grid; place-items: center; }
    .topbar-date { margin-left: auto; }
    .content-grid { grid-template-columns: 1fr; }
    .dashboard-grid { grid-template-columns: 1fr; }
    .detail-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
    .login-shell { grid-template-columns: minmax(280px,.8fr) minmax(360px,1.2fr); }
    .login-intro { padding-right: 30px; padding-left: 30px; }
}
@media (max-width: 600px) {
    .main-content { padding: 25px 15px 35px; }
    .topbar { padding: 0 15px; }
    .app-footer { padding: 13px 15px; }
    .app-footer span:last-child { display: none; }
    .page-heading { align-items: flex-start; flex-direction: column; margin-bottom: 18px; }
    .page-heading h1 { font-size: 23px; }
    .stats-grid { gap: 9px; }
    .stat-card { min-height: 111px; padding: 14px 12px; }
    .stat-value { margin-top: 14px; font-size: 18px; }
    .stat-label { font-size: 10px; }
    .panel-heading { padding: 15px 14px 12px; }
    .panel-body { padding: 14px; }
    .filters { align-items: stretch; }
    .filters .filter-small { width: calc(50% - 5px); flex: 1 1 calc(50% - 5px); }
    .filters .filter-wide { flex-basis: 100%; }
    .filters .button { flex: 1; }
    .form-stack .form-row { grid-template-columns: 1fr; }
    .data-table td, .data-table th { padding-right: 10px; padding-left: 10px; }
    .chart-legend { gap: 8px; }
    .login-shell { grid-template-columns: 1fr; }
    .login-intro { min-height: 200px; padding: 24px 23px; }
    .intro-copy { margin: 28px 0 0; padding: 0 0 22px; }
    .intro-copy h1 { font-size: 29px; }
    .intro-copy > p:last-child, .login-copyright, .login-decoration { display: none; }
    .login-panel { padding: 40px 23px; }
    .login-form-wrap h2 { font-size: 21px; }
    .install-card { padding: 20px 17px; }
    .install-step { font-size: 8px; }
    .install-step:not(:last-child)::after { width: calc(100% - 30px); left: calc(50% + 15px); top: 13px; }
    .install-step b { width: 27px; height: 27px; }
    .install-card .form-stack .button-row { align-items: stretch; flex-direction: column; }
}
@media print {
    body { background: #fff; }
    .sidebar, .topbar, .app-footer, .filters, .heading-actions, .menu-toggle, .sidebar-scrim, .no-print { display: none !important; }
    .main-column { margin: 0; }
    .main-content { width: 100%; padding: 0; }
    .panel, .stat-card { box-shadow: none; border-color: #ddd; }
    .print-only { display: block; }
    .page-heading { margin-bottom: 12px; }
    .data-table th, .data-table td { padding: 7px; }
}
