@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;500;700&family=IBM+Plex+Sans:wght@400;500&display=swap');

:root {
    --bg-main: #f6f3ee;
    --bg-card: #fffdf8;
    --text-main: #102a43;
    --text-muted: #486581;
    --brand: #1f8a70;
    --brand-dark: #115e4c;
    --brand-soft: #d9f0e8;
    --brand-strong: #0f5132;
    --accent: #6bbf59;
    --error: #b42318;
    --border: #d9e2ec;
    --shadow: 0 20px 45px rgba(16, 42, 67, 0.12);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: 'IBM Plex Sans', sans-serif;
    color: var(--text-main);
    background:
        radial-gradient(circle at 10% 10%, rgba(239, 125, 87, 0.2), transparent 35%),
        radial-gradient(circle at 90% 80%, rgba(0, 127, 127, 0.2), transparent 35%),
        var(--bg-main);
    display: grid;
    place-items: center;
    padding: 24px;
}

.auth-shell {
    width: 100%;
    max-width: 980px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 24px;
    overflow: hidden;
    display: grid;
    grid-template-columns: 1.2fr 1fr;
    box-shadow: var(--shadow);
    animation: riseIn 0.65s ease both;
}

.auth-hero {
    padding: 44px;
    background: linear-gradient(155deg, #102a43 0%, #243b53 45%, #005f5f 100%);
    color: #f0f4f8;
}

.auth-hero h1 {
    margin: 0 0 16px;
    font-family: 'Space Grotesk', sans-serif;
    font-size: clamp(2rem, 2.8vw, 2.8rem);
    line-height: 1.1;
}

.auth-hero p {
    margin: 0;
    color: #d9e2ec;
    line-height: 1.6;
}

.auth-hero a {
    color: #8fd3ff;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.auth-hero a:hover {
    color: #c8ecff;
}

.auth-form {
    padding: 36px;
}

.auth-form h2 {
    margin-top: 0;
    font-family: 'Space Grotesk', sans-serif;
    font-size: 1.8rem;
}

.form-row {
    margin-bottom: 14px;
}

label {
    display: block;
    margin-bottom: 6px;
    font-size: 0.95rem;
    color: var(--text-muted);
}

input {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px 14px;
    font-size: 1rem;
    font-family: inherit;
    background: #fff;
}

select {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px 14px;
    font-size: 1rem;
    font-family: inherit;
    background: #fff;
}

input:focus {
    outline: 2px solid rgba(0, 127, 127, 0.35);
    border-color: var(--brand);
}

select:focus {
    outline: 2px solid rgba(0, 127, 127, 0.35);
    border-color: var(--brand);
}

.btn {
    border: 0;
    border-radius: 12px;
    width: 100%;
    background: linear-gradient(100deg, var(--brand), var(--brand-dark));
    color: #fff;
    padding: 12px 14px;
    font-size: 1rem;
    font-family: 'Space Grotesk', sans-serif;
    letter-spacing: 0.2px;
    cursor: pointer;
    transition: transform 0.15s ease, opacity 0.15s ease;
}

.btn:hover {
    transform: translateY(-1px);
    opacity: 0.95;
}

.auth-links {
    margin-top: 14px;
    text-align: center;
    color: var(--text-muted);
}

.auth-links a {
    color: var(--accent);
    text-decoration: none;
    font-weight: 500;
}

.flash {
    margin-bottom: 12px;
    padding: 10px 12px;
    border-radius: 10px;
    border: 1px solid #f7c7c3;
    background: #fdecea;
    color: var(--error);
}

.flash.success {
    border-color: #b8f0dd;
    background: #ecfff7;
    color: #05603a;
}

.dashboard {
    width: min(820px, 100%);
    background: var(--bg-card);
    border-radius: 22px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    padding: 34px;
    animation: riseIn 0.65s ease both;
}

.dashboard h1 {
    margin-top: 0;
    font-family: 'Space Grotesk', sans-serif;
}

.dashboard-meta {
    color: var(--text-muted);
    margin-bottom: 18px;
}

.dashboard-page {
    display: block;
    padding: 0;
    overflow-x: hidden;
    background:
        radial-gradient(circle at 12% 10%, rgba(31, 138, 112, 0.16), transparent 28%),
        radial-gradient(circle at 88% 0%, rgba(107, 191, 89, 0.16), transparent 26%),
        linear-gradient(180deg, #eef7f3 0%, #f7faf8 100%);
}

.dashboard-page .topbar {
    width: 100vw;
    margin-left: calc(50% - 50vw);
    margin-right: calc(50% - 50vw);
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 24px;
    justify-content: space-between;
    padding: 14px 22px;
    background: linear-gradient(90deg, #143d2e 0%, #1f5f4a 50%, #0f5132 100%);
    color: #f7fbf8;
    box-shadow: 0 12px 32px rgba(15, 81, 50, 0.28);
}

.topbar-brand {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 1.15rem;
    font-weight: 700;
    letter-spacing: 0.2px;
    white-space: nowrap;
}

.topbar-nav {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.topbar-menu {
    position: relative;
}

.topbar-link {
    color: #e7f5ef;
    text-decoration: none;
    padding: 10px 12px;
    border-radius: 10px;
    font-weight: 500;
    transition: background-color 0.15s ease, color 0.15s ease, transform 0.15s ease;
}

.topbar-link:hover,
.topbar-link.is-active {
    background: rgba(255, 255, 255, 0.12);
    color: #ffffff;
    transform: translateY(-1px);
}

.topbar-menu-trigger {
    position: relative;
    padding-right: 30px;
}

.topbar-menu-trigger::after {
    content: '';
    position: absolute;
    right: 12px;
    top: 50%;
    width: 7px;
    height: 7px;
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    transform: translateY(-65%) rotate(45deg);
    opacity: 0.9;
}

.topbar-dropdown {
    position: absolute;
    left: 0;
    top: calc(100% + 8px);
    min-width: 220px;
    padding: 8px;
    border-radius: 16px;
    background: rgba(15, 81, 50, 0.98);
    box-shadow: 0 16px 36px rgba(9, 46, 29, 0.34);
    border: 1px solid rgba(255, 255, 255, 0.12);
    opacity: 0;
    visibility: hidden;
    transform: translateY(8px);
    transition: opacity 0.16s ease, visibility 0.16s ease, transform 0.16s ease;
    z-index: 30;
}

.topbar-menu:hover .topbar-dropdown,
.topbar-menu:focus-within .topbar-dropdown {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.topbar-dropdown-link {
    display: block;
    padding: 10px 12px;
    border-radius: 12px;
    color: #edf8f2;
    text-decoration: none;
    font-weight: 500;
    transition: background-color 0.15s ease, transform 0.15s ease;
}

.topbar-dropdown-link:hover {
    background: rgba(255, 255, 255, 0.12);
    transform: translateX(2px);
}

.topbar-user {
    display: flex;
    align-items: center;
    gap: 12px;
    white-space: nowrap;
}

.topbar-hello {
    color: #d7ede3;
    font-size: 0.95rem;
}

.topbar-logout {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 84px;
    padding: 8px 12px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.14);
    color: #ffffff;
    text-decoration: none;
    font-weight: 600;
    transition: background-color 0.15s ease, transform 0.15s ease;
}

.topbar-logout:hover {
    background: rgba(255, 255, 255, 0.22);
    transform: translateY(-1px);
}

.dashboard-shell {
    width: min(1200px, calc(100% - 40px));
    margin: 28px auto 40px;
    display: grid;
    gap: 22px;
}

.dashboard-card {
    background: rgba(255, 253, 248, 0.92);
    border: 1px solid rgba(31, 138, 112, 0.12);
    border-radius: 24px;
    box-shadow: var(--shadow);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
}

.dashboard-hero {
    display: grid;
    grid-template-columns: 1.5fr 1fr;
    gap: 24px;
    padding: 28px;
    align-items: start;
}

.dashboard-kicker {
    margin: 0 0 10px;
    color: var(--brand);
    text-transform: uppercase;
    letter-spacing: 0.18em;
    font-size: 0.78rem;
    font-weight: 700;
}

.dashboard-hero h1 {
    margin: 0 0 12px;
    font-family: 'Space Grotesk', sans-serif;
    font-size: clamp(2rem, 3vw, 3rem);
    line-height: 1.1;
}

.dashboard-intro {
    margin: 0;
    color: var(--text-muted);
    line-height: 1.7;
    max-width: 62ch;
}

.license-panel {
    display: grid;
    gap: 12px;
    padding: 18px;
    border-radius: 20px;
    background: linear-gradient(180deg, #ecf8f3 0%, #dff2e9 100%);
    border: 1px solid rgba(31, 138, 112, 0.18);
}

.license-row {
    display: grid;
    gap: 4px;
    padding: 14px 16px;
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.7);
}

.license-emphasis {
    background: linear-gradient(90deg, rgba(31, 138, 112, 0.14), rgba(107, 191, 89, 0.14));
}

.license-label,
.card-tag {
    color: var(--text-muted);
    font-size: 0.82rem;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    font-weight: 700;
}

.license-row strong {
    color: var(--brand-strong);
    font-size: 1.02rem;
}

.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 18px;
}

.action-card {
    padding: 22px;
    min-height: 180px;
}

.action-card h2,
.dashboard-note h2 {
    margin: 10px 0 10px;
    font-family: 'Space Grotesk', sans-serif;
    font-size: 1.35rem;
}

.action-card p,
.dashboard-note p {
    margin: 0;
    color: var(--text-muted);
    line-height: 1.65;
}

.dashboard-note {
    padding: 22px 24px;
}

.dashboard-chart-head {
    margin-bottom: 10px;
}

#documents-summary {
    padding: 24px;
}

#documents-summary-monthly {
    padding: 24px;
}

#top-clients-summary {
    padding: 30px;
}

