/* ---------- Base ---------- */

/* Fallback colours (before the theme has loaded) follow the OS setting */
:root {
    --bt-bg: #F6F5F3;
    --bt-fg: #1C1917;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bt-bg: #0F172A;
        --bt-fg: #F1F5F9;
    }
}

/* Once loaded, always use the theme's colours, so the in-app light/dark choice wins over the OS setting */
html, body {
    margin: 0;
    background: var(--mud-palette-background, var(--bt-bg));
    color: var(--mud-palette-text-primary, var(--bt-fg));
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
}

/* Never scroll sideways on a phone */
body {
    overflow-x: hidden;
}

/* Native <button> tiles need the page font, not the browser default */
button {
    font-family: inherit;
}

#blazor-error-ui {
    display: none;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 2000;
    padding: 0.75rem 1.25rem calc(0.75rem + env(safe-area-inset-bottom));
    background: #FEF3C7;
    color: #1C1917;
    box-shadow: 0 -1px 4px rgba(0, 0, 0, 0.3);
}

#blazor-error-ui .reload {
    margin-left: 0.5rem;
}

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

/* ---------- App shell ---------- */

/* Keep the app bar clear of the notch / status bar when installed on the home screen */
.bt-appbar {
    padding-top: env(safe-area-inset-top);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
    height: auto;
    border-bottom: 1px solid var(--mud-palette-lines-default);
}

.bt-appbar .mud-toolbar {
    min-height: 56px;
    gap: 4px;
}

.bt-brand {
    font-weight: 700;
    letter-spacing: 0.2px;
    margin-right: 12px;
}

.bt-drawer {
    border-right: 1px solid var(--mud-palette-lines-default);
}

.bt-main {
    min-height: 100dvh;
}

/* Room for the bottom tab bar (phones only) */
@media (max-width: 959.95px) {
    .bt-main.bt-has-bottom-nav {
        padding-bottom: calc(72px + env(safe-area-inset-bottom));
    }
}

.bt-page-loader {
    display: flex;
    justify-content: center;
    padding: 4rem 0;
}

.bt-ellipsis {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}

.bt-avatar-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    min-height: 44px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: none;
    color: inherit;
    cursor: pointer;
}

.bt-avatar-button:focus-visible {
    outline: 3px solid var(--mud-palette-primary);
    outline-offset: 2px;
}

.bt-user-menu {
    min-width: 240px;
}

/* ---------- Chosen company + project in the app bar ---------- */

.bt-context-chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    max-width: min(320px, calc(100vw - 130px));
    min-height: 44px;
    padding: 4px 10px;
    border-radius: 999px;
    border: 1px solid rgba(248, 250, 252, 0.25);
    color: inherit;
    text-decoration: none;
}

.bt-context-chip:hover {
    background: rgba(248, 250, 252, 0.08);
}

.bt-context-chip__text {
    display: flex;
    flex-direction: column;
    min-width: 0;
    line-height: 1.15;
}

