@import url('https://fonts.googleapis.com/css2?family=Vazirmatn:wght@400;500;600;700;800&display=swap');

:root {
    --wine: #7b2435;
    --wine-dark: #571725;
    --ink: #25232a;
    --muted: #777580;
    --line: #e9e7eb;
    --paper: #fff;
    --bg: #f5f4f6;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: Vazirmatn, Tahoma, sans-serif;
    font-size: 13px;
}

a {
    color: var(--wine);
    text-decoration: none;
}

button,
input,
select,
textarea {
    font: inherit;
}

button {
    cursor: pointer;
}

.app-shell {
    min-height: 100vh;
    display: flex;
}

.sidebar {
    width: 245px;
    background: #211c22;
    color: #fff;
    padding: 26px 16px;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 8px 30px;
}

.brand-mark,
.login-logo {
    display: grid;
    place-items: center;
    background: var(--wine);
    color: #fff;
    border-radius: 12px;
    width: 43px;
    height: 43px;
    font-size: 24px;
    font-weight: 800;
}

.brand small {
    display: block;
    color: #a9a2a9;
    font-size: 10px;
    margin-top: 3px;
}

.sidebar nav {
    display: grid;
    gap: 7px;
}

.sidebar nav a {
    color: #d4cfd4;
    padding: 12px 13px;
    border-radius: 9px;
}

.sidebar nav a:hover,
.sidebar nav a:focus {
    background: #382b34;
    color: #fff;
}

.side-foot {
    margin-top: auto;
    color: #9c929a;
    padding: 20px 10px 0;
    font-size: 11px;
}

.main {
    min-width: 0;
    flex: 1;
    display: flex;
    flex-direction: column;
}

.topbar {
    height: 74px;
    background: #fff;
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 34px;
}

.topbar b {
    display: block;
    font-size: 14px;
}

.muted,
.eyebrow {
    color: var(--muted);
    font-size: 10px;
}

.logout {
    font-size: 12px;
}

.content {
    padding: 30px;
    max-width: 1500px;
    width: 100%;
    margin: 0 auto;
    flex: 1;
}

.footer {
    text-align: center;
    color: #8a858d;
    font-size: 11px;
    padding: 20px;
    border-top: 1px solid var(--line);
    background: #fff;
}

.footer b {
    color: var(--wine);
}

.page-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 24px;
}

.page-heading h1 {
    font-size: 25px;
    margin: 4px 0;
}

.page-heading p {
    color: var(--muted);
    margin: 4px 0;
}

.eyebrow {
    letter-spacing: 1.5px;
    color: var(--wine);
    font-weight: 700;
}

.btn {
    border: 1px solid transparent;
    border-radius: 8px;
    padding: 10px 16px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    font-weight: 600;
}

.btn.primary {
    background: var(--wine);
    color: #fff;
}

.btn.primary:hover {
    background: var(--wine-dark);
}

.btn.secondary {
    background: #fff;
    border-color: var(--line);
    color: #4c4850;
}

.btn.small {
    padding: 7px 11px;
    font-size: 11px;
}

.btn.large {
    padding: 14px 25px;
    font-size: 14px;
}

.btn.full {
    width: 100%;
}

.panel,
.stat {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 13px;
    padding: 21px;
    margin-bottom: 18px;
    box-shadow: 0 4px 18px #30233306;
}

.panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 18px;
}

.panel h2,
.panel-head h2 {
    font-size: 15px;
    margin: 0;
}

.panel-head small,
.count {
    color: var(--muted);
    font-size: 11px;
}

.stats {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 15px;
    margin-bottom: 20px;
}

.stat {
    margin: 0;
    padding: 20px;
}

.stat span,
.stat small {
    display: block;
    color: var(--muted);
}

.stat b {
    display: block;
    font-size: 25px;
    margin: 8px 0;
    color: var(--wine);
}

.stat small {
    font-size: 10px;
}

.table-wrap {
    overflow: auto;
}

table {
    border-collapse: collapse;
    width: 100%;
    white-space: nowrap;
}

th,
td {
    padding: 12px 11px;
    text-align: right;
    border-bottom: 1px solid var(--line);
}

th {
    background: #faf9fa;
    color: #6f6972;
    font-size: 11px;
    font-weight: 700;
}

td {
    font-size: 12px;
}

tbody tr:last-child td {
    border-bottom: 0;
}

.empty {
    text-align: center;
    color: var(--muted);
    padding: 30px;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 15px;
}

