:root {
    --teams-bg-start: #f3f6fd;
    --teams-bg-end: #eef4ff;
    --teams-surface: #ffffff;
    --teams-outline: #d7def0;
    --teams-text: #1b1f3b;
    --teams-muted: #5f6788;
    --teams-primary: #3d57d8;
}

body.teams-shell-bg {
    background: radial-gradient(circle at 0% 0%, #ffffff 0%, var(--teams-bg-start) 45%, var(--teams-bg-end) 100%);
    color: var(--teams-text);
    font-family: "Segoe UI", "Segoe UI Variable", Tahoma, Geneva, Verdana, sans-serif;
}

.teams-topbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1100;
    background: rgba(255, 255, 255, 0.78);
    border-bottom: 1px solid rgba(215, 222, 240, 0.8);
    backdrop-filter: saturate(160%) blur(8px);
}

.teams-topbar-inner {
    min-height: 78px;
    display: flex;
    align-items: center;
    gap: 1rem;
}

.teams-brand-logo {
    height: 3.3rem;
    width: auto;
}

.teams-title-wrap {
    display: flex;
    align-items: baseline;
    gap: 0.4rem;
    flex: 1;
    min-width: 0;
}

.teams-home-link {
    color: #1f2d5c;
    text-decoration: none;
    font-weight: 600;
}

.teams-home-link:hover {
    color: var(--teams-primary);
}

.teams-page-title {
    color: #293768;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.teams-sticky-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    margin-left: auto;
    min-width: 0;
}

.js-sticky-action-source:not([data-sticky-mounted]) {
    /* Keep visible by default. Hidden only after JS mounts (data-sticky-mounted set). */
}

.teams-sticky-actions .ui-action-row {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    flex-wrap: wrap;
    margin: 0;
}

.teams-sticky-actions .js-sticky-action-source {
    display: flex;
}

.teams-sticky-actions .ui-btn {
    white-space: nowrap;
}

.teams-menu-toggle {
    display: none;
    border: 1px solid var(--teams-outline);
    background: #fff;
    color: var(--teams-text);
    border-radius: 10px;
    padding: 0.35rem 0.55rem;
}

.teams-user-menu {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.teams-user-link {
    color: #253666;
    text-decoration: none;
    font-weight: 600;
}

.teams-user-link:hover {
    color: var(--teams-primary);
}

.teams-user-description {
    color: var(--teams-muted);
}

.teams-main {
    padding-top: 88px;
}

.teams-layout-row {
    align-items: stretch;
}

.teams-sidebar-col {
    margin-top: 0.9rem;
    align-self: flex-start;
    position: sticky;
    top: 88px;
    overflow: visible;
}

.teams-sidebar {
    background: var(--teams-surface);
    border: 1px solid var(--teams-outline);
    border-radius: 12px;
    box-shadow: 0 10px 28px rgba(57, 69, 120, 0.08);
    padding: 0.75rem;
    max-height: calc(100vh - 88px);
    overflow-y: auto;
}

.teams-sidebar-toggle {
    position: absolute;
    right: -12px;
    top: 50%;
    transform: translateY(-50%);
    width: 24px;
    height: 52px;
    border: 1px solid var(--teams-outline);
    border-left: none;
    border-radius: 0 10px 10px 0;
    background: #ffffff;
    color: #253666;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 6px 16px rgba(57, 69, 120, 0.12);
    z-index: 3;
}

.teams-sidebar-toggle:hover {
    color: var(--teams-primary);
    background: #f4f7ff;
}

.teams-layout-row.sidebar-collapsed .teams-sidebar {
    display: none;
}

.teams-layout-row.sidebar-collapsed .teams-sidebar-col {
    flex: 0 0 24px;
    max-width: 24px;
    min-height: 52px;
    padding-left: 0;
    padding-right: 0;
    overflow: visible;
}

.teams-layout-row.sidebar-collapsed .teams-sidebar-toggle {
    right: 0;
    top: 0;
    transform: none;
}

.teams-layout-row.sidebar-collapsed .teams-content-col {
    flex: 1 1 calc(100% - 24px);
    max-width: calc(100% - 24px);
}

.teams-sidebar-list,
.teams-sidebar-sublist {
    list-style: none;
    margin: 0;
    padding: 0;
}

.teams-sidebar-list > li + li {
    margin-top: 0.35rem;
}

.teams-sidebar-link,
.teams-sidebar-sublink {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    text-decoration: none;
    border-radius: 8px;
    padding: 0.45rem 0.6rem;
    color: #253666;
    font-weight: 600;
    border: 1px solid transparent;
}

.teams-sidebar-link:hover,
.teams-sidebar-sublink:hover {
    color: var(--teams-primary);
    background: #eef3ff;
    border-color: #d8e1fb;
}

.teams-sidebar-sublist {
    margin-top: 0.2rem;
    margin-left: 0.5rem;
    border-left: 2px solid #e1e8fa;
    padding-left: 0.5rem;
}

.teams-sidebar-sublink {
    font-weight: 500;
    font-size: 0.93rem;
}

.teams-sidebar-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.1rem;
    flex: 0 0 1.1rem;
    color: currentColor;
}

.teams-sidebar-action-form {
    margin: 0;
}

.teams-sidebar-action {
    background: transparent;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    text-align: left;
    cursor: pointer;
}

.teams-sidebar-action-danger {
    color: #a12533;
}

.teams-content-col {
    min-width: 0;
}

.ui-input,
.ui-select {
    border: 1px solid #bec9e8;
    border-radius: 10px;
    background: #fff;
    color: #1a2348;
    box-shadow: inset 0 1px 2px rgba(40, 53, 97, 0.05);
}

