:root {
    --tvl-purple: #79257f;
    --tvl-purple-dark: #6f2379;
    --tvl-purple-muted: #82488e;
    --tvl-purple-soft: #eaddea;
    --tvl-accent: #1eb5cb;
    --tvl-cream: #f8deb3;
    --tvl-text: #252033;
    --tvl-text-muted: #604a66;
    --tvl-accent-red: #ff4d61;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html, body {
    font-family: Arial, Helvetica, sans-serif;
    background: #ffffff;
    color: var(--tvl-text);
}

h1:focus {
    outline: none;
}

a, .btn-link {
    color: var(--tvl-purple-dark);
}

.btn:focus, .btn:active:focus, .btn-link.nav-link:focus, .form-control:focus, .form-check-input:focus {
    box-shadow: 0 0 0 0.1rem white, 0 0 0 0.25rem rgba(30, 181, 203, 0.45);
}

.valid.modified:not([type=checkbox]) {
    outline: 1px solid #26b050;
}

.invalid {
    outline: 1px solid red;
}

.validation-message {
    color: red;
}

#blazor-error-ui {
    color-scheme: light only;
    background: lightyellow;
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
    box-sizing: border-box;
    display: none;
    left: 0;
    padding: 0.6rem 1.25rem 0.7rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
}

#blazor-error-ui .dismiss {
    cursor: pointer;
    position: absolute;
    right: 0.75rem;
    top: 0.5rem;
}

.blazor-error-boundary {
    background: #b32121;
    padding: 1rem;
    color: white;
}

.blazor-error-boundary::after {
    content: "An error has occurred.";
}

.loading-progress {
    position: relative;
    display: block;
    width: 8rem;
    height: 8rem;
    margin: 20vh auto 1rem auto;
}

.loading-progress circle {
    fill: none;
    stroke: #e0e0e0;
    stroke-width: 0.6rem;
    transform-origin: 50% 50%;
    transform: rotate(-90deg);
}

.loading-progress circle:last-child {
    stroke: var(--tvl-accent);
    stroke-dasharray: calc(3.141 * var(--blazor-load-percentage, 0%) * 0.8), 500%;
    transition: stroke-dasharray 0.05s ease-in-out;
}

.loading-progress-text {
    position: absolute;
    text-align: center;
    font-weight: bold;
    inset: calc(20vh + 3.25rem) 0 auto 0.2rem;
}

.loading-progress-text::after {
    content: var(--blazor-load-percentage-text, "Loading");
}

code {
    color: var(--tvl-purple-dark);
}

.portal-header {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    padding: 1.5rem 0 1rem;
}

.eyebrow {
    margin: 0 0 0.35rem;
    color: var(--tvl-purple-muted);
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
}

.portal-header h1 {
    margin: 0;
    color: var(--tvl-purple-dark);
    font-size: clamp(2rem, 6vw, 3.25rem);
    font-weight: 750;
    letter-spacing: 0;
}

.summary {
    max-width: 42rem;
    margin: 0.75rem 0 0;
    color: var(--tvl-text-muted);
    font-size: 1rem;
    line-height: 1.55;
}

.workflow-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr));
    gap: 1rem;
    margin: 1rem 0;
}

.workflow-card,
.settings-panel {
    border: 1px solid rgba(121, 37, 127, 0.18);
    border-radius: 8px;
    background: var(--tvl-purple-soft);
    box-shadow: 0 2px 8px rgba(66, 25, 72, 0.12);
}

.workflow-card {
    color: var(--tvl-text);
}

.workflow-card {
    min-height: 12rem;
    padding: 1.25rem;
}

.workflow-icon {
    width: 2.25rem;
    height: 2.25rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    background: var(--tvl-accent);
    color: #ffffff;
    font-weight: 700;
    font-size: 0.85rem;
}

.workflow-card h2,
.settings-panel h2 {
    margin: 1rem 0 0.45rem;
    color: var(--tvl-purple-dark);
    font-size: 1.05rem;
    font-weight: 700;
}

.workflow-card p {
    margin: 0;
    color: var(--tvl-text-muted);
    line-height: 1.5;
}

.settings-panel {
    margin-top: 1rem;
    padding: 1.25rem;
}

.settings-panel h2 {
    margin-top: 0;
}

.settings-panel dl {
    display: grid;
    gap: 0.85rem;
    margin: 0;
}

.settings-panel dl div {
    display: grid;
    grid-template-columns: minmax(8rem, 12rem) minmax(0, 1fr);
    gap: 1rem;
    padding-top: 0.85rem;
    border-top: 1px solid rgba(121, 37, 127, 0.12);
}

