:root {
    --app-primary: #1f6f5f;
    --app-primary-dark: #185649;
    --app-primary-soft: #eaf5f2;
    --app-ink: #1d2926;
    --app-muted: #66736f;
    --app-border: #dce4e1;
    --app-bg: #f3f6f5;
    --app-work: #2764ad;
    --app-material: #a65a1d;
    --app-ai: #6846c7;
    --bs-primary: var(--app-primary);
    --bs-primary-rgb: 31, 111, 95;
    --bs-body-color: var(--app-ink);
    --bs-body-bg: var(--app-bg);
    --bs-border-color: var(--app-border);
    --bs-font-sans-serif: Inter, "Segoe UI", Roboto, Arial, sans-serif;
}

body {
    min-height: 100vh;
    background:
        radial-gradient(circle at 100% 0, rgba(31, 111, 95, 0.08), transparent 34rem),
        var(--app-bg);
}

.app-container {
    max-width: 1560px;
}

.app-header {
    background: rgba(255, 255, 255, 0.92);
    border-bottom: 1px solid var(--app-border);
    backdrop-filter: blur(10px);
    position: sticky;
    top: 0;
    z-index: 1040;
}

.brand-mark {
    display: inline-grid;
    width: 42px;
    height: 42px;
    place-items: center;
    border-radius: 12px;
    background: var(--app-primary);
    color: #fff;
    font-size: 1.25rem;
    box-shadow: 0 8px 18px rgba(31, 111, 95, 0.18);
}

.save-status {
    color: var(--app-muted);
    font-size: 0.8rem;
}

.card,
.export-panel {
    border: 1px solid var(--app-border);
    border-radius: 16px;
    box-shadow: 0 8px 28px rgba(29, 41, 38, 0.045);
}

.document-card,
.estimate-card {
    overflow: hidden;
}

.estimate-workspace {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 330px;
    align-items: start;
    gap: 1rem;
}

.estimate-workspace .estimate-card {
    min-width: 0;
}

.yandex-search-card {
    position: sticky;
    top: 86px;
    overflow: hidden;
    border-color: #ead36a;
    background: linear-gradient(180deg, #fffdf2 0, #fff 180px);
}

.yandex-search-card::before {
    display: block;
    height: 5px;
    background: #ffcc00;
    content: '';
}

.yandex-search-heading {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.yandex-mark {
    display: inline-grid;
    flex: 0 0 auto;
    width: 42px;
    height: 42px;
    place-items: center;
    border-radius: 12px;
    color: #e00000;
    background: #ffdf55;
    font-size: 1.45rem;
    font-weight: 800;
}

.selected-search-item {
    padding: 0.75rem;
    border: 1px solid #eadf9f;
    border-radius: 12px;
    background: rgba(255, 241, 166, 0.28);
}

.selected-search-item span,
.selected-search-item strong {
    display: block;
}

.selected-search-item span {
    margin-bottom: 0.15rem;
    color: var(--app-muted);
    font-size: 0.68rem;
}

.selected-search-item strong {
    overflow-wrap: anywhere;
    font-size: 0.86rem;
}

.btn-yandex {
    border-color: #ffcc00;
    color: #191919;
    background: #ffcc00;
    font-weight: 700;
}

.btn-yandex:hover,
.btn-yandex:focus-visible {
    border-color: #efbd00;
    color: #111;
    background: #f5c400;
}

.yandex-window-hint {
    display: flex;
    align-items: flex-start;
    gap: 0.55rem;
    padding: 0.7rem;
    border-radius: 10px;
    color: var(--app-muted);
    background: #f6f7f6;
    font-size: 0.72rem;
}

.yandex-window-hint i {
    flex: 0 0 auto;
    color: var(--app-primary);
    font-size: 0.95rem;
}

.section-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.position-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 0.5rem;
}

.btn-outline-ai {
    border-color: #b9a9e8;
    color: #5d3db7;
    background: #fff;
}

.btn-outline-ai:hover,
.btn-outline-ai:focus-visible {
    border-color: var(--app-ai);
    color: #fff;
    background: var(--app-ai);
}

.btn-ai {
    border-color: var(--app-ai);
    color: #fff;
    background: var(--app-ai);
}

.btn-ai:hover,
.btn-ai:focus-visible {
    border-color: #5536aa;
    color: #fff;
    background: #5536aa;
}

.ai-intro {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.9rem 1rem;
    border: 1px solid #ddd3f6;
    border-radius: 12px;
    color: #402a7c;
    background: #f7f4ff;
}

.ai-intro i {
    flex: 0 0 auto;
    font-size: 1.15rem;
}

.ai-intro strong,
.ai-intro span {
    display: block;
}

.ai-intro span {
    margin-top: 0.15rem;
    color: #6e628d;
    font-size: 0.8rem;
}

.ai-price-check {
    width: 100%;
    padding: 0.75rem 0.75rem 0.75rem 2.2rem;
    border: 1px solid var(--app-border);
    border-radius: 10px;
    background: #f8faf9;
}

.ai-preview-heading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
}

