/* Small global styles. Most styling comes from MudBlazor. */

h1:focus {
    outline: none;
}

/* Yellow bar shown at the bottom if something goes badly wrong. */
#blazor-error-ui {
    color-scheme: light only;
    background: lightyellow;
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
    box-sizing: border-box;
    display: none;
    left: 0;
    padding: 0.6rem 1.25rem 0.7rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 2000;
}

    #blazor-error-ui .dismiss {
        cursor: pointer;
        position: absolute;
        right: 0.75rem;
        top: 0.5rem;
    }

.blazor-error-boundary {
    background: #b32121;
    padding: 1rem;
    color: white;
}

    .blazor-error-boundary::after {
        content: "An error has occurred."
    }

.validation-message {
    color: #e50000;
}

/* Shopping list: items that have been bought. */
.bought {
    text-decoration: line-through;
    color: var(--mud-palette-text-disabled);
}

/* Shopping rows can be swiped left to delete. MudBlazor blocks all touch
   scrolling on swipe areas; allow up/down scrolling so long lists still scroll
   on a phone, while left/right swipes still reach the swipe code. */
.mud-swipearea.shopping-row {
    touch-action: pan-y;
}

/* Calendar agenda */
.agenda-day {
    overflow: hidden; /* keeps the coloured header inside the rounded corners */
}

.agenda-day .agenda-day-header {
    background-color: var(--mud-palette-background-gray);
}

/* Today stands out: coloured border and header. */
.agenda-day.today {
    border: 2px solid var(--mud-palette-primary);
}

.agenda-day.today .agenda-day-header {
    background-color: var(--mud-palette-primary);
    color: var(--mud-palette-primary-text);
}

/* ---- Bottom bar on phones and small tablets (MainLayout.razor) ----
   Shown below 960px wide, where the side menu is hidden. */
.bottom-nav {
    display: none;
}

@media (max-width: 959.98px) {
    .desktop-only {
        display: none !important;
    }

    .bottom-nav {
        display: flex;
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 1050; /* above the page, below the side menu and pop-ups */
        height: calc(60px + env(safe-area-inset-bottom));
        padding-bottom: env(safe-area-inset-bottom);
        background: var(--mud-palette-surface);
        border-top: 1px solid var(--mud-palette-lines-default);
        box-shadow: 0 -2px 6px rgba(0, 0, 0, 0.08);
    }

    .bottom-nav-item {
        flex: 1 1 0;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 2px;
        border: none;
        background: none;
        font: inherit;
        font-size: 0.75rem;
        color: var(--mud-palette-text-secondary);
        text-decoration: none;
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
    }

    .bottom-nav-item.active {
        color: var(--mud-palette-primary);
        font-weight: 500;
    }

    /* Room at the bottom of every page so the bar never covers anything. */
    .mud-main-content {
        padding-bottom: calc(68px + env(safe-area-inset-bottom));
    }

    /* Pop-up messages ("Deleted - Undo") sit just above the bar. */
    .mud-snackbar-location-bottom-center {
        bottom: calc(68px + env(safe-area-inset-bottom)) !important;
    }
}

/* Family page: long email addresses wrap instead of pushing the buttons off a phone screen. */
.family-email {
    overflow-wrap: anywhere;
}

/* Budget: the "last 6 months" bars. */
.trend-bars {
    display: flex;
    align-items: flex-end;
    gap: 6px;
    height: 140px;
}

.trend-bar-wrap {
    flex: 1 1 0;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    align-items: center;
}

.trend-bar {
    width: 70%;
    background: var(--mud-palette-primary);
    opacity: 0.45;
    border-radius: 4px 4px 0 0;
}

.trend-bar.current {
    opacity: 1;
}

.trend-amount, .trend-label {
    font-size: 0.7rem;
    color: var(--mud-palette-text-secondary);
}

/* Info board: keep line breaks in notes, and let long words/links wrap. */
.info-content {
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    font-size: 0.9rem;
}

/* Ask Family Hub: chat bubbles (family on the right, assistant on the left). */
.chat-line {
    display: flex;
    margin-bottom: 8px;
}

.chat-family {
    justify-content: flex-end;
}