.settings-panel dt {
    color: var(--tvl-purple-muted);
    font-weight: 700;
}

.settings-panel dd {
    margin: 0;
    color: var(--tvl-text);
    overflow-wrap: anywhere;
}

.login-shell {
    min-height: calc(100vh - 2rem);
    display: grid;
    align-items: center;
    padding: 2rem 1rem;
    background: #ffffff;
}

.login-panel {
    width: min(100%, 28rem);
    margin: 0 auto;
    padding: 2rem;
    border: 1px solid rgba(121, 37, 127, 0.18);
    border-radius: 8px;
    background: #ffffff;
    box-shadow: 0 10px 30px rgba(66, 25, 72, 0.14);
}

.login-panel h1 {
    margin: 0 0 1.5rem;
    color: var(--tvl-purple-dark);
    font-size: 2rem;
    letter-spacing: 0;
}

.login-form {
    display: grid;
    gap: 1rem;
}

.form-field {
    display: grid;
    gap: 0.4rem;
}

.form-field label {
    color: var(--tvl-text);
    font-weight: 700;
}

.form-control {
    width: 100%;
    min-height: 2.75rem;
    box-sizing: border-box;
    border: 1px solid rgba(96, 74, 102, 0.4);
    border-radius: 6px;
    padding: 0.65rem 0.75rem;
    color: var(--tvl-text);
    font: inherit;
}

.primary-button {
    min-height: 2.75rem;
    border: 0;
    border-radius: 6px;
    background: var(--tvl-purple-dark);
    color: #ffffff;
    font-weight: 700;
    cursor: pointer;
}

.primary-button:disabled {
    cursor: default;
    opacity: 0.7;
}

.login-error {
    margin: 0;
    color: #9f1d2d;
    font-weight: 700;
}

@media (max-width: 520px) {
    .settings-panel dl div {
        grid-template-columns: 1fr;
        gap: 0.2rem;
    }
}

.workflow-action {
    border: 0;
    text-decoration: none;
    font-size: 1.35rem;
    line-height: 1;
}

.workflow-action:hover,
.workflow-action:focus {
    background: var(--tvl-purple-dark);
    color: #ffffff;
}

.workflow-card-link {
    display: block;
    color: inherit;
    text-decoration: none;
}

.workflow-card-link:hover h2,
.workflow-card-link:focus h2 {
    color: var(--tvl-accent);
    text-decoration: underline;
}

.form-panel {
    max-width: 42rem;
    padding: 1.5rem;
    border: 1px solid rgba(121, 37, 127, 0.18);
    border-radius: 8px;
    background: #ffffff;
    box-shadow: 0 2px 8px rgba(66, 25, 72, 0.12);
}

.form-panel h2 {
    margin: 0 0 1.25rem;
    color: var(--tvl-purple-dark);
    font-size: 1.2rem;
}

.form-panel form {
    display: grid;
    gap: 1rem;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1rem;
}

@media (max-width: 640px) {
    .form-row { grid-template-columns: 1fr; }
}

/* Billing workspace */
.billing-header {
    align-items: flex-end;
    display: flex;
    justify-content: space-between;
    gap: 1.5rem;
}

.billing-header .primary-link {
    flex: 0 0 auto;
    margin-bottom: .25rem;
}

.billing-workflows {
    margin-bottom: 1.25rem;
}

.metric-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(10.5rem, 1fr));
    gap: .85rem;
    margin: 1.25rem 0;
}

.metric-card {
    min-width: 0;
    padding: 1rem 1.1rem;
    border: 1px solid #ded8e8;
    border-left: 4px solid var(--tvl-purple);
    border-radius: 8px;
    background: #fff;
    box-shadow: 0 3px 12px rgba(48, 34, 68, .06);
}

.metric-card.warning {
    border-left-color: #bf6b19;
    background: #fffaf4;
}

.metric-card span,
.metric-card small {
    display: block;
    color: var(--tvl-text-muted);
}

.metric-card span {
    font-size: .78rem;
    font-weight: 800;
    letter-spacing: .04em;
    text-transform: uppercase;
}

.metric-card strong {
    display: block;
    margin: .25rem 0;
    color: var(--tvl-purple-dark);
    font-size: clamp(1.4rem, 2.5vw, 2rem);
    line-height: 1.1;
}

.table-scroll {
    width: 100%;
    overflow-x: auto;
}

.billing-table {
    width: 100%;
    min-width: 48rem;
    border-collapse: collapse;
    font-size: .9rem;
}

