/* ==========================================================================
   Layouts / shells
   public  : sticky header + footer          (visitors, admin previewing the site)
   app     : right sidebar + topbar (mobile: bottom tab bar)   (students)
   auth    : split screen                    (login, register)
   player  : header only                     (lesson player)
   admin   : dark sidebar + topbar           (teacher)
   ========================================================================== */

/* --- Brand ----------------------------------------------------------------- */
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 800; font-size: 1.12rem; color: var(--text); line-height: 1.2; }
.brand:hover { color: var(--link); }
.brand-mark { display: inline-flex; flex: none; }
.brand-mark img { height: 40px; width: auto; }
.brand-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 230px; }

/* --- Public header --------------------------------------------------------- */
.site-header {
  position: sticky; top: 0; z-index: 60; background: var(--glass);
  backdrop-filter: saturate(1.5) blur(12px); border-bottom: 1px solid var(--border);
}
.site-header .container { display: flex; align-items: center; gap: 18px; height: var(--header-h); }
.nav { display: flex; gap: 2px; margin-inline-start: 8px; }
.nav a { color: var(--muted); padding: 8px 14px; border-radius: 11px; font-weight: 700; font-size: .95rem; }
.nav a:hover { color: var(--link); background: var(--primary-50); }
.nav a.active { color: var(--link); background: var(--primary-50); }
.header-search { position: relative; margin-inline-start: auto; width: 250px; }
.header-search .input { min-height: 42px; padding-inline-start: 42px; border-radius: 999px; background: var(--surface-2); border-color: transparent; font-size: .92rem; }
.header-search .input:focus { background: var(--surface); }
.header-search svg { position: absolute; top: 50%; inset-inline-start: 14px; transform: translateY(-50%); color: var(--faint); pointer-events: none; }
.header-actions { display: flex; gap: 10px; align-items: center; }
.menu-toggle { display: none; background: none; border: 0; padding: 8px; cursor: pointer; color: var(--text); border-radius: 10px; }
.menu-toggle:hover { background: var(--surface-2); }
.mobile-nav { display: none; }

@media (max-width: 900px) {
  .nav, .header-search, .header-actions .hide-sm { display: none; }
  .header-actions { margin-inline-start: auto; flex: none; }
  .menu-toggle { display: inline-flex; }
  /* Let the brand fill whatever room the (now fixed-size) actions leave it,
     instead of capping it to an arbitrary fraction of the viewport — that cap
     was often narrower than the space actually available, cutting the name
     short for no reason. Only fall back to ellipsis if it still doesn't fit.
     flex-basis 0 (not auto) so its size is driven purely by the free space
     left over, not by its own content — with auto, the nested flex container
     used its content width as a starting point and undershot the space it
     actually had left to grow into. */
  /* Scoped to .site-header: an unscoped .brand here also matched the app-shell
     topbar's brand link (icon only at this width, see .topbar .brand below),
     handing it half the flex row and starving .topbar-search of the space it
     needs — the placeholder ended up clipped to a couple of characters. */
  .site-header .brand { flex: 1 1 0%; min-width: 0; }
  .site-header .brand-text { max-width: none; }
  /* On pages without the search form (e.g. /courses), a <span class="grow">
     stands in as a spacer to push header-actions to the end — it also has
     flex:1 (base.css) and was splitting the free space with .brand instead
     of leaving it all to the name. header-actions' own margin-inline-start:auto
     (above) already pushes it to the end, so the spacer can just be removed
     from the flex flow entirely (flex:none alone would still cost it a gap). */
  .site-header .grow { display: none; }
  .header-actions .hide-phone { display: none; }
  .mobile-nav.open {
    display: flex; flex-direction: column; padding: 8px 20px 18px; gap: 2px;
    border-top: 1px solid var(--border); background: var(--surface);
  }
  .mobile-nav .m-search { position: relative; margin: 8px 0 10px; }
  .mobile-nav .m-search .input { padding-inline-start: 44px; border-radius: 999px; }
  .mobile-nav .m-search svg { position: absolute; top: 50%; inset-inline-start: 16px; transform: translateY(-50%); color: var(--faint); }
  .mobile-nav a, .mobile-nav button {
    padding: 12px 10px; color: var(--text); font-weight: 700; border-radius: 10px; text-align: start;
    background: none; border: 0; font: inherit; font-weight: 700; cursor: pointer; width: 100%; display: block;
  }
  .mobile-nav a:hover, .mobile-nav button:hover { background: var(--primary-50); color: var(--link); }
}
@media (min-width: 901px) { .mobile-nav.open { display: none; } }
@media (max-width: 420px) {
  .site-header .brand-text { font-size: .96rem; }
  .site-header .btn-sm { padding-inline: 12px; font-size: .86rem; }
  /* Trim a few more px off the logo and its gap so the full name still fits
     on one line around 375px, without falling all the way back to wrapping. */
  .site-header .brand-mark img { height: 32px; }
  .site-header .brand { gap: 6px; }
}
@media (max-width: 370px) {
  /* Even the trimmed actions + logo no longer leave enough room on one line for
     the full name at this width — wrap onto a second line rather than truncate. */
  .site-header .container { flex-wrap: wrap; height: auto; padding-block: 10px; row-gap: 8px; }
  .site-header .brand { flex-basis: 100%; order: -1; }
  .site-header .brand-text { white-space: normal; overflow: visible; text-overflow: clip; }
}