.dashboard-top-clients-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px;
    margin-top: 10px;
}

.dashboard-top-clients-column h3 {
    margin: 0;
    font-family: 'Space Grotesk', sans-serif;
    font-size: 1.15rem;
    color: #1f2937;
}

.dashboard-top-clients-column {
    padding: 4px 6px;
}

#top-clients-summary .clients-table th,
#top-clients-summary .clients-table td {
    font-size: 0.86rem;
    padding: 8px 9px;
}

#top-clients-summary .clients-table {
    min-width: 0;
    table-layout: fixed;
}

#top-clients-summary .clients-table th:first-child,
#top-clients-summary .clients-table td:first-child {
    width: 50%;
    white-space: normal;
    overflow-wrap: anywhere;
    word-break: break-word;
}

#top-clients-summary .clients-table th:nth-child(n + 2),
#top-clients-summary .clients-table td:nth-child(n + 2) {
    width: 16.66%;
    text-align: right;
    white-space: nowrap;
}

.dashboard-chart-head h2 {
    margin: 0;
    font-family: 'Space Grotesk', sans-serif;
    font-size: clamp(1.4rem, 2.2vw, 2.1rem);
    color: #1f2937;
}

.dashboard-chart-canvas-wrap {
    overflow-x: auto;
    border-top: 1px solid rgba(31, 138, 112, 0.12);
    border-bottom: 1px solid rgba(31, 138, 112, 0.12);
    padding: 6px 0;
    margin-top: 8px;
}

