.sanad-assistant {
    position: fixed;
    inset-inline-end: 16px;
    /* --assistant-clear is raised by JS (ai-assistant.js) to the height of a
       page's sticky/fixed bottom action bar (e.g. .sticky-form-actions on the
       student form), so this floating button never sits on top of it. */
    bottom: calc(16px + var(--assistant-clear, 0px));
    z-index: 1080;
    font-family: inherit;
    transition: bottom .2s ease;
}

/* Small, unmistakably-round icon button — deliberately smaller than every
   other button in the app (the smallest existing button is 32px, see
   .icon-action-btn) so it never reads as competing with a real action
   button, and stays out of the way of nearby content. */
/* Bootstrap removes modal-open on close, so both V1/V2 controls return
   without moving focus out of the modal or changing assistant state. */
body.modal-open .sanad-assistant {
    display: none;
}

.sanad-assistant-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: #17324d;
    color: #fff;
    font-weight: 700;
    font-size: .78rem;
    box-shadow: 0 8px 18px rgba(0,0,0,.22);
}

.sanad-assistant-toggle span {
    /* Visually hidden but still readable by screen readers / accessible name. */
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.sanad-assistant-toggle:hover {
    transform: translateY(-1px) scale(1.06);
}

.sanad-assistant-panel {
    position: absolute;
    inset-inline-end: 0;
    bottom: 40px;
    width: min(390px, calc(100vw - 32px));
    height: min(620px, calc(100vh - 120px));
    display: none;
    flex-direction: column;
    background: #fff;
    border: 1px solid rgba(0,0,0,.08);
    border-radius: 18px;
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0,0,0,.2);
}

.sanad-assistant-panel.is-open {
    display: flex;
}

.sanad-assistant-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 16px;
    border-bottom: 1px solid #eef1f4;
}

.sanad-assistant-header strong,
.sanad-assistant-header small {
    display: block;
}

.sanad-assistant-header small {
    color: #6c757d;
    margin-top: 2px;
}

.sanad-assistant-close {
    border: 0;
    background: transparent;
    font-size: 1.1rem;
}

.sanad-assistant-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: #f7f9fb;
}

.sanad-assistant-message {
    display: flex;
    margin-bottom: 12px;
}

.sanad-assistant-message.user {
    justify-content: flex-start;
}

.sanad-assistant-message.assistant {
    justify-content: flex-end;
}

.sanad-assistant-bubble {
    max-width: 86%;
    white-space: pre-wrap;
    line-height: 1.65;
    padding: 10px 13px;
    border-radius: 14px;
    background: #fff;
    border: 1px solid #e4e8ec;
}

.sanad-assistant-message.user .sanad-assistant-bubble {
    background: #17324d;
    color: #fff;
    border-color: #17324d;
}

.sanad-assistant-message.error .sanad-assistant-bubble {
    background: #fff3f3;
}

.sanad-assistant-message.loading .sanad-assistant-bubble {
    opacity: .7;
}

.sanad-assistant-suggestions {
    display: flex;
    gap: 7px;
    overflow-x: auto;
    padding: 10px 12px;
    border-top: 1px solid #eef1f4;
    background: #fff;
}

.sanad-assistant-suggestions button {
    flex: 0 0 auto;
    border: 1px solid #d9dee4;
    background: #fff;
    border-radius: 999px;
    padding: 6px 10px;
    font-size: .82rem;
}

.sanad-assistant-form {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px;
    border-top: 1px solid #eef1f4;
    background: #fff;
}

.sanad-assistant-form input {
    flex: 1;
    min-width: 0;
    border: 1px solid #d8dde3;
    border-radius: 12px;
    padding: 10px 12px;
    outline: none;
}

.sanad-assistant-form input:focus {
    border-color: #17324d;
}

.sanad-assistant-form button {
    width: 42px;
    height: 42px;
    border: 0;
    border-radius: 12px;
    background: #17324d;
    color: #fff;
}

@media (max-width: 576px) {
    .sanad-assistant {
        inset-inline-end: 12px;
        bottom: calc(12px + var(--assistant-clear, 0px));
    }

    .sanad-assistant-panel {
        position: fixed;
        inset: 12px;
        width: auto;
        height: auto;
        bottom: 12px;
        border-radius: 16px;
    }
}

