/*
 * Floating UI: popovers, menus, dropdowns, date picker, modals, tooltips.
 * Popovers live in the top layer; floating.js sets top/left, phones dock data-mobile="sheet" panels.
 */
.float {
    position: fixed;
    inset: auto;
    margin: 0;
    padding: var(--space-2);
    min-width: max(220px, var(--anchor-width, 0px));
    max-width: min(360px, calc(100vw - 16px));
    max-height: min(420px, 70dvh);
    overflow: auto;
    overscroll-behavior: contain;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-m);
    background: var(--bg-raised);
    color: var(--text);
    box-shadow: var(--shadow-2);
    opacity: 0;
    translate: 0 -4px;
    scale: 0.98;
    transition: opacity var(--dur-2), translate var(--dur-2) var(--ease-out), scale var(--dur-2) var(--ease-out), overlay var(--dur-2) allow-discrete, display var(--dur-2) allow-discrete;
}
.float:popover-open { opacity: 1; translate: 0 0; scale: 1; }
/* Panels set their own display (grid), which would beat the UA rule that hides a closed popover. */
.float:not(:popover-open) { display: none; }
@starting-style { .float:popover-open { opacity: 0; translate: 0 -4px; scale: 0.98; } }

@media (max-width: 719px) {
    .float[data-mobile="sheet"] {
        inset: auto 0 0 0;
        width: 100%;
        max-width: none;
        max-height: 86dvh;
        padding: var(--space-3) var(--gutter) calc(var(--space-4) + env(safe-area-inset-bottom));
        border-radius: var(--radius-l) var(--radius-l) 0 0;
        border-width: 1px 0 0;
        translate: 0 100%;
        scale: 1;
    }
    .float[data-mobile="sheet"]:popover-open { translate: 0 0; }
    @starting-style { .float[data-mobile="sheet"]:popover-open { translate: 0 100%; } }
    .float[data-mobile="sheet"]::backdrop { background: rgb(0 0 0 / 0.5); }
    .float[data-mobile="sheet"]::before { content: ""; display: block; width: 44px; height: 5px; margin: 0 auto var(--space-3); border-radius: 9px; background: var(--line-strong); }
}

/* ---------- Menu ---------- */
.menu-host { display: inline-flex; }
.menu { display: grid; gap: 2px; min-width: 220px; }
.menu__item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    width: 100%;
    min-height: 44px;
    padding: 0 var(--space-3);
    border: 0;
    border-radius: var(--radius-s);
    background: transparent;
    color: var(--text);
    font: inherit;
    font-weight: 600;
    text-align: left;
    text-decoration: none;
    cursor: pointer;
}
.menu__item svg { width: 20px; height: 20px; color: var(--text-3); flex: none; }
.menu__item:hover, .menu__item:focus-visible { background: var(--surface-2); outline: none; }
.menu__item kbd { margin-left: auto; color: var(--text-3); font: 600 12px var(--font-body); }
.menu__item--danger, .menu__item--danger svg { color: var(--danger); }
.menu__item[aria-disabled="true"] { opacity: 0.45; cursor: not-allowed; }
.menu__sep { height: 1px; margin: 4px 6px; background: var(--line); }
.menu__label { padding: 8px var(--space-3) 4px; font-size: 11px; font-weight: 800; letter-spacing: 0.12em; text-transform: uppercase; color: var(--text-3); }

/* ---------- Popover card ---------- */
.popcard { display: grid; gap: var(--space-2); padding: var(--space-2); max-width: 300px; }
.popcard h4 { font-size: var(--step-1); }
.popcard p { margin: 0; color: var(--text-2); font-size: var(--step--1); }

