:root {
    --bg: #f4f6f8;
    --paper: #ffffff;
    --ink: #172026;
    --muted: #65717c;
    --line: #d9e0e6;
    --accent: #1b6fb8;
    --accent-strong: #0e528c;
    --success: #157a4f;
    --danger: #b3261e;
    --soft: #eaf3fb;
    --shadow: 0 10px 30px rgba(23, 32, 38, 0.08);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
    box-sizing: border-box;
}

html {
    overflow-y: scroll;
}

body {
    margin: 0;
    color: var(--ink);
    background: var(--bg);
    line-height: 1.5;
}

a {
    color: var(--accent);
    text-decoration: none;
}

a:hover {
    color: var(--accent-strong);
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    min-height: 72px;
    padding: 12px clamp(18px, 4vw, 48px);
    background: rgba(255, 255, 255, 0.94);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(12px);
}

.topbar-right {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 14px;
    min-width: 0;
}

.brand,
.doc-brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    color: var(--ink);
    font-weight: 800;
    letter-spacing: 0;
}

.doc-brand-copy {
    display: grid;
    gap: 3px;
    min-width: 0;
}

.doc-brand-copy strong,
.doc-brand-copy span {
    overflow-wrap: anywhere;
}

.doc-brand-copy span {
    color: var(--muted);
    font-size: 13px;
    font-weight: 650;
}

.brand-logo {
    display: block;
    width: auto;
    max-width: 142px;
    max-height: 42px;
    object-fit: contain;
}

.doc-logo {
    max-width: 170px;
    max-height: 54px;
}

.brand-mark {
    display: inline-grid;
    place-items: center;
    width: 38px;
    height: 38px;
    border-radius: 8px;
    color: #fff;
    background: linear-gradient(135deg, #1b6fb8, #14936d);
    font-weight: 800;
}

.main-nav {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
    overflow: visible;
}

.main-nav a,
.nav-dropdown-trigger {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    min-height: 40px;
    padding: 0 13px;
    border: 0;
    border-radius: 8px;
    color: var(--muted);
    background: transparent;
    font: inherit;
    font-weight: 650;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
}

.main-nav a.is-active,
.main-nav a:hover,
.main-nav a:focus-visible,
.nav-dropdown-trigger.is-active,
.nav-dropdown-trigger:hover,
.nav-dropdown-trigger:focus-visible,
.nav-dropdown[open] > .nav-dropdown-trigger,
.nav-dropdown:focus-within > .nav-dropdown-trigger {
    color: var(--accent-strong);
    background: var(--soft);
}

.nav-dropdown,
.user-menu {
    position: relative;
}

.nav-dropdown summary,
.user-menu summary {
    list-style: none;
}

.nav-dropdown summary::-webkit-details-marker,
.user-menu summary::-webkit-details-marker {
    display: none;
}

.dropdown-caret {
    font-size: 11px;
    line-height: 1;
}

.nav-dropdown-menu {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    z-index: 30;
    display: none;
    min-width: 168px;
    padding: 6px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    box-shadow: 0 18px 45px rgba(16, 24, 40, 0.16);
}

.nav-dropdown[open] > .nav-dropdown-menu,
.nav-dropdown:hover > .nav-dropdown-menu,
.nav-dropdown:focus-within > .nav-dropdown-menu,
.user-menu[open] > .nav-dropdown-menu,
.user-menu:hover > .nav-dropdown-menu,
.user-menu:focus-within > .nav-dropdown-menu {
    display: grid;
    gap: 2px;
}

.nav-dropdown-menu a,
.dropdown-submit {
    display: flex;
    align-items: center;
    width: 100%;
    min-height: 36px;
    padding: 0 10px;
    border: 0;
    border-radius: 6px;
    color: var(--muted);
    background: transparent;
    font: inherit;
    font-size: 13px;
    font-weight: 700;
    text-align: left;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
}

.nav-dropdown-menu a.is-active,
.nav-dropdown-menu a:hover,
.nav-dropdown-menu a:focus-visible,
.dropdown-submit:hover,
.dropdown-submit:focus-visible {
    color: var(--accent-strong);
    background: var(--soft);
}

.user-menu {
    display: flex;
    align-items: center;
    padding-left: 14px;
    border-left: 1px solid var(--line);
    white-space: nowrap;
}

.user-menu-trigger {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    min-height: 36px;
    padding: 0 10px;
    border-radius: 8px;
    color: var(--muted);
    font: inherit;
    font-size: 13px;
    font-weight: 750;
    cursor: pointer;
}

.user-menu-trigger.is-active,
.user-menu-trigger:hover,
.user-menu-trigger:focus-visible,
.user-menu[open] > .user-menu-trigger,
.user-menu:focus-within > .user-menu-trigger {
    color: var(--accent-strong);
    background: var(--soft);
}

.user-dropdown-menu {
    right: 0;
    left: auto;
    min-width: 176px;
}

.topbar-button {
    min-height: 34px;
    padding: 0 11px;
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--ink);
    background: #fff;
    font: inherit;
    font-size: 13px;
    font-weight: 750;
    cursor: pointer;
}