.ai-preview-table-wrap {
    border: 1px solid var(--app-border);
    border-radius: 12px;
}

.ai-preview-table {
    min-width: 680px;
}

.ai-preview-table th {
    color: var(--app-muted);
    background: #f7f9f8;
    font-size: 0.7rem;
    text-transform: uppercase;
}

.ai-preview-table td {
    font-size: 0.8rem;
}

.ai-notes {
    padding: 0.8rem 0.9rem;
    border-radius: 10px;
    color: #5f5024;
    background: #fff9df;
    font-size: 0.78rem;
}

.ai-disclaimer {
    color: var(--app-muted);
    font-size: 0.72rem;
}

.estimate-check-alert {
    display: flex;
    align-items: flex-start;
    gap: 0.7rem;
    padding: 0.85rem 1rem;
    border-bottom: 1px solid var(--app-border);
    font-size: 0.82rem;
}

.estimate-check-alert.check-success {
    color: #155b43;
    background: #e9f7f1;
}

.estimate-check-alert.check-warning {
    color: #7b4d0f;
    background: #fff7e7;
}

.estimate-check-alert.check-error {
    color: #8c2230;
    background: #fff0f2;
}

.estimate-check-alert i {
    flex: 0 0 auto;
    margin-top: 0.05rem;
    font-size: 1rem;
}

.eyebrow {
    color: var(--app-primary);
    font-size: 0.7rem;
    font-weight: 800;
    letter-spacing: 0.09em;
    text-transform: uppercase;
}

.hint-text,
.form-text {
    color: var(--app-muted);
    font-size: 0.75rem;
}

.required-mark {
    color: #bd2b37;
}

.form-label {
    font-size: 0.82rem;
    font-weight: 700;
}

.form-control,
.form-select,
.input-group-text {
    border-color: #ccd7d3;
}

.form-control:focus,
.form-select:focus,
.form-check-input:focus {
    border-color: var(--app-primary);
    box-shadow: 0 0 0 0.2rem rgba(31, 111, 95, 0.13);
}

.form-check-input:checked {
    background-color: var(--app-primary);
    border-color: var(--app-primary);
}

.btn-primary {
    --bs-btn-bg: var(--app-primary);
    --bs-btn-border-color: var(--app-primary);
    --bs-btn-hover-bg: var(--app-primary-dark);
    --bs-btn-hover-border-color: var(--app-primary-dark);
    --bs-btn-active-bg: var(--app-primary-dark);
    --bs-btn-active-border-color: var(--app-primary-dark);
}

.btn-outline-primary {
    --bs-btn-color: var(--app-primary);
    --bs-btn-border-color: var(--app-primary);
    --bs-btn-hover-bg: var(--app-primary);
    --bs-btn-hover-border-color: var(--app-primary);
}

.summary-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 1rem;
}

.summary-card {
    display: flex;
    align-items: center;
    gap: 0.9rem;
    min-width: 0;
    padding: 1.1rem;
    border: 1px solid var(--app-border);
    border-radius: 15px;
    background: #fff;
}

.summary-card p {
    margin: 0 0 0.12rem;
    color: var(--app-muted);
    font-size: 0.76rem;
}

