* {
    box-sizing: border-box;
}

html,
body {
    min-height: 100%;
}

body {
    margin: 0;
    background: #f9fafb;
    color: #1f2937;
    font-family: "Inter", sans-serif;
}

.hidden {
    display: none !important;
}

::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 3px;
}

h1,
h2,
h3,
.h-title {
    font-weight: 600;
    letter-spacing: 0;
}

*:focus-visible {
    outline: 2px solid #6366f1;
    outline-offset: 2px;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.skip-link {
    position: absolute;
    top: -40px;
    left: 8px;
    z-index: 1000;
    padding: 8px 12px;
    border-radius: 6px;
    background: #111827;
    color: #fff;
    text-decoration: none;
}

.skip-link:focus {
    top: 8px;
}

.app-header {
    position: sticky;
    top: 0;
    z-index: 30;
    border-bottom: 1px solid #f3f4f6;
    background: rgba(255, 255, 255, 0.88);
    backdrop-filter: blur(8px);
}

.app-header-inner {
    max-width: 1200px;
    height: 64px;
    margin: 0 auto;
    padding: 0 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.brand-link,
.header-actions,
.product-headline,
.quantity-row,
.analog-title {
    display: flex;
    align-items: center;
}

.brand-link {
    gap: 10px;
    color: inherit;
    text-decoration: none;
}

.brand-title {
    font-size: 18px;
    font-weight: 700;
    color: #111827;
}

.brand-title span {
    color: #6366f1;
}

.header-actions {
    gap: 20px;
}

.header-icon-btn,
.logout-btn,
.icon-btn {
    border: 0;
    background: transparent;
    cursor: pointer;
    font-family: inherit;
}

.header-icon-btn {
    position: relative;
    color: #4b5563;
    padding: 6px;
}

.header-icon-btn:hover,
.logout-btn:hover {
    color: #111827;
}

.cart-counter {
    position: absolute;
    top: -3px;
    right: -4px;
    min-width: 20px;
    padding: 2px 6px;
    border: 2px solid #fff;
    border-radius: 10px;
    background: #6366f1;
    color: #fff;
    font-size: 11px;
    font-weight: 600;
    line-height: 1.2;
    text-align: center;
}

.header-divider {
    width: 1px;
    height: 24px;
    background: #e5e7eb;
}

.logout-btn {
    color: #6b7280;
    font-size: 14px;
    font-weight: 500;
}

.page-shell {
    max-width: 1200px;
    margin: 0 auto;
    padding: 40px 24px 80px;
}

.search-wrapper {
    position: relative;
    max-width: 720px;
    margin: 0 auto 40px;
}

.search-wrapper form {
    position: relative;
}

.search-input {
    width: 100%;
    padding: 16px 120px 16px 48px;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    background: #fff;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
    color: #111827;
    font: inherit;
    font-size: 16px;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.search-input:focus {
    border-color: #6366f1;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.15);
}

.search-icon {
    position: absolute;
    top: 50%;
    left: 16px;
    z-index: 1;
    color: #9ca3af;
    transform: translateY(-50%);
    pointer-events: none;
}

.search-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    bottom: 8px;
    padding: 0 24px;
    border: 0;
    border-radius: 8px;
    background: #111827;
    color: #fff;
    font: inherit;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
}

.search-btn:hover,
.primary-btn:hover {
    background: #374151;
}

#loader {
    text-align: center;
    padding: 40px;
}

.loader-spinner {
    width: 36px;
    height: 36px;
    margin: 0 auto;
    border: 3px solid #f3f4f6;
    border-top-color: #6366f1;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.message-container,
.error-message {
    max-width: 720px;
    margin: 0 auto 24px;
}

.error-message {
    padding: 16px;
    border: 1px solid #fee2e2;
    border-radius: 12px;
    background: #fef2f2;
    text-align: center;
}

.error-message p {
    margin: 0 0 4px;
    color: #b91c1c;
    font-weight: 600;
}

.error-message span {
    color: #dc2626;
    font-size: 14px;
}

.results-stack {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.markup-section {
    margin-bottom: 8px;
    background: transparent;
}

.markup-label {
    display: block;
    margin-bottom: 12px;
    color: #9ca3af;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0;
    text-transform: uppercase;
}

.markup-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

.markup-item {
    display: inline-flex;
    align-items: center;
    padding: 4px 0;
}

.markup-name,
.markup-editor-item .supplier-name {
    margin-right: 8px;
    color: #4b5563;
    font-size: 13px;
    font-weight: 500;
}

.markup-input-wrap {
    display: inline-flex;
    align-items: center;
}

.markup-input,
.markup-editor-item .markup-input {
    width: 36px;
    padding: 0 2px 2px;
    border: 0;
    border-bottom: 1px dashed #d1d5db;
    border-radius: 0;
    background: transparent;
    color: #111827;
    font: inherit;
    font-size: 14px;
    font-weight: 600;
    text-align: center;
    transition: border-color 0.2s;
}

.markup-input:focus {
    border-bottom-color: #6366f1;
    outline: none;
}

.markup-input::-webkit-inner-spin-button,
.markup-input::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.markup-input[type="number"] {
    -moz-appearance: textfield;
}

.markup-pct {
    margin-left: 4px;
    color: #9ca3af;
    font-size: 14px;
    font-weight: 500;
}

.markup-reset,
.reset-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    margin-left: 4px;
    border: 0;
    border-radius: 4px;
    background: transparent;
    color: #9ca3af;
    cursor: pointer;
    transition: color 0.2s, background 0.2s;
}

.markup-reset:hover,
.reset-btn:hover {
    background: #f3f4f6;
    color: #4b5563;
}

.markup-reset.invisible,
.reset-btn.hidden-reset {
    opacity: 0;
    pointer-events: none;
}

.custom-markup-indicator {
    display: inline-block;
    width: 6px;
    height: 6px;
    margin-left: 6px;
    border-radius: 50%;
    background: #6366f1;
}

.panel {
    overflow: hidden;
    margin-bottom: 0;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    background: #fff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.02);
}

.panel-header,
.analog-summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid #f3f4f6;
}

.panel-header h2,
.analog-summary h2 {
    margin: 0;
    color: #111827;
    font-size: 18px;
}

.sort-group {
    display: inline-flex;
    padding: 2px;
    border-radius: 8px;
    background: #f3f4f6;
}

.sort-opt {
    padding: 6px 16px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: #6b7280;
    font: inherit;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: color 0.2s, background 0.2s, box-shadow 0.2s;
}

.sort-opt.active {
    background: #fff;
    color: #111827;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.sort-opt:not(.active):hover {
    color: #111827;
}

/* ===== SUPPLIER TABS ===== */
.supplier-tabs-container {
    position: sticky;
    top: 64px;
    z-index: 20;
    overflow-x: auto;
    padding: 16px 24px 0;
    background: #fff;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

.supplier-tabs-container::-webkit-scrollbar {
    display: none;
}

.supplier-tabs {
    display: flex;
    gap: 8px;
    padding-bottom: 2px;
    border-bottom: 1px solid #e5e7eb;
}

.supplier-tab {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border: 1px solid transparent;
    border-radius: 20px;
    background: transparent;
    color: #6b7280;
    font: inherit;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: color 0.2s, background 0.2s;
}

.supplier-tab:hover {
    background: #f3f4f6;
    color: #111827;
}

.supplier-tab.active {
    background: #fff;
    color: #111827;
}

.panel .supplier-tab.active {
    background: #111827;
    color: #fff;
}

.tab-count,
.tab-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    border-radius: 10px;
    background: rgba(107, 114, 128, 0.1);
    color: inherit;
    font-size: 11px;
    font-weight: 600;
}

.supplier-tab.active .tab-count,
.supplier-tab.active .tab-badge {
    background: rgba(255, 255, 255, 0.2);
    color: inherit;
}

.tab-panel {
    opacity: 0;
    transition: opacity 0.15s ease;
}

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

.data-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
}