/* --- Footer ---------------------------------------------------------------- */
.site-footer { border-top: 1px solid var(--border); background: var(--surface); padding: 28px 0; color: var(--muted); font-size: .92rem; margin-top: 40px; }
.site-footer .container { display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; }
.site-footer .foot-brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 700; color: var(--text); }
.site-footer .foot-brand img { height: 28px; width: auto; }

/* --- Student app shell ----------------------------------------------------- */
.app { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: 100vh; }
.app-side {
  position: sticky; top: 0; height: 100vh; overflow-y: auto; background: var(--surface);
  border-inline-end: 1px solid var(--border); padding: 20px 16px; display: flex; flex-direction: column; gap: 6px;
}
.side-brand { padding: 4px 10px 20px; }
.side-label { padding: 8px 12px 6px; font-size: .78rem; font-weight: 700; color: var(--faint); letter-spacing: .3px; }
.side-nav { display: flex; flex-direction: column; gap: 4px; }
.side-nav a {
  position: relative; display: flex; align-items: center; gap: 12px; padding: 11px 14px; border-radius: 12px;
  color: var(--muted); font-weight: 700; transition: background .15s, color .15s;
}
.side-nav a svg { flex: none; }
.side-nav a:hover { background: var(--surface-2); color: var(--text); }
.side-nav a.active { background: var(--primary-50); color: var(--link); }
.side-nav a.active::before { content: ""; position: absolute; inset-inline-end: -16px; top: 20%; bottom: 20%; width: 4px; border-radius: 4px 0 0 4px; background: var(--primary); }
.side-foot { margin-top: auto; padding-top: 16px; }
.side-help { padding: 16px; border-radius: 16px; background: linear-gradient(160deg, var(--primary-50), var(--surface-2)); border: 1px solid var(--primary-100); font-size: .9rem; }
.side-help strong { display: block; margin-bottom: 2px; }
.side-help a { font-weight: 700; }

.app-main { min-width: 0; display: flex; flex-direction: column; min-height: 100vh; }
.topbar {
  position: sticky; top: 0; z-index: 50; height: var(--header-h); display: flex; align-items: center; gap: 14px; padding: 0 28px;
  background: var(--glass-bg); backdrop-filter: saturate(1.5) blur(12px); border-bottom: 1px solid var(--border);
}
.topbar .brand { display: none; }
.topbar-search { position: relative; flex: 1; max-width: 460px; }
.topbar-search .input { min-height: 44px; padding-inline-start: 44px; border-radius: 999px; border-color: var(--border); }
.topbar-search svg { position: absolute; top: 50%; inset-inline-start: 16px; transform: translateY(-50%); color: var(--faint); pointer-events: none; }
.topbar .grow { min-width: 0; }
.app-content { flex: 1; padding: 28px; width: 100%; max-width: 1240px; margin-inline: auto; }
.app-content .container { padding: 0; max-width: none; }
.app-main .site-footer { margin-top: 0; }

