/* =====================================================================
   acc2-base.css — always-on foundation (TODO-079 Phase 4b/5)
   Font, page shell, color utilities, editable/overlay, glightbox,
   minimal --ui-* for tablesorter (styles.css не auto-load, TODO-080).
   Loaded before acc2-tokens / kit. Do not put page-specific rules here.
   ===================================================================== */

@import url('https://fonts.googleapis.com/css?family=Roboto:400,700&display=swap&subset=cyrillic');

:root {
    /* Core colors used by base utilities / overlays */
    --color-transparent: transparent;
    --color-white: #fff;
    --color-black: #000;
    --color-overlay-dark: rgba(0, 0, 0, 0.55);
    --color-overlay-light: rgba(255, 255, 255, 0.85);
    --color-overlay-light-soft: rgba(255, 255, 255, 0.82);

    --radius-round: 50%;
    --border-none: none;
    --border-reset: 0;
    --border-width: 1px;
    --border-style: solid;

    /* tablesorter + shared UI tokens (subset of styles.css :root) */
    --ui-color-primary-blue: #1c68a2;
    --ui-color-blue: #0971d5;
    --ui-color-grey: #6e6e6e;
    --ui-blue: #4297D7;
    --ui-blue-border-soft: #B6D0E4;
    --ui-blue-spinner-border: rgba(66, 151, 215, 0.2);
    --ui-bg-page: #f1f1f3;
    --ui-bg-blue-soft: #DFEFFC;
    --ui-bg-blue-edit: #eaf4fd;
    --ui-bg-glass-85-dfeffc: linear-gradient(to bottom, #f1f9ff 0%, #edf7ff 10%, #d9ebfa 30%, #f2f9ff 100%);
    --ui-bg-panel-glass: var(--ui-bg-blue-soft) var(--ui-bg-glass-85-dfeffc) repeat-x scroll 50% 50%;

    --border-ui-soft: var(--border-width) var(--border-style) var(--ui-blue-border-soft);
    --border-spinner: 4px var(--border-style) var(--ui-blue-spinner-border);
    --border-spinner-lg: 5px var(--border-style) var(--ui-blue-spinner-border);
    --border-spinner-success: 4px var(--border-style) var(--status-green);

    --text-shadow-heading: 1px 1px 1px var(--color-white);
    --text-shadow-emboss: 1px 1px 0 var(--color-white);

    --status-red: red;
    --status-red-soft: #ffe6e3;
    --status-red-flash: rgba(210, 50, 50, 0.35);
    --status-green: green;
    --status-orange: #FF960A;
    --status-purple: #702bb4;
    --row-blue-soft: #d6f1ff;

    --shadow-editable-access-normal: inset 0 0 0 100px var(--color-transparent);
    --shadow-editable-access-denied: inset 0 0 0 100px var(--status-red-flash);
    --transition-spinner: border-color 0.2s ease, border-top-color 0.2s ease;
}

/* Typography — same as styles.css so opt-out pages stay readable */
* {
    font-family: Helvetica, Roboto;
    line-height: 1.4 !important;
}

body {
    /* Только размер: shorthand font:+!important из legacy ломал MD-диалоги.
       family уже задан через * выше; поля с font:inherit берут 12px отсюда. */
    font-size: 12px;
    background-color: var(--ui-bg-page);
    color: var(--color-black) !important;
}

/* Page shell (header.php).
   #main gutters — из styles.css: без always-on styles topbar/breadcrumb липнут к краям. */
div#wrapper {
    position: relative;
    width: 100%;
}

div#main {
    padding: 15px;
    padding-top: 0;
    text-align: center;
}

.page-center {
    width: 100%;
    box-sizing: border-box;
}

.page-center .page-shell {
    display: block;
    width: 100%;
    min-width: 0;
    max-width: none;
    margin: 0;
    padding: 0 0 10px;
    text-align: initial;
}

/* Color utilities — единая nav-палитра (токены из acc2-tokens / kit-shell --green).
   Дубль в kit-table убран (Wave D). */
.c-grey,
.c-grey * {
    color: var(--nav-muted, var(--ui-color-grey)) !important;
}

