/* App-shell layout — mobile-first, native-app feel */
:root {
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --brand: #f97316;
}

html, body { -webkit-tap-highlight-color: transparent; }
body.app-shell { padding-top: var(--safe-top); padding-bottom: var(--safe-bottom); }

/* Sticky top bar */
.app-topbar {
    position: sticky; top: 0; z-index: 30;
    background: linear-gradient(135deg, #0f172a 0%, #1e293b 60%, #7c2d12 100%);
    color: white;
    padding-top: var(--safe-top);
    box-shadow: 0 1px 0 rgba(0,0,0,0.04);
}

.app-main { min-height: calc(100vh - 56px - 64px); }

/* Bottom tab bar */
.app-tabbar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
    display: grid; grid-template-columns: 1fr 1fr 1fr;
    background: #ffffffd9; backdrop-filter: saturate(180%) blur(10px);
    border-top: 1px solid #e2e8f0;
    padding-bottom: var(--safe-bottom);
}
.tab-link {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    padding: 10px 6px 8px; color: #475569; text-decoration: none;
    font-size: 11px; font-weight: 600;
}
.tab-icon { font-size: 20px; line-height: 1; }
.tab-label { margin-top: 2px; }
.tab-link:active { background: #f1f5f9; }

/* Hero card */
.hero {
    background: linear-gradient(135deg, #0f172a 0%, #1e293b 50%, #c2410c 100%);
    position: relative; overflow: hidden;
}
.hero::after {
    content: ''; position: absolute; inset: -40% -20% auto auto;
    width: 220px; height: 220px; border-radius: 9999px;
    background: radial-gradient(closest-side, rgba(249,115,22,.6), transparent 70%);
    pointer-events: none;
}

/* Prevent iOS zoom on focus by keeping form-control font-size ≥16px on small
   screens. iOS Safari only auto-zooms when the focused control's computed
   font-size is < 16px, so we only enforce this below the 'sm' breakpoint and
   leave desktop free to use Tailwind's text-sm/text-xs utilities at will. */
input, select, textarea, button { font-size: 16px; }
@media (max-width: 640px) {
    input:not([type="checkbox"]):not([type="radio"]):not([type="range"]),
    select, textarea {
        font-size: 16px !important;
    }
}

/* Pretty radio cards used in registration */
input[type="radio"].peer:checked + div { box-shadow: 0 0 0 2px var(--brand) inset; }

/* Forms — bigger tap targets on mobile */
@media (max-width: 640px) {
    button, .tab-link { min-height: 44px; }
}

/* Hide spinners on number inputs */
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
input[type="number"] { -moz-appearance: textfield; }

/* Attendance overlay views (confirm / result) — render inline inside
   .app-main, but reserve enough top padding so the sticky topbar never
   covers their content. Keeping them in normal flow means iOS Safari's
   regular page scroll works without any special handling. */
.attendance-overlay {
    scroll-margin-top: calc(64px + var(--safe-top));
}

/* Prevent stray horizontal overflow on admin pages with wide tables.
   Force the document and every direct main child to respect the viewport,
   so a too-wide card or table can never push content under the right edge. */
html, body { max-width: 100vw; overflow-x: hidden; }
main { max-width: 100vw; overflow-x: hidden; }
main > section, main > div { max-width: 100%; min-width: 0; }
main * { min-width: 0; }

/* Themed native <select> — brand chevron, rounded, consistent across browsers.
   Opt-in via class so we don't break file inputs or other form controls. */
select.themed-select {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    background-color: #ffffff;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23475569' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    background-size: 1rem;
    padding-right: 2.25rem;
    border: 1px solid #e2e8f0;
    border-radius: 0.5rem;
    color: #0f172a;
    cursor: pointer;
    transition: border-color .15s ease, box-shadow .15s ease;
}
select.themed-select:hover { border-color: #cbd5e1; }
select.themed-select:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(249, 115, 22, .2);
}
select.themed-select:disabled { background-color: #f1f5f9; color: #94a3b8; cursor: not-allowed; }
/* Option styling (best-effort; native options have limited styling on most OSes) */
select.themed-select option { background: #ffffff; color: #0f172a; padding: 8px; }
select.themed-select option:checked { background: #fff7ed; color: #c2410c; }

/* Toast notifications — stacked top-right, brand-tinted, auto-dismiss.
   Triggered by window.showToast(message, type?) in app.js. */
.toast-stack {
    position: fixed;
    top: calc(var(--safe-top) + 12px);
    left: 50%;
    transform: translateX(-50%);
    z-index: 60;
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: calc(100vw - 24px);
    max-width: 420px;
    pointer-events: none;
}
.toast {
    pointer-events: auto;
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 12px 14px;
    border-radius: 14px;
    box-shadow: 0 10px 24px rgba(15, 23, 42, .18), 0 2px 4px rgba(15, 23, 42, .08);
    background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
    color: #f8fafc;
    font-size: 14px;
    line-height: 1.35;
    border: 1px solid rgba(255, 255, 255, .08);
    transform: translateY(-12px);
    opacity: 0;
    transition: transform .22s ease, opacity .22s ease;
}
.toast.is-visible { transform: translateY(0); opacity: 1; }
.toast-icon {
    width: 22px; height: 22px; flex: 0 0 22px;
    border-radius: 999px;
    display: flex; align-items: center; justify-content: center;
    font-weight: 800; font-size: 13px;
    background: rgba(255, 255, 255, .12);
}
.toast-body { flex: 1; min-width: 0; word-wrap: break-word; }
.toast--error {
    background: linear-gradient(135deg, #b91c1c 0%, #7f1d1d 100%);
    border-color: rgba(254, 226, 226, .25);
}
.toast--error .toast-icon { background: rgba(255, 255, 255, .18); }
.toast--success {
    background: linear-gradient(135deg, #047857 0%, #065f46 100%);
    border-color: rgba(209, 250, 229, .25);
}
.toast--brand {
    background: linear-gradient(135deg, #c2410c 0%, #7c2d12 100%);
    border-color: rgba(255, 237, 213, .25);
}

/* Print pass without chrome */
@media print {
    .app-topbar, .app-tabbar, .no-print { display: none !important; }
    .app-main { padding: 0 !important; max-width: none !important; }
}
