/* ─────────────────────────────────────────────────────────────────────────
   Floor plan — realistic restaurant tables on a responsive canvas.

   Layout model: a fixed logical "world" holds the tables at percentage
   positions, so spacing maths is deterministic in world pixels. The world is
   auto-scaled to fit the viewport by the viewport controller
   (js/reservations/floor-viewport.js) — there is no zoom or pan; the whole plan
   is always shown and stays responsive. Status is shown by a coloured border +
   small badge — the tabletop is never colour-filled.

   Shared by the admin editor and the public booking view; admin-only
   affordances live under .floorplan-canvas--admin.
   ───────────────────────────────────────────────────────────────────────── */

:root {
    --fp-available: #2f9e57;
    --fp-pending:   #e0a800;
    --fp-booked:    #d9463e;
    --fp-blocked:   #9aa1aa;
    /* Distinct blue so a picked table can't be confused with the amber
       "pending" status or the green/red availability colours. */
    --fp-selected:  #2563eb;
    /* Figma table two-tone greys. */
    --fp-header:    #6f6f6f;
    --fp-body:      #d6d6d6;
}

/* Viewport: the visible window onto the world. Its shape follows the uploaded
   floor-plan image (aspect-ratio set inline per image), capped so very tall
   plans stay usable; the world is then zoom-fitted inside. */
.floorplan-canvas {
    position: relative;
    aspect-ratio: 16 / 10;
    max-height: 78vh;
    border-radius: 18px;
    background: #fff;
    overflow: hidden;
    user-select: none;
    -webkit-user-select: none;
}

/* Transform layer driven by the viewport controller. */
.floorplan-zoom {
    position: absolute;
    top: 0;
    left: 0;
    transform-origin: 0 0;
    transform: translate(var(--pan-x, 0px), var(--pan-y, 0px)) scale(var(--zoom, 1));
    will-change: transform;
}

/* The fixed logical floor. Clean by default (customer); the admin overlays the
   reference image on top of this via ::before. */
.floorplan-world {
    --world-w: 1600px;
    --world-h: 1000px;
    position: relative;
    width: var(--world-w);
    height: var(--world-h);
    background: #fff;
    border-radius: 14px;
}

/* Decorative room walls / door / window / labels drawn behind the tables. */
.fp-room {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
}

/* ── Table ─────────────────────────────────────────────────────────────── */
.ftable {
    --scale: 1;
    --base: 210px;             /* fixed logical size — keeps spacing deterministic */
    --size: calc(var(--base) * var(--scale));
    --chair: calc(52px * var(--scale));   /* chair footprint (enlarged, tappable) */
    --rot: 0deg;
    --sc: var(--fp-available);
    position: absolute;
    left: 50%;
    top: 50%;
    width: var(--size);
    height: var(--size);
    transform: translate(-50%, -50%);
    z-index: 1;
    cursor: pointer;
}
.ftable--rectangle { width: calc(var(--size) * 1.7); }

.ftable__ring {
    position: absolute;
    inset: 0;
    transform: rotate(var(--rot));
    transition: transform .28s cubic-bezier(.2, .8, .2, 1);
}

/* Figma table — a two-tone grey card: a dark header band ("Table N") over a
   lighter body ("N People"). The whole card rotates with the table, so a
   diamond tilts 45° and its header sits on the upper-left facet exactly like
   the design. */
.ftable__body {
    position: absolute;
    inset: 20%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--fp-body);
    border-radius: 12px;
    box-shadow: 0 6px 14px -8px rgba(40, 30, 20, .35);
    transition: box-shadow .22s ease, transform .22s ease, opacity .22s ease;
}
.ftable__body--round   { border-radius: 50%; }
/* -45° puts the header on the upper-left facet with ascending text (Figma T12). */
.ftable__body--diamond { transform: rotate(-45deg); }

/* Dark header band with the table name. */
.ftable__header {
    flex: 0 0 auto;
    padding: 7px 8px;
    background: var(--fp-header);
    color: #fff;
    font-size: 25px;
    font-weight: 500;
    line-height: 1.15;
    text-align: center;
    letter-spacing: .2px;
    white-space: nowrap;
    transition: background-color .22s ease;
}
/* Lighter body with the seat count. */
.ftable__content {
    flex: 1 1 auto;
    display: grid;
    place-items: center;
    padding: 6px 8px;
    color: #232323;
    font-size: 25px;
    font-weight: 600;
    text-align: center;
}