.data-table th {
    padding: 12px 16px;
    border-bottom: 1px solid #f3f4f6;
    color: #9ca3af;
    font-size: 13px;
    font-weight: 500;
    text-align: left;
}

.data-table td {
    padding: 12px 16px;
    border-bottom: 1px solid #f9fafb;
    vertical-align: middle;
}

.data-table td[data-label="Цена"],
.data-table td[data-label="Наличие"],
.data-table td[data-label="Срок"] {
    text-align: right;
}

.data-table tbody tr {
    transition: background-color 0.15s;
}

.data-table tbody tr:hover {
    background-color: #f9fafb;
}

.part-cell {
    display: flex;
    align-items: center;
    gap: 16px;
}

.s-logo,
.supplier-logo {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    background: #f3f4f6;
    color: #4b5563;
    font-size: 13px;
    font-weight: 600;
    text-transform: uppercase;
}

.part-title {
    margin-bottom: 2px;
    color: #111827;
    font-size: 14px;
}

.part-brand {
    font-weight: 600;
}

.part-separator {
    margin: 0 6px;
    color: #d1d5db;
}

.part-number {
    color: #4b5563;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.part-name {
    max-width: 430px;
    color: #6b7280;
    font-size: 13px;
    line-height: 1.4;
}

.price-col,
.price-display {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 2px;
}