.form-grid label,
.login-card label {
    display: flex;
    flex-direction: column;
    gap: 7px;
    color: #55515a;
    font-size: 12px;
    font-weight: 600;
}

.form-grid input,
.form-grid select,
.form-grid textarea,
.login-card input:not([type=checkbox]),
.searchbar input {
    width: 100%;
    border: 1px solid #e4e1e6;
    background: #fff;
    border-radius: 7px;
    padding: 10px 11px;
    outline: none;
    color: var(--ink);
    min-height: 40px;
}

.form-grid input:focus,
.form-grid select:focus,
.form-grid textarea:focus,
.login-card input:focus {
    border-color: var(--wine);
    box-shadow: 0 0 0 3px #7b243510;
}

.form-grid textarea {
    resize: vertical;
}

.wide {
    grid-column: 1 / -1;
}

.check {
    display: flex !important;
    flex-direction: row !important;
    align-items: center;
    gap: 9px !important;
}

.check input {
    width: auto !important;
    min-height: 0 !important;
    accent-color: var(--wine);
}

.inline {
    display: inline;
}

.link {
    border: 0;
    background: none;
    color: var(--wine);
    padding: 0;
}

.danger {
    color: #b42332;
}

.alert {
    padding: 12px 15px;
    background: #f3edf0;
    color: var(--wine);
    border-radius: 8px;
    margin-bottom: 18px;
}

.alert.error {
    background: #fff0f0;
    color: #a3222b;
}

.two-col {
    display: grid;
    grid-template-columns: minmax(280px, .8fr) minmax(0, 1.2fr);
    gap: 18px;
}

.searchbar {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
}

.searchbar input {
    max-width: 340px;
}

.pill {
    background: #f6eef1;
    color: var(--wine);
    border-radius: 30px;
    padding: 6px 10px;
    font-size: 11px;
}

.compact {
    margin-top: 18px;
}

.calc-strip {
    display: flex;
    flex-wrap: wrap;
    gap: 25px;
    padding: 15px;
    background: #faf8f9;
    border-radius: 9px;
    margin-top: 16px;
}

.calc-strip b {
    color: var(--wine);
}

.edit-table input {
    min-width: 100px;
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 8px;
}

.edit-table td:first-child {
    min-width: 230px;
}

.installment-box[hidden] {
    display: none;
}

.actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.login-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    background: radial-gradient(circle at 15% 15%, #eadde1, transparent 35%), #f5f2f4;
}

.login-card {
    width: min(420px, calc(100% - 30px));
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 17px;
    padding: 35px;
    box-shadow: 0 20px 70px #39212a14;
}

.login-logo {
    margin: 0 auto 15px;
    width: 55px;
    height: 55px;
    font-size: 30px;
}

.login-card h1,
.login-card h2 {
    text-align: center;
    font-size: 20px;
}

.login-card p {
    text-align: center;
    color: var(--muted);
    margin-bottom: 25px;
}

.login-card label {
    margin: 14px 0 7px;
}

.login-card .check {
    margin: 18px 0;
}

.login-note {
    display: block;
    text-align: center;
    color: #999;
    margin-top: 22px;
}

.invoice-paper {
    position: relative;
    background: #fff;
    color: #111;
    width: 100%;
    max-width: 794px;
    min-height: 560px;
    margin: 0 auto 30px;
    padding: 26px 30px;
    border: 1px solid #ddd;
    box-shadow: 0 8px 30px #0000000b;
    overflow: hidden;
    isolation: isolate;
}

.invoice-content {
    position: relative;
    z-index: 1;
}

.watermark {
    position: absolute;
    z-index: 0;
    inset: 0;
    background-repeat: no-repeat;
    background-position: center;
    background-size: 62%;
    opacity: var(--watermark-opacity);
    pointer-events: none;
}

.invoice-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 15px;
}

.invoice-brand {
    display: flex;
    align-items: center;
    gap: 13px;
}

.invoice-logo {
    width: 75px;
    height: 65px;
    object-fit: contain;
}

.invoice-brand h1 {
    font-size: 19px;
    margin: 0 0 5px;
    color: var(--invoice-color);
}

.invoice-brand small {
    font-size: 10px;
    color: #666;
}

.invoice-meta {
    display: flex;
    align-items: center;
    gap: 14px;
}

.invoice-meta > div:not(.qr) {
    display: grid;
    gap: 5px;
    text-align: center;
}

