/* Kiosk styles. Big everything. Designed for a 10-12" tablet held landscape. */
:root {
    --bg: #1c2230;
    --bg-2: #2a3142;
    --fg: #f4f6fa;
    --fg-dim: #a9b2c5;
    --accent: #4ea1ff;
    --good: #59c275;
    --warn: #f1c155;
    --danger: #ef5757;
    --tile-bg: rgba(255, 255, 255, 0.16);
    --tile-bg-hover: rgba(255, 255, 255, 0.24);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    /* iOS Safari shrinks 100vh by browser-chrome height; dvh follows the
       visible viewport so the pair card never gets cropped at the bottom. */
    min-height: 100dvh;
    width: 100%;
    background: var(--bg);
    color: var(--fg);
    font-family: -apple-system, system-ui, "Segoe UI", Roboto, sans-serif;
    font-size: 22px;
    overflow: hidden;
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

#bg {
    position: fixed;
    top: 0; right: 0; bottom: 0; left: 0;
    background-size: cover;
    background-position: center;
    /* z-index: 0 (not -1) — html and body both have a solid `background:
       var(--bg)`, and z-index:-1 puts #bg behind body's bg, hiding the
       image entirely. At z-index:0 we paint after body and the screens
       (with z-index:auto, later in DOM order) still stack above us. */
    z-index: 0;
    opacity: 0.55;
    pointer-events: none;
    /* Always-on blur softens detail so feed cards stay readable and the
       backdrop reads as ambient colour rather than a competing image.
       Scale up slightly so the blur's blurred edges don't show at the
       viewport border. */
    -webkit-filter: blur(14px) saturate(1.05);
    filter: blur(14px) saturate(1.05);
    -webkit-transform: scale(1.08);
    transform: scale(1.08);
    transition: background-image 0.5s;
}

.hidden { display: none !important; }

.screen {
    position: fixed;
    top: 0; right: 0; bottom: 0; left: 0;
    display: flex;
    flex-direction: column;
    /* Honour iPhone safe-area insets so notch/home-indicator don't clip. */
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
}

/* ---- Pairing ---- */
#pair {
    align-items: center;
    justify-content: center;
    /* Allow the card to scroll if a tiny iPhone landscape screen can't fit
       the whole thing — better than the button being cut off. */
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 1.5rem 2rem;
}
#pair::before {
    content: "";
    position: absolute;
    top: 0; right: 0; bottom: 0; left: 0;
    width: 100%;
    height: 100%;
    background: url("/backgrounds/photos/flower-bokeh.jpg") center/cover no-repeat;
    -webkit-filter: blur(18px) saturate(1.1) brightness(0.55);
    filter: blur(18px) saturate(1.1) brightness(0.55);
    -webkit-transform: scale(1.15);
    transform: scale(1.15);
    z-index: 0;
}
#pair > * { position: relative; z-index: 1; }
#pair .pair-card {
    max-width: 36rem;
    width: 100%;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    background: rgba(20, 26, 38, 0.45);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    border-radius: 28px;
    padding: 2rem 2.2rem;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
    /* Don't inflate beyond the visible viewport; allow the inner content
       to shrink instead of pushing the button off-screen on iOS. */
    margin: auto 0;
}
#pair h1 { font-size: 2.6rem; margin: 0 0 0.6rem; }
#pair p { font-size: 1.15rem; color: var(--fg-dim); margin: 0 0 1.2rem; }
#pair input {
    font-family: ui-monospace, SFMono-Regular, Menlo, "Courier New", monospace;
    font-weight: 700;
    font-size: 1.8rem;
    text-align: center;
    letter-spacing: 0.2rem;
    text-indent: 0.2rem;
    width: 100%;
    max-width: 16rem;
    padding: 0.7rem 0.9rem;
    border: 2px solid var(--accent);
    border-radius: 12px;
    background: var(--bg-2);
    color: var(--fg);
    text-transform: uppercase;
    margin-bottom: 1rem;
}

