
/* ============================================================
КРОССБРАУЗЕРНАЯ СОВМЕСТИМОСТЬ
============================================================ */

*, *::before, *::after {
    box-sizing: border-box;
    -moz-box-sizing: border-box;
    -webkit-box-sizing: border-box;
}

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

/* Firefox-specific fixes */
@-moz-document url-prefix() {
    .container {
        width: 98%;
        max-width: 100%;
    }
    
    .works {
        width: 100%;
        table-layout: fixed;
    }
}
/* ============================================================
   БАЗА
   ============================================================ */
* { box-sizing: border-box; }
body { font-family: Arial, Helvetica, sans-serif; margin: 0; background: #f4f4f4; color: #222; font-size: 14px; }

.top {
    background: #2c3e50;
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    -moz-box-sizing: border-box;
}
.top a { color: #fff; margin-left: 15px; text-decoration: none; }
.top a:hover { text-decoration: underline; }

.container { width: 98%; max-width: 100%; margin: 20px auto; background: #fff; padding: 20px; border-radius: 6px; }
.box { max-width: 360px; margin: 80px auto; background: #fff; padding: 30px; border-radius: 6px; }

h1 { margin-top: 0; font-size: 22px; }
h2 { font-size: 17px; margin: 22px 0 8px; }
h3 { font-size: 15px; margin: 18px 0 6px; }

label { display: block; margin-top: 6px; font-weight: bold; font-size: 13px; }
input, select, textarea { padding: 6px 8px; margin-top: 4px; border: 1px solid #ccc; border-radius: 4px; font-size: 13px; font-family: inherit; }
textarea { width: 100%; min-height: 70px; }

/* Поля в «обычных» формах (вход, шаблоны) — на всю ширину */
form:not(.inline-form):not(.filter-bar) > input:not([type="hidden"]):not([type="file"]),
form:not(.inline-form):not(.filter-bar) > select,
form:not(.inline-form):not(.filter-bar) > textarea { display: block; width: 100%; max-width: 640px; }
#conds input { width: 100%; margin-top: 0; }

.inline-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.inline-form input, .inline-form select { margin-top: 0; }

button { margin-top: 8px; padding: 8px 16px; background: #2980b9; color: #fff; border: none; border-radius: 4px; cursor: pointer; font-size: 14px; }
button:not(.btn-icon):not(.btn-add-row):hover { background: #2471a3; }
button.danger { background: #c0392b; }
button.danger:hover { background: #a93226; }
button.small { padding: 2px 8px; margin: 0; }

.button { display: inline-block; padding: 8px 16px; background: #2980b9; color: #fff; text-decoration: none; border-radius: 4px; font-size: 14px; }
.button:hover { background: #2471a3; }
.button.secondary { background: #7f8c8d; }
.button.secondary:hover { background: #6c7a7b; }

table { width: 100%; border-collapse: collapse; margin-top: 10px; }
th, td { border: 1px solid #ddd; padding: 6px; text-align: left; vertical-align: top; }
th { background: #ecf0f1; }

.error   { background: #fdecea; color: #c0392b; padding: 10px; border-radius: 4px; margin: 10px 0; }
.success { background: #d5f5e3; color: #1e8449; padding: 10px; border-radius: 4px; margin: 10px 0; }
.muted   { color: #6b7280; font-size: 12px; font-weight: normal; }
.hidden-form { display: none; }

/* ============================================================
   НАСТРОЙКИ НАД БЛАНКОМ / ФИЛЬТРЫ
   ============================================================ */
.settings-row {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
    margin-bottom: 20px;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    -moz-box-sizing: border-box;
}

.settings-row > div {
    flex: 1;
    min-width: 200px;
}
.settings-row label { margin-top: 0; }

.filter-bar { display: flex; gap: 16px; flex-wrap: wrap; align-items: flex-end; margin: 8px 0 12px; padding: 10px 12px; background: #f8f9fa; border: 1px solid #eee; border-radius: 6px; }
.filter-bar label { margin-top: 0; }
.filter-bar input, .filter-bar select { margin-top: 2px; }

/* Журнал действий */
.log-summary { display: flex; gap: 12px; flex-wrap: wrap; margin: 16px 0; }
.log-stat { flex: 1 1 150px; padding: 10px 14px; background: #f8f9fa; border: 1px solid #eee; border-radius: 6px; }
.log-stat span { display: block; color: #6b7280; font-size: 12px; }
.log-stat b { display: block; margin-top: 4px; font-size: 20px; color: #2c3e50; }
.pagination { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin: 16px 0 8px; }
.pagination a, .pagination-current, .pagination-gap { display: inline-block; padding: 4px 10px; border: 1px solid #ddd; border-radius: 4px; text-decoration: none; color: #2c3e50; background: #fff; font-size: 13px; }
.pagination a:hover { background: #f0f4f8; }
.pagination-current { background: #2c3e50; border-color: #2c3e50; color: #fff; font-weight: bold; }
.pagination-gap { border: none; background: transparent; color: #999; }

.cat-select { max-width: 100%; }

/* Бейджи (счётчики) */
.badge { display: inline-block; min-width: 28px; padding: 2px 8px; border-radius: 12px; font-size: 12px; font-weight: bold; text-align: center; text-decoration: none; }
.badge-cat      { background: #d6eaf8; color: #1f618d; }
.badge-none     { background: #eee;    color: #666; }
.badge-material { background: #d5f5e3; color: #1e8449; }
a.badge:hover { filter: brightness(.95); }

/* ============================================================
   КНОПКИ-ИКОНКИ
   ============================================================ */
.btn-icon { display: inline-block; width: 32px; height: 30px; padding: 0; margin: 1px; border: none; border-radius: 6px; cursor: pointer; font-size: 15px; line-height: 30px; text-align: center; text-decoration: none; vertical-align: middle; color: #222; transition: transform .1s, filter .15s; }
.btn-icon:hover  { transform: scale(1.12); filter: brightness(1.05); }
.btn-icon:active { transform: scale(.92); }
.btn-edit   { background: #fcf3cf; }
.btn-save   { background: #d5f5e3; }
.btn-cancel { background: #e5e8e8; }
.btn-del    { background: #fadbd8; }
.btn-word   { background: #d6eaf8; }
.btn-excel  { background: #d5f5e3; }
.actions-cell { white-space: nowrap; }

/* ============================================================
   КОМПАКТНАЯ ТАБЛИЦА МАТЕРИАЛОВ / КАТЕГОРИЙ
   ============================================================ */
.items-table th, .items-table td { padding: 3px 6px; font-size: 13px; vertical-align: middle; }
.items-table .cell-input, .items-table .cell-select { width: 100%; padding: 3px 6px; margin: 0; border: 1px solid transparent; border-radius: 3px; font-size: 13px; background: transparent; color: #2c3e50; }
.items-table .cell-input:disabled, .items-table .cell-select:disabled { color: #2c3e50; opacity: 1; cursor: default; -webkit-text-fill-color: #2c3e50; }
.items-table .cell-select:disabled { appearance: none; -webkit-appearance: none; -moz-appearance: none; }
.items-table tr.editing { background: #fffbe6; }
.items-table tr.editing .cell-input, .items-table tr.editing .cell-select { border-color: #2980b9; background: #fff; }

/* ============================================================
   БЛАНК ДОКУМЕНТА
   ============================================================ */
.blank { border: 2px solid #333; padding: 20px; margin-top: 10px; background: #fff; }
.blank-title { text-align: center; font-size: 22px; font-weight: bold; padding: 10px 0 8px; letter-spacing: 1px; border-bottom: 2px solid #333; margin-bottom: 10px; }
.blank-header { display: flex; justify-content: space-between; align-items: flex-start; border-bottom: 1px solid #999; padding-bottom: 10px; margin-bottom: 10px; }
.blank-logo { width: 160px; height: 90px; border: 1px dashed #aaa; display: flex; align-items: center; justify-content: center; text-align: center; flex-shrink: 0; }
.blank-logo img { max-width: 100%; max-height: 90px; object-fit: contain; display: block; }
.logo-stub { color: #999; font-size: 12px; }
.blank-from { flex: 1; padding-left: 20px; }
.section-title { font-weight: bold; margin: 15px 0 5px; background: #eef2f4; padding: 5px 8px; }

.kv { width: auto; }
.kv td { border: none; padding: 2px 8px; }
.kv-key { font-weight: bold; white-space: nowrap; }
.hint { color: #6b7280; font-size: 11px; font-style: italic; }
.inline-input { width: 160px; margin-top: 0; }
.wide-input { width: 100%; }

.works th { background: #dfe6e9; font-size: 12px; text-align: center; padding: 5px 4px; }
.works td { font-size: 13px; padding: 4px; vertical-align: middle; }
.works td input, .works td select { margin-top: 0; }
.works .cat-select { width: 100%; font-size: 12px; }
.row-num { text-align: center; }
.js-sum { text-align: right; white-space: nowrap; }
.total-label { text-align: right; font-weight: bold; }
.total-value { text-align: right; font-weight: bold; white-space: nowrap; }
.info-box { border: 1px solid #ccc; min-height: 40px; padding: 8px; white-space: pre-wrap; }
.sign td { border: none; padding: 8px; }
.sign-name { font-weight: bold; }
.sign-mp { text-align: center; }

/* Кнопка «+ Добавить строку» — справа, под колонкой быстрого поиска */
.add-row-wrap { display: flex; justify-content: flex-end; padding-right: 44px; margin: 8px 0 16px; }
.btn-add-row { background: #27ae60; color: #fff; border: none; padding: 8px 18px; border-radius: 6px; cursor: pointer; font-size: 14px; margin-top: 0; }
.btn-add-row:hover { background: #229954; }

/* ============================================================
   БЫСТРЫЙ ПОИСК ПОЗИЦИЙ
   ============================================================ */
.pick-wrap { position: relative; width: 100%; min-width: 130px; }
.pick-input { width: 100%; padding: 6px 8px 6px 26px; box-sizing: border-box; border: 1px solid #bdc3c7; border-radius: 4px; font-size: 13px; margin-top: 0;
    background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%23999' stroke-width='2'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'/%3E%3C/svg%3E") no-repeat 6px center; }
.pick-input:focus { outline: none; border-color: #2980b9; box-shadow: 0 0 0 2px rgba(41,128,185,.15); }

.pick-dropdown { position: fixed; background: #fff; border: 1px solid #2980b9; border-radius: 6px; max-height: 360px; overflow-y: auto; z-index: 9999; box-shadow: 0 8px 28px rgba(0,0,0,.22); display: none; width: 360px; }
.pick-dropdown.open { display: block; }
.pick-header { padding: 6px 12px; font-size: 11px; color: #888; background: #f8f9fa; border-bottom: 1px solid #eee; position: sticky; top: 0; z-index: 1; }
.pick-group { padding: 5px 12px 3px; font-size: 11px; font-weight: bold; text-transform: uppercase; letter-spacing: .5px; color: #fff; }
.pick-group.group-service  { background: #2980b9; }
.pick-group.group-material { background: #27ae60; }
.pick-item { display: flex; align-items: center; gap: 10px; padding: 8px 12px; cursor: pointer; border-bottom: 1px solid #f0f0f0; transition: background .12s; }
.pick-item:last-child { border-bottom: none; }
.pick-item:hover, .pick-item.active { background: #eaf4fb; }
.pick-icon { width: 28px; height: 28px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 14px; flex-shrink: 0; }
.pick-icon.icon-service  { background: #d6eaf8; }
.pick-icon.icon-material { background: #d5f5e3; }
.pick-body { flex: 1; min-width: 0; }
.pick-name { font-size: 13px; font-weight: 600; color: #2c3e50; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pick-name mark { background: #fff3cd; color: #2c3e50; border-radius: 2px; padding: 0 1px; }
.pick-meta { font-size: 11px; color: #95a5a6; margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pick-price { text-align: right; flex-shrink: 0; }
.pick-price-val { font-size: 13px; font-weight: bold; color: #27ae60; white-space: nowrap; }
.pick-price-unit { font-size: 10px; color: #aaa; }
.pick-empty { padding: 20px; text-align: center; color: #aaa; font-size: 13px; }
.pick-footer { padding: 5px 12px; font-size: 10px; color: #bbb; background: #f8f9fa; border-top: 1px solid #eee; text-align: center; }

/* Всплывающее окно с полным текстом позиции — в левой части экрана */
.pick-tooltip { position: fixed; left: 16px; background: #2c3e50; color: #fff; padding: 12px 16px; border-radius: 8px; max-width: 320px; font-size: 13px; line-height: 1.5; box-shadow: 0 8px 24px rgba(0,0,0,.3); z-index: 10000; display: none; pointer-events: none; }
.pick-tooltip.show { display: block; }
.pick-tooltip .tt-name  { font-weight: bold; font-size: 14px; margin-bottom: 6px; word-break: break-word; }
.pick-tooltip .tt-row   { color: #bdc3c7; font-size: 12px; }
.pick-tooltip .tt-price { color: #2ecc71; font-weight: bold; font-size: 15px; margin-top: 6px; }
/* ============================================================
УЛУЧШЕННАЯ ТАБЛИЦА СМЕТЫ
============================================================ */

/* Таблица работ — на всю ширину */
.works {
    width: 100%;
    max-width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
    box-sizing: border-box;
    -moz-box-sizing: border-box;
    -webkit-box-sizing: border-box;
}
/* Ячейка наименования — с поиском внутри */
.name-cell {
    position: relative;
    padding: 0 !important;
}

.name-cell .pick-wrap {
    width: 100%;
    height: 100%;
}

.name-cell .pick-input {
    width: 100%;
    border: none;
    border-radius: 0;
    padding: 6px 30px 6px 8px;
    font-size: 13px;
}

.name-cell .pick-input:focus {
    background: #fffbe6;
    box-shadow: inset 0 0 0 2px #2980b9;
}

/* Иконка лупы справа от поля */
.name-cell .pick-input {
    background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%23999' stroke-width='2'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'/%3E%3C/svg%3E") no-repeat right 8px center;
    background-size: 14px;
}

/* Dropdown поиска — позиционируем относительно ячейки */
.name-cell .pick-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 1000;
    width: auto !important;
    min-width: 400px;
    max-width: 600px;
}

/* Кнопка удаления — появляется при наведении на строку */
.works tbody tr {
    transition: background 0.15s;
}

.works tbody tr:hover {
    background: #f8f9fa;
}

.works tbody tr .btn-del {
    opacity: 0.6;
    transition: opacity 0.15s;
}

.works tbody tr:hover .btn-del {
    opacity: 1;
}

/* Компактные поля ввода */
.works td input,
.works td select {
    width: 100%;
    box-sizing: border-box;
    margin: 0;
    padding: 4px 6px;
    font-size: 12px;
}

/* Фиксированная ширина для числовых полей */
.works td input.js-qty,
.works td input.js-price,
.works td input.js-discount,
.works td input.js-cost-price {
    text-align: right;
}

/* Итого — правое выравнивание */
.works tfoot td {
    padding: 8px 6px;
    background: #f8f9fa;
}
/* Исправление позиционирования dropdown поиска */
.name-cell {
    position: relative;
}

.name-cell .pick-wrap {
    position: relative;
    width: 100%;
}

.name-cell .pick-dropdown {
    position: absolute !important;
    top: 100% !important;
    left: 0 !important;
    right: 0 !important;
    width: auto !important;
    min-width: 400px;
    max-width: 600px;
    z-index: 1000;
    margin-top: 2px;
}

.name-cell .pick-input {
    width: 100%;
    padding: 6px 30px 6px 8px;
}

/* Кнопка удаления появляется при наведении */
.works tbody tr .btn-del {
    opacity: 0.6;
    transition: opacity 0.15s;
}

.works tbody tr:hover .btn-del {
    opacity: 1;
}
/* Подсветка строк с материалами без закупки */
.warning-row {
    background: #fff3cd !important;
}
.warning-row td {
    border-left: 3px solid #ffc107;
}
/* В конец style.css добавь: */
.js-type {
    font-size: 11px !important;
    padding: 1px 2px !important;
    width: 38px !important;
    height: 28px;
    line-height: 1;
}

.js-type option {
    font-size: 11px;
    padding: 0;
}

/* ============================================================
   ДОСТУПНОСТЬ И АДАПТИВНОСТЬ
   ============================================================ */

img { max-width: 100%; }
body { -webkit-text-size-adjust: 100%; }

a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
.button:focus-visible {
    outline: 3px solid rgba(41, 128, 185, .45);
    outline-offset: 2px;
}

@media (max-width: 900px) {
    .top {
        flex-wrap: wrap;
        gap: 4px 0;
        padding: 10px 12px;
    }
    .top > div:last-child {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        gap: 6px 16px;
        width: 100%;
    }
    .top a { margin-left: 0; }

    .container {
        width: 100%;
        margin: 0;
        padding: 12px;
        border-radius: 0;
    }
    .box {
        width: 92%;
        margin: 24px auto;
        padding: 20px;
    }

    h1 { font-size: 19px; }
    h2 { font-size: 16px; }

    .filter-bar { gap: 10px; padding: 8px 10px; }
    .filter-bar > div { flex: 1 1 45%; min-width: 140px; }
    .inline-form input, .inline-form select { max-width: 100%; }

    /* 16px не даёт iOS зумить страницу при фокусе на поле */
    input, select, textarea, button { font-size: 16px; }
    .items-table .cell-input, .items-table .cell-select,
    .works td input, .works td select { font-size: 16px; }

    .btn-icon { width: 40px; height: 38px; line-height: 38px; font-size: 17px; }
    button { min-height: 38px; }
    .button { padding: 9px 14px; }

    /* Широкие таблицы прокручиваем, а не обрезаем */
    .container table:not(.works):not(.kv):not(.sign) {
        display: block;
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        white-space: nowrap;
    }
    .items-table th, .items-table td { white-space: nowrap; }

    /* Редактор сметы: прокрутка вместо сжатия колонок */
    .blank { overflow-x: auto; padding: 10px; }
    .works { min-width: 860px; }
    .blank-header { flex-wrap: wrap; gap: 10px; }
    .blank-from { padding-left: 0; }
    .settings-row { gap: 10px; }
    .settings-row > div { flex: 1 1 100%; min-width: 0; }

    /* Выпадающий поиск не должен вылезать за экран */
    .name-cell .pick-dropdown,
    .pick-dropdown {
        min-width: 0 !important;
        max-width: 92vw !important;
    }

    .pick-tooltip { display: none !important; }
}

@media (max-width: 560px) {
    .top { font-size: 13px; }
    .top > div:last-child { gap: 4px 12px; }
    .actions-cell .btn-icon { margin: 0 1px; }
    .add-row-wrap { padding-right: 0; justify-content: stretch; }
    .btn-add-row { width: 100%; }
    .badge { min-width: 24px; }
}

/* На устройствах без hover кнопка удаления должна быть видна всегда */
@media (hover: none) {
    .works tbody tr .btn-del { opacity: 1; }
}

/* ============================================================
   СТАТУСЫ ДОКУМЕНТОВ И АКТУАЛЬНОСТЬ
   ============================================================ */
.summary-cards { display: flex; gap: 10px; flex-wrap: wrap; margin: 14px 0 6px; }
.summary-card {
    flex: 1 1 150px;
    min-width: 140px;
    padding: 10px 14px;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    background: #fff;
    color: inherit;
    text-decoration: none;
    transition: box-shadow .15s, border-color .15s, transform .1s;
}
.summary-card:hover { border-color: #b8c4d0; transform: translateY(-1px); }
.summary-card.active { border-color: #3498db; box-shadow: 0 0 0 2px #d6eaf8; }
.summary-card .card-label { display: block; color: #6b7280; font-size: 12px; }
.summary-card b { display: block; margin-top: 2px; font-size: 22px; color: #2c3e50; }
.summary-card.card-progress { border-left: 4px solid #f39c12; }
.summary-card.card-wait     { border-left: 4px solid #3498db; }
.summary-card.card-done     { border-left: 4px solid #27ae60; }
.summary-card.card-alert    { border-left: 4px solid #c0392b; }
.summary-card.card-alert b  { color: #c0392b; }

.status-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: bold;
    white-space: nowrap;
}
.status-draft       { background: #e5e7eb; color: #374151; }
.status-sent        { background: #dbeafe; color: #1d4ed8; }
.status-approved    { background: #cffafe; color: #0e7490; }
.status-in_progress { background: #ffedd5; color: #c2410c; }
.status-done        { background: #d1fae5; color: #047857; }
.status-cancelled   { background: #fee2e2; color: #b91c1c; }
.status-none        { background: #f3f4f6; color: #6b7280; border: 1px dashed #cbd5e1; }

.status-select { padding: 3px 6px; font-size: 12px; border-radius: 6px; border: 1px solid #d1d5db; max-width: 100%; }
.status-form { margin: 0; }
.status-form select { margin: 0; width: auto; }

.doc-status-bar { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin: 6px 0 12px; }

.validity-ok      { color: #6b7280; }
.validity-none    { color: #9ca3af; font-style: italic; }
.validity-soon    { color: #b45309; font-weight: 600; }
.validity-overdue { color: #b91c1c; font-weight: 700; }

tr.doc-attention td { background: #fff7ed; }
.attention-hint { color: #b45309; font-size: 11px; margin-top: 2px; }

.notice { padding: 10px 12px; border-radius: 6px; margin: 10px 0; font-size: 13px; }
.notice-warn { background: #fef3c7; border: 1px solid #fcd34d; color: #92400e; }

.btn-copy { background: #e8f6f3; }

/* Быстрое продление срока действия сметы */
.date-quick { display: inline-flex; gap: 4px; margin-left: 8px; vertical-align: middle; font-weight: normal; }
.date-quick button {
    margin: 0;
    padding: 2px 8px;
    font-size: 11px;
    font-weight: normal;
    color: #37474f;
    background: #fff;
    border: 1px solid #cfd8dc;
    border-radius: 4px;
}
.date-quick button:hover { background: #eaf4fb; border-color: #90caf9; }
#validHint { margin-left: 8px; font-weight: normal; }