.invoice-meta span {
    font-size: 9px;
    color: #777;
}

.invoice-meta b {
    font-size: 11px;
}

.qr-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
}

.qr {
    width: 100px;
    height: 100px;
    padding: 5px;
    background: #fff;
    border: 1px solid #ddd;
    display: flex;
    align-items: center;
    justify-content: center;
}

.qr img,
.qr canvas {
    width: 94px !important;
    height: 94px !important;
    display: block;
}

@media print {
    .qr {
        width: 160px !important;
        height: 160px !important;
        border: 1px solid #000 !important;
        background: #fff !important;
        print-color-adjust: exact;
        -webkit-print-color-adjust: exact;
    }

    .qr img,
    .qr canvas {
        width: 94px !important;
        height: 94px !important;
    }
}

@media (max-width: 576px) {
    .qr-wrapper {
        gap: 3px;
    }

    .qr {
        width: 65px;
        height: 65px;
        padding: 3px;
    }

    .qr img,
    .qr canvas {
        width: 59px !important;
        height: 59px !important;
    }
}

.invoice-rule {
    height: 3px;
    background: var(--invoice-color);
    margin: 17px 0;
}

.parties {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.parties section {
    border: 1px solid #d9d9d9;
    border-radius: 7px;
    padding: 11px 13px;
    min-width: 0;
}

.parties h3,
.description h3,
.installment-print h3 {
    font-size: 11px;
    color: var(--invoice-color);
    margin: 0 0 8px;
    padding-bottom: 6px;
    border-bottom: 1px solid #ddd;
}

.party-name {
    font-size: 12px;
}

.parties p {
    font-size: 9px;
    line-height: 1.8;
    margin: 4px 0;
    white-space: normal;
}

.invoice-items {
    margin-top: 17px;
    font-size: 10px;
}

.invoice-items th {
    background: #f0edef;
    color: #222;
    border-bottom: 1px solid #bbb;
    font-size: 9px;
}

.invoice-items td {
    font-size: 9px;
    padding: 10px 8px;
    white-space: normal;
}

.invoice-bottom {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
    margin-top: 15px;
}

.description {
    border: 1px solid #ddd;
    border-radius: 7px;
    padding: 10px;
}

.description p {
    font-size: 9px;
    line-height: 1.8;
    min-height: 35px;
}

.sale-kind {
    font-size: 10px;
    margin-top: 12px;
}

.totals {
    position: relative;
    border: 1px solid #ddd;
    border-radius: 7px;
    padding: 9px 12px;
}

.totals > div {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    padding: 6px 0;
    border-bottom: 1px dashed #ddd;
    font-size: 9px;
}

.totals > div:last-child {
    border: 0;
}

.totals b {
    font-variant-numeric: tabular-nums;
}

.totals .grand {
    background: #f3f0f1;
    color: var(--invoice-color);
    padding: 9px;
    margin: 4px -5px;
    font-weight: 800;
}

.totals .grand b {
    font-size: 12px;
}

.totals .remaining {
    font-weight: 800;
}

.installment-print {
    margin-top: 14px;
}

.installment-print table th,
.installment-print table td {
    font-size: 9px;
    padding: 7px;
}

.invoice-signatures {
    display: flex;
    gap: 12px;
    margin-top: 18px;
}

.sign-box {
    flex: 1;
    height: 75px;
    border: 1px dashed #aaa;
    border-radius: 6px;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 8px;
    position: relative;
    font-size: 9px;
    color: #555;
}

.sign-box img {
    position: absolute;
    max-width: 100px;
    max-height: 48px;
    object-fit: contain;
    bottom: 4px;
}

.bank-details {
    display: flex;
    flex-wrap: wrap;
    gap: 10px 18px;
    padding: 10px 12px;
    border: 1px solid #ddd;
    border-radius: 6px;
    margin-top: 14px;
    font-size: 9px;
}

.bank-details b {
    color: var(--invoice-color);
}

.invoice-footer {
    display: flex;
    justify-content: space-between;
    border-top: 1px solid #ddd;
    margin-top: 16px;
    padding-top: 8px;
    color: #666;
    font-size: 8px;
}

.invoice-footer small {
    color: #777;
}

.payment-stamp {
    position: absolute;
    z-index: 2;
    left: 20px;
    top: 100%;
    width: 115px;
    height: 115px;
    object-fit: contain;
    opacity: .75;
    transform: translateY(-50%) rotate(-12deg);
    pointer-events: none;
}

.text-stamp {
    position: absolute;
    z-index: 2;
    left: 28px;
    top: 210px;
    border: 3px double #9c2639;
    color: #9c2639;
    padding: 9px 14px;
    font-size: 17px;
    font-weight: 800;
    transform: rotate(-14deg);
    opacity: .75;
}

.public-page {
    background: #eee;
}

.public-toolbar {
    max-width: 794px;
    margin: 15px auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.public-toolbar span {
    font-size: 12px;
    color: #555;
}

@media (max-width: 900px) {
    .sidebar {
        width: 205px;
    }

    .content {
        padding: 22px;
    }

    .stats {
        grid-template-columns: repeat(2, 1fr);
    }

    .two-col {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 650px) {
    .app-shell {
        display: block;
    }

    .sidebar {
        width: 100%;
        padding: 12px;
    }

    .brand {
        padding: 0 5px 10px;
    }

    .sidebar nav {
        display: flex;
        overflow: auto;
        gap: 5px;
    }

    .sidebar nav a {
        white-space: nowrap;
        padding: 9px;
        font-size: 11px;
    }

    .side-foot {
        display: none;
    }

    .topbar {
        height: 58px;
        padding: 0 15px;
    }

    .content {
        padding: 16px 12px;
    }

    .page-heading {
        align-items: flex-start;
        flex-direction: column;
    }

    .stats {
        gap: 8px;
    }

    .stat {
        padding: 13px;
    }

    .stat b {
        font-size: 20px;
    }

    .form-grid {
        grid-template-columns: 1fr;
    }

    .wide {
        grid-column: auto;
    }

    .panel {
        padding: 15px;
    }

    .invoice-paper {
        padding: 16px 12px;
        min-height: 0;
    }

    .invoice-top {
        align-items: flex-start;
    }

    .invoice-brand h1 {
        font-size: 14px;
    }

    .invoice-logo {
        width: 48px;
        height: 48px;
    }

    .invoice-meta {
        gap: 5px;
        flex-wrap: wrap;
        justify-content: flex-end;
    }

    .invoice-meta b {
        font-size: 9px;
    }

    .parties {
        gap: 6px;
    }

    .parties section {
        padding: 8px;
    }

    .parties p {
        font-size: 8px;
    }

    .invoice-items th,
    .invoice-items td {
        padding: 7px 4px;
        font-size: 8px;
    }

    .invoice-bottom {
        grid-template-columns: 1fr;
    }

    .payment-stamp {
        left: 15px;
        top: 165px;
        width: 85px;
        height: 85px;
    }

    .invoice-signatures {
        gap: 5px;
    }

    .sign-box {
        font-size: 8px;
        height: 65px;
    }

    .bank-details {
        gap: 7px;
    }

    .public-toolbar {
        padding: 0 12px;
    }

    .actions {
        width: 100%;
    }
}

@page {
    size: A5 portrait;
    margin: 8mm;
}

@media print {
    html,
    body {
        background: #fff !important;
        margin: 0 !important;
        padding: 0 !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    .no-print,
    .public-toolbar,
    .sidebar,
    .topbar,
    .footer {
        display: none !important;
    }

    .app-shell,
    .main,
    .content {
        display: block !important;
        width: auto !important;
        margin: 0 !important;
        padding: 0 !important;
        background: #fff !important;
    }

    .invoice-paper {
        width: 100% !important;
        max-width: none !important;
        min-height: 0 !important;
        margin: 0 !important;
        padding: 0 !important;
        border: 0 !important;
        box-shadow: none !important;
        overflow: visible !important;
    }

    .invoice-content {
        z-index: 1;
    }

    .invoice-items th,
    .totals .grand {
        background: #eee !important;
    }

    .payment-stamp {
        opacity: .8;
    }

    .invoice-paper * {
        break-inside: avoid;
    }

    .installment-print,
    .bank-details,
    .invoice-signatures {
        break-inside: avoid;
    }
}

.product-picker {
    display: flex;
    gap: 9px;
    margin-bottom: 13px;
}

.product-picker select {
    min-width: 250px;
    border: 1px solid var(--line);
    border-radius: 7px;
    padding: 9px;
    background: #fff;
}

@media (max-width: 650px) {
    .product-picker {
        flex-direction: column;
    }

    .product-picker select {
        width: 100%;
        min-width: 0;
    }
}