/*
    Rental Calendar — mobile-first stylesheet.

    Written for a phone held in one hand and scaled up from there, rather than a desktop
    layout squeezed down. The rules that matter most on a real device:

      - 16px minimum on form controls, or iOS Safari zooms the page on focus.
      - 44px minimum on anything tappable (Apple's HIG figure).
      - env(safe-area-inset-*) so the fixed tab bar clears the home indicator.
      - Nothing wider than the viewport: the page never scrolls sideways.
*/

:root {
    --accent: #512bd4;
    --accent-contrast: #ffffff;
    --danger: #b3261e;
    --warning: #b26a00;

    --bg: #f6f6f8;
    --surface: #ffffff;
    --surface-alt: #f0f0f4;
    --text: #16161a;
    --text-muted: #6b6b76;
    --border: #e0e0e6;

    --today: #f59e0b;

    --radius: 12px;
    --radius-sm: 8px;

    --tabbar-height: 56px;
    --header-height: 52px;
    --tap: 44px;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #121216;
        --surface: #1c1c22;
        --surface-alt: #24242c;
        --text: #f2f2f5;
        --text-muted: #a0a0ad;
        --border: #34343e;
    }
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    /* Stops iOS bumping text size when the device is rotated. */
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 16px;
    line-height: 1.45;
    /* Keeps a rubber-band scroll from dragging the whole page around. */
    overscroll-behavior-y: contain;
}

/* Removes the grey flash Android draws over tapped elements. */
a,
button,
[role="button"] {
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

h1 {
    font-size: 1.35rem;
    margin: 0 0 0.75rem;
}

h1:focus {
    outline: none;
}

/*
    Pages whose title already shows in the sticky header still need an <h1> — it is the
    focus target after navigation and the document's outline for screen readers. This
    keeps it available to assistive tech without drawing it twice.
*/
.visually-hidden-heading {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
}

h2 {
    font-size: 1.05rem;
    margin: 0 0 0.5rem;
}

a {
    color: var(--accent);
}

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

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

.app-header {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-height: var(--header-height);
    padding: 0 0.75rem;
    padding-top: env(safe-area-inset-top);
    background: color-mix(in srgb, var(--surface) 88%, transparent);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
}

.app-header .title {
    flex: 1;
    font-weight: 600;
    font-size: 1rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.app-header .back {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: var(--tap);
    min-height: var(--tap);
    margin-left: -0.5rem;
    border: 0;
    background: none;
    color: var(--accent);
    font-size: 1.5rem;
    cursor: pointer;
    text-decoration: none;
}

.app-main {
    flex: 1;
    width: 100%;
    max-width: 760px;
    margin: 0 auto;
    padding: 0.75rem;
    /* Clears the fixed tab bar plus the home indicator. */
    padding-bottom: calc(var(--tabbar-height) + env(safe-area-inset-bottom) + 1rem);
}

.app-main.no-tabbar {
    padding-bottom: calc(env(safe-area-inset-bottom) + 1rem);
}

/* ---- Bottom tab bar ----------------------------------------------------- */

.tabbar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 30;
    display: flex;
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    backdrop-filter: blur(12px);
    border-top: 1px solid var(--border);
    padding-bottom: env(safe-area-inset-bottom);
}

.tabbar a {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-height: var(--tabbar-height);
    padding: 6px 2px;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.7rem;
    font-weight: 500;
}

.tabbar a.active {
    color: var(--accent);
}

.tabbar .icon {
    font-size: 1.15rem;
    line-height: 1;
}

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

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    min-height: var(--tap);
    padding: 0.5rem 1rem;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    background: var(--accent);
    color: var(--accent-contrast);
    font-size: 1rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    text-decoration: none;
}

.btn:disabled {
    opacity: 0.5;
    cursor: default;
}

.btn-block {
    width: 100%;
}

.btn-secondary {
    background: transparent;
    color: var(--accent);
    border-color: var(--border);
}

.btn-danger {
    background: transparent;
    color: var(--danger);
    border-color: var(--danger);
}

.btn-small {
    min-height: 34px;
    padding: 0.25rem 0.7rem;
    font-size: 0.8rem;
    font-weight: 500;
}

/* Floating action button, kept in thumb reach above the tab bar. */
.fab {
    position: fixed;
    right: 1rem;
    bottom: calc(var(--tabbar-height) + env(safe-area-inset-bottom) + 1rem);
    z-index: 25;
    width: 56px;
    height: 56px;
    min-height: 56px;
    padding: 0;
    border-radius: 50%;
    font-size: 1.75rem;
    font-weight: 400;
    box-shadow: 0 4px 14px rgb(0 0 0 / 0.25);
}

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

