/* ============================================================
   FLOOR — tables as a map, a grid or a list
   ------------------------------------------------------------
   The floor screen (js/pages/tables.js) and the drawn tables it
   shares with the table picker (js/components/table-shape.js).
   Builds on the .sec-bar / .table-card rules in pos-design.css;
   every colour is a theme token so dark mode follows on its own.
   ============================================================ */

/* ─── A drawn table ───────────────────────────────────────── */

/* State sets `color`; the drawing paints in currentColor. */
.tshape{display:inline-flex;align-items:center;justify-content:center;line-height:0;color:var(--ink-3)}
.ts-busy{color:var(--danger)}
.ts-hold{color:var(--warn)}
.ts-bill{color:var(--ok)}
.tshape .tsvg{display:block;max-width:100%;max-height:100%;overflow:visible;transition:transform .25s ease}
.tshape .top{
  fill:color-mix(in srgb,currentColor 14%,var(--surface));
  stroke:currentColor;stroke-width:2.5;
}
.ts-free .top{fill:var(--surface);stroke:var(--line-strong)}
.tshape .rim{fill:none;stroke:currentColor;stroke-width:1;stroke-opacity:.28;stroke-dasharray:3 3}
.tshape .chair{fill:var(--surface-2);stroke:var(--line-strong);stroke-width:1.5;transition:fill .2s}
.tshape .chair.occ{fill:currentColor;stroke:currentColor;fill-opacity:.85}
.tshape .bench{fill:var(--line-strong)}

/* ─── Tools row: view switch, summary, edit ───────────────── */

.fm-tools{
  display:flex;align-items:center;gap:12px;flex-wrap:wrap;
  padding:10px 14px;background:var(--surface);border-radius:var(--r-m);box-shadow:var(--shadow);
}
.fm-tools.editing{background:var(--info-soft);box-shadow:inset 0 0 0 2px var(--info)}

.fm-views{display:inline-flex;padding:3px;border-radius:var(--r-m);background:var(--surface-2);border:1.5px solid var(--line)}
.fm-view{
  display:inline-flex;align-items:center;gap:6px;min-height:36px;padding:0 14px;border-radius:6px;
  font-size:13px;font-weight:800;color:var(--ink-2);transition:background .16s,color .16s,box-shadow .16s;
}
.fm-view svg{width:17px;height:17px}
.fm-view[aria-pressed="true"]{background:var(--surface);color:var(--brand);box-shadow:var(--shadow),0 0 0 1.5px var(--brand-ring)}
.fm-view:disabled{opacity:.4;cursor:not-allowed}

.fm-sum{display:flex;gap:14px;font-size:12.5px;font-weight:700;color:var(--ink-3)}
.fm-sum b{color:var(--ink);font-size:14px}
.fm-edit{margin-inline-start:auto;display:inline-flex;align-items:center;gap:7px}
.fm-edit svg,.fm-acts .b svg{width:16px;height:16px}

.fm-hint{display:grid;gap:1px;min-width:120px}
.fm-hint b{font-size:13.5px;font-weight:800;color:var(--info)}
.fm-hint span{font-size:12.5px;font-weight:700;color:var(--ink-2)}
.fm-ctl{display:flex;align-items:center;gap:6px}
.fm-ctl:empty{display:none}
.fm-ic,.fm-shape-btn{
  width:40px;height:40px;border-radius:var(--r-m);display:grid;place-items:center;
  background:var(--surface);border:1.5px solid var(--line-strong);color:var(--ink-2);transition:.15s;
}
.fm-ic svg{width:18px;height:18px}
.fm-ic.flip svg{transform:scaleX(-1)}
.fm-ic:hover,.fm-shape-btn:hover{border-color:var(--info);color:var(--info)}
.fm-shape-btn{padding:4px;color:var(--ink-3)}
.fm-shape-btn svg{width:30px;height:30px}
.fm-shape-btn .top{fill:var(--surface);stroke:currentColor;stroke-width:3}
.fm-shape-btn .rim{display:none}
.fm-shape-btn .chair{fill:currentColor;stroke:none;opacity:.55}
.fm-shape-btn .bench{fill:currentColor}
.fm-shape-btn[aria-pressed="true"]{border-color:var(--info);color:var(--info);background:var(--info-soft)}
.fm-sep{width:1.5px;height:26px;background:var(--line-strong);margin-inline:4px}
.fm-acts{display:flex;gap:8px;margin-inline-start:auto}
.fm-acts .b{display:inline-flex;align-items:center;gap:6px}

/* "Open too long" in the legend: a dashed warn ring, like on the tables. */
.fm-lg-long{color:var(--warn)}
.fm-lg-long i{border-style:dashed;background:none}

/* ─── Body ────────────────────────────────────────────────── */