.topbar-button:hover {
    color: var(--accent-strong);
    border-color: #b7c6d2;
}

.page-shell {
    width: min(1240px, calc(100% - 32px));
    margin: 0 auto;
    padding: 34px 0 64px;
}

.page-heading,
.section-title,
.panel-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
}

.page-heading {
    margin-bottom: 24px;
}

.page-heading h1,
.panel-title h2,
.section-title h2 {
    margin: 0;
}

.page-heading h1 {
    font-size: 34px;
    line-height: 1.1;
}

.eyebrow {
    margin: 0 0 6px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.actions,
.form-actions,
.row-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    flex-wrap: wrap;
}

.button,
button.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 42px;
    padding: 0 16px;
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--ink);
    background: #fff;
    font: inherit;
    font-weight: 750;
    cursor: pointer;
}

.button:hover {
    border-color: #b7c6d2;
    color: var(--accent-strong);
}

.button.primary {
    color: #fff;
    border-color: var(--accent);
    background: var(--accent);
}

.button.primary:hover {
    color: #fff;
    border-color: var(--accent-strong);
    background: var(--accent-strong);
}

.button.danger {
    color: var(--danger);
    border-color: #efb4af;
    background: #fff5f4;
}

.button.danger:hover {
    color: #fff;
    border-color: var(--danger);
    background: var(--danger);
}

.icon-button {
    display: inline-grid;
    place-items: center;
    width: 34px;
    height: 34px;
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--muted);
    background: #fff;
    font: inherit;
    font-weight: 800;
    cursor: pointer;
}

.icon-button:hover {
    color: var(--accent-strong);
    border-color: #b7c6d2;
}

.icon-button.danger:hover {
    color: var(--danger);
    border-color: #efb4af;
}

.flash {
    margin-bottom: 18px;
    padding: 14px 16px;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: #fff;
    box-shadow: var(--shadow);
}

.flash-success {
    color: var(--success);
    border-color: #b7dfce;
    background: #f1fbf6;
}

.flash-error {
    color: var(--danger);
    border-color: #efb4af;
    background: #fff5f4;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 24px;
}

.stat-card,
.panel,
.content-block,
.empty-state,
.print-sheet {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--paper);
    box-shadow: var(--shadow);
}

.stat-card {
    display: block;
    padding: 20px;
    color: var(--ink);
}

.stat-card span {
    display: block;
    font-size: 34px;
    font-weight: 850;
    line-height: 1;
}

.stat-card strong {
    display: block;
    margin-top: 8px;
    color: var(--muted);
}

.content-block,
.panel {
    padding: 20px;
}

.empty-state {
    padding: 34px;
    text-align: center;
}

.empty-state h1,
.empty-state h2 {
    margin: 0 0 8px;
}

.empty-state p {
    margin: 0 auto 16px;
    max-width: 520px;
    color: var(--muted);
}

.empty-state pre {
    white-space: pre-wrap;
    text-align: left;
    background: #f7f9fb;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 14px;
}

.split-layout {
    display: grid;
    grid-template-columns: minmax(320px, 0.85fr) minmax(0, 1.15fr);
    gap: 18px;
    align-items: start;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
}

