/*
 * Sponsor web app — mobile-first design system.
 * Scoped to Layout/sponsor_mobile.ctp and Layout/sponsor_auth.ctp only —
 * these render for mobile devices; desktop keeps the original AdminLTE
 * sponsor pages untouched.
 * Brand color is red (matches webroot/images/logo.png and webroot/img/admin.png),
 * not green.
 */

:root {
    --ctl-primary: #B02127;
    --ctl-primary-dark: #8f1a1f;
    --ctl-success: #2e7d32;
    --ctl-success-dark: #1b5e20;
    --ctl-ink: #23272b;
    --ctl-ink-soft: #5c6570;
    --ctl-muted: #8a939c;
    --ctl-border: #e4e7eb;
    --ctl-bg: #f5f6f8;
    --ctl-surface: #ffffff;
    --ctl-danger-bg: #fdeceb;
    --ctl-success-bg: #eaf7e8;

    --ctl-radius-sm: 8px;
    --ctl-radius: 14px;
    --ctl-radius-lg: 20px;
    --ctl-shadow: 0 1px 3px rgba(20, 24, 28, 0.08), 0 1px 2px rgba(20, 24, 28, 0.06);
    --ctl-shadow-lg: 0 12px 32px rgba(20, 24, 28, 0.18);

    --ctl-tabbar-h: 60px;
    --ctl-header-h: 56px;
    --ctl-safe-top: env(safe-area-inset-top, 0px);
    --ctl-safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--ctl-bg);
    color: var(--ctl-ink);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    -webkit-tap-highlight-color: transparent;
    overscroll-behavior-y: none;
}

img { max-width: 100%; }

a { color: var(--ctl-primary); text-decoration: none; }

h1, h2, h3, h4 { margin: 0 0 8px; line-height: 1.25; }
p { margin: 0 0 12px; line-height: 1.5; }

button { font-family: inherit; }

/* ---------- App shell (Layout/sponsor_mobile.ctp) ---------- */

.app-shell {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header itself is Element/site_header.ctp — the same #fh5co-header/
   #fh5co-offcanvas/.fh5co-nav-toggle markup the public homepage uses, styled
   by the "Site header" rules further down. */

.app-main {
    flex: 1;
    width: 100%;
    max-width: 720px;
    margin: 0 auto;
    padding: calc(var(--ctl-header-h) + var(--ctl-safe-top) + 16px) 16px calc(var(--ctl-tabbar-h) + var(--ctl-safe-bottom) + 24px);
}

/* ---------- Site header (Element/site_header.ctp) ----------
 * Copied from webroot/css/style.css (the public homepage's stylesheet) so
 * the header is pixel-identical there and here: same #fh5co-header /
 * #fh5co-offcanvas / .fh5co-nav-toggle rules, including the brand-red nav
 * text override. Not just a <link> to style.css itself — that file also
 * redefines body/a/h1-h6/p/.btn globally for the one-page marketing site,
 * which would clobber this app's own typography and buttons everywhere,
 * not just inside the header.
 */

#fh5co-header {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 999;
    background: transparent;
    padding: 0;
    width: 100%;
}
#fh5co-header #fh5co-logo {
    float: left;
    line-height: 1.2;
    margin-top: 15px;
    width: 330px;
}
#fh5co-header #fh5co-logo a {
    font-family: "Roboto Slab", sans-serif;
    font-size: 30px;
    color: #fff;
}
#fh5co-header #fh5co-logo img {
    float: left;
    width: 100%;
}
#fh5co-header #fh5co-main-nav {
    float: right;
    margin-top: 40px;
}
#fh5co-header #fh5co-main-nav ul {
    padding: 0;
    margin: 4px 0 0 0;
}
#fh5co-header #fh5co-main-nav ul li {
    padding: 0;
    margin: 0;
    display: inline;
}
#fh5co-header #fh5co-main-nav ul li a {
    font-family: "Roboto Slab", sans-serif;
    color: #af2127 !important;
    font-weight: bold !important;
    text-decoration: none;
    margin-left: 30px;
    border-bottom: 2px solid transparent;
}
#fh5co-header #fh5co-main-nav ul li a:hover { text-decoration: none; color: #f9ad81; }
#fh5co-header #fh5co-main-nav ul li.active a { border-bottom: 2px solid #f9ad81; }