.field {
    display: block;
    margin-bottom: 1rem;
}

.field > label,
.label {
    display: block;
    margin-bottom: 0.25rem;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-muted);
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="date"],
input[type="number"],
input[type="url"],
select,
textarea {
    width: 100%;
    min-height: var(--tap);
    padding: 0.55rem 0.7rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    /* 16px exactly — anything smaller makes iOS Safari zoom in on focus. */
    font-size: 1rem;
    font-family: inherit;
}

textarea {
    min-height: 5rem;
    resize: vertical;
}

input:focus-visible,
select:focus-visible,
textarea:focus-visible,
.btn:focus-visible,
.chip:focus-visible,
.day:focus-visible,
.booking:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

input[type="date"] {
    appearance: none;
    -webkit-appearance: none;
}

.field-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
}

.validation-message {
    display: block;
    margin-top: 0.25rem;
    color: var(--danger);
    font-size: 0.8rem;
}

/* ---- Toggle switch ----------------------------------------------------- */

.switch-row {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    min-height: var(--tap);
    padding: 0.15rem 0;
}

.switch-row .swatch {
    flex: 0 0 auto;
    width: 6px;
    height: 22px;
    border-radius: 3px;
}

.switch-row .name {
    flex: 1;
}

.switch {
    position: relative;
    flex: 0 0 auto;
    width: 48px;
    height: 30px;
}

.switch input {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    opacity: 0;
    cursor: pointer;
}

.switch .track {
    position: absolute;
    inset: 0;
    border-radius: 999px;
    background: var(--surface-alt);
    border: 1px solid var(--border);
    transition: background 0.15s ease;
    pointer-events: none;
}

.switch .track::after {
    content: "";
    position: absolute;
    top: 3px;
    left: 3px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--surface);
    box-shadow: 0 1px 3px rgb(0 0 0 / 0.3);
    transition: transform 0.15s ease;
}

.switch input:checked + .track {
    background: var(--accent);
    border-color: var(--accent);
}

.switch input:checked + .track::after {
    transform: translateX(18px);
}

.switch input:focus-visible + .track {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* ---- Cards and notices ------------------------------------------------- */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.9rem;
    margin-bottom: 0.75rem;
}

.muted {
    color: var(--text-muted);
    font-size: 0.85rem;
}

.notice {
    padding: 0.7rem 0.85rem;
    border-radius: var(--radius-sm);
    border: 1px solid;
    margin-bottom: 0.75rem;
    font-size: 0.9rem;
}

.notice-error {
    color: var(--danger);
    border-color: var(--danger);
    background: color-mix(in srgb, var(--danger) 8%, transparent);
}

.notice-warning {
    color: var(--warning);
    border-color: var(--warning);
    background: color-mix(in srgb, var(--warning) 10%, transparent);
}

.notice-ok {
    color: var(--accent);
    border-color: var(--accent);
    background: color-mix(in srgb, var(--accent) 8%, transparent);
}

/* ---- Calendar ---------------------------------------------------------- */

.month-nav {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    margin-bottom: 0.5rem;
}

.month-nav .month-title {
    flex: 1;
    margin: 0;
    text-align: center;
    font-size: 1.1rem;
    font-weight: 600;
}

.month-nav button {
    min-width: var(--tap);
    min-height: var(--tap);
    padding: 0;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--accent);
    font-size: 1.3rem;
    font-family: inherit;
    cursor: pointer;
}

/* Chip strip scrolls sideways rather than wrapping if more houses appear. */
.house-filters {
    display: flex;
    gap: 0.5rem;
    overflow-x: auto;
    padding-bottom: 0.5rem;
    scrollbar-width: none;
}

.house-filters::-webkit-scrollbar {
    display: none;
}

.chip {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    min-height: 36px;
    padding: 0 0.85rem;
    border-radius: 999px;
    border: 1px solid;
    background: transparent;
    color: var(--text);
    font-size: 0.85rem;
    font-family: inherit;
    cursor: pointer;
    white-space: nowrap;
}

.chip.selected {
    border-width: 2px;
    font-weight: 600;
}

.weekdays,
.days {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    /* Tight, so consecutive booked days almost join up. */
    gap: 1px;
}