.summary-card strong {
    display: block;
    overflow: hidden;
    font-size: clamp(1rem, 1.7vw, 1.35rem);
    line-height: 1.2;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.summary-total {
    color: #fff;
    background: linear-gradient(135deg, var(--app-primary), #2b8a76);
    border-color: transparent;
}

.summary-total p {
    color: rgba(255, 255, 255, 0.78);
}

.summary-icon {
    display: inline-grid;
    flex: 0 0 auto;
    width: 42px;
    height: 42px;
    place-items: center;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.16);
    font-size: 1.05rem;
}

.work-icon {
    color: var(--app-work);
    background: #edf4fc;
}

.material-icon {
    color: var(--app-material);
    background: #fff2e8;
}

.neutral-icon {
    color: #5c6670;
    background: #f0f2f4;
}

.bulk-toolbar {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 0.75rem 1rem;
    background: #f8faf9;
    border-bottom: 1px solid var(--app-border);
}

.selected-label {
    min-width: 112px;
    color: var(--app-primary-dark);
    font-size: 0.85rem;
}

.bulk-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.bulk-help {
    color: var(--app-muted);
    font-size: 0.73rem;
}

.percent-input {
    width: 110px;
}

.estimate-table {
    --bs-table-bg: #fff;
    width: 100%;
    min-width: 0;
    table-layout: fixed;
}

.estimate-table thead th {
    padding: 0.72rem 0.55rem;
    color: #5b6864;
    background: #f8faf9;
    border-bottom-width: 1px;
    font-size: 0.69rem;
    font-weight: 800;
    letter-spacing: 0.025em;
    text-transform: uppercase;
    white-space: nowrap;
}

.estimate-table tbody td {
    padding: 0.65rem 0.35rem;
    border-color: #edf1f0;
}

.estimate-row:hover td {
    background: #fcfdfd;
}

.estimate-row.row-invalid td {
    background: #fffafa;
}

.check-col {
    width: 34px;
    text-align: center;
}

.number-col {
    width: 36px;
    color: var(--app-muted);
    text-align: center;
}

.type-col { width: 112px; }
.name-col { width: auto; min-width: 0; }
.unit-col { width: 108px; }
.money-col { width: 122px; }
.quantity-col { width: 104px; }
.sum-col { width: 136px; }
.monitor-col { width: 106px; }
.action-col { width: 42px; text-align: center; }

.estimate-table .form-control,
.estimate-table .form-select {
    min-width: 0;
}

.row-sum {
    font-variant-numeric: tabular-nums;
}

.price-status {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.32rem;
    width: 100%;
    min-height: 30px;
    padding: 0.25rem 0.45rem;
    border: 1px solid transparent;
    border-radius: 999px;
    font-size: 0.66rem;
    font-weight: 800;
    line-height: 1.1;
    white-space: nowrap;
}

@media (min-width: 768px) {
    .estimate-card .table-responsive {
        overflow-x: hidden;
    }
}

.price-status:disabled {
    opacity: 1;
}

.price-status:not(:disabled):hover {
    filter: brightness(0.97);
}

.status-idle,
.status-loading,
.status-no-data {
    color: #5e6a66;
    background: #f0f3f2;
    border-color: #dfe6e3;
}

.status-market {
    color: #146143;
    background: #e7f7f0;
    border-color: #bce5d2;
}

.status-high {
    color: #a02231;
    background: #fff0f2;
    border-color: #f3c8ce;
}

.status-low {
    color: #1c5f9b;
    background: #edf5fc;
    border-color: #c8def1;
}

.status-search {
    color: #3b3100;
    background: #fff1a6;
    border-color: #e6cf59;
}

.estimate-row.search-active td {
    background: #fffdf1;
}

.price-overview {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.65rem;
    margin-bottom: 1.1rem;
}

.price-overview-item {
    padding: 0.75rem;
    border: 1px solid var(--app-border);
    border-radius: 12px;
    background: #f8faf9;
}

.price-overview-item span {
    display: block;
    margin-bottom: 0.15rem;
    color: var(--app-muted);
    font-size: 0.68rem;
}

.price-overview-item strong {
    font-size: 0.95rem;
}

.price-source-list {
    display: grid;
    gap: 0.5rem;
    margin: 0;
    padding: 0;
    list-style: none;
}

.price-source-list li {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.65rem 0.75rem;
    border: 1px solid var(--app-border);
    border-radius: 10px;
}

.price-source-list a {
    color: var(--app-primary-dark);
    font-size: 0.78rem;
    font-weight: 650;
    text-decoration: none;
}

.price-source-list a:hover {
    text-decoration: underline;
}

.price-source-list strong {
    flex: 0 0 auto;
    font-size: 0.78rem;
}

.monitoring-disclaimer {
    margin-top: 1rem;
    padding: 0.7rem 0.8rem;
    border-radius: 10px;
    color: var(--app-muted);
    background: #f5f7f6;
    font-size: 0.72rem;
}

.btn-row-delete {
    color: #7c8985;
    border: 0;
}

.btn-row-delete:hover {
    color: #b42331;
    background: #fdecef;
}

.table-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    border-top: 1px solid var(--app-border);
    background: #fff;
}