#fh5co-header.navbar-fixed-top {
    position: fixed !important;
    background: #fff;
    box-shadow: 0 0 9px 0 rgba(0, 0, 0, 0.1);
    top: 0;
    left: 0;
}

#fh5co-offcanvas {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 9999;
    width: 275px;
    background: #444853;
    overflow-y: auto;
    padding: 50px 30px 30px 30px;
    transform: translateX(275px);
    transition: 0.4s;
}
#fh5co-offcanvas .fh5co-offcanvas-close {
    position: absolute;
    top: 20px;
    right: 30px;
    width: 30px;
    height: 30px;
    color: rgba(255, 255, 255, 0.5);
    font-size: 26px;
    line-height: 1;
}
#fh5co-offcanvas .fh5co-offcanvas-close:hover { color: #fff; }
#fh5co-offcanvas nav ul { padding: 0; margin: 0; }
#fh5co-offcanvas nav ul li { padding: 0; margin: 0; list-style: none; }
#fh5co-offcanvas nav ul li a { display: block; color: rgba(255, 255, 255, 0.85); padding: 7px 0; }
#fh5co-offcanvas nav ul li a:hover { color: #f9ad81; }
.offcanvas-visible #fh5co-offcanvas { transform: translateX(0); }

.fh5co-nav-toggle {
    position: absolute;
    top: 8px;
    right: 15px;
    z-index: 21;
    display: none;
    height: 44px;
    width: 25px;
    cursor: pointer;
    text-decoration: none;
}
@media screen and (max-width: 768px) {
    .fh5co-nav-toggle { display: block; }
}
.fh5co-nav-toggle.active i::before, .fh5co-nav-toggle.active i::after { background: #f9ad81; }
.fh5co-nav-toggle i {
    position: relative;
    display: inline-block;
    width: 25px;
    height: 3px;
    background: #535659;
    transition: all .2s ease-out;
}
.fh5co-nav-toggle i::before, .fh5co-nav-toggle i::after {
    content: '';
    width: 25px;
    height: 3px;
    background: #535659;
    position: absolute;
    left: 0;
    transition: 0.2s;
}
.fh5co-nav-toggle i::before { top: -7px; }
.fh5co-nav-toggle i::after { bottom: -7px; }
.fh5co-nav-toggle.active i { background: transparent; }
.fh5co-nav-toggle.active i::before { top: 0; transform: rotateZ(45deg); }
.fh5co-nav-toggle.active i::after { bottom: 0; transform: rotateZ(-45deg); }

/* Compact this same header down from the public page's hero-sized version
   (330px-wide logo, 40px nav margin meant to sit over a tall background
   image) to a normal fixed top bar — there's no hero behind it here. */
.app-shell #fh5co-header {
    height: calc(var(--ctl-header-h) + var(--ctl-safe-top));
    padding-top: var(--ctl-safe-top);
    display: flex;
    align-items: center;
}
.app-shell #fh5co-header .container { display: flex; align-items: center; width: 100%; padding: 0 16px; }
.app-shell #fh5co-header #fh5co-logo { float: none; margin: 0; width: auto; }
.app-shell #fh5co-header #fh5co-logo img { float: none; width: auto; height: 26px; }
.app-shell #fh5co-header #fh5co-main-nav { float: none; margin: 0 0 0 auto; }
.app-shell #fh5co-header #fh5co-main-nav ul { margin: 0; }
.app-shell #fh5co-header #fh5co-main-nav ul li a { margin-left: 16px; font-size: 13px; }

/* No hamburger drawer here — the bottom tab bar already covers navigation
   on phones, and the full menu stays inline on desktop below. */
.app-shell .fh5co-nav-toggle { display: none !important; }

/* The Logout <li> carries both an icon and a text label (site_header.ctp);
   by default (public page, sponsor desktop) only the label shows, matching
   every other nav item. */
.nav-logout-icon { display: none; }

/* Phones: header bar shows logo + Logout only, as the original round icon
   button (like the rest of the app's header actions) instead of a text nav
   item — the bottom tab bar already has Home/Updates/Gallery/Profile, and
   the other menu items (Public Page, My Children, Updates, My Gallery, name)
   would just repeat it. Desktop keeps the full inline text menu. */