.dashboard-chart-svg {
    width: 100%;
    min-width: 980px;
    height: 400px;
    display: block;
}

.dashboard-svg-grid {
    stroke: rgba(31, 41, 55, 0.16);
    stroke-width: 1;
}

.dashboard-svg-axis {
    stroke: rgba(31, 41, 55, 0.35);
    stroke-width: 1;
}

.dashboard-svg-axis-label {
    fill: #6b7280;
    font-size: 12px;
    font-weight: 500;
}

.dashboard-svg-xlabel {
    fill: #6b7280;
    font-size: 11px;
}

.dashboard-svg-xlabel-weekend {
    fill: #b42318;
    font-weight: 700;
}

.dashboard-svg-bar {
    fill: rgba(76, 175, 80, 0.28);
    stroke: rgba(67, 137, 71, 0.9);
    stroke-width: 1.2;
}

.dashboard-svg-average {
    stroke: #4f7bff;
    stroke-width: 1.5;
    stroke-dasharray: 7 6;
}

.dashboard-svg-average-label {
    fill: #365acb;
    font-size: 12px;
    font-weight: 700;
}

.dashboard-kpis {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 18px;
    margin-top: 14px;
}

.dashboard-secondary-chart-section {
    margin-top: 28px;
    padding-top: 22px;
    border-top: 1px solid rgba(31, 138, 112, 0.14);
}

.dashboard-kpi-item {
    padding: 6px 0;
}

.dashboard-kpi-break {
    grid-column: 1 / -1;
    height: 0;
}

