/* ============================================
   SHARED COMPONENTS
   Buttons, badges, chips, cards, tooltips,
   forms, toggles, color-picker, utilities
   ============================================ */

/* === Buttons === */

.btn {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    min-height: var(--tap-min);
    padding: var(--space-3) var(--space-5);
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    font-size: var(--text-sm);
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.2s, color 0.2s, border-color 0.2s, box-shadow 0.2s, transform 0.2s, opacity 0.2s;
    text-decoration: none;
    line-height: 1.4;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn svg {
    width: var(--icon-sm);
    height: var(--icon-sm);
    flex-shrink: 0;
    stroke-width: 2;
}

.btn-icon {
    width: var(--icon-sm);
    height: var(--icon-sm);
    flex-shrink: 0;
    stroke-width: 2;
}

/* Подпись для кнопок, которые на десктопе живут как иконка, а на узком экране
   растягиваются на всю ширину: голая иконка в такой полосе не читается */
.btn-label-narrow {
    display: none;
}

@media (max-width: 768px) {
    .btn-label-narrow {
        display: inline;
    }
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background: var(--primary-dark);
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

.btn-secondary {
    background: var(--background);
    color: var(--text-secondary);
    border-color: var(--border-strong);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--background-secondary);
    border-color: var(--primary-color);
    color: var(--text-brand);
}

.btn-secondary:active:not(:disabled) {
    transform: scale(0.98);
}

.btn-success {
    background: var(--success-btn-bg);
    color: white;
}

.btn-success:hover:not(:disabled) {
    background: var(--success-btn-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

.btn-danger {
    background: var(--danger-color);
    color: white;
}

.btn-danger:hover:not(:disabled) {
    background: #c53030;
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn-accent {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

.btn-accent:hover:not(:disabled) {
    background: var(--accent-light);
    border-color: var(--accent-light);
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

.btn-sm {
    padding: var(--space-2) var(--space-3);
    font-size: var(--text-sm);
}

.btn-sm .btn-icon {
    width: var(--icon-sm);
    height: var(--icon-sm);
}

.btn-lg {
    padding: var(--space-3) var(--space-6);
    font-size: var(--text-lg);
}

.btn-reset {
    background: var(--surface);
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

.btn-reset:hover:not(:disabled) {
    background: var(--background-secondary);
    border-color: var(--accent);
    color: var(--accent);
}

.btn-reset svg {
    flex-shrink: 0;
}

.btn-icon-only {
    padding: 0;
    justify-content: center;
    width: var(--space-8);
    height: var(--space-8);
    min-width: var(--tap-min);
}

.btn-icon-only.btn-sm {
    width: var(--space-7);
    height: var(--space-7);
}

/* Ряд иконочных действий в ячейке таблицы (см. includes/_row_actions.html).
   Кнопка удаления обязана жить в POST-форме, а форма — блочная и ломала бы
   строку; display: contents убирает её из потока. */
.row-actions {
    display: flex;
    gap: var(--space-2);
    justify-content: center;
}

.row-actions form {
    display: contents;
}

/* Под высоту .form-input — для кнопок в одну строку с полем */
.btn-icon-only--input {
    width: var(--control-height);
    height: var(--control-height);
}

/* Состояние «скопировано» (ставит shared/copy-to-clipboard.mjs на 2 сек).
   :not(:disabled) — поднять специфичность выше .btn-secondary:hover: сразу после
   клика курсор ещё на кнопке, иначе hover перекрыл бы акцент. */
.btn.is-copied:not(:disabled) {
    color: var(--accent);
    border-color: var(--accent-soft);
    background: var(--accent-soft-bg);
}

/* === Manager Card === */

.manager-card {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: start;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    background: var(--background-secondary);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    transition: all 0.2s ease;
    cursor: pointer;
}

.manager-card:hover {
    border-color: var(--primary-color);
    box-shadow: 0 4px 12px var(--black-8);
    transform: translateY(-2px);
}

.manager-card.manager-inactive {
    opacity: 0.7;
    background: var(--danger-bg-subtle);
    border-color: var(--danger-color);
    border-width: 1px;
}

.manager-card.manager-inactive .manager-name {
    color: var(--danger-color);
}

/* === Status Toggle (compact pill badge) === */

.emp-status-toggle {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-1) var(--space-3);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 99px;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: pointer;
    user-select: none;
}

.emp-status-toggle:hover {
    border-color: var(--accent-light);
    transform: scale(1.01);
}

.emp-status-toggle input[type="checkbox"] {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.emp-status-slider {
    position: relative;
    width: 30px;
    height: 18px;
    background: var(--border);
    border-radius: 999px;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: inset 0 0 0 1px var(--black-5);
    flex-shrink: 0;
}

.emp-status-slider::after {
    content: '';
    position: absolute;
    left: 2px;
    top: 2px;
    width: 14px;
    height: 14px;
    background: var(--surface);
    border-radius: 50%;
    box-shadow: 0 2px 4px var(--black-15);
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.emp-status-toggle input[type="checkbox"]:checked + .emp-status-slider {
    background: var(--accent);
    box-shadow: inset 0 0 0 1px rgba(237, 137, 54, 0.2),
                0 0 0 3px var(--accent-glow);
}

.emp-status-toggle input[type="checkbox"]:checked + .emp-status-slider::after {
    transform: translateX(12px);
}

.emp-status-toggle-label {
    font-size: var(--text-xs);
    font-weight: 600;
    letter-spacing: 0.01em;
    transition: color 0.25s ease;
    color: var(--text-secondary);
}

.emp-status-toggle input[type="checkbox"]:checked ~ .emp-status-toggle-label {
    color: var(--accent);
}

.emp-status-toggle:has(input[type="checkbox"]:disabled) {
    opacity: 0.6;
    cursor: not-allowed;
}

.emp-status-toggle:has(input[type="checkbox"]:disabled):hover {
    transform: none;
    border-color: var(--border);
}

.emp-status-toggle--neutral:hover { border-color: var(--primary-color); }
.emp-status-toggle--neutral input[type="checkbox"]:checked + .emp-status-slider {
    background: var(--primary-color);
    box-shadow: none;
}
.emp-status-toggle--neutral input[type="checkbox"]:checked ~ .emp-status-toggle-label {
    color: var(--text-brand);
}

:root[data-theme="dark"] .emp-status-toggle--neutral:hover { border-color: var(--border-strong); }
:root[data-theme="dark"] .emp-status-toggle--neutral input[type="checkbox"]:checked + .emp-status-slider {
    background: var(--accent);
}
:root[data-theme="dark"] .emp-status-toggle--neutral input[type="checkbox"]:checked ~ .emp-status-toggle-label {
    color: var(--accent);
}

/* === Color Picker (compact pill badge) === */

.emp-color-picker {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-1) var(--space-3);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 99px;
    cursor: default;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.emp-color-picker:hover {
    border-color: var(--accent-light);
    transform: scale(1.01);
}

.emp-color-picker input[type="color"] {
    width: 18px;
    height: 18px;
    min-width: 18px;
    padding: 1px;
    border: 1px solid var(--border);
    border-radius: 50%;
    cursor: pointer;
    background: var(--surface);
    box-shadow: 0 2px 4px var(--black-10);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.emp-color-picker input[type="color"]::-webkit-color-swatch-wrapper {
    padding: 0;
}

.emp-color-picker input[type="color"]::-webkit-color-swatch {
    border-radius: 50%;
    border: none;
}

.emp-color-picker input[type="color"]:hover:not(:disabled) {
    border-color: var(--primary-color);
}

.emp-color-picker input[type="color"]:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-glow);
    outline: none;
}

.emp-color-picker input[type="color"]:disabled {
    cursor: not-allowed;
    opacity: 0.7;
}

.emp-color-picker:has(input[type="color"]:disabled) {
    opacity: 0.6;
    cursor: not-allowed;
}

.emp-color-picker:has(input[type="color"]:disabled):hover {
    transform: none;
    border-color: var(--border);
}

.emp-color-picker__label {
    font-size: var(--text-xs);
    font-weight: 600;
    letter-spacing: 0.01em;
    color: var(--text-secondary);
    cursor: pointer;
    margin: 0;
}

/* === Forms === */

.form-label {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--text-primary);
}

.form-input,
.form-select,
.form-textarea {
    width: 100%;
    height: var(--control-height);
    padding: 0 var(--space-4);
    background: var(--surface);
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: var(--control-font);
    font-family: inherit;
    color: var(--text-primary);
    -webkit-appearance: none;
    appearance: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: var(--shadow-focus);
}

.form-input:hover,
.form-select:hover,
.form-textarea:hover {
    border-color: var(--primary-color);
}

.form-input::placeholder,
.form-textarea::placeholder {
    color: var(--text-secondary);
}

/* WebKit/iOS centers native time/date value by default — align like text/number */
input.form-input[type="time"],
input.form-input[type="date"],
input.form-input[type="datetime-local"] {
    text-align: start;
}

/* iOS Safari draws the value in this pseudo — input text-align doesn't reach it */
input.form-input[type="time"]::-webkit-date-and-time-value,
input.form-input[type="date"]::-webkit-date-and-time-value,
input.form-input[type="datetime-local"]::-webkit-date-and-time-value {
    text-align: start;
    margin: 0;
}

.form-select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='none' stroke='%239ca3af' stroke-width='1.5' d='M1 1.5l5 5 5-5'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right var(--space-3) center;
    background-size: 12px;
    padding-inline-end: var(--space-9);
}

.form-textarea {
    height: auto;
    min-height: calc(100px * var(--space-scale));
    padding: var(--space-2) var(--space-4);
    resize: vertical;
    field-sizing: content;
    overflow: hidden;
}



input.form-input:read-only,
.form-textarea:read-only,
.form-input:disabled,
.form-select:disabled,
.form-textarea:disabled {
    background: var(--background-secondary);
    color: var(--text-secondary);
    cursor: not-allowed;
}


input[type="file"]::file-selector-button {
    padding: var(--space-2) var(--space-4);
    margin-inline-end: var(--space-3);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text-primary);
    font-size: var(--text-sm);
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}

input[type="file"]::file-selector-button:hover {
    background: var(--background);
    border-color: var(--primary-color);
    color: var(--text-brand);
}

input[type="file"]::file-selector-button:active {
    transform: translateY(1px);
}

input[type="number"] {
    appearance: textfield;
    -moz-appearance: textfield;
}

input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-4);
}

.form-row--3col {
    grid-template-columns: 2fr 1.5fr 1.5fr;
}

.form-row--full {
    grid-template-columns: 1fr;
}

.form-row--full .form-field {
    min-width: 0;
}

.form-actions {
    display: flex;
    gap: var(--space-3);
    justify-content: flex-end;
}

/* === Toggle Switch === */

.toggle-inactive {
    display: inline-flex;
    align-items: center;
    gap: var(--space-3);
    user-select: none;
    font-size: var(--text-sm);
    color: var(--text-primary);
    cursor: pointer;
}

.toggle-inactive input[type="checkbox"] {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-inactive input[type="checkbox"] + span {
    position: relative;
    padding-inline-start: 44px;
    cursor: pointer;
    line-height: 20px;
}

.toggle-inactive input[type="checkbox"] + span::before {
    content: '';
    position: absolute;
    inset-inline-start: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 36px;
    height: 20px;
    background: var(--border);
    border-radius: 999px;
    transition: all 0.2s ease;
    box-shadow: inset 0 0 0 1px var(--black-6);
}

.toggle-inactive input[type="checkbox"] + span::after {
    content: '';
    position: absolute;
    inset-inline-start: 2px;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    background: var(--surface);
    border-radius: 50%;
    box-shadow: 0 2px 6px var(--black-15);
    transition: all 0.2s ease;
}

.toggle-inactive input[type="checkbox"]:checked + span::before {
    background: var(--primary-color);
}

:root[data-theme="dark"] .toggle-inactive input[type="checkbox"] + span::after {
    background: var(--text-brand);
}

:root[data-theme="dark"] .toggle-inactive input[type="checkbox"]:checked + span::before {
    background: var(--accent);
}

.toggle-inactive--accent input[type="checkbox"]:checked + span::before {
    background: var(--accent);
}

.toggle-inactive input[type="checkbox"]:checked + span::after {
    transform: translateY(-50%) translateX(16px);
}

[dir="rtl"] .toggle-inactive input[type="checkbox"]:checked + span::after {
    transform: translateY(-50%) translateX(-16px);
}

.toggle-inactive:hover input[type="checkbox"] + span::before {
    box-shadow: inset 0 0 0 1px var(--primary-alpha-20);
}

.toggle-inactive--switch-only input[type="checkbox"] + span {
    display: inline-block;
    width: 36px;
    height: 20px;
    padding-inline-start: 0;
    line-height: 20px;
}

@media (max-width: 768px) {
    .toggle-inactive {
        min-height: var(--tap-min);
    }

    .toggle-inactive input[type="checkbox"] + span {
        padding-inline-start: 56px;
        line-height: 28px;
    }

    .toggle-inactive--switch-only input[type="checkbox"] + span {
        width: 48px;
        height: 28px;
        padding-inline-start: 0;
    }

    .toggle-inactive input[type="checkbox"] + span::before {
        width: 48px;
        height: 28px;
    }

    .toggle-inactive input[type="checkbox"] + span::after {
        width: 24px;
        height: 24px;
    }

    .toggle-inactive input[type="checkbox"]:checked + span::after {
        transform: translateY(-50%) translateX(20px);
    }

    [dir="rtl"] .toggle-inactive input[type="checkbox"]:checked + span::after {
        transform: translateY(-50%) translateX(-20px);
    }
}

/* === Photo / Avatar === */
/* Unified circle style with solid primary placeholder */

.photo-wrapper {
    position: relative;
    flex-shrink: 0;
}

.photo-avatar {
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    border: 2px solid var(--border);
}

.photo-avatar--xs  { width: calc(24px * var(--space-scale));  height: calc(24px * var(--space-scale)); }
.photo-avatar--sm  { width: var(--space-10);  height: var(--space-10); }
.photo-avatar--md  { width: calc(64px * var(--space-scale));  height: calc(64px * var(--space-scale)); }
.photo-avatar--lg  { width: calc(120px * var(--space-scale)); height: calc(120px * var(--space-scale)); }
.photo-avatar--xl  { width: calc(200px * var(--space-scale)); height: calc(200px * var(--space-scale)); }

.photo-placeholder {
    border-radius: 50%;
    /* avatar-hue--N palette (если класс задан), иначе — primary */
    background: var(--avatar-bg, var(--primary-color));
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--avatar-fg, white);
    font-weight: 600;
    font-size: var(--text-2xl);
    flex-shrink: 0;
}

.photo-placeholder.photo-avatar--xs { font-size: var(--text-xs); }
.photo-placeholder.photo-avatar--sm { font-size: var(--text-lg); }

.photo-placeholder svg {
    width: 40%;
    height: 40%;
    color: rgba(255, 255, 255, 0.7);
    opacity: 1;
}

@media (max-width: 768px) {
    .photo-avatar--xl, .photo-placeholder.photo-avatar--xl { width: calc(150px * var(--space-scale)); height: calc(150px * var(--space-scale)); }
}

/* === Avatar hue palette (8 buckets, stable per name) ===
   Single source of truth. Apply class avatar-hue--{{ name|avatar_hue }} to any
   avatar element to colour it deterministically from its name; the element's CSS
   reads var(--avatar-bg) / var(--avatar-fg). Same name → same colour everywhere. */
.avatar-hue--1 { --avatar-bg: #fed7aa; --avatar-fg: #92400e; }
.avatar-hue--2 { --avatar-bg: #fde68a; --avatar-fg: #854d0e; }
.avatar-hue--3 { --avatar-bg: #bbf7d0; --avatar-fg: #166534; }
.avatar-hue--4 { --avatar-bg: #bae6fd; --avatar-fg: #075985; }
.avatar-hue--5 { --avatar-bg: #ddd6fe; --avatar-fg: #5b21b6; }
.avatar-hue--6 { --avatar-bg: #fbcfe8; --avatar-fg: #9d174d; }
.avatar-hue--7 { --avatar-bg: #fecaca; --avatar-fg: #991b1b; }
.avatar-hue--8 { --avatar-bg: #d9f99d; --avatar-fg: #3f6212; }

/* === Detail Grid === */

.detail-grid {
    display: grid;
    gap: var(--space-4);
}

.detail-item {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
}

.detail-label {
    font-size: var(--text-sm);
    color: var(--text-secondary);
    font-weight: 500;
}

.detail-value {
    font-weight: 600;
    color: var(--text-primary);
}

/* === Info Rows === */

.info-row {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-size: var(--text-sm);
    color: var(--text-secondary);
}

.info-icon {
    width: var(--icon-sm);
    height: var(--icon-sm);
    stroke-width: 2;
    flex-shrink: 0;
}

.info-label {
    font-size: var(--text-sm);
    font-weight: 500;
    color: var(--text-secondary);
}

.info-value {
    font-weight: 500;
    color: var(--text-primary);
}

/* === Stat Cards === */

.stats-grid {
    display: grid;
    gap: var(--space-5);
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: var(--space-5);
    display: flex;
    align-items: center;
    gap: var(--space-4);
    transition: all 0.2s ease;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.stat-icon {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.stat-value {
    font-size: var(--text-2xl);
    font-weight: 700;
    color: var(--text-brand);
}

.stat-label {
    font-size: var(--text-sm);
    color: var(--text-secondary);
}

/* Stat item (simplified variant, e.g. profile) */
.stat-item {
    text-align: center;
    padding: var(--space-5);
    background: var(--background-secondary);
    border-radius: var(--radius-sm);
    transition: transform 0.2s;
}

.stat-item:hover {
    transform: translateY(-2px);
}

.stat-item--positive {
    background: var(--alert-success-bg-light);
    border: 1px solid var(--alert-success-border);
}

.stat-item--positive .stat-value {
    color: var(--alert-success-text);
}

.stat-item--negative {
    background: var(--alert-error-bg-light);
    border: 1px solid var(--alert-error-border);
}

.stat-item--negative .stat-value {
    color: var(--danger-color);
}

.info-value--success {
    color: var(--alert-success-text);
    font-weight: 600;
}

.info-value--warning {
    color: var(--alert-warning-text);
    font-weight: 600;
}

.info-section {
    margin: var(--space-4) 0;
}

/* === Data Tables === */

.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table thead {
    background: var(--background-secondary);
}

.data-table th {
    padding: var(--space-3) var(--space-4);
    text-align: left;
    font-weight: 600;
    font-size: var(--text-sm);
    color: var(--text-secondary);
    border-bottom: 2px solid var(--border);
}

[dir="rtl"] .data-table th {
    text-align: right;
}

.data-table td {
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--border-light);
    font-size: var(--text-sm);
}

.data-table tbody tr {
    transition: background 0.2s;
}

.data-table tbody tr:hover {
    background: var(--background-secondary);
}

/* Строка-ссылка: весь ряд ведёт на свою страницу (shared/row-link.mjs) */
.data-table tbody tr[data-row-url] {
    cursor: pointer;
}

/* Centered variant (expenses, notifications) */
.data-table--centered th,
.data-table--centered td {
    text-align: center;
}

/* Primary header variant */
.data-table--primary-header thead {
    background: var(--primary-color);
}

.data-table--primary-header th {
    color: white;
    border-bottom: none;
}

/* Zebra striping */
.data-table--striped tbody tr:nth-child(even) {
    background: var(--black-4);
}

/* Stacked variant: на узком экране строка становится карточкой «подпись —
   значение», шапка скрыта. Подписи берутся из data-label ячеек — колонок 5-6,
   в телефон они не помещаются, а .data-table-container режет переполнение,
   так что хвост строки иначе не увидеть.
   Ячейка без data-label (действия) идёт отдельной строкой справа. */
@media (max-width: 768px) {
    .data-table--stacked thead {
        display: none;
    }

    .data-table--stacked,
    .data-table--stacked tbody,
    .data-table--stacked tr {
        display: block;
    }

    .data-table--stacked tbody tr {
        padding: var(--space-2) 0;
        border-bottom: 1px solid var(--border);
    }

    .data-table--stacked tbody tr:last-child {
        border-bottom: none;
    }

    /* Подпись — абсолютом в своей колонке: у ячейки может быть сколько угодно
       детей (бейдж + время, иконки), flex/grid развалил бы их по колонкам. */
    /* Двойной класс — не «на всякий случай»: page-specific правила задают
       ячейкам свой padding и грузятся позже, при равной специфичности они
       забрали бы место под подпись. */
    .data-table.data-table--stacked td {
        position: relative;
        display: block;
        padding: var(--space-1) var(--space-4);
        padding-inline-start: 38%;
        border-bottom: none;
        text-align: start;
    }

    .data-table--stacked td[data-label]::before {
        content: attr(data-label);
        position: absolute;
        inset-inline-start: var(--space-4);
        width: calc(38% - var(--space-6));
        color: var(--text-secondary);
        font-size: var(--text-xs);
        font-weight: 600;
    }

    .data-table.data-table--stacked td:not([data-label]) {
        display: flex;
        justify-content: flex-end;
        padding-inline-start: var(--space-4);
    }
}

/* Table container with card styling */
.data-table-container {
    background: var(--surface);
    border-radius: var(--radius-md);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
}

/* === Filter Components === */

.filter-group {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.filter-label {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-size: var(--text-sm);
    font-weight: 500;
    color: var(--text-primary);
}

.filter-icon {
    width: var(--icon-sm);
    height: var(--icon-sm);
    stroke-width: 2;
    flex-shrink: 0;
}

.filter-input {
    width: 100%;
    height: var(--control-height);
    padding: 0 var(--space-4);
    background: var(--surface);
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: var(--control-font);
    font-family: inherit;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.filter-input:hover {
    border-color: var(--primary-color);
}

.filter-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: var(--shadow-focus);
}

.filter-input::placeholder {
    color: var(--text-secondary);
}

.filter-select {
    width: 100%;
    min-width: 0;
    min-height: var(--control-height);
    padding-block: var(--space-3);
    padding-inline: var(--space-3) var(--space-8);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: var(--control-font);
    font-family: inherit;
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%234a5568' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    transition: border-color 0.2s, box-shadow 0.2s;
}

[dir="rtl"] .filter-select {
    background-position: left 0.75rem center;
}

.filter-select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: var(--shadow-focus);
}

.filter-actions {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

.filter-actions .toggle-inactive {
    margin-inline-end: auto;
}

/* === Badges === */

.badge {
    display: inline-flex;
    align-items: center;
    padding: var(--space-1) var(--space-3);
    border-radius: var(--radius-xs);
    font-size: var(--text-xs);
    font-weight: 600;
    line-height: 1;
}

.badge--pill {
    border-radius: var(--space-3);
}

.badge--success {
    color: var(--alert-success-icon);
    background: var(--alert-success-bg);
}

.badge--danger {
    color: var(--alert-error-icon);
    background: var(--alert-error-bg-light);
}

.badge--warning {
    color: var(--alert-warning-icon);
    background: var(--alert-warning-bg-light);
}

.badge--info {
    color: var(--alert-info-icon);
    background: var(--alert-info-bg);
}

.badge--neutral {
    background: var(--badge-bg);
    color: var(--badge-text);
}

.badge--dark {
    background: var(--badge-dark-bg);
    color: var(--badge-dark-text);
}

.badge--outlined.badge--danger {
    border: 1px solid var(--danger-border-light);
}

.badge--outlined.badge--warning {
    border: 1px solid rgba(245, 158, 11, 0.35);
}

/* Count badge (pill, primary) */
.count-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: calc(22px * var(--space-scale));
    height: calc(22px * var(--space-scale));
    padding: 0 var(--space-2);
    background: var(--primary-color);
    color: white;
    border-radius: calc(11px * var(--space-scale));
    font-size: var(--text-xs);
    font-weight: 700;
    flex-shrink: 0;
}

.count-badge--accent {
    background: var(--accent-glow);
    color: var(--accent);
    height: 18px;
    min-width: 18px;
    padding: 0 5px;
    border-radius: var(--radius-full);
    font-size: var(--text-xs);
}

/* Inactive badge (danger, lowercase) */
.inactive-badge {
    display: inline-block;
    padding: var(--space-1) var(--space-2);
    font-size: var(--text-xs);
    font-weight: 500;
    color: var(--danger-color);
    background: var(--danger-bg);
    border-radius: var(--radius-xs);
    text-transform: lowercase;
    white-space: nowrap;
    flex-shrink: 0;
}

/* === Card === */

.card {
    background: var(--surface);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    overflow: hidden;
    transition: box-shadow 0.2s;
}

.card--hoverable:hover {
    box-shadow: var(--shadow-lg);
}

/* === Chip === */

.chip {
    padding: var(--space-1) var(--space-3);
    border-radius: var(--radius-md);
    font-size: var(--text-xs);
    font-weight: 500;
}

.chip--info {
    background: linear-gradient(135deg, var(--alert-info-bg) 0%, #bfdbfe 100%);
    color: var(--info-color);
    border: 1px solid rgba(30, 64, 175, 0.1);
}

.chip--danger {
    background: var(--danger-bg);
    color: var(--danger-color);
    border: 1px solid var(--danger-color);
    opacity: 0.8;
}

/* Dark: убираем светлый стоп градиента (#bfdbfe) — на нём светло-синий info-текст
   становился нечитаемым; тёмный градиент + var(--info-color) даёт контраст */
:root[data-theme="dark"] .chip--info {
    background: linear-gradient(135deg, var(--alert-info-bg) 0%, var(--alert-info-bg-light) 100%);
    border-color: var(--info-soft-border);
}

/* === Skill Badge (square chip, used in CV row/card and vacancies) === */

.skill-badge {
    display: inline-block;
    padding: calc(var(--space-1) + 1px) var(--space-3);
    background: var(--chip-bg);
    color: var(--chip-text);
    border: 1px solid var(--chip-border);
    border-radius: var(--radius-xs);
    font-size: var(--text-xs);
    font-weight: 600;
    line-height: 1.3;
    white-space: nowrap;
}

.skill-badge[hidden] {
    display: none;
}

/* === Tooltip === */

.tooltip-fixed {
    position: fixed;
    background: var(--tooltip-bg);
    color: var(--tooltip-text);
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-sm);
    font-size: var(--text-sm);
    white-space: pre-wrap;
    text-align: center;
    max-width: 250px;
    pointer-events: none;
    z-index: 10000;
    box-shadow: 0 4px 12px var(--black-15);
    opacity: 0;
    transition: opacity var(--transition-normal);
}

.tooltip-fixed.visible {
    opacity: 1;
}

/* === Form Field === */

.form-field {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    position: relative;
    margin-bottom: var(--space-5);
}

.form-field:last-of-type {
    margin-bottom: 0;
}

.form-row .form-field {
    margin-bottom: 0;
}

/* === Form Checkbox === */

.form-checkbox-label {
    display: inline-flex;
    align-items: center;
    gap: var(--space-3);
    cursor: pointer;
    font-size: var(--text-sm);
    color: var(--text-primary);
    user-select: none;
}

.form-checkbox {
    width: var(--icon-sm);
    height: var(--icon-sm);
    min-width: var(--tap-check);
    min-height: var(--tap-check);
    cursor: pointer;
    accent-color: var(--accent);
}

.form-checkbox:disabled {
    cursor: not-allowed;
    opacity: 0.5;
}

/* === Checkbox Group === */

.checkbox-group {
    max-height: calc(200px * var(--space-scale));
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: var(--space-3);
    background: var(--background-secondary);
    margin-top: var(--space-1);
}

/* Внутри карточки собственная рамка группы дублирует рамку карточки */
.checkbox-group.checkbox-group--flush {
    border: none;
    background: transparent;
    padding: 0;
    max-height: none;
    overflow: visible;
}

.checkbox-item {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2);
    border-radius: var(--radius-xs);
    cursor: pointer;
    transition: background-color 0.2s;
    margin-bottom: var(--space-1);
}

.checkbox-item:last-child {
    margin-bottom: 0;
}

.checkbox-item:hover {
    background: var(--border-light);
}

.checkbox-item input[type="checkbox"] {
    margin: 0;
    cursor: pointer;
    width: var(--icon-sm);
    height: var(--icon-sm);
    accent-color: var(--accent);
}

.checkbox-item span {
    flex: 1;
    font-size: var(--text-sm);
    color: var(--text-primary);
    line-height: 1.4;
}

/* === Required Marker === */

.form-label.required::after {
    content: ' *';
    color: var(--danger-color);
    font-weight: 700;
}

/* === Form Error === */

.form-error {
    color: var(--danger-color);
    font-size: var(--text-xs);
    margin-top: var(--space-1);
}

.form-field-error {
    font-size: var(--text-sm);
    color: var(--danger-color);
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    background: var(--alert-error-bg-light);
    border-radius: var(--radius-sm);
    border-left: 3px solid var(--danger-color);
}

/* === Form Hint === */

.form-hint {
    font-size: var(--text-xs);
    color: var(--text-secondary);
}

/* Подсказка-предупреждение: не ошибка (сохранить можно), но стоит обратить внимание */
.form-hint--warning {
    color: var(--warning-color);
}

/* === Hidden === */

.hidden {
    display: none !important;
}

/* === Responsive === */

@media (max-width: 768px) {
    .form-row {
        grid-template-columns: 1fr;
    }

    .checkbox-group {
        max-height: calc(150px * var(--space-scale));
        padding: var(--space-2);
    }

    .checkbox-item {
        padding: var(--space-1);
        margin-bottom: calc(2px * var(--space-scale));
    }
}

@media (max-width: 576px) {
    .btn {
        padding: var(--space-2) var(--space-4);
        font-size: var(--text-sm);
    }
}

/* ===== Star Rating ===== */

.star-rating-wrapper {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

.star-rating {
    display: flex;
    align-items: center;
    gap: var(--space-1);
}

.star-item {
    position: relative;
    cursor: pointer;
    width: var(--space-8);
    height: var(--space-8);
    transition: transform 0.2s ease;
}

.star-item:hover {
    transform: scale(1.15);
}

.star-item:active {
    transform: scale(0.95);
}

.star-half-left,
.star-half-right {
    position: absolute;
    top: 0;
    width: 50%;
    height: 100%;
    z-index: 10;
}

.star-half-left {
    left: 0;
}

.star-half-right {
    right: 0;
}

.star-icon {
    width: var(--space-8);
    height: var(--space-8);
    transition: all 0.2s ease;
}

.star-icon.star-empty {
    fill: none;
    stroke: hsl(45, 93%, 47%);
    stroke-width: 1.5;
}

.star-icon.star-filled {
    fill: hsl(45, 93%, 47%);
    stroke: hsl(45, 93%, 47%);
    stroke-width: 1.5;
}

.star-icon.star-half {
    fill: url(#halfStarGradient);
    stroke: hsl(45, 93%, 47%);
    stroke-width: 1.5;
}

.star-rating--readonly {
    pointer-events: none;
}

.star-rating--readonly .star-icon {
    width: var(--space-5);
    height: var(--space-5);
}

.star-rating-value {
    font-size: var(--text-lg);
    font-weight: 600;
    color: var(--text-primary);
    min-width: var(--space-12);
    text-align: left;
}

/* ===== Company Filter (single-company switcher) ===== */
.company-filter {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    margin-bottom: var(--space-6);
}

.company-filter .form-label {
    margin-bottom: 0;
    white-space: nowrap;
}

.company-filter .form-select {
    max-width: 300px;
}

/* ============================================
   Command palette (Cmd/Ctrl+K)
   ============================================ */
.palette-overlay {
    position: fixed;
    inset: 0;
    background: rgba(var(--ink-rgb), 0.45);
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
    z-index: 10010; /* поверх modal.css (10001) */
    display: none;
}

.palette-overlay.is-open {
    display: block;
}

.palette {
    position: absolute;
    top: 12vh;
    left: 50%;
    transform: translateX(-50%);
    width: min(640px, calc(100vw - 2 * var(--space-4)));
    background: var(--surface);
    border-radius: 12px;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.28);
    overflow: hidden;
}

.palette-overlay.is-open .palette {
    animation: palette-in 0.16s ease-out;
}

@keyframes palette-in {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(-10px) scale(0.98);
    }
}

@media (prefers-reduced-motion: reduce) {
    .palette-overlay.is-open .palette {
        animation: none;
    }
}

.palette__input-wrap {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding-inline: var(--space-4);
    border-bottom: 1px solid var(--border);
}

.palette__input-wrap:focus-within {
    box-shadow: inset 0 -2px 0 var(--accent);
}

.palette__input-wrap > .palette__icon {
    color: var(--accent);
}

.palette__input {
    flex: 1;
    border: none;
    padding: var(--space-4) 0;
    font-size: var(--text-lg);
    color: var(--text-primary);
    background: transparent;
    outline: none;
}

.palette__list {
    max-height: 55vh;
    overflow-y: auto;
    padding: var(--space-2) 0;
}

.palette__section {
    padding: var(--space-2) var(--space-4) var(--space-1);
    font-size: var(--text-xs);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
}

.palette__item {
    position: relative;
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-2) var(--space-4);
    color: var(--text-primary);
    text-decoration: none;
    cursor: pointer;
}

.palette__item--active,
.palette__item:hover {
    background: var(--background);
}

.palette__item--active::before {
    content: '';
    position: absolute;
    inset-block: 6px;
    inset-inline-start: 0;
    width: 3px;
    border-start-end-radius: 2px;
    border-end-end-radius: 2px;
    background: var(--accent);
}

.palette__icon {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    color: var(--text-secondary);
}

.palette__item--active .palette__icon {
    color: var(--accent);
}

.palette__match {
    background: none;
    color: var(--accent);
    font-weight: 600;
}

.palette__item-sub {
    min-width: 0;
    font-size: var(--text-sm);
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.palette__item-company {
    margin-inline-start: auto;
    flex-shrink: 0;
    font-size: var(--text-xs);
    color: var(--text-secondary);
    opacity: 0.8;
}

.palette__status {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-4);
    color: var(--text-secondary);
}

.palette__spinner {
    width: 14px;
    height: 14px;
    border: 2px solid var(--border);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite; /* @keyframes spin — patterns.css */
}

.palette__hints {
    display: flex;
    gap: var(--space-4);
    padding: var(--space-2) var(--space-4);
    border-top: 1px solid var(--border);
    font-size: var(--text-xs);
    color: var(--text-secondary);
}

.palette__hints kbd {
    display: inline-block;
    min-width: 16px;
    padding: 0 4px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--background);
    font-family: inherit;
    text-align: center;
}

.palette-trigger__kbd {
    margin-inline-start: auto;
    padding: 1px 6px;
    border: 1px solid currentColor;
    border-radius: 4px;
    font-family: inherit;
    font-size: var(--text-xs);
    color: inherit;
    opacity: 0.7;
}

.sidebar.collapsed .palette-trigger__kbd {
    display: none;
}

/* ==========================================================================
   Impersonation bar — режим просмотра от имени другого пользователя.
   Оформление по образцу .related-banner (components/row.css), но на
   темизированной паре --accent-soft-bg / --accent-deep.
   ========================================================================== */

.impersonation-bar {
    /* fit-content + auto-margin: ширина по содержимому, плашка по центру */
    display: flex;
    width: fit-content;
    max-width: 100%;
    align-items: center;
    flex-wrap: wrap;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    margin: var(--space-2) auto;
    background: var(--accent-soft-bg);
    color: var(--accent-deep);
    border-radius: var(--radius-sm);
    font-size: var(--text-sm);
}

.impersonation-bar__icon {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

.impersonation-bar__text {
    font-weight: 500;
}

/* Форма нужна только для POST-выхода — не должна ломать flex-строку плашки */
.impersonation-bar__form {
    display: contents;
}

.impersonation-bar__reset {
    display: inline-flex;
    padding: 0;
    background: none;
    border: none;
    color: inherit;
    opacity: 0.7;
    cursor: pointer;
}

.impersonation-bar__reset svg {
    width: 16px;
    height: 16px;
}

.impersonation-bar__reset:hover {
    opacity: 1;
}