.footer-total {
    display: flex;
    align-items: baseline;
    gap: 1rem;
}

.footer-total span {
    color: var(--app-muted);
    font-size: 0.82rem;
}

.footer-total strong {
    color: var(--app-primary-dark);
    font-size: 1.45rem;
}

.empty-state {
    padding: 3.5rem 1rem;
    text-align: center;
}

.empty-state p {
    color: var(--app-muted);
    font-size: 0.85rem;
}

.empty-icon {
    display: inline-grid;
    width: 54px;
    height: 54px;
    place-items: center;
    border-radius: 16px;
    color: var(--app-primary);
    background: var(--app-primary-soft);
    font-size: 1.4rem;
}

.export-panel {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1.5rem;
    padding: 1.25rem 1.5rem;
    background: #fff;
}

.toast-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--app-primary);
}

.toast-dot.error { background: #bd2b37; }
.toast-dot.warning { background: #b97412; }

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

    .bulk-toolbar {
        grid-template-columns: 1fr;
    }

    .bulk-controls {
        flex-wrap: wrap;
    }

    .position-actions {
        width: 100%;
    }
}

@media (max-width: 1199.98px) {
    .estimate-workspace {
        grid-template-columns: 1fr;
    }

    .yandex-search-card {
        position: static;
    }
}

@media (max-width: 575.98px) {
    .app-header {
        position: static;
    }

    .app-header .small,
    .save-status {
        display: none;
    }

    .summary-grid {
        grid-template-columns: 1fr;
        gap: 0.65rem;
    }

    .summary-card {
        padding: 0.9rem 1rem;
    }

    .section-heading,
    .export-panel,
    .table-footer {
        align-items: stretch;
        flex-direction: column;
    }

    .section-heading .btn,
    .export-panel .btn {
        width: 100%;
    }

    .position-actions {
        display: grid;
        grid-template-columns: 1fr;
    }

    .hint-text {
        display: none;
    }

    .bulk-controls .btn {
        flex: 1 1 auto;
    }

    .percent-input {
        width: 100%;
    }

    .footer-total {
        justify-content: space-between;
    }
}

@media (max-width: 991.98px) {
    .table-responsive {
        overflow: visible;
    }

    .estimate-table {
        display: block;
        min-width: 0;
        padding: 0.75rem;
        background: #f8faf9;
    }

    .estimate-table thead {
        display: none;
    }

    .estimate-table tbody {
        display: grid;
        gap: 0.75rem;
    }

    .estimate-table tr {
        display: block;
        overflow: hidden;
        border: 1px solid var(--app-border);
        border-radius: 12px;
        background: #fff;
        box-shadow: 0 3px 12px rgba(29, 41, 38, 0.04);
    }

    .estimate-table tbody td,
    .estimate-table tbody td:first-child,
    .estimate-table tbody td:last-child {
        display: grid;
        grid-template-columns: 102px minmax(0, 1fr);
        align-items: center;
        width: auto;
        min-width: 0;
        padding: 0.48rem 0.7rem;
        text-align: left !important;
        border: 0;
        border-bottom: 1px solid #edf1f0;
    }

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

    .estimate-table tbody td::before {
        content: attr(data-label);
        color: var(--app-muted);
        font-size: 0.69rem;
        font-weight: 700;
        text-transform: uppercase;
    }

    .estimate-table .check-col,
    .estimate-table .number-col,
    .estimate-table .action-col {
        min-height: 40px;
    }

    .estimate-table .row-sum {
        color: var(--app-primary-dark);
        font-size: 1rem;
        text-align: right;
    }

    .estimate-table .price-status {
        justify-self: end;
        width: auto;
        min-width: 112px;
    }

    .estimate-table .btn-row-delete {
        justify-self: end;
    }
}

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

    .price-source-list li {
        flex-direction: column;
        gap: 0.25rem;
    }
}

@media print {
    .app-header,
    .bulk-toolbar,
    .table-footer .btn,
    .export-panel,
    .yandex-search-card,
    .action-col,
    .monitor-col,
    .check-col {
        display: none !important;
    }

    body { background: #fff; }
    .card { box-shadow: none; }
    .app-container { max-width: none; }
}