.c-blue,
.c-blue * {
    color: var(--nav-blue-deep, #00478f) !important;
}

.c-blue-light,
.c-blue-light * {
    color: var(--nav-blue-light, #0d92ef) !important;
}

.c-red,
.c-red * {
    color: var(--nav-red, #c62828) !important;
}

.c-orange,
.c-orange * {
    color: var(--nav-orange, #ff960a) !important;
}

.c-green,
.c-green * {
    color: var(--green, #1a8f4c) !important;
}

/* Копирование текста: атрибуты data-copy / data-copy-from, логика — jStyles.js.
   .copy-float — значок у текста при наведении и по фокусу клавиатуры (место выбирает скрипт:
   соседнюю ссылку и поле значок не закрывает); он один на страницу и лежит в body
   (или в открытом диалоге), поэтому токены кита (.acc2) до него могут не дойти — значения с запасными. */
:is([data-copy], [data-copy-from]):not(:empty) { cursor: pointer; }
/* подсветка «кликни — скопируется» только там, где копирует клик по тексту: не у кнопок, не у настоящих ссылок
   и не у значка в цветной шапке (.head-action: цвет шапки, при наведении — подложка, «скопировано» — галочка) */
:is([data-copy], [data-copy-from]):not(.btn, .head-action a, a[href]:not([href="#"])):hover,
:is([data-copy], [data-copy-from]):not(.btn, .head-action a, a[href]:not([href="#"])):hover i.fa-copy { color: var(--nav-blue) !important; }
:is([data-copy], [data-copy-from]):not(.btn, .head-action a).is-copied,
:is([data-copy], [data-copy-from]):not(.btn, .head-action a).is-copied i.fa-copy { color: var(--green, #1a8f4c) !important; }
/* «Скопировано»: значок копии на время становится галочкой */
.is-copied > i.fa-copy { --fa: "\f00c"; font-weight: 900; }
/* Вид — как у иконок действий: цвет ссылки, без рамки, при наведении полупрозрачная подложка.
   --copy-bg — почти непрозрачный белый под значком: он стоит поверх соседнего текста, и без
   подложки буквы просвечивали бы. Появление и исчезание — по .2s, без задержек (FADE в
   jStyles.js); visibility гаснет после opacity, чтобы на гаснущий значок можно было вернуться.
   Подложка при наведении — за .15s, как у значков действий (.row-act, .msgrs). */
.copy-float {
    --copy-bg: color-mix(in srgb, var(--nav-panel) 90%, transparent);
    position: fixed; z-index: 100000; display: inline-flex;
    width: 22px; height: 22px; align-items: center; justify-content: center;
    border-radius: 6px; background: var(--copy-bg);
    color: var(--nav-blue-deep); font-size: 13px; line-height: 1; cursor: pointer;
    opacity: 0; visibility: hidden;
    transition: opacity .2s ease, visibility 0s linear .2s, background .15s ease;
}
.copy-float.is-on { opacity: 1; visibility: visible; transition: opacity .2s ease, visibility 0s, background .15s ease; }
.copy-float:hover { background: color-mix(in srgb, currentColor 13%, var(--copy-bg)); }
/* значок прежнего элемента, пока гаснет (курсор ушёл на соседний): уже не нажимается */
.copy-float--out { pointer-events: none; }
.copy-float.is-copied { color: var(--green, #1a8f4c); }
.copy-float i { margin: 0; }
@media print { .copy-float { display: none !important; } }

.c-purple,
.c-purple * {
    color: var(--status-purple) !important;
}

/* Коричневый — перемещения / wait-state (токен st-wait) */
.c-brown,
.c-brown * {
    color: var(--acc2-state-wait, #8a5a2b) !important;
}

/* Align / size — без styles.css (TODO-080) */
.t-right {
    text-align: right !important;
}

.t-left {
    text-align: left !important;
}

.text-center,
.t-center {
    text-align: center !important;
}

/* Legacy float/weight/visibility utilities still used in tpl */
.right {
    float: right !important;
}

.b {
    font-weight: bold;
}

.lt,
.lt * {
    text-decoration: line-through;
}

/* Hide until dialog/JS (invoices list msgs_*, payLink textarea, act-price, …).
   Was only in styles.css — without it content leaks into the page. */
.hidden {
    display: none !important;
}

input[type=checkbox] {
    appearance: none;
    -webkit-appearance: none;
    cursor: pointer;
    width: 20px;
    height: 20px;
    margin: 0;
    padding: 0;
    box-shadow: none;
    vertical-align: middle;
    display: inline-grid;
    place-content: center;
    border: 1.5px solid var(--nav-line, #c5cdd8);
    border-radius: 6px;
    background: var(--input-bg, #fff);
}
input[type=checkbox]:hover {
    border-color: var(--nav-blue, #005fbd);
}
input[type=checkbox]:checked,
input[type=checkbox]:checked:focus,
input[type=checkbox]:checked:focus-visible {
    background: var(--nav-blue, #005fbd);
    border-color: var(--nav-blue, #005fbd);
}
input[type=checkbox]:checked::after,
input[type=checkbox]:checked:focus::after,
input[type=checkbox]:checked:focus-visible::after {
    content: '';
    width: 6px;
    height: 10px;
    border: solid #fff;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg) translate(-1px, -1px);
}
input[type=checkbox]:indeterminate {
    background: var(--nav-blue, #005fbd);
    border-color: var(--nav-blue, #005fbd);
}
input[type=checkbox]:indeterminate::after {
    content: '';
    width: 9px;
    height: 0;
    border-top: 2px solid #fff;
}
input[type=checkbox]:focus-visible {
    outline: 2px solid var(--nav-blue, #005fbd);
    outline-offset: 2px;
}
input[type=checkbox]:checked:focus-visible {
    outline-color: var(--nav-orange, #005fbd);
}

/* Ширины полей — шкала *Text (из старого styles.css), не сам .field-input.
   Без *Text / date — 150px. Имя должно содержать "Text": селектор :not([class*="Text"]).
   На всю ширину родителя — fullText (вместо локальных width:100% !important). */
input.field-input:not([class*="Text"]):not(.date):not(.datepicker),
select.field-select:not([class*="Text"]),
.field-input:not(textarea):not([class*="Text"]):not(.date):not(.datepicker),
.field-select:not([class*="Text"]) {
    width: 150px;
}

input.shortText,
.field-input.shortText,
.field-select.shortText {
    width: 100px;
}

input.midText,
.field-input.midText,
.field-select.midText {
    width: 200px;
}

.field-input.field-num {
    text-align: right;
}

input.longText, 
select.longText,
textarea.longText,
.field-input.longText,
.field-select.longText {
    width: 250px;
}

input.sLongText,
select.sLongText,
textarea.sLongText,
.field-input.sLongText,
.field-select.sLongText {
    width: 400px;
}

input.xLongText,
select.xLongText,
textarea.xLongText,
.field-input.xLongText,
.field-select.xLongText {
    width: 600px;
}

input.xlText,
select.xlText,
textarea.xlText,
.field-input.xlText,
.field-select.xlText {
    width: 350px;
}

input.fullText,
select.fullText,
textarea.fullText,
.field-input.fullText,
.field-select.fullText {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

/* Default textarea size (из styles.css) — без этого Description и др. сжимаются */
textarea {
    width: 350px;
    height: 100px;
    box-sizing: border-box;
}

textarea.bigArea {
    width: 400px;
    height: 400px;
}

input.date {
    width: 70px;
    text-align: center;
}

/* Попапы date / dateRange / mSelect / select — один хром, эталон: календарь даты.
   Порталы в body, поэтому правило глобальное (не внутри .acc2). */
.flatpickr-calendar:not(.inline),
.ui-shim-fp-month-list,
.ms-dropdown.ms-dropdown,
:is(select.field-select, .f-field select:not([data-mselect]))::picker(select) {
    border: 1px solid var(--nav-line, #d9dde2) !important;
    border-radius: var(--r-panel, 9px) !important;
    box-shadow: var(--shadow-dropdown) !important;
    background: var(--nav-panel, #fff);
}

/* Появление — как flatpickr fpFadeInDown. translate, не transform: у списка месяца уже translateX(-50%). */
@keyframes acc2-dropdown-in {
    from { opacity: 0; translate: 0 -20px; }
    to { opacity: 1; translate: 0 0; }
}
.flatpickr-calendar.animate.open,
.ui-shim-fp-month-list.is-open,
.ms-dropdown.ms-dropdown--visible,
:is(select.field-select, .f-field select:not([data-mselect])):open::picker(select) {
    animation: acc2-dropdown-in 300ms cubic-bezier(.23, 1, .32, 1);
}
@starting-style {
    :is(select.field-select, .f-field select:not([data-mselect])):open::picker(select) {
        opacity: 0;
        translate: 0 -20px;
    }
}

/* Typography utilities — полный набор из styles.css (не по одному: t-small/t-s11/…).
   t-l20 не переносим: глобальный line-height:1.4 !important его всё равно гасит. */
.t-small { font-size: 10px !important; }
.t-mono { font-family: monospace !important; }
.t-s11 { font-size: 11px !important; }
.t-s12 { font-size: 12px !important; }
.t-s14,
.t-middle { font-size: 14px !important; }
.t-big,
.t-s16 { font-size: 16px !important; line-height: 20px !important; }
.t-s18,
.t-s18 select { font-size: 18px !important; }
.t-s20 { font-size: 20px !important; }
.t-top { vertical-align: top; }
.t-bottom { vertical-align: bottom; }

.abs {
    position: absolute;
}

/* Glightbox */
.glightbox-wrap {
    position: relative;
    display: inline-block;
}

/* Число фото — в нижнем правом углу миниатюры, у самого края */
.img-count-badge {
    position: absolute;
    bottom: 1px;
    right: 1px;
    background: var(--color-overlay-dark);
    color: var(--color-white);
    font-size: 11px;
    width: 15px;
    height: 15px;
    border-radius: var(--radius-round);
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

/* Inline editable (jStyles) — was styles-only blocker */
th.editable {
    padding-right: 10px !important;
    background: var(--ui-bg-blue-edit) url(../../images/edit.png) no-repeat right;
}

.editable {
    position: relative;
}

/* В строке под заголовком место под карандаш не держится: он появляется при наведении справа, поверх точки-разделителя */
.tb-meta .editable {
    display: inline-block;
    vertical-align: baseline;
}
.tb-meta .editable .editable-icon {
    right: -22px;
    top: 50%;
    transform: translateY(-50%);
    background: var(--color-white);
}

.editable .editable-icon {
    cursor: pointer;
    position: absolute;
    right: 0;
    top: 0;
    display: none;
    z-index: 100;
    width: 22px;
    height: 22px;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    opacity: .5;
    transition: background .15s ease, opacity .15s ease;
}

.editable .editable-icon:hover {
    opacity: 1;
    background: rgba(225, 112, 9, .13);
}

.editableField {
    position: absolute;
    z-index: 300;
    padding: 3px;
    border: var(--border-none);
    top: calc(25%);
    left: 2px;
    opacity: 0;
    transition: opacity .16s ease;
}
.editableField.editableField--on {
    opacity: 1;
}
/* Текстовое поле правки на месте (ячейка таблицы или блок карточки): поверх текста, шрифт и строки — как у текста,
   размер и место задаёт editableStartInline() — текст при правке не сдвигается */
.acc2 .editableField--over :is(textarea, input).field-input,
.editableField--over :is(textarea, input) {
    box-sizing: border-box;
    max-width: none;
    min-height: 0;
    font: inherit;
    letter-spacing: inherit;
}
.acc2 .editableField--over textarea.field-input,
.editableField--over textarea {
    line-height: inherit;
    resize: vertical;
}

.inEdit.editable:hover .editable-icon {
    display: none;
}

.editable:hover .editable-icon {
    display: inline-flex;
}

@keyframes editable-access-flash {
    0%, 100% { box-shadow: var(--shadow-editable-access-normal); }
    50% { box-shadow: var(--shadow-editable-access-denied); }
}

.editable.editable-access-denied {
    animation: editable-access-flash 0.25s ease-in-out 2;
}

body.acc2-scroll-lock {
    overflow: hidden;
    overscroll-behavior: none;
}

/* Loading overlays / dialog spinner / success checkmark */
.dialog-loading-overlay,
.loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.dialog-loading-overlay {
    background: var(--color-overlay-light);
    z-index: 9999;
}

.dialog-global-loading {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--dialog-backdrop);
    z-index: 9999;
    animation: dialog-global-loading-fade .16s ease-out;
}

.dialog-global-loading.is-ready {
    animation: none;
}

.dialog-global-loading .dialog-loading-spinner {
    opacity: 1;
    transition: opacity .2s ease-out;
}

.dialog-global-loading.is-ready .dialog-loading-spinner {
    opacity: 0;
}

.dialog-global-loading.is-closing {
    pointer-events: none;
    animation: dialog-global-loading-fade-out .15s ease-in forwards;
}

body.dialog-global-loading-active {
    overflow-y: hidden;
}

@keyframes dialog-global-loading-fade {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes dialog-global-loading-fade-out {
    from { opacity: 1; }
    to { opacity: 0; }
}

.dialog-loading-spinner {
    width: 62px;
    height: 62px;
    border: var(--border-spinner-lg);
    transition: var(--transition-spinner);
}

.dialog-loading-spinner,
.loading-spinner {
    border-top-color: var(--ui-blue);
    border-radius: var(--radius-round);
    animation: dialog-spinner-rotate 0.8s linear infinite;
}

.dialog-loading-spinner.is-success {
    border: var(--border-spinner-success);
    border-top-color: var(--status-green);
    animation: none;
    position: relative;
    opacity: 0.8;
}

.dialog-loading-spinner.is-success::after {
    content: '';
    position: absolute;
    left: 19px;
    top: 11px;
    width: 14px;
    height: 26px;
    border-right: var(--border-spinner-success);
    border-bottom: var(--border-spinner-success);
    transform: rotate(40deg);
}

@keyframes dialog-spinner-rotate {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.loading-overlay {
    background: var(--color-overlay-light-soft);
    z-index: 100;
    border-radius: inherit;
    min-height: 60px;
}

.loading-overlay--float {
    position: fixed;
    z-index: 9998;
    margin: 0;
    box-sizing: border-box;
}

.loading-spinner {
    width: 38px;
    height: 38px;
    border: var(--border-spinner);
    border-top-color: var(--ui-blue);
}

.loading-spinner--lg {
    width: 62px;
    height: 62px;
    border: var(--border-spinner-lg);
    border-top-color: var(--ui-blue);
}

i.fa-spinner {
    animation: dialog-spinner-rotate 2s linear infinite;
}
.checkList label {
    font-size: 12px;
}

/* --- always-on form indicators (Wave C/D) ---
   Legacy input.error / .changed-data — здесь.
   .field-input.error + focus ring — в kit-shell. */
input.error,
select.error,
textarea.error,
input[type=checkbox].error,
input[type=radio].error,
table.error {
    border: 1px solid var(--nav-red);
}

.element.changed-data input,
.element.changed-data select,
.element.changed-data textarea,
.element.changed-data input[type=checkbox],
.element.changed-data input[type=radio],
.element.changed-data table,
.element.changed-data .ms-field {
    border-color: var(--nav-orange) !important;
    background-color: var(--nav-orange-pale);
}

/* Save flash (stdEditTpl UPDATED) */
.ui-state-success {
    margin-bottom: 10px;
    padding: 10px;
    background: #e8f5e9;
    border: 1px solid #a5d6a7;
    color: #2e7d32;
    border-radius: var(--r-panel, 6px);
}

/* Toggle switch (delivery dialog и др.) — был только в styles.css */
.ui-switch {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    font-weight: normal;
    font-size: 12px;
    user-select: none;
    margin: 0;
}
.ui-switch input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
    pointer-events: none;
}
.ui-switch-track {
    position: relative;
    flex-shrink: 0;
    width: 36px;
    height: 20px;
    border-radius: 10px;
    background: var(--nav-muted, #b0b0b0);
    transition: background .2s ease;
}
.ui-switch-track::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--color-white, #fff);
    box-shadow: 0 1px 3px rgba(0, 0, 0, .25);
    transition: transform .2s ease;
}
.ui-switch input:checked + .ui-switch-track {
    background: var(--nav-orange);
}
.ui-switch input:checked + .ui-switch-track::after {
    transform: translateX(16px);
}
.ui-switch input:focus-visible + .ui-switch-track {
    box-shadow: 0 0 0 2px var(--nav-orange-soft, #ffe0b2);
}
.ui-switch-label {
    line-height: 1.35;
}
.ui-switch-amt {
    margin-left: auto;
    white-space: nowrap;
    color: var(--nav-muted);
    font-size: 12px;
}
.ui-switch input:checked ~ .ui-switch-amt {
    color: var(--color-black, #000);
    font-weight: bold;
}

