/* ===== Tickets self-contained theme layer ===== */

/* Local fallbacks live only on tickets nodes */
.tk,
.tk-modal,
.tk-lightbox,
.tk-toast {
    --tk-bg-primary: #0a0e17;
    --tk-bg-secondary: #111827;
    --tk-bg-glass: rgba(17, 24, 39, 0.65);
    --tk-bg-glass-hover: rgba(17, 24, 39, 0.8);
    --tk-border-glass: rgba(255, 255, 255, 0.08);
    --tk-border-glass-hover: rgba(255, 255, 255, 0.15);
    --tk-text-primary: #f1f5f9;
    --tk-text-secondary: #94a3b8;
    --tk-text-muted: #64748b;
    --tk-accent: #3b82f6;
    --tk-accent-hover: #2563eb;
    --tk-accent-glow: rgba(59, 130, 246, 0.25);
    --tk-accent-subtle: rgba(59, 130, 246, 0.1);
    --tk-success: #10b981;
    --tk-error: #ef4444;
    --tk-error-bg: rgba(239, 68, 68, 0.1);
    --tk-warning: #f59e0b;
    --tk-shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.4);
    --tk-shadow-md: 0 4px 24px rgba(0, 0, 0, 0.5);
    --tk-shadow-lg: 0 8px 48px rgba(0, 0, 0, 0.6);
    --tk-shadow-glow: 0 0 40px var(--tk-accent-glow);
    --tk-radius-sm: 8px;
    --tk-radius-md: 12px;
    --tk-radius-lg: 20px;
    --tk-radius-full: 9999px;
    --tk-layout-max: 1152px;
}

/* Match parser_standalone light theme via host theme switcher */
:root[data-theme="light"] .tk,
:root[data-theme="light"] .tk-modal,
:root[data-theme="light"] .tk-lightbox,
:root[data-theme="light"] .tk-toast {
    --tk-bg-primary: #f0f4f8;
    --tk-bg-secondary: #ffffff;
    --tk-bg-glass: rgba(255, 255, 255, 0.7);
    --tk-bg-glass-hover: rgba(255, 255, 255, 0.85);
    --tk-border-glass: rgba(0, 0, 0, 0.08);
    --tk-border-glass-hover: rgba(0, 0, 0, 0.12);
    --tk-text-primary: #0f172a;
    --tk-text-secondary: #475569;
    --tk-text-muted: #94a3b8;
    --tk-accent: #2563eb;
    --tk-accent-hover: #1d4ed8;
    --tk-accent-glow: rgba(37, 99, 235, 0.2);
    --tk-accent-subtle: rgba(37, 99, 235, 0.06);
    --tk-success: #059669;
    --tk-error: #dc2626;
    --tk-error-bg: rgba(220, 38, 38, 0.06);
    --tk-warning: #d97706;
    --tk-shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
    --tk-shadow-md: 0 4px 24px rgba(0, 0, 0, 0.1);
    --tk-shadow-lg: 0 8px 48px rgba(0, 0, 0, 0.12);
}

/* Scoped mapping keeps existing module rules unchanged */
.tk,
.tk-modal,
.tk-lightbox,
.tk-toast {
    --bg-primary: var(--tk-bg-primary);
    --bg-secondary: var(--tk-bg-secondary);
    --bg-glass: var(--tk-bg-glass);
    --bg-glass-hover: var(--tk-bg-glass-hover);
    --border-glass: var(--tk-border-glass);
    --border-glass-hover: var(--tk-border-glass-hover);
    --text-primary: var(--tk-text-primary);
    --text-secondary: var(--tk-text-secondary);
    --text-muted: var(--tk-text-muted);
    --accent: var(--tk-accent);
    --accent-hover: var(--tk-accent-hover);
    --accent-glow: var(--tk-accent-glow);
    --accent-subtle: var(--tk-accent-subtle);
    --success: var(--tk-success);
    --error: var(--tk-error);
    --error-bg: var(--tk-error-bg);
    --warning: var(--tk-warning);
    --shadow-sm: var(--tk-shadow-sm);
    --shadow-md: var(--tk-shadow-md);
    --shadow-lg: var(--tk-shadow-lg);
    --shadow-glow: var(--tk-shadow-glow);
    --radius-sm: var(--tk-radius-sm);
    --radius-md: var(--tk-radius-md);
    --radius-lg: var(--tk-radius-lg);
    --radius-full: var(--tk-radius-full);
}

