// Thinkera Academy: the student app. Mobile first, right-to-left first; logical properties only (inline-start/end),
// so the same rules hold in Arabic and English. Every tap target is at least 44px, every form field 16px text.

$tk-app-bg: #F3F6FB;
$tk-line: #E3E9F2;
$tk-line-strong: #C9D3E3;
$tk-tint: #E9EFF9;
$tk-good-bg: #E9F6EF;
$tk-bad-bg: #FBECEA;
$tk-shadow: 0 1px 2px rgba(15, 27, 45, .04), 0 8px 24px rgba(15, 27, 45, .05);

// ---------------------------------------------------------------- the frame
body.tk-app {
    background: $tk-app-bg;
    color: #1F2A3C;
    @include media-breakpoint-down(md) { padding-bottom: 68px; }   // room for the tab bar

    #page-wrapper { min-height: 100vh; display: flex; flex-direction: column; }
    #page { margin: 0 !important; padding: 0 !important; flex: 1 0 auto; display: flex; flex-direction: column; }
    // Moodle chrome that must never show in the app
    #page-header, .secondary-navigation, .activity-navigation, nav.breadcrumb, .breadcrumb,
    #page-footer, .btn-footer-popover, .drawer-toggles, .usermenu, .tool_dataprivacy, .helplink-mobileapp { display: none !important; }
}

.tk-appbar {
    position: sticky; top: 0; z-index: 1030;
    background: rgba(255, 255, 255, .94);
    backdrop-filter: saturate(180%) blur(12px);
    border-bottom: 1px solid $tk-line;
}
.tk-appbar-inner {
    max-width: 1180px; height: 64px; margin: 0 auto; padding: 0 1rem;
    display: flex; align-items: center; gap: 1.25rem;
}
.tk-appbar-brand { display: flex; align-items: center; flex: none; min-height: 44px; img { height: 32px; width: auto; } }
.tk-appbar-nav {
    display: none;
    @include media-breakpoint-up(md) { display: block; }
    ul { display: flex; gap: .25rem; list-style: none; margin: 0; padding: 0; }
    a {
        display: block; padding: .5rem 1rem; border-radius: 999px;
        color: $tk-ink; font-weight: 600; text-decoration: none;
        &:hover { background: $tk-app-bg; }
        &.is-active { background: $tk-tint; color: $tk-royal; }
    }
}
.tk-appbar-tools { margin-inline-start: auto; display: flex; align-items: center; gap: .5rem; }
.tk-appbar-plugins {
    display: flex; align-items: center;
    .popover-region-toggle { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 50%; }
    .popover-region-toggle:hover { background: $tk-app-bg; }
    .popover-region-container { border-radius: 16px; border-color: $tk-line; box-shadow: 0 16px 40px rgba(15, 27, 45, .12); }
}
.tk-avatar-btn {
    width: 40px; height: 40px; padding: 0; border: 2px solid #fff; border-radius: 50%; overflow: hidden;
    background: $tk-tint; box-shadow: 0 0 0 1px $tk-line;
    img { width: 100%; height: 100%; object-fit: cover; }
}
.tk-usermenu-panel {
    min-width: 270px; padding: .5rem; border: 1px solid $tk-line; border-radius: 16px;
    box-shadow: 0 16px 40px rgba(15, 27, 45, .14);
    .dropdown-item { border-radius: 10px; padding: .7rem .8rem; font-weight: 500; }
    .tk-usermenu-out { color: $tk-bad; }
}
.tk-usermenu-head {
    display: flex; align-items: center; gap: .75rem;
    padding: .5rem .5rem .8rem; margin-bottom: .35rem; border-bottom: 1px solid $tk-line;
    img { border-radius: 50%; flex: none; }
    strong { display: block; color: $tk-ink; }
    span { display: block; font-size: .85rem; color: $tk-muted; }
}

