/* ==========================================================================
   Papir CRM — Shared UI
   Підключати у всіх нових модулях:
   <link rel="stylesheet" href="/modules/shared/ui.css">
   ========================================================================== */

/* ── Токени ────────────────────────────────────────────────────────────────── */
:root {
    --bg:           #f4f7fa;
    --bg-card:      #ffffff;
    --bg-header:    #f8fafc;
    --bg-hover:     #f0f5fa;

    --border:       #e8edf3;
    --border-input: #d0d9e3;

    --text:         #222222;
    --text-muted:   #666666;
    --text-faint:   #999999;

    --blue:         #2563c4;
    --blue-dark:    #1a4fa0;
    --blue-light:   #4a90d9;
    --blue-bg:      #e8f0fa;

    --green:        #1a7f3c;
    --green-bg:     #edfdf3;

    --red:          #c0392b;
    --red-bg:       #fff0f0;
    --red-border:   #e8d0d0;

    --orange:       #b26a00;
    --orange-bg:    #fff4e5;

    --radius-sm:    5px;
    --radius:       8px;
    --radius-lg:    10px;

    --shadow-card:  0 1px 4px rgba(0,0,0,.07);
    --shadow-modal: 0 8px 32px rgba(0,0,0,.18);

    --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* ── Reset ─────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
body {
    margin: 0;
    font-family: var(--font);
    font-size: 13px;
    color: var(--text);
    background: var(--bg);
    line-height: 1.5;
}
a { color: var(--blue-light); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Макет сторінки ────────────────────────────────────────────────────────── */
.page-wrap       { max-width: 1200px; margin: 0 auto; padding: 24px 16px; }
.page-wrap-sm    { max-width: 960px; margin: 0 auto; padding: 24px 16px; }
.page-wrap-lg    { max-width: 1600px; margin: 0 auto; padding: 24px 20px; }

/* ── Footer ─────────────────────────────────────────────────────────────────── */
.app-footer {
    padding: 3px 20px;
    font-size: 10px;
    color: #d1d5db;
    text-align: center;
    border-top: 1px solid #f3f4f6;
    background: #fff;
    flex-shrink: 0;
}
body.has-shell:not(.ws-body) {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}
body.has-shell:not(.ws-body) .app-footer { margin-top: auto; }
body.ws-body {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

.page-head {
    display: flex; align-items: center;
    justify-content: space-between;
    margin-bottom: 20px; gap: 12px; flex-wrap: wrap;
}
.page-head h1 { margin: 0; font-size: 20px; font-weight: 600; }
.page-title-count { font-size: 14px; font-weight: 400; color: var(--text-muted); }

.breadcrumb { font-size: 12px; color: var(--text-faint); margin-bottom: 8px; }
.breadcrumb a { color: var(--blue-light); }
.breadcrumb a:hover { text-decoration: underline; }
.breadcrumb span { color: var(--text-muted); }

/* ── Toolbar (пошук + фільтри) ─────────────────────────────────────────────── */
.toolbar {
    display: flex; align-items: center;
    gap: 10px; margin-bottom: 16px; flex-wrap: wrap;
}

/* ── Кнопки ────────────────────────────────────────────────────────────────── */
.btn {
    display: inline-flex; align-items: center; justify-content: center;
    padding: 7px 14px; border: 1px solid var(--border-input);
    border-radius: var(--radius-sm); background: var(--bg-card);
    color: var(--text); font-size: 13px; font-family: var(--font);
    cursor: pointer; text-decoration: none; white-space: nowrap;
    transition: background .12s, border-color .12s, color .12s;
    line-height: 1.4;
}
.btn:hover { background: var(--bg-hover); border-color: var(--blue-light); text-decoration: none; }
.btn:disabled, .btn[disabled] { opacity: .45; cursor: default; pointer-events: none; }

.btn-primary {
    background: var(--blue); border-color: var(--blue); color: #fff;
}
.btn-primary:hover { background: var(--blue-dark); border-color: var(--blue-dark); color: #fff; }

.btn-danger {
    background: none; border-color: var(--red-border); color: var(--red);
}
.btn-danger:hover { background: var(--red-bg); }

.btn-ghost {
    background: none; border-color: transparent; color: var(--text-muted);
}
.btn-ghost:hover { background: var(--bg-hover); border-color: var(--border-input); color: var(--text); }

.btn-sm  { padding: 4px 10px; font-size: 12px; }
.btn-xs  { padding: 3px 7px;  font-size: 11px; }

.btn-row { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }

/* ── Форми ─────────────────────────────────────────────────────────────────── */
.form-row { margin-bottom: 14px; }
.form-row label {
    display: block; font-size: 12px; font-weight: 600;
    color: var(--text-muted); margin-bottom: 5px;
}
.form-row input[type=text],
.form-row input[type=number],
.form-row input[type=email],
.form-row select,
.form-row textarea,
input.field,
select.field,
textarea.field {
    width: 100%; padding: 7px 10px;
    border: 1px solid var(--border-input);
    border-radius: var(--radius-sm);
    font-size: 13px; font-family: var(--font);
    background: var(--bg-card); color: var(--text);
    outline: none; transition: border-color .15s;
}
.form-row input:focus,
.form-row select:focus,
.form-row textarea:focus,
input.field:focus,
select.field:focus,
textarea.field:focus { border-color: var(--blue-light); }
.form-row textarea, textarea.field { resize: vertical; min-height: 70px; }

.search-input {
    padding: 7px 10px; border: 1px solid var(--border-input);
    border-radius: var(--radius-sm); font-size: 13px;
    font-family: var(--font); outline: none; background: var(--bg-card);
    transition: border-color .15s; width: 240px;
}
.search-input:focus { border-color: var(--blue-light); }

/* Unsaved highlight */
.input-dirty {
    background: #fffbe6 !important;
    border-color: #f0b429 !important;
    box-shadow: 0 0 0 2px rgba(240,180,41,.18);
}

/* ── Карточки ──────────────────────────────────────────────────────────────── */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 20px;
    box-shadow: var(--shadow-card);
}

/* ── Таблиця ───────────────────────────────────────────────────────────────── */
.crm-table {
    width: 100%; border-collapse: collapse;
    background: var(--bg-card);
    border-radius: var(--radius); overflow: hidden;
    box-shadow: var(--shadow-card);
}
.crm-table th {
    text-align: left; padding: 9px 14px;
    font-size: 11px; font-weight: 600; letter-spacing: .03em;
    text-transform: uppercase; color: var(--text-muted);
    background: var(--bg-header); border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
.crm-table td {
    padding: 9px 14px; font-size: 13px;
    border-bottom: 1px solid #f0f4f8;
    vertical-align: middle;
}
.crm-table tr:last-child td { border-bottom: none; }
.crm-table tbody tr:hover td { background: var(--bg-hover); }
.crm-table td.num { font-variant-numeric: tabular-nums; }
/* No word-wrap in th by default; allow in td */
.crm-table td.wrap { word-break: break-word; }
.crm-table td.nowrap { white-space: nowrap; }
.crm-table td.trunc {
    max-width: 200px; overflow: hidden;
    text-overflow: ellipsis; white-space: nowrap;
}

/* Клікабельний рядок */
.crm-table tbody tr.clickable { cursor: pointer; }

/* ── Бейджики статусу ──────────────────────────────────────────────────────── */
.badge {
    display: inline-block; padding: 2px 8px;
    border-radius: 999px; font-size: 11px;
    font-weight: 600; white-space: nowrap;
}
.badge-green  { background: var(--green-bg);  color: var(--green); }
.badge-red    { background: var(--red-bg);    color: var(--red); }
.badge-blue   { background: var(--blue-bg);   color: var(--blue); }
.badge-orange { background: var(--orange-bg); color: var(--orange); }
.badge-gray   { background: #f0f4f8;          color: var(--text-muted); }
.badge-indigo { background: #ede9fe;          color: #5b21b6; }
.badge-purple { background: #fae8ff;          color: #7e22ce; }
.badge-teal   { background: #ccfbf1;          color: #0f766e; }
.badge-violet { background: #ede9fe;          color: #6d28d9; }
.badge-rose   { background: #ffe4e6;          color: #be123c; }

/* ── Toggle group ──────────────────────────────────────────────────────────── */
.toggle-group { display: inline-flex; border-radius: var(--radius-sm); overflow: hidden; }
.toggle-group label { display: block; }
.toggle-group input[type=radio] { display: none; }
.toggle-group label span {
    display: block; padding: 6px 11px; font-size: 12px;
    cursor: pointer; background: var(--bg-card); color: var(--text-muted);
    white-space: nowrap; border: 1px solid var(--border-input); border-right: none;
    transition: background .12s, color .12s;
}
.toggle-group label:first-child span { border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
.toggle-group label:last-child  span { border-right: 1px solid var(--border-input); border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.toggle-group input[type=radio]:checked + span { background: var(--blue); color: #fff; border-color: var(--blue); }

/* ── Пагінація ─────────────────────────────────────────────────────────────── */
.pagination { display: flex; gap: 4px; align-items: center; margin-top: 16px; flex-wrap: wrap; }
.pagination a,
.pagination span {
    display: inline-block; padding: 5px 11px;
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    text-decoration: none; color: var(--text);
    font-size: 13px; background: var(--bg-card);
    transition: background .12s, border-color .12s;
}
.pagination a:hover { background: var(--bg-hover); border-color: var(--blue-light); text-decoration: none; }
.pagination .cur  { background: var(--blue); border-color: var(--blue); color: #fff; }
.pagination .dots { border: none; background: none; color: var(--text-faint); padding: 5px 4px; }

/* ── Модальне вікно ────────────────────────────────────────────────────────── */
.modal-overlay {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,.35); z-index: 2000;
    align-items: center; justify-content: center;
}
.modal-overlay.open { display: flex; }

.modal-box {
    background: var(--bg-card); border-radius: var(--radius-lg);
    box-shadow: var(--shadow-modal);
    width: 440px; max-width: 95vw;
    display: flex; flex-direction: column;
    max-height: 90vh; overflow: hidden;
}
.modal-box-sm { width: 360px; }
.modal-box-lg { width: 640px; }

.modal-head {
    padding: 16px 20px 12px;
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
    flex-shrink: 0;
}
.modal-head h3, .modal-head h4 { margin: 0; font-size: 16px; font-weight: 600; }
.modal-close {
    background: none; border: none; cursor: pointer;
    color: var(--text-faint); font-size: 18px; line-height: 1; padding: 0;
    transition: color .15s;
}
.modal-close:hover { color: var(--text); }

.modal-body {
    padding: 20px; overflow-y: auto; flex: 1;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    touch-action: pan-y;
}
.modal-footer {
    padding: 12px 20px;
    border-top: 1px solid var(--border);
    display: flex; justify-content: flex-end;
    gap: 8px; flex-shrink: 0;
}
.modal-error { color: var(--red); font-size: 12px; margin-top: 8px; }

/* ── Toast ─────────────────────────────────────────────────────────────────── */
.toast {
    position: fixed; bottom: 24px; left: 50%;
    transform: translateX(-50%) translateY(10px);
    background: #222; color: #fff;
    padding: 8px 18px; border-radius: var(--radius-sm);
    font-size: 13px; opacity: 0;
    transition: opacity .2s, transform .2s;
    z-index: 3000; pointer-events: none;
    white-space: nowrap;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── Утиліти ───────────────────────────────────────────────────────────────── */
.text-muted   { color: var(--text-muted); }
.text-faint   { color: var(--text-faint); }
.text-green   { color: var(--green); }
.text-red     { color: var(--red); }
.text-blue    { color: var(--blue); }
.text-orange  { color: var(--orange); }
.fw-600       { font-weight: 600; }
.fs-12        { font-size: 12px; }
.fs-11        { font-size: 11px; }
.nowrap       { white-space: nowrap; }
.text-right   { text-align: right; }
.text-center  { text-align: center; }

/* Sticky sidebar layout */
.layout-2col { display: grid; grid-template-columns: 320px 1fr; gap: 20px; align-items: start; }
.sticky-top  { position: sticky; top: 16px; }
@media (max-width: 900px) {
    .layout-2col { grid-template-columns: 1fr; }
    .sticky-top  { position: static; }
}

/* Action dropdown */
.act-wrap { position: relative; display: inline-block; }
.act-dot  {
    background: none; border: 1px solid var(--border-input);
    border-radius: var(--radius-sm); padding: 2px 7px;
    cursor: pointer; font-size: 15px; color: var(--text-muted); line-height: 1.2;
}
.act-dot:hover { background: var(--bg-hover); border-color: var(--blue-light); }
.act-dd {
    display: none; position: absolute; right: 0; top: 100%; z-index: 300;
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: var(--radius-sm); box-shadow: 0 4px 14px rgba(0,0,0,.13);
    min-width: 140px; padding: 4px 0;
}
.act-dd.open { display: block; }
.act-dd button {
    display: block; width: 100%; padding: 6px 12px; font-size: 12px;
    text-align: left; background: none; border: none;
    cursor: pointer; white-space: nowrap; color: var(--text); font-family: var(--font);
}
.act-dd button:hover   { background: var(--bg-hover); }
.act-dd button.danger  { color: var(--red); }
.act-dd .dd-sep { margin: 3px 0; border: none; border-top: 1px solid var(--border); }

/* Remove number spinners in table inputs */
td input[type=number] { -moz-appearance: textfield; }
td input[type=number]::-webkit-outer-spin-button,
td input[type=number]::-webkit-inner-spin-button { display: none; }

/* ── Category Tree ──────────────────────────────────────────────────────────
   Використовується у: модальному вікні вибору категорії, /category-mapping,
   та будь-якому іншому місці де потрібне дерево категорій.
   JS: /modules/shared/category-tree.js
   ─────────────────────────────────────────────────────────────────────────── */
.cat-tree { display: flex; flex-direction: column; overflow: hidden; }
.cat-tree-search-wrap { flex-shrink: 0; padding: 10px 12px 8px; }
.cat-tree-search {
    width: 100%; box-sizing: border-box;
    padding: 7px 10px; border: 1px solid var(--border-input);
    border-radius: var(--radius); font-size: 13px; outline: none;
    font-family: var(--font);
}
.cat-tree-search:focus { border-color: var(--blue-light); }
.cat-tree-nodes { overflow-y: auto; flex: 1; min-height: 0; padding: 4px 0; overscroll-behavior: contain; }

/* Node row */
.cat-node-row {
    display: flex; align-items: center; gap: 4px;
    padding: 5px 12px 5px 0; cursor: pointer; border-radius: 0;
    user-select: none;
}
.cat-node-row:hover { background: var(--bg-hover); }
.cat-node-row.selected { background: var(--blue-bg); color: var(--blue); font-weight: 600; }
.cat-node-row.inactive .cat-node-name { opacity: .45; }
.cat-node-row.inactive .cat-node-toggle { opacity: .45; }

/* Toggle arrow */
.cat-node-toggle {
    flex-shrink: 0; width: 18px; text-align: center;
    font-size: 9px; color: #8ab4f8;
    transition: transform .18s ease; line-height: 1;
    cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
}
.cat-node-toggle.open { transform: rotate(90deg); }
.cat-node-toggle.leaf { opacity: 0; pointer-events: none; }

/* Name */
.cat-node-name { font-size: 13px; color: var(--text); }
.cat-node-row.selected .cat-node-name { color: var(--blue); font-weight: 600; }
.cat-node-row:hover .cat-node-name { color: var(--blue); }

/* Children container — indented */
.cat-node-children { display: none; }
.cat-node-children.open { display: block; }
/* Each depth level adds left indent via inline style set in JS */

/* "Nothing found" */
.cat-tree-empty { padding: 20px 16px; color: var(--text-faint); font-size: 13px; text-align: center; }

/* ── Chip search input ────────────────────────────────────────────────────── */
/*
 * Стандартный поиск CRM: поле-контейнер с чипами.
 * Использование:
 *   <div class="chip-input" id="searchChipBox">
 *       <input type="text" id="searchChipTyper" placeholder="…">
 *   </div>
 *   <input type="hidden" name="search" id="search" value="…">
 * JS: ChipSearch.init('searchChipBox', 'searchChipTyper', 'search', form)
 */
.chip-input {
    display: flex; flex-wrap: wrap; gap: 4px;
    padding: 3px 64px 3px 8px; min-height: 36px;
    border: 1px solid var(--border-input); border-radius: var(--radius);
    background: var(--bg-card); cursor: text; align-items: center;
    transition: border-color .15s; position: relative;
}
.chip-input:focus-within { border-color: var(--blue-light); }
.chip {
    display: inline-flex; align-items: center; gap: 3px;
    background: var(--blue-bg); color: var(--blue);
    border-radius: 4px; padding: 2px 6px 2px 8px;
    font-size: 13px; white-space: nowrap; line-height: 1.5;
}
.chip-x {
    cursor: pointer; font-size: 15px; line-height: 1;
    color: var(--blue); opacity: .55; margin-left: 1px;
}
.chip-x:hover { opacity: 1; }
.chip-typer {
    border: none; outline: none; background: transparent;
    font-size: 14px; min-width: 80px; flex: 1;
    padding: 2px 0; font-family: var(--font); color: var(--text);
}
/* Actions inside chip-input (clear × and search 🔍) */
.chip-actions {
    position: absolute; right: 0; top: 0; bottom: 0;
    display: flex; align-items: center;
}
.chip-act-btn {
    display: flex; align-items: center; justify-content: center;
    width: 30px; height: 100%;
    border: none; background: transparent;
    color: var(--text-faint); cursor: pointer;
    font-size: 13px; transition: color .12s, background .12s;
    flex-shrink: 0;
}
.chip-act-btn:hover { color: var(--text); background: var(--bg-hover); }
.chip-act-clear:hover { color: var(--red); }
.chip-act-submit { border-radius: 0 var(--radius) var(--radius) 0; }
.chip-act-submit:hover { color: var(--blue); }
.chip-act-clear.hidden { visibility: hidden; pointer-events: none; }

/* ── App Shell ─────────────────────────────────────────────────────────────── */
:root {
    --shell-h:      0px;
    --sticky-top:   16px;
}
body.has-shell {
    --shell-h:      98px;
    --sticky-top:   114px;  /* 98px shell + 16px gap */
    padding-top:    98px;
    margin:         0;
}

/* Header */
.app-header {
    background:     #1a1f2e;
    height:         58px;
    display:        flex;
    align-items:    center;
    padding:        0 12px 0 16px;
    position:       fixed;
    top: 0; left: 0; right: 0;
    z-index:        1000;
    user-select:    none;
    gap:            4px;
}

/* Logo */
.app-logo {
    display: flex; align-items: center; gap: 9px;
    text-decoration: none; margin-right: 8px; flex-shrink: 0;
}
.app-logo:hover { text-decoration: none; }
.app-logo-mark {
    width: 34px; height: 34px;
    background: linear-gradient(140deg, #5b8af8 0%, #7c3aed 100%);
    border-radius: 9px;
    display: flex; align-items: center; justify-content: center;
    font-weight: 900; font-size: 17px; color: #fff;
    box-shadow: 0 2px 8px rgba(92,138,248,.35);
    flex-shrink: 0;
}
.app-logo-text { display: flex; flex-direction: column; gap: 1px; }
.app-logo-name { font-size: 13px; font-weight: 700; color: rgba(255,255,255,.9); letter-spacing: .3px; line-height: 1; }
.app-logo-sub  { font-size: 9px; font-weight: 500; color: rgba(255,255,255,.3); letter-spacing: 2px; text-transform: uppercase; line-height: 1; }

/* Header separator */
.app-hdr-sep {
    width: 1px; height: 30px;
    background: rgba(255,255,255,.08);
    margin: 0 6px; flex-shrink: 0;
}

/* Module buttons */
.app-modules { display: flex; align-items: center; flex: 1; gap: 1px; }
.app-mod-btn {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 4px; padding: 0 13px; height: 50px;
    border-radius: 9px; cursor: pointer; border: none;
    background: transparent; color: rgba(255,255,255,.45);
    font-family: var(--font); font-size: 10px; font-weight: 500;
    transition: color .15s, background .15s;
    min-width: 70px; text-decoration: none; position: relative;
    letter-spacing: .2px; white-space: nowrap;
}
.app-mod-btn:hover { background: rgba(255,255,255,.06); color: rgba(255,255,255,.8); text-decoration: none; }
.app-mod-btn.active { color: #fff; background: rgba(255,255,255,.07); }
.app-mod-btn.active::after {
    content: ''; position: absolute; bottom: 5px; left: 50%; transform: translateX(-50%);
    width: 22px; height: 2.5px; border-radius: 2px;
    background: var(--mod-color, #4f7ef8); opacity: .9;
}
.app-mod-btn svg { width: 21px; height: 21px; flex-shrink: 0; }

/* Right side */
.app-hdr-right { display: flex; align-items: center; gap: 2px; flex-shrink: 0; }
.app-hdr-btn {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 3px; width: 50px; height: 50px; border-radius: 9px;
    cursor: pointer; border: none; background: transparent;
    color: rgba(255,255,255,.45); font-family: var(--font);
    font-size: 9.5px; font-weight: 500; letter-spacing: .2px;
    transition: color .15s, background .15s; position: relative; flex-shrink: 0;
}
.app-hdr-btn:hover { background: rgba(255,255,255,.06); color: rgba(255,255,255,.8); }
.app-hdr-btn svg { width: 20px; height: 20px; }
.app-hdr-badge {
    position: absolute; top: 6px; right: 7px;
    min-width: 15px; height: 15px;
    background: #ef4444; border-radius: 8px;
    border: 1.5px solid #1a1f2e;
    font-size: 8.5px; font-weight: 700; color: #fff;
    display: flex; align-items: center; justify-content: center;
    padding: 0 3px; line-height: 1;
}
.app-lang-btn {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 2px; width: 46px; height: 50px;
    border-radius: 9px; cursor: pointer; border: none;
    background: transparent; font-family: var(--font);
    color: rgba(255,255,255,.45); transition: color .15s, background .15s;
}
.app-lang-btn:hover { background: rgba(255,255,255,.06); color: rgba(255,255,255,.8); }
.app-lang-code { font-size: 12px; font-weight: 700; letter-spacing: .5px; }
.app-lang-lbl  { font-size: 9px; font-weight: 500; opacity: .55; }
.app-user-btn {
    display: flex; align-items: center; gap: 8px;
    padding: 0 10px 0 8px; height: 50px;
    border-radius: 9px; cursor: pointer; border: none;
    background: transparent; color: rgba(255,255,255,.75);
    font-family: var(--font); transition: color .15s, background .15s;
}
.app-user-btn:hover { background: rgba(255,255,255,.06); color: #fff; text-decoration: none; }
.app-user-avatar {
    width: 30px; height: 30px; border-radius: 50%;
    background: linear-gradient(135deg, #5b8af8, #7c3aed);
    display: flex; align-items: center; justify-content: center;
    font-size: 11px; font-weight: 700; color: #fff; flex-shrink: 0;
}
.app-user-info { display: flex; flex-direction: column; align-items: flex-start; }
.app-user-name { font-size: 12px; font-weight: 600; line-height: 1.25; }
.app-user-role { font-size: 10px; opacity: .45; line-height: 1.25; }
.app-user-arr  { width: 13px; height: 13px; opacity: .35; margin-left: 1px; flex-shrink: 0; transition: transform .2s; }
.app-user-wrap.open .app-user-arr { transform: rotate(180deg); }

/* User dropdown */
.app-user-wrap { position: relative; }
.app-user-dropdown {
    position: absolute; top: calc(100% + 6px); right: 0;
    min-width: 200px; background: #1e2132;
    border: 1px solid rgba(255,255,255,.1); border-radius: 10px;
    box-shadow: 0 8px 32px rgba(0,0,0,.45); z-index: 2000;
    overflow: hidden; opacity: 0; transform: translateY(-6px);
    pointer-events: none; transition: opacity .15s, transform .15s;
}
.app-user-wrap.open .app-user-dropdown {
    opacity: 1; transform: translateY(0); pointer-events: auto;
}
.app-user-drop-head {
    padding: 12px 14px 10px;
    border-bottom: 1px solid rgba(255,255,255,.07);
}
.app-user-drop-name { font-size: 13px; font-weight: 700; color: #fff; line-height: 1.3; }
.app-user-drop-role { font-size: 11px; color: rgba(255,255,255,.38); margin-top: 1px; }
.app-user-drop-item {
    display: flex; align-items: center; gap: 10px;
    padding: 9px 14px; font-size: 13px; font-weight: 500;
    color: rgba(255,255,255,.7); text-decoration: none; cursor: pointer;
    transition: background .12s, color .12s; border: none; background: none;
    width: 100%; font-family: inherit; text-align: left;
}
.app-user-drop-item:hover { background: rgba(255,255,255,.07); color: #fff; text-decoration: none; }
.app-user-drop-item svg { width: 15px; height: 15px; opacity: .6; flex-shrink: 0; }
.app-user-drop-sep { height: 1px; background: rgba(255,255,255,.07); margin: 3px 0; }
.app-user-drop-item.danger { color: #f87171; }
.app-user-drop-item.danger:hover { background: rgba(248,113,113,.1); color: #fca5a5; }
.app-user-drop-item.app-user-drop-mobile,
.app-user-drop-sep.app-user-drop-sep-mobile { display: none; }

/* Subnav */
.app-subnav {
    background: #fff; border-bottom: 1px solid #e8eaed;
    height: 40px; display: flex; align-items: center;
    padding: 0 20px; position: fixed;
    top: 58px; left: 0; right: 0; z-index: 999; gap: 0;
}
.app-sub-lnk {
    padding: 0 14px; height: 40px;
    display: flex; align-items: center;
    font-size: 13px; color: #6b7280;
    text-decoration: none; white-space: nowrap;
    font-weight: 500; letter-spacing: .1px;
    border-bottom: 2.5px solid transparent;
    transition: color .15s;
}
.app-sub-lnk:hover { color: #1a1f2e; text-decoration: none; }
.app-sub-lnk.active { color: var(--subnav-color, #4f7ef8); border-bottom-color: var(--subnav-color, #4f7ef8); }

/* Adjust sticky panels when shell is present */
body.has-shell .sticky-panel { top: var(--sticky-top); max-height: calc(100vh - var(--sticky-top)); }

/* ── Lightbox (повноекранний перегляд зображення) ─────────────────────────── */
.crm-lightbox {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,.78); z-index: 9000;
    align-items: center; justify-content: center;
    cursor: zoom-out;
}
.crm-lightbox.open { display: flex; }
.crm-lightbox-img {
    max-width: 92vw; max-height: 92vh;
    border-radius: var(--radius-lg); object-fit: contain;
}

/* ── Filter bar ─────────────────────────────────────────────────────────────
 * Стандартний блок між тулбаром і таблицею.
 * Концепція сторінок з таблицями:
 *   1. Тулбар  (.xxx-toolbar)  — заголовок, кнопка додати, chip-search, select, bulk-actions
 *   2. Фільтри (.filter-bar)   — чекбокси, date-пікери, додаткові select-фільтри
 *   3. Таблиця (.crm-table)
 *
 * Структура:
 *   <div class="filter-bar">
 *     <div class="filter-bar-group">
 *       <span class="filter-bar-label">Магазин</span>
 *       <label class="filter-pill"><input type="checkbox"> Off</label>
 *       <label class="filter-pill active"><input type="checkbox" checked> Mff</label>
 *     </div>
 *     <div class="filter-bar-sep"></div>
 *     <div class="filter-bar-group">...</div>
 *   </div>
 * ─────────────────────────────────────────────────────────────────────────── */
.filter-bar {
    display: flex; align-items: center;
    gap: 16px; padding: 7px 12px;
    background: var(--bg-header);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin-bottom: 12px;
    flex-wrap: wrap; min-height: 36px;
}
/* Група споріднених фільтрів всередині .filter-bar */
.filter-bar-group {
    display: flex; align-items: center; gap: 6px;
}
/* Вертикальний роздільник між групами */
.filter-bar-sep {
    width: 1px; height: 18px;
    background: var(--border); flex-shrink: 0;
}
/* Мітка перед групою (напр. "Магазин:", "Статус:") */
.filter-bar-label {
    font-size: 11px; font-weight: 600; white-space: nowrap;
    color: var(--text-faint); text-transform: uppercase; letter-spacing: .04em;
}

/* ── Filter pill (чекбокс-фільтр всередині filter-bar) ──────────────────────
 * Використовується: filter-bar checkboxes, site filters і т.п.
 * Без рамок і фону — тільки чекбокс + текст.
 * ─────────────────────────────────────────────────────────────────────────── */
.filter-pill {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 2px 4px; font-size: 12px;
    cursor: pointer; user-select: none;
    color: var(--text-muted); transition: color .12s;
}
.filter-pill:hover { color: var(--text); }
.filter-pill.active { color: #1f6feb; font-weight: 600; }
.filter-pill input[type=checkbox],
.filter-pill input[type=radio] {
    width: 13px; height: 13px; margin: 0;
    cursor: pointer; accent-color: #1f6feb;
}

/* ── Filter bar settings gear ───────────────────────────────────────────────
 * Шестерня в правому куті .filter-bar — майбутнє налаштування складу фільтрів.
 * Завжди останній елемент у .filter-bar, відштовхується вправо через margin-left:auto.
 * При кліку відкриватиме дропдаун зі списком доступних груп фільтрів (toggle).
 *
 * Використання:
 *   <div class="filter-bar">
 *     ... групи фільтрів ...
 *     <button type="button" class="filter-bar-gear" title="Налаштувати фільтри">
 *       <svg>...</svg>
 *     </button>
 *   </div>
 * ─────────────────────────────────────────────────────────────────────────── */
.filter-bar-gear {
    margin-left: auto; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    width: 24px; height: 24px; padding: 0;
    border: none; background: transparent;
    color: var(--text-faint); cursor: pointer;
    border-radius: var(--radius-sm);
    transition: color .15s, background .15s;
}
.filter-bar-gear:hover {
    color: var(--text-muted); background: var(--bg-hover);
}
.filter-bar-gear svg { width: 14px; height: 14px; }

/* ══════════════════════════════════════════════════════════════════════════
   History Modal — HistoryModal.open(type, id)
   ══════════════════════════════════════════════════════════════════════════ */
.history-modal-box {
    width: 900px;
    max-width: 96vw;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
}
.history-modal-body {
    overflow-y: auto;
    flex: 1;
    padding: 0 0 4px;
}
.history-modal-footer {
    padding-top: 10px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: center;
}
.history-modal-loading,
.history-modal-empty,
.history-modal-error {
    padding: 32px;
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
}
.history-modal-error { color: var(--danger); }

/* Таблица истории */
.history-modal-table {
    font-size: 12.5px;
    table-layout: fixed;
    width: 100%;
}

/* Актор: имя + badge под ним */
.hist-td-actor { vertical-align: middle; line-height: 1.3; }

/* Колонка "Позиція" — обрезается с тултипом */
.hist-td-item  { overflow: hidden; }
.hist-cell-clip {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Колонки "Було/Стало" — перенос слов, не ломают таблицу */
.hist-td-val {
    overflow: hidden;
    word-break: break-word;
    vertical-align: middle;
}
.hist-val-long {
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
    cursor: help;
}

/* ── Visibility helpers ── */
.mobile-only { display: none !important; }
.desktop-only { display: inline !important; }

/* ── Global mobile (≤768px) ── */
@media (max-width: 768px) {
    .mobile-only { display: inline !important; }
    .desktop-only { display: none !important; }
    /* Prevent horizontal scroll but allow pull-to-refresh */
    html {
        overflow-x: clip;
        overflow-y: auto;
        height: 100%;
        -webkit-overflow-scrolling: touch;
    }

    body {
        overflow-x: clip;
        overflow-y: auto !important;
        overscroll-behavior-y: auto !important;
        -webkit-overflow-scrolling: touch;
        position: relative !important;
        min-height: 100%;
    }
    .app-header { padding: 0 6px; gap: 2px; height: 52px; }
    body { padding-top: 92px; --sticky-top: 108px; }
    .app-logo { margin-right: 4px; }
    .app-logo-mark { width: 30px; height: 30px; font-size: 15px; }
    .app-logo-text { display: none; }
    .app-hdr-sep { display: none; }
    .app-modules {
        overflow-x: auto; flex-wrap: nowrap;
        min-width: 0; /* allow flex:1 to shrink below intrinsic children width */
        scrollbar-width: none; -webkit-overflow-scrolling: touch;
    }
    .app-lang-btn { display: none; }
    .app-hdr-right .app-hdr-sep { display: none; }
    /* На мобільному ховаємо «Чат» і «Бэклог» з шапки — вони перекривають меню
       і палець за них чіпляється при скролі. Доступні через dropdown користувача. */
    #globalChatBtn, #blQuickBtn { display: none; }
    .app-user-drop-item.app-user-drop-mobile { display: flex; }
    .app-user-drop-sep.app-user-drop-sep-mobile { display: block; }
    /* Subnav — horizontal scroll instead of cut-off */
    .app-subnav {
        padding: 0 10px; overflow-x: auto; top: 52px;
        scrollbar-width: none; -webkit-overflow-scrolling: touch;
    }
    .app-subnav::-webkit-scrollbar { display: none; }
    .app-sub-lnk { padding: 0 10px; font-size: 12.5px; flex-shrink: 0; }
    .app-modules::-webkit-scrollbar { display: none; }
    .app-mod-btn { min-width: 44px; padding: 0 6px; height: 44px; font-size: 0; gap: 0; }
    .app-mod-btn svg { width: 20px; height: 20px; }
    .app-mod-btn.active::after { bottom: 3px; width: 16px; }
    .app-hdr-btn { width: 40px; height: 44px; font-size: 0; gap: 0; }
    .app-hdr-btn svg { width: 19px; height: 19px; }
    .app-lang-btn { width: 36px; height: 44px; }
    .app-user-btn { padding: 0 6px; height: 44px; }
    .app-user-info { display: none; }
    .app-user-arr { display: none; }
    /* Page wrappers: constrain width + clip overflow for mobile */
    .page-wrap, .page-wrap-sm, .page-wrap-lg {
        max-width: 100%; overflow-x: hidden;
        padding-left: 8px; padding-right: 8px;
    }
    .filter-bar { gap: 6px 10px; padding: 6px 8px; font-size: 12px; }
    .filter-bar-group { flex-wrap: wrap; gap: 4px 8px; }
    .filter-bar-sep { display: none; }
    .filter-bar-label { font-size: 10px; }
    .filter-pill { font-size: 12px; }
}