/* Roomier on tablets — keep the original generous look where it fits. */
@media (min-height: 640px) {
    #pair .pair-card { padding: 3rem 2.5rem; }
    #pair h1 { font-size: 3.4rem; margin: 0 0 1rem; }
    #pair p { font-size: 1.4rem; margin: 0 0 1.6rem; }
    #pair input { font-size: 2.2rem; max-width: 18rem; padding: 0.8rem 1rem; margin-bottom: 1.4rem; }
}

button {
    font: inherit;
    cursor: pointer;
}
button.primary {
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 12px;
    padding: 1rem 1.6rem;
    font-size: 1.6rem;
    font-weight: 600;
}
button.primary.big {
    font-size: 2rem;
    padding: 1.4rem 2.2rem;
}
.error { color: var(--danger); min-height: 1.5em; margin-top: 1rem; }

/* ---- Home ---- */
#home { padding: 1.6rem 2rem; }

#home > header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1.2rem;
    margin-bottom: 1.2rem;
    flex-shrink: 0;
}
#home .header-right {
    display: flex;
    align-items: center;
    gap: 1rem;
}
#home .time {
    font-size: 3.6rem;
    font-weight: 700;
    letter-spacing: -1px;
    font-variant-numeric: tabular-nums;
}
#home {
    /* Allow the absolute-positioned presence dot to anchor inside the
       home screen rather than the body, so it ignores safe-area padding. */
    position: relative;
}
#home .presence {
    position: absolute;
    bottom: 1rem;
    left: 1rem;
    font-size: 0.85rem;
    color: var(--good);
    line-height: 1;
    padding: 0.25rem 0.5rem;
    border-radius: 999px;
    background: rgba(89, 194, 117, 0.15);
    pointer-events: none;
    opacity: 0.6;
    z-index: 1;
}
#home .presence.offline {
    color: var(--fg-dim);
    background: rgba(169, 178, 197, 0.15);
    /* Slightly more visible when offline so the carer's eye catches it. */
    opacity: 0.85;
}

/* ---- Feed ---- */
.feed {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    padding-bottom: 1rem;
    /* Hide the scrollbar — old eyes find a thin grey track stressful and
       drag-scrolling on a touchscreen is the natural gesture anyway. */
    scrollbar-width: none;
    -ms-overflow-style: none;
    -webkit-overflow-scrolling: touch;
}
.feed::-webkit-scrollbar { width: 0; height: 0; display: none; }
/* Sibling margin (rather than `gap`) for row spacing — iPad Safari < 14.5
   ignores flexbox gap and the cards collapse into a tight stack. Margin is
   the universal path and matches the prior visual rhythm. */
.feed > * + * { margin-top: 0.9rem; }

.feed-empty {
    margin: auto;
    text-align: center;
    color: var(--fg-dim);
    font-size: 1.4rem;
}

.feed-card {
    background: var(--tile-bg);
    border-radius: 18px;
    padding: 1.1rem 1.4rem;
    display: flex;
    align-items: center;
    gap: 1.1rem;
}
.feed-card.viewed { opacity: 0.55; }

/* "Done today" recap — dimmed but still readable, no action buttons.
   Strikethrough on the title makes the completed state unambiguous. */
.feed-card.done {
    opacity: 0.6;
    background: rgba(255, 255, 255, 0.04);
}
.feed-card.done .feed-title { text-decoration: line-through; }
.feed-card.done .feed-icon { color: var(--good); }
.feed-card.done-skipped .feed-icon { color: var(--fg-dim); }

.feed-section-heading {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    color: var(--fg-dim);
    font-size: 0.95rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin: 0.6rem 0.3rem 0;
    padding-top: 0.6rem;
    border-top: 1px solid rgba(255, 255, 255, 0.07);
}
.feed-section-heading .count {
    background: rgba(255, 255, 255, 0.1);
    color: var(--fg);
    border-radius: 999px;
    padding: 0.05rem 0.55rem;
    font-size: 0.85rem;
    font-weight: 700;
    letter-spacing: 0;
}
.feed-card.kind-alarm {
    background: rgba(239, 87, 87, 0.18);
    border: 2px solid rgba(239, 87, 87, 0.6);
}
/* Messages put media (audio/video) in the body and need column-style stacking. */
.feed-card.kind-message { align-items: flex-start; }

