:root {
    --ink: #111927;
    --navy: #151b2f;
    --navy-2: #202944;
    --petrol: #0f4f4b;
    --petrol-2: #0b3f3c;
    --gold: #d9a441;
    --gold-2: #f1c56a;
    --paper: #f6f7f4;
    --line: #e4e1d8;
    --muted: #6d7480;
    --white: #ffffff;
    --green: #18815f;
    --red: #b64242;
    --blue: #2d67b1;
    font-family: "Inter", "Segoe UI", Arial, sans-serif;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    color: var(--ink);
    background: var(--paper);
}

a {
    color: inherit;
    text-decoration: none;
}

.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 270px;
    padding: 28px 22px;
    color: var(--white);
    background: linear-gradient(180deg, var(--navy), #0e1322);
}

.brand {
    display: flex;
    gap: 14px;
    align-items: center;
    margin-bottom: 34px;
}

.brand-mark {
    display: grid;
    width: 48px;
    height: 48px;
    place-items: center;
    border: 1px solid rgba(255, 255, 255, .22);
    background: var(--gold);
    color: var(--navy);
    font-weight: 800;
}

.brand strong,
.brand small {
    display: block;
}

.brand small,
.sidebar-foot small {
    color: rgba(255, 255, 255, .62);
}

nav {
    display: grid;
    gap: 8px;
}

nav a {
    padding: 12px 14px;
    border-radius: 6px;
    color: rgba(255, 255, 255, .76);
}

nav a.active,
nav a:hover {
    background: rgba(217, 164, 65, .16);
    color: var(--white);
}

.sidebar-foot {
    position: absolute;
    right: 22px;
    bottom: 26px;
    left: 22px;
    padding-top: 18px;
    border-top: 1px solid rgba(255, 255, 255, .14);
}

.main {
    margin-left: 270px;
    padding: 34px;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    margin-bottom: 24px;
}

h1,
h2 {
    margin: 0;
    letter-spacing: 0;
}

h1 {
    font-size: 34px;
    line-height: 1.12;
}

h2 {
    font-size: 20px;
}

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

.muted {
    color: var(--muted);
}

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

.button-primary {
    border-color: var(--petrol);
    background: var(--petrol);
    color: var(--white);
}

a.button-primary,
button.button-primary {
    color: var(--white);
}

.button-primary:hover {
    border-color: var(--petrol-2);
    background: var(--petrol-2);
}

.table-action {
    display: inline-flex;
    min-height: 30px;
    align-items: center;
    justify-content: center;
    padding: 0 10px;
    border: 1px solid var(--petrol);
    border-radius: 6px;
    background: var(--petrol);
    color: var(--white);
    font-size: 12px;
    font-weight: 800;
    white-space: nowrap;
}

.as-button {
    color: var(--white);
    font: inherit;
    cursor: pointer;
}

.table-action:hover {
    border-color: var(--petrol-2);
    background: var(--petrol-2);
    color: var(--white);
}

.actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.actions form {
    margin: 0;
}

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

.metric,
.panel,
.module-hero,
.login-panel {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--white);
    box-shadow: 0 18px 50px rgba(17, 25, 39, .06);
}

.metric {
    padding: 22px;
}

.metric span,
table small {
    display: block;
    color: var(--muted);
    font-size: 12px;
}

.metric strong {
    display: block;
    margin-top: 10px;
    font-size: 28px;
}

.grid {
    display: grid;
    gap: 18px;
}

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

.form-list {
    grid-template-columns: 360px minmax(0, 1fr);
    align-items: start;
}

.form-list.wide-form {
    grid-template-columns: 520px minmax(0, 1fr);
}

.editor-panel {
    width: 100%;
}

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

.wide-field,
.items-box,
.form-actions {
    grid-column: 1 / -1;
}

.form-actions {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}

.items-box {
    display: grid;
    gap: 8px;
}

.item-grid {
    display: grid;
    grid-template-columns: minmax(180px, 1fr) 82px 110px 82px 34px;
    gap: 8px;
}

.item-grid-head {
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
}

.item-grid input {
    min-height: 38px;
    padding: 8px 10px;
}

.items-list {
    display: grid;
    gap: 8px;
}

.icon-button {
    width: 34px;
    min-height: 38px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--white);
    color: var(--red);
    font-weight: 900;
    cursor: pointer;
}

.panel {
    overflow: hidden;
    padding: 22px;
}

.panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 16px;
}