.tk-glass,
.tk .glass:not(.tk-modal__content) {
    background: var(--bg-glass);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.tk-glass:hover,
.tk .glass:not(.tk-modal__content):hover {
    border-color: var(--border-glass-hover);
}

@keyframes tkFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes tkFadeInUp {
    from { opacity: 0; transform: translateY(16px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ===== TICKET SYSTEM ===== */

.tk {
    display: flex;
    flex-direction: column;
    gap: 20px;
    width: 100%;
    max-width: var(--tk-layout-max);
    margin-inline: auto;
    box-sizing: border-box;
    padding-inline: clamp(12px, 3vw, 24px);
}

/* --- Header & Counters --- */

.tk-header {
    padding: 28px 32px;
}

.tk-header__top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
}

.tk-header__title {
    font-size: 1.5rem;
    font-weight: 700;
}

.tk-counters {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
}

.tk-counter {
    padding: 16px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-glass);
    text-align: center;
    transition: border-color 0.2s;
}

.tk-counter:hover {
    border-color: var(--border-glass-hover);
}

.tk-counter__value {
    display: block;
    font-size: 1.75rem;
    font-weight: 700;
    line-height: 1;
    margin-bottom: 4px;
}

.tk-counter__label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.tk-counter--open .tk-counter__value { color: var(--accent); }
.tk-counter--progress .tk-counter__value { color: var(--warning); }
.tk-counter--resolved .tk-counter__value { color: var(--success); }
.tk-counter--total .tk-counter__value { color: var(--text-secondary); }

/* --- Filters --- */

.tk-filters {
    padding: 16px 24px;
}

.tk-filters__row {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.tk-filters__search {
    flex: 1;
    min-width: 200px;
    padding: 10px 16px;
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-full);
    background: transparent;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.875rem;
    outline: none;
    transition: border-color 0.2s;
}

.tk-filters__search:focus {
    border-color: var(--accent);
}

.tk-filters__search::placeholder {
    color: var(--text-muted);
}

.tk-filters__select {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    padding: 10px 36px 10px 16px;
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-full);
    background-color: var(--bg-secondary);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 14px 14px;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.875rem;
    cursor: pointer;
    outline: none;
    transition: border-color 0.2s;
}

.tk-filters__select:focus {
    border-color: var(--accent);
}

/* --- Ticket list --- */

.tk-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.tk-list__empty {
    text-align: center;
    padding: 48px 24px;
    color: var(--text-muted);
    font-size: 0.95rem;
}

.tk-item {
    padding: 20px 24px;
    cursor: pointer;
    transition: border-color 0.2s, box-shadow 0.2s;
    animation: tkFadeInUp 0.3s ease both;
}

.tk-item:hover {
    border-color: var(--accent);
    box-shadow: var(--shadow-glow);
}

.tk-item__top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 8px;
}

.tk-item__title {
    font-size: 1rem;
    font-weight: 600;
    line-height: 1.4;
    flex: 1;
}