/* Setup Assistant V2 */

.sanad-assistant-message.setup-message {
    justify-content: stretch;
}

.sanad-setup-card {
    width: 100%;
    background: #fff;
    border: 1px solid #e3e8ed;
    border-radius: 16px;
    padding: 14px;
    box-shadow: 0 8px 22px rgba(0,0,0,.06);
}

.sanad-setup-card-header,
.sanad-operations-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.sanad-setup-card-header small {
    display: block;
    color: #6c757d;
    margin-bottom: 2px;
}

.sanad-setup-card-header strong {
    display: block;
    font-size: 1rem;
}

.sanad-setup-score {
    font-size: 1.35rem;
    font-weight: 800;
    color: #17324d;
}

.sanad-setup-progress {
    height: 8px;
    overflow: hidden;
    background: #edf1f4;
    border-radius: 999px;
    margin-top: 10px;
}

.sanad-setup-progress-bar {
    height: 100%;
    background: #198754;
    border-radius: inherit;
    transition: width .3s ease;
}

.sanad-setup-meta {
    margin-top: 7px;
    color: #6c757d;
    font-size: .8rem;
}

.sanad-setup-checks {
    margin-top: 13px;
    border-top: 1px solid #eef1f4;
}

.sanad-setup-check {
    display: flex;
    gap: 9px;
    padding: 10px 0;
    border-bottom: 1px solid #eef1f4;
}

.sanad-setup-check-icon {
    width: 24px;
    height: 24px;
    flex: 0 0 24px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    font-size: .78rem;
    font-weight: 800;
}

.sanad-setup-check.is-done .sanad-setup-check-icon {
    background: #e8f6ef;
    color: #198754;
}

.sanad-setup-check.is-pending .sanad-setup-check-icon {
    background: #fff3cd;
    color: #8a6d00;
}

.sanad-setup-check.is-next {
    background: #f7fafc;
    margin-inline: -7px;
    padding-inline: 7px;
    border-radius: 9px;
}

.sanad-setup-check-body {
    min-width: 0;
    flex: 1;
}

.sanad-setup-check-body strong,
.sanad-setup-check-body small {
    display: block;
}

.sanad-setup-check-body strong {
    font-size: .86rem;
}

.sanad-setup-check-body small {
    color: #6c757d;
    margin-top: 2px;
    line-height: 1.45;
}

.sanad-setup-action {
    display: inline-block;
    margin-top: 5px;
    font-size: .78rem;
    font-weight: 700;
    text-decoration: none;
}

.sanad-setup-next {
    margin-top: 14px;
    padding: 12px;
    border-radius: 12px;
    background: #f2f6fa;
}

.sanad-setup-next small,
.sanad-setup-next strong,
.sanad-setup-next span {
    display: block;
}

.sanad-setup-next small {
    color: #6c757d;
}

.sanad-setup-next strong {
    margin-top: 2px;
    color: #17324d;
}

.sanad-setup-next span {
    margin-top: 4px;
    font-size: .8rem;
    color: #58636e;
}

.sanad-setup-next-action {
    display: inline-block;
    margin-top: 9px;
    padding: 7px 11px;
    border-radius: 9px;
    background: #17324d;
    color: #fff;
    text-decoration: none;
    font-size: .8rem;
    font-weight: 700;
}

.sanad-setup-next-action:hover {
    color: #fff;
}

.sanad-setup-ready {
    margin-top: 14px;
    padding: 11px;
    border-radius: 11px;
    background: #e8f6ef;
    color: #146c43;
    font-weight: 700;
    font-size: .85rem;
}

.sanad-operations-summary {
    margin-top: 14px;
    padding-top: 13px;
    border-top: 1px solid #e5e9ed;
}

.sanad-operations-header strong {
    font-size: .88rem;
}

.sanad-operations-header span {
    font-weight: 800;
    color: #17324d;
}

.sanad-operations-summary > small {
    display: block;
    margin-top: 6px;
    color: #6c757d;
    font-size: .78rem;
}

@media (max-width: 576px) {
    .sanad-setup-card {
        padding: 12px;
    }
}