.price-old,
.price-supplier {
    color: #9ca3af;
    font-size: 12px;
    text-decoration: line-through;
}

.price-new,
.price-main {
    color: #111827;
    font-size: 18px;
    font-weight: 700;
}

.status-badge {
    display: inline-block;
    font-size: 13px;
    font-weight: 500;
}

.status-qty {
    color: #374151;
    background: transparent;
}

.d-today {
    color: #059669;
    font-weight: 500;
    white-space: nowrap;
}

.d-soon {
    color: #d97706;
    font-weight: 500;
    white-space: nowrap;
}

.d-norm {
    color: #4b5563;
    white-space: nowrap;
}

.d-long {
    color: #ef4444;
    white-space: nowrap;
}

.cart-btn {
    width: 36px;
    height: 36px;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: #9ca3af;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: color 0.2s, background 0.2s, transform 0.2s;
}

.cart-btn:hover {
    background: #f3f4f6;
    color: #111827;
}

.cart-btn:active {
    transform: translateY(1px);
}

.tab-panel .cart-btn {
    background: transparent;
    color: #9ca3af;
}

.tab-panel .cart-btn:hover {
    background: #f3f4f6;
    color: #111827;
}

.tab-pagination {
    padding: 12px 16px;
    border-top: 1px solid #f3f4f6;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: #6b7280;
    font-size: 13px;
}

.tab-show-all-btn {
    padding: 4px 12px;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    background: transparent;
    color: #6366f1;
    font: inherit;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
}

.analog-summary {
    cursor: pointer;
    list-style: none;
    user-select: none;
}

.analog-summary::-webkit-details-marker {
    display: none;
}

.analog-title {
    gap: 12px;
}

.analog-count {
    padding: 2px 10px;
    border-radius: 12px;
    background: #f3f4f6;
    color: #4b5563;
    font-size: 12px;
    font-weight: 600;
}

.analog-chevron {
    color: #9ca3af;
    transition: transform 0.2s;
}

details[open] .analog-chevron {
    transform: rotate(180deg);
}

.analog-content {
    border-top: 0;
}

.modal {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: none;
    align-items: center;
    justify-content: center;
}

.modal.active,
.modal.is-open {
    display: flex;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(17, 24, 39, 0.4);
    backdrop-filter: blur(4px);
}

.modal-content {
    position: relative;
    z-index: 1;
    width: min(440px, calc(100% - 32px));
    max-height: calc(100vh - 32px);
    overflow: auto;
    border-radius: 16px;
    background: #fff;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    transform: scale(0.97) translateY(-8px);
    opacity: 0;
    transition: transform 0.2s, opacity 0.2s;
}

.modal.is-open .modal-content {
    transform: scale(1) translateY(0);
    opacity: 1;
}

.modal-header,
.modal-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
}

.modal-header {
    border-bottom: 1px solid #f3f4f6;
}

.modal-header h3 {
    margin: 0;
    color: #111827;
    font-size: 18px;
}

.icon-btn {
    padding: 4px;
    border-radius: 6px;
    color: #9ca3af;
}

.icon-btn:hover {
    background: #f3f4f6;
    color: #4b5563;
}

.modal-body {
    padding: 20px;
}

.product-info {
    padding-bottom: 18px;
    border-bottom: 1px solid #f3f4f6;
}

.product-headline {
    gap: 12px;
    margin-bottom: 12px;
}

.product-brand {
    color: #111827;
    font-size: 14px;
    font-weight: 600;
}

.product-part-number,
.product-supplier,
.product-delivery {
    color: #6b7280;
    font-size: 13px;
}

.product-name {
    margin-bottom: 8px;
    color: #111827;
    font-size: 14px;
    font-weight: 500;
    line-height: 1.45;
}

.product-price-row {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 16px;
    margin-top: 14px;
}

