/* Invoice preview dialog: scroll inside dialog on short viewports (phones). */
.invoice-preview-dialog .mud-dialog-content {
    max-height: min(88dvh, calc(100dvh - 7rem));
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

.invoice-preview-dialog-container {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    padding-left: max(4px, env(safe-area-inset-left));
    padding-right: max(4px, env(safe-area-inset-right));
}

.invoice-preview-dialog-container .mud-grid {
    align-items: stretch;
}

/* Preview column: stretch with the dialog row so the gray card can grow on desktop. */
.invoice-preview-column {
    display: flex;
    flex-direction: column;
    align-self: stretch;
    min-width: 0;
}

/* Grid so the iframe can height:100% and grow with the dialog row (taller left column). */
.invoice-preview-frame-shell {
    box-sizing: border-box;
    width: 100%;
    max-width: 100%;
    overflow: hidden;
    min-width: 0;
    background-color: #e0e0e0;
    padding: clamp(8px, 2.5vw, 20px);
    border-radius: 8px;
    flex: 1 1 auto;
    min-height: clamp(300px, 50dvh, 440px);
    display: grid;
    grid-template-rows: minmax(0, 1fr);
    align-self: stretch;
}

.invoice-preview-frame-shell--fullscreen {
    min-height: clamp(340px, 54dvh, 500px);
}

.invoice-preview-frame-placeholder {
    width: 100%;
    height: 100%;
    min-height: clamp(280px, 48dvh, 520px);
}

.invoice-preview-iframe {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    display: block;
    border: none;
    background: white;
    border-radius: 4px;
    transition: min-height 0.3s ease, height 0.3s ease;
    align-self: stretch;
    box-sizing: border-box;
    /* Single-column layout: parent has no definite height, so use a concrete viewport-based height. */
    height: clamp(320px, 58dvh, 680px);
    min-height: clamp(320px, 58dvh, 680px);
}

.invoice-preview-iframe--fullscreen {
    height: clamp(400px, 76dvh, 820px);
    min-height: clamp(400px, 76dvh, 820px);
}

.invoice-preview-nav {
    width: 100%;
    row-gap: 0.5rem;
}

.invoice-preview-nav-counter {
    min-width: 4.5rem;
    justify-content: center;
}

/* Desktop / tablet: tall preview area; shell min-height tracks viewport so the card fills space. */
@media (min-width: 960px) {
    .invoice-preview-dialog .mud-dialog-content {
        max-height: min(92dvh, calc(100dvh - 3.5rem));
    }

    .invoice-preview-frame-shell {
        min-height: min(560px, calc(100dvh - 14rem));
    }

    .invoice-preview-frame-shell--fullscreen {
        min-height: min(620px, calc(100dvh - 11rem));
    }

    .invoice-preview-frame-placeholder {
        min-height: min(520px, calc(100dvh - 15rem));
    }

    /* Split layout: row height comes from the taller column — iframe fills the gray shell. */
    .invoice-preview-iframe:not(.invoice-preview-iframe--fullscreen) {
        height: 100%;
        min-height: min(560px, calc(100dvh - 14rem));
    }

    /* Fullscreen hides the left column, so there is no row stretch — use viewport-based height. */
    .invoice-preview-iframe--fullscreen {
        height: min(780px, calc(100dvh - 10rem));
        min-height: min(640px, calc(100dvh - 11rem));
    }
}

@media (max-width: 600px) {
    .invoice-preview-dialog .mud-dialog-content {
        max-height: calc(100dvh - 5.5rem);
    }

    .invoice-preview-nav-btn {
        flex: 1 1 auto;
        min-width: 0;
    }
}

h1:focus {
    outline: none;
}

.valid.modified:not([type=checkbox]) {
    outline: 1px solid #26b050;
}

.invalid {
    outline: 1px solid #e50000;
}

.validation-message {
    color: #e50000;
}

.blazor-error-boundary {
    background: url(data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNTYiIGhlaWdodD0iNDkiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIG92ZXJmbG93PSJoaWRkZW4iPjxkZWZzPjxjbGlwUGF0aCBpZD0iY2xpcDAiPjxyZWN0IHg9IjIzNSIgeT0iNTEiIHdpZHRoPSI1NiIgaGVpZ2h0PSI0OSIvPjwvY2xpcFBhdGg+PC9kZWZzPjxnIGNsaXAtcGF0aD0idXJsKCNjbGlwMCkiIHRyYW5zZm9ybT0idHJhbnNsYXRlKC0yMzUgLTUxKSI+PHBhdGggZD0iTTI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MTE2IDkzLjUyOTUgMjY3LjM4NyA5Mi4yODM3IDI2Ny4zODcgODkuNzkyMSAyNjcuMzg3IDg3LjMwMDUgMjY2LjExNiA4Ni4wNTQ3IDI2My41NzYgODYuMDU0N1oiIGZpbGw9IiNGRkU1MDAiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjwvZz48L3N2Zz4=) no-repeat 1rem/1.8rem, #b32121;
    padding: 1rem 1rem 1rem 3.7rem;
    color: white;
}

    .blazor-error-boundary::after {
        content: "An error has occurred."
    }

.darker-border-checkbox.form-check-input {
    border-color: #929292;
}

.form-floating > .form-control-plaintext::placeholder, .form-floating > .form-control::placeholder {
    color: var(--bs-secondary-color);
    text-align: end;
}

.form-floating > .form-control-plaintext:focus::placeholder, .form-floating > .form-control:focus::placeholder {
    text-align: start;
}

/* Short fixed "Typ" (VAT, etc.): never wrap; column also gets min-width on MudTd/MudTh */
.easyksef-table-cell-type {
    white-space: nowrap;
}

/* --- Invoice table cell clamp (global): scoped CSS cannot target ClampedCellText/MudTooltip DOM reliably --- */
.mud-table-cell > .easyksef-table-cell-clamp-root {
    flex: 1 1 auto;
    min-width: 0;
    max-width: 100%;
    box-sizing: border-box;
}

.easyksef-table-cell-clamp-root {
    display: block;
    width: 100%;
    min-width: 0;
    max-width: 100%;
    box-sizing: border-box;
}

.mud-tooltip-root.easyksef-table-cell-clamp-tooltip {
    display: block !important;
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
}

.easyksef-table-cell-clamp-empty {
    color: #ccc;
    font-style: italic;
}

.easyksef-table-cell-clamp-text {
    display: -webkit-box !important;
    -webkit-box-orient: vertical !important;
    -webkit-line-clamp: 2 !important;
    line-clamp: 2 !important;
    overflow: hidden !important;
    word-break: break-word;
    overflow-wrap: anywhere;
    min-width: 0;
    max-width: 100%;
    box-sizing: border-box;
    line-height: 1.43;
    /* Two lines: lh matches cell typography when supported */
    max-height: calc(2 * 1.43em);
    max-height: 2lh;
    text-overflow: ellipsis;
}

/* Portal instruction page (/instrukcja-portalu) */
.portal-instruction-page {
    --instruction-accent: var(--mud-palette-primary, #594ae2);
    --instruction-surface: var(--mud-palette-surface, #fff);
    --instruction-muted: var(--mud-palette-text-secondary, #64748b);
    --instruction-border: var(--mud-palette-lines-default, #e2e8f0);
}

.portal-instruction-surface {
    background: var(--instruction-surface);
    border: 1px solid var(--instruction-border);
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06);
    overflow: hidden;
}

.instruction-doc {
    color: var(--mud-palette-text-primary, #1e293b);
    font-size: 1rem;
    line-height: 1.65;
}

.instruction-hero {
    padding: 2rem 2.25rem 1.5rem;
    background: linear-gradient(
        135deg,
        color-mix(in srgb, var(--instruction-accent) 12%, transparent),
        color-mix(in srgb, var(--instruction-accent) 4%, transparent)
    );
    border-bottom: 1px solid var(--instruction-border);
}

.instruction-eyebrow {
    margin: 0 0 0.35rem;
    font-size: 0.8125rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--instruction-accent);
}

.instruction-doc .instruction-title {
    margin: 0 0 0.75rem;
    font-size: clamp(1.5rem, 2.5vw, 2rem);
    font-weight: 700;
    line-height: 1.2;
}

.instruction-lead {
    margin: 0;
    max-width: 42rem;
    font-size: 1.0625rem;
    color: var(--instruction-muted);
}

.instruction-meta {
    margin: 1rem 0 0;
    font-size: 0.875rem;
    color: var(--instruction-muted);
}

.instruction-layout {
    display: grid;
    grid-template-columns: minmax(200px, 240px) 1fr;
    gap: 0;
    align-items: start;
}

@media (max-width: 960px) {
    .instruction-layout {
        grid-template-columns: 1fr;
    }
}

.instruction-toc {
    position: sticky;
    top: 1rem;
    max-height: calc(100vh - 2rem);
    overflow-y: auto;
    padding: 1.25rem 1rem 1.25rem 1.25rem;
    border-right: 1px solid var(--instruction-border);
    background: color-mix(in srgb, var(--instruction-surface) 96%, var(--instruction-accent));
}

@media (max-width: 960px) {
    .instruction-toc {
        position: static;
        max-height: none;
        border-right: none;
        border-bottom: 1px solid var(--instruction-border);
    }
}

.instruction-toc-title {
    margin: 0 0 0.75rem;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--instruction-muted);
}

.instruction-toc-list {
    margin: 0;
    padding-left: 1.35rem;
    font-size: 0.8125rem;
    line-height: 1.5;
    list-style-position: outside;
}

.instruction-toc-list li::marker {
    font-weight: 600;
    color: var(--instruction-accent);
}

.instruction-toc-list a {
    color: var(--mud-palette-text-primary, #334155);
    text-decoration: none;
}

.instruction-toc-list a:hover {
    color: var(--instruction-accent);
    text-decoration: underline;
}

.instruction-main {
    min-width: 0;
}

.instruction-body {
    padding: 1.75rem 2.25rem 2rem;
}

.instruction-section {
    margin-bottom: 2.5rem;
    padding-bottom: 2rem;
    border-bottom: 1px solid var(--instruction-border);
}

.instruction-section:last-child {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}

.instruction-body h2 {
    margin: 0 0 1rem;
    font-size: 1.375rem;
    font-weight: 700;
    line-height: 1.3;
    scroll-margin-top: 1rem;
}

.instruction-body h3 {
    margin: 1.5rem 0 0.75rem;
    font-size: 1.0625rem;
    font-weight: 600;
    scroll-margin-top: 1rem;
}

.instruction-body p,
.instruction-body ul,
.instruction-body ol,
.instruction-body dl {
    margin: 0 0 1rem;
}

.instruction-body li + li {
    margin-top: 0.35rem;
}

.instruction-body code {
    padding: 0.1em 0.35em;
    border-radius: 4px;
    font-size: 0.9em;
    background: color-mix(in srgb, var(--instruction-border) 60%, transparent);
}

.instruction-glossary {
    display: grid;
    gap: 0;
    margin: 0;
}

.instruction-glossary dt {
    margin-top: 1rem;
    font-weight: 700;
    color: var(--mud-palette-text-primary, #0f172a);
}

.instruction-glossary dt:first-child {
    margin-top: 0;
}

.instruction-glossary dd {
    margin: 0.25rem 0 0;
    padding-left: 0;
    color: var(--instruction-muted);
}

.instruction-table {
    border-collapse: collapse;
    width: 100%;
    margin: 1rem 0 1.25rem;
    font-size: 0.9375rem;
}

.instruction-table th,
.instruction-table td {
    border: 1px solid var(--instruction-border);
    padding: 0.6rem 0.75rem;
    text-align: left;
    vertical-align: top;
}

.instruction-table th {
    background: color-mix(in srgb, var(--instruction-accent) 8%, transparent);
    font-weight: 600;
}

.instruction-faq {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.instruction-faq-item {
    border: 1px solid var(--instruction-border);
    border-radius: 8px;
    overflow: hidden;
    background: color-mix(in srgb, var(--instruction-surface) 98%, var(--instruction-accent));
}

.instruction-faq-item summary {
    padding: 0.75rem 1rem;
    font-weight: 600;
    cursor: pointer;
    list-style: none;
}

.instruction-faq-item summary::-webkit-details-marker {
    display: none;
}

.instruction-faq-item[open] summary {
    border-bottom: 1px solid var(--instruction-border);
    background: color-mix(in srgb, var(--instruction-accent) 6%, transparent);
}

.instruction-faq-item p {
    margin: 0;
    padding: 0.75rem 1rem 1rem;
}

.instruction-footer {
    margin: 0;
    padding: 1rem 2.25rem 1.5rem;
    font-size: 0.875rem;
    color: var(--instruction-muted);
    border-top: 1px solid var(--instruction-border);
}

a.portal-instruction-link {
    color: var(--instruction-accent);
    font-weight: 600;
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 2px;
}

a.portal-instruction-link:hover {
    text-decoration-thickness: 2px;
}

a.portal-instruction-link[href^="/"] {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.9em;
    font-weight: 500;
}