.dashboard-kpi-label {
    display: block;
    margin-bottom: 4px;
    color: #6b7280;
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.dashboard-kpi-item strong {
    font-size: 2rem;
    line-height: 1;
    color: #111827;
    font-family: 'Space Grotesk', sans-serif;
}

.dashboard-kpi-item-emphasis strong {
    color: #3f7b39;
}

.dashboard-chart-wrap {
    overflow-x: auto;
    padding: 10px 4px 2px;
}

.dashboard-chart-shell {
    min-width: 760px;
    display: grid;
    grid-template-columns: 78px 1fr;
    gap: 12px;
    align-items: stretch;
}

.dashboard-chart-axis {
    height: 320px;
    display: grid;
    grid-template-rows: repeat(5, 1fr);
    align-items: end;
    justify-items: end;
    padding: 10px 6px 22px 0;
}

.dashboard-chart-axis-tick {
    width: 100%;
    text-align: right;
    font-size: 0.72rem;
    color: var(--text-muted);
    position: relative;
}

.dashboard-chart-axis-tick::after {
    content: '';
    position: absolute;
    right: -10px;
    top: 50%;
    width: 6px;
    border-top: 1px solid rgba(31, 138, 112, 0.32);
}

.dashboard-chart {
    height: 320px;
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: minmax(36px, 1fr);
    gap: 10px;
    align-items: end;
    padding: 10px 12px;
    border: 1px solid rgba(31, 138, 112, 0.18);
    border-radius: 16px;
    background:
        repeating-linear-gradient(
            to top,
            rgba(31, 138, 112, 0.12) 0,
            rgba(31, 138, 112, 0.12) 1px,
            transparent 1px,
            transparent calc(25% - 1px)
        ),
        linear-gradient(180deg, rgba(236, 248, 243, 0.7) 0%, rgba(255, 255, 255, 0.8) 100%);
    position: relative;
}

.dashboard-chart-item {
    height: 100%;
    display: grid;
    grid-template-rows: minmax(18px, auto) 220px 20px;
    align-items: stretch;
    gap: 8px;
}

.dashboard-chart-value {
    font-size: 0.78rem;
    color: var(--brand-strong);
    font-weight: 600;
    text-align: center;
    white-space: nowrap;
}

.dashboard-chart-track {
    height: 100%;
    border-radius: 6px;
    background: transparent;
    display: flex;
    align-items: flex-end;
    overflow: hidden;
    border-bottom: 2px solid rgba(19, 98, 82, 0.45);
}

.dashboard-chart-fill {
    width: 100%;
    background: linear-gradient(180deg, #1f8a70 0%, #136252 100%);
    border-radius: 8px 8px 0 0;
}

.dashboard-chart-fill-tiny {
    min-height: 2px;
}

.dashboard-chart-label {
    font-size: 0.72rem;
    color: var(--text-muted);
    text-align: center;
    white-space: nowrap;
}

.dashboard-chart-label-weekend {
    color: #b42318;
    font-weight: 700;
}

@media (max-width: 860px) {
    #documents-summary {
        padding: 16px;
    }

    #documents-summary-monthly,
    #top-clients-summary {
        padding: 18px;
    }

    .dashboard-top-clients-grid {
        grid-template-columns: 1fr;
    }

    .dashboard-kpis {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .dashboard-kpi-item strong {
        font-size: 1.5rem;
    }
}

.meta-dot {
    padding: 0 6px;
    color: var(--brand);
    font-weight: 700;
}

.clients-shell {
    gap: 18px;
}

.clients-hero {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 20px;
    padding: 26px 28px;
}

.clients-toolbar-actions {
    display: grid;
    gap: 10px;
    justify-items: end;
}

.btn-inline {
    width: auto;
    min-width: 150px;
    padding-inline: 18px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.btn-secondary {
    background: linear-gradient(100deg, #5c7280, #334e68);
}

.btn-danger {
    background: linear-gradient(100deg, #c0392b, #922b21);
}

.btn-danger:hover {
    background: linear-gradient(100deg, #a93226, #7b241c);
}

.btn-secondary.btn-new-draft {
    background: linear-gradient(100deg, #c06014, #8a3f06);
}

.clients-toolbar-note,
.form-help {
    margin: 0;
    color: var(--text-muted);
    font-size: 0.93rem;
    line-height: 1.5;
}

.clients-table-card {
    padding: 22px;
}

.clients-table-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
}

.clients-table-header h2 {
    margin: 0;
    font-family: 'Space Grotesk', sans-serif;
}

.clients-table-controls {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.documents-table-controls {
    display: grid;
    grid-template-columns: repeat(12, minmax(0, 1fr));
    gap: 12px;
    align-items: end;
    justify-content: stretch;
}

.documents-filters-section {
    padding: 22px;
}

.documents-table-controls .table-filter {
    width: 100%;
    min-width: 0;
}

.documents-filter-field {
    margin: 0;
    min-width: 0;
}

.documents-filter-select {
    width: 100%;
    min-width: 0;
}

.documents-table-controls .documents-filter-field input {
    width: 100%;
    min-width: 0;
}

.documents-table-controls .documents-filter-field select {
    width: 100%;
    min-width: 0;
}

.documents-filters-section .clients-table-header {
    margin-bottom: 14px;
}

.documents-filter-period-from,
.documents-filter-period-to,
.documents-filter-client,
.documents-filter-number,
.documents-filter-document-type,
.documents-filter-payment-type,
.documents-filter-status {
    grid-column: span 3;
}

.documents-filter-actions {
    grid-column: 1 / -1;
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-start;
    gap: 10px;
}

.documents-filter-actions .table-action-button {
    min-width: 130px;
}

.table-filter {
    display: flex;
    align-items: center;
    gap: 8px;
}

.table-filter input {
    width: min(460px, 62vw);
}

.clients-count {
    display: inline-flex;
    align-items: center;
    padding: 8px 12px;
    border-radius: 999px;
    background: var(--brand-soft);
    color: var(--brand-strong);
    font-weight: 600;
}

.table-wrap {
    overflow-x: auto;
    border-radius: 18px;
    border: 1px solid rgba(31, 138, 112, 0.12);
}

.table-wrap.js-infinite-wrap {
    max-height: 62vh;
    overflow: auto;
}

.table-wrap.js-infinite-wrap .clients-table thead th {
    position: sticky;
    top: 0;
    z-index: 3;
    background: #e8f4ee;
    opacity: 1;
    box-shadow: inset 0 -1px 0 rgba(26, 111, 90, 0.18);
}

.table-loader {
    padding: 12px 14px;
    font-size: 0.92rem;
    color: var(--text-muted);
    background: rgba(217, 240, 232, 0.32);
    border-top: 1px solid rgba(31, 138, 112, 0.12);
}

.import-loader-overlay {
    position: fixed;
    inset: 0;
    z-index: 120;
    background: rgba(16, 42, 67, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.import-loader-overlay[hidden] {
    display: none !important;
}

.import-loader-card {
    min-width: 280px;
    max-width: 420px;
    border-radius: 16px;
    background: #fff;
    border: 1px solid rgba(31, 138, 112, 0.2);
    box-shadow: 0 20px 45px rgba(16, 42, 67, 0.28);
    display: grid;
    justify-items: center;
    gap: 12px;
    padding: 20px 22px;
    text-align: center;
}

.import-loader-card p {
    margin: 0;
    color: var(--text-main);
    font-weight: 500;
}

.import-loader-spinner {
    width: 34px;
    height: 34px;
    border-radius: 999px;
    border: 3px solid rgba(17, 94, 76, 0.22);
    border-top-color: var(--brand-dark);
    animation: loaderSpin 0.8s linear infinite;
}

body.is-busy {
    cursor: progress;
}

@keyframes loaderSpin {
    to {
        transform: rotate(360deg);
    }
}

.clients-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 860px;
    background: rgba(255, 255, 255, 0.82);
}

.clients-table th:first-child,
.clients-table td:first-child {
    min-width: 280px;
}

.documents-table th:first-child,
.documents-table td:first-child {
    width: 110px;
    min-width: 110px;
    max-width: 130px;
    white-space: nowrap;
}

.clients-table th,
.clients-table td {
    padding: 14px 14px;
    border-bottom: 1px solid rgba(217, 226, 236, 0.9);
    text-align: left;
    vertical-align: top;
}

.clients-table th {
    background: #e8f4ee;
    color: var(--brand-strong);
    font-size: 0.83rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.clients-table tbody tr:hover {
    background: rgba(217, 240, 232, 0.35);
}

.clients-table tbody tr.documents-row.documents-row-issued {
    background: rgba(31, 138, 112, 0.12);
}

.clients-table tbody tr.documents-row.documents-row-draft {
    background: rgba(246, 189, 96, 0.18);
}

.clients-table tbody tr.documents-row.documents-row-issued:hover {
    background: rgba(31, 138, 112, 0.2);
}

.clients-table tbody tr.documents-row.documents-row-draft:hover {
    background: rgba(246, 189, 96, 0.26);
}

.table-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.documents-list-actions {
    margin-top: 12px;
    justify-content: flex-end;
}

.table-action-button {
    border: 1px solid rgba(31, 138, 112, 0.18);
    background: rgba(31, 138, 112, 0.08);
    color: var(--brand-strong);
    border-radius: 10px;
    padding: 8px 12px;
    font: inherit;
    cursor: pointer;
    transition: transform 0.15s ease, background-color 0.15s ease;
}

.table-action-button:hover {
    transform: translateY(-1px);
    background: rgba(31, 138, 112, 0.14);
}

.empty-state {
    padding: 22px;
    border-radius: 18px;
    border: 1px dashed rgba(31, 138, 112, 0.3);
    background: rgba(217, 240, 232, 0.32);
    color: var(--text-muted);
}

.empty-state-inline {
    margin: 10px;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.modal {
    position: fixed;
    inset: 0;
    z-index: 80;
    display: none;
}

.modal.is-open {
    display: block;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(9, 28, 20, 0.58);
}

.modal-dialog {
    position: relative;
    z-index: 1;
    width: min(1120px, calc(100vw - 24px));
    max-height: calc(100vh - 24px);
    margin: 12px auto;
    overflow: auto;
    border-radius: 26px;
    background: var(--bg-card);
    box-shadow: 0 28px 70px rgba(0, 0, 0, 0.28);
    border: 1px solid rgba(31, 138, 112, 0.16);
    padding: 24px;
}

.modal-dialog.session-modal {
    width: min(420px, calc(100vw - 24px)) !important;
    max-width: 420px !important;
}

.modal-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
}

.modal-header h2 {
    margin: 4px 0 0;
    font-family: 'Space Grotesk', sans-serif;
}

.modal-close {
    border: 0;
    width: 42px;
    height: 42px;
    border-radius: 12px;
    background: rgba(31, 138, 112, 0.1);
    color: var(--brand-strong);
    font-size: 1.55rem;
    cursor: pointer;
}

.client-form {
    display: grid;
    gap: 18px;
}

.client-common-grid,
.modal-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
}

.modal-grid .form-row-full {
    grid-column: 1 / -1;
}

textarea {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px 14px;
    font-size: 1rem;
    font-family: inherit;
    background: #fff;
    resize: vertical;
    min-height: 100px;
}

textarea:focus {
    outline: 2px solid rgba(31, 138, 112, 0.25);
    border-color: var(--brand);
}

.modal-tabs {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    padding: 8px;
    border-radius: 16px;
    background: rgba(217, 240, 232, 0.5);
}

.modal-tab {
    border: 0;
    padding: 10px 14px;
    border-radius: 12px;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    font-weight: 600;
}

.modal-tab.is-active {
    background: linear-gradient(100deg, var(--brand), var(--brand-dark));
    color: #fff;
}

.modal-tab .flag-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    margin-right: 6px;
    padding: 0;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.2);
    font-size: 0.75em;
    font-weight: 700;
    letter-spacing: 0.5px;
    vertical-align: middle;
}

.modal-tab.is-active .flag-badge {
    background: rgba(255, 255, 255, 0.4);
    color: #fff;
}

.modal-panels {
    display: grid;
    gap: 14px;
}

.tab-panel {
    display: none;
    padding: 18px;
    border-radius: 18px;
    border: 1px solid rgba(31, 138, 112, 0.12);
    background: rgba(255, 255, 255, 0.88);
}

.tab-panel.is-active {
    display: block;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    flex-wrap: wrap;
}

.document-section {
    padding: 14px;
    border-radius: 16px;
    border: 1px solid rgba(31, 138, 112, 0.14);
    background: rgba(217, 240, 232, 0.24);
}

.document-section .dashboard-kicker {
    margin-bottom: 12px;
}

.document-lines-table input {
    width: 100%;
    min-width: 0;
    padding: 8px 10px;
    border-radius: 10px;
}

.document-lines-table textarea {
    width: 100%;
    min-width: 0;
    min-height: 56px;
    padding: 8px 10px;
    border-radius: 10px;
}

.document-lines-table td {
    vertical-align: middle;
}

.document-lines-table th:first-child,
.document-lines-table td:first-child {
    width: 40px;
    min-width: 40px;
    max-width: 40px;
    padding-left: 8px;
    padding-right: 8px;
}

.document-line-cell {
    display: grid;
    width: fit-content;
    margin: 0 auto;
    gap: 6px;
    justify-items: center;
}

.document-line-cell .table-action-button {
    width: 100%;
    min-width: 0;
    padding: 6px 8px;
}

.document-line-cell .table-action-button.document-line-picker-button {
    width: 24px !important;
    min-width: 24px !important;
    max-width: 24px !important;
    height: 24px !important;
    min-height: 24px !important;
    max-height: 24px !important;
    aspect-ratio: 1 / 1;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 9px;
    overflow: hidden;
    flex: 0 0 24px;
    align-self: center;
}

.document-line-picker-icon {
    width: 14px;
    height: 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 0;
    flex: 0 0 14px;
}

.document-line-picker-button svg {
    width: 14px;
    height: 14px;
    min-width: 14px;
    min-height: 14px;
    max-width: 14px;
    max-height: 14px;
    display: block;
    flex: 0 0 14px;
}

.document-lines-totals-wrap {
    display: flex;
    justify-content: flex-end;
    margin-top: 12px;
}

.document-lines-totals-grid {
    width: min(460px, 100%);
    grid-template-columns: 1fr;
    gap: 8px;
}

.document-lines-totals-grid .form-row {
    margin-bottom: 0;
    display: grid;
    grid-template-columns: minmax(120px, 1fr) minmax(150px, 180px);
    align-items: center;
    gap: 10px;
}

.document-lines-totals-grid label {
    margin-bottom: 0;
    text-align: right;
}

.document-lines-totals-grid input {
    text-align: right;
}

.document-lines-totals-grid select {
    text-align: right;
    text-align-last: right;
}

.status-chip {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 0.82rem;
    font-weight: 600;
}

.status-chip-draft {
    color: #7a4a0a;
    background: rgba(246, 189, 96, 0.24);
}

.status-chip-issued {
    color: #0b5b49;
    background: rgba(31, 138, 112, 0.2);
}

.status-chip-paid {
    color: #0b5b49;
    background: rgba(31, 138, 112, 0.2);
}

.status-chip-unpaid {
    color: #8e1a12;
    background: rgba(180, 35, 24, 0.16);
}

.client-preview {
    border: 1px solid rgba(31, 138, 112, 0.18);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.88);
    padding: 12px 14px;
}

.client-preview-title {
    margin: 0 0 10px;
    font-family: 'Space Grotesk', sans-serif;
    font-size: 1rem;
}

.client-preview-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px 12px;
}

.client-preview-row {
    display: grid;
    gap: 2px;
}

.client-preview-label {
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
}

.modal-dialog.client-picker-dialog {
    width: min(760px, calc(100vw - 24px));
}

.modal-dialog.client-editor-dialog {
    width: min(860px, calc(100vw - 24px));
}

.modal-dialog.document-print-preview-dialog {
    width: min(1180px, calc(100vw - 24px));
}

.document-print-preview-body {
    background: #f2f2f2;
    border: 1px solid rgba(16, 42, 67, 0.15);
    border-radius: 14px;
    padding: 14px;
    max-height: 62vh;
    overflow: auto;
}

.document-pdf-viewer-body {
    height: 70vh;
    border: 1px solid rgba(16, 42, 67, 0.15);
    border-radius: 14px;
    overflow: hidden;
    background: #fff;
}

.document-pdf-viewer-body iframe {
    width: 100%;
    height: 100%;
    border: 0;
    display: block;
}

.document-pdf-email-actions {
    margin-top: 10px;
    padding: 12px;
    border: 1px solid rgba(16, 42, 67, 0.12);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.85);
}

.document-pdf-email-row {
    display: flex;
    gap: 10px;
    align-items: center;
}

.document-pdf-email-row input {
    flex: 1 1 auto;
}

.document-pdf-email-row .btn {
    width: auto;
    min-width: 180px;
    white-space: nowrap;
}

.document-pdf-email-actions .form-help {
    margin: 8px 0 0;
}

.document-pdf-export-node {
    position: absolute;
    left: 0;
    top: 0;
    width: 1200px;
    z-index: 1;
    opacity: 0;
    pointer-events: none;
}

.invoice-preview-sheet {
    width: min(100%, 1060px);
    margin: 0 auto;
    background: #fff;
    border: 1px solid #c9ced6;
    padding: 18px 20px;
    color: #111;
    font-family: 'IBM Plex Sans', sans-serif;
}

.invoice-brand-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    border-bottom: 1px solid #bbb;
    padding-bottom: 8px;
    margin-bottom: 10px;
}

.invoice-brand-name {
    font-size: 1.35rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    color: #2c4f7f;
}

.invoice-brand-logo {
    display: block;
    max-width: 33.333%;
    max-height: 72px;
    width: auto;
    height: auto;
    object-fit: contain;
}

.invoice-brand-note {
    font-size: 0.83rem;
    color: #4a4a4a;
    text-align: right;
    max-width: 60%;
}

.invoice-title-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.invoice-title-row h3 {
    margin: 0;
    font-size: 1.9rem;
    letter-spacing: 0.05em;
}

.invoice-original-badge {
    border: 2px solid #111;
    padding: 4px 14px;
    font-weight: 700;
    letter-spacing: 0.25em;
    font-size: 0.82rem;
}

.invoice-meta-row {
    border-top: 1px solid #999;
    border-bottom: 1px solid #999;
    padding: 8px 0;
    font-size: 0.92rem;
}

.invoice-parties {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 22px;
    margin: 14px 0 10px;
}

.invoice-parties h4 {
    margin: 0 0 8px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.invoice-parties p {
    margin: 0 0 4px;
    line-height: 1.35;
}

.invoice-lines-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 8px;
}

.invoice-lines-table th,
.invoice-lines-table td {
    border: 1px solid #bbb;
    padding: 6px 8px;
    font-size: 0.92rem;
}

.invoice-lines-table thead th {
    background: #ececec;
}

.invoice-col-right {
    text-align: right;
}

.invoice-col-center {
    text-align: center;
}

.invoice-totals {
    margin-top: 10px;
    margin-left: auto;
    width: min(520px, 100%);
}

.invoice-totals > div {
    display: flex;
    justify-content: space-between;
    border-bottom: 1px solid #d7d7d7;
    padding: 4px 0;
}

.invoice-totals .invoice-grand-total {
    font-size: 1.3rem;
    font-weight: 700;
    border-top: 2px solid #111;
    border-bottom: 2px solid #111;
    margin-top: 4px;
}

.invoice-payment-block {
    margin-top: 14px;
    border-top: 1px solid #aaa;
    padding-top: 8px;
}

.invoice-payment-block h4 {
    margin: 0 0 8px;
    font-size: 1.08rem;
}

.invoice-payment-block p {
    margin: 0 0 4px;
}

.invoice-footer-note {
    margin-top: 14px;
    border-top: 1px solid #d7d7d7;
    padding-top: 8px;
    text-align: center;
    color: #555;
    font-size: 0.86rem;
}

body.document-print-export {
    background: #fff;
    padding: 0;
    margin: 0;
}

body.document-print-export .invoice-preview-sheet {
    border: 0;
    width: 100%;
    max-width: none;
}

.client-picker-list {
    max-height: 42vh;
}

.client-picker-search-actions {
    display: flex;
    gap: 10px;
    align-items: center;
}

.client-picker-search-actions input {
    flex: 1 1 auto;
}

#open-client-create-in-picker {
    width: 50%;
}

