/* Обратная связь интерфейса: уведомления, кнопки «занято», фокус, ссылки-действия.
   Подключается после crm.css, палитру не меняет. */

/* ---- Уведомления (uiToast) ---- */
.ui-toasts {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: .5rem;
    width: min(380px, calc(100vw - 2rem));
    pointer-events: none;
}
.ui-toast {
    pointer-events: auto;
    display: flex;
    align-items: flex-start;
    gap: .65rem;
    padding: .75rem .85rem .75rem 1rem;
    border-radius: 10px;
    background: var(--card);
    color: var(--text);
    border: 1px solid var(--border);
    border-left: 5px solid var(--accent);
    box-shadow: 0 10px 28px rgba(20, 30, 45, .16);
    font-size: .93rem;
    line-height: 1.35;
    animation: ui-toast-in .18s ease-out;
}
.ui-toast.success { border-left-color: var(--ok); }
.ui-toast.error { border-left-color: var(--danger); background: #fff7f7; }
.ui-toast.warning { border-left-color: #c58a00; background: #fffbf0; }
.ui-toast-text { flex: 1 1 auto; overflow-wrap: anywhere; }
.ui-toast-close {
    flex: 0 0 auto;
    border: none;
    background: transparent;
    color: var(--muted);
    font-size: 1.2rem;
    line-height: 1;
    padding: .1rem .3rem;
    margin: -.15rem -.2rem 0 0;
    border-radius: 6px;
    cursor: pointer;
}
.ui-toast-close:hover { color: var(--text); background: rgba(0, 0, 0, .06); }
.ui-toast.is-leaving { opacity: 0; transform: translateX(12px); transition: opacity .18s, transform .18s; }
@keyframes ui-toast-in {
    from { opacity: 0; transform: translateY(-6px); }
    to { opacity: 1; transform: none; }
}
/* JS переносит сообщения в уведомления; без JS остаётся старая полоса */
.ui-js .messages { display: none; }

/* ---- Кнопки: наведение, нажатие, «занято» ---- */
.btn, button.btn, a.btn {
    transition: filter .12s, box-shadow .12s, transform .06s;
}
.btn:hover, button.btn:hover, a.btn:hover { filter: brightness(1.08); }
.btn:active, button.btn:active, a.btn:active { transform: translateY(1px); filter: brightness(.95); }
.btn.ghost:hover { background: rgba(47, 111, 106, .07); }
.logout-form button:hover { background: rgba(255, 255, 255, .08); }

.is-busy {
    position: relative;
    pointer-events: none;
    opacity: .7;
    cursor: progress;
}
.is-busy::after {
    content: '';
    display: inline-block;
    width: .9em;
    height: .9em;
    margin-left: .5em;
    vertical-align: -.12em;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: ui-spin .7s linear infinite;
}
form.is-busy-form button[type="submit"]:not(.is-busy),
form.is-busy-form input[type="submit"] { opacity: .6; pointer-events: none; }
@keyframes ui-spin { to { transform: rotate(360deg); } }

/* ---- Видимый фокус с клавиатуры ---- */
:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}
.sidebar :focus-visible { outline-color: #9fd3cd; }
input:focus-visible, select:focus-visible, textarea:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

/* ---- Ссылки-действия в таблицах ---- */
.link-action {
    display: inline-flex;
    align-items: center;
    min-height: 32px;
    padding: 0 .25rem;
    color: var(--accent);
    text-decoration: none;
    border: none;
    background: none;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    border-radius: 6px;
}
.link-action:hover { text-decoration: underline; }
.link-action.danger { color: var(--danger); }
.link-action + .link-action { margin-left: .35rem; }

/* ---- Числа в таблицах ---- */
th.num, td.num {
    text-align: right;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}
.money { font-variant-numeric: tabular-nums; white-space: nowrap; }
.text-danger { color: var(--danger); }

/* ================= Этап 2 ================= */

/* ---- Поиск в меню ---- */
.sidebar-body > .role,
.sidebar-body > .nav-search { flex-shrink: 0; }
.nav-search {
    display: flex;
    align-items: center;
    gap: .6rem;
    width: 100%;
    margin: 0 0 .6rem;
    padding: .45rem .75rem;
    border: 1px solid rgba(255,255,255,.16);
    border-radius: 8px;
    background: rgba(255,255,255,.06);
    color: var(--side-text);
    font: inherit;
    font-size: .9rem;
    text-align: left;
    cursor: pointer;
}
.nav-search:hover { background: rgba(255,255,255,.1); color: #fff; }
.nav-search span { flex: 1 1 auto; }
.nav-search kbd {
    font: inherit;
    font-size: .7rem;
    padding: .05rem .35rem;
    border: 1px solid rgba(255,255,255,.2);
    border-radius: 4px;
    color: #9aafc0;
}
@media (max-width: 900px) { .nav-search kbd { display: none; } }

/* ---- Окна: подтверждение и быстрый поиск ---- */
dialog.ui-confirm,
dialog.ui-search {
    border: none;
    border-radius: 16px;
    padding: 0;
    color: var(--text);
    background: var(--card);
    box-shadow: 0 4px 6px rgba(18, 28, 40, .06), 0 20px 48px rgba(18, 28, 40, .22);
}
dialog.ui-confirm::backdrop,
dialog.ui-search::backdrop { background: rgba(18, 28, 40, .48); backdrop-filter: blur(3px); }
dialog.ui-confirm { width: min(420px, calc(100vw - 2rem)); }
dialog.ui-confirm form { padding: 1.35rem 1.4rem 1.25rem; margin: 0; }
.ui-confirm-text { margin: 0 0 1.25rem; line-height: 1.45; white-space: pre-line; font-size: 1rem; }
.ui-confirm-actions { display: flex; justify-content: flex-end; gap: .6rem; flex-wrap: wrap; }
.ui-confirm-actions .btn { min-width: 7rem; }

dialog.ui-search {
    width: min(560px, calc(100vw - 2rem));
    margin-top: 12vh;
    overflow: hidden;
}
.ui-search-input {
    border: none;
    border-bottom: 1px solid var(--border);
    border-radius: 0;
    padding: 1rem 1.1rem 1rem 2.7rem;
    font-size: 1.05rem;
    background:
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' fill='none' stroke='%23667788' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='8' cy='8' r='6'/%3E%3Cpath d='M13 13l4 4'/%3E%3C/svg%3E")
        1rem 50% / 18px no-repeat #fff;
}
.ui-search-input:focus { box-shadow: none; outline: none; }
.ui-search-results { max-height: min(55vh, 420px); overflow-y: auto; padding: .35rem; }
.ui-search-item {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .6rem .75rem;
    border-radius: 10px;
    color: var(--text);
    text-decoration: none;
}
.ui-search-item.is-active { background: #eef6f5; }
.ui-search-main { display: flex; flex-direction: column; min-width: 0; }
.ui-search-main strong, .ui-search-main span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ui-search-kind {
    flex: 0 0 auto;
    font-size: .7rem;
    font-weight: 700;
    padding: .15rem .45rem;
    border-radius: 999px;
    background: #e3efee;
    color: var(--accent);
}
.ui-search-kind.pet { background: #f7ebdf; color: #8a4b12; }
.ui-search-empty { padding: 1rem .75rem; }
.ui-search-foot { padding: .5rem 1rem; border-top: 1px solid var(--border); font-size: .78rem; }

/* ---- Формы: отступы, подсказки, единые списки ---- */
.grid > div > small,
form > div > small { display: block; margin-top: .3rem; line-height: 1.35; }
select:not([multiple]):not([size]) {
    -webkit-appearance: none;
    appearance: none;
    padding-right: 2rem;
    background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='none' stroke='%23667788' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M2.5 4.5L6 8l3.5-3.5'/%3E%3C/svg%3E") no-repeat right .7rem center / 12px;
    cursor: pointer;
}
select:disabled { background-color: #f3f5f8; cursor: not-allowed; }
.combo-trigger { min-height: 2.6rem; }

/* ---- Шапка страницы и главная ---- */
.page-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .75rem 1rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}
.page-head h1 { margin: 0; }
.quick-actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.stat-link {
    display: block;
    color: inherit;
    text-decoration: none;
    transition: border-color .12s, box-shadow .12s;
}
.stat-link:hover { border-color: rgba(47,111,106,.45); box-shadow: 0 2px 10px rgba(47,111,106,.1); }
.dash-money {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 1rem 1.5rem;
    margin-bottom: 1.5rem;
}
.dash-money-periods { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem; }
.dash-money-value { font-size: 1.35rem; font-weight: 700; color: var(--accent); font-variant-numeric: tabular-nums; white-space: nowrap; }
.dash-row { display: flex; justify-content: space-between; gap: 1rem; padding: .15rem 0; font-size: .93rem; }
.dash-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
    gap: 1rem;
    align-items: start;
}
.dash-block h2 { margin: 0; font-size: 1.05rem; }
.dash-block-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .5rem;
    margin-bottom: .6rem;
}
.dash-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .35rem; }
.dash-list li { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.dot { width: 10px; height: 10px; border-radius: 3px; flex: 0 0 10px; display: inline-block; }
table.table-plain th, table.table-plain td { padding: .4rem .35rem; font-size: .9rem; }
table.table-plain tr:last-child td { border-bottom: none; }
.empty-note { color: var(--muted); margin: .25rem 0; font-size: .92rem; }

/* ---- Карточка счёта ---- */
.meta-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: .85rem 1.25rem;
    margin: 0;
}
.meta-grid dt {
    font-size: .75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--muted);
    margin-bottom: .2rem;
}
.meta-grid dd { margin: 0; line-height: 1.4; }
.meta-grid dd a { color: var(--accent); font-weight: 600; text-decoration: none; }
.meta-grid dd a:hover { text-decoration: underline; }
.inv-head { margin-bottom: 1rem; }
.inv-comment { margin: .85rem 0 0; }
table.table-head-strong thead th {
    background: #e9eff5;
    color: var(--text);
    font-weight: 700;
}
table.table-head-strong thead th:first-child { border-top-left-radius: 8px; }
table.table-head-strong thead th:last-child { border-top-right-radius: 8px; }
.inv-total {
    display: flex;
    align-items: flex-end;
    gap: 1.5rem 2.5rem;
    flex-wrap: wrap;
    margin-top: 1rem;
}
.inv-total-value { font-size: 1.9rem; font-weight: 700; color: var(--accent); font-variant-numeric: tabular-nums; white-space: nowrap; line-height: 1.15; }
.inv-total-sub { font-size: 1.15rem; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---- Пустые состояния ---- */
td.empty-cell { padding: 0; }
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .75rem;
    padding: 2rem 1rem;
    text-align: center;
    color: var(--muted);
}
.empty-state p { margin: 0; font-size: .98rem; }

/* ---- Вход ---- */
.login-card { padding: 2rem 1.75rem 1.75rem; }
.login-brand { display: flex; flex-direction: column; align-items: center; gap: .35rem; text-align: center; margin-bottom: 1.5rem; }
.login-logo { width: 72px; height: 72px; object-fit: contain; border-radius: 14px; margin-bottom: .35rem; }
.login-name { font-size: 1.35rem; font-weight: 700; line-height: 1.25; text-wrap: balance; }
.login-form { display: flex; flex-direction: column; gap: 1rem; }
.login-form .btn { width: 100%; min-height: 44px; font-size: 1rem; }

/* ---- Узкие экраны: без горизонтальной прокрутки ---- */
@media (max-width: 900px) {
    .dash-money { grid-template-columns: 1fr; }
    .dash-grid { grid-template-columns: 1fr; }
    .content.full { margin: 2rem auto; padding: 1rem; }
}
@media (max-width: 480px) {
    .dash-money-periods { grid-template-columns: 1fr; gap: .5rem; }
    .quick-actions { width: 100%; }
    .quick-actions .btn { flex: 1 1 auto; text-align: center; }
    .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .6rem; }
    .stat .value { font-size: 1.3rem; }
    .stat .value.money { font-size: 1.1rem; white-space: normal; }
}