/* Next Action Engine V1 */

.sanad-assistant-message.next-action-message {
    justify-content: stretch;
}

.sanad-next-action-card {
    width: 100%;
    background: #fff;
    border: 1px solid #dfe6ec;
    border-radius: 16px;
    padding: 15px;
    box-shadow: 0 8px 24px rgba(0,0,0,.07);
}

.sanad-next-action-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 10px;
}

.sanad-next-action-header small,
.sanad-next-action-header strong {
    display: block;
}

.sanad-next-action-header small {
    color: #6c757d;
    margin-bottom: 2px;
}

.sanad-next-action-header strong {
    color: #17324d;
    font-size: 1rem;
}

.sanad-next-action-score {
    flex: 0 0 auto;
    font-size: 1.15rem;
    font-weight: 800;
    color: #17324d;
}

.sanad-next-action-detail {
    margin: 0 0 12px;
    padding: 10px 11px;
    border-radius: 10px;
    background: #f7f9fb;
    color: #4f5b66;
    font-size: .84rem;
    line-height: 1.55;
}

.sanad-next-action-info {
    padding: 10px 0;
    border-top: 1px solid #eef1f4;
}

.sanad-next-action-info small,
.sanad-next-action-info span {
    display: block;
}

.sanad-next-action-info small {
    font-weight: 700;
    color: #17324d;
    margin-bottom: 3px;
}

.sanad-next-action-info span {
    font-size: .82rem;
    color: #626d78;
    line-height: 1.55;
}

.sanad-next-action-button {
    display: block;
    margin-top: 13px;
    padding: 10px 12px;
    border-radius: 10px;
    text-align: center;
    text-decoration: none;
    background: #17324d;
    color: #fff;
    font-size: .84rem;
    font-weight: 700;
}

.sanad-next-action-button:hover {
    color: #fff;
    text-decoration: none;
}

.sanad-next-action-complete {
    margin-top: 10px;
    padding: 11px;
    border-radius: 10px;
    background: #e8f6ef;
    color: #146c43;
    font-size: .84rem;
    font-weight: 700;
}

@media (max-width: 576px) {
    .sanad-next-action-card {
        padding: 12px;
    }
}

/* Issue Detection Engine V1 */

.sanad-assistant-message.issues-message {
    justify-content: stretch;
}

.sanad-issues-card {
    width: 100%;
    background: #fff;
    border: 1px solid #dfe6ec;
    border-radius: 16px;
    padding: 15px;
    box-shadow: 0 8px 24px rgba(0,0,0,.07);
}

.sanad-issues-card.is-clean {
    border-color: #cfe8dc;
}

.sanad-issues-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.sanad-issues-header small,
.sanad-issues-header strong {
    display: block;
}

.sanad-issues-header small {
    color: #6c757d;
    margin-bottom: 2px;
}

.sanad-issues-header strong {
    color: #17324d;
}

.sanad-issues-count {
    min-width: 34px;
    height: 34px;
    padding: 0 9px;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: #edf1f4;
    color: #17324d;
    font-weight: 800;
}

.sanad-issues-card.is-clean .sanad-issues-count {
    background: #e8f6ef;
    color: #146c43;
}

.sanad-issues-clean {
    display: flex;
    gap: 10px;
    margin-top: 13px;
    padding: 12px;
    background: #e8f6ef;
    border-radius: 11px;
}

.sanad-issues-clean-icon {
    width: 27px;
    height: 27px;
    flex: 0 0 27px;
    border-radius: 50%;
    background: #198754;
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
}

.sanad-issues-clean strong,
.sanad-issues-clean small {
    display: block;
}

.sanad-issues-clean strong {
    color: #146c43;
    font-size: .86rem;
}

.sanad-issues-clean small {
    margin-top: 3px;
    color: #4c6b5b;
    line-height: 1.5;
}

.sanad-issues-summary {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 12px;
}

.sanad-issue-summary-badge,
.sanad-issue-severity {
    padding: 4px 7px;
    border-radius: 999px;
    font-size: .72rem;
    font-weight: 700;
}

.sanad-issues-list {
    margin-top: 12px;
}

.sanad-issue-item {
    padding: 11px 0;
    border-top: 1px solid #eef1f4;
}