.tk-btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
    min-height: 44px; padding: 0 1.1rem; border-radius: 12px; border: 1px solid transparent;
    font-weight: 600; text-decoration: none; white-space: nowrap;
    &:hover { text-decoration: none; }
}
.tk-btn-primary { background: $tk-royal; color: #fff; &:hover { background: $tk-royal-600; color: #fff; } }
.tk-btn-ghost { background: #fff; border-color: $tk-line-strong; color: $tk-royal; &:hover { background: $tk-tint; color: $tk-royal; } }
.tk-btn-quiet { color: $tk-ink; &:hover { background: $tk-app-bg; color: $tk-ink; } }
.tk-appbar .tk-btn-quiet { @include media-breakpoint-down(sm) { display: none; } }

.tk-page-content { width: 100%; max-width: 1180px; margin: 0 auto; padding: 1.25rem 1rem 2rem;
    @include media-breakpoint-up(md) { padding: 2rem 1.5rem 3rem; } }
.tk-page-content:not(.is-format) .tk-region-main { max-width: 880px; margin: 0 auto; }
.tk-app-practice .tk-page-content .tk-region-main { max-width: 760px; }

.tk-back {
    display: inline-flex; align-items: center; gap: .4rem; min-height: 44px; margin-bottom: .25rem;
    color: $tk-muted; font-weight: 600; font-size: .92rem; text-decoration: none;
    &:hover { color: $tk-royal; text-decoration: none; }
}
.tk-back-arrow::before { content: "\2190"; }
[dir="rtl"] .tk-back-arrow::before { content: "\2192"; }
.tk-page-title {
    margin: 0 0 1.25rem; font-size: 1.55rem; font-weight: 700; line-height: 1.35; color: $tk-ink; unicode-bidi: plaintext;
    @include media-breakpoint-up(md) { font-size: 2rem; }
}

.tk-footer {
    margin-top: auto; padding: 2rem 1rem;
    display: flex; flex-direction: column; align-items: center; gap: .35rem; color: $tk-muted;
    img { opacity: .55; }
    small { font-size: .875rem; }      // read on a phone, not skimmed on a desktop
    .tk-footer-contact { margin: .25rem 0 0; max-width: 38ch; text-align: center; font-size: .875rem; }
}

// Moodle's own notification popover is sized for a desktop: on a phone it hangs from the top bar, screen-wide,
// instead of off the side of the screen
.popover-region-container { max-inline-size: calc(100vw - 1.5rem); }
@include media-breakpoint-down(md) {
    .popover-region .popover-region-container {
        position: fixed; inset-inline: .75rem; inset-block-start: 60px; inline-size: auto; max-inline-size: none;
        max-block-size: calc(100vh - 140px); overflow-y: auto;
    }
}
.popover-region-content-container, .popover-region-content, .all-notifications, .notifications { max-inline-size: 100%; }
.popover-region-container .see-all-link { min-height: 44px; display: flex; align-items: center; justify-content: center; }

// an icon-only link is still a 44px target
.tk-app .btn-link.p-0, .tk-app a.icon-no-margin { min-inline-size: 44px; min-height: 44px;
    display: inline-flex; align-items: center; justify-content: center; }

.tk-tabbar {
    position: fixed; inset-inline: 0; bottom: 0; z-index: 1030;
    display: flex; background: #fff; border-top: 1px solid $tk-line;
    padding-bottom: env(safe-area-inset-bottom);
    @include media-breakpoint-up(md) { display: none; }
}
.tk-tab {
    flex: 1; min-height: 60px; padding: .45rem 0 .4rem;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    color: #6B7A90; font-size: .75rem; font-weight: 600; text-decoration: none;
    &:hover { text-decoration: none; color: $tk-royal; }
    &.is-active { color: $tk-royal; .tk-tab-icon { background: $tk-tint; } }
}
.tk-tab-icon { display: grid; place-items: center; width: 56px; height: 30px; border-radius: 999px; }

// the student's initial when there is no photo
.tk-initial {
    display: grid; place-items: center; width: 100%; height: 100%; border-radius: 50%;
    background: $tk-royal; color: #fff; font-weight: 700; font-size: 1.05rem;
}
.tk-usermenu-head .tk-initial { width: 48px; height: 48px; flex: none; font-size: 1.3rem; }

// ---------------------------------------------------------------- general content in the app
.tk-app {
    .card, .tk-activity-header .activity-header { border: 1px solid $tk-line; border-radius: 18px; box-shadow: $tk-shadow; }
    .tk-activity-header .activity-header { background: #fff; padding: 1rem 1.25rem; margin-bottom: 1rem; }
    .generaltable { background: #fff; border-radius: 14px; overflow: hidden; border: 1px solid $tk-line; }
    .generaltable th, .generaltable td { padding: .75rem 1rem; vertical-align: middle; }
    .alert { border-radius: 14px; }
    // an activity's own action strip (for example the quiz's start button): a plain row, no Moodle bar
    .tertiary-navigation { padding: 0; margin: 0 0 1rem; background: none; border: 0; }
    .tertiary-navigation .btn-primary { min-height: 48px; padding: 0 1.75rem; border-radius: 999px; }
    input.form-control, select.form-select, textarea.form-control, .custom-select {
        font-size: 16px; min-height: 48px; border-radius: 12px; border-color: $tk-line-strong;
    }
    .btn { min-height: 44px; font-weight: 600; }
    // forms: label above the field on phones
    .mform .fitem { margin-bottom: 1rem; }
    @include media-breakpoint-down(md) {
        .mform .fitem > .col-md-3, .mform .fitem > .col-md-9 { flex: 0 0 100%; max-width: 100%; }
    }
    // the profile form: the account's own fields only, in a card
    &#page-user-edit .mform, &#page-login-change_password .mform {
        background: #fff; border: 1px solid $tk-line; border-radius: 20px; padding: 1.25rem; box-shadow: $tk-shadow;
        @include media-breakpoint-up(md) { padding: 2rem; }
    }
}

// ---------------------------------------------------------------- practice (quiz attempt, summary, review)
.tk-quiznav {
    margin-bottom: 1rem;
    .block { background: #fff; border: 1px solid $tk-line; border-radius: 18px; box-shadow: none; margin: 0 0 .75rem; }
    .block .card-body { padding: .85rem 1rem; }
    .block .card-title, .block h2, .block h5 { display: none; }
    .qn_buttons { display: flex; flex-wrap: nowrap; gap: .5rem; overflow-x: auto; padding: .15rem .1rem .35rem; scrollbar-width: thin; }
    .qnbutton {
        position: relative; flex: none; width: 40px; height: 40px; min-height: 40px; margin: 0; padding: 0;
        display: grid; place-items: center; border-radius: 50%;
        border: 2px solid $tk-line-strong; background: #fff; color: $tk-ink; font-weight: 700; text-decoration: none;
        .trafficlight, .thispageholder { display: none; }
        &.answersaved, &.complete { background: $tk-tint; border-color: $tk-royal; color: $tk-royal; }
        &.correct { background: $tk-good-bg; border-color: $tk-good; color: $tk-good; }
        &.incorrect, &.notanswered { background: $tk-bad-bg; border-color: $tk-bad; color: $tk-bad; }
        &.partiallycorrect { background: #FDF4E3; border-color: $tk-amber; color: $tk-amber-800; }
        &.thispage { box-shadow: 0 0 0 3px rgba(17, 57, 114, .25); }
    }
    .othernav { display: flex; flex-wrap: wrap; gap: .5rem 1rem; margin-top: .5rem; font-weight: 600; }
    #quiz-timer-wrapper, #quiz-timer { border-radius: 999px; }
}

.path-mod-quiz.tk-app {
    .que {
        display: block; margin: 0 0 1rem; padding: 1.25rem;
        background: #fff; border: 1px solid $tk-line; border-radius: 22px; box-shadow: $tk-shadow;
        @include media-breakpoint-up(md) { padding: 1.75rem 2rem; }
    }
    .que .info {
        float: none; width: auto; min-height: 0; margin: 0 0 1rem; padding: 0; background: none; border: 0;
        display: flex; flex-wrap: wrap; align-items: center; gap: .5rem;
        .no { margin: 0; padding: .25rem .8rem; border-radius: 999px; background: $tk-tint; color: $tk-royal; font-size: .85rem; font-weight: 700; }
        .state, .grade, .questionflag, .editquestion { display: none; }
    }
    .que .content { margin: 0; }
    .que .formulation { margin: 0 0 1rem; padding: 0; background: none; border: 0; color: inherit; }
    .que .qtext { margin-bottom: 1.1rem; font-size: 1.12rem; font-weight: 600; line-height: 1.75; color: $tk-ink; unicode-bidi: plaintext; }
    .que .ablock { margin: 0; }
    .que .ablock .prompt { display: none; }
    .que .answer { display: flex; flex-direction: column; gap: .6rem; }
    .que .answer > div {
        position: relative; display: flex; align-items: flex-start; gap: .75rem; min-height: 54px; margin: 0;
        padding: .85rem 1rem; border: 2px solid $tk-line; border-radius: 16px; background: #fff; cursor: pointer;
        transition: border-color .15s ease, background-color .15s ease;
        &:hover { border-color: $tk-line-strong; background: #FAFBFD; }
        &:has(input:checked) { border-color: $tk-royal; background: #EEF3FB; }
        &:has(input:focus-visible) { box-shadow: 0 0 0 3px rgba(17, 57, 114, .25); }
        input[type="radio"], input[type="checkbox"] { flex: none; width: 20px; height: 20px; margin: .3rem 0 0; accent-color: $tk-royal; }
        > div, > label { flex: 1; cursor: pointer; unicode-bidi: plaintext; }
        .answernumber { font-weight: 700; color: $tk-royal; }
        &.correct { border-color: $tk-good; background: $tk-good-bg; }
        &.incorrect { border-color: $tk-bad; background: $tk-bad-bg; }
        .questioncorrectnessicon { margin-inline-start: auto; }
    }
    .que.match .answer { display: table; width: 100%; }
    .que.match .answer td { padding: .5rem .25rem; }
    .que.match select { min-height: 44px; border-radius: 12px; font-size: 16px; }
    .que .im-controls { margin-top: 1rem; }
    .que .im-controls input.submit, .que .im-controls button.submit {
        min-height: 48px; padding: 0 1.9rem; border: 0; border-radius: 999px;
        background: $tk-royal; color: #fff; font-weight: 700;
        &:hover { background: $tk-royal-600; }
    }
    .que .outcome { margin-top: 1rem; padding: 0; background: none; border: 0; color: inherit; }
    .que .specificfeedback, .que .generalfeedback, .que .rightanswer, .que .numpartscorrect {
        margin-top: .75rem; padding: 1rem 1.1rem; border-radius: 16px; line-height: 1.8;
    }
    .que .specificfeedback { background: $tk-app-bg; }
    .que .generalfeedback { background: #EEF3FB; border-inline-start: 4px solid $tk-azure; }
    .que .rightanswer { background: $tk-good-bg; color: #14532D; font-weight: 600; }
    .que.correct .specificfeedback, .que .outcome .correct { color: #14532D; }
    .que .validationerror { color: $tk-bad; font-weight: 600; }
    .submitbtns {
        display: flex; flex-wrap: wrap; justify-content: space-between; gap: .75rem; margin-top: 1.25rem;
        input[type="submit"], .btn { min-height: 48px; padding: 0 1.6rem; border-radius: 999px; font-weight: 700; }
        .mod_quiz-next-nav { background: $tk-royal; border-color: $tk-royal; color: #fff; }
    }
    // the activity's "back" strip is the frame's back link here
    &.tk-app-practice .tertiary-navigation { display: none; }
    .quizattemptsummary, .quizreviewsummary, .quizsummaryofattempt { width: 100%; }
    #mod_quiz_navblock .othernav a { color: $tk-royal; }
}

// An English page title in an Arabic page lines up with the Arabic around it.
[dir="rtl"] .tk-page-title { text-align: right; }

// The practice set's name is already the frame's title: Moodle's own copy of it goes.
.tk-app-practice [role="main"] > h2:first-of-type { display: none; }
.tk-app-practice [role="main"] > h3:first-of-type { font-size: 1.15rem; font-weight: 700; margin: .5rem 0 1rem; }

// how to reach us: the number carries WhatsApp's own green so it is recognised before it is read
.tk-wa {
    display: inline-flex; align-items: center; gap: .4rem; min-height: 44px;
    color: $tk-royal; font-weight: 700; text-decoration: none;
    svg { color: #25D366; flex: none; }
    &:hover, &:focus { color: $tk-royal-600; text-decoration: none; }
}
.tk-auth-foot .tk-wa { margin-inline-end: .75rem; }