.billing-table th,
.billing-table td {
    padding: .8rem .7rem;
    border-bottom: 1px solid #e7e2ec;
    text-align: left;
    vertical-align: top;
}

.billing-table th {
    color: #62566e;
    background: #f7f4f9;
    font-size: .75rem;
    letter-spacing: .035em;
    text-transform: uppercase;
    white-space: nowrap;
}

.billing-table td small,
.financial-label {
    display: block;
    margin-top: .18rem;
    color: var(--tvl-text-muted);
}

.billing-table tfoot th {
    color: var(--tvl-purple-dark);
    background: #f3eff7;
    font-size: .9rem;
    text-align: right;
    text-transform: none;
}

.billing-table a {
    color: var(--tvl-purple-dark);
}

.table-actions {
    display: flex;
    gap: .8rem;
    white-space: nowrap;
}

.amount-warning {
    color: #9b4b0e;
    font-weight: 800;
}

.compact-grid {
    grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
}

.form-grid label,
.company-picker,
.confirmation-modal label {
    display: flex;
    flex-direction: column;
    gap: .35rem;
    color: #51465d;
    font-size: .82rem;
    font-weight: 750;
}

.form-grid input,
.form-grid select,
.form-grid textarea,
.company-picker select,
.confirmation-modal input,
.confirmation-modal textarea {
    width: 100%;
    min-height: 2.65rem;
    border: 1px solid #cfc6d7;
    border-radius: 6px;
    padding: .6rem .7rem;
    background: #fff;
    color: #292333;
    font: inherit;
}

.form-grid textarea,
.confirmation-modal textarea {
    min-height: 5rem;
    resize: vertical;
}

.form-grid .check-label,
.check-label {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: .5rem;
}

.check-label input {
    width: 1rem;
    min-height: 1rem;
}

.field-checkbox {
    align-self: end;
    min-height: 2.65rem;
}

.wide-field {
    grid-column: 1 / -1;
}

.filter-panel {
    margin-top: 1rem;
}

.filter-panel .form-actions,
.inline-editor .form-actions {
    margin-top: 1rem;
}

.inline-editor {
    margin: 1rem 0;
    padding: 1rem;
    border: 1px solid #d9d1e1;
    border-radius: 8px;
    background: #faf8fc;
}

.inline-editor h3 {
    margin: 0 0 1rem;
    color: var(--tvl-purple-dark);
}

.record-button {
    width: 100%;
    border: 0;
    background: transparent;
    color: inherit;
    font: inherit;
    text-align: left;
    cursor: pointer;
}

.record-button:hover,
.record-button:focus-visible {
    background: #f6f2f9;
}

.record-button > span:last-child {
    display: flex;
    align-items: center;
    gap: .6rem;
}

.status-pill {
    display: inline-flex;
    align-items: center;
    min-height: 1.55rem;
    padding: .15rem .55rem;
    border-radius: 999px;
    background: #ece7f1;
    color: #51465d;
    font-size: .72rem;
    font-weight: 800;
    line-height: 1;
}

.status-issued,
.status-settled {
    background: #e5f4ec;
    color: #17663d;
}

.status-draft {
    background: #eee8f7;
    color: #5c3583;
}

.status-void {
    background: #eeeeee;
    color: #656565;
}

.status-overdue {
    background: #fce8e3;
    color: #9b2f20;
}

.status-financial {
    background: #fff2d8;
    color: #805100;
}

.header-status {
    display: flex;
    align-items: center;
    gap: .45rem;
}

.selected-row {
    background: #f4effa;
}

.released-row {
    color: #827a88;
    background: #f8f8f8;
}

.selection-bar {
    position: sticky;
    z-index: 25;
    bottom: 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin: 1rem 0;
    padding: .85rem 1rem;
    border-radius: 8px;
    background: #30233f;
    color: #fff;
    box-shadow: 0 10px 30px rgba(37, 25, 50, .28);
}

.selection-bar strong,
.selection-bar span {
    display: block;
}

.selection-bar span {
    margin-top: .15rem;
    color: #dbcee7;
}

.success-message,
.validation-panel,
.audit-note {
    margin: 1rem 0;
    padding: .85rem 1rem;
    border-radius: 7px;
}

.success-message {
    border: 1px solid #a5d3b9;
    background: #edf9f2;
    color: #195d38;
}

.validation-panel {
    border: 1px solid #e0a8a0;
    background: #fff2ef;
    color: #842a1f;
}

.validation-panel ul {
    margin: .5rem 0 0;
    padding-left: 1.2rem;
}

.audit-note {
    background: #f5f2f7;
    color: #554a60;
}