.sanad-issue-item-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 8px;
}

.sanad-issue-item-header strong {
    font-size: .85rem;
    color: #263746;
}

.sanad-issue-detail {
    margin: 5px 0 0;
    font-size: .8rem;
    color: #626d78;
    line-height: 1.5;
}

.sanad-issue-count-text {
    display: block;
    margin-top: 5px;
    color: #6c757d;
}

.sanad-issue-samples {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    margin-top: 7px;
}

.sanad-issue-samples span {
    padding: 3px 7px;
    background: #f1f4f6;
    border-radius: 999px;
    font-size: .72rem;
}

.sanad-issue-action {
    display: inline-block;
    margin-top: 8px;
    font-size: .78rem;
    font-weight: 700;
    text-decoration: none;
}

.severity-critical {
    background: #fde8e8;
    color: #a61b1b;
}

.severity-high {
    background: #fff0e1;
    color: #9a4d00;
}

.severity-warning {
    background: #fff8d9;
    color: #806500;
}

.severity-info {
    background: #e8f1fb;
    color: #245b8a;
}

@media (max-width: 576px) {
    .sanad-issues-card {
        padding: 12px;
    }
}

/* Assistant layout refinement */

.sanad-assistant,
.sanad-assistant-panel,
.sanad-assistant-messages,
.sanad-assistant-message,
.sanad-assistant-bubble,
.sanad-setup-card,
.sanad-next-action-card,
.sanad-issues-card {
    box-sizing: border-box;
}

.sanad-assistant-panel {
    overflow-x: hidden;
}

.sanad-assistant-messages {
    overflow-x: hidden;
}

.sanad-assistant-message {
    width: 100%;
    max-width: 100%;
}

.sanad-assistant-message.setup-message,
.sanad-assistant-message.next-action-message,
.sanad-assistant-message.issues-message {
    padding-inline: 0;
}

.sanad-setup-card,
.sanad-next-action-card,
.sanad-issues-card {
    width: 100%;
    max-width: 100%;
    min-width: 0;
}

.sanad-issues-header,
.sanad-issue-item-header,
.sanad-next-action-header,
.sanad-setup-card-header {
    min-width: 0;
}

.sanad-issues-header > div,
.sanad-issue-item-header > div,
.sanad-next-action-header > div,
.sanad-setup-card-header > div {
    min-width: 0;
}

.sanad-issues-header strong,
.sanad-issues-clean strong,
.sanad-issues-clean small,
.sanad-issue-detail,
.sanad-next-action-detail,
.sanad-setup-check-body {
    overflow-wrap: anywhere;
    word-break: normal;
}

.sanad-assistant-suggestions {
    max-width: 100%;
    overflow-x: auto;
    scrollbar-width: thin;
}

@media (max-width: 576px) {
    .sanad-assistant-messages {
        padding-inline: 12px;
    }

    .sanad-issues-card,
    .sanad-next-action-card,
    .sanad-setup-card {
        width: 100%;
        max-width: 100%;
    }
}

/* Operational Monitoring Engine V1 */

.sanad-assistant-message.operations-message {
    justify-content: stretch;
}

.sanad-operations-card {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
    background: #fff;
    border: 1px solid #dfe6ec;
    border-radius: 16px;
    padding: 15px;
    box-shadow: 0 8px 24px rgba(0,0,0,.07);
}

.sanad-operations-card-header {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}

.sanad-operations-card-header small,
.sanad-operations-card-header strong {
    display: block;
}

.sanad-operations-card-header small {
    color: #6c757d;
    margin-bottom: 2px;
}

.sanad-operations-card-header strong {
    color: #17324d;
}

.sanad-operations-metrics {
    display: grid;
    grid-template-columns: repeat(5, minmax(0,1fr));
    gap: 6px;
    margin-bottom: 12px;
}

.sanad-operations-metric {
    min-width: 0;
    text-align: center;
    padding: 8px 4px;
    background: #f7f9fb;
    border-radius: 9px;
}

.sanad-operations-metric strong,
.sanad-operations-metric small {
    display: block;
}

.sanad-operations-metric strong {
    color: #17324d;
    font-size: 1rem;
}