/* ---------- Tooltip (CSS only, text stays in the accessibility tree via aria-describedby) ---------- */
.tip { position: relative; display: inline-flex; }
.tip__bubble {
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    z-index: 40;
    width: max-content;
    max-width: 240px;
    padding: 6px 10px;
    border-radius: var(--radius-s);
    background: var(--text);
    color: var(--bg);
    font-size: 13px;
    font-weight: 700;
    line-height: 1.35;
    pointer-events: none;
    visibility: hidden;
    opacity: 0;
    translate: -50% 4px;
    transition: opacity var(--dur-2), translate var(--dur-2) var(--ease-out), visibility var(--dur-2);
}
.tip__bubble::after { content: ""; position: absolute; top: 100%; left: 50%; margin-left: -5px; border: 5px solid transparent; border-top-color: var(--text); }
.tip:is(:hover, :focus-within):not([data-dismissed]) .tip__bubble { visibility: visible; opacity: 1; translate: -50% 0; transition-delay: 250ms; }

/* ---------- Dropdown (custom select) ---------- */
.dropdown { display: grid; gap: var(--space-2); }
.dropdown__trigger {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    width: 100%;
    min-height: var(--tap);
    padding: 0 var(--space-3) 0 var(--space-4);
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-m);
    background: var(--bg-sunken);
    color: var(--text-3);
    font: inherit;
    font-size: 16px;
    text-align: left;
    cursor: pointer;
    transition: border-color var(--dur-2), box-shadow var(--dur-2), background var(--dur-2);
}
.dropdown__trigger > svg { width: 20px; height: 20px; flex: none; color: var(--text-3); }
.dropdown__trigger > span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dropdown__trigger .dropdown__chev { transition: rotate var(--dur-2) var(--ease-out); }
[data-filled] > .dropdown__trigger, [data-filled] .dropdown__trigger { color: var(--text); font-weight: 600; }
.dropdown__trigger:hover { border-color: var(--text-3); }
.dropdown__trigger:focus-visible, .dropdown__trigger[aria-expanded="true"] { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); background: var(--bg); }
.dropdown__trigger[aria-expanded="true"] .dropdown__chev { rotate: 180deg; }
.dropdown__trigger:disabled { opacity: 0.5; cursor: not-allowed; }
.field--error .dropdown__trigger { border-color: var(--danger); }

.dropdown__panel { padding: var(--space-2); display: grid; gap: var(--space-2); align-content: start; }
.dropdown__panel .search .input { min-height: 44px; }
.dropdown__list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; outline: none; max-height: 290px; overflow: auto; overscroll-behavior: contain; }
.dropdown__group { display: grid; gap: 2px; }
.dropdown__group-label { padding: 8px var(--space-3) 4px; font-size: 11px; font-weight: 800; letter-spacing: 0.12em; text-transform: uppercase; color: var(--text-3); }
.option {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    min-height: 44px;
    padding: 6px var(--space-3);
    border-radius: var(--radius-s);
    cursor: pointer;
}
.option small { display: block; color: var(--text-3); font-size: 12px; font-weight: 600; }
.option > svg { width: 18px; height: 18px; margin-left: auto; color: var(--accent-2); opacity: 0; flex: none; }
.option[data-active] { background: var(--surface-2); }
.option[aria-selected="true"] { color: var(--accent-2); font-weight: 800; }
.option[aria-selected="true"] > svg { opacity: 1; }
.option[aria-disabled="true"] { opacity: 0.4; cursor: not-allowed; }
.option__box { width: 20px; height: 20px; flex: none; border: 1.5px solid var(--line-strong); border-radius: 6px; display: grid; place-items: center; }
.option[aria-selected="true"] .option__box { background: var(--accent); border-color: var(--accent); }
.option[aria-selected="true"] .option__box::after { content: ""; width: 10px; height: 10px; background: var(--accent-ink); clip-path: polygon(14% 52%, 0 66%, 38% 100%, 100% 22%, 86% 8%, 37% 70%); }
.option .swatch-dot { width: 12px; height: 12px; border-radius: 50%; flex: none; }
.dropdown__empty { margin: 0; padding: var(--space-4); text-align: center; color: var(--text-3); font-size: var(--step--1); }
.dropdown__control { position: relative; }
.dropdown--clearable .dropdown__trigger { padding-right: 84px; }
.dropdown__clear { position: absolute; right: 44px; top: 50%; translate: 0 -50%; display: grid; place-items: center; width: 32px; height: 32px; padding: 0; border: 0; border-radius: 50%; background: transparent; color: var(--text-3); cursor: pointer; }
.dropdown__clear svg { width: 18px; height: 18px; }
.dropdown__clear:hover, .dropdown__clear:focus-visible { background: var(--surface-2); color: var(--text); outline: none; }
.dropdown:not([data-filled]) .dropdown__clear, .dropdown__clear:disabled { display: none; }