.weekdays div {
    padding: 0.25rem 0;
    text-align: center;
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-muted);
}

.day {
    /* Keeps cells roughly square whatever the phone width, so the grid never
       overflows and every day stays comfortably tappable. */
    aspect-ratio: 1 / 1.25;
    min-height: 56px;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 2px;
    /* Only 1px at the sides, so a multi-day booking reads as one continuous band
       across consecutive days rather than a row of separate dashes. */
    padding: 3px 1px 4px;
    border: 1.5px solid transparent;
    border-radius: var(--radius-sm);
    background: transparent;
    color: inherit;
    font-family: inherit;
    cursor: pointer;
    overflow: hidden;
}

.day.weekend {
    background: color-mix(in srgb, var(--text) 5%, transparent);
}

.day.today {
    border-color: var(--today);
}

.day.selected {
    border-color: var(--accent);
    background: color-mix(in srgb, var(--accent) 14%, transparent);
}

.day .num {
    text-align: center;
    font-size: 0.8rem;
    line-height: 1.2;
}

.day.outside .num {
    opacity: 0.35;
}

.day.today .num {
    font-weight: 700;
}

/*
    Sits directly under the day number rather than at the foot of the cell. Pinned to the
    bottom, a bar ends up closer to the next week's number than to its own date, and reads
    as belonging to the row below.
*/
.day .bars {
    margin-top: 2px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

/*
    One row per house, two columns wide, so a booking can occupy half a day — which is what
    makes a changeover (one party out, the next in) legible.

    The column gap separates the two halves of a changeover so they read as two bookings
    rather than one bar. A full day spans both tracks and covers the gutter, so it stays
    unbroken.
*/
.day .bar-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    column-gap: 5px;
    height: 11px;
}

.day .seg {
    height: 11px;
    border-radius: 2px;
}

/* ---- Booking list ------------------------------------------------------ */

.list-heading {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin: 1rem 0 0.5rem;
}

.list-heading h2 {
    flex: 1;
    margin: 0;
}

.booking {
    display: flex;
    align-items: stretch;
    width: 100%;
    padding: 0;
    margin-bottom: 0.5rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    text-align: left;
    font-family: inherit;
    color: inherit;
    cursor: pointer;
}

/* One band per house — a whole-property booking shows both colours. */
.booking .stripes {
    flex: 0 0 6px;
    display: flex;
    flex-direction: column;
}

.booking .stripes span {
    flex: 1;
}

.booking .body {
    flex: 1;
    min-width: 0;
    padding: 0.65rem 0.8rem;
}

.booking .top {
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
}

.booking .guest {
    flex: 1;
    min-width: 0;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.booking .price {
    flex: 0 0 auto;
    font-size: 0.9rem;
}

.booking .meta {
    display: flex;
    gap: 0.5rem;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.booking .meta .houses {
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.booking .notes {
    font-size: 0.8rem;
    color: var(--text-muted);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.empty {
    padding: 1.5rem 0;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.9rem;
}

/* ---- Sign-in ----------------------------------------------------------- */

.login {
    max-width: 380px;
    margin: 0 auto;
    padding-top: 2rem;
}

.login h1 {
    text-align: center;
    font-size: 1.6rem;
}

.login .lead {
    text-align: center;
    margin-bottom: 1.5rem;
}

/* ---- Users ------------------------------------------------------------- */

.user-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.user-row .who {
    flex: 1;
    min-width: 0;
}

.user-row .who strong {
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.badge {
    display: inline-block;
    padding: 0.1rem 0.5rem;
    border-radius: 999px;
    font-size: 0.7rem;
    font-weight: 600;
    background: var(--surface-alt);
    color: var(--text-muted);
}

.badge.admin {
    background: color-mix(in srgb, var(--accent) 15%, transparent);
    color: var(--accent);
}

.badge.inactive {
    background: color-mix(in srgb, var(--danger) 12%, transparent);
    color: var(--danger);
}

/* ---- Wider screens ----------------------------------------------------- */

@media (min-width: 700px) {
    :root {
        --header-height: 58px;
    }

    .app-main {
        padding: 1.25rem;
        padding-bottom: calc(var(--tabbar-height) + env(safe-area-inset-bottom) + 1.5rem);
    }

    .day {
        aspect-ratio: 1 / 0.85;
    }

    .day .num {
        font-size: 0.9rem;
    }

    .day .bar-row,
    .day .seg {
        height: 13px;
    }
}