.tk-item__badges {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

.tk-item__desc {
    color: var(--text-secondary);
    font-size: 0.85rem;
    line-height: 1.5;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    margin-bottom: 12px;
}

.tk-item__meta {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px 16px;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.tk-item__meta-sep {
    opacity: 0.45;
    user-select: none;
}

.tk-item__author-row {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    min-width: 0;
}

.tk-item__author {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    max-width: min(100%, 260px);
    min-width: 0;
}

.tk-item__author-txt {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}

.tk-item__author--muted {
    opacity: 0.65;
    font-style: italic;
}

.tk-item__meta-comments {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.tk-item__meta-attach {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    opacity: 0.9;
}

.tk-icon.tk-icon--inline {
    display: inline-block;
    vertical-align: middle;
    flex-shrink: 0;
    color: var(--text-muted);
    opacity: 0.95;
}

/* --- Badges --- */

.tk-badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: var(--radius-full);
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    white-space: nowrap;
}

.tk-badge--open       { background: var(--accent-subtle); color: var(--accent); }
.tk-badge--in_progress { background: rgba(245, 158, 11, 0.12); color: var(--warning); }
.tk-badge--resolved   { background: rgba(16, 185, 129, 0.12); color: var(--success); }
.tk-badge--closed     { background: rgba(100, 116, 139, 0.12); color: var(--text-muted); }

.tk-badge--low       { background: rgba(100, 116, 139, 0.1); color: var(--text-muted); }
.tk-badge--medium    { background: var(--accent-subtle); color: var(--accent); }
.tk-badge--high      { background: rgba(245, 158, 11, 0.12); color: var(--warning); }
.tk-badge--critical  { background: var(--error-bg); color: var(--error); }

.tk-badge--bug       { background: var(--error-bg); color: var(--error); }
.tk-badge--feature   { background: rgba(139, 92, 246, 0.12); color: #a78bfa; }
.tk-badge--question  { background: rgba(16, 185, 129, 0.12); color: var(--success); }
.tk-badge--general   { background: rgba(100, 116, 139, 0.1); color: var(--text-muted); }

/* --- Buttons --- */

.tk-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-full);
    font-family: inherit;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.tk-btn--primary {
    background: var(--accent);
    color: #fff;
}

.tk-btn--primary:hover {
    background: var(--accent-hover);
    box-shadow: 0 4px 16px var(--accent-glow);
}

.tk-btn--ghost {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border-glass);
}

.tk-btn--ghost:hover {
    border-color: var(--text-muted);
    color: var(--text-primary);
}

.tk-btn--sm {
    padding: 6px 14px;
    font-size: 0.8rem;
}

/* Только иконка (редактирование и т.п.) */
.tk-btn--icon-only {
    padding: 0;
    min-width: 28px;
    min-height: 28px;
    justify-content: center;
    align-items: center;
    gap: 0;
}

.tk-btn--sm.tk-btn--icon-only {
    min-width: 28px;
    min-height: 28px;
    padding: 0;
}

.tk-btn--icon-only .tk-edit-icon {
    display: block;
    flex-shrink: 0;
    color: inherit;
}

.tk-btn--danger {
    background: var(--error-bg);
    color: var(--error);
    border: 1px solid transparent;
}

.tk-btn--danger:hover {
    background: var(--error);
    color: #fff;
}

/* Менее агрессивное удаление в карточке тикета */
.tk-detail__delete {
    background: transparent;
    color: var(--error);
    border: 1px solid rgba(239, 68, 68, 0.35);
}

.tk-detail__delete:hover {
    background: var(--error-bg);
    color: var(--error);
    border-color: rgba(239, 68, 68, 0.55);
}

[data-theme="light"] .tk-detail__delete {
    border-color: rgba(220, 38, 38, 0.4);
}

[data-theme="light"] .tk-detail__delete:hover {
    background: rgba(239, 68, 68, 0.08);
}

/* --- Modal --- */

@keyframes tkModalBackdropIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Центрированная панель: лёгкий подъём + scale — без смены позиции layout */
@keyframes tkModalContentIn {
    from {
        opacity: 0;
        transform: translate3d(0, 14px, 0) scale(0.97);
    }
    to {
        opacity: 1;
        transform: translate3d(0, 0, 0) scale(1);
    }
}

.tk-modal[hidden] { display: none; }

.tk-modal {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    /* Не обрезать панель у краёв экрана / «диагонали» (notch, скругление дисплея) */
    padding:
        max(12px, env(safe-area-inset-top, 0px))
        max(16px, env(safe-area-inset-right, 0px))
        max(12px, env(safe-area-inset-bottom, 0px))
        max(16px, env(safe-area-inset-left, 0px));
    box-sizing: border-box;
}

.tk-modal__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    animation: tkModalBackdropIn 0.25s cubic-bezier(0.22, 1, 0.36, 1);
}

.tk-modal__busy {
    display: none;
    position: absolute;
    z-index: 2;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    padding: 12px 20px;
    border-radius: var(--radius-md);
    background: var(--bg-secondary);
    border: 1px solid var(--border-glass);
    color: var(--text-muted);
    font-size: 0.9rem;
    pointer-events: none;
    box-shadow: var(--shadow-md);
}

.tk-modal--pending .tk-modal__busy {
    display: block;
}