/* ---------- Date picker ---------- */
.datepicker { width: 340px; max-height: min(600px, 92dvh); padding: var(--space-3); display: grid; gap: var(--space-3); }
.datepicker__head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); }
.datepicker__head strong { font-family: var(--font-display); font-size: var(--step-1); font-weight: var(--display-weight); letter-spacing: var(--display-tracking); }
.datepicker__head .btn--icon { width: 40px; height: 40px; min-height: 40px; }
.datepicker__quick { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; }
.datepicker__quick .chip { cursor: pointer; flex: none; font: inherit; font-size: 13px; font-weight: 700; }
.datepicker__foot { display: flex; justify-content: space-between; gap: var(--space-2); }
.dp-grid { width: 100%; border-collapse: collapse; table-layout: fixed; }
.dp-grid th { padding: 0 0 6px; font-size: 11px; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-3); }
.dp-grid td { padding: 2px 0; text-align: center; }
.dp-day {
    position: relative;
    width: 40px;
    height: 40px;
    border: 0;
    border-radius: var(--radius-m);
    background: transparent;
    color: var(--text);
    font: inherit;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    cursor: pointer;
}
.dp-day:hover { background: var(--surface-2); }
.dp-day:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 1px; }
.dp-day[data-outside] { color: var(--text-3); opacity: 0.55; }
.dp-day[data-today] { box-shadow: inset 0 0 0 1.5px var(--accent); }
.dp-day[data-marked]::after { content: ""; position: absolute; left: 50%; bottom: 5px; width: 5px; height: 5px; margin-left: -2.5px; border-radius: 50%; background: var(--accent-2); box-shadow: 0 0 6px var(--glow); }
.dp-day[data-between] { background: var(--accent-soft); border-radius: 0; }
.dp-day[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); box-shadow: 0 0 16px -2px var(--glow); }
.dp-day[aria-pressed="true"]::after { background: var(--accent-ink); box-shadow: none; }
.dp-day[data-edge="start"] { border-radius: var(--radius-m) 0 0 var(--radius-m); }
.dp-day[data-edge="end"] { border-radius: 0 var(--radius-m) var(--radius-m) 0; }
.dp-day[aria-disabled="true"] { color: var(--text-3); opacity: 0.35; text-decoration: line-through; cursor: not-allowed; background: none; }
@media (max-width: 719px) {
    .datepicker { width: 100%; }
    .dp-day { width: 100%; max-width: 48px; height: 46px; }
}

/* Time slots */
.timeslots-field { margin: 0; padding: 0; border: 0; min-width: 0; }
.timeslots-field legend { padding: 0; margin-bottom: var(--space-2); }
.timeslots { display: grid; grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); gap: var(--space-2); }
.timeslot input { position: absolute; opacity: 0; pointer-events: none; }
.timeslot {
    position: relative;
    display: grid;
    place-items: center;
    min-height: 44px;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-m);
    background: var(--bg-sunken);
    color: var(--text);
    font: inherit;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    cursor: pointer;
}
.timeslot:hover { border-color: var(--text-3); }
.timeslot:has(input:checked) { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-2); }
.timeslot:has(input:focus-visible) { outline: 2px solid var(--accent-2); outline-offset: 2px; }
.timeslot:has(input:disabled) { opacity: 0.35; text-decoration: line-through; cursor: not-allowed; }
.input[type="time"], .input[type="date"] { font-variant-numeric: tabular-nums; color-scheme: inherit; }