.sanad-operations-metric small {
    color: #6c757d;
    font-size: .68rem;
    margin-top: 2px;
}

.sanad-operations-state {
    padding: 11px;
    border-radius: 11px;
    margin-top: 8px;
}

.sanad-operations-state strong,
.sanad-operations-state small {
    display: block;
}

.sanad-operations-state small {
    margin-top: 3px;
    line-height: 1.5;
}

.sanad-operations-state.is-not-started {
    background: #e8f1fb;
    color: #245b8a;
}

.sanad-operations-state.is-ok {
    background: #e8f6ef;
    color: #146c43;
}

.sanad-operations-items {
    margin-top: 12px;
}

.sanad-operation-item {
    padding: 11px 0;
    border-top: 1px solid #eef1f4;
    background: transparent;
}

.sanad-operation-item-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 8px;
}

.sanad-operation-item-header strong {
    font-size: .85rem;
    color: #263746;
}

.sanad-operation-severity {
    flex: 0 0 auto;
    padding: 4px 7px;
    border-radius: 999px;
    font-size: .7rem;
    font-weight: 700;
}

.sanad-operation-detail {
    margin: 5px 0 0;
    font-size: .8rem;
    color: #626d78;
    line-height: 1.5;
}

.sanad-operation-samples {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    margin-top: 7px;
}

.sanad-operation-samples span {
    padding: 3px 7px;
    background: #f1f4f6;
    border-radius: 999px;
    font-size: .72rem;
}

.sanad-operation-action {
    display: inline-block;
    margin-top: 8px;
    font-size: .78rem;
    font-weight: 700;
    text-decoration: none;
}

.sanad-operation-classes {
    margin-top: 12px;
    padding: 10px;
    background: #f7f9fb;
    border-radius: 10px;
    font-size: .8rem;
}

.sanad-operation-classes strong {
    display: block;
    margin-bottom: 5px;
}

.sanad-operations-unavailable {
    padding: 11px;
    border-radius: 10px;
    background: #fff3cd;
    color: #806500;
    line-height: 1.5;
}

@media (max-width: 576px) {
    .sanad-operations-card {
        padding: 12px;
    }

    .sanad-operations-metrics {
        grid-template-columns: repeat(3, minmax(0,1fr));
    }
}

/* ==========================================================
   Class Priority Card V1
   ========================================================== */

.sanad-class-priority {
    margin-top: 14px;
    padding: 14px;
    border: 1px solid var(--border-color, #e5e7eb);
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.72);
}

.sanad-class-priority.severity-high {
    border-inline-start: 4px solid #dc2626;
}

.sanad-class-priority.severity-warning {
    border-inline-start: 4px solid #d97706;
}

.sanad-class-priority.severity-info {
    border-inline-start: 4px solid #2563eb;
}

.sanad-class-priority-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
}

.sanad-class-priority-header > div {
    min-width: 0;
}

.sanad-class-priority-eyebrow {
    display: block;
    margin-bottom: 3px;
    opacity: 0.7;
}

.sanad-class-priority-name {
    display: block;
    font-size: 1rem;
    overflow-wrap: anywhere;
}

.sanad-class-priority-reason {
    margin: 10px 0 0;
    line-height: 1.7;
    font-size: 0.9rem;
}

.sanad-class-priority-stats {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 7px;
    margin-top: 12px;
}

.sanad-class-priority-stat {
    padding: 8px 5px;
    text-align: center;
    border-radius: 10px;
    background: rgba(0, 0, 0, 0.035);
}

.sanad-class-priority-stat strong,
.sanad-class-priority-stat small {
    display: block;
}

.sanad-class-priority-stat small {
    margin-top: 2px;
    font-size: 0.7rem;
    opacity: 0.72;
}

.sanad-class-priority-teachers {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin-top: 11px;
}

.sanad-class-priority-teachers small {
    opacity: 0.7;
}

.sanad-class-priority-action {
    display: inline-flex;
    margin-top: 12px;
}

.sanad-operation-class-line {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 6px 0;
}

@media (max-width: 520px) {
    .sanad-class-priority-stats {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .sanad-class-priority-header {
        flex-direction: column;
    }
}