/* ── Chairs — outlined line-art chairs, backrest facing outward ─────────── */
.ftable__seat {
    position: absolute;
    left: calc(50% + var(--sx, 0) * var(--size));
    top: calc(50% + var(--sy, 0) * var(--size));
    width: var(--chair);
    height: var(--chair);
    transform: translate(-50%, -50%) rotate(var(--sa, 0deg));
    background: center / contain no-repeat
        url("data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2040%2038'%3E%3Cg%20fill='%23ffffff'%20stroke='%238d8d8d'%20stroke-width='2'%20stroke-linejoin='round'%3E%3Crect%20x='11'%20y='2'%20width='18'%20height='7'%20rx='3.5'/%3E%3Crect%20x='7'%20y='10'%20width='26'%20height='25'%20rx='6'/%3E%3Crect%20x='2'%20y='14'%20width='6'%20height='15'%20rx='3'/%3E%3Crect%20x='32'%20y='14'%20width='6'%20height='15'%20rx='3'/%3E%3C/g%3E%3C/svg%3E");
}

/* ── Status — colour reads at a glance: green = available, amber = pending,
   red = booked, grey = unavailable. Each table takes a tinted body + a matching
   coloured header band and ring so availability is obvious on the plan. ────── */
.ftable--available .ftable__header { background: var(--fp-available); }
.ftable--available .ftable__body {
    background: #e9f7ee;
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--fp-available) 60%, transparent), 0 6px 14px -8px rgba(40, 30, 20, .35);
}

.ftable--pending .ftable__header { background: var(--fp-pending); }
.ftable--pending .ftable__body {
    background: #fdf3d8;
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--fp-pending) 75%, transparent), 0 6px 14px -8px rgba(40, 30, 20, .35);
}

.ftable--booked .ftable__header { background: var(--fp-booked); }
.ftable--booked .ftable__body {
    background: #fdeceb;
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--fp-booked) 70%, transparent), 0 6px 14px -8px rgba(40, 30, 20, .35);
    opacity: .9;
}

.ftable--blocked .ftable__header { background: var(--fp-blocked); }
.ftable--blocked .ftable__body { opacity: .5; filter: grayscale(.4); }

/* ── Interactions ──────────────────────────────────────────────────────── */
.ftable:hover { z-index: 4; }
.ftable--available:hover .ftable__body { transform: translateY(-2px) scale(1.03); box-shadow: 0 12px 22px -10px rgba(40, 30, 20, .45); }
.ftable:focus-visible { outline: none; }
.ftable:focus-visible .ftable__body { box-shadow: 0 0 0 3px rgba(201, 162, 39, .6); }

.ftable.is-locked { cursor: not-allowed; }
.ftable.is-locked:hover .ftable__body { transform: none; }

/* Free, but not the right fit for the current party — clearly non-selectable. */
.ftable.is-toosmall .ftable__body,
.ftable.is-toobig .ftable__body { opacity: .45; filter: grayscale(.4); }

/* Selected — blue ring + blue header + blue tint, distinct from every status. */
.ftable.is-selected { z-index: 5; }
.ftable.is-selected .ftable__body { background: #e8f0ff; box-shadow: 0 0 0 3px var(--fp-selected), 0 10px 22px -10px rgba(40, 30, 20, .5); animation: fp-pop .3s ease; }
.ftable.is-selected .ftable__header { background: var(--fp-selected); }
@keyframes fp-pop { 0% { transform: scale(1); } 60% { transform: scale(1.05); } 100% { transform: scale(1.02); } }

/* Admin: edited table. */
.ftable.is-active { z-index: 5; }
.ftable.is-active .ftable__body { box-shadow: 0 0 0 3px #7b61ff; }
.ftable.is-active .ftable__header { background: #7b61ff; }
.floorplan-canvas--admin .ftable { cursor: pointer; }

@media (prefers-reduced-motion: reduce) {
    .ftable__ring, .ftable__body { transition: none; }
    .ftable.is-selected .ftable__body { animation: none; }
}

/* Empty state (admin, no tables). */
.fp-empty { position: absolute; inset: 0; display: grid; place-items: center; color: #a99; text-align: center; padding: 20px; z-index: 2; }

/* ── Legend ────────────────────────────────────────────────────────────── */
.fp-legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 13px; align-items: center; }
.fp-legend span { display: inline-flex; align-items: center; gap: 6px; }
.fp-legend .dot { width: 13px; height: 13px; border-radius: 50%; box-shadow: inset 0 -2px 3px rgba(0, 0, 0, .2); }
.fp-legend .dot--available { background: var(--fp-available); }
.fp-legend .dot--pending   { background: var(--fp-pending); }
.fp-legend .dot--booked    { background: var(--fp-booked); }
.fp-legend .dot--blocked   { background: var(--fp-blocked); }

/* On phones give the plan more vertical room so the auto-fitted tables stay
   large and easy to tap. */
@media (max-width: 640px) {
    .floorplan-canvas { max-height: 82vh; }
}
