:root {
    --bg: #eef2ea;
    --bg-accent: radial-gradient(circle at top left, rgba(184, 148, 93, 0.18), transparent 30%), radial-gradient(circle at bottom right, rgba(15, 77, 59, 0.12), transparent 32%);
    --panel: rgba(255, 255, 255, 0.92);
    --panel-strong: #ffffff;
    --panel-soft: #f7f3ec;
    --text: #1f2a23;
    --muted: #647067;
    --line: rgba(53, 66, 58, 0.12);
    --brand: #154c3f;
    --brand-2: #b68645;
    --brand-3: #20352d;
    --danger: #b23a2f;
    --success: #1d6a49;
    --shadow: 0 24px 60px rgba(27, 36, 31, 0.10);
    --radius: 22px;
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body {
    margin: 0;
    color: var(--text);
    font-family: "Trebuchet MS", "Gill Sans", "Segoe UI", sans-serif;
    background: var(--bg-accent), linear-gradient(180deg, #f4f1ea, #edf3ef 45%, #eff2ee);
}
a { text-decoration: none; color: inherit; }
button { border: 0; cursor: pointer; font: inherit; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 14px 16px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { color: var(--muted); font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase; }
input, select, textarea {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid rgba(21, 76, 63, 0.16);
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.96);
    color: var(--text);
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.7);
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: rgba(182, 134, 69, 0.65);
    box-shadow: 0 0 0 4px rgba(182, 134, 69, 0.12);
}

.app-shell { display: flex; min-height: 100vh; gap: 18px; padding: 18px; }
.sidebar {
    width: 272px;
    background: linear-gradient(180deg, rgba(246, 239, 228, 0.96), rgba(241, 242, 237, 0.98));
    color: var(--text);
    padding: 16px 12px;
    border-radius: 28px;
    box-shadow: var(--shadow);
    position: sticky;
    top: 18px;
    display: flex;
    flex-direction: column;
    align-self: flex-start;
    border: 1px solid rgba(21, 76, 63, 0.08);
}
.brand {
    padding: 8px 10px 14px;
    border-bottom: 1px solid rgba(31, 42, 35, 0.08);
    margin-bottom: 12px;
}
.brand h1 { margin: 0; font-size: 20px; line-height: 1.2; letter-spacing: 0.02em; }
.brand p { margin: 8px 0 0; color: var(--muted); font-size: 13px; }
.nav {
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.nav-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.nav-label {
    padding: 2px 12px 4px;
    color: var(--muted);
    font-size: 11px;
    letter-spacing: 0.10em;
    text-transform: uppercase;
    font-weight: 700;
}
.nav a {
    padding: 10px 12px;
    border-radius: 12px;
    color: var(--text);
    border: 1px solid transparent;
    transition: 180ms ease;
}
.nav a:hover {
    background: rgba(255, 255, 255, 0.95);
    border-color: rgba(21, 76, 63, 0.10);
    color: var(--brand-3);
    transform: translateX(2px);
    box-shadow: 0 12px 24px rgba(20, 24, 22, 0.06);
}
.nav a.active {
    background: #fff;
    border-color: rgba(21, 76, 63, 0.12);
    color: var(--brand-3);
    font-weight: 700;
    box-shadow: 0 12px 24px rgba(20, 24, 22, 0.08);
 }

.main-content { flex: 1; min-width: 0; padding: 6px 6px 24px; }
.topbar {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
    margin-bottom: 18px;
}
.topbar-actions {
    display: flex;
    align-items: stretch;
    gap: 12px;
}
.topbar-shortcuts {
    display: flex;
    gap: 10px;
    align-items: center;
}
.topbar-shortcut {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 14px;
    border-radius: 18px;
    background: linear-gradient(180deg, rgba(255,255,255,0.92), rgba(247,243,236,0.92));
    border: 1px solid rgba(21, 76, 63, 0.10);
    box-shadow: var(--shadow);
    font-size: 14px;
    font-weight: 700;
    color: var(--brand-3);
}
.topbar-shortcut span {
    width: 24px;
    height: 24px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    background: linear-gradient(135deg, var(--brand), #1e6a58);
    color: #fff;
    font-size: 12px;
}
.topbar h2 { margin: 0 0 8px; font-size: clamp(28px, 4vw, 38px); line-height: 1; }
.topbar p { margin: 0; color: var(--muted); }
.topbar-card, .stat-card, .panel, .login-card, .hero-panel {
    background: var(--panel);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(255,255,255,0.65);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.topbar-card {
    padding: 16px 20px;
    min-width: 140px;
    text-align: center;
    background: linear-gradient(180deg, rgba(255,255,255,0.92), rgba(247,243,236,0.92));
}
.topbar-card span { display: block; color: var(--muted); margin-bottom: 6px; font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase; }
.topbar-card strong { font-size: 26px; color: var(--brand); }

.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 18px; margin-bottom: 20px; }
.stats-grid-wide { grid-template-columns: repeat(4, 1fr); }
.stat-card { padding: 22px; position: relative; overflow: hidden; }
.stat-card::after {
    content: "";
    position: absolute;
    inset: auto -24px -24px auto;
    width: 100px;
    height: 100px;
    background: radial-gradient(circle, rgba(182,134,69,0.24), transparent 60%);
}
.stat-card span { display: block; color: var(--muted); margin-bottom: 12px; font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase; }
.stat-card strong { font-size: 28px; line-height: 1.1; color: var(--brand-3); }

.panel-grid { display: grid; grid-template-columns: minmax(320px, 1fr) minmax(0, 1.5fr); gap: 20px; }
.panel-stack { display: grid; grid-template-columns: 1fr; gap: 20px; }
.products-layout { grid-template-columns: minmax(320px, 1.05fr) minmax(0, 1.95fr); }
.panel { padding: 22px; }
.panel-muted {
    background: linear-gradient(180deg, rgba(21,76,63,0.08), rgba(182,134,69,0.06));
    border-radius: var(--radius);
    padding: 22px;
    border: 1px solid rgba(21, 76, 63, 0.08);
}
.panel-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    margin-bottom: 18px;
}
.panel-head h3, .panel h3, .hero-panel h3 { margin: 0; font-size: 22px; }
.form-grid { display: grid; gap: 14px; }
.two-col { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.full-width { grid-column: 1 / -1; }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 11px 16px;
    border-radius: 999px;
    font-weight: 700;
    letter-spacing: 0.01em;
    transition: 180ms ease;
}
.btn:hover { transform: translateY(-1px); }
.btn-primary { background: linear-gradient(135deg, var(--brand), #1e6a58); color: #fff; }
.btn-secondary { background: #edf0e8; color: var(--brand-3); }
.btn-danger { background: linear-gradient(135deg, #b23a2f, #d55445); color: #fff; }
.small-muted { color: var(--muted); font-size: 13px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.field-action {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
    align-items: center;
}
.btn-small { padding: 10px 12px; white-space: nowrap; }
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(19, 28, 23, 0.45);
    display: none;
    place-items: center;
    z-index: 1000;
    padding: 20px;
}
.modal-backdrop.show { display: grid; }
.modal-card {
    width: min(460px, 100%);
    background: #fff;
    border-radius: 22px;
    padding: 20px;
    box-shadow: 0 30px 60px rgba(0,0,0,0.18);
}
.modal-card-compact {
    width: min(360px, 100%);
}
.qr-panel {
    text-align: center;
    padding-top: 8px;
}
.qr-panel img {
    width: min(280px, 100%);
    height: auto;
    border-radius: 12px;
    border: 1px solid rgba(21, 76, 63, 0.10);
    background: #fff;
}
.qr-link {
    margin: 12px 0 0;
    word-break: break-all;
}
.app-footer {
    padding: 0 24px 24px;
}
.app-footer-inner {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 16px 18px;
    border: 1px solid rgba(21, 76, 63, 0.10);
    border-radius: 20px;
    background: linear-gradient(180deg, rgba(255,255,255,0.92), rgba(247,243,236,0.92));
    box-shadow: var(--shadow);
}
.developer-logo {
    width: auto;
    height: 34px;
    object-fit: contain;
    flex: 0 0 auto;
}
.developer-logo-login {
    height: 30px;
    margin-bottom: 6px;
}
.developer-logo-settings {
    height: 30px;
}
.developer-credit strong {
    display: block;
    margin-bottom: 4px;
}
.developer-credit p {
    margin: 0;
    color: var(--muted);
    font-size: 13px;
}
.developer-credit a {
    color: var(--brand);
}
.developer-credit-card {
    display: flex;
    gap: 12px;
    align-items: center;
}
.login-credit {
    margin-top: 18px;
    padding-top: 16px;
    border-top: 1px solid var(--line);
    text-align: center;
}
.login-credit p {
    margin: 4px 0;
}
.hidden { display: none !important; }

.alert {
    padding: 14px 16px;
    border-radius: 16px;
    margin-bottom: 18px;
    border: 1px solid transparent;
}
.alert-success { background: rgba(29,106,73,0.10); color: #155437; border-color: rgba(29,106,73,0.12); }
.alert-error { background: rgba(178,58,47,0.10); color: #7c241d; border-color: rgba(178,58,47,0.12); }

.table-wrap {
    overflow-x: auto;
    border-radius: 18px;
    border: 1px solid rgba(53, 66, 58, 0.08);
    background: rgba(255,255,255,0.82);
}
tbody tr:hover { background: rgba(21,76,63,0.03); }
.badge {
    display: inline-flex;
    padding: 7px 12px;
    border-radius: 999px;
    font-size: 12px;
    background: rgba(21,76,63,0.09);
    color: var(--brand);
    font-weight: 700;
}
.row-alert { background: rgba(255, 243, 227, 0.82); }

.login-body {
    display: grid;
    place-items: center;
    min-height: 100vh;
    background: radial-gradient(circle at top, rgba(182,134,69,0.2), transparent 25%), linear-gradient(180deg, #f6f2ea, #edf2ee);
}
.login-card { width: min(460px, calc(100% - 24px)); padding: 34px; }
.login-card h1 { margin-top: 0; }

.search-box { position: relative; width: min(420px, 100%); }
.inline-search { position: relative; width: 100%; }
.search-results {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    background: #fff;
    border: 1px solid rgba(21,76,63,0.12);
    border-radius: 18px;
    max-height: 280px;
    overflow: auto;
    z-index: 10;
    box-shadow: 0 18px 42px rgba(27,36,31,0.12);
}
.search-item { padding: 14px 16px; border-bottom: 1px solid var(--line); cursor: pointer; }
.search-item:hover { background: rgba(21,76,63,0.05); }

.billing-grid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(300px, 1fr); gap: 18px; }
.summary-card p {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px dashed rgba(53, 66, 58, 0.18);
    padding: 12px 0;
    margin: 0;
}
.summary-card strong { color: var(--brand); }
.summary-card p:last-child { border-bottom: 0; }

.sales-page {
    border-top: 5px solid #c58a2c;
    background: linear-gradient(180deg, rgba(255, 252, 246, 0.96), rgba(255, 247, 234, 0.92));
}
.sales-page > form > .billing-grid > .panel-muted,
.sales-page .panel-muted {
    background: linear-gradient(180deg, rgba(197, 138, 44, 0.14), rgba(255, 235, 198, 0.20));
    border-color: rgba(197, 138, 44, 0.16);
}
.sales-page h3:first-child,
.sales-page .panel-head h3 {
    color: #8e5b0e;
}

.purchase-page {
    border-top: 5px solid #1a6b58;
    background: linear-gradient(180deg, rgba(245, 252, 248, 0.96), rgba(236, 247, 242, 0.92));
}
.purchase-page > form > .billing-grid > .panel-muted,
.purchase-page .panel-muted {
    background: linear-gradient(180deg, rgba(26, 107, 88, 0.12), rgba(197, 230, 217, 0.20));
    border-color: rgba(26, 107, 88, 0.14);
}
.purchase-page h3:first-child,
.purchase-page .panel-head h3 {
    color: #165245;
}
.purchase-page .btn-primary {
    background: linear-gradient(135deg, #1a6b58, #23846d);
}

.data-tools {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}
.table-search { width: min(320px, 100%); }
.table-pagination {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 8px;
    padding-top: 14px;
}
.table-pagination button {
    padding: 8px 12px;
    border-radius: 999px;
    background: #edf0e8;
    color: var(--brand-3);
}
.table-pagination button[disabled] { opacity: 0.45; cursor: default; }
.sortable {
    cursor: pointer;
    user-select: none;
    position: relative;
    padding-right: 18px;
}
.sortable::after {
    content: "↕";
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    font-size: 12px;
    color: #9aa59d;
}
.sortable.asc::after { content: "↑"; color: var(--brand); }
.sortable.desc::after { content: "↓"; color: var(--brand); }

.hero-panel {
    padding: 24px 26px;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 18px;
    margin-bottom: 20px;
    background: linear-gradient(135deg, rgba(255,255,255,0.96), rgba(247,243,236,0.92));
}
.eyebrow {
    margin: 0 0 10px;
    color: var(--brand-2);
    text-transform: uppercase;
    font-size: 12px;
    letter-spacing: 0.18em;
    font-weight: 700;
}
.statement-balance {
    min-width: 240px;
    background: linear-gradient(135deg, var(--brand-3), var(--brand));
    color: #fff;
    border-radius: 22px;
    padding: 18px 20px;
}
.statement-balance span { display: block; opacity: 0.7; text-transform: uppercase; font-size: 12px; letter-spacing: 0.1em; margin-bottom: 8px; }
.statement-balance strong { font-size: 30px; line-height: 1; }

.invoice-sheet {
    background: #fff;
    max-width: 940px;
    margin: 0 auto;
    border-radius: 28px;
    overflow: hidden;
    box-shadow: 0 28px 60px rgba(27,36,31,0.14);
    border: 1px solid rgba(53,66,58,0.08);
}
.invoice-banner {
    display: flex;
    justify-content: space-between;
    gap: 20px;
    padding: 28px 32px;
    background: linear-gradient(135deg, var(--brand-3), var(--brand));
    color: #fff;
}
.invoice-banner h2 { margin: 0 0 8px; font-size: 30px; }
.invoice-banner p { margin: 4px 0; opacity: 0.82; }
.invoice-label {
    text-align: right;
    min-width: 220px;
}
.invoice-label strong {
    display: inline-block;
    padding: 8px 14px;
    background: rgba(255,255,255,0.10);
    border-radius: 999px;
    margin-bottom: 12px;
}
.invoice-body { padding: 28px 32px 34px; }
.invoice-meta-grid {
    display: grid;
    grid-template-columns: 1.4fr 1fr;
    gap: 18px;
    margin-bottom: 22px;
}
.invoice-card {
    border: 1px solid rgba(53,66,58,0.08);
    border-radius: 20px;
    padding: 18px;
    background: #fcfbf8;
}
.invoice-card p { margin: 0 0 10px; }
.invoice-card p:last-child { margin-bottom: 0; }
.invoice-items th { background: #faf7f0; }
.invoice-items td:nth-child(4),
.invoice-items td:nth-child(5),
.invoice-items td:nth-child(6),
.invoice-items td:nth-child(7),
.invoice-items td:nth-child(8),
.invoice-items th:nth-child(4),
.invoice-items th:nth-child(5),
.invoice-items th:nth-child(6),
.invoice-items th:nth-child(7),
.invoice-items th:nth-child(8) {
    text-align: right;
}
.invoice-items tfoot td {
    font-weight: 700;
    background: #fcfbf8;
}
.invoice-print-footer {
    margin-top: 18px;
}
.invoice-summary-inline,
.invoice-amount-words,
.invoice-rounded-total,
.invoice-note-line {
    margin: 0;
}
.invoice-summary-inline {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    padding-top: 14px;
    border-top: 1px solid rgba(53,66,58,0.10);
    color: var(--brand-3);
    font-weight: 700;
}
.invoice-amount-words {
    margin-top: 8px;
    color: var(--brand-3);
    font-size: 14px;
}
.invoice-rounded-total {
    margin-top: 6px;
    padding-top: 8px;
    border-top: 1px solid rgba(53,66,58,0.10);
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 16px;
    color: var(--brand-3);
}
.invoice-rounded-total strong {
    font-size: 34px;
    line-height: 1;
}
.invoice-note-line {
    margin-top: 6px;
    padding-top: 6px;
    border-top: 1px solid rgba(53,66,58,0.10);
}

.filter-bar { display: flex; gap: 12px; align-items: end; flex-wrap: wrap; margin-bottom: 16px; }
.dummy-card-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.checkbox-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 14px; margin-top: 10px; }
.quick-add-row { display: flex; justify-content: space-between; gap: 12px; align-items: center; }
.entity-balance-chip {
    padding: 10px 14px;
    border-radius: 999px;
    background: rgba(255,255,255,0.85);
    border: 1px solid rgba(21, 76, 63, 0.10);
    color: var(--brand-3);
    font-size: 13px;
}
.report-total { font-size: 18px; color: var(--brand-3); }
.mt-20 { margin-top: 20px; }
.hidden-row { display: none; }

@media (max-width: 1180px) {
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .panel-grid, .products-layout, .billing-grid, .invoice-meta-grid, .two-col { grid-template-columns: 1fr; }
}

@media (max-width: 860px) {
    .app-shell { flex-direction: column; padding: 12px; }
    .sidebar {
        width: 100%;
        height: auto;
        position: static;
        border-radius: 22px;
    }
    .main-content { padding: 4px 2px 20px; }
    .hero-panel, .panel-head, .topbar, .topbar-actions, .topbar-shortcuts, .quick-add-row { flex-direction: column; align-items: stretch; }
    .stats-grid, .stats-grid-wide { grid-template-columns: 1fr; }
    .invoice-banner, .invoice-body { padding: 20px; }
    .dummy-card-grid, .checkbox-grid { grid-template-columns: 1fr; }
    .app-footer-inner, .developer-credit-card { flex-direction: column; align-items: flex-start; }
    .invoice-summary-inline,
    .invoice-rounded-total { flex-direction: column; align-items: flex-start; }
}

@media print {
    @page {
        size: A3 landscape;
        margin: 10px;
    }
    html, body {
        background: #fff !important;
        color: #000 !important;
        font-family: Arial, Helvetica, sans-serif;
        font-size: 11px;
        line-height: 1.2;
    }
    .sidebar, .topbar, .no-print, .table-search, .table-pagination, .app-footer { display: none !important; }
    .app-shell, .main-content {
        display: block;
        padding: 0 !important;
        margin: 0 !important;
        background: #fff !important;
    }
    .panel, .invoice-sheet, .invoice-banner, .invoice-body, .invoice-card, .table-wrap {
        box-shadow: none !important;
        border: 0 !important;
        border-radius: 0 !important;
        background: #fff !important;
        color: #000 !important;
        margin: 0 !important;
    }
    .invoice-sheet {
        max-width: none;
        overflow: visible;
        min-height: 250mm;
        display: flex;
        flex-direction: column;
    }
    .invoice-banner {
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        gap: 12px;
        padding: 0 0 6px !important;
        margin-bottom: 6px !important;
        border-bottom: 1px solid #000 !important;
    }
    .invoice-banner h2 {
        margin: 0 0 2px !important;
        font-size: 18px !important;
        color: #000 !important;
    }
    .invoice-banner p, .invoice-card p {
        margin: 1px 0 !important;
        opacity: 1 !important;
        color: #000 !important;
    }
    .eyebrow { margin: 0 0 2px !important; color: #000 !important; letter-spacing: 0.08em; }
    .invoice-label {
        text-align: right;
        min-width: 160px;
    }
    .invoice-label strong {
        display: block;
        padding: 0 !important;
        margin: 0 0 4px !important;
        background: none !important;
        border-radius: 0 !important;
        color: #000 !important;
    }
    .invoice-body {
        padding: 0 !important;
        display: flex;
        flex-direction: column;
        flex: 1 1 auto;
    }
    .invoice-meta-grid {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 8px;
        margin: 0 0 6px !important;
    }
    .invoice-card {
        padding: 2px 0 !important;
    }
    .table-wrap { overflow: visible; }
    .table-wrap.invoice-items { margin-bottom: 0 !important; }
    .invoice-items table {
        border-collapse: collapse !important;
        border-top: 1px solid #000 !important;
        border-bottom: 1px solid #000 !important;
    }
    .invoice-items th,
    .invoice-items td {
        border-top: 0 !important;
        border-bottom: 0 !important;
        border-left: 0 !important;
        border-right: 0 !important;
    }
    .invoice-items th,
    .invoice-items td {
        padding: 3px 4px !important;
        color: #000 !important;
        background: #fff !important;
        font-size: 10.5px !important;
    }
    .invoice-items th {
        font-size: 10px !important;
        letter-spacing: 0.04em !important;
        border-bottom: 1px solid #000 !important;
    }
    .invoice-print-footer {
        margin-top: auto !important;
        padding-top: 6px !important;
        flex-shrink: 0;
    }
    .invoice-summary-inline {
        padding-top: 4px !important;
        border-top: 1px solid #000 !important;
        gap: 12px !important;
        font-size: 10.5px !important;
        color: #000 !important;
    }
    .invoice-summary-inline span:first-child {
        margin-left: auto !important;
    }
    .invoice-amount-words {
        margin-top: 4px !important;
        font-size: 10.5px !important;
        color: #000 !important;
    }
    .invoice-rounded-total {
        margin-top: 4px !important;
        padding-top: 4px !important;
        border-top: 1px solid #000 !important;
        color: #000 !important;
    }
    .invoice-rounded-total span {
        font-size: 11px !important;
    }
    .invoice-rounded-total strong {
        font-size: 22px !important;
        color: #000 !important;
    }
    .invoice-note-line {
        margin-top: 4px !important;
        padding-top: 4px !important;
        border-top: 1px solid #000 !important;
        font-size: 10.5px !important;
        color: #000 !important;
    }
    .btn, .actions { display: none !important; }
}