.chat-bubble {
    max-width: 85%;
    padding: 8px 12px;
    border-radius: 14px;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.chat-family .chat-bubble {
    background: var(--mud-palette-primary);
    color: var(--mud-palette-primary-text);
    border-bottom-right-radius: 4px;
}

.chat-assistant .chat-bubble {
    background: var(--mud-palette-background-gray);
    color: var(--mud-palette-text-primary);
    border-bottom-left-radius: 4px;
}

/* Meals page: the day column on the left of each planned meal. */
.meal-day {
    width: 3.75rem;
    flex-shrink: 0;
    line-height: 1.2;
}

.meal-date {
    font-size: 0.75rem;
}

.meal-today {
    background-color: var(--mud-palette-action-default-hover);
}

/* Shopping list: the small coloured letter showing who added an item. */
.added-by {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    font-size: 0.7rem;
    font-weight: 500;
    margin: 0 4px;
    flex-shrink: 0;
}

/* "Still connecting" bar, just under the top bar (MainLayout.razor). */
.connecting-bar {
    position: fixed !important;
    top: var(--mud-appbar-height);
    left: 0;
    right: 0;
    z-index: 1400;
}

/* Phones: no grey flash when tapping buttons and links, no "copy/share" pop-up on a long press of the bottom bar. */
* {
    -webkit-tap-highlight-color: transparent;
}

.bottom-nav {
    -webkit-touch-callout: none;
    user-select: none;
}

/* "Can't connect - tap to try again" (App.razor), shown at the top of the screen. */
.cant-connect {
    position: fixed;
    top: var(--mud-appbar-height);
    left: 8px;
    right: 8px;
    z-index: 1500;
    padding: 14px 16px;
    border-radius: 8px;
    background: #e65100;
    color: #fff;
    font-size: 15px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    cursor: pointer;
}

/* Calendar month view (MonthGrid.razor): 7 columns, Monday to Sunday. */
.month-grid {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    border-top: 1px solid var(--mud-palette-lines-default);
    border-left: 1px solid var(--mud-palette-lines-default);
}

.month-weekday {
    font-size: 0.75rem;
    text-align: center;
    padding: 4px 0;
    border-right: 1px solid var(--mud-palette-lines-default);
    border-bottom: 1px solid var(--mud-palette-lines-default);
}

.month-cell {
    /* a plain button that looks like a calendar square */
    display: flex;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    min-height: 96px;
    padding: 2px 3px 4px;
    border: none;
    border-right: 1px solid var(--mud-palette-lines-default);
    border-bottom: 1px solid var(--mud-palette-lines-default);
    background: var(--mud-palette-surface);
    color: var(--mud-palette-text-primary);
    font: inherit;
    text-align: left;
    cursor: pointer;
    overflow: hidden;
}

.month-cell:hover {
    background: var(--mud-palette-action-default-hover);
}

.month-cell.other-month {
    color: var(--mud-palette-text-disabled);
    background: var(--mud-palette-background-gray);
}

.month-cell.selected {
    outline: 2px solid var(--mud-palette-primary);
    outline-offset: -2px;
}

.month-daynum {
    align-self: flex-start;
    min-width: 1.6rem;
    height: 1.6rem;
    line-height: 1.6rem;
    border-radius: 50%;
    text-align: center;
    font-size: 0.875rem;
}

/* Today: the day number in a teal circle. */
.month-cell.today .month-daynum {
    background: var(--mud-palette-primary);
    color: var(--mud-palette-primary-text);
    font-weight: bold;
}

.month-event {
    display: block;
    font-size: 0.75rem;
    line-height: 1.3;
    margin-top: 2px;
    padding-left: 4px;
    border-left: 3px solid; /* coloured per family member */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.month-event-time {
    color: var(--mud-palette-text-secondary);
    margin-right: 3px;
}

/* Agenda / Month buttons joined together. */
.view-switch {
    display: inline-flex;
}

.view-switch .mud-button-root:first-child {
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
}

.view-switch .mud-button-root:last-child {
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
    margin-left: -1px;
}

.month-more {
    display: block;
    font-size: 0.7rem;
    margin-top: 2px;
}

.month-dots {
    display: none; /* only on phones, see below */
    flex-wrap: wrap;
    justify-content: center;
    gap: 3px;
    margin-top: 2px;
}

.month-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
}

.agenda-time {
    width: 6.5rem;
    flex-shrink: 0;
    font-size: 0.875rem;
    padding-top: 2px;
}

/* Family page: round colour buttons to pick a member's colour. */
.colour-swatch {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 2px solid transparent;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.colour-swatch.chosen {
    border-color: var(--mud-palette-text-primary);
    box-shadow: 0 0 0 2px var(--mud-palette-surface) inset;
}

/* ---- Sign-in pages (Components/Account) ----
   Plain form fields styled to look like the app's MudBlazor fields. */
.account-page {
    min-height: 100vh;
    background-color: var(--mud-palette-background-gray);
}

.account-topbar {
    display: flex;
    align-items: center;
    height: 56px;
    padding: 0 16px;
    background-color: var(--mud-palette-appbar-background);
    color: var(--mud-palette-appbar-text);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.account-topbar-title {
    font-size: 1.25rem;
    font-weight: 500;
}

.account-main {
    display: flex;
    justify-content: center;
    padding: 32px 16px;
}

.account-card {
    width: 100%;
    max-width: 420px;
}

.account-field {
    margin-bottom: 16px;
}

.account-field label {
    display: block;
    margin-bottom: 4px;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--mud-palette-text-secondary);
}

.account-input {
    width: 100%;
    box-sizing: border-box;
    padding: 12px 14px;
    font-size: 1rem; /* 16px stops phones zooming in when you tap the field */
    font-family: inherit;
    color: var(--mud-palette-text-primary);
    background-color: var(--mud-palette-surface);
    border: 1px solid var(--mud-palette-lines-inputs);
    border-radius: var(--mud-default-borderradius);
}

.account-input:focus {
    outline: none;
    border-color: var(--mud-palette-primary);
    box-shadow: 0 0 0 1px var(--mud-palette-primary);
}

.account-input.invalid {
    border-color: var(--mud-palette-error);
}

.account-hint {
    margin-top: 4px;
    font-size: 0.75rem;
    color: var(--mud-palette-text-secondary);
}

.account-field .validation-message {
    margin-top: 4px;
    font-size: 0.75rem;
    color: var(--mud-palette-error);
}

/* The "Log out" button in the menu looks like the other menu links. */
.logout-button {
    width: 100%;
    background: none;
    border: none;
    font: inherit;
    color: inherit;
    text-align: left;
    cursor: pointer;
}

/* Phones: pop-up dialogs use almost the whole width, so dates and times
   in the event dialog aren't cut off. */
@media (max-width: 599px) {
    .mud-dialog.mud-dialog-width-full {
        width: calc(100% - 16px);
    }

    .mud-dialog .mud-dialog-content {
        padding-left: 16px;
        padding-right: 16px;
    }

    /* Month view on a phone: smaller squares with dots instead of event text. */
    .month-cell {
        min-height: 52px;
        align-items: center;
    }

    .month-daynum {
        align-self: center;
    }

    .month-events {
        display: none;
    }

    .month-dots {
        display: flex;
    }
}