@media screen and (max-width: 768px) {
    .app-shell #fh5co-header #fh5co-main-nav li:not(.nav-logout-item) {
        display: none;
    }
    .app-shell #fh5co-header #fh5co-main-nav .nav-logout-item a {
        margin-left: 0;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 36px;
        height: 36px;
        border-radius: 50%;
        color: var(--ctl-ink-soft);
    }
    .app-shell #fh5co-header #fh5co-main-nav .nav-logout-icon {
        display: block;
        font-size: 18px;
    }
    .app-shell #fh5co-header #fh5co-main-nav .nav-logout-label {
        display: none;
    }
}

.app-tabbar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 20;
    display: flex;
    background: var(--ctl-surface);
    border-top: 1px solid var(--ctl-border);
    padding-bottom: var(--ctl-safe-bottom);
}

.app-tabbar__item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 8px 4px 6px;
    color: var(--ctl-muted);
    font-size: 11px;
    font-weight: 600;
    text-decoration: none;
}

.app-tabbar__item i { font-size: 20px; }

.app-tabbar__item.is-active { color: var(--ctl-primary); }

/* ---------- Auth shell (Layout/sponsor_auth.ctp) ---------- */

.auth-shell {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 32px 16px calc(32px + var(--ctl-safe-bottom));
    background: linear-gradient(180deg, var(--ctl-primary) 0%, var(--ctl-primary) 220px, var(--ctl-bg) 220px);
}

.auth-card {
    width: 100%;
    max-width: 400px;
    background: var(--ctl-surface);
    border-radius: var(--ctl-radius-lg);
    box-shadow: var(--ctl-shadow-lg);
    padding: 28px 24px;
}

.auth-logo {
    display: flex;
    justify-content: center;
    margin-bottom: 20px;
}
.auth-logo img { max-height: 48px; }

.auth-title {
    text-align: center;
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 4px;
}

.auth-subtitle {
    text-align: center;
    color: var(--ctl-ink-soft);
    font-size: 14px;
    margin-bottom: 20px;
}

.auth-links {
    margin-top: 18px;
    text-align: center;
    font-size: 14px;
    color: var(--ctl-ink-soft);
}
.auth-links a { font-weight: 600; }
.auth-links p { margin: 6px 0; }

/* ---------- Buttons ---------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 46px;
    padding: 0 20px;
    border-radius: var(--ctl-radius-sm);
    border: 1px solid transparent;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
}

.btn-primary { background: var(--ctl-primary); color: #fff; }
.btn-primary:active { background: var(--ctl-primary-dark); }

.btn-secondary { background: var(--ctl-bg); color: var(--ctl-ink); border-color: var(--ctl-border); }
.btn-secondary:active { background: var(--ctl-border); }

.btn-danger { background: var(--ctl-primary); color: #fff; }
.btn-danger:active { background: var(--ctl-primary-dark); }

.btn-text { background: transparent; color: var(--ctl-primary); min-height: auto; padding: 8px; }

.btn-block { display: flex; width: 100%; }

.btn[disabled] { opacity: 0.6; cursor: default; }

/* ---------- Forms ---------- */

.field { margin-bottom: 16px; }

.field label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--ctl-ink-soft);
    margin-bottom: 6px;
}

.field input[type="text"],
.field input[type="email"],
.field input[type="password"],
.field input[type="tel"],
.field input[type="file"],
.field select,
.field textarea {
    width: 100%;
    min-height: 46px;
    padding: 10px 14px;
    font-size: 16px; /* prevents iOS auto-zoom on focus */
    border: 1px solid var(--ctl-border);
    border-radius: var(--ctl-radius-sm);
    background: var(--ctl-surface);
    color: var(--ctl-ink);
    -webkit-appearance: none;
    appearance: none;
}

.field textarea { min-height: 110px; resize: vertical; }

.field input:focus,
.field select:focus,
.field textarea:focus {
    outline: none;
    border-color: var(--ctl-primary);
    box-shadow: 0 0 0 3px rgba(176, 33, 39, 0.15);
}

.field-row { display: flex; gap: 12px; }
.field-row .field { flex: 1; }

.field-checkbox {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    color: var(--ctl-ink-soft);
}
.field-checkbox input { width: 18px; height: 18px; }