.screen[data-screen="tables"] .fm-body{display:flex;flex-direction:column;min-height:0}
.fm-body[data-view="map"]{overflow:hidden}
.fm-body[data-view="list"]{overflow:auto}

/* ─── Map ─────────────────────────────────────────────────── */

.fm-stage{flex:1;min-height:0;display:grid;place-items:center}
.fm-canvas{
  --u:1;
  position:relative;width:100%;aspect-ratio:16/10;border-radius:var(--r-l);
  background-color:var(--surface);
  /* Floor: soft dots every grid step, so the snap has something to land on. */
  background-image:radial-gradient(circle,var(--line-strong) 1px,transparent 1.4px);
  background-size:calc(var(--snap) * 2 * var(--u) * 1px) calc(var(--snap) * 2 * var(--u) * 1px);
  box-shadow:var(--shadow),inset 0 0 0 1.5px var(--line);
  overflow:hidden;touch-action:pan-y;user-select:none;-webkit-user-select:none;
  transition:box-shadow .2s;
}
/* Editing: the full snap grid shows, and touch belongs to the drag. */
.fm-canvas.editing{
  touch-action:none;
  background-image:
    linear-gradient(var(--line) 1px,transparent 1px),
    linear-gradient(90deg,var(--line) 1px,transparent 1px);
  background-size:calc(var(--snap) * var(--u) * 1px) calc(var(--snap) * var(--u) * 1px);
  box-shadow:var(--shadow),inset 0 0 0 2px var(--info);
}
.fm-empty{position:absolute;inset:0;display:grid;place-items:center}

.fm-t{
  position:absolute;width:calc(var(--bw) * var(--u) * 1px);height:calc(var(--bh) * var(--u) * 1px);
  transform:translate(-50%,-50%);padding:0;border:0;background:none;border-radius:14px;
  transition:left .22s ease,top .22s ease,filter .16s;
}
.fm-t:hover{filter:drop-shadow(0 6px 10px rgba(0,0,0,.14))}
.fm-t:focus-visible{outline:3px solid var(--brand-ring);outline-offset:4px}
.fm-t .fm-art{
  /* Physical left: centring is symmetric, and the map never mirrors. */
  position:absolute;left:50%;top:50%;
  width:calc(var(--sw) * var(--u) * 1px);height:calc(var(--sh) * var(--u) * 1px);
  transform:translate(-50%,-50%);
}
.fm-t .fm-art .tsvg{width:100%;height:100%;transform:rotate(var(--rot,0deg))}
.fm-lbl{
  position:absolute;inset:0;display:grid;place-items:center;pointer-events:none;
}
.fm-lbl b{
  font-size:calc(max(12px, 17px * var(--u)));font-weight:800;letter-spacing:-.02em;color:var(--ink);
  padding:1px 6px;border-radius:6px;background:color-mix(in srgb,var(--surface) 70%,transparent);
  max-width:calc(100% - 6px);white-space:nowrap;overflow:hidden;text-overflow:ellipsis;
}
.fm-lbl b.long{font-size:calc(max(10px, 12px * var(--u)))}
.fm-info{
  position:absolute;top:calc(100% - 4px);left:50%;transform:translateX(-50%);
  display:flex;gap:6px;white-space:nowrap;pointer-events:none;z-index:1;
  padding:2px 8px;border-radius:999px;background:var(--surface);box-shadow:var(--shadow),0 0 0 1.5px currentColor;
  font-size:11px;font-weight:800;color:var(--ink-2);
}
.fm-t.t-busy .fm-info{color:var(--danger)}
.fm-t.t-bill .fm-info{color:var(--ok)}
.fm-t.t-hold .fm-info{color:var(--warn)}
.fm-clock{font-variant-numeric:tabular-nums;unicode-bidi:isolate;white-space:nowrap}
.fm-info .fm-clock{color:var(--ink-3)}

/* Bill asked for: the table breathes, so it is found across the room. */
.fm-t.t-bill .tsvg{animation:fm-pulse 1.8s ease-in-out infinite}
@keyframes fm-pulse{
  0%,100%{filter:drop-shadow(0 0 0 transparent)}
  50%{filter:drop-shadow(0 0 7px var(--ok))}
}
/* Open too long: a dashed warn halo round the drawing, and the timer goes warn. */
.fm-t.long::before{
  content:"";position:absolute;inset:-6px;border-radius:50%;
  border:2px dashed var(--warn);opacity:.8;pointer-events:none;
}
.fm-t.long .fm-info .fm-clock,.fm-card.long .fm-clock,.fm-li.long .fm-clock{color:var(--warn);font-weight:800}