.feed-icon {
    font-size: 2.4rem;
    line-height: 1;
    flex-shrink: 0;
    width: 3rem;
    text-align: center;
}
.feed-body {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}
.feed-title {
    font-size: 1.35rem;
    font-weight: 600;
    line-height: 1.25;
}
.feed-sub {
    color: var(--fg-dim);
    font-size: 1.05rem;
    line-height: 1.35;
}

/* Actions live in one of two places:
     - on non-message cards, as a sibling of feed-body, anchored to the right;
     - on message cards, stacked under the body content (like before).
   The selectors below target each case. */
.feed-card > .feed-actions {
    margin: 0 0 0 auto;
    flex-shrink: 0;
    display: flex;
    align-items: center;
}
.feed-card > .feed-actions > * + * { margin-left: 0.6rem; }
.feed-body .feed-actions {
    margin-top: 0.6rem;
    display: flex;
    flex-wrap: wrap;
}
.feed-body .feed-actions > * + * { margin-left: 0.6rem; }
.feed-actions button {
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 10px;
    padding: 0.7rem 1.3rem;
    font-size: 1.1rem;
    font-weight: 600;
    white-space: nowrap;
}
.feed-actions button.skip {
    background: transparent;
    color: var(--fg-dim);
    border: 1.5px solid var(--fg-dim);
}
.feed-actions button.danger {
    background: var(--danger);
}
/* Big, colour-coded person pill at the start of each row. Always present
   (empty when the item isn't tied to a specific person) so icons line up
   in a tidy column. */
.feed-person {
    flex-shrink: 0;
    width: 5.4rem;
    text-align: center;
    font-size: 1.15rem;
    font-weight: 700;
    padding: 0.55rem 0.6rem;
    border-radius: 12px;
    line-height: 1.1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    letter-spacing: 0.01em;
}
.feed-person-empty {
    background: transparent !important;
}

audio, video {
    width: 100%;
    max-width: 520px;
    margin-top: 0.4rem;
    border-radius: 8px;
}

/* ---- Alarm overlay ----
   Two severity levels show a takeover. Medium is a calmer red flash;
   high pulses faster and uses a more urgent palette. */
#alarm-overlay {
    position: fixed;
    top: 0; right: 0; bottom: 0; left: 0;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 2rem;
}
#alarm-overlay h1 { font-size: 5rem; margin: 0 0 1rem; }
#alarm-overlay p { font-size: 2rem; margin: 0 0 2rem; }

#alarm-overlay.sev-medium {
    animation: alarm-flash-medium 1.4s steps(2) infinite;
}
@keyframes alarm-flash-medium {
    0%   { background: rgba(239, 87, 87, 0.95); }
    100% { background: rgba(180, 30, 30, 0.95); }
}

#alarm-overlay.sev-high {
    animation: alarm-flash-high 0.5s steps(2) infinite;
}
#alarm-overlay.sev-high h1 { font-size: 6rem; }
@keyframes alarm-flash-high {
    0%   { background: rgba(255, 50, 50, 0.97); }
    100% { background: rgba(120, 0, 0, 0.97); }
}

/* Low-severity in-feed alarm card — pulsing outline draws the eye
   without taking over the screen. */
.feed-card.kind-alarm {
    animation: low-alarm-pulse 2.2s ease-in-out infinite;
}
@keyframes low-alarm-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(239, 87, 87, 0.45); }
    50%      { box-shadow: 0 0 0 10px rgba(239, 87, 87, 0); }
}

/* ---- Contact carer (lives in the home header now) ---- */
.contact-btn {
    background: var(--good);
    color: #fff;
    border: none;
    border-radius: 18px;
    font-size: 1.4rem;
    font-weight: 600;
    padding: 1rem 1.5rem;
    display: inline-flex;
    align-items: center;
    /* Sibling margin instead of `gap` for the same iPad-Safari reason. */
    transition: filter 0.15s;
}
.contact-btn > * + * { margin-left: 0.9rem; }
.contact-btn:active { filter: brightness(0.9); }
.contact-btn.sent { background: rgba(89, 194, 117, 0.5); }
.contact-icon { font-size: 1.6rem; }
.contact-status {
    display: block;
    font-size: 1rem;
    color: var(--fg-dim);
    text-align: center;
    margin-top: 0.4rem;
    min-height: 1em;
}