.form-grid .panel-title,
.form-grid .form-actions,
.span-2 {
    grid-column: 1 / -1;
}

.field {
    display: grid;
    gap: 7px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 750;
}

.checkbox-field {
    display: flex;
    align-items: center;
    align-self: end;
    min-height: 42px;
    padding: 0 0 4px;
}

.checkbox-field input {
    width: 18px;
    min-height: 18px;
}

input,
select,
textarea {
    width: 100%;
    min-height: 42px;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--ink);
    background: #fff;
    font: inherit;
    font-size: 15px;
}

textarea {
    min-height: 86px;
    resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
    outline: 3px solid rgba(27, 111, 184, 0.16);
    border-color: var(--accent);
}

.table-wrap {
    overflow-x: auto;
}

.table-wrap.compact {
    max-height: 620px;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th,
td {
    padding: 12px 10px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: top;
}

th {
    color: var(--muted);
    font-size: 12px;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

td small {
    display: block;
    margin-top: 3px;
    color: var(--muted);
}

.num {
    text-align: right;
    white-space: nowrap;
}

.pill {
    display: inline-flex;
    align-items: center;
    min-height: 26px;
    padding: 0 9px;
    border-radius: 999px;
    color: var(--accent-strong);
    background: var(--soft);
    font-size: 12px;
    font-weight: 800;
    white-space: nowrap;
}

.inline-form {
    display: inline-flex;
    margin: 0;
}

.tabs {
    display: flex;
    gap: 6px;
    margin-bottom: 16px;
    border-bottom: 1px solid var(--line);
}

.tabs a {
    padding: 10px 12px;
    color: var(--muted);
    border-bottom: 3px solid transparent;
    font-weight: 750;
}

.tabs a.is-active {
    color: var(--accent-strong);
    border-color: var(--accent);
}

.document-form {
    display: grid;
    gap: 18px;
}

.document-form + .document-form {
    margin-top: 24px;
}

.document-meta {
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

.line-editor .panel-title {
    margin-bottom: 14px;
}

.lines th:nth-child(1) {
    width: 210px;
}

.lines th:nth-child(3),
.lines th:nth-child(4),
.lines th:nth-child(5),
.lines th:nth-child(6) {
    width: 110px;
}

.lines th:nth-child(8) {
    width: 48px;
}

.line-row textarea {
    min-width: 260px;
    height: 140px;
    min-height: 100px;
}

.document-bottom {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 360px;
    gap: 18px;
    align-items: start;
}

.totals-box dl,
.print-summary dl,
.document-facts {
    margin: 0;
}

.totals-box dl div,
.print-summary dl div,
.document-facts div {
    display: flex;
    justify-content: space-between;
    gap: 18px;
    padding: 8px 0;
    border-bottom: 1px solid var(--line);
}

.totals-box dt,
.print-summary dt,
.document-facts dt {
    color: var(--muted);
    font-weight: 750;
}

.totals-box dd,
.print-summary dd,
.document-facts dd {
    margin: 0;
    text-align: right;
    font-weight: 800;
}

.totals-box .grand,
.print-summary .grand {
    padding-top: 14px;
    border-bottom: 0;
    font-size: 20px;
}

.print-sheet {
    max-width: 920px;
    margin: 0 auto;
    padding: 54px;
}

.document-head,
.document-addresses {
    display: flex;
    justify-content: space-between;
    gap: 32px;
}

.document-head {
    align-items: flex-start;
    margin-bottom: 54px;
}

.doc-title {
    text-align: right;
}

.doc-title h2 {
    margin: 0;
    font-size: 34px;
}

.doc-title p {
    margin: 6px 0 0;
    color: var(--muted);
    font-weight: 800;
}

.document-addresses {
    align-items: flex-start;
    margin-bottom: 34px;
}

.address-stack {
    width: min(430px, 100%);
}

.sender-address {
    margin-bottom: 18px;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--line);
}

.sender-address address {
    color: var(--muted);
    font-size: 13px;
}

.sender-address p {
    margin: 6px 0 0;
    color: var(--muted);
    font-size: 13px;
}

address {
    margin-top: 8px;
    font-style: normal;
    white-space: pre-line;
}

.label {
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.document-facts {
    min-width: 280px;
}

.document-text,
.document-notes {
    margin: 26px 0;
}

.print-lines {
    margin-top: 24px;
}

.print-summary {
    display: flex;
    justify-content: flex-end;
    margin-top: 24px;
}

.print-summary dl {
    width: min(390px, 100%);
}

.print-sheet.rbapps-document {
    display: flex;
    flex-direction: column;
    width: 210mm;
    min-height: 297mm;
    max-width: none;
    margin: 0 auto;
    padding: 15mm 20mm 10mm 22mm;
    color: #050505;
    background: #fff;
    font-family: Arial, Helvetica, sans-serif;
    font-size: 9.5pt;
    line-height: 1.28;
    print-color-adjust: exact;
    -webkit-print-color-adjust: exact;
}

.rbapps-doc-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 24mm;
    margin-bottom: 14mm;
}

.rbapps-logo-wrap {
    min-width: 58mm;
}

.rbapps-template-logo {
    display: block;
    width: 44mm;
    max-width: 44mm;
    height: auto;
}

.rbapps-document-claim {
    margin: 3mm 0 0;
    color: #bdbdbd;
    font-size: 16pt;
    font-weight: 300;
    line-height: 1;
    white-space: nowrap;
}

.rbapps-document-body {
    flex: 1 0 auto;
}

.rbapps-address-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 62mm;
    gap: 10mm;
    align-items: start;
    margin-bottom: 12mm;
}

.rbapps-sender-line {
    width: 97mm;
    margin: 0 0 3.5mm;
    padding-bottom: 1.4mm;
    border-bottom: 0.4pt solid #555;
    font-size: 6.5pt;
    line-height: 1.15;
}

.rbapps-recipient {
    margin: 0;
    font-size: 10pt;
    line-height: 1.45;
    white-space: normal;
}

.rbapps-recipient strong,
.rbapps-recipient b {
    font-weight: 700;
}

.rbapps-document-meta {
    display: grid;
    grid-template-columns: max-content 1fr;
    column-gap: 12mm;
    row-gap: 2mm;
    margin: 15mm 0 0;
}

.rbapps-document-meta div {
    display: contents;
}

.rbapps-document-meta dt,
.rbapps-document-meta dd {
    margin: 0;
    font-size: 9.5pt;
    line-height: 1.2;
}

.rbapps-document-meta dt {
    font-weight: 400;
}

.rbapps-document-meta dd {
    text-align: right;
}

.rbapps-document-meta .is-primary dt,
.rbapps-document-meta .is-primary dd {
    font-weight: 700;
}

.rbapps-intro {
    margin-bottom: 4mm;
}

.rbapps-intro h2 {
    margin: 0 0 3mm;
    font-size: 11.5pt;
    line-height: 1.2;
}

.rbapps-intro p {
    margin: 0;
    font-size: 9.5pt;
    line-height: 1.12;
}

.rbapps-lines {
    width: 100%;
    margin-top: 2.5mm;
    border-collapse: collapse;
    table-layout: fixed;
}

.rbapps-col-pos {
    width: 8%;
}

.rbapps-col-desc {
    width: 42%;
}

.rbapps-col-qty {
    width: 15%;
}

.rbapps-col-price {
    width: 14%;
}

.rbapps-col-tax {
    width: 10%;
}

.rbapps-col-total {
    width: 11%;
}

.rbapps-lines th,
.rbapps-lines td {
    border-bottom: 0;
    padding: 2.2mm 1.4mm;
    color: #050505;
    font-size: 9.5pt;
    letter-spacing: 0;
    text-transform: none;
    vertical-align: top;
}

.rbapps-lines thead th {
    color: #444;
    background: #dedede;
    font-size: 9.5pt;
    font-weight: 400;
    print-color-adjust: exact;
    -webkit-print-color-adjust: exact;
}

.rbapps-lines tbody td {
    padding: 2mm 1.4mm 1.1mm;
}

.rbapps-lines td strong {
    font-weight: 700;
}

.rbapps-lines td p {
    margin: 2mm 0 0;
    line-height: 1.18;
}

.rbapps-totals-area {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 86mm;
    gap: 12mm;
    margin-top: 3mm;
    padding-top: 3mm;
    border-top: 0.4pt solid #555;
}

.rbapps-payment-note {
    align-self: end;
    padding-top: 16mm;
    font-size: 9.5pt;
}

.rbapps-summary {
    margin: 0;
}

.rbapps-summary div {
    display: grid;
    grid-template-columns: 1fr 28mm;
    gap: 4mm;
    align-items: baseline;
    padding: 1.5mm 0;
}

.rbapps-summary dt,
.rbapps-summary dd {
    margin: 0;
    font-size: 9.5pt;
    line-height: 1.15;
}

.rbapps-summary dt {
    text-align: right;
}

.rbapps-summary dd {
    text-align: right;
    white-space: nowrap;
}

.rbapps-summary .grand {
    margin-top: 3mm;
    padding-top: 2.5mm;
    padding-bottom: 2.5mm;
    border-top: 0.4pt solid #555;
    border-bottom: 1.2pt double #555;
    font-weight: 700;
}

.rbapps-footer {
    flex: 0 0 auto;
    margin-top: auto;
    padding-top: 2mm;
    border-top: 0.4pt solid #999;
    color: #666;
    text-align: center;
    font-size: 8pt;
    line-height: 1.35;
}

.rbapps-footer p {
    margin: 0;
}

.auth-page {
    min-height: 100vh;
    background:
        linear-gradient(135deg, rgba(27, 111, 184, 0.12), rgba(20, 147, 109, 0.1)),
        var(--bg);
}

.auth-shell {
    display: grid;
    place-items: center;
    min-height: 100vh;
    padding: 24px;
}

.auth-panel {
    width: min(460px, 100%);
    padding: 32px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--paper);
    box-shadow: var(--shadow);
}