.text-danger-button {
    border: 0;
    padding: .2rem;
    background: transparent;
    color: #a02424;
    font: inherit;
    font-weight: 750;
    cursor: pointer;
}

.text-link-button {
    display: block;
    border: 0;
    padding: .25rem 0;
    background: transparent;
    color: var(--tvl-purple);
    font: inherit;
    font-size: .82rem;
    font-weight: 750;
    text-decoration: underline;
    cursor: pointer;
}

.text-link-button:disabled {
    opacity: .55;
    cursor: wait;
}

.confirmation-modal {
    width: min(100%, 31rem);
    padding: 1.5rem;
    border-radius: 8px;
    background: #fff;
    box-shadow: 0 18px 55px rgba(37, 32, 51, .32);
}

.confirmation-modal h2 {
    margin: 0;
    color: var(--tvl-purple-dark);
}

.confirmation-modal p {
    color: var(--tvl-text-muted);
    line-height: 1.5;
}

@media (max-width: 760px) {
    .billing-header,
    .selection-bar {
        align-items: stretch;
        flex-direction: column;
    }

    .billing-header .primary-link,
    .selection-bar .primary-button {
        text-align: center;
    }

    .metric-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 460px) {
    .metric-grid {
        grid-template-columns: 1fr;
    }
}

.checkbox-field,
.form-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.checkbox-field input {
    width: 1.1rem;
    height: 1.1rem;
}

.form-actions {
    margin-top: 0.5rem;
}

.form-actions button {
    padding: 0.65rem 1rem;
}

.permission-selection {
    display: grid;
    gap: 0.75rem;
    margin: 0.25rem 0;
    padding: 1rem;
    border: 1px solid rgba(121, 37, 127, 0.2);
    border-radius: 8px;
}

.permission-selection legend {
    padding: 0 0.35rem;
    color: var(--tvl-purple-dark);
    font-weight: 700;
}

.permission-option {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    cursor: pointer;
}

.permission-option input {
    width: 1.1rem;
    height: 1.1rem;
    margin-top: 0.15rem;
}

.permission-option span,
.permission-option small {
    display: block;
}

.permission-option small {
    margin-top: 0.15rem;
    color: var(--tvl-text-muted);
    font-weight: 400;
}

.secondary-button {
    min-height: 2.75rem;
    border: 1px solid rgba(96, 74, 102, 0.4);
    border-radius: 6px;
    background: #ffffff;
    color: var(--tvl-purple-dark);
    font-weight: 700;
    cursor: pointer;
}

.active-card {
    border-color: var(--tvl-accent);
}

.management-panel {
    margin-top: 1.25rem;
    padding: 1.25rem;
    border: 1px solid rgba(121, 37, 127, 0.18);
    border-radius: 8px;
    background: #ffffff;
    box-shadow: 0 2px 8px rgba(66, 25, 72, 0.12);
}

.management-heading,
.record-row,
.record-link,
.record-actions {
    display: flex;
    align-items: center;
}

.management-heading,
.record-row {
    justify-content: space-between;
    gap: 1rem;
}

.management-heading h2 {
    margin: 0;
    color: var(--tvl-purple-dark);
    font-size: 1.2rem;
}

.management-actions,
.list-filter-toggle {
    display: flex;
    align-items: center;
}

.management-actions {
    gap: 0.85rem;
}

.list-filter-toggle {
    gap: 0.45rem;
    color: var(--tvl-text-muted);
    font-weight: 700;
    cursor: pointer;
    white-space: nowrap;
}

.list-filter-toggle input {
    width: 1.05rem;
    height: 1.05rem;
    accent-color: var(--tvl-purple-dark);
}

.primary-link {
    border-radius: 6px;
    padding: 0.7rem 0.9rem;
    background: var(--tvl-purple-dark);
    color: #ffffff;
    font-weight: 700;
    text-decoration: none;
}

.record-list {
    margin-top: 1rem;
    border-top: 1px solid rgba(121, 37, 127, 0.14);
}

.record-row {
    min-height: 3.75rem;
    border-bottom: 1px solid rgba(121, 37, 127, 0.14);
}

.record-link {
    flex: 1;
    justify-content: space-between;
    gap: 1rem;
    padding: 1rem 0;
    color: var(--tvl-text);
    font-weight: 700;
    text-decoration: none;
}

.record-link:hover span:first-child {
    color: var(--tvl-purple-dark);
    text-decoration: underline;
}

.record-detail {
    display: block;
    margin-top: 0.25rem;
    color: var(--tvl-text-muted);
    font-weight: 400;
}

