:root {
    --bg: #f4efe7;
    --surface: #fffaf1;
    --surface-strong: #fff4dc;
    --ink: #241b13;
    --muted: #77695d;
    --line: #eadbc4;
    --accent: #b45309;
    --accent-dark: #7c2d12;
    --busy: #2563eb;
    --available: #0f766e;
    --off: #d8c8b5;
    --shadow: 0 24px 80px rgb(74 45 16 / 0.16);
    --radius-lg: 28px;
    --radius-md: 18px;
}

* {
    box-sizing: border-box;
}

body {
    min-height: 100vh;
    margin: 0;
    color: var(--ink);
    font-family: Georgia, "Noto Serif TC", "Songti TC", serif;
    background:
        radial-gradient(circle at top left, rgb(251 191 36 / 0.25), transparent 34rem),
        radial-gradient(circle at bottom right, rgb(20 184 166 / 0.18), transparent 30rem),
        linear-gradient(135deg, #fbf7ee 0%, var(--bg) 60%, #eee2cf 100%);
}

button,
input,
textarea {
    font: inherit;
}

button {
    color: inherit;
}

a {
    color: inherit;
    text-decoration: none;
}

.app-shell {
    width: min(1180px, calc(100% - 32px));
    margin: 0 auto;
    padding: 32px 0 48px;
}

.hero {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    margin-bottom: 20px;
}

.eyebrow {
    margin: 0 0 8px;
    color: var(--accent-dark);
    font-family: "Gill Sans", "Avenir Next", sans-serif;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.16em;
    text-transform: uppercase;
}

h1,
h2,
h3,
p {
    margin-top: 0;
}

h1 {
    margin-bottom: 8px;
    font-size: clamp(2.2rem, 6vw, 5rem);
    line-height: 0.94;
    letter-spacing: -0.06em;
}

h2 {
    margin-bottom: 4px;
    font-size: clamp(1.35rem, 4vw, 2.25rem);
}

h3 {
    margin-bottom: 0;
    font-size: 1.6rem;
}

h4 {
    margin: 18px 0 10px;
    font-size: 1.05rem;
}

.subtitle,
#activeMemberLabel,
.help-text,
.empty-note,
.field-label {
    color: var(--muted);
}

.icon-button,
.primary-button,
.ghost-button,
.small-button,
.switch-button,
.nav-button,
.member-button {
    border: 0;
    border-radius: 999px;
    cursor: pointer;
    transition: transform 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

.icon-button,
.primary-button {
    background: var(--ink);
    color: #fffaf1;
    box-shadow: 0 12px 30px rgb(36 27 19 / 0.18);
}

.icon-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 14px 20px;
    white-space: nowrap;
}

.primary-button {
    padding: 12px 18px;
}

.ghost-button,
.small-button,
.switch-button,
.nav-button {
    background: #ffffffb8;
    border: 1px solid var(--line);
}

button:hover {
    transform: translateY(-1px);
}

.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
}

.member-buttons {
    display: flex;
    flex: 1;
    gap: 10px;
    overflow-x: auto;
    padding-bottom: 4px;
}

.member-button {
    flex: 0 0 auto;
    padding: 11px 16px 11px 14px;
    background: #ffffffa6;
    border: 1px solid var(--line);
}

.member-button::before {
    display: inline-block;
    width: 10px;
    height: 10px;
    margin-right: 8px;
    border-radius: 50%;
    background: var(--member-color);
    content: "";
}

.member-button.active {
    background: var(--ink);
    color: #fffaf1;
}

.view-switch {
    display: inline-flex;
    padding: 4px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: rgb(255 250 241 / 0.72);
}

.switch-button {
    padding: 9px 14px;
    background: transparent;
}

.switch-button.active {
    background: var(--accent);
    color: #fffaf1;
}

.calendar-card {
    overflow: hidden;
    border: 1px solid rgb(234 219 196 / 0.9);
    border-radius: var(--radius-lg);
    background: rgb(255 250 241 / 0.86);
    box-shadow: var(--shadow);
    backdrop-filter: blur(14px);
}

