/* Training Matrix — compact split-pane layout */
body.tm-dashboard {
    background: var(--workspace-bg, #f1f5f9);
}

body.tm-dashboard .app-main {
    min-height: 0;
    height: 100dvh;
    max-height: 100dvh;
    overflow: hidden;
}

body.tm-dashboard .header-bar--rich {
    min-height: 52px;
    padding: 6px 14px;
}

body.tm-dashboard .main-content--tm {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: 6px 10px 8px;
    gap: 0;
}

.tm-shell {
    --tm-emp-width: 228px;
    --tm-row-h: 36px;
    --tm-head-h1: 26px;
    --tm-head-h2: 22px;
    --tm-head-total: calc(var(--tm-head-h1) + var(--tm-head-h2));
    --tm-cert-col-w: 72px;

    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
    direction: ltr;
    text-align: left;
}

/* —— Top bar —— */
.tm-top {
    flex-shrink: 0;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 4px 12px;
}
.tm-top__title {
    margin: 0;
    font-size: 1rem;
    font-weight: 800;
    color: #0f172a;
    letter-spacing: -0.02em;
    line-height: 1.2;
}
.tm-top__meta {
    display: none;
}
.tm-top__saved {
    font-size: 10px;
    color: #64748b;
    white-space: nowrap;
}

.tm-bar {
    flex-shrink: 0;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    padding: 6px 8px;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}
.tm-bar__left {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    flex: 1;
    min-width: 160px;
}
.tm-bar__right {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    align-items: center;
}
.tm-field {
    display: inline-flex;
    align-items: center;
    gap: 5px;
}
.tm-field label {
    font-size: 10px;
    font-weight: 700;
    color: #475569;
    white-space: nowrap;
}
.tm-field select {
    padding: 4px 7px;
    border-radius: 6px;
    border: 1px solid #cbd5e1;
    font-size: 11px;
    min-width: 110px;
}
.tm-search {
    position: relative;
    flex: 1;
    min-width: 120px;
    max-width: 220px;
}
.tm-search i {
    position: absolute;
    left: 7px;
    top: 50%;
    transform: translateY(-50%);
    color: #94a3b8;
    font-size: 11px;
    pointer-events: none;
}
.tm-search input {
    width: 100%;
    box-sizing: border-box;
    padding: 5px 8px 5px 24px;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    font-size: 11px;
}
.tm-search input:focus {
    outline: none;
    border-color: #6366f1;
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.12);
}