/* ---------- Modal (native dialog) ---------- */
.modal {
    width: min(520px, calc(100vw - 2 * var(--gutter)));
    max-height: min(86dvh, 760px);
    margin: auto;
    padding: 0;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-l);
    background: var(--bg-raised);
    color: var(--text);
    box-shadow: var(--shadow-2);
    overflow: hidden;
    opacity: 0;
    translate: 0 16px;
    scale: 0.98;
    transition: opacity var(--dur-2), translate var(--dur-3) var(--ease-out), scale var(--dur-3) var(--ease-out), overlay var(--dur-3) allow-discrete, display var(--dur-3) allow-discrete;
}
.modal[open] { display: flex; flex-direction: column; opacity: 1; translate: 0 0; scale: 1; }
@starting-style { .modal[open] { opacity: 0; translate: 0 16px; scale: 0.98; } }
.modal::backdrop { background: rgb(0 0 0 / 0); backdrop-filter: blur(0); transition: background var(--dur-3), backdrop-filter var(--dur-3), overlay var(--dur-3) allow-discrete, display var(--dur-3) allow-discrete; }
.modal[open]::backdrop { background: rgb(0 0 0 / 0.6); backdrop-filter: blur(3px); }
@starting-style { .modal[open]::backdrop { background: rgb(0 0 0 / 0); backdrop-filter: blur(0); } }
.modal--wide { width: min(600px, calc(100vw - 2 * var(--gutter))); }
.modal__head { display: flex; align-items: flex-start; gap: var(--space-3); padding: var(--space-5) var(--space-5) var(--space-3); }
.modal__head h3 { flex: 1; font-size: var(--step-2); }
.modal__titles { flex: 1; display: grid; gap: 6px; }
.modal__art { position: relative; height: 150px; display: grid; place-items: center; background: radial-gradient(70% 90% at 50% 100%, var(--accent-soft), transparent 70%), var(--bg-sunken); border-bottom: 1px solid var(--line); }
.modal__art .coal { --size: 72px; }
.modal__head .btn--icon { margin: -6px -10px 0 0; }
.modal__body { display: grid; gap: var(--space-4); padding: 0 var(--space-5) var(--space-5); overflow: auto; overscroll-behavior: contain; color: var(--text-2); }
.modal__body > p { margin: 0; }
.modal__foot { display: flex; justify-content: flex-end; gap: var(--space-2); padding: var(--space-4) var(--space-5); border-top: 1px solid var(--line); background: var(--bg-sunken); }
.modal__icon { display: grid; place-items: center; width: 48px; height: 48px; border-radius: 50%; flex: none; background: var(--accent-soft); color: var(--accent-2); }
.modal__icon svg { width: 26px; height: 26px; }
.modal--danger .modal__icon { background: var(--danger-soft); color: var(--danger); }

@media (max-width: 719px) {
    .modal--sheet { width: 100%; max-width: none; margin: auto 0 0; border-radius: var(--radius-l) var(--radius-l) 0 0; border-width: 1px 0 0; translate: 0 100%; scale: 1; }
    .modal--sheet[open] { translate: 0 0; }
    @starting-style { .modal--sheet[open] { translate: 0 100%; } }
    .modal--sheet .modal__foot { padding-bottom: calc(var(--space-4) + env(safe-area-inset-bottom)); }
    .modal__foot { flex-direction: column-reverse; }
    .modal__foot .btn { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
    .float, .modal, .modal::backdrop { transition: none; }
}

.modal__meta { display: flex; flex-wrap: wrap; gap: 8px 18px; margin: 0; color: var(--text-2); font-weight: 600; }
.modal__meta > span, .agenda-item__meta > span { display: inline-flex; align-items: center; gap: 6px; }
.modal__meta svg { width: 18px; height: 18px; color: var(--text-3); }