.calendar-topbar {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 20px;
    padding: 22px;
    border-bottom: 1px solid var(--line);
}

.nav-button {
    width: 46px;
    height: 46px;
    font-size: 2rem;
    line-height: 1;
}

.calendar-area {
    padding: 18px;
}

.month-grid {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 10px;
}

.weekday {
    padding: 8px;
    color: var(--muted);
    font-family: "Gill Sans", "Avenir Next", sans-serif;
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-align: center;
}

.day-cell {
    min-height: 126px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    background: linear-gradient(180deg, #fffdf8 0%, #fff5e2 100%);
    text-align: left;
}

.day-cell.muted {
    opacity: 0.42;
}

.day-cell.today {
    border-color: var(--accent);
    box-shadow: inset 0 0 0 2px rgb(180 83 9 / 0.16);
}

.date-number {
    display: block;
    margin-bottom: 18px;
    font-size: 1.45rem;
    font-weight: 700;
}

.summary-line {
    display: block;
    width: fit-content;
    margin-top: 6px;
    padding: 4px 8px;
    border-radius: 999px;
    font-family: "Gill Sans", "Avenir Next", sans-serif;
    font-size: 0.72rem;
}

.summary-line.busy {
    background: rgb(37 99 235 / 0.12);
    color: var(--busy);
}

.summary-line.available {
    background: rgb(15 118 110 / 0.12);
    color: var(--available);
}

.week-grid {
    display: grid;
    min-width: 860px;
    grid-template-columns: 74px repeat(7, minmax(98px, 1fr));
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.week-corner,
.week-day-header,
.week-time,
.week-slot {
    min-height: 42px;
    border: 0;
    border-right: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
}

.week-corner,
.week-day-header,
.week-time {
    display: grid;
    place-items: center;
    background: var(--surface-strong);
    color: var(--muted);
    font-family: "Gill Sans", "Avenir Next", sans-serif;
    font-weight: 700;
}

.week-day-header.today {
    color: var(--accent-dark);
}

.week-slot {
    overflow: hidden;
    padding: 4px;
    font-size: 0.74rem;
    line-height: 1.25;
    text-overflow: ellipsis;
    white-space: pre-line;
}

.week-slot.off,
.day-slot.off {
    background: rgb(216 200 181 / 0.28);
    color: #8a7a67;
}

.week-slot.available,
.day-slot.available {
    background: rgb(15 118 110 / 0.13);
    color: var(--available);
}

.week-slot.busy,
.day-slot.busy {
    background: rgb(37 99 235 / 0.13);
    color: var(--busy);
}

.calendar-area:has(.week-grid) {
    overflow-x: auto;
}

.legend {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 16px;
    margin-top: 18px;
    color: var(--muted);
    font-family: "Gill Sans", "Avenir Next", sans-serif;
}

.dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    margin-right: 6px;
    border-radius: 50%;
}

.dot.busy {
    background: var(--busy);
}

.dot.available {
    background: var(--available);
}

.dot.off {
    background: var(--off);
}

.admin-badge {
    padding: 4px 10px;
    border-radius: 999px;
    background: var(--ink);
    color: #fffaf1;
}

.hidden {
    display: none !important;
}

.dialog {
    width: min(720px, calc(100% - 28px));
    padding: 0;
    border: 0;
    border-radius: 26px;
    background: transparent;
}

.dialog::backdrop {
    background: rgb(36 27 19 / 0.42);
    backdrop-filter: blur(5px);
}

.dialog-panel {
    padding: 24px;
    border: 1px solid var(--line);
    border-radius: 26px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.dialog-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
}

.add-member-row,
.member-editor-row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 10px;
}

.member-editor-row {
    grid-template-columns: 1fr auto auto;
    margin-top: 10px;
}

.booking-record-section {
    margin-top: 16px;
    border-top: 1px solid var(--line);
}

