:root {
    --bg: #f6f8fb;
    --surface: #ffffff;
    --surface-soft: #f1f5f9;
    --text: #172033;
    --muted: #64748b;
    --border: #dbe4ef;
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-soft: #dbeafe;
    --success: #15803d;
    --warning: #b45309;
    --danger: #b91c1c;
    --shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
    --shadow-soft: 0 6px 18px rgba(15, 23, 42, 0.05);
    --radius: 8px;
    --header-text: #102033;
    --content-max-width: 1420px;
    --page-x: clamp(16px, 2vw, 28px);
}

* {
    box-sizing: border-box;
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    min-height: 100vh;
    margin: 0;
    font-family: "Segoe UI", Arial, sans-serif;
    font-size: 1rem;
    line-height: 1.55;
    color: var(--text);
    background: var(--bg);
}

img,
svg,
video {
    max-width: 100%;
    height: auto;
}

a {
    color: var(--primary);
}

hr {
    margin: 24px 0;
    border: 0;
    border-top: 1px solid var(--border);
}

h1,
h2,
h3 {
    line-height: 1.2;
    color: #111827;
}

h1,
h2 {
    margin: 0 0 18px;
}

h3 {
    margin: 20px 0 12px;
}

.header {
    position: sticky;
    top: 0;
    z-index: 20;
    padding: 14px var(--page-x);
    color: var(--header-text);
    background: rgba(255, 255, 255, 0.94);
    border-bottom: 1px solid var(--border);
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.06);
    backdrop-filter: blur(14px);
}

.header-top,
.nav,
.container {
    width: min(100%, var(--content-max-width));
    margin-inline: auto;
}

.admin-billing-reminders {
    margin-top: 12px;
    padding: 10px 14px;
    color: #b91c1c;
    background: #fff1f2;
    border: 1px solid #fecaca;
    border-radius: 8px;
    font-weight: 700;
}

.admin-billing-reminders p {
    margin: 4px 0;
}

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

.brand {
    display: inline-flex;
    align-items: center;
    min-width: 0;
    gap: 12px;
    color: inherit;
    text-decoration: none;
}

.brand-mark {
    display: inline-flex;
    flex: 0 0 40px;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    color: #ffffff;
    font-weight: 800;
    border-radius: var(--radius);
    background: linear-gradient(135deg, #1d4ed8 0%, #0f766e 100%);
    box-shadow: 0 8px 18px rgba(37, 99, 235, 0.18);
}

.header h1 {
    margin: 0 0 3px;
    font-size: clamp(1.1rem, 1.2vw, 1.35rem);
    letter-spacing: 0;
}

.header-subtitle {
    margin: 0;
    color: var(--muted);
    font-size: 0.92rem;
}

.header-actions {
    display: flex;
    flex-shrink: 0;
    align-items: center;
    gap: 10px;
}

.logout-form {
    display: block;
    margin: 0;
}

.logout-button,
.menu-toggle {
    min-height: 42px;
    font-weight: 700;
    color: var(--text);
    cursor: pointer;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.logout-button {
    padding: 9px 14px;
}

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

.menu-toggle {
    display: none;
    width: 44px;
    padding: 8px;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 5px;
}

.menu-toggle span {
    width: 20px;
    height: 2px;
    background: currentColor;
    border-radius: 999px;
    transition: transform 0.18s ease, opacity 0.18s ease;
}

.menu-toggle.open span:nth-child(1) {
    transform: translateY(7px) rotate(45deg);
}

.menu-toggle.open span:nth-child(2) {
    opacity: 0;
}

.menu-toggle.open span:nth-child(3) {
    transform: translateY(-7px) rotate(-45deg);
}

.nav {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}

.nav a {
    display: inline-flex;
    align-items: center;
    min-height: 40px;
    gap: 7px;
    padding: 8px 11px;
    font-weight: 650;
    color: #334155;
    text-decoration: none;
    border: 1px solid transparent;
    border-radius: var(--radius);
    transition: background 0.18s ease, color 0.18s ease, border-color 0.18s ease;
}

.nav a:hover,
.nav a.active {
    color: #1e3a8a;
    background: var(--primary-soft);
    border-color: #bfdbfe;
}

.nav-icon {
    width: 1.2em;
    color: var(--primary);
    text-align: center;
}

.container {
    padding: 26px var(--page-x) 40px;
}

.page-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    margin-bottom: 18px;
}

.page-header h2 {
    margin-bottom: 0;
}

.page-header .action-bar {
    margin: 0;
}

.section {
    margin-top: 24px;
}

.section-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}