.tk-modal__content {
    position: relative;
    z-index: 1;
    max-width: 560px;
    width: min(560px, 100%);
    min-width: 0;
    /* Fallback, затем dvh + safe-area — чтобы на ноутбуках с вырезом не резало углы */
    max-height: min(85vh, calc(100vh - 48px));
    max-height: min(85dvh, calc(100dvh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - 48px));
    padding: 32px;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    scrollbar-color: rgba(148, 163, 184, 0.35) transparent;
    animation: tkModalContentIn 0.32s cubic-bezier(0.22, 1, 0.36, 1) both;
    transform-origin: center center;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-glass);
    box-sizing: border-box;
}

/* Модалка деталей: затемнение + .tk-modal__busy сразу, панель — после fetch + render */
.tk-modal--pending .tk-modal__content {
    opacity: 0;
    transform: translate3d(0, 14px, 0) scale(0.97);
    animation: none;
    pointer-events: none;
}

@media (prefers-reduced-motion: reduce) {
    .tk-modal__backdrop {
        animation: tkFadeIn 0.2s ease;
    }

    .tk-modal__content {
        animation: tkFadeIn 0.2s ease both;
    }
}

/* Непрозрачная панель вместо стекла в detail/create modal (те же радиус и бордер, что у .tk-glass) */
.tk-modal__content.tk-glass,
.tk-modal__content.glass {
    background: var(--bg-secondary);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    box-shadow: var(--shadow-lg);
}

[data-theme="light"] .tk-modal__content {
    scrollbar-color: rgba(100, 116, 139, 0.4) transparent;
}

.tk-modal__content::-webkit-scrollbar {
    width: 8px;
}

.tk-modal__content::-webkit-scrollbar-track {
    margin: 6px 0;
    background: transparent;
    border-radius: var(--radius-full);
}

.tk-modal__content::-webkit-scrollbar-thumb {
    border-radius: var(--radius-full);
    border: 2px solid transparent;
    background-clip: padding-box;
    background-color: rgba(148, 163, 184, 0.35);
}

[data-theme="light"] .tk-modal__content::-webkit-scrollbar-thumb {
    background-color: rgba(100, 116, 139, 0.38);
}

.tk-modal__content::-webkit-scrollbar-thumb:hover {
    background-color: rgba(148, 163, 184, 0.55);
}

[data-theme="light"] .tk-modal__content::-webkit-scrollbar-thumb:hover {
    background-color: rgba(100, 116, 139, 0.55);
}

.tk-modal__content--wide {
    max-width: 720px;
}

/* Карточка тикета (issue): шире, как в GitHub / Linear */
.tk-modal__content--issue {
    max-width: min(var(--tk-layout-max), 94vw);
    width: 94%;
    padding: 30px 34px 34px;
}

.tk-modal__close {
    position: absolute;
    top: 16px;
    right: 16px;
    background: none;
    border: none;
    font-size: 1.05rem;
    color: var(--text-muted);
    cursor: pointer;
    line-height: 1;
    transition: color 0.2s;
}

.tk-modal__close:hover {
    color: var(--text-primary);
}

.tk-modal__title {
    font-size: 1.2rem;
    font-weight: 700;
    margin-bottom: 24px;
}

/* --- Form --- */

.tk-form__group {
    margin-bottom: 16px;
}

.tk-form__row {
    display: flex;
    gap: 12px;
}

.tk-form__group--half {
    flex: 1;
}

.tk-form__label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.tk-form__input,
.tk-form__select,
.tk-form__textarea {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-md);
    background: transparent;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.9rem;
    outline: none;
    transition: border-color 0.2s;
}

.tk-form__select {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    padding: 12px 40px 12px 16px;
    background-color: var(--bg-primary);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
    background-size: 16px 16px;
    cursor: pointer;
}

[data-theme="light"] .tk-filters__select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
}

[data-theme="light"] .tk-form__select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
}

.tk-form__textarea {
    resize: vertical;
    min-height: 100px;
    line-height: 1.6;
}

.tk-form__input:focus,
.tk-form__select:focus,
.tk-form__textarea:focus {
    border-color: var(--accent);
}

.tk-form__input::placeholder,
.tk-form__textarea::placeholder {
    color: var(--text-muted);
}

/* Форма в модалке: те же поверхности и скругления, что у строки фильтров */
.tk-modal .tk-form__input,
.tk-modal .tk-form__textarea {
    background: var(--bg-primary);
    border-radius: var(--radius-md);
}