.field-hint { font-size: 12px; color: var(--ctl-muted); margin-top: 6px; }
.field-error { font-size: 12px; color: var(--ctl-primary); margin-top: 6px; }

/* Fallback styling for default CakePHP FormHelper output (e.g. CaptchaHelper's
   generated input) that isn't hand-marked-up with .field/.btn classes. */
.input { margin-bottom: 16px; }
.input label { display: block; font-size: 13px; font-weight: 600; color: var(--ctl-ink-soft); margin-bottom: 6px; }
.input input[type="text"],
.input input[type="email"],
.input input[type="password"] {
    width: 100%;
    min-height: 46px;
    padding: 10px 14px;
    font-size: 16px;
    border: 1px solid var(--ctl-border);
    border-radius: var(--ctl-radius-sm);
    background: var(--ctl-surface);
    color: var(--ctl-ink);
}
.input.error input { border-color: var(--ctl-primary); }
.error-message { font-size: 12px; color: var(--ctl-primary); margin-top: 4px; }
.creload { display: inline-block; font-size: 13px; margin: 8px 0; }

/* ---------- Flash messages ---------- */

.flash-message {
    border-radius: var(--ctl-radius-sm);
    padding: 12px 14px;
    font-size: 14px;
    margin-bottom: 16px;
}
.flash-message.success { background: var(--ctl-success-bg); color: var(--ctl-success-dark); }
.flash-message.error { background: var(--ctl-danger-bg); color: var(--ctl-primary-dark); }

/* ---------- Cards / lists ---------- */

.card {
    background: var(--ctl-surface);
    border-radius: var(--ctl-radius);
    box-shadow: var(--ctl-shadow);
    padding: 16px;
    margin-bottom: 14px;
}

.section-title {
    font-size: 15px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    color: var(--ctl-ink-soft);
    margin: 4px 0 10px;
}

.child-card {
    display: flex;
    align-items: center;
    gap: 14px;
    background: var(--ctl-surface);
    border-radius: var(--ctl-radius);
    box-shadow: var(--ctl-shadow);
    padding: 14px;
    margin-bottom: 12px;
    text-decoration: none;
    color: inherit;
}

.child-card__avatar {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    background: var(--ctl-bg);
}

.child-card__body { flex: 1; min-width: 0; }
.child-card__name { font-size: 16px; font-weight: 700; margin-bottom: 2px; }
.child-card__meta { font-size: 13px; color: var(--ctl-ink-soft); }

.child-card__chevron { color: var(--ctl-muted); font-size: 18px; }

.empty-state {
    text-align: center;
    color: var(--ctl-ink-soft);
    padding: 48px 16px;
}
.empty-state i { font-size: 36px; color: var(--ctl-border); margin-bottom: 12px; display: block; }

/* ---------- Avatar circle (profile) ---------- */

.avatar-picker { display: flex; flex-direction: column; align-items: center; gap: 10px; margin-bottom: 20px; }
.avatar-picker__img {
    width: 96px;
    height: 96px;
    border-radius: 50%;
    object-fit: cover;
    border: 1px solid var(--ctl-border);
    cursor: pointer;
}

/* ---------- Timeline feed (Updates tab / child detail) ---------- */

.feed-item {
    background: var(--ctl-surface);
    border-radius: var(--ctl-radius);
    box-shadow: var(--ctl-shadow);
    overflow: hidden;
    margin-bottom: 14px;
}
.feed-item__header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
}
.feed-item__avatar { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; }
.feed-item__sender { font-size: 14px; font-weight: 700; }
.feed-item__date { font-size: 12px; color: var(--ctl-muted); }
.feed-item__media { width: 100%; max-height: 360px; object-fit: cover; display: block; background: var(--ctl-bg); }

/* ---------- Video fullscreen button (wireVideoFullscreen() wraps each
   video.feed-item__media in this at runtime) ---------- */

.video-wrap { position: relative; }
.video-fullscreen-btn {
    position: absolute;
    right: 10px;
    bottom: 10px;
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.55);
    color: #fff;
    font-size: 14px;
    cursor: pointer;
}

