body[data-page="documents"].pos-app {
    height: 100vh;
    overflow: hidden;
}

.documents-page {
    max-width: 960px;
    margin: 0 auto;
    padding: 20px 16px 40px;
    height: calc(100vh - 56px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.documents-intro {
    margin: 0 0 20px;
    color: var(--pos-muted, #64748b);
    font-size: 0.95rem;
}

.documents-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 12px;
}

.documents-card {
    display: block;
    padding: 16px 14px;
    border: 1px solid var(--pos-line, #e2e8f0);
    border-radius: 14px;
    background: #fff;
    text-decoration: none;
    color: inherit;
    transition: border-color 0.15s, box-shadow 0.15s;
}

@media (max-width: 1024px) {
    .documents-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 10px;
    }

    .documents-card {
        padding: 14px 12px;
    }

    .documents-card__icon {
        font-size: 1.35rem;
        margin-bottom: 6px;
    }

    .documents-card h2 {
        font-size: 0.95rem;
    }

    .documents-card p {
        font-size: 0.78rem;
    }
}

@media (max-width: 640px) {
    .documents-grid {
        grid-template-columns: 1fr;
    }
}

.documents-card:hover {
    border-color: #93c5fd;
    box-shadow: 0 8px 24px rgba(37, 99, 235, 0.1);
}

.documents-card__icon {
    font-size: 1.6rem;
    display: block;
    margin-bottom: 8px;
}

.documents-card h2 {
    margin: 0 0 6px;
    font-size: 1.05rem;
}

.documents-card p {
    margin: 0;
    font-size: 0.85rem;
    color: var(--pos-muted, #64748b);
    line-height: 1.4;
}

.doc-header-fields {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 10px;
    margin-bottom: 12px;
}

.doc-header-fields label {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 0.85rem;
    min-width: 0;
}

.doc-header-fields input,
.doc-header-fields select {
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
}

/* Документы со сканером: две колонки без отступа под POS-корзину */
.stock-doc-page .pos-shell,
.inventory-shell {
    grid-template-columns: minmax(0, 1fr) minmax(240px, min(380px, 34vw));
    padding-right: 16px;
    min-height: 0;
}

.stock-doc-layout {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.stock-doc-page .pos-cart-panel {
    min-height: 0;
    max-height: 100%;
}

.stock-doc-page .pos-cart-list {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
}

.stock-doc-page .pos-search-block {
    position: relative;
    flex-shrink: 0;
    min-width: 0;
}

.stock-doc-page .pos-search-choices {
    max-height: min(280px, 40vh);
    overflow-y: auto;
}

.doc-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto auto;
    gap: 8px;
    align-items: center;
    padding: 10px;
    border: 1px solid var(--pos-line);
    border-radius: 12px;
    background: #fff;
    margin-bottom: 8px;
    min-width: 0;
}

.doc-row > div:first-child {
    min-width: 0;
    overflow: hidden;
}

.doc-row.is-selected {
    border-color: #93c5fd;
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.12);
}

.doc-row__title {
    font-weight: 600;
    font-size: 0.92rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.doc-row__meta {
    font-size: 0.78rem;
    color: var(--pos-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.doc-row__qty input {
    width: 64px;
    text-align: center;
    margin: 0;
}

.doc-row__extra {
    font-size: 0.78rem;
    color: var(--pos-muted);
    text-align: right;
    min-width: 0;
    max-width: 96px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.doc-row__remove {
    border: none;
    background: transparent;
    color: var(--pos-danger, #dc2626);
    cursor: pointer;
    font-size: 1rem;
}

.doc-history-panel {
    flex: 0 1 auto;
    min-height: 0;
    max-height: min(38vh, 320px);
    margin: 0;
    padding: 12px 16px 16px;
    border-top: 1px solid var(--pos-line, #e2e8f0);
    background: var(--pos-surface, #fff);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.doc-history-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    padding-right: 2px;
}

.doc-history-row {
    width: 100%;
    text-align: left;
    border: 1px solid var(--pos-line, #e2e8f0);
    border-radius: 12px;
    background: #fff;
    padding: 12px 14px;
    cursor: pointer;
    font: inherit;
    color: inherit;
}

.doc-history-row:hover {
    border-color: #93c5fd;
}

.doc-history-row.is-active {
    border-color: #2563eb;
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.12);
}

.doc-history-row.is-cancelled {
    opacity: 0.72;
}

.doc-history-row.is-draft {
    border-style: dashed;
}

.doc-history-row__title {
    font-weight: 600;
    font-size: 0.92rem;
}

.doc-history-row__meta {
    margin-top: 4px;
    font-size: 0.8rem;
    color: var(--pos-muted, #64748b);
}

.doc-history-row__detail {
    margin-top: 4px;
    font-size: 0.78rem;
    color: #475569;
}

@media (max-width: 960px) {
    .stock-doc-page .pos-shell,
    .inventory-shell {
        grid-template-columns: 1fr;
        padding-right: 16px;
        overflow: visible;
    }

    .stock-doc-page {
        height: auto;
        min-height: 100vh;
        overflow: auto;
    }

    .stock-doc-layout {
        overflow: visible;
    }

    .doc-history-panel {
        max-height: none;
        overflow: visible;
    }

    .doc-history-list {
        overflow: visible;
        max-height: none;
    }

    .doc-row {
        grid-template-columns: minmax(0, 1fr) auto auto;
        grid-template-areas:
            "info extra remove"
            "info qty qty";
    }

    .doc-row > div:first-child {
        grid-area: info;
    }

    .doc-row__extra {
        grid-area: extra;
        max-width: none;
    }

    .doc-row__qty {
        grid-area: qty;
        justify-self: end;
    }

    .doc-row__remove {
        grid-area: remove;
    }
}

.doc-history-panel__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 10px;
    flex-shrink: 0;
}

.doc-history-panel__head h2 {
    margin: 0;
    font-size: 1rem;
}