.record-link small {
    border-radius: 999px;
    padding: 0.25rem 0.55rem;
    font-size: 0.72rem;
}

.status-active {
    background: #dff3e5;
    color: #176232;
}

.status-inactive {
    background: #eee9ef;
    color: var(--tvl-text-muted);
}

.company-products-form {
    max-width: 52rem;
}

.product-selection {
    display: grid;
    gap: 0;
    margin: 0;
    padding: 0;
    border: 1px solid rgba(121, 37, 127, 0.18);
    border-radius: 8px;
}

.product-selection legend {
    margin-left: 0.75rem;
    padding: 0 0.35rem;
    color: var(--tvl-purple-dark);
    font-weight: 700;
}

.field-help {
    margin: 0;
    padding: 0.75rem 1rem;
    color: var(--tvl-text-muted);
    font-size: 0.9rem;
}

.product-selection-row {
    display: grid;
    grid-template-columns: minmax(12rem, 1fr) minmax(14rem, 1fr);
    gap: 1rem;
    align-items: center;
    padding: 0.85rem 1rem;
    border-top: 1px solid rgba(121, 37, 127, 0.14);
}

.product-check {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    font-weight: 700;
}

.product-check input {
    width: 1.1rem;
    height: 1.1rem;
}

.product-check small {
    display: block;
    margin-top: 0.15rem;
    color: var(--tvl-text-muted);
    font-weight: 400;
}

.product-code-field label {
    font-size: 0.82rem;
}

.product-code-field .form-control {
    min-height: 2.4rem;
}

@media (max-width: 640px) {
    .product-selection-row { grid-template-columns: 1fr; }
}

.record-actions {
    gap: 0.75rem;
    margin-left: 1rem;
}

.record-actions a,
.delete-link {
    font: inherit;
    font-weight: 700;
}

.delete-link {
    border: 0;
    padding: 0;
    background: transparent;
    color: #9f1d2d;
    cursor: pointer;
}

.danger-button {
    min-height: 2.75rem;
    margin-left: auto;
    border: 1px solid #b32121;
    border-radius: 6px;
    background: #ffffff;
    color: #9f1d2d;
    font-weight: 700;
    cursor: pointer;
}

.empty-state {
    margin: 1rem 0 0;
    color: var(--tvl-text-muted);
}

.breadcrumb {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding-top: 1.25rem;
    color: var(--tvl-text-muted);
    font-size: 0.85rem;
}

.breadcrumb a {
    color: var(--tvl-purple-dark);
    font-weight: 700;
    text-decoration: none;
}

.breadcrumb a:hover,
.breadcrumb a:focus {
    text-decoration: underline;
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1100;
    display: grid;
    place-items: center;
    padding: 1rem;
    background: rgba(37, 32, 51, 0.58);
}

.app-modal {
    width: min(100%, 30rem);
    border-radius: 8px;
    padding: 1.5rem;
    background: #ffffff;
    box-shadow: 0 18px 55px rgba(37, 32, 51, 0.32);
}

.app-modal h2 {
    margin: 0;
    color: var(--tvl-purple-dark);
    font-size: 1.35rem;
}

.app-modal p {
    margin: 0.85rem 0 1.4rem;
    color: var(--tvl-text-muted);
    line-height: 1.5;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
}

.modal-actions button {
    padding: 0.65rem 1rem;
}

.confirm-delete-button {
    min-height: 2.75rem;
    border: 0;
    border-radius: 6px;
    background: #9f1d2d;
    color: #ffffff;
    font-weight: 700;
    cursor: pointer;
}

.confirm-delete-button:disabled {
    cursor: default;
    opacity: 0.7;
}

@media (max-width: 640px) {
    .record-row {
        align-items: flex-start;
        flex-direction: column;
        gap: 0;
        padding-bottom: 0.85rem;
    }

    .record-link {
        width: 100%;
    }

    .record-actions {
        margin-left: 0;
    }
}

/* Invoice editors use the existing form grid without a browser fieldset border. */
.management-panel > fieldset,
.manual-invoice-lines { border: 0; padding: 0; margin: 0; min-width: 0; }
.manual-invoice-lines legend { font-weight: 700; font-size: 1.15rem; margin-bottom: .75rem; }
.manual-invoice-lines output { display: block; padding: .75rem 0; font-weight: 600; }
.manual-invoice-lines .inline-editor { margin-bottom: 1rem; }

.invoice-advanced-filters { margin-top: 1rem; }
.invoice-advanced-filters > summary { cursor: pointer; font-weight: 600; color: var(--tvl-purple-dark); }
.invoice-advanced-filters > .form-grid { margin-top: 1rem; }