.tm-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 5px 8px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 600;
    border: 1px solid #cbd5e1;
    background: #fff;
    color: #334155;
    cursor: pointer;
    white-space: nowrap;
}
.tm-btn i { font-size: 10px; }
.tm-btn:hover { background: #f8fafc; border-color: #94a3b8; }
.tm-btn--primary {
    background: linear-gradient(180deg, #4f46e5 0%, #4338ca 100%);
    border-color: #4338ca;
    color: #fff;
}
.tm-btn--primary:hover { background: #4338ca; }
.tm-btn--icon {
    padding: 5px 7px;
    min-width: 28px;
    justify-content: center;
}

.tm-stats-row {
    flex-shrink: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    align-items: center;
}
.tm-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 7px;
    border-radius: 999px;
    font-size: 10px;
    font-weight: 600;
    border: 1px solid #e2e8f0;
    background: #fff;
    color: #475569;
}
.tm-chip b { font-weight: 800; color: #0f172a; }
.tm-chip--ok { background: #ecfdf5; border-color: #a7f3d0; color: #047857; }
.tm-chip--bad { background: #fef2f2; border-color: #fecaca; color: #b91c1c; }
.tm-chip--muted { background: #f8fafc; border-color: #e2e8f0; color: #64748b; }

.tm-orphan-note {
    flex-shrink: 0;
    margin: 0;
    font-size: 10px;
    color: #64748b;
}

/* —— Matrix card —— */
.tm-card {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.05);
    overflow: hidden;
}
.tm-card__head {
    flex-shrink: 0;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 4px 8px;
    padding: 4px 8px;
    border-bottom: 1px solid #e2e8f0;
    background: #f8fafc;
}
.tm-card__head-title {
    font-size: 11px;
    font-weight: 800;
    color: #0f172a;
}
.tm-card__head-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-wrap: wrap;
}
.tm-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    font-size: 9px;
    color: #64748b;
}
.tm-legend span {
    display: inline-flex;
    align-items: center;
    gap: 3px;
}
.tm-legend i {
    width: 8px;
    height: 8px;
    border-radius: 2px;
    display: inline-block;
}
.tm-legend .lg-valid { background: #10b981; }
.tm-legend .lg-expired { background: #ef4444; }
.tm-legend .lg-empty { background: #cbd5e1; }
.tm-legend .lg-na { background: #f1f5f9; border: 1px solid #cbd5e1; }

.tm-card__body {
    flex: 1;
    min-height: 0;
    position: relative;
    display: flex;
    flex-direction: column;
}

.tm-loading {
    position: absolute;
    inset: 0;
    z-index: 20;
    display: none;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: rgba(255, 255, 255, 0.88);
    font-size: 11px;
    font-weight: 600;
    color: #475569;
}
.tm-loading.is-on { display: flex; }

/* Split frame */
.tm-split {
    flex: 1;
    min-height: 0;
    display: flex;
    overflow: hidden;
}

.tm-split__emp {
    flex-shrink: 0;
    width: var(--tm-emp-width);
    min-width: var(--tm-emp-width);
    overflow-y: auto;
    overflow-x: hidden;
    border-right: 2px solid #cbd5e1;
    background: #fafbfc;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
}
.tm-split__certs {
    flex: 1;
    min-width: 0;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    scrollbar-color: #94a3b8 #f1f5f9;
}
.tm-split__certs::-webkit-scrollbar,
.tm-split__emp::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}
.tm-split__certs::-webkit-scrollbar-thumb,
.tm-split__emp::-webkit-scrollbar-thumb {
    background: #94a3b8;
    border-radius: 4px;
    border: 1px solid #f1f5f9;
}
.tm-split__certs::-webkit-scrollbar-track,
.tm-split__emp::-webkit-scrollbar-track {
    background: #f1f5f9;
}

/* Tables — compact */
.tm-table {
    border-collapse: separate;
    border-spacing: 0;
    width: 100%;
    background: #fff;
    table-layout: fixed;
}
.tm-table--certs {
    width: max-content;
    min-width: 100%;
    table-layout: auto;
}
.tm-table th,
.tm-table td {
    border-bottom: 1px solid #e2e8f0;
    border-right: 1px solid #e2e8f0;
    padding: 0;
    vertical-align: middle;
    box-sizing: border-box;
}
.tm-table thead th {
    position: sticky;
    z-index: 3;
    background: #f1f5f9;
    font-size: 9px;
    font-weight: 700;
    color: #0f172a;
    padding: 3px 4px;
    text-align: center;
    white-space: nowrap;
    line-height: 1.2;
}
.tm-table--emp thead th {
    top: 0;
    background: #eef2ff;
    color: #1e1b4b;
}
.tm-table--emp thead th[rowspan="2"] {
    min-height: var(--tm-head-total);
    height: var(--tm-head-total);
    vertical-align: middle;
}
.tm-table--emp thead tr.tm-h2--ghost {
    height: 0;
    line-height: 0;
}
.tm-table--certs thead tr.tm-h1 th { top: 0; }
.tm-table--certs thead tr.tm-h2 th {
    top: var(--tm-head-h1);
    box-shadow: 0 1px 0 #e2e8f0;
}
.tm-table--certs thead tr.tm-h1 th {
    min-height: var(--tm-head-h1);
    height: var(--tm-head-h1);
    background: #e0e7ff;
    color: #312e81;
    font-size: 10px;
    padding: 2px 3px;
}
.tm-table--certs thead tr.tm-h2 th {
    min-height: var(--tm-head-h2);
    height: var(--tm-head-h2);
}
.tm-table--certs .th-start {
    background: #dcfce7;
    color: #14532d;
    width: var(--tm-cert-col-w);
    min-width: var(--tm-cert-col-w);
    max-width: var(--tm-cert-col-w);
}
.tm-table--certs .th-end {
    background: #fee2e2;
    color: #7f1d1d;
    width: var(--tm-cert-col-w);
    min-width: var(--tm-cert-col-w);
    max-width: var(--tm-cert-col-w);
}

.tm-table tbody tr {
    height: var(--tm-row-h);
}
.tm-table tbody tr:hover td {
    filter: brightness(0.98);
}
.tm-td-num {
    width: 26px;
    min-width: 26px;
    max-width: 26px;
    text-align: center;
    font-size: 9px;
    font-weight: 700;
    color: #64748b;
    background: #f8fafc;
    padding: 0 2px;
}
.tm-td-name {
    font-size: 10px;
    font-weight: 600;
    color: #0f172a;
    padding: 3px 5px;
    width: 96px;
    max-width: 96px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    background: #fff;
}
.tm-td-pos {
    font-size: 9px;
    color: #64748b;
    padding: 3px 5px;
    width: 88px;
    max-width: 88px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    background: #fff;
}

.tm-cert-head-input {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    box-sizing: border-box;
    border: 1px solid #a5b4fc;
    border-radius: 4px;
    padding: 2px 4px;
    font-weight: 700;
    font-size: 9px;
    text-align: center;
    background: #fff;
    color: #312e81;
}

.tm-cell-date {
    width: 100%;
    min-width: 0;
    border: none;
    padding: 2px 3px;
    font-size: 10px;
    line-height: 1.2;
    box-sizing: border-box;
    background: transparent;
    color: inherit;
}
.tm-td-cert {
    padding: 0;
    width: var(--tm-cert-col-w);
    min-width: var(--tm-cert-col-w);
    max-width: var(--tm-cert-col-w);
}
.tm-td-cert.tm-state-valid {
    background: #ecfdf5;
    color: #065f46;
    box-shadow: inset 2px 0 0 #10b981;
}
.tm-td-cert.tm-state-expired {
    background: #fef2f2;
    color: #991b1b;
    box-shadow: inset 2px 0 0 #ef4444;
}
.tm-td-cert.tm-state-empty {
    background: #f8fafc;
    color: #475569;
    box-shadow: inset 2px 0 0 #cbd5e1;
}
.tm-td-cert.tm-state-na {
    background: #f1f5f9;
    color: #94a3b8;
    text-align: center;
}
.tm-cert-stack {
    display: flex;
    flex-direction: column;
    gap: 1px;
    padding: 2px;
    justify-content: center;
    min-height: calc(var(--tm-row-h) - 2px);
}
.tm-btn-na {
    font-size: 8px;
    padding: 1px 4px;
    border-radius: 3px;
    border: 1px solid #cbd5e1;
    background: #fff;
    color: #64748b;
    cursor: pointer;
    align-self: center;
    line-height: 1.2;
}
.tm-btn-na:hover { background: #f1f5f9; }
.tm-na-cell {
    cursor: pointer;
    width: calc(var(--tm-cert-col-w) * 2);
    min-width: calc(var(--tm-cert-col-w) * 2);
    max-width: calc(var(--tm-cert-col-w) * 2);
    font-size: 9px;
}
.tm-na-cell:hover { background: #e2e8f0 !important; }
.tm-readonly .tm-btn-na,
.tm-readonly .tm-na-cell { cursor: default; }
.tm-readonly .tm-cell-date { cursor: default; }

.tm-empty {
    padding: 24px 12px;
    text-align: center;
    color: #64748b;
    font-size: 12px;
}

/* Modal */
.tm-modal {
    position: fixed;
    inset: 0;
    z-index: 2500;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(15, 23, 42, 0.5);
    padding: 12px;
}
.tm-modal.is-open { display: flex; }
.tm-modal__panel {
    background: #fff;
    border-radius: 10px;
    width: 100%;
    max-width: 440px;
    max-height: 90vh;
    overflow: auto;
    box-shadow: 0 20px 40px rgba(15, 23, 42, 0.2);
}
.tm-modal__head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    border-bottom: 1px solid #e2e8f0;
    font-size: 13px;
    font-weight: 800;
}
.tm-modal__body { padding: 10px 12px 14px; }
.tm-modal__hint {
    font-size: 11px;
    color: #64748b;
    margin: 0 0 10px;
    line-height: 1.4;
}
.tm-modal__row {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-bottom: 6px;
}
.tm-modal__row span {
    flex: 1;
    font-size: 12px;
    font-weight: 600;
}

@media (max-width: 768px) {
    body.tm-dashboard .main-content--tm {
        overflow: auto;
        padding: 8px;
    }
    .tm-shell {
        min-height: 70vh;
        --tm-emp-width: 100%;
        --tm-cert-col-w: 68px;
    }
    .tm-split {
        flex-direction: column;
        min-height: 360px;
    }
    .tm-split__emp {
        width: 100%;
        min-width: 0;
        max-height: 120px;
        border-right: none;
        border-bottom: 2px solid #cbd5e1;
    }
    .tm-split__certs {
        min-height: 240px;
    }
}

@media (min-width: 1400px) {
    .tm-shell {
        --tm-emp-width: 248px;
        --tm-cert-col-w: 76px;
    }
    .tm-td-name { width: 104px; max-width: 104px; }
    .tm-td-pos { width: 96px; max-width: 96px; }
}
