:root {
    --bg: #f4f6f9;
    --surface: #ffffff;
    --surface-muted: #f8fafc;
    --border: #dfe5ec;
    --text: #1a2431;
    --text-muted: #64748b;
    --accent: #1e5eff;
    --accent-soft: #e8efff;
    --danger: #c0392b;
    --radius: 12px;
    --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 8px 24px rgba(15, 23, 42, .06);
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC",
        "PingFang TC", "Microsoft JhengHei", Helvetica, Arial, sans-serif;
}

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

/* Panes, lists and the QR figure set their own display, which would
   otherwise win over the user-agent rule for the hidden attribute. */
[hidden] {
    display: none !important;
}

html,
body {
    height: 100%;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.5;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* ---------- Top bar ---------- */

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 20px;
    padding: 14px 24px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    box-shadow: 0 1px 3px rgba(15, 23, 42, .04);
}

.topbar__brand {
    display: flex;
    align-items: baseline;
    gap: 10px;
    padding-right: 20px;
    border-right: 1px solid var(--border);
}

.brand__mark {
    font-size: 13px;
    font-weight: 700;
    letter-spacing: .12em;
    color: var(--accent);
    background: var(--accent-soft);
    border-radius: 6px;
    padding: 4px 8px;
}

.brand__name {
    font-size: 15px;
    font-weight: 600;
    letter-spacing: .04em;
}

.topbar__fields {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 16px;
    flex: 1 1 auto;
    min-width: 0;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}

.field__label {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: .08em;
    color: var(--text-muted);
    text-transform: uppercase;
}

.field__control {
    appearance: none;
    min-width: 180px;
    max-width: 240px;
    padding: 8px 30px 8px 12px;
    font: inherit;
    font-variant-numeric: tabular-nums;
    color: var(--text);
    background: var(--surface)
        url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath fill='%2364748b' d='M0 0h10L5 6z'/%3E%3C/svg%3E")
        no-repeat right 12px center;
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
}

.field__control:disabled {
    opacity: .55;
    cursor: default;
}

.field__control:focus-visible,
.option:focus-visible,
.button:focus-visible,
.list__item--group:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.field__control--event {
    min-width: 240px;
    max-width: 340px;
}

/* Event phase badge (進行中 / 即將開始 / 已結束). */
.phase {
    align-self: flex-end;
    margin-bottom: 9px;
    padding: 3px 9px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .04em;
    border-radius: 999px;
    white-space: nowrap;
}

.phase--ongoing {
    color: #0a6b3d;
    background: #dcf5e7;
}

.phase--upcoming {
    color: #8a5a00;
    background: #fdf0d5;
}

.phase--ended {
    color: var(--text-muted);
    background: #eceff3;
}

/* ---------- Date picker ---------- */

.datepicker {
    position: relative;
}

.datepicker__button {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    min-width: 190px;
    /* .field__control paints a chevron background for <select>; this button
       draws its own, so drop the background image and its reserved padding. */
    padding-right: 12px;
    background-image: none;
    text-align: left;
}

.datepicker__value {
    font-variant-numeric: tabular-nums;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.datepicker__chevron {
    flex: 0 0 auto;
    width: 0;
    height: 0;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-top: 6px solid var(--text-muted);
}

.datepicker__popover {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    z-index: 40;
    width: 300px;
    padding: 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 12px 32px rgba(15, 23, 42, .16);
}

.datepicker__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 10px;
}

.datepicker__month {
    font-size: 14px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.datepicker__nav {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    font-size: 18px;
    line-height: 1;
    color: var(--text-muted);
    background: transparent;
    border: 1px solid transparent;
    border-radius: 7px;
    cursor: pointer;
}

.datepicker__nav:hover {
    color: var(--accent);
    background: var(--accent-soft);
}

.datepicker__nav:focus-visible,
.datepicker__day:focus-visible,
.datepicker__link:focus-visible,
.datepicker__button:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.datepicker__weekdays,
.datepicker__grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 3px;
}

.datepicker__weekdays {
    margin-bottom: 4px;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-align: center;
}

.datepicker__day {
    position: relative;
    aspect-ratio: 1 / 1;
    display: flex;
    align-items: center;
    justify-content: center;
    font: inherit;
    font-size: 13px;
    font-variant-numeric: tabular-nums;
    color: var(--text);
    background: transparent;
    border: 1px solid transparent;
    border-radius: 7px;
    cursor: pointer;
}