.ui-input:focus,
.ui-select:focus {
    border-color: #6f8cf8;
    box-shadow: 0 0 0 3px rgba(96, 130, 255, 0.2);
}

.ui-textarea {
    min-height: 110px;
}

.ui-checkbox {
    border-color: #7f8db9;
}

.ui-btn {
    border-radius: 10px;
    padding: 0.45rem 0.85rem;
    font-weight: 600;
}

.ui-btn-primary {
    background: linear-gradient(180deg, #4a67ea 0%, #3b56d8 100%);
    border-color: #354fc8;
}

.ui-disclosure {
    background: var(--teams-surface);
    border: 1px solid var(--teams-outline);
    border-radius: 12px;
    box-shadow: 0 10px 28px rgba(57, 69, 120, 0.08);
    margin-bottom: 0.75rem;
}

.ui-disclosure-summary {
    list-style: none;
    cursor: pointer;
    padding: 0.9rem 1rem;
    color: var(--teams-text);
}

.ui-disclosure-summary::-webkit-details-marker {
    display: none;
}

.ui-disclosure-summary h3 {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.ui-panel {
    padding: 0 1rem 1rem;
    border-top: 1px solid #e8edfa;
}

.ui-field-container {
    margin-bottom: 0.35rem;
}

.ui-field-row {
    background: transparent;
}

.ui-field-cell {
    margin-bottom: 0.4rem;
}

.ui-field-label {
    color: #2e3e74;
    font-weight: 600;
}

.ui-table-container {
    border: 1px solid #d4ddf3;
    border-radius: 12px;
    background: #ffffff;
    padding: 0.5rem;
}

.ui-table-controls {
    background: #f8faff;
    border: 1px solid #e4eaf9;
    border-radius: 10px;
    padding: 0.4rem;
}

.ui-table {
    margin-bottom: 0;
}

.ui-table-head th {
    background: linear-gradient(180deg, #22315f 0%, #1b2549 100%);
}

.alert {
    border: 1px solid #d7def0;
    border-radius: 10px;
}

.ui-flash-stack {
    display: grid;
    gap: 0.45rem;
    margin-top: 0.6rem;
}

.ui-flash {
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-radius: 10px;
    padding: 0.65rem 0.8rem;
    border: 1px solid var(--teams-outline);
    background: #fff;
    color: #162044;
}

.ui-flash-success {
    background: #e5f5e4;
    border-color: #afd8ac;
}

.ui-flash-warning {
    background: #fff3dc;
    border-color: #ebce8e;
}

.ui-flash-error {
    background: #fbe4e8;
    border-color: #e5b3bd;
}

.ui-flash-info {
    background: #e8f0ff;
    border-color: #b7caef;
}

.ui-flash-close {
    border: none;
    background: transparent;
    color: #1e2f61;
    padding: 0.1rem;
    line-height: 1;
}

.text-h2-color {
    color: var(--teams-muted);
}

@media (max-width: 900px) {
    .teams-topbar-inner {
        flex-wrap: wrap;
        min-height: 72px;
    }

    .teams-sticky-actions {
        order: 4;
        width: 100%;
        justify-content: flex-start;
        margin-left: 0;
        padding-top: 0.3rem;
    }

    .teams-sidebar {
        position: static;
        margin-bottom: 0.7rem;
    }

    .teams-sidebar-toggle {
        display: none;
    }

    .teams-menu-toggle {
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .teams-user-menu {
        position: absolute;
        top: calc(100% + 8px);
        right: 12px;
        min-width: 220px;
        background: #ffffff;
        border: 1px solid var(--teams-outline);
        border-radius: 12px;
        box-shadow: 0 14px 30px rgba(36, 46, 86, 0.18);
        padding: 0.8rem;
        display: none;
        flex-direction: column;
        align-items: flex-start;
        gap: 0.45rem;
    }

    .teams-user-menu.is-open {
        display: flex;
    }
}

/* =====================================================================
   TomSelect – Teams-palette override (replaces Bootstrap5 theme bleed)
   ===================================================================== */
.ts-wrapper.single .ts-control,
.ts-wrapper.multi .ts-control {
    background: var(--teams-surface);
    border: 1px solid var(--teams-outline);
    border-radius: 6px;
    padding: 0.375rem 0.75rem;
    font-size: 0.875rem;
    color: var(--teams-text);
    box-shadow: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.ts-wrapper.single .ts-control:focus-within,
.ts-wrapper.multi .ts-control:focus-within {
    border-color: var(--teams-primary);
    box-shadow: 0 0 0 2px rgba(98, 100, 167, 0.25);
    outline: none;
}

.ts-dropdown {
    background: var(--teams-surface);
    border: 1px solid var(--teams-outline);
    border-radius: 6px;
    box-shadow: 0 4px 16px rgba(36, 46, 86, 0.12);
    font-size: 0.875rem;
    color: var(--teams-text);
}

.ts-dropdown .option {
    padding: 0.4rem 0.75rem;
    cursor: pointer;
    transition: background 0.1s;
}

.ts-dropdown .option:hover,
.ts-dropdown .option.active {
    background: var(--teams-bg-start);
    color: var(--teams-primary);
}

.ts-dropdown .option.selected {
    background: var(--teams-primary);
    color: #fff;
}

.ts-wrapper .ts-control .item {
    background: var(--teams-bg-start);
    border: 1px solid var(--teams-outline);
    border-radius: 4px;
    padding: 0 0.45rem;
    color: var(--teams-text);
}

.ts-wrapper .ts-control input {
    color: var(--teams-text);
}

.ts-wrapper .ts-control input::placeholder {
    color: #8b8fa8;
}

.ts-wrapper .clear-button,
.ts-wrapper .dropdown-input {
    color: var(--teams-text);
}