/* Editing on the map. */
.fm-canvas.editing .fm-t{cursor:grab;transition:filter .16s}
.fm-canvas.editing .fm-info{display:none}
.fm-t.fm-on{outline:2.5px solid var(--info);outline-offset:5px}
.fm-t.dragging{cursor:grabbing;z-index:5;filter:drop-shadow(0 14px 18px rgba(0,0,0,.28))}
.fm-t.dragging .fm-art{scale:1.06}
.fm-guide{position:absolute;display:none;pointer-events:none;z-index:4;background:var(--info)}
.fm-guide.on{display:block}
.fm-guide.v{top:0;bottom:0;width:1.5px;margin-left:-.75px}
.fm-guide.h{left:0;right:0;height:1.5px;margin-top:-.75px}

/* ─── Grid (and the picker) ───────────────────────────────── */

.fm-grid{grid-template-columns:repeat(auto-fill,minmax(180px,1fr));padding:4px 2px}
.fm-card{gap:6px}
.fm-card .fm-cart{display:grid;place-items:center;height:92px;padding:4px 0}
.fm-card .fm-cart .tshape{width:100%;height:100%}
.fm-cfoot{display:flex;gap:12px;flex-wrap:wrap}
.fm-card .meta .num{color:var(--ink-2)}
.fm-card.t-bill{border-color:var(--ok)}
.fm-card.t-bill .st{background:var(--ok-soft);color:var(--ok)}
.fm-card.long{box-shadow:0 0 0 3px var(--warn-soft)}
.tp-grid .fm-card .fm-cart{height:64px}

/* ─── List ────────────────────────────────────────────────── */

.fm-list{display:grid;background:var(--surface);border-radius:var(--r-m);box-shadow:var(--shadow);overflow:hidden}
.fm-li{
  display:grid;align-items:center;gap:12px;padding:8px 14px;
  grid-template-columns:56px minmax(110px,1.3fr) 112px 70px 84px minmax(70px,1fr) 104px 140px;
  border-bottom:1px solid var(--line);font-size:13.5px;font-weight:700;color:var(--ink-2);
  border-inline-start:4px solid var(--line-strong);cursor:pointer;transition:background .14s;
}
.fm-li:last-child{border-bottom:0}
.fm-li:hover{background:var(--surface-2)}
.fm-li:focus-visible{outline:3px solid var(--brand-ring);outline-offset:-3px}
.fm-li.t-busy{border-inline-start-color:var(--danger)}
.fm-li.t-hold{border-inline-start-color:var(--warn)}
.fm-li.t-bill{border-inline-start-color:var(--ok)}
.fm-li.long{background:color-mix(in srgb,var(--warn-soft) 55%,transparent)}
.fm-lh{
  position:sticky;top:0;z-index:1;cursor:default;background:var(--surface-2);
  font-size:11.5px;font-weight:800;text-transform:uppercase;letter-spacing:.04em;color:var(--ink-3);
  border-inline-start-color:transparent;
}
.fm-lh:hover{background:var(--surface-2)}
.fm-li .end{text-align:end;justify-self:end}
.fm-thumb{width:56px;height:44px;display:grid;place-items:center}
.fm-thumb .tshape,.fm-card .fm-cart .tsvg,.fm-thumb .tsvg{width:100%;height:100%}
.fm-name{display:grid;min-width:0}
.fm-name b{font-size:17px;font-weight:800;color:var(--ink)}
.fm-name small,.fm-total small{font-size:11.5px;font-weight:700;color:var(--ink-3);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.fm-total{display:grid;font-size:15px;font-weight:800;color:var(--ink)}
.fm-waiter{white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.fm-dim{color:var(--ink-3)}
.fm-li .st{padding:4px 10px;border-radius:999px;font-size:11.5px;font-weight:800;border:1.5px solid currentColor;white-space:nowrap}
.fm-li.t-free .st{background:var(--surface-2);color:var(--ink-3)}
.fm-li.t-busy .st{background:var(--danger-soft);color:var(--danger)}
.fm-li.t-hold .st{background:var(--warn-soft);color:var(--warn)}
.fm-li.t-bill .st{background:var(--ok-soft);color:var(--ok)}
.fm-li .b{display:inline-flex;align-items:center;gap:6px;white-space:nowrap}
.fm-li .b svg{width:15px;height:15px}

/* Narrow till or phone: the list drops the columns that can wait. */
@media (max-width:820px){
  .fm-li{grid-template-columns:44px 1fr auto auto}
  .fm-li > :nth-child(4),.fm-li > :nth-child(5),.fm-li > :nth-child(6){display:none}
  .fm-sum{display:none}
  .fm-view span{display:none}
}

/* ─── Motion ──────────────────────────────────────────────── */

@media (prefers-reduced-motion:reduce){
  .fm-t,.fm-t .fm-art,.tshape .tsvg,.tshape .chair,.fm-view,.fm-li{transition:none}
  .fm-t.t-bill .tsvg{animation:none;filter:drop-shadow(0 0 4px var(--ok))}
}