.datepicker__day:hover {
    background: var(--surface-muted);
}

/* Days outside the displayed month: visible but quieter. */
.datepicker__day--outside {
    color: #b6c0cd;
}

/* A date that has at least one event. */
.datepicker__day--has-events {
    font-weight: 700;
    color: var(--accent);
    background: var(--accent-soft);
}

.datepicker__day--has-events:hover {
    background: #d8e5ff;
}

/* Dot marker so the state is not carried by colour alone. */
.datepicker__day--has-events::after {
    content: "";
    position: absolute;
    bottom: 4px;
    left: 50%;
    width: 4px;
    height: 4px;
    margin-left: -2px;
    background: currentColor;
    border-radius: 50%;
}

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

.datepicker__day--selected,
.datepicker__day--selected:hover {
    color: #fff;
    background: var(--accent);
    border-color: var(--accent);
}

.datepicker__day--selected::after {
    background: #fff;
}

.datepicker__day:disabled {
    color: #cdd5df;
    background: transparent;
    cursor: default;
}

.datepicker__footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--border);
    font-size: 12px;
    color: var(--text-muted);
}

.datepicker__count {
    font-variant-numeric: tabular-nums;
}

.datepicker__link {
    padding: 2px 6px;
    font: inherit;
    font-size: 12px;
    font-weight: 600;
    color: var(--accent);
    background: transparent;
    border: 0;
    border-radius: 5px;
    cursor: pointer;
}

.datepicker__link:hover {
    background: var(--accent-soft);
}

@media (max-width: 760px) {
    .datepicker__button {
        min-width: 0;
        width: 100%;
    }

    .datepicker__popover {
        width: min(300px, calc(100vw - 48px));
    }
}

.topbar__options {
    display: flex;
    gap: 6px;
    padding: 4px;
    background: var(--surface-muted);
    border: 1px solid var(--border);
    border-radius: 10px;
    margin-left: auto;
}

.option {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 7px 14px;
    font: inherit;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-muted);
    background: transparent;
    border: 1px solid transparent;
    border-radius: 7px;
    cursor: pointer;
    white-space: nowrap;
    transition: background .15s ease, color .15s ease, box-shadow .15s ease;
}

.option:hover {
    color: var(--text);
    background: #eef2f7;
}

.option[aria-pressed="true"] {
    color: var(--accent);
    background: var(--surface);
    border-color: var(--border);
    box-shadow: 0 1px 2px rgba(15, 23, 42, .08);
}

.option__icon {
    font-size: 13px;
    line-height: 1;
}

.button {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 9px 15px;
    font: inherit;
    font-size: 13px;
    font-weight: 600;
    color: #fff;
    background: var(--accent);
    border: 1px solid transparent;
    border-radius: 8px;
    cursor: pointer;
    transition: filter .15s ease, opacity .15s ease;
}

.button:hover {
    filter: brightness(1.07);
}

.button:disabled {
    opacity: .5;
    cursor: default;
    filter: none;
}

.button__icon {
    font-size: 14px;
    display: inline-block;
}

.button--refresh.is-spinning .button__icon {
    animation: spin .8s linear infinite;
}

/* ---------- Panes ---------- */

.panes {
    flex: 1 1 auto;
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
    padding: 20px 24px 28px;
    align-items: start;
}

/* Columns track the number of visible panes so they always fill the row. */
.panes--1 {
    grid-template-columns: minmax(0, 1fr);
}

.panes--2 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.panes--3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.panes__empty {
    grid-column: 1 / -1;
    margin: 0;
    padding: 72px 24px;
    text-align: center;
    color: var(--text-muted);
    font-size: 14px;
}