#client-picker-list .clients-table {
    min-width: 0;
    table-layout: fixed;
}

#client-picker-list .clients-table th:first-child,
#client-picker-list .clients-table td:first-child {
    min-width: 0;
    width: 52%;
}

#client-picker-list .clients-table th:nth-child(2),
#client-picker-list .clients-table td:nth-child(2) {
    width: 24%;
}

#client-picker-list .clients-table th:nth-child(3),
#client-picker-list .clients-table td:nth-child(3) {
    width: 24%;
    white-space: nowrap;
}

#client-picker-list .clients-table td:first-child {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#client-picker-list .client-picker-row {
    cursor: pointer;
}

.products-page .client-common-grid {
    grid-template-columns: minmax(140px, 0.55fr) 1fr 1fr;
}

.products-page .modal-grid {
    grid-template-columns: minmax(0, 5fr) minmax(110px, 1fr);
    align-items: end;
}

.products-page .modal-grid .item-name-row {
    min-width: 0;
}

.products-page .modal-grid .unit-name-row {
    max-width: 150px;
    justify-self: start;
}

@keyframes riseIn {
    from {
        opacity: 0;
        transform: translateY(18px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@media (max-width: 860px) {
    .auth-shell {
        grid-template-columns: 1fr;
    }

    .auth-hero {
        padding: 30px;
    }

    .auth-form {
        padding: 26px;
    }

    .topbar {
        flex-wrap: wrap;
        gap: 12px;
    }

    .topbar-nav {
        order: 3;
        width: 100%;
    }

    .topbar-menu {
        width: 100%;
    }

    .topbar-menu-trigger {
        width: 100%;
    }

    .topbar-dropdown {
        position: static;
        min-width: 0;
        margin-top: 8px;
        opacity: 1;
        visibility: visible;
        transform: none;
        display: none;
    }

    .topbar-menu:hover .topbar-dropdown,
    .topbar-menu:focus-within .topbar-dropdown {
        display: block;
    }

    .topbar-user {
        margin-left: auto;
    }

    .dashboard-shell {
        width: min(100% - 24px, 1200px);
        margin-top: 18px;
    }

    .dashboard-hero,
    .dashboard-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 520px) {
    body {
        padding: 12px;
    }

    .topbar {
        padding: 12px 14px;
    }

    .topbar-brand {
        font-size: 1rem;
    }

    .topbar-link {
        padding: 8px 10px;
        font-size: 0.92rem;
    }

    .topbar-hello {
        display: none;
    }

    .dashboard-shell {
        width: 100%;
        margin: 14px auto 28px;
    }

    .dashboard-hero,
    .action-card,
    .dashboard-note {
        padding: 18px;
    }

    .clients-hero {
        flex-direction: column;
    }

    .clients-toolbar-actions {
        justify-items: start;
    }

    .clients-table-card,
    .documents-filters-section,
    .modal-dialog {
        padding: 18px;
    }

    .clients-table-header,
    .modal-header {
        flex-direction: column;
        align-items: stretch;
    }

    .clients-table-controls {
        justify-content: flex-start;
    }

    .table-filter {
        width: 100%;
        flex-wrap: wrap;
    }

    .table-filter input {
        width: 100%;
    }

    .client-common-grid,
    .modal-grid {
        grid-template-columns: 1fr;
    }

    .products-page .modal-grid .unit-name-row {
        max-width: none;
    }
}

@media (max-width: 1080px) {
    .documents-table-controls {
        grid-template-columns: repeat(6, minmax(0, 1fr));
    }

    .documents-filter-period-from,
    .documents-filter-period-to,
    .documents-filter-number,
    .documents-filter-document-type,
    .documents-filter-payment-type,
    .documents-filter-status {
        grid-column: span 3;
    }

    .documents-filter-client,
    .documents-filter-actions {
        grid-column: span 6;
    }

    .documents-filter-actions {
        justify-content: flex-start;
        grid-column: 1 / -1;
    }
}

@media (max-width: 680px) {
    .documents-table-controls {
        grid-template-columns: 1fr;
    }

    .documents-filter-period-from,
    .documents-filter-period-to,
    .documents-filter-client,
    .documents-filter-number,
    .documents-filter-document-type,
    .documents-filter-payment-type,
    .documents-filter-status,
    .documents-filter-actions {
        grid-column: 1;
    }

    .documents-filter-actions {
        justify-content: stretch;
    }

    .documents-filter-actions .table-action-button {
        width: 100%;
    }
}

@media print {
    @page {
        size: A4 landscape;
        margin: 10mm;
    }

    .reports-page {
        background: #fff !important;
        padding: 0;
        font-size: 11px;
        line-height: 1.25;
    }

    .reports-page .clients-table,
    .reports-page .clients-table th,
    .reports-page .clients-table td,
    .reports-page .clients-toolbar-note {
        font-size: 10px;
    }

    .reports-page .clients-table th,
    .reports-page .clients-table td {
        padding: 5px 8px;
        line-height: 1.15;
    }

    .reports-page .status-chip {
        font-size: 9px;
        padding: 2px 6px;
        line-height: 1.1;
    }

    .reports-page .topbar,
    .reports-page .documents-table-controls,
    .reports-page .clients-table-header .clients-count,
    .reports-page .documents-filter-actions,
    .reports-page .table-action-button {
        display: none !important;
    }

    .reports-page .dashboard-shell,
    .reports-page .clients-table-card {
        width: 100%;
        margin: 0;
        padding: 0;
        border: 0;
        box-shadow: none;
        background: #fff;
    }

    .reports-page .table-wrap {
        margin-top: 0 !important;
        border: 0;
        border-radius: 0;
        overflow: visible;
    }

    .reports-page .clients-table {
        min-width: 0;
    }
}
