﻿/*
 * أستاذي — phone layout, for the site and every portal.
 *
 * One file, loaded after the theme, holding everything that changes below tablet width.
 * The desktop rules stay untouched; on a phone the aim is: one column, comfortable tap
 * targets, less padding, nothing that overflows sideways, and the things a person needs
 * first (the strip of buttons, the install offer, the pay button) within reach of a thumb.
 */

/* ---------- the strip of portal buttons ----------
   On a phone a row of ten wrapped buttons is a cloud nobody can scan. It becomes one
   swipeable rail: every button stays a tap away, in a fixed order, with the current
   screen highlighted. On wider screens it wraps as before. */

.ostazy-strip {
  --strip-fade: var(--ostazy-bg, #F7F7FC);
}

@media (max-width: 767.98px) {
  .ostazy-strip {
    flex-wrap: nowrap !important;
    overflow-x: auto;
    overflow-y: hidden;
    gap: 0.5rem !important;
    padding: 0.25rem 0 0.6rem;
    margin-inline: -14px;
    padding-inline: 14px;
    scroll-snap-type: x proximity;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    /* the badge (top-0 start-100 translate-middle) needs room above the buttons */
    padding-top: 0.6rem;
  }

  .ostazy-strip::-webkit-scrollbar {
    display: none;
  }

  .ostazy-strip > * {
    flex: 0 0 auto;
    scroll-snap-align: start;
    white-space: nowrap;
  }

  .ostazy-strip .btn {
    border-radius: 999px;
    padding-inline: 0.9rem;
  }
}

/* The screen you are on, on every width. */
.ostazy-strip .btn.active,
.ostazy-strip .btn.active:hover {
  background-color: var(--ostazy-primary);
  border-color: var(--ostazy-primary);
  color: #fff;
}

/* ---------- install bar (site and portals) ---------- */

.ostazy-install-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.6rem 1rem;
  background: #EEF2FF;
  border-bottom: 1px solid #C7D2FE;
  color: #3730A3;
  font-weight: 600;
  font-size: 0.95rem;
}

.ostazy-install-bar[hidden] {
  display: none;
}

