:root {
    --bg: #f4f7fb;
    --panel: #ffffff;
    --text: #162033;
    --muted: #667085;
    --line: #e6ebf2;
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --green: #16a34a;
    --green-bg: #dcfce7;
    --yellow: #d97706;
    --yellow-bg: #fef3c7;
    --red: #dc2626;
    --red-bg: #fee2e2;
    --blue: #2563eb;
    --blue-bg: #dbeafe;
    --gray-bg: #eef2f7;
    --shadow: 0 18px 45px rgba(18, 38, 63, 0.08);
    --radius: 8px;
}

* {
    box-sizing: border-box;
}

html,
body {
    max-width: 100%;
    overflow-x: hidden;
}

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    line-height: 1.5;
}

a {
    color: inherit;
    text-decoration: none;
}

.app-shell {
    width: min(1280px, calc(100% - 32px));
    margin: 0 auto;
    padding: 28px 0 48px;
}

.narrow-shell {
    width: min(620px, calc(100% - 32px));
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 22px;
}

.topbar h1,
.panel h2,
.product-hero h2 {
    margin: 0;
    letter-spacing: 0;
}

.topbar h1 {
    font-size: clamp(28px, 4vw, 42px);
    line-height: 1.1;
}

.eyebrow {
    margin: 0 0 6px;
    color: var(--primary);
    font-size: 13px;
    font-weight: 800;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.header-actions,
.form-actions,
.actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.inline-form {
    margin: 0;
}

.btn,
.icon-btn {
    border: 0;
    border-radius: var(--radius);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    transition: transform 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

.btn {
    min-height: 44px;
    padding: 0 18px;
}

.btn:hover,
.icon-btn:hover {
    transform: translateY(-1px);
}

.btn-primary {
    background: var(--primary);
    color: #fff;
    box-shadow: 0 12px 24px rgba(37, 99, 235, 0.22);
}

.btn-primary:hover {
    background: var(--primary-dark);
}

.btn-secondary {
    background: #fff;
    color: var(--text);
    border: 1px solid var(--line);
}

.btn-success {
    background: var(--green);
    color: #fff;
}

.btn-danger {
    background: var(--red);
    color: #fff;
}

.btn-success {
    box-shadow: 0 12px 24px rgba(22, 163, 74, 0.14);
}

.btn-danger {
    box-shadow: 0 12px 24px rgba(220, 38, 38, 0.14);
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 18px;
}

.stat-card,
.panel {
    background: var(--panel);
    border: 1px solid rgba(230, 235, 242, 0.9);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.stat-card {
    min-height: 118px;
    padding: 18px;
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.stat-card::before {
    content: "";
    position: absolute;
    inset: 0 auto 0 0;
    width: 4px;
    background: #94a3b8;
}

.stat-card span {
    color: var(--muted);
    display: block;
    font-size: 13px;
    font-weight: 700;
}

.stat-card strong {
    display: block;
    font-size: 32px;
    margin-top: 10px;
}

.accent-blue::before {
    background: var(--blue);
}

.accent-green::before {
    background: var(--green);
}

.accent-yellow::before {
    background: var(--yellow);
}

.accent-red::before {
    background: var(--red);
}

.panel {
    padding: 22px;
    margin-bottom: 18px;
}

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

.section-heading h2,
.panel h2 {
    font-size: 20px;
}

.section-heading span,
.muted {
    color: var(--muted);
}

.section-heading-wrap {
    align-items: flex-start;
}

.filters {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.filters a {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    color: var(--muted);
    font-size: 14px;
    font-weight: 800;
    padding: 9px 12px;
    transition: 0.18s ease;
}

.filters a:hover,
.filters a.active {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

.logistics-filter {
    display: grid;
    grid-template-columns: repeat(3, minmax(160px, 1fr)) auto auto;
    align-items: end;
    gap: 12px;
    margin: 18px 0 20px;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #f8fafc;
}

.order-filter {
    grid-template-columns: repeat(2, minmax(180px, 1fr)) auto auto;
}

.logistics-filter label {
    display: grid;
    gap: 7px;
}

.logistics-filter span {
    color: var(--muted);
    font-size: 12px;
    font-weight: 900;
    text-transform: uppercase;
}

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

.notice {
    border-radius: var(--radius);
    font-weight: 700;
    padding: 12px 14px;
}

.notice-warning {
    background: var(--yellow-bg);
    color: #92400e;
}

.notice-danger {
    background: var(--red-bg);
    color: #991b1b;
}

.notice-info {
    background: var(--blue-bg);
    color: #1e40af;
}

.table-wrap {
    width: 100%;
    overflow-x: auto;
    overflow-y: visible;
    padding-bottom: 6px;
}

.table-wrap::-webkit-scrollbar {
    height: 8px;
}

.table-wrap::-webkit-scrollbar-track {
    background: #eef2f7;
    border-radius: 999px;
}

.table-wrap::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 999px;
}

.products-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    table-layout: auto;
}

.orders-table {
    min-width: 1240px;
}

.orders-table th {
    white-space: nowrap;
}

.orders-table th:nth-child(3),
.orders-table td:nth-child(3),
.orders-table th:nth-child(5),
.orders-table td:nth-child(5),
.orders-table th:nth-child(6),
.orders-table td:nth-child(6),
.orders-table th:nth-child(7),
.orders-table td:nth-child(7),
.orders-table th:nth-child(8),
.orders-table td:nth-child(8),
.orders-table th:nth-child(9),
.orders-table td:nth-child(9) {
    min-width: 96px;
}

.order-products-table {
    min-width: 1320px;
}

.compact-table th:nth-child(1),
.compact-table td:nth-child(1) {
    width: 72px;
}

.compact-table th:nth-child(2),
.compact-table td:nth-child(2) {
    width: 22%;
}

.compact-table th:nth-child(3),
.compact-table td:nth-child(3) {
    width: 96px;
}

.compact-table th:nth-child(4),
.compact-table td:nth-child(4) {
    width: 140px;
}

.compact-table th:nth-child(10),
.compact-table td:nth-child(10) {
    width: 170px;
}

.order-products-table th:nth-child(10),
.order-products-table td:nth-child(10) {
    width: auto;
}

.order-products-table th:nth-child(11),
.order-products-table td:nth-child(11) {
    width: 132px;
}

.order-products-table th:nth-child(5),
.order-products-table td:nth-child(5),
.order-products-table th:nth-child(6),
.order-products-table td:nth-child(6),
.order-products-table th:nth-child(7),
.order-products-table td:nth-child(7),
.order-products-table th:nth-child(8),
.order-products-table td:nth-child(8),
.order-products-table th:nth-child(9),
.order-products-table td:nth-child(9),
.order-products-table th:nth-child(10),
.order-products-table td:nth-child(10) {
    min-width: 96px;
}

.order-products-table th {
    white-space: nowrap;
}

.orders-table th:nth-child(11),
.orders-table td:nth-child(11) {
    width: 170px;
}

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

.products-table th {
    color: var(--muted);
    font-size: 12px;
    line-height: 1.35;
    font-weight: 900;
    text-transform: uppercase;
    white-space: normal;
}

.products-table tbody tr {
    transition: background 0.16s ease;
}

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

.product-link {
    display: grid;
    gap: 4px;
    min-width: 0;
}

.product-link strong {
    overflow-wrap: anywhere;
}

.product-link span {
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
}

.product-thumb,
.product-photo {
    object-fit: cover;
    background: #eef2f7;
    border: 1px solid var(--line);
    color: var(--primary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 900;
}

.product-thumb {
    width: 60px;
    height: 60px;
    border-radius: var(--radius);
    font-size: 20px;
}

.product-photo {
    width: 180px;
    height: 180px;
    border-radius: var(--radius);
    font-size: 54px;
}

.product-placeholder {
    background: linear-gradient(135deg, #e0ecff, #f8fafc);
}

.js-image-modal {
    cursor: zoom-in;
}

.status {
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 28px;
    padding: 4px 10px;
    font-size: 12px;
    font-weight: 900;
    white-space: nowrap;
}

.status-ok,
.status-received {
    background: var(--green-bg);
    color: #166534;
}

.status-low_stock {
    background: var(--yellow-bg);
    color: #92400e;
}

.status-partially_received {
    background: var(--yellow-bg);
    color: #92400e;
}

.status-need_order,
.status-delayed {
    background: var(--red-bg);
    color: #991b1b;
}

.status-in_transit {
    background: var(--blue-bg);
    color: #1e40af;
}

.status-no_data {
    background: var(--gray-bg);
    color: #475569;
}

.toggle-btn {
    min-height: 34px;
    min-width: 64px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #fff;
    color: #64748b;
    cursor: pointer;
    font-weight: 900;
    transition: 0.18s ease;
}

.toggle-btn:hover {
    transform: translateY(-1px);
    border-color: var(--primary);
    color: var(--primary);
}

.toggle-btn.is-on {
    background: var(--green-bg);
    border-color: #86efac;
    color: #166534;
}

.switch-row {
    min-height: 46px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #f8fafc;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 0 12px;
    cursor: pointer;
}

.switch-row input {
    width: 18px;
    min-height: 18px;
}

.delivery-badge {
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    min-height: 28px;
    padding: 4px 10px;
    font-size: 12px;
    font-weight: 900;
    white-space: nowrap;
}

.delivery-air {
    background: var(--blue-bg);
    color: #1e40af;
}

.delivery-rail {
    background: #ede9fe;
    color: #5b21b6;
}

.delivery-sea {
    background: #ccfbf1;
    color: #0f766e;
}

.delivery-unknown {
    background: var(--gray-bg);
    color: #475569;
}

.cargo-name {
    display: inline-block;
    min-width: 96px;
    max-width: 150px;
    color: #334155;
    font-size: 13px;
    font-weight: 800;
    overflow-wrap: anywhere;
}

.icon-btn {
    min-height: 34px;
    padding: 0 10px;
    background: #eaf0f8;
    color: #334155;
    font-size: 13px;
}

.icon-btn:hover {
    background: #dbeafe;
    color: #1e40af;
}

.icon-btn.danger {
    background: var(--red-bg);
    color: #991b1b;
}

.icon-btn.danger:hover {
    background: #fecaca;
}

.positive {
    color: var(--green);
    font-weight: 800;
}

.negative {
    color: var(--red);
    font-weight: 800;
}

.form-card {
    max-width: 1040px;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
}

.field {
    display: grid;
    gap: 8px;
}

.field-wide {
    grid-column: span 3;
}

.field span {
    color: #344054;
    font-size: 14px;
    font-weight: 800;
}

input,
select {
    width: 100%;
    min-height: 46px;
    border: 1px solid #d7deea;
    border-radius: var(--radius);
    background: #fff;
    color: var(--text);
    font: inherit;
    padding: 10px 12px;
    outline: none;
    transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

input:focus,
select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.12);
}

input.is-invalid,
select.is-invalid {
    border-color: var(--red);
}

.field small,
.form-alert {
    color: #991b1b;
}

.field small.muted {
    color: var(--muted);
}

.form-alert {
    background: var(--red-bg);
    border-radius: var(--radius);
    font-weight: 800;
    margin-bottom: 18px;
    padding: 12px 14px;
}

.upload-row {
    display: flex;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
}

.form-thumb {
    width: 76px;
    height: 76px;
}

.file-control input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.file-control {
    display: inline-flex;
    position: relative;
}

.file-control span {
    min-height: 42px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #f8fafc;
    color: #334155;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 14px;
}

.form-actions {
    margin-top: 22px;
}

.product-hero {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 22px;
}

.product-hero h2 {
    font-size: clamp(26px, 3vw, 36px);
    margin-top: 14px;
    overflow-wrap: anywhere;
}

.hero-profit {
    min-width: 260px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #f8fafc;
    padding: 18px;
}

.hero-profit span {
    color: var(--muted);
    display: block;
    font-weight: 800;
}

.hero-profit strong {
    display: block;
    font-size: 28px;
    margin-top: 8px;
}

.detail-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px;
}

.detail-grid .panel {
    margin-bottom: 0;
}

.info-list {
    display: grid;
    gap: 12px;
    margin: 18px 0 0;
}

.info-list div {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    border-bottom: 1px solid var(--line);
    padding-bottom: 10px;
}

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

.info-list dd {
    margin: 0;
    font-weight: 900;
    text-align: right;
}

.hint-box,
.empty-state {
    background: #f8fafc;
    border: 1px dashed #cbd5e1;
    border-radius: var(--radius);
    color: #334155;
    font-weight: 800;
    margin-top: 14px;
    padding: 14px;
}

.empty-state {
    display: grid;
    gap: 8px;
    justify-items: start;
}

.empty-state h3,
.empty-state p,
.confirm-card h1 {
    margin: 0;
}

.confirm-card {
    display: grid;
    gap: 14px;
    justify-items: start;
}

.auth-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px 0;
}

.auth-card {
    width: 100%;
    margin-bottom: 0;
}

.auth-card h1 {
    margin: 0 0 8px;
    font-size: 34px;
}

.auth-form {
    display: grid;
    gap: 16px;
    margin-top: 22px;
}

.auth-form .btn {
    width: 100%;
}

.payments-list {
    display: grid;
    gap: 12px;
    margin-bottom: 18px;
}

.payment-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 14px;
}

.payment-main {
    display: flex;
    align-items: center;
    gap: 12px;
}

.payment-row span,
.payment-row p {
    display: block;
    margin: 3px 0 0;
    color: var(--muted);
}

.payment-row-detailed {
    align-items: flex-start;
}

.payment-preview {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    margin-top: 14px;
}

.payment-preview span {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #f8fafc;
    color: var(--muted);
    font-weight: 800;
    padding: 10px 12px;
}

.payment-preview strong {
    color: var(--text);
}

.order-payment-form {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #fff;
    padding: 16px;
    margin-bottom: 18px;
}

.payment-card {
    display: grid;
    gap: 18px;
}

.payment-image-large img,
.payment-image-large .product-placeholder {
    width: 100%;
    max-height: 70vh;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    object-fit: contain;
    background: #f8fafc;
}

.payment-image-large .product-placeholder {
    min-height: 260px;
    display: grid;
    place-items: center;
    color: var(--muted);
    font-weight: 800;
}

.image-modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: rgba(15, 23, 42, 0.78);
    display: none;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.image-modal.is-open {
    display: flex;
}

.image-modal img {
    max-width: min(920px, 96vw);
    max-height: 88vh;
    border-radius: var(--radius);
    background: #fff;
    box-shadow: 0 24px 70px rgba(0, 0, 0, 0.35);
    object-fit: contain;
}

.image-modal button {
    position: fixed;
    top: 18px;
    right: 18px;
    width: 44px;
    height: 44px;
    border: 0;
    border-radius: 999px;
    background: #fff;
    color: var(--text);
    cursor: pointer;
    font-size: 24px;
    font-weight: 900;
}

@media (max-width: 1180px) {
    .stats-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .form-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .field-wide {
        grid-column: span 2;
    }

    .compact-table th,
    .compact-table td {
        font-size: 14px;
        padding: 12px 8px;
    }

    .compact-table th:nth-child(10),
    .compact-table td:nth-child(10),
    .orders-table th:nth-child(11),
    .orders-table td:nth-child(11),
    .order-products-table th:nth-child(11),
    .order-products-table td:nth-child(11) {
        width: 150px;
    }
}

@media (max-width: 900px) {
    .table-wrap {
        overflow: visible;
        padding-bottom: 0;
    }

    .orders-table,
    .order-products-table {
        min-width: 0;
    }

    .compact-table thead {
        display: none;
    }

    .compact-table,
    .compact-table tbody,
    .compact-table tr,
    .compact-table td {
        display: block;
        width: 100%;
    }

    .compact-table th:nth-child(1),
    .compact-table td:nth-child(1),
    .compact-table th:nth-child(2),
    .compact-table td:nth-child(2),
    .compact-table th:nth-child(3),
    .compact-table td:nth-child(3),
    .compact-table th:nth-child(4),
    .compact-table td:nth-child(4),
    .compact-table th:nth-child(10),
    .compact-table td:nth-child(10),
    .orders-table th:nth-child(11),
    .orders-table td:nth-child(11),
    .order-products-table th:nth-child(11),
    .order-products-table td:nth-child(11) {
        width: 100%;
    }

    .compact-table tr {
        border: 1px solid var(--line);
        border-radius: var(--radius);
        box-shadow: 0 12px 26px rgba(18, 38, 63, 0.06);
        margin-bottom: 14px;
        padding: 14px;
    }

    .compact-table td {
        align-items: center;
        border-bottom: 1px solid #eef2f7;
        display: flex;
        justify-content: space-between;
        gap: 14px;
        padding: 10px 0;
        text-align: right;
    }

    .compact-table td::before {
        content: attr(data-label);
        color: var(--muted);
        flex: 0 0 42%;
        font-size: 13px;
        font-weight: 800;
        text-align: left;
    }

    .compact-table td:first-child {
        justify-content: flex-start;
    }

    .compact-table td:first-child::before {
        display: none;
    }

    .compact-table td:nth-child(2) {
        align-items: flex-start;
        display: grid;
        gap: 6px;
        justify-content: stretch;
        text-align: left;
    }

    .compact-table td:nth-child(2)::before {
        flex: none;
    }

    .compact-table td:last-child {
        border-bottom: 0;
        display: block;
        text-align: left;
    }

    .compact-table td:last-child::before {
        display: block;
        margin-bottom: 8px;
    }

    .actions {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 760px) {
    .app-shell {
        width: min(100% - 20px, 720px);
        padding-top: 18px;
    }

    .topbar,
    .section-heading,
    .section-heading-wrap {
        align-items: stretch;
        flex-direction: column;
    }

    .btn,
    .inline-form,
    .inline-form .btn {
        width: 100%;
    }

    .stats-grid,
    .detail-grid,
    .form-grid,
    .logistics-filter,
    .product-hero {
        grid-template-columns: 1fr;
    }

    .field-wide {
        grid-column: span 1;
    }

    .panel {
        padding: 16px;
    }

    .filters {
        justify-content: flex-start;
    }

    .filters a {
        flex: 1 1 calc(50% - 8px);
        text-align: center;
    }

    .hero-profit,
    .product-photo {
        min-width: 0;
        width: 100%;
    }

    .product-photo {
        height: 220px;
    }

    .info-list div {
        align-items: flex-start;
        flex-direction: column;
        gap: 4px;
    }

    .info-list dd {
        text-align: left;
    }

    .payment-row,
    .payment-main {
        align-items: flex-start;
        flex-direction: column;
    }
}

@media (max-width: 430px) {
    .filters a,
    .actions {
        grid-template-columns: 1fr;
        flex-basis: 100%;
    }

    .topbar h1 {
        font-size: 27px;
    }
}