.tk-modal .tk-form__select {
    padding: 10px 36px 10px 16px;
    border-radius: var(--radius-full);
    background-color: var(--bg-secondary);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 14px 14px;
}

[data-theme="light"] .tk-modal .tk-form__select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
}

.tk-form__actions {
    display: flex;
    gap: 10px;
    margin-top: 8px;
}

.tk-form__file-pick {
    display: inline-flex;
    margin-top: 6px;
    max-width: 100%;
}

.tk-form__file-pick .tk-attach-btn__inner {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

/* Подсказки вложений и вставки из буфера (Ctrl+V / ⌘V) */
.tk-form__hint-text {
    font-size: 0.75rem;
    line-height: 1.45;
    color: var(--text-muted);
}

.tk-form__attachments-lead {
    display: block;
    margin: 0 0 6px;
    font-weight: 400;
}

.tk-form__paste-hint {
    margin: 0 0 10px;
}

.tk-form__file-hint {
    margin-top: 10px;
    font-size: 0.75rem;
    line-height: 1.45;
    color: var(--text-muted);
    word-break: break-word;
}

/* --- Issue detail (GitHub Issue + Linear spacing) --- */

.tk-sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.tk-detail {
    max-width: 100%;
}

.tk-detail__hero {
    margin-bottom: 24px;
    padding-bottom: 0;
    border-bottom: none;
}

.tk-detail__title-row {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 16px;
}

.tk-detail__title {
    font-size: 1.35rem;
    font-weight: 700;
    margin: 0;
    line-height: 1.35;
    letter-spacing: -0.02em;
    flex: 1;
    min-width: 0;
}

.tk-title__edit.tk-btn--icon-only {
    flex-shrink: 0;
}

.tk-title__edit-wrap {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.tk-title__edit-input {
    width: 100%;
    box-sizing: border-box;
    font-size: 1.05rem;
    font-weight: 600;
}

.tk-title__edit-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: flex-end;
}

.tk-detail__toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
}

.tk-detail__badges {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    align-items: center;
}

.tk-detail__toolbar-right {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.tk-detail__field-label {
    font-size: 0.75rem;
    font-weight: 500;
    letter-spacing: 0.01em;
    color: var(--text-muted);
}

.tk-detail__meta-bar {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 14px;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.tk-detail__meta-sep {
    opacity: 0.5;
    user-select: none;
}

.tk-detail__author {
    color: var(--text-secondary);
}

.tk-detail__author-line {
    display: inline-flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
}

.tk-detail__author-label {
    font-weight: 600;
    margin-right: 4px;
    color: var(--text-muted);
}

.tk-detail__author--muted {
    font-style: italic;
    opacity: 0.9;
}

.tk-detail__section {
    margin-bottom: 28px;
}

.tk-detail__section--description {
    padding-bottom: 4px;
}

.tk-detail__section--thread {
    margin-bottom: 20px;
}

.tk-section__head {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 14px;
}

.tk-section__head--desc {
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
}

.tk-section__head--desc .tk-desc__edit {
    flex-shrink: 0;
}

.tk-section__head--attachments {
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px 12px;
    margin-bottom: 12px;
}

.tk-detail__desc-container {
    min-width: 0;
}

.tk-desc__edit-area {
    display: block;
    width: 100%;
    min-height: 120px;
    box-sizing: border-box;
}

.tk-desc__edit-wrap {
    width: 100%;
}

/* Тот же паттерн, что у композера: textarea внутри tk-composer__box */
.tk-desc__edit-wrap .tk-composer__box .tk-desc__edit-area {
    border: none;
    border-radius: 0;
    border-bottom: 1px solid var(--border-glass);
    resize: vertical;
}

.tk-comment__edit-wrap .tk-composer__box .tk-comment__edit-area {
    width: 100%;
    box-sizing: border-box;
    min-height: 72px;
    border: none;
    border-radius: 0;
    border-bottom: 1px solid var(--border-glass);
    resize: vertical;
}

.tk-section__label {
    margin: 0;
    font-size: 0.8125rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    color: var(--text-muted);
}

.tk-section__count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 22px;
    height: 22px;
    padding: 0 7px;
    border-radius: var(--radius-full);
    font-size: 0.7rem;
    font-weight: 600;
    background: rgba(100, 116, 139, 0.12);
    color: var(--text-muted);
}

.tk-detail__desc.tk-prose {
    font-size: 0.9375rem;
    line-height: 1.65;
    color: var(--text-secondary);
    white-space: pre-wrap;
    word-break: break-word;
    padding: 4px 0 2px;
    border-radius: 0;
    border: none;
    border-bottom: 1px solid var(--border-glass);
    background: transparent;
}

[data-theme="light"] .tk-detail__desc.tk-prose {
    background: transparent;
}

.tk-detail__empty,
.tk-detail__muted {
    font-size: 0.9rem;
    color: var(--text-muted);
    font-style: italic;
    margin: 0;
}

.tk-upload-inline {
    margin-top: 12px;
}

.tk-attachments__empty {
    margin: 0 0 12px;
    font-size: 0.85rem;
}

/* --- Attachments (к описанию) --- */

.tk-detail__section--ticket-attachments .tk-gallery {
    margin-top: 0;
}

.tk-detail__section .tk-gallery {
    margin-bottom: 4px;
}

.tk-gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(76px, 1fr));
    gap: 8px;
}