.ostazy-install-bar .btn {
  white-space: nowrap;
  border-radius: 999px;
  /* The platform's own green on every layout, not Bootstrap's blue. */
  background-color: var(--ostazy-primary, #4338CA);
  border-color: var(--ostazy-primary, #4338CA);
  color: #fff;
}

@media (min-width: 992px) {
  .ostazy-install-bar:not(.ostazy-push-bar) {
    display: none;
  }
}

/* The offer to turn notifications on: same bar, warmer colour, and it is the one bar that
   still belongs inside the installed app. */
.ostazy-push-bar {
  background: var(--ostazy-tint-warning, #FFF7ED);
  border-bottom-color: #FED7AA;
  color: #9A3412;
}

/* "Later" is a word, not a button: none of the bar's pill styling applies to it. */
.ostazy-push-bar .btn-link,
.ostazy-push-bar .btn-link:hover {
  min-height: auto;
  padding: 0 0.25rem;
  border: 0;
  border-radius: 0;
  background: none !important;
  font-size: 0.85rem;
  font-weight: 600;
  color: #9A3412;
  text-decoration: underline;
  white-space: nowrap;
}

/* ---------- portal chrome on phones ---------- */

@media (max-width: 767.98px) {
  body > .container {
    padding-inline: 14px;
  }

  .ostazy-navbar {
    margin-bottom: 0 !important;
  }

  .ostazy-navbar + .ostazy-install-bar {
    margin-bottom: 0.75rem;
  }

  .ostazy-navbar .navbar-toggler {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    border: 1px solid var(--ostazy-line);
    border-radius: 999px;
    padding: 0.35rem 0.8rem;
  }

  .ostazy-navbar .navbar-collapse {
    padding: 0.5rem 0 0.75rem;
  }

  .ostazy-navbar .navbar-nav .nav-link {
    padding: 0.55rem 0.25rem;
    border-bottom: 1px solid var(--ostazy-line);
  }

  /* Cards, heroes and tiles: the same shapes, with phone-sized padding. */
  .ostazy-card {
    padding: 1.1rem;
    border-radius: 14px;
  }

  .ostazy-portal-hero {
    padding: 1.35rem 1.1rem;
    margin-top: 0.75rem;
    border-radius: 16px;
  }

  .ostazy-portal-hero h1 {
    font-size: 1.35rem;
  }

  .ostazy-stat-tile {
    padding: 0.9rem 0.6rem;
  }

  .ostazy-stat-tile:hover {
    transform: none;
  }

  .ostazy-stat-icon {
    width: 40px;
    height: 40px;
    font-size: 1.25rem;
    margin-bottom: 0.4rem;
  }

  .ostazy-stat-value {
    font-size: 1.5rem;
  }

  /* Three tiles side by side on a phone, not three tall cards in a column. */
  .ostazy-portal-hero .row > [class*="col-md-4"] {
    flex: 0 0 33.333%;
    max-width: 33.333%;
  }

  h1.h3 {
    font-size: 1.35rem;
  }

  .display-6 {
    font-size: 1.6rem;
  }

  .h4, h4 {
    font-size: 1.15rem;
  }

  /* Tables scroll sideways inside their card instead of squeezing every column. */
  .ostazy-card > table,
  .ostazy-card > .table,
  .ostazy-card > div:not(.table-responsive) > table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
  }

  .ostazy-card .table-responsive {
    margin-inline: -1.1rem;
    padding-inline: 1.1rem;
  }

  .table > :not(caption) > * > * {
    padding: 0.55rem 0.5rem;
  }

  /* Forms: 16px inputs so iPhone does not zoom in on focus; buttons that are easy to hit. */
  .form-control,
  .form-select {
    font-size: 16px;
    min-height: 44px;
  }

  .btn:not(.btn-sm):not(.btn-link) {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  form .btn-primary.w-100,
  .ostazy-auth-card .btn-primary {
    min-height: 48px;
    font-size: 1.05rem;
  }

  .ostazy-auth-card {
    margin: 1rem auto;
    padding: 1.25rem;
  }

  /* A row of actions wraps and each takes the width it needs; nothing falls off the edge. */
  .d-flex.gap-2 > .btn,
  .d-flex.gap-3 > .btn {
    flex: 0 1 auto;
  }

  .alert {
    padding: 0.75rem 0.9rem;
    font-size: 0.95rem;
  }

  .ostazy-footer .container {
    text-align: center;
    font-size: 0.85rem;
  }
}

/* ---------- the public site on phones ---------- */

@media (max-width: 767.98px) {
  .ostazy-topbar .container {
    padding-inline: 14px;
  }

  .ostazy-topbar .navbar-collapse {
    padding: 0.5rem 0 1rem;
  }

  .ostazy-topbar .navbar-nav .nav-link {
    padding: 0.6rem 0.25rem;
    border-bottom: 1px solid var(--ostazy-line);
  }

  .ostazy-topbar .navbar-collapse .d-flex {
    padding-top: 0.75rem;
  }

  .ostazy-topbar .navbar-collapse .btn,
  .ostazy-topbar .navbar-collapse form {
    width: 100%;
  }

  .ostazy-topbar .navbar-collapse form .btn {
    width: 100%;
  }

  /* "حساب جديد" opens its three choices in place, under the button, instead of floating off
     the side of a narrow screen. */
  .ostazy-topbar .navbar-collapse .dropdown {
    width: 100%;
  }

  .ostazy-topbar .navbar-collapse .dropdown-menu {
    position: static !important;
    transform: none !important;
    width: 100%;
    margin-top: 0.5rem;
  }

  .ostazy-hero {
    padding: 2.25rem 0 2.75rem;
  }

  .ostazy-hero__title {
    font-size: 1.75rem;
    line-height: 1.35;
  }

  .ostazy-hero__lead {
    font-size: 0.98rem;
    line-height: 1.8;
  }

  .ostazy-hero .btn {
    min-height: 46px;
  }

  .ostazy-section {
    padding: 2rem 0;
  }

  .ostazy-section__title {
    font-size: 1.4rem;
  }

  .ostazy-section__lead {
    font-size: 0.95rem;
  }

  .ostazy-crumbs {
    font-size: 0.85rem;
  }

  .ostazy-video-row {
    padding: 0.7rem 0.75rem;
    gap: 0.6rem;
  }

  .ostazy-video-row .btn {
    padding-inline: 0.8rem;
  }

  .ostazy-plan {
    padding: 1.25rem 1rem;
  }

  .ostazy-pay__head {
    padding: 1.2rem 1rem;
  }

  .ostazy-pay__head h1 {
    font-size: 1.2rem;
  }

  .ostazy-pay__body {
    padding: 1.1rem 1rem;
  }

  .ostazy-price__amount {
    font-size: 1.35rem;
  }

  .ostazy-code__value {
    font-size: 1.7rem;
    letter-spacing: 0.1em;
  }

  .ostazy-steps-inline li {
    font-size: 0.95rem;
  }
}

/* ---------- the study screens on phones ---------- */

@media (max-width: 767.98px) {
  /* Units: one compact row each, and the whole row is the link. */
  .ostazy-units {
    --bs-gutter-y: 0.6rem;
  }

  .ostazy-unit-card {
    flex-direction: row;
    align-items: center;
    gap: 0.8rem;
    height: auto;
    padding: 0.8rem 0.9rem;
  }

  .ostazy-unit-card:hover {
    transform: none;
  }

  .ostazy-unit-card__head {
    flex: none;
  }

  .ostazy-unit-card__head .badge {
    display: none;
  }

  .ostazy-unit-card .ostazy-unit-number {
    margin-bottom: 0;
  }

  .ostazy-unit-card__body {
    flex: 1;
    min-width: 0;
  }

  .ostazy-unit-card__body h5 {
    font-size: 1rem;
    margin-bottom: 0.15rem !important;
  }

  .ostazy-unit-card__body .text-muted {
    margin-bottom: 0.35rem !important;
  }

  .ostazy-unit-card__body .ostazy-level-track {
    height: 6px;
    margin: 0 !important;
  }

  .ostazy-unit-card__cta {
    display: none;
  }

  .ostazy-unit-card::after {
    content: "‹";
    flex: none;
    font-size: 1.6rem;
    line-height: 1;
    color: var(--ostazy-muted);
  }

  /* Lesson content: a wide table scrolls inside the page instead of stretching it. */
  .ostazy-content {
    font-size: 1rem;
  }

  .ostazy-content table {
    display: block;
    max-width: 100%;
    overflow-x: auto;
  }

  /* Quiz: the hand-in button spans the width, where the thumb is. */
  .ostazy-quiz__submit .btn {
    width: 100%;
  }

  /* Stat tiles: three abreast means smaller words. */
  .ostazy-stat-label {
    font-size: 0.78rem;
    margin-bottom: 0.3rem;
  }

  .ostazy-stat-sub {
    font-size: 0.72rem;
  }
}

/* ---------- the phone's tab bar ----------
   Four screens and "more", fixed to the bottom where a thumb rests, with a badge on the
   bell. Rendered on every page for whoever is signed in; on wider screens it does not exist
   and the strip does its job as before. */

.ostazy-tabbar {
  display: none;
}

@media (max-width: 767.98px) {
  body.has-tabbar main {
    padding-bottom: calc(5.5rem + env(safe-area-inset-bottom)) !important;
  }

  body.has-tabbar .ostazy-footer {
    padding-bottom: calc(4.75rem + env(safe-area-inset-bottom));
  }

  /* The tab bar and its "more" sheet carry every link the strip has, so the strip steps aside. */
  body.has-tabbar .ostazy-strip {
    display: none !important;
  }

  .ostazy-tabbar {
    display: flex;
    position: fixed;
    bottom: 0;
    inset-inline: 0;
    z-index: 1030;
    background: var(--ostazy-surface);
    border-top: 1px solid var(--ostazy-line, #E4E4F0);
    padding: 0.3rem 0 calc(0.3rem + env(safe-area-inset-bottom));
    box-shadow: 0 -6px 18px rgba(15, 23, 42, 0.06);
  }

  .ostazy-tab {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.2rem;
    min-height: 50px;
    padding: 0.2rem 0;
    border: 0;
    background: none;
    color: var(--ostazy-muted, #5B5E7A);
    font-size: 0.68rem;
    font-weight: 700;
    text-decoration: none;
  }

  .ostazy-tab__icon {
    position: relative;
    font-size: 1.3rem;
    line-height: 1;
  }

  .ostazy-tab.active {
    color: var(--ostazy-primary, #4338CA);
  }

  .ostazy-tab.active .ostazy-tab__icon {
    transform: translateY(-2px);
  }

  .ostazy-tab__badge {
    position: absolute;
    top: -0.45rem;
    inset-inline-end: -0.8rem;
    min-width: 1.15rem;
    padding: 0.08rem 0.3rem;
    border-radius: 999px;
    background: #DC2626;
    color: #fff;
    font-size: 0.6rem;
    font-weight: 800;
    line-height: 1.1;
    text-align: center;
  }

  .ostazy-more {
    border-radius: 18px 18px 0 0;
  }

  .ostazy-more .list-group-item {
    font-weight: 700;
    padding: 0.8rem 0.5rem;
  }

  .ostazy-more .list-group-item.active {
    background: var(--ostazy-primary);
    border-color: var(--ostazy-primary);
  }

  /* The helper's corner button and panel sit above the tab bar, not under it. */
  body.has-tabbar .ostazy-bot__launch {
    inset-block-end: calc(4.6rem + env(safe-area-inset-bottom));
  }

  body.has-tabbar .ostazy-bot__panel {
    inset-block-end: calc(8.6rem + env(safe-area-inset-bottom));
    max-height: min(30rem, calc(100vh - 12rem));
  }
}

/* ---------- when running as the installed app ---------- */

@media (display-mode: standalone) {
  /* No browser chrome to fall back on: the header is the app bar, so it stays put. */
  .ostazy-topbar,
  .ostazy-navbar {
    position: sticky;
    top: 0;
    z-index: 1030;
  }

  .ostazy-install-bar:not(.ostazy-push-bar) {
    display: none !important;
  }
}
