﻿:root {
    --card: #ffffff;
    --text: #1f2a33;
    --muted: #5b6b78;
    --accent: #0f766e;
    --accent-hover: #0b5f59;
    --danger: #b42318;
    --danger-hover: #8f1c13;
    --line: #d8e0e6;
    --success-bg: #dcfce7;
    --success-text: #166534;
    --error-bg: #fee2e2;
    --error-text: #991b1b;
}

* {
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

body {
    margin: 0;
    font-family: "Segoe UI", Tahoma, sans-serif;
    background: linear-gradient(180deg, #ecf4f8 0%, #f9fbfd 100%);
    color: var(--text);
}

.container {
    max-width: 1150px;
    margin: 0 auto;
    padding: 16px;
}

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

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

h1 {
    font-size: 1.6rem;
    margin: 8px 0;
}

h2 {
    margin: 0 0 14px;
    font-size: 1.2rem;
}

h3 {
    margin: 8px 0 12px;
}

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

.nav a,
.link-btn {
    text-decoration: none;
    color: #084c61;
    background: #dbedf6;
    border: 1px solid #bfddeb;
    padding: 8px 12px;
    border-radius: 10px;
    font-weight: 600;
    display: inline-block;
}

.card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 16px;
    margin-bottom: 16px;
    box-shadow: 0 8px 24px rgba(31, 42, 51, 0.06);
}

.form-grid,
.login-form,
.admin-create-form,
.profile-form,
.position-form,
.filter-form {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 12px;
    align-items: end;
}

.login-form,
.profile-form,
.position-form,
.filter-form {
    max-width: 780px;
}

label {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 0.95rem;
    color: var(--muted);
}

input,
select,
button {
    font: inherit;
    padding: 10px 11px;
    border-radius: 10px;
    border: 1px solid #b7c5cf;
}

input:focus,
select:focus {
    outline: 2px solid rgba(15, 118, 110, 0.25);
    border-color: var(--accent);
}

button {
    cursor: pointer;
    border: none;
    background: var(--accent);
    color: #fff;
    font-weight: 600;
    width: auto;
}

button:hover {
    background: var(--accent-hover);
}

button.danger {
    background: var(--danger);
}

button.danger:hover {
    background: var(--danger-hover);
}

.compact-btn {
    padding: 8px 12px;
    font-size: 0.9rem;
    line-height: 1.2;
}

.name-link {
    color: #1f2a33;
    text-decoration: none;
    font-weight: 700;
}

.name-link:hover {
    text-decoration: none;
}

.col-center {
    text-align: center;
}

.table-wrap {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 860px;
}

th,
td {
    border-bottom: 1px solid var(--line);
    text-align: left;
    padding: 10px;
    font-size: 0.95rem;
    vertical-align: middle;
}

th {
    background: #f8fafb;
}

.inline-form {
    margin: 0;
}

.actions-cell {
    white-space: nowrap;
}

.actions-cell .link-btn,
.actions-cell .inline-form {
    display: inline-flex;
    vertical-align: middle;
    margin-right: 6px;
    align-items: center;
}

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

.icon-btn {
    border: 1px solid #bfddeb;
    background: #dbedf6;
    border-radius: 10px;
    width: 34px;
    height: 34px;
    padding: 7px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.icon-btn img {
    width: 18px;
    height: 18px;
    display: block;
}

.icon-btn-danger {
    background: #fee2e2;
    border-color: #fecaca;
}

.qr-thumb {
    width: 54px;
    height: 54px;
    border-radius: 6px;
    border: 1px solid var(--line);
}

.qr-large {
    width: 220px;
    max-width: 100%;
    border-radius: 12px;
    border: 1px solid var(--line);
}

.details-grid {
    display: grid;
    gap: 8px;
    margin-bottom: 14px;
}

.qr-block {
    margin: 14px 0;
}

.reader {
    width: 100%;
    max-width: 420px;
    margin-bottom: 16px;
}

.scan-result {
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 12px;
    margin-bottom: 14px;
    background: #f8fafb;
}

.scan-result p {
    margin: 6px 0;
}

.manual-form {
    display: grid;
    gap: 10px;
    max-width: 420px;
}

.mobile-only-select {
    display: none;
    margin-top: 6px;
}

.row-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 14px;
    align-items: center;
}

.service-item,
.page-item {
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 12px;
    margin-bottom: 12px;
    background: #f8fafc;
}

.service-item legend,
.page-item legend {
    font-weight: 700;
    color: var(--text);
    padding: 0 6px;
}

.admin-section {
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 10px 12px 14px;
    margin-bottom: 14px;
    background: #fbfdff;
}

.site-content-form {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 14px;
}

.site-content-form .admin-section {
    margin-bottom: 0;
}

.admin-section-head {
    margin-bottom: 8px;
}

.admin-section-toggle {
    width: 100%;
    text-align: left;
    border: 1px solid var(--line);
    background: #eef4f8;
    color: var(--text);
    font-weight: 700;
    border-radius: 10px;
    padding: 10px 12px;
}

.admin-section.is-open .admin-section-toggle {
    background: #dde9f0;
}

.admin-section-toggle:hover {
    background: #d6e5ef;
}

.page-media-list {
    display: grid;
    gap: 6px;
    margin-top: 8px;
}

.site-content-form label {
    width: 100%;
}

.site-content-form input,
.site-content-form textarea,
.site-content-form select {
    width: 100%;
}

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

.stock-tools {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 8px;
}

.bulk-writeoff-btn {
    min-width: 184px !important;
    width: 184px;
    height: 42px;
    font-size: 0.95rem;
}

.users-list {
    display: grid;
    gap: 10px;
}

.user-details {
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #fcfdff;
}

.user-details summary {
    cursor: pointer;
    padding: 12px;
    font-weight: 600;
}

.user-card {
    border-top: 1px solid var(--line);
    padding: 12px;
    display: grid;
    gap: 10px;
}

.position-inline-form {
    display: flex;
    gap: 8px;
    align-items: center;
}

.position-inline-form input {
    min-width: 170px;
}

.position-edit-form {
    display: inline-flex;
    gap: 8px;
    align-items: center;
}

.position-edit-form input {
    min-width: 180px;
}

.position-label {
    font-weight: 600;
}

.perm-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 8px;
}