.tk-gallery__item {
    position: relative;
    border-radius: var(--radius-md);
    overflow: hidden;
    border: 1px solid var(--border-glass);
    aspect-ratio: 1;
    background: var(--bg-secondary);
}

.tk-gallery__item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
    cursor: zoom-in;
    display: block;
}

.tk-gallery__del {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 20px;
    height: 20px;
    border: none;
    border-radius: var(--radius-sm);
    background: rgba(0, 0, 0, 0.55);
    color: #fff;
    font-size: 0.65rem;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.tk-gallery__del:hover {
    background: var(--error);
}

.tk-upload-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    margin-top: 12px;
}

.tk-upload-row input[type="file"] {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* --- Lightbox --- */

.tk-lightbox[hidden] {
    display: none;
}

.tk-lightbox {
    position: fixed;
    inset: 0;
    z-index: 300;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: tkFadeIn 0.2s ease;
}

.tk-lightbox__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
}

.tk-lightbox__img {
    position: relative;
    z-index: 1;
    max-width: min(92vw, var(--tk-layout-max));
    max-height: 88vh;
    object-fit: contain;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
}

.tk-lightbox__close {
    position: absolute;
    top: 16px;
    right: 16px;
    z-index: 2;
    width: 32px;
    height: 32px;
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-full);
    background: var(--bg-glass);
    color: var(--text-primary);
    font-size: 1.05rem;
    line-height: 1;
    cursor: pointer;
    transition: border-color 0.2s, color 0.2s;
}

.tk-lightbox__close:hover {
    border-color: var(--accent);
    color: var(--accent);
}

/* --- Status select --- */

.tk-status-select {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    padding: 6px 32px 6px 12px;
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-full);
    background-color: var(--bg-secondary);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 14px 14px;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    outline: none;
    transition: border-color 0.2s;
}

.tk-status-select:focus {
    border-color: var(--accent);
}

/* --- Кнопки вложений (скрытый input) --- */

.tk-attach-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border-radius: var(--radius-full);
    border: 1px solid var(--border-glass);
    background: transparent;
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 0.8125rem;
    font-weight: 500;
    transition: border-color 0.2s, color 0.2s, background 0.2s;
}

/* Иконка вместо длинной подписи (деталь тикета) */
.tk-attach-btn--icon {
    min-width: 34px;
    min-height: 34px;
    padding: 0;
}

.tk-attach-btn--icon .tk-attach-btn__inner {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 7px;
    line-height: 0;
}

.tk-attach-btn--icon .tk-attach-icon {
    display: block;
    flex-shrink: 0;
    color: inherit;
}

.tk-attach-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-subtle);
}

.tk-attach-btn--ghost {
    border-style: dashed;
}

/* В карточке тикета вторичные вложения без пунктира */
.tk-detail .tk-attach-btn--ghost {
    border-style: solid;
}

.tk-attach-btn__inner {
    display: inline-block;
    padding: 7px 14px;
}