.panel-head a:not(.button),
.panel-head span {
    color: var(--gold);
    font-weight: 800;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

th {
    color: var(--muted);
    font-size: 12px;
    text-align: left;
    text-transform: uppercase;
}

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

tbody tr:hover {
    background: #fbfaf6;
}

.stack {
    display: grid;
    gap: 14px;
}

label {
    display: grid;
    gap: 7px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
}

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

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

.badge {
    display: inline-flex;
    min-height: 28px;
    align-items: center;
    padding: 0 10px;
    border-radius: 999px;
    background: #eceff4;
    color: var(--ink);
    font-size: 12px;
    font-weight: 800;
    white-space: nowrap;
}

.badge-active,
.badge-paid,
.badge-accepted {
    background: rgba(24, 129, 95, .12);
    color: var(--green);
}

.badge-open,
.badge-sent,
.badge-trial {
    background: rgba(217, 164, 65, .18);
    color: #9a6d12;
}

.badge-overdue,
.badge-past_due,
.badge-cancelled {
    background: rgba(182, 66, 66, .12);
    color: var(--red);
}

.badge-paused,
.badge-draft {
    background: rgba(45, 103, 177, .12);
    color: var(--blue);
}

.module-hero {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 18px;
    padding: 26px;
    background: linear-gradient(135deg, var(--navy), var(--navy-2));
    color: var(--white);
}

.module-hero p {
    max-width: 780px;
    margin: 8px 0 0;
    color: rgba(255, 255, 255, .72);
}

.module-hero strong {
    color: var(--gold-2);
    font-size: 24px;
    white-space: nowrap;
}

.alert {
    margin-bottom: 18px;
    padding: 13px 16px;
    border: 1px solid rgba(217, 164, 65, .45);
    border-radius: 6px;
    background: #fff7e4;
    color: #7a5514;
    font-weight: 700;
}

.login-body {
    display: grid;
    min-height: 100vh;
    place-items: center;
    background: linear-gradient(135deg, var(--navy), #0e1322);
}

.login-shell {
    width: min(440px, calc(100vw - 32px));
}

.login-panel {
    padding: 34px;
}

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

.logo-upload,
.settings-form label:nth-last-child(-n+3),
.settings-form .button {
    grid-column: 1 / -1;
}

.logo-upload {
    display: grid;
    grid-template-columns: 220px minmax(0, 1fr);
    gap: 18px;
    align-items: center;
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fffdf9;
}

.settings-logo {
    display: block;
    max-width: 220px;
    max-height: 90px;
    object-fit: contain;
}

.number-preview {
    display: grid;
    gap: 14px;
    margin: 18px 0;
}

.number-preview div {
    padding: 18px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fffdf9;
}

.number-preview span {
    display: block;
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
}

.number-preview strong {
    display: block;
    margin-top: 8px;
    font-size: 24px;
}

.document-body {
    background: #dfe3ea;
    padding: 28px;
}

.print-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    width: min(900px, 100%);
    margin: 0 auto 18px;
}

.document-page {
    width: min(900px, 100%);
    min-height: 1180px;
    margin: 0 auto;
    padding: 56px;
    background: var(--white);
    box-shadow: 0 24px 70px rgba(17, 25, 39, .18);
}

.document-head,
.document-addresses,
.document-meta,
.totals,
.bank-footer {
    display: flex;
    justify-content: space-between;
    gap: 28px;
}

.document-head {
    align-items: flex-start;
    justify-content: flex-end;
    padding-bottom: 34px;
    border-bottom: 3px solid var(--gold);
}

.document-head .brand-mark {
    margin-bottom: 14px;
}

.document-logo {
    display: block;
    max-width: 300px;
    max-height: 95px;
    margin-bottom: 18px;
    object-fit: contain;
    object-position: right center;
}

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

.document-title strong {
    display: block;
    color: var(--navy);
    font-size: 30px;
}

.document-addresses {
    margin: 42px 0;
}

.document-addresses div,
.document-meta div {
    display: grid;
    gap: 4px;
}

.document-addresses small,
.document-meta span {
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
}

.document-meta {
    justify-content: flex-start;
    margin-bottom: 38px;
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fffdf9;
}

.document-table {
    margin-top: 22px;
}

.document-table th,
.document-table td {
    padding-top: 12px;
    padding-bottom: 12px;
}

.document-table th:last-child,
.document-table td:last-child {
    text-align: right;
}

.totals {
    align-items: flex-end;
    flex-direction: column;
    margin: 24px 0;
}

.totals div {
    display: flex;
    width: 320px;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid var(--line);
}

.totals .grand-total {
    color: var(--navy);
    font-size: 20px;
    font-weight: 900;
}

.document-footer {
    margin-top: 50px;
    color: var(--muted);
    line-height: 1.6;
}

.tax-note {
    margin-top: 18px;
    padding: 12px 14px;
    border-left: 4px solid var(--gold);
    background: #fff7e4;
    color: var(--ink);
    font-weight: 800;
}

.quote-closing {
    color: var(--ink);
}

.invoice-footer {
    color: var(--ink);
    font-weight: 400;
}

.invoice-footer strong {
    font-weight: 800;
}

.bank-footer {
    margin-top: 70px;
    padding-top: 18px;
    border-top: 1px solid var(--line);
    color: var(--muted);
    font-size: 12px;
    flex-wrap: wrap;
}

@media print {
    body {
        background: var(--white);
    }

    .print-actions {
        display: none;
    }

    .document-body {
        padding: 0;
    }

    .document-page {
        width: 100%;
        min-height: auto;
        padding: 0;
        box-shadow: none;
    }
}

@media (max-width: 1100px) {
    .stats-grid,
    .grid.two,
    .form-list,
    .form-list.wide-form,
    .editor-form,
    .settings-form {
        grid-template-columns: 1fr;
    }

    .wide-field,
    .items-box,
    .form-actions {
        grid-column: auto;
    }

    .settings-form label:nth-last-child(-n+3),
    .settings-form .button {
        grid-column: auto;
    }

    .logo-upload {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 760px) {
    .sidebar {
        position: static;
        width: auto;
    }

    .sidebar-foot {
        position: static;
        margin-top: 24px;
    }

    .main {
        margin-left: 0;
        padding: 22px 16px;
    }

    .topbar,
    .module-hero,
    .document-head,
    .document-addresses,
    .document-meta {
        align-items: flex-start;
        flex-direction: column;
    }

    .document-body {
        padding: 12px;
    }

    .document-page {
        padding: 24px;
    }

    table {
        display: block;
        overflow-x: auto;
        white-space: nowrap;
    }

    .item-grid {
        grid-template-columns: 1fr 72px 72px;
    }

    .item-grid-head {
        display: none;
    }
}