.booking-record-list {
    display: grid;
    gap: 10px;
    max-height: 260px;
    overflow: auto;
}

.booking-record {
    display: grid;
    gap: 5px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: #fffdf8;
}

.booking-record.cancel {
    border-color: rgb(185 28 28 / 0.22);
}

.booking-record strong,
.booking-record span,
.booking-record time {
    display: block;
}

.booking-record span,
.booking-record p,
.booking-record time {
    margin: 0;
    color: var(--muted);
    font-size: 0.86rem;
}

input {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: #fffdf8;
    color: var(--ink);
}

textarea {
    width: 100%;
    resize: vertical;
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: #fffdf8;
    color: var(--ink);
}

.field-label {
    display: block;
    margin-bottom: 8px;
    font-family: "Gill Sans", "Avenir Next", sans-serif;
    font-weight: 700;
}

.permission-note {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
    padding: 12px;
    border: 1px solid rgb(15 118 110 / 0.22);
    border-radius: 16px;
    background: rgb(15 118 110 / 0.08);
    color: var(--available);
}

.login-panel,
.admin-panel {
    margin-top: 8px;
}

.dialog-actions {
    display: flex;
    justify-content: flex-end;
    margin-top: 16px;
}

.small-button,
.ghost-button {
    padding: 10px 14px;
}

.danger {
    color: #b91c1c;
}

.danger-button {
    background: #b91c1c;
}

.day-panel {
    max-height: min(760px, 88vh);
    overflow: auto;
}

.day-slot-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(138px, 1fr));
    gap: 10px;
    margin-top: 16px;
}

.day-slot {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
    gap: 10px;
    min-height: 52px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 16px;
    cursor: pointer;
}

.day-slot span {
    overflow: hidden;
    justify-self: end;
    max-width: 100%;
    line-height: 1.3;
    text-overflow: ellipsis;
    white-space: pre-line;
}

.day-slot em {
    grid-column: 1 / -1;
    overflow: hidden;
    color: var(--muted);
    font-size: 0.82rem;
    font-style: normal;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.empty-calendar {
    display: grid;
    min-height: 280px;
    place-items: center;
    color: var(--muted);
    text-align: center;
}

.toast {
    position: fixed;
    right: 24px;
    top: 24px;
    z-index: 10000;
    max-width: min(360px, calc(100% - 48px));
    padding: 13px 18px;
    border-radius: 999px;
    background: var(--ink);
    color: #fffaf1;
    box-shadow: var(--shadow);
    opacity: 0;
    transform: translateY(-16px);
    transition: opacity 180ms ease, transform 180ms ease;
    pointer-events: none;
}

.toast.show {
    opacity: 1;
    transform: translateY(0);
}

@media (max-width: 760px) {
    .app-shell {
        width: min(100% - 20px, 1180px);
        padding-top: 18px;
    }

    .hero,
    .toolbar,
    .calendar-topbar {
        align-items: stretch;
        flex-direction: column;
    }

    .toolbar {
        display: block;
    }

    .member-buttons {
        margin-bottom: 12px;
    }

    .view-switch {
        width: 100%;
    }

    .switch-button {
        flex: 1;
    }

    .calendar-topbar {
        display: flex;
        text-align: center;
    }

    .nav-button {
        width: 100%;
    }

    .month-grid {
        gap: 6px;
    }

    .weekday {
        font-size: 0.7rem;
    }

    .day-cell {
        min-height: 94px;
        padding: 8px;
        border-radius: 14px;
    }

    .date-number {
        margin-bottom: 10px;
        font-size: 1rem;
    }

    .summary-line {
        max-width: 100%;
        overflow: hidden;
        padding: 3px 6px;
        font-size: 0.64rem;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .add-member-row,
    .member-editor-row {
        grid-template-columns: 1fr;
    }

    .permission-note {
        align-items: stretch;
        flex-direction: column;
    }

    .toast {
        right: 12px;
        top: 12px;
        max-width: calc(100% - 24px);
    }
}