.section-header h3 {
    margin: 0;
}

.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr));
    gap: 16px;
}

.card,
.auth-card,
.page-card {
    width: 100%;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.card {
    padding: 18px;
}

.card h3 {
    margin-top: 0;
    color: var(--muted);
    font-size: 0.96rem;
    font-weight: 700;
}

.card h1 {
    margin-bottom: 0;
    color: #0f172a;
    font-size: clamp(1.55rem, 2vw, 2rem);
}

.auth-card,
.page-card {
    max-width: 560px;
    margin: 24px auto;
    padding: 24px;
}

.auth-card h1,
.page-card h1 {
    margin-top: 0;
}

.table-wrapper {
    width: 100%;
    overflow-x: auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.table {
    width: 100%;
    min-width: 760px;
    border-collapse: separate;
    border-spacing: 0;
    background: var(--surface);
}

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

.table th {
    color: #334155;
    font-size: 0.82rem;
    font-weight: 800;
    text-transform: uppercase;
    white-space: nowrap;
    background: var(--surface-soft);
}

.table tbody tr:hover {
    background: #f8fafc;
}

.table tr:last-child td {
    border-bottom: 0;
}

.table .numeric-cell {
    font-variant-numeric: tabular-nums;
    text-align: right;
    white-space: nowrap;
}

form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

label {
    display: inline-block;
    margin-bottom: 5px;
    color: #334155;
    font-weight: 700;
}

input,
select,
textarea,
button {
    font: inherit;
}

input,
select,
textarea {
    width: 100%;
    max-width: 100%;
    min-height: 42px;
    padding: 10px 12px;
    color: var(--text);
    background: var(--surface);
    border: 1px solid #cbd5e1;
    border-radius: var(--radius);
}

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

input:focus,
select:focus,
textarea:focus,
button:focus-visible,
a:focus-visible {
    outline: 3px solid rgba(37, 99, 235, 0.2);
    outline-offset: 2px;
    border-color: var(--primary);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    padding: 9px 14px;
    color: #ffffff;
    font-weight: 700;
    line-height: 1.2;
    text-align: center;
    text-decoration: none;
    cursor: pointer;
    background: var(--primary);
    border: 1px solid var(--primary);
    border-radius: var(--radius);
    transition: background 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
}

.btn:hover {
    background: var(--primary-dark);
    border-color: var(--primary-dark);
    box-shadow: 0 8px 18px rgba(37, 99, 235, 0.16);
}

.btn-secondary {
    color: #334155;
    background: #f8fafc;
    border-color: #cbd5e1;
}

.btn-secondary:hover {
    color: #0f172a;
    background: #e2e8f0;
    border-color: #cbd5e1;
    box-shadow: none;
}

.btn-danger {
    background: var(--danger);
    border-color: var(--danger);
}

.status {
    display: inline-flex;
    align-items: center;
    min-height: 28px;
    padding: 5px 10px;
    font-size: 0.82rem;
    font-weight: 800;
    text-align: center;
    border-radius: 999px;
}

.status-draft { background: #fef3c7; color: #92400e; }
.status-sent { background: #dbeafe; color: #1e40af; }
.status-accepted-by-warehouse { background: #dcfce7; color: #166534; }
.status-edited-by-warehouse { background: #ffedd5; color: #9a3412; }
.status-mismatch { background: #fee2e2; color: #991b1b; }
.status-linked-to-combined { background: #ede9fe; color: #5b21b6; }
.status-sent-to-producer { background: #f3e8ff; color: #7e22ce; }
.status-closed { background: #e5e7eb; color: #374151; }
.status-active { background: #dcfce7; color: #166534; }
.status-inactive { background: #fef3c7; color: #92400e; }
.status-archived { background: #e5e7eb; color: #374151; }
.status-yes { background: #dbeafe; color: #1e40af; }
.status-no { background: #f1f5f9; color: #475569; }

.page-actions,
.filter-bar,
.action-bar,
.inline-actions,
.table-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
}

.page-actions,
.filter-bar,
.action-bar {
    margin: 12px 0 18px;
}

/* Desktop filter bar: Variant 1 / GitHub-Jira style */
.filter-bar {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 180px), 1fr));
    align-items: end;
    gap: 12px;
    width: 100%;
    padding: 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: calc(var(--radius) + 4px);
    box-shadow: 0 6px 18px rgba(15, 23, 42, 0.04);
}

.filter-bar > * {
    min-width: 0;
}

.filter-bar label {
    display: block;
    margin-bottom: 6px;
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.filter-bar input,
.filter-bar select {
    width: 100%;
    min-width: 0;
    height: 42px;
    background: #ffffff;
}

.filter-bar input[type="text"],
.filter-bar input[type="search"] {
    width: 100%;
}

.filter-bar .btn,
.filter-bar button {
    width: auto;
    min-width: 104px;
    height: 42px;
    white-space: nowrap;
}

.filter-bar .btn-secondary {
    min-width: 92px;
}

.filter-bar form {
    display: contents;
}

.filter-bar .filter-actions,
.filter-bar .actions {
    display: flex;
    justify-content: flex-end;
    align-items: end;
    gap: 10px;
}

.table-actions form,
.inline-actions form,
.action-bar form {
    display: inline-flex !important;
    flex-direction: row;
    align-items: center;
    gap: 8px;
    margin: 0;
}

.table-actions select,
.inline-actions select {
    width: auto;
    min-width: 130px;
}

.auth-card form,
.page-card form {
    width: 100%;
}

.auth-card .btn,
.page-card .btn {
    width: auto;
    min-width: 140px;
}

.document-edit-table {
    width: 100%;
    table-layout: fixed;
    border-collapse: separate;
    border-spacing: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.document-edit-name-col {
    width: auto;
}

.document-edit-price-col {
    width: 88px;
}

.document-edit-quantity-col {
    width: 104px;
}

.document-view-previous-col {
    width: 104px;
}

.document-view-quantity-col {
    width: 92px;
}

.document-edit-table th,
.document-edit-table td {
    padding: 10px 12px;
    vertical-align: middle;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.document-edit-table th {
    color: #334155;
    font-size: 0.82rem;
    font-weight: 800;
    text-transform: uppercase;
    white-space: nowrap;
    background: var(--surface-soft);
}

.document-edit-table tr:last-child td {
    border-bottom: 0;
}

.document-edit-table tbody tr:hover {
    background: #f8fafc;
}

.document-edit-table td:first-child {
    overflow-wrap: anywhere;
    word-break: normal;
    font-size: 1.03rem;
    font-weight: 650;
    line-height: 1.3;
}

.document-edit-table td:nth-child(2) {
    white-space: nowrap;
    font-size: 1.08rem;
    font-weight: 750;
}

.document-view-table td:nth-child(3),
.document-view-table td:nth-child(4) {
    white-space: nowrap;
    font-size: 1.04rem;
    font-weight: 750;
}

.document-quantity-input {
    min-height: 44px;
    padding: 8px 10px;
    font-size: 1.02rem;
    font-weight: 750;
}

.admin-documents-page h2 {
    margin-bottom: 14px;
}

.admin-document-panel {
    gap: 14px;
    padding: 16px;
    margin-top: 18px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-soft);
}

.admin-document-panel h3 {
    margin: 0;
}

.admin-document-panel > div:first-of-type {
    max-width: 520px;
}

.admin-document-panel .table {
    box-shadow: none;
}

.admin-documents-table,
.admin-history-table,
.admin-linked-table {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow-soft);
}

.admin-documents-table th,
.admin-documents-table td,
.admin-history-table th,
.admin-history-table td,
.admin-linked-table th,
.admin-linked-table td {
    padding: 10px 12px;
}

.admin-documents-table td:nth-child(2),
.admin-linked-table td:nth-child(2) {
    font-weight: 700;
}

.admin-documents-table td:nth-child(5),
.admin-history-table td:nth-child(5),
.admin-history-table td:nth-child(6) {
    white-space: nowrap;
    font-weight: 750;
}

.admin-documents-table input[type="checkbox"] {
    width: 20px;
    min-height: 20px;
    accent-color: var(--primary);
}

.pagination-actions {
    justify-content: space-between;
    padding-top: 4px;
}

.pagination {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-top: 16px;
}

.pagination-info {
    color: var(--muted);
    font-weight: 700;
}

.pagination-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.alert {
    padding: 12px 16px;
    margin: 15px 0;
    font-weight: 650;
    border-radius: var(--radius);
}

.alert-error {
    color: #991b1b;
    background: #fee2e2;
    border: 1px solid #fecaca;
}

.alert-success {
    color: #166534;
    background: #dcfce7;
    border: 1px solid #bbf7d0;
}

@media (min-width: 1600px) {
    :root {
        --content-max-width: 1500px;
    }
}

@media (max-width: 1280px) {
    :root {
        --content-max-width: 1180px;
    }

    .nav a {
        padding-inline: 9px;
        font-size: 0.94rem;
    }

    .card-grid {
        grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr));
    }
}

@media (max-width: 1024px) {
    .header-top {
        align-items: flex-start;
    }

    .nav {
        gap: 6px;
    }

    .table {
        min-width: 700px;
    }

    .filter-bar {
        grid-template-columns: repeat(auto-fit, minmax(min(100%, 180px), 1fr));
    }

    .filter-bar input,
    .filter-bar select {
        width: 100%;
    }
}

@media (max-width: 900px) {
    .header {
        padding-block: 12px;
    }

    .header-top {
        margin-bottom: 0;
    }

    .brand-mark {
        width: 36px;
        height: 36px;
        flex-basis: 36px;
    }

    .header h1 {
        font-size: 1.1rem;
    }

    .header-subtitle {
        display: none;
    }

    .menu-toggle {
        display: inline-flex;
    }

    .logout-button {
        min-height: 40px;
        padding: 8px 11px;
    }

    .nav {
        display: none;
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
        margin-top: 12px;
        padding-top: 12px;
        border-top: 1px solid var(--border);
    }

    .nav.open {
        display: flex;
    }

    .nav a {
        width: 100%;
        min-height: 44px;
        justify-content: flex-start;
        padding: 10px 12px;
        background: #f8fafc;
        border-color: var(--border);
    }

    .container {
        padding-block: 18px 32px;
    }

    h1,
    h2 {
        font-size: 1.35rem;
    }

    .card-grid {
        grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr));
        gap: 12px;
    }

    .filter-bar,
    .action-bar,
    .page-actions,
    .page-header,
    .section-header,
    .pagination,
    .pagination-buttons,
    .inline-actions,
    .table-actions {
        flex-direction: column;
        align-items: stretch;
    }

    .filter-bar {
        display: flex;
        grid-template-columns: none;
    }

    .filter-bar input,
    .filter-bar select,
    .table-actions select,
    .inline-actions select {
        width: 100%;
        min-width: 0;
    }

    .table-actions form,
    .inline-actions form,
    .action-bar form {
        width: 100%;
        flex-direction: column;
        align-items: stretch;
    }

    .btn,
    .auth-card .btn,
    .page-card .btn {
        width: 100%;
    }
}

@media (max-width: 480px) {
    body {
        font-size: 15px;
    }

    .document-edit-price-col {
        width: 66px;
    }

    .document-edit-quantity-col {
        width: 78px;
    }

    .document-view-previous-col {
        width: 72px;
    }

    .document-view-quantity-col {
        width: 62px;
    }

    .document-edit-table th,
    .document-edit-table td {
        padding: 8px 7px;
    }

    .document-edit-table th {
        font-size: 0.72rem;
        white-space: normal;
    }

    .document-edit-table td:first-child {
        font-size: 0.94rem;
    }

    .document-edit-table td:nth-child(2) {
        font-size: 0.96rem;
    }

    .document-view-table td:nth-child(3),
    .document-view-table td:nth-child(4) {
        font-size: 0.94rem;
    }

    .document-quantity-input {
        min-height: 40px;
        padding: 7px 6px;
        font-size: 0.96rem;
    }

    .header-actions {
        gap: 6px;
    }

    .logout-button {
        padding-inline: 9px;
        font-size: 0.9rem;
    }

    .container {
        padding-block: 12px 24px;
    }

    .card,
    .auth-card,
    .page-card {
        padding: 16px;
    }
}

/* Shared document-style tables and controls. */
.table-wrapper .table {
    border: 0;
    border-radius: 0;
    box-shadow: none;
}

.table td {
    font-size: 1.03rem;
    line-height: 1.3;
}

.table td:first-child {
    font-weight: 650;
}

.table .numeric-cell {
    font-size: 1.04rem;
    font-weight: 750;
}

.table th:first-child,
.document-edit-table th:first-child {
    border-top-left-radius: var(--radius);
}

.table th:last-child,
.document-edit-table th:last-child {
    border-top-right-radius: var(--radius);
}

input[type="checkbox"],
input[type="radio"] {
    width: 20px;
    min-height: 20px;
    height: 20px;
    padding: 0;
    accent-color: var(--primary);
}

.container > form > br {
    display: none;
}

.container > form {
    margin-block: 16px;
}

@media (max-width: 480px) {
    .table th,
    .table td {
        padding: 8px 7px;
    }

    .table td {
        font-size: 0.94rem;
    }
}

/* Keep regular tables readable without horizontal scrolling on mobile. */
@media (max-width: 900px) {
    .table-wrapper {
        overflow: visible;
        background: transparent;
        border: 0;
        box-shadow: none;
    }

    .table {
        display: block;
        width: 100%;
        min-width: 0;
        overflow: visible;
        background: transparent;
        border: 0;
        box-shadow: none;
    }

    .table thead {
        display: none;
    }

    .table,
    .table tbody,
    .table tr,
    .table td {
        display: block;
    }

    .table tr {
        width: 100%;
        padding: 12px;
        margin-bottom: 12px;
        background: var(--surface);
        border: 1px solid var(--border);
        border-radius: var(--radius);
        box-shadow: var(--shadow-soft);
    }

    .table td {
        min-width: 0;
        padding: 8px 0;
        border: 0;
    }

    .table td + td {
        border-top: 1px solid #eef2f7;
    }

    .table td::before {
        content: attr(data-label);
        display: block;
        margin-bottom: 3px;
        color: var(--muted);
        font-size: 0.78rem;
        font-weight: 800;
        text-transform: uppercase;
    }

    .container,
    .container form,
    .table-wrapper,
    .table td {
        min-width: 0;
        max-width: 100%;
    }

    .table-wrapper .table td,
    .table .numeric-cell {
        white-space: normal;
        overflow-wrap: anywhere;
        text-align: left;
    }

    .filter-bar > div,
    .filter-bar .filter-actions,
    .filter-bar .actions {
        width: 100%;
        min-width: 0;
    }
}
.partner-filter {
    position: relative;
    min-width: 0;
}
.partner-filter summary {
    min-height: 42px;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    cursor: pointer;
}
.partner-filter-options {
    position: absolute;
    z-index: 25;
    width: 100%;
    min-width: 0;
    max-height: 280px;
    overflow-y: auto;
    padding: 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.filter-bar .partner-filter-options label {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 0;
    text-transform: none;
    overflow-wrap: anywhere;
}
.filter-bar .partner-filter-options input[type="checkbox"] {
    flex: 0 0 20px;
    width: 20px;
    height: 20px;
    min-height: 20px;
}
@media (max-width: 900px) {
    .partner-filter-options { position: static; }
}

.notification-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 23px;
    height: 23px;
    padding: 0 6px;
    border-radius: 999px;
    background: var(--danger);
    color: white;
    font-size: 0.75rem;
    font-weight: 800;
    line-height: 1;
}
.menu-toggle.has-unread {
    position: relative;
}
.menu-toggle.has-unread::after {
    content: '';
    position: absolute;
    top: 3px;
    right: 3px;
    width: 10px;
    height: 10px;
    border: 2px solid var(--surface);
    border-radius: 50%;
    background: var(--danger);
}