.tk-attach-btn:focus-within {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* --- Лента переписки --- */

.tk-comment-thread {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.tk-comment {
    animation: tkFadeInUp 0.25s ease both;
}

.tk-comment__bubble {
    flex: 1;
    min-width: 0;
    padding: 12px 14px 10px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-glass);
    background: transparent;
}

/* Свои / чужие: палитра из global.css (accent-subtle, bg-*) */
.tk-comment--mine .tk-comment__bubble {
    background: var(--accent-subtle);
    border-color: var(--border-glass);
}

.tk-comment--other .tk-comment__bubble {
    background: color-mix(in srgb, var(--bg-secondary) 78%, var(--bg-primary));
    border-color: var(--border-glass);
}

@supports not (background: color-mix(in srgb, white, black)) {
    .tk-comment--other .tk-comment__bubble {
        background: var(--bg-secondary);
    }
}

.tk-comment__head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 8px;
}

.tk-comment__head-main {
    flex: 1;
    min-width: 0;
}

.tk-comment__head-meta {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: flex-end;
    flex-shrink: 0;
}

.tk-comment__edited {
    font-size: 0.7rem;
    color: var(--text-muted);
    font-style: italic;
}

.tk-comment__edit {
    padding: 2px 8px;
    font-size: 0.75rem;
}

.tk-comment__edit.tk-btn--icon-only {
    padding: 0;
    font-size: 0;
    line-height: 0;
}

.tk-comment__edit-wrap {
    margin-bottom: 8px;
}

.tk-comment__edit-area {
    width: 100%;
    min-height: 72px;
    resize: vertical;
}

.tk-comment__edit-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 8px;
}

.tk-comment__author-row {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    min-width: 0;
}

.tk-comment__author {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: min(100%, 280px);
}

.tk-comment__role-badge {
    display: inline-flex;
    align-items: center;
    padding: 1px 7px;
    border-radius: var(--radius-full);
    font-size: 0.65rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    color: var(--text-muted);
    background: rgba(128, 128, 128, 0.12);
    border: 1px solid var(--border-glass);
    flex-shrink: 0;
}

.tk-comment__role-badge--admin {
    color: var(--accent, #6ee7b7);
    border-color: rgba(110, 231, 183, 0.35);
    background: rgba(110, 231, 183, 0.08);
}

.tk-comment__author--muted {
    font-weight: 500;
    font-style: italic;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.tk-comment__date {
    font-size: 0.75rem;
    color: var(--text-muted);
    white-space: nowrap;
}

.tk-comment__body {
    font-size: 0.9rem;
    line-height: 1.6;
    white-space: pre-wrap;
    word-break: break-word;
    color: var(--text-primary);
}

.tk-comment__no-text {
    color: var(--text-muted);
    font-style: italic;
}

.tk-comment__gallery {
    margin-top: 12px;
}

.tk-comment__footer {
    margin-top: 10px;
    padding-top: 8px;
    border-top: 1px solid var(--border-glass);
}

.tk-comments__empty {
    text-align: center;
    padding: 24px 16px;
    color: var(--text-muted);
    font-size: 0.875rem;
    border-radius: var(--radius-md);
    border: none;
    background: rgba(100, 116, 139, 0.06);
}

[data-theme="light"] .tk-comments__empty {
    background: rgba(100, 116, 139, 0.08);
}

/* --- Композер ответа --- */

.tk-detail__composer {
    margin-top: 8px;
    padding-top: 20px;
}

.tk-detail__composer > .tk-section__label {
    margin-bottom: 14px;
}

.tk-comments__form {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.tk-composer__box {
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-md);
    background: rgba(255, 255, 255, 0.03);
    overflow: hidden;
}

[data-theme="light"] .tk-composer__box {
    background: rgba(255, 255, 255, 0.65);
}

.tk-comments__input--composer {
    min-height: 88px;
    resize: vertical;
    padding: 12px 14px;
    font-size: 0.9375rem;
    line-height: 1.5;
}

.tk-detail__composer .tk-composer__box .tk-comments__input--composer {
    width: 100%;
    box-sizing: border-box;
    border: none;
    border-radius: 0;
    border-bottom: 1px solid var(--border-glass);
}

/* Превью в композере и в форме создания тикета */
.tk-composer__previews.tk-gallery,
.tk-create__previews.tk-gallery {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border-glass);
}

/* Иначе .tk-gallery { display: grid } перебивает UA display:none у [hidden] — пустая полоса с двойной линией */
.tk-composer__previews.tk-gallery[hidden],
.tk-create__previews.tk-gallery[hidden] {
    display: none !important;
    padding: 0;
    border: none;
}

.tk-create__previews.tk-gallery {
    margin-top: 10px;
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-md);
}