.modal-price {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

.product-supplier-price {
    color: #9ca3af;
    font-size: 12px;
    text-decoration: line-through;
}

.product-price {
    color: #111827;
    font-size: 22px;
    font-weight: 700;
}

.product-min-qty-info,
.qty-validation-message,
.validation-message {
    margin-top: 8px;
    color: #dc2626;
    font-size: 12px;
    font-weight: 500;
}

.quantity-section,
.comment-section {
    margin-top: 18px;
}

.field-label {
    display: block;
    margin-bottom: 8px;
    color: #374151;
    font-size: 14px;
    font-weight: 500;
}

.field-label span {
    color: #ef4444;
}

.quantity-row {
    gap: 10px;
}

.qty-btn {
    width: 38px;
    height: 38px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    background: #fff;
    color: #4b5563;
    font-size: 20px;
    cursor: pointer;
}

.qty-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.qty-input {
    width: 76px;
    text-align: center;
}

.qty-total-price {
    margin-left: auto;
    color: #4b5563;
    font-size: 14px;
    font-weight: 500;
}

.input-standard {
    width: 100%;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    padding: 10px 12px;
    color: #111827;
    font: inherit;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.input-standard:focus {
    border-color: #6366f1;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

textarea.input-standard {
    resize: none;
}

textarea.error {
    border-color: #ef4444;
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1);
}

.comment-feedback {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 18px;
    margin-top: 6px;
}

.char-count {
    color: #9ca3af;
    font-size: 12px;
}

.char-count.over-limit {
    color: #dc2626;
}

.modal-footer {
    justify-content: flex-end;
    gap: 12px;
    border-top: 1px solid #f3f4f6;
    background: #f9fafb;
}

.primary-btn,
.secondary-btn {
    padding: 10px 16px;
    border-radius: 8px;
    font: inherit;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
}

.primary-btn {
    border: 0;
    background: #111827;
    color: #fff;
}

.primary-btn:disabled,
.btn-add-to-cart.loading {
    opacity: 0.5;
    cursor: not-allowed;
}

.secondary-btn {
    border: 1px solid #d1d5db;
    background: #fff;
    color: #374151;
}

.secondary-btn:hover {
    background: #f3f4f6;
}

.notification-toast {
    border-radius: 8px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
    font-family: "Inter", sans-serif;
}

.confirmation-dialog .relative {
    animation: confirmationSlideIn 0.2s ease-out forwards;
}

@keyframes confirmationSlideIn {
    from {
        transform: scale(0.95) translateY(-10px);
        opacity: 0;
    }
    to {
        transform: scale(1) translateY(0);
        opacity: 1;
    }
}

@media screen and (max-width: 768px) {
    .page-shell {
        padding: 28px 16px 56px;
    }

    .app-header-inner {
        padding: 0 16px;
    }

    .brand-title {
        font-size: 16px;
    }

    .search-input {
        padding-right: 104px;
        font-size: 15px;
    }

    .search-btn {
        padding: 0 18px;
    }

    .panel-header,
    .analog-summary {
        align-items: flex-start;
        gap: 16px;
        padding: 18px 16px;
    }

    .supplier-tabs-container {
        padding: 12px 16px 0;
    }

    .supplier-tab {
        padding: 8px 12px;
        font-size: 12px;
    }

    .data-table thead {
        display: none;
    }

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

    .data-table tr {
        padding: 14px 16px;
        border-bottom: 1px solid #f3f4f6;
    }

    .data-table td {
        display: flex;
        align-items: flex-start;
        justify-content: space-between;
        gap: 16px;
        padding: 8px 0;
        border-bottom: 0;
        text-align: right !important;
    }

    .data-table td::before {
        content: attr(data-label);
        color: #6b7280;
        font-size: 13px;
        font-weight: 600;
        text-align: left;
    }

    .data-table td:first-child {
        display: block;
        text-align: left !important;
    }

    .data-table td:first-child::before,
    .data-table td.actions::before {
        display: none;
    }

    .part-name {
        max-width: none;
    }

    .cart-btn {
        margin-left: auto;
        background: #111827;
        color: #fff;
    }

    .cart-btn:hover {
        background: #374151;
        color: #fff;
    }

    .modal-footer {
        flex-direction: column-reverse;
    }

    .primary-btn,
    .secondary-btn {
        width: 100%;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        scroll-behavior: auto !important;
        transition-duration: 0.01ms !important;
    }
}