.bt-context-chip__project,
.bt-context-chip__company {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.bt-context-chip__project {
    font-size: 0.875rem;
    font-weight: 500;
}

.bt-context-chip__company {
    font-size: 0.7rem;
    opacity: 0.75;
}

/* ---------- Bottom tab bar (phones) ---------- */

.bt-bottom-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1100;
    display: flex;
    background: var(--mud-palette-surface);
    border-top: 1px solid var(--mud-palette-lines-default);
    padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.bt-bottom-nav__item {
    flex: 1 1 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-height: 60px;
    color: var(--mud-palette-text-secondary);
    text-decoration: none;
    font-size: 0.75rem;
    font-weight: 500;
}

/* Every icon gets the same box so labels line up; only the active one is filled */
.bt-bottom-nav__item .mud-icon-root {
    border-radius: 999px;
    width: 56px;
    height: 30px;
    padding: 3px 16px;
    box-sizing: border-box;
}

.bt-bottom-nav__item.active {
    color: var(--mud-palette-primary);
}

.bt-bottom-nav__item.active .mud-icon-root {
    background: color-mix(in srgb, var(--mud-palette-primary) 16%, transparent);
}

/* Keep toasts above the tab bar on phones */
@media (max-width: 959.95px) {
    body:has(.bt-bottom-nav) .mud-snackbar-location-bottom-center {
        bottom: calc(76px + env(safe-area-inset-bottom));
    }
}

/* Slightly smaller page titles on phones */
@media (max-width: 599.95px) {
    .mud-typography-h4 {
        font-size: 1.75rem;
    }
}

/* ---------- Big tap targets: tiles ---------- */

.bt-tiles {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.bt-group-title {
    display: block;
    margin: 4px 4px 6px;
}

.bt-tile {
    display: flex;
    align-items: center;
    gap: 14px;
    width: 100%;
    min-height: 72px;
    padding: 12px 16px;
    text-align: left;
    cursor: pointer;
    color: var(--mud-palette-text-primary);
    background: var(--mud-palette-surface);
    border: 1px solid var(--mud-palette-lines-default);
    border-radius: var(--mud-default-borderradius);
    font-size: 1rem;
    transition: border-color 0.15s, background 0.15s, transform 0.05s;
}

.bt-tile:hover {
    border-color: var(--mud-palette-primary);
}

.bt-tile:active {
    transform: scale(0.99);
}

.bt-tile:focus-visible {
    outline: 3px solid var(--mud-palette-primary);
    outline-offset: 2px;
}

.bt-tile--current {
    border-color: var(--mud-palette-primary);
    background: color-mix(in srgb, var(--mud-palette-primary) 8%, var(--mud-palette-surface));
}

.bt-tile--action {
    border-color: var(--mud-palette-primary);
}

.bt-tile__body {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-width: 0;
}

.bt-tile__title {
    font-weight: 500;
    font-size: 1.0625rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.bt-tile__sub {
    font-size: 0.875rem;
    color: var(--mud-palette-text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ---------- Work shift row ---------- */

.bt-shift {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 16px;
    min-height: 72px;
}

/* Shift details may wrap instead of being cut off */
.bt-shift .bt-tile__sub {
    white-space: normal;
}

.bt-shift__date {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex: 0 0 48px;
    line-height: 1.1;
}

.bt-shift__day {
    font-size: 1.5rem;
    font-weight: 700;
}

.bt-shift__month {
    font-size: 0.75rem;
    text-transform: uppercase;
    color: var(--mud-palette-text-secondary);
}

/* ---------- Landing page ---------- */

.bt-hero {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 12vh 0 4vh;
}

.bt-hero__icon {
    width: 88px;
    height: 88px;
}

.bt-hero__cta {
    max-width: 360px;
}

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

/* 16px+ inputs so iOS Safari doesn't zoom the page on focus */
.bt-form input,
.bt-form textarea {
    font-size: 1rem;
}

/* CSS for loader at startup */

/* Container centered both horizontally and vertically */
.bt-center-container {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    height: 100%;
    min-height: 100vh;
}

/* Loader box styles and shared div styles inside the loader */
.bt-loader,
.bt-loader div {
    box-sizing: border-box;
}

/* Loader main container */
.bt-loader {
    display: inline-block;
    position: relative;
    width: 80px;
    height: 80px;
}

.bt-loader div {
    display: inline-block;
    position: absolute;
    left: 8px;
    width: 16px;
    background: currentColor;
    animation: bt-loader 1.2s cubic-bezier(0, 0.5, 0.5, 1) infinite;
}

.bt-loader div:nth-child(1) {
    left: 8px;
    animation-delay: -0.24s;
}

.bt-loader div:nth-child(2) {
    left: 32px;
    animation-delay: -0.12s;
}

.bt-loader div:nth-child(3) {
    left: 56px;
    animation-delay: 0s;
}

@keyframes bt-loader {
    0% {
        top: 8px;
        height: 64px;
    }
    50%, 100% {
        top: 24px;
        height: 32px;
    }
}


/* ---------- Feels like an app ---------- */

/* No 300 ms wait or zoom on a double tap on things that can be pressed (zooming with two fingers still works) */
a, button, input, select, textarea, label, summary, [role="button"], .mud-button-root, .mud-nav-link, .bt-tile {
    touch-action: manipulation;
}

/* Only when it has been added to the home screen (no browser frame around it) */
@media (display-mode: standalone) {
    /* No pull to refresh and no rubber band bounce at the top and bottom of the page */
    html, body {
        overscroll-behavior-y: none;
    }

    /* Menus, buttons and tiles are not text: no selection handles or magnifier when a finger rests on them */
    .bt-appbar, .bt-bottom-nav, .mud-drawer, .mud-nav-link, .mud-button-root, .mud-chip, .bt-tile, .bt-shift {
        -webkit-user-select: none;
        user-select: none;
        -webkit-touch-callout: none;
    }
}
