/*
 * =========================================================
 * ШАБЛОН ДОКУМЕНТА В ВКЛАДКАХ «ОБОРУДОВАНИЕ» И «ФУНКЦИИ»
 * (js/template-tables.js)
 *
 * Размеченные элементы подсвечиваются теми же правилами,
 * что и во вкладке «Документы» ([data-node-id] в editor.css).
 * =========================================================
 */

.tt-view { font-family: Arial, sans-serif; font-size: 13px; }

.tt-head { margin-bottom: 4px; }

.tt-info { min-height: 16px; color: #666; font-size: 12px; margin-bottom: 6px; }

.tt-scroll {
    overflow: auto;
    max-height: 70vh;
    padding: 8px;
    background: #e8e8e8;
    border: 1px solid #ccc;
    border-radius: 3px;
}

.tt-scope { background: #fff; width: max-content; min-width: 100%; box-sizing: border-box; }

.tt-scope table { border-collapse: collapse; }

/* размеченная таблица — выбирается кликом по её линии */
.tt-scope table[data-node-id] { cursor: default; }

/* активная таблица */
.tt-scope table.tt-active[data-node-id] {
    outline: 3px solid #ff9800;
    box-shadow: 0 0 0 4px rgba(255, 152, 0, 0.3);
}

/* значения других устройств/функций и текущего */
.tt-scope td.tt-filled,
.tt-scope th.tt-filled { background: #e3f1df !important; font-size: 11px; }

.tt-scope td.tt-mine,
.tt-scope th.tt-mine { background: #d4e8ff !important; font-size: 11px; }

/* строка со списками величин */
.tt-scope td.tt-edit,
.tt-scope th.tt-edit { background: #fff6d6 !important; padding: 1px !important; }

.tt-scope td.tt-bad,
.tt-scope th.tt-bad { color: #c62828; }

/* поле ячейки: нажать — откроется калькулятор */
.tt-scope .tt-cell {
    display: block;
    width: 100%;
    min-width: 0;
    min-height: 20px;
    box-sizing: border-box;
    padding: 1px 3px;
    border: 1px dashed #c9a227;
    border-radius: 2px;
    background: #fff;
    color: #222;
    font: 11px Arial, sans-serif;
    text-align: left;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    cursor: text;
}

.tt-scope .tt-cell:hover { border-color: #1976d2; }
.tt-scope .tt-cell.tt-cell-f { color: #0b57d0; font-weight: bold; }
/* строка другого устройства/функции: видна, но не правится */
.tt-scope .tt-cell.tt-other { cursor: default; border-style: solid; border-color: #bbb; background: #f4f4f4; }
.tt-scope .tt-cell.tt-other:hover { border-color: #bbb; }
.tt-scope .tt-cell.tt-cell-err { color: #c62828; border-color: #c62828; }


/* ---------- калькулятор ячейки ---------- */

.tt-pop {
    position: fixed;
    z-index: 3000;
    width: 360px;
    max-width: calc(100vw - 16px);
    box-sizing: border-box;
    padding: 8px;
    background: #fff;
    border: 1px solid #888;
    border-radius: 5px;
    box-shadow: 0 6px 22px rgba(0, 0, 0, 0.28);
    font: 12px Arial, sans-serif;
    color: #222;
}

.tt-pop-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }

.tt-seg { display: inline-flex; }
.tt-seg button {
    padding: 3px 12px;
    border: 1px solid #999;
    background: #f3f3f3;
    font-size: 12px;
    cursor: pointer;
}
.tt-seg button:first-child { border-radius: 3px 0 0 3px; }
.tt-seg button:last-child { border-radius: 0 3px 3px 0; border-left: 0; }
.tt-seg button.on { background: #1976d2; border-color: #1976d2; color: #fff; }

.tt-pop-x { border: 0; background: none; font-size: 18px; line-height: 1; cursor: pointer; color: #666; }

.tt-pop-input {
    width: 100%;
    box-sizing: border-box;
    padding: 5px 6px;
    border: 1px solid #999;
    border-radius: 3px;
    font-size: 13px;
}
.tt-pop-input.tt-pop-mono { font-family: Consolas, monospace; }

.tt-pop-tools { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; margin-top: 6px; }
.tt-pop-tools select { flex: 1 1 130px; min-width: 0; padding: 3px; font-size: 12px; }
.tt-pop-ops { display: inline-flex; gap: 2px; }
.tt-pop-ops button {
    width: 26px;
    padding: 2px 0;
    border: 1px solid #999;
    border-radius: 3px;
    background: #f3f3f3;
    font-size: 13px;
    cursor: pointer;
}
.tt-pop-ops button:hover { background: #e3eefb; }

.tt-pop-foot { display: flex; align-items: center; gap: 10px; margin-top: 8px; min-height: 22px; }
.tt-pop-nwrap { color: #666; }
.tt-pop-n { width: 44px; padding: 2px; }
.tt-pop-res { flex: 1; text-align: right; font-weight: bold; color: #1b5e20; overflow-wrap: anywhere; }
.tt-pop-res.bad { color: #c62828; font-weight: normal; font-size: 11px; }

.tt-pop-desc { margin-top: 4px; font-size: 11px; color: #666; overflow-wrap: anywhere; }
.tt-pop-desc:empty { display: none; }

.tt-pop-btns { display: flex; justify-content: flex-end; gap: 6px; margin-top: 8px; }
.tt-pop-btns button { padding: 4px 14px; border: 1px solid #999; border-radius: 3px; background: #f3f3f3; cursor: pointer; }
.tt-pop-btns button[data-a="done"] { background: #1976d2; border-color: #1976d2; color: #fff; }

/* перетаскивание панели за заголовок */
.tt-pop-head { cursor: move; user-select: none; }
.tt-pop-head button { cursor: pointer; }
.tt-pop.tt-dragging { opacity: 0.9; }

.tt-pop-hint { margin-top: 6px; font-size: 11px; color: #1976d2; }

/* калькулятор открыт: размеченные элементы шаблона можно выбирать кликом */
.tt-scroll.tt-picking .tt-scope [data-node-id]:not(table) { cursor: crosshair; }
.tt-scroll.tt-picking .tt-scope [data-node-id]:not(table):hover {
    outline: 2px solid #1976d2;
    background: #d9eaff;
}

.tt-pop-title { font-weight: bold; color: #444; }