.feed-item__body { padding: 12px 14px; }
.feed-item__subject { font-size: 15px; font-weight: 700; margin-bottom: 4px; }
.feed-item__message { font-size: 14px; color: var(--ctl-ink-soft); }
.feed-item__message p:last-child { margin-bottom: 0; }

/* ---------- Gallery grid ---------- */

.gallery-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
}
.gallery-grid img {
    width: 100%;
    aspect-ratio: 1 / 1;
    object-fit: cover;
    border-radius: var(--ctl-radius-sm);
}

/* ---------- Lightbox (gallery photos, feed/timeline photos) ---------- */

.gallery-grid img,
img.feed-item__media {
    cursor: zoom-in;
}

.lightbox-overlay {
    position: fixed;
    inset: 0;
    z-index: 90;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: rgba(10, 12, 14, 0.92);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    cursor: zoom-out;
}
.lightbox-overlay.is-open { opacity: 1; pointer-events: auto; }

.lightbox-overlay img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: var(--ctl-radius);
    box-shadow: var(--ctl-shadow-lg);
}

.lightbox-close {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
}

/* ---------- Bottom sheet (message composer) ---------- */

.sheet-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 18, 20, 0.5);
    z-index: 50;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}
.sheet-overlay.is-open { opacity: 1; pointer-events: auto; }

.sheet {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 51;
    max-height: 92vh;
    display: flex;
    flex-direction: column;
    background: var(--ctl-surface);
    border-radius: var(--ctl-radius-lg) var(--ctl-radius-lg) 0 0;
    box-shadow: var(--ctl-shadow-lg);
    transform: translateY(100%);
    transition: transform 0.25s ease;
    padding-bottom: var(--ctl-safe-bottom);
}
.sheet.is-open { transform: translateY(0); }

.sheet__handle {
    width: 40px;
    height: 4px;
    border-radius: 2px;
    background: var(--ctl-border);
    margin: 10px auto;
}

.sheet__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 18px 12px;
    border-bottom: 1px solid var(--ctl-border);
}
.sheet__title { font-size: 16px; font-weight: 700; }
.sheet__close {
    border: none;
    background: transparent;
    font-size: 20px;
    color: var(--ctl-muted);
    width: 32px;
    height: 32px;
}

.sheet__body { padding: 16px 18px; overflow-y: auto; }
.sheet__footer { padding: 12px 18px; border-top: 1px solid var(--ctl-border); }

/* ---------- Loading ---------- */

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--ctl-border);
    border-top-color: var(--ctl-primary);
    border-radius: 50%;
    margin: 32px auto;
    animation: ctl-spin 0.8s linear infinite;
}
@keyframes ctl-spin { to { transform: rotate(360deg); } }

/* ---------- Utilities ---------- */

.u-mt-0 { margin-top: 0; }
.u-text-center { text-align: center; }
.u-flex { display: flex; }
.u-flex-between { display: flex; align-items: center; justify-content: space-between; }
.u-gap-8 { gap: 8px; }

/* ---------- Desktop: header nav replaces the bottom tab bar ---------- */

@media (min-width: 769px) {
    .app-tabbar { display: none; }
    .app-main { padding-bottom: 32px; }
}

/* ---------- Tablet / desktop scale-up ---------- */

@media (min-width: 640px) {
    .gallery-grid { grid-template-columns: repeat(4, 1fr); }
    .sheet {
        left: 50%;
        right: auto;
        bottom: 24px;
        width: 480px;
        max-height: 85vh;
        transform: translate(-50%, 40px);
        border-radius: var(--ctl-radius-lg);
        opacity: 0;
        visibility: hidden;
        pointer-events: none;
        transition: transform 0.25s ease, opacity 0.2s ease, visibility 0s linear 0.25s;
    }
    .sheet.is-open {
        transform: translate(-50%, 0);
        opacity: 1;
        visibility: visible;
        pointer-events: auto;
        transition: transform 0.25s ease, opacity 0.2s ease;
    }

    /* Same app shell, just kept from stretching edge-to-edge on wide
       browser windows — the tabbar lines up with .app-main's width instead
       of spreading 4 items across the full browser width. */
    .app-tabbar {
        max-width: 720px;
        left: 50%;
        right: auto;
        transform: translateX(-50%);
        width: 100%;
        border-left: 1px solid var(--ctl-border);
        border-right: 1px solid var(--ctl-border);
    }
}