.auth-brand {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 26px;
}

.auth-logo {
    display: block;
    width: auto;
    max-width: 190px;
    max-height: 58px;
    object-fit: contain;
}

.auth-copy {
    margin-bottom: 20px;
}

.auth-copy h1 {
    margin: 0;
    font-size: 28px;
    line-height: 1.12;
}

.auth-form {
    display: grid;
    gap: 14px;
}

@media (max-width: 980px) {
    .topbar,
    .page-heading,
    .document-head,
    .document-addresses {
        align-items: flex-start;
        flex-direction: column;
    }

    .topbar-right {
        align-items: flex-start;
        flex-direction: column;
        width: 100%;
    }

    .user-menu {
        padding-left: 0;
        border-left: 0;
    }

    .split-layout,
    .document-bottom {
        grid-template-columns: 1fr;
    }

    .stats-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .document-meta {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .doc-title {
        text-align: left;
    }
}

@media (max-width: 620px) {
    .page-shell {
        width: min(100% - 20px, 1240px);
        padding-top: 20px;
    }

    .page-heading h1 {
        font-size: 28px;
    }

    .stats-grid,
    .form-grid,
    .document-meta {
        grid-template-columns: 1fr;
    }

    .span-2,
    .form-grid .panel-title,
    .form-grid .form-actions {
        grid-column: auto;
    }

    .content-block,
    .panel,
    .print-sheet {
        padding: 16px;
    }

    .auth-panel {
        padding: 22px;
    }

    .actions {
        width: 100%;
        justify-content: flex-start;
    }

    .button {
        flex: 1 1 auto;
    }
}

@page {
    size: A4;
    margin: 0;
}

@media print {
    body {
        background: #fff;
    }

    .topbar,
    .no-print,
    .flash {
        display: none !important;
    }

    .page-shell {
        width: 100%;
        padding: 0;
    }

    .print-sheet {
        width: 100%;
        max-width: none;
        min-height: auto;
        border: 0;
        border-radius: 0;
        box-shadow: none;
        padding: 16mm;
    }

    .print-sheet.rbapps-document {
        width: 210mm;
        min-height: 297mm;
        padding: 15mm 20mm 10mm 22mm;
    }

    a {
        color: inherit;
    }
}