.tabbar { display: none; }
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .app-side { display: none; }
  .topbar { padding: 0 14px; gap: 10px; }
  .topbar .brand { display: inline-flex; }
  .topbar .brand-text { display: none; }
  .app-content { padding: 18px 14px calc(88px + env(safe-area-inset-bottom)); }
  .tabbar {
    display: grid; grid-template-columns: repeat(var(--tabs, 4), 1fr); position: fixed; z-index: 70; inset-inline: 0; bottom: 0;
    background: var(--glass-strong); backdrop-filter: blur(12px); border-top: 1px solid var(--border);
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom)); box-shadow: 0 -6px 24px rgba(18, 59, 50, .08);
  }
  .tabbar a { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 4px; border-radius: 12px; color: var(--faint); font-size: .72rem; font-weight: 700; line-height: 1.3; }
  .tabbar a.active { color: var(--link); background: var(--primary-50); }
}

/* --- Auth split screen ----------------------------------------------------- */
/* Same identity as the homepage: forest green, ivory, saffron and terracotta, with the
   Algerian lattice pattern. Column 1 renders on the right in this RTL grid (the green
   brand panel, first in the markup) and gets the smaller share. */
.auth { position: relative; min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr); background: var(--sand); }
.auth-art {
  position: relative; overflow: hidden; isolation: isolate; color: #fff; padding: 56px; display: flex; flex-direction: column; justify-content: center; gap: 20px;
  background:
    radial-gradient(700px 460px at 100% 0%, rgba(232, 180, 74, .16), transparent 62%),
    linear-gradient(160deg, #0f332b 0%, #174c3f 62%, #245e4e 130%);
}
.auth-art::before { content: ""; position: absolute; inset: 0 0 auto; height: 5px; z-index: 2; background: linear-gradient(90deg, var(--primary), #e8b44a, var(--accent)); }
.auth-art > * { position: relative; z-index: 1; }
.auth-art .art-pattern {
  position: absolute; z-index: 0; inset: auto auto -30px -30px; width: 340px; height: 340px; opacity: .1; pointer-events: none;
  background-image: radial-gradient(circle at center, transparent 28%, #e8b44a 29%, #e8b44a 31%, transparent 32%); background-size: 38px 38px;
}
.auth-art .art-logo {
  display: inline-flex; align-items: center; gap: 12px; align-self: flex-start; padding: 10px 20px 10px 22px; border-radius: 20px;
  background: rgba(255, 255, 255, .09); border: 1px solid rgba(255, 255, 255, .18);
  color: #fff; font-weight: 800; font-size: 1.3rem; line-height: 1.2;
}
.auth-art .art-logo:hover { color: #fff; background: rgba(255, 255, 255, .15); }
.auth-art .art-logo img { height: 42px; width: auto; }
.auth-art .art-eyebrow { display: inline-flex; align-items: center; gap: 10px; color: #e8b44a; font-size: .9rem; font-weight: 800; margin-top: 8px; }
.auth-art .art-eyebrow::before { content: ""; width: 28px; height: 2px; border-radius: 3px; background: #e8b44a; }
.auth-art h2 { color: #fff; font-size: clamp(1.7rem, 3vw, 2.5rem); font-weight: 800; margin: 0; max-width: 440px; line-height: 1.3; }
.auth-art p { color: rgba(255, 255, 255, .8); max-width: 440px; margin: 0; }
.auth-points { list-style: none; padding: 0; margin: 6px 0 0; display: grid; gap: 12px; }
.auth-points li {
  display: flex; gap: 14px; align-items: center; font-weight: 700; padding: 10px 14px 10px 10px; border-radius: 16px;
  background: rgba(255, 255, 255, .07); border: 1px solid rgba(255, 255, 255, .12);
}
.auth-points svg { flex: none; width: 38px; height: 38px; padding: 9px; border-radius: 12px; box-sizing: border-box; background: #e8b44a; color: #213a31; }
.auth-points li:nth-child(2) svg { background: #f3e3bd; }
.auth-points li:nth-child(3) svg { background: #e8a178; color: #3b1d10; }
.auth-motto {
  margin-top: auto; display: inline-flex; align-items: center; gap: 10px; align-self: flex-start; font-weight: 700; font-size: .92rem;
  color: rgba(255, 255, 255, .9); padding-top: 18px;
}
.auth-motto svg { flex: none; width: 30px; height: 30px; padding: 6px; border-radius: 10px; background: rgba(232, 180, 74, .2); color: #e8b44a; box-sizing: border-box; }

.auth-panel { position: relative; isolation: isolate; display: grid; place-items: center; padding: 40px 20px; background: var(--sand); }
.auth-panel::before {
  content: ""; position: absolute; z-index: -1; inset: 0; opacity: .5; pointer-events: none;
  background-image: linear-gradient(30deg, var(--primary) 12%, transparent 12.5%, transparent 87%, var(--primary) 87.5%), linear-gradient(150deg, var(--primary) 12%, transparent 12.5%, transparent 87%, var(--primary) 87.5%), linear-gradient(30deg, var(--primary) 12%, transparent 12.5%, transparent 87%, var(--primary) 87.5%), linear-gradient(150deg, var(--primary) 12%, transparent 12.5%, transparent 87%, var(--primary) 87.5%);
  background-size: 42px 74px; background-position: 0 0, 0 0, 21px 37px, 21px 37px;
  -webkit-mask-image: radial-gradient(60% 60% at 50% 50%, transparent 40%, rgba(0, 0, 0, .1) 100%); mask-image: radial-gradient(60% 60% at 50% 50%, transparent 40%, rgba(0, 0, 0, .1) 100%);
}
.auth-card { width: 100%; max-width: 440px; }
.auth-card.card { position: relative; overflow: hidden; border-radius: 24px; box-shadow: var(--shadow-lg); }
.auth-card.card::before { content: ""; position: absolute; inset: 0 0 auto; height: 5px; background: linear-gradient(90deg, var(--primary), #e8b44a, var(--accent)); }
.auth-card .card-body { padding: 40px 34px 32px; }
.auth-card-logo { display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center; margin-bottom: 22px; }
.auth-card-logo img { height: 52px; width: auto; }
.auth-card-logo strong { font-size: 1.15rem; font-weight: 800; color: var(--primary); }
.auth-card h1 { font-size: 1.6rem; margin-bottom: 4px; text-align: center; color: var(--heading); }
.auth-card p.muted.center { margin-bottom: 24px; }
.auth-card .btn-lg { border-radius: 14px; background: var(--primary); box-shadow: 0 6px 16px rgba(23, 76, 63, .24); }
.auth-card .btn-lg:hover { background: var(--primary-700); }
.auth-wrap { width: 100%; max-width: 440px; }
.auth-wrap .back-link { justify-content: center; color: var(--faint); }
.auth-wrap .back-link:hover { color: var(--link); }
.auth-mobile-logo { display: none; }

/* Field with a leading icon (phone, lock…). The input itself is unchanged. */
.input-icon { position: relative; }
.input-icon > svg { position: absolute; top: 50%; inset-inline-start: 15px; transform: translateY(-50%); color: var(--faint); pointer-events: none; }
.input-icon > .input, .input-icon.pw-wrap > .input { padding-inline-start: 46px; }
.input-icon:focus-within > svg { color: var(--link); }
.auth-card .input { min-height: 52px; border-radius: 14px; background: var(--field-bg); }
@media (max-width: 900px) {
  .auth { grid-template-columns: 1fr; }
  .auth-art { display: none; }
  .auth-panel { padding: 28px 16px; align-content: start; }
}
@media (max-width: 480px) { .auth-card .card-body { padding: 22px; } }

/* --- Admin shell ----------------------------------------------------------- */
.admin { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: 100vh; }
.admin-side {
  background: linear-gradient(180deg, var(--deep) 0%, #08241e 100%); color: #c5d8cd; padding: 20px 14px; position: sticky; top: 0;
  height: 100vh; overflow-y: auto; display: flex; flex-direction: column;
}
.admin-side .brand { color: #fff; padding: 4px 10px 20px; }
.admin-side .brand:hover { color: #fff; }
.admin-side .brand-mark { background: #fff; border-radius: 12px; padding: 5px 7px; }
.admin-side .brand-mark img { height: 30px; }
.admin-side nav { display: flex; flex-direction: column; gap: 3px; }
.admin-side nav a { display: flex; align-items: center; gap: 12px; padding: 11px 14px; border-radius: 12px; color: #c5d8cd; font-weight: 700; transition: background .15s, color .15s; }
.admin-side nav a:hover { background: rgba(255, 255, 255, .08); color: #fff; }
.admin-side nav a.active { background: linear-gradient(135deg, var(--primary), var(--sky)); color: #fff; box-shadow: 0 6px 16px rgba(0, 0, 0, .25); }
.admin-side nav a .pill { margin-inline-start: auto; background: var(--accent); color: var(--on-accent); border-radius: 99px; font-size: .74rem; padding: 0 8px; font-weight: 800; }
.admin-side .side-foot { margin-top: auto; padding-top: 16px; border-top: 1px solid rgba(255, 255, 255, .1); }
.admin-side .side-foot a, .admin-side .side-foot button { color: #c5d8cd; background: none; border: 0; font: inherit; font-weight: 700; cursor: pointer; padding: 9px 14px; display: flex; gap: 10px; align-items: center; width: 100%; border-radius: 10px; }
.admin-side .side-foot a:hover, .admin-side .side-foot button:hover { background: rgba(255, 255, 255, .08); color: #fff; }
.admin-main { min-width: 0; }
.backdrop { display: none; }
.admin-top {
  height: var(--header-h); display: flex; align-items: center; gap: 12px; padding: 0 28px; background: var(--glass);
  backdrop-filter: saturate(1.5) blur(12px); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 40;
}
.admin-top .title { font-weight: 800; font-size: 1.1rem; }
.admin-top .user-chip { display: flex; align-items: center; gap: 10px; font-weight: 700; }
.admin-content { padding: 28px; max-width: 1260px; }
.admin-menu-btn { display: none; }
@media (max-width: 960px) {
  .admin { grid-template-columns: 1fr; }
  .admin-side { position: fixed; inset-block: 0; inset-inline-start: 0; width: 284px; z-index: 100; transform: translateX(100%); transition: transform .22s; box-shadow: var(--shadow-lg); }
  .admin-side.open { transform: none; }
  .admin-menu-btn { display: inline-grid; }
  .admin-content { padding: 18px 14px; }
  .admin-top { padding: 0 14px; }
  .backdrop.open { display: block; position: fixed; inset: 0; background: rgba(8, 24, 19, .55); z-index: 90; }
  .admin-top .hide-sm { display: none !important; }
}
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; }
.grid-side { display: grid; grid-template-columns: 1fr 340px; gap: 22px; align-items: start; }
@media (max-width: 1100px) { .grid-2, .grid-side { grid-template-columns: 1fr; } }

/* --- Width helpers & shell adjustments ------------------------------------- */
.container.narrow { max-width: 760px; }
.container.narrow-lg { max-width: 900px; }
.app-content .container.narrow { max-width: 760px; }
.app-content .container.narrow-lg { max-width: 900px; }
.app-content .page-head { padding-top: 4px; }
.app-content .course-hero { border-radius: var(--radius-lg); overflow: hidden; margin-bottom: 8px; }
.app-content .course-hero .container { padding-inline: 32px; }
.app-content .course-body { padding: 28px 0 24px; }
@media (max-width: 960px) { .app-content .course-hero .container { padding-inline: 20px; } }

@media (max-width: 900px) {
  .topbar-search { max-width: none; }
  .topbar-search ~ .grow { display: none; }
}

/* LTR fields (phone, email) sit in an RTL page: the icon is on the right, so pad the right. */
.input-icon > .input[dir="ltr"] { padding-inline-start: 14px; padding-left: 14px; padding-right: 46px; }