/* ---- Carer message banner (pinned to the bottom of #home) ---- */
.carer-banner {
    flex-shrink: 0;
    margin-top: 1rem;
    padding: 1.1rem 1.4rem;
    background: rgba(95, 180, 255, 0.16);
    border: 2px solid rgba(95, 180, 255, 0.55);
    border-radius: 18px;
    display: flex;
    align-items: center;
    /* Margin-based spacing for iPad Safari compat — see .feed comment. */
}
.carer-banner > * + * { margin-left: 1.2rem; }
.carer-banner-body {
    flex: 1;
    min-width: 0;
}
.carer-banner-from {
    font-size: 0.95rem;
    color: var(--fg-dim);
    margin-bottom: 0.3rem;
}
.carer-banner-text {
    font-size: 1.4rem;
    line-height: 1.35;
    color: var(--fg);
    /* Allow long messages to wrap rather than overflow the banner. */
    overflow-wrap: anywhere;
}
.carer-banner-ok {
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 14px;
    font-size: 1.5rem;
    font-weight: 700;
    padding: 0.95rem 1.8rem;
    flex-shrink: 0;
    transition: filter 0.15s;
}
.carer-banner-ok:active { filter: brightness(0.85); }

/* ---- Screensaver ---- */
#screensaver {
    background: #000;
    z-index: 500;
}

/* Two photo layers used for cross-fade. Both fill the screen. */
.ss-photo {
    position: absolute;
    top: 0; right: 0; bottom: 0; left: 0;
    background-size: cover;
    background-position: center;
    transition: opacity 1.5s ease-in-out;
    opacity: 0;
}
.ss-photo.ss-visible { opacity: 1; }
/* When no photos: just a dark background, which is already on #screensaver */

/* Clock overlay — bottom-left corner with a soft dark pill */
.ss-clock-overlay {
    position: absolute;
    bottom: 3rem;
    left: 3rem;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.3rem;
    padding: 1.2rem 1.8rem;
    background: rgba(0, 0, 0, 0.5);
    -webkit-backdrop-filter: blur(6px);
    backdrop-filter: blur(6px);
    border-radius: 20px;
    pointer-events: none;
    z-index: 1;
}

#ss-clock {
    font-size: 12rem;
    font-weight: 700;
    letter-spacing: -4px;
    line-height: 1;
    color: #fff;
    /* Use tabular-nums so the digits don't shift sideways as the clock ticks. */
    font-variant-numeric: tabular-nums;
}

#ss-date {
    font-size: 2.2rem;
    color: rgba(255, 255, 255, 0.75);
    font-weight: 400;
}

#ss-caption {
    font-size: 1.6rem;
    color: rgba(255, 255, 255, 0.65);
    font-style: italic;
    min-height: 1em;
    margin-top: 0.2rem;
}

/* Fade-in animation used when first entering screensaver */
@keyframes ss-fade-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}
#screensaver.ss-entering {
    animation: ss-fade-in 1s ease-in-out forwards;
}

/* Screensaver active: body class allows other CSS to adapt if needed */
body.screensaver-mode #home { opacity: 0; pointer-events: none; }

/* ---- Preview / readonly (for admin iframe embedding) ---- */
body.readonly-mode .contact-btn { pointer-events: none; opacity: 0.55; }
body.readonly-mode #alarm-overlay button { pointer-events: none; opacity: 0.6; }
body.preview-mode::after {
    content: "PREVIEW";
    position: fixed;
    top: 0.5rem; right: 0.5rem;
    background: rgba(0, 0, 0, 0.55);
    color: #fff;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    padding: 0.2rem 0.55rem;
    border-radius: 999px;
    pointer-events: none;
    z-index: 2000;
}