.pane {
    display: flex;
    flex-direction: column;
    min-height: 320px;
    max-height: calc(100vh - 150px);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.pane__header {
    padding: 16px 20px 12px;
    border-bottom: 1px solid var(--border);
    background: var(--surface-muted);
}

.pane__title {
    margin: 0;
    font-size: 15px;
    font-weight: 700;
    display: flex;
    align-items: baseline;
    gap: 8px;
}

.pane__subtitle {
    font-size: 13px;
    font-weight: 500;
    color: var(--accent);
}

.pane__hint {
    margin: 4px 0 0;
    font-size: 12px;
    color: var(--text-muted);
}

.pane__body {
    flex: 1 1 auto;
    padding: 16px 20px;
    min-height: 0;
}

.pane__body--scroll {
    overflow-y: auto;
    padding: 8px 12px 12px;
}

.pane__footer {
    padding: 10px 20px;
    border-top: 1px solid var(--border);
    background: var(--surface-muted);
    font-size: 12px;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
    display: flex;
    justify-content: space-between;
    gap: 12px;
}

.pane__summary {
    white-space: nowrap;
}

/* ---------- QR pane ---------- */

.qr {
    margin: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}

.qr__canvas {
    width: min(100%, 320px);
    aspect-ratio: 1 / 1;
    padding: 14px;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 10px;
}

.qr__canvas svg {
    display: block;
    width: 100%;
    height: 100%;
}

.qr__caption {
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-width: 100%;
}

.qr__link {
    font-size: 12px;
    color: var(--accent);
    word-break: break-all;
}

.qr__meta {
    font-size: 12px;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}

/* ---------- Lists ---------- */

.list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.list__item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 12px;
    border-radius: 8px;
    border: 1px solid transparent;
    font-variant-numeric: tabular-nums;
}

.list__item + .list__item {
    border-top-color: var(--border);
    border-radius: 0;
}

.list__item--group {
    width: 100%;
    font: inherit;
    color: inherit;
    text-align: left;
    background: transparent;
    cursor: pointer;
    transition: background .12s ease, border-color .12s ease;
}

.list__item--group:hover {
    background: var(--surface-muted);
}

.list__item--group.is-active {
    background: var(--accent-soft);
    border-color: #c9d9ff;
    border-radius: 8px;
}

.list__item--group.is-active .list__name {
    color: var(--accent);
    font-weight: 600;
}

.list__name {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.list__count {
    flex: 0 0 auto;
    min-width: 32px;
    text-align: right;
    font-size: 14px;
    font-weight: 700;
    color: var(--accent);
}

.list__badge {
    flex: 0 0 auto;
    padding: 2px 8px;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    background: #eef2f7;
    border-radius: 999px;
}

.list--members .list__item {
    gap: 14px;
}

.list__time {
    flex: 0 0 auto;
    font-size: 13px;
    color: var(--text-muted);
    white-space: nowrap;
}

.list__index {
    flex: 0 0 24px;
    font-size: 11px;
    color: var(--text-muted);
    text-align: right;
}

/* ---------- States ---------- */

.state {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 40px 16px;
    color: var(--text-muted);
    font-size: 13px;
    text-align: center;
}

.state--error {
    color: var(--danger);
}

.state--empty {
    color: var(--text-muted);
}

.spinner {
    width: 16px;
    height: 16px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin .7s linear infinite;
    flex: 0 0 auto;
}

.toast {
    position: fixed;
    left: 50%;
    bottom: 24px;
    transform: translateX(-50%);
    z-index: 50;
    padding: 10px 18px;
    font-size: 13px;
    color: #fff;
    background: #1f2937;
    border-radius: 8px;
    box-shadow: 0 10px 30px rgba(15, 23, 42, .25);
    animation: toast-in .2s ease;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

@keyframes toast-in {
    from {
        opacity: 0;
        transform: translate(-50%, 8px);
    }
    to {
        opacity: 1;
        transform: translate(-50%, 0);
    }
}

@media (max-width: 760px) {
    .topbar {
        padding: 12px 16px;
    }

    .topbar__brand {
        border-right: 0;
        padding-right: 0;
    }

    .topbar__fields {
        gap: 12px;
    }

    .field__control {
        min-width: 0;
        width: 100%;
        max-width: none;
    }

    .field {
        flex: 1 1 140px;
    }

    .topbar__options {
        order: 3;
        width: 100%;
        margin-left: 0;
    }

    .option {
        flex: 1 1 0;
        justify-content: center;
    }

    #refresh-button {
        order: 4;
        width: 100%;
        justify-content: center;
    }

    .panes,
    .panes--1,
    .panes--2,
    .panes--3 {
        grid-template-columns: minmax(0, 1fr);
        padding: 14px 16px 24px;
    }

    .pane {
        max-height: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: .01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .01ms !important;
    }
}