.tk-composer__previews .tk-gallery__item img,
.tk-create__previews .tk-gallery__item img {
    cursor: default;
}

.tk-gallery__item--file {
    aspect-ratio: auto;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    justify-content: center;
    min-height: 72px;
    padding: 8px;
    box-sizing: border-box;
}

.tk-gallery__file-link {
    font-size: 0.8125rem;
    line-height: 1.35;
    word-break: break-word;
    color: var(--accent);
    text-decoration: none;
}

.tk-gallery__file-link:hover {
    text-decoration: underline;
}

/* Имя файла в превью композера (ещё не загружено — не ссылка) */
.tk-gallery__file-label {
    font-size: 0.8125rem;
    line-height: 1.35;
    word-break: break-word;
    color: var(--text-primary);
    flex: 1;
    min-width: 0;
}

.tk-composer__actions {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 12px;
    flex-wrap: wrap;
    padding: 10px 12px;
}

/* Скрепка слева; первая кнопка после label — справа (Отмена | Сохранить или только Отправить) */
.tk-composer__actions > label + .tk-btn {
    margin-left: auto;
}

.tk-composer__hint {
    margin: 0;
    padding: 8px 12px 10px;
    font-size: 0.72rem;
    line-height: 1.45;
    color: var(--text-muted);
    border-top: 1px solid var(--border-glass);
    background: rgba(0, 0, 0, 0.12);
}

[data-theme="light"] .tk-composer__hint {
    background: rgba(0, 0, 0, 0.03);
}

.tk-comments__input {
    flex: 1;
    padding: 10px 16px;
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-md);
    background: transparent;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.875rem;
    outline: none;
    resize: none;
    transition: border-color 0.2s;
}

.tk-comments__input:focus {
    border-color: var(--accent);
}

.tk-comments__input::placeholder {
    color: var(--text-muted);
}

/* --- Pagination --- */

.tk-pagination {
    display: flex;
    justify-content: center;
    gap: 4px;
    padding: 8px 0;
}

.tk-pagination__btn {
    min-width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s;
}

.tk-pagination__btn:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.tk-pagination__btn--active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.tk-pagination__btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* --- Toast --- */

.tk-toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    max-width: min(420px, calc(100vw - 48px));
    padding: 12px 20px;
    border-radius: var(--radius-md);
    background: var(--success);
    color: #fff;
    font-size: 0.85rem;
    font-weight: 500;
    box-shadow: var(--shadow-md);
    animation: tkFadeInUp 0.3s ease;
    /* Поверх модалки тикета (.tk-modal z-index: 200) и любых overflow у body */
    z-index: 2147483647;
    isolation: isolate;
}

.tk-toast--error {
    background: var(--error);
}

/* ===== RESPONSIVE ===== */

@media (max-width: 768px) {
    .tk-header { padding: 20px; }

    .tk-counters {
        grid-template-columns: repeat(2, 1fr);
    }

    .tk-filters__row {
        flex-direction: column;
    }

    .tk-form__row {
        flex-direction: column;
    }

    .tk-item { padding: 16px; }

    .tk-modal__content {
        padding: 24px;
        width: min(560px, 100%);
    }

    .tk-modal__content--issue {
        width: min(840px, 94%);
        padding: 22px 20px 24px;
    }

    .tk-detail__toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    .tk-detail__toolbar-right {
        justify-content: flex-start;
    }
}

@media (max-width: 480px) {
    .tk-header__top {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
    }

    .tk-counters {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }

    .tk-counter { padding: 12px; }
    .tk-counter__value { font-size: 1.35rem; }

    .tk-detail__title {
        font-size: 1.15rem;
    }

    .tk-composer__actions {
        flex-direction: column;
        align-items: stretch;
    }

    .tk-composer__actions > label + .tk-btn {
        margin-left: 0;
    }

    .tk-composer__actions .tk-btn {
        width: 100%;
        justify-content: center;
    }
}