.form-span-all {
    grid-column: 1 / -1;
}

.admin-create-user-form .role-stack {
    display: grid;
    gap: 8px;
    align-content: end;
}

.check-inline {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 8px;
}

.check-inline input {
    width: auto;
}

.weights-cell {
    white-space: normal;
    word-break: break-word;
    max-width: 360px;
}

.weights-columns {
    display: flex;
    justify-content: center;
    column-gap: 6px;
    align-items: flex-start;
}

.weights-split-col {
    width: calc(var(--weight-item-ch, 3ch) + 1.2ch);
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.weights-split-col .weight-item {
    min-width: calc(var(--weight-item-ch, 3ch) + 0.8ch);
    padding: 0 0.3ch;
    white-space: nowrap;
    text-align: center;
}

.balances-table-uniform {
    table-layout: fixed;
}

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

.filter-form .search-input {
    min-width: 360px;
    flex: 1 1 360px;
}

.filter-form .search-btn {
    min-width: 88px;
    text-align: center;
    justify-content: center;
    display: inline-flex;
    align-items: center;
    padding: 8px 10px;
}

.filter-form-location {
    align-items: flex-end;
}

.filter-label-inline {
    margin: 0;
}

.filter-form-location select,
.filter-form-location .search-btn {
    height: 42px;
}

tr.skip-print {
    opacity: 0.45;
}

.location-section {
    margin-top: 12px;
}

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

.empty {
    margin: 2px 0;
}

.landscape-table-v3 {
    width: max-content;
    min-width: max-content;
    table-layout: fixed;
}

.landscape-table-v3 th,
.landscape-table-v3 td {
    text-align: center;
    border-right: 1px solid var(--line);
}

.landscape-table-v3 tr:first-child > * {
    border-top: 1px solid var(--line);
}

.landscape-table-v3 tr > *:first-child {
    border-left: 1px solid var(--line);
}

.landscape-table-v3 .row-header-cell {
    text-align: left;
    white-space: nowrap;
    width: 1%;
    min-width: 0;
}

.landscape-table-v3 .material-cell {
    width: max(
        130px,
        calc(var(--split-multiplier, 1) * (var(--weight-item-ch, 3ch) + 2ch))
    );
    min-width: 130px;
}

.name-cell-top {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    margin-bottom: 5px;
}

.split-input {
    width: 56px;
    min-width: 56px;
    height: 28px;
    border-radius: 6px;
    text-align: center;
    padding: 2px 4px;
}

.name-cell-title {
    text-align: center;
    white-space: normal;
    word-break: break-word;
    overflow-wrap: anywhere;
    line-height: 1.2;
}

.name-cell-label {
    display: inline-flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 8px;
    color: var(--text);
}

.col-disabled {
    opacity: 0.45;
    background: #eef3f7;
}

.print-dialog {
    position: fixed;
    inset: 0;
    background: rgba(31, 42, 51, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 50;
}

.print-dialog-card {
    width: min(430px, calc(100vw - 32px));
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 14px;
}

.print-dialog-wide {
    width: min(900px, calc(100vw - 32px));
}

.compact-table-wrap {
    max-height: 45vh;
}

.compact-preview-table {
    min-width: 620px;
}

.row-actions-between {
    justify-content: space-between;
}

.bulk-form-grid {
    display: grid;
    gap: 10px;
}

.labels-print-area {
    display: grid;
    gap: 12px;
}

.labels-print-only {
    display: none;
}

.labels-page {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    min-height: 260mm;
    display: grid;
    grid-template-rows: 1fr 1fr;
    overflow: hidden;
}

.label-half {
    border-bottom: 1px dashed #9ca3af;
    padding: 6mm;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.label-half:last-child {
    border-bottom: none;
}

.label-half-inner {
    width: 100%;
    height: 100%;
    display: grid;
    grid-template-columns: 2fr 6fr;
    gap: 6mm;
    align-items: center;
    justify-items: center;
}

.label-qr-wrap {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 3mm;
}

.label-qr-wrap img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    border: 1px solid #cbd5e1;
}

.label-fields {
    display: grid;
    gap: 4mm;
    width: 100%;
    align-content: center;
}

.label-row {
    display: flex;
    align-items: baseline;
    gap: 4mm;
    border-bottom: 1px solid #d1d5db;
    padding-bottom: 2mm;
    font-size: 1.05rem;
    width: 100%;
    min-width: 0;
}

.label-row span {
    flex: 0 0 40%;
    max-width: 40%;
    white-space: nowrap;
    text-align: left;
}

.label-row strong {
    font-weight: 700;
    flex: 1 1 auto;
    min-width: 0;
    text-align: left;
    white-space: normal;
    overflow-wrap: anywhere;
}

.qr-portrait {
    display: none;
    width: 100%;
    justify-content: center;
    align-items: center;
    padding-top: 2mm;
}

.qr-portrait img {
    width: min(100%, 42mm);
    height: auto;
    object-fit: contain;
    border: 1px solid #cbd5e1;
}

.label-row-no {
    width: 50%;
    margin: 0 auto;
    justify-content: center;
    text-align: center;
}

.label-row-no span {
    flex: 0 0 auto;
    max-width: none;
    text-align: center;
}

.label-row-no strong {
    flex: 0 0 auto;
    text-align: center;
}

.label-corner-qrs {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.label-corner-qr {
    position: absolute;
    width: 30mm;
    height: 30mm;
    object-fit: contain;
    border: 1px solid #cbd5e1;
    background: #fff;
}

.corner-tl {
    top: 2mm;
    left: 2mm;
}

.corner-tr {
    top: 2mm;
    right: 2mm;
}

.corner-bl {
    bottom: 2mm;
    left: 2mm;
}

.corner-br {
    bottom: 2mm;
    right: 2mm;
}

.labels-landscape .corner-tl,
.labels-landscape .corner-bl {
    left: calc(25% + 2mm);
}

.stock-found {
    color: #15803d;
    font-weight: 700;
}

.stock-missing {
    color: #b91c1c;
    font-weight: 700;
}

.inventory-row-scanned {
    background: #ecfdf3;
}

.inventory-row-missing {
    background: #fef2f2;
}

.confirm-summary-label {
    text-align: right;
}

.confirm-summary-weight {
    font-size: 1.08rem;
    font-weight: 700;
}

.print-datetime {
    display: none;
    font-size: 0.85rem;
    color: #111827;
}

.material-editor-table input[type="text"] {
    width: 100%;
    min-width: 180px;
}

.alerts {
    display: grid;
    gap: 8px;
    margin-bottom: 14px;
}

.alert {
    padding: 10px 12px;
    border-radius: 10px;
    font-size: 0.95rem;
}

.alert.success {
    background: var(--success-bg);
    color: var(--success-text);
}

.alert.error {
    background: var(--error-bg);
    color: var(--error-text);
}

@media (max-width: 768px) {
    h1 {
        font-size: 1.3rem;
    }

    .nav a,
    .link-btn {
        font-size: 0.9rem;
        padding: 7px 10px;
    }

    table,
    .landscape-table {
        min-width: 720px;
    }

    .qr-thumb {
        width: 46px;
        height: 46px;
    }

    .row-between {
        flex-direction: column;
        align-items: flex-start;
    }

    .filter-form .search-input {
        min-width: 240px;
        flex-basis: 240px;
    }

    .mobile-only-select {
        display: block;
    }
}

@media print {
    body {
        background: #fff;
    }

    .container {
        max-width: none;
        width: 100%;
        padding: 0;
    }

    .no-print {
        display: none !important;
    }

    .print-datetime {
        display: block;
        margin-bottom: 3mm;
    }

    .card {
        box-shadow: none;
        border: none;
        padding: 0;
        margin: 0;
    }

    table {
        min-width: 0;
    }

    .balances-print-full .table-wrap {
        overflow: visible;
    }

    .balances-print-full table {
        width: 100% !important;
        min-width: 0 !important;
    }

    .balances-print-full .landscape-table-v3 {
        width: max-content !important;
        min-width: max-content !important;
        table-layout: fixed;
    }

    .balances-print-full th,
    .balances-print-full td {
        font-size: 1.2rem;
    }

    .balances-print-full th {
        font-size: 1.3rem;
    }

    tr.skip-print {
        display: none !important;
    }

    .col-skip-print {
        display: none !important;
    }

    .location-section.section-skip-print {
        display: none !important;
    }

    .labels-print-area {
        display: grid !important;
        gap: 0;
    }

    .labels-page {
        border: none;
        border-radius: 0;
        min-height: 0;
        page-break-after: always;
    }

    .labels-page:last-child {
        page-break-after: auto;
    }

    .labels-landscape .labels-page {
        width: 287mm;
        height: 200mm;
        margin: 0 auto;
        grid-template-rows: 1fr 1fr;
    }

    .labels-portrait .labels-page {
        width: 200mm;
        height: 287mm;
        margin: 0 auto;
        grid-template-rows: 1fr 1fr;
    }

    .label-half-inner {
        grid-template-columns: 2fr 6fr;
        gap: 6mm;
        align-items: center;
        justify-items: center;
    }

    .label-row {
        font-size: 2.52rem;
        line-height: 1.05;
    }

    .label-row-no {
        width: 50%;
    }

    .labels-landscape .qr-landscape {
        display: flex;
    }

    .labels-landscape .qr-portrait {
        display: none;
    }

    .labels-portrait .label-half-inner {
        grid-template-columns: 1fr;
        gap: 4mm;
    }

    .labels-portrait .qr-landscape {
        display: none;
    }

    .labels-portrait .qr-portrait {
        display: flex;
    }

}